Skip to content

Commit

Permalink
Merge pull request lihenggui#177 from lihenggui/modularization
Browse files Browse the repository at this point in the history
Fix ordering issues in the app list and component list
  • Loading branch information
lihenggui authored May 2, 2023
2 parents b0e3f80 + 2639d68 commit 4ecc9d8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/AndroidCIWithGmd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ on:
pull_request:

jobs:

android-ci:
runs-on: macos-12
strategy:
matrix:
device-config: [ "pixel4api30aospatd", "pixelcapi30aospatd" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
Expand All @@ -29,7 +25,7 @@ jobs:

- name: Run instrumented tests with GMD
run: ./gradlew cleanManagedDevices --unused-only &&
./gradlew ${{ matrix.device-config }}fossDebugAndroidTest -Dorg.gradle.workers.max=1
./gradlew ciFossDebugAndroidTest -Dorg.gradle.workers.max=1
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true

- name: Upload test reports
Expand All @@ -38,4 +34,4 @@ jobs:
with:
name: test-reports
path: |
'**/*/build/reports/androidTests/'
'**/build/reports/androidTests/'
19 changes: 13 additions & 6 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,22 @@ jobs:
- name: Upload build outputs (APKs)
uses: actions/upload-artifact@v3
with:
name: build-outputs
path: app/build/outputs
name: APKs
path: '**/build/outputs/apk/**/*.apk'

- name: Upload build reports
- name: Upload lint reports (HTML)
if: always()
uses: actions/upload-artifact@v3
with:
name: build-reports
path: app/build/reports
name: lint-reports
path: '**/build/reports/lint-results-*.html'

- name: Upload test results (XML)
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: '**/build/test-results/test*UnitTest/**.xml'

androidTest:
needs: build
Expand Down Expand Up @@ -97,4 +104,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ matrix.api-level }}
path: '*/build/reports/androidTests'
path: '**/build/reports/androidTests'
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.merxury.blocker

import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ManagedVirtualDevice
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.invoke

/**
Expand All @@ -27,23 +28,31 @@ import org.gradle.kotlin.dsl.invoke
internal fun configureGradleManagedDevices(
commonExtension: CommonExtension<*, *, *, *>,
) {
val deviceConfigs = listOf(
DeviceConfig("Pixel 4", 30, "aosp-atd"),
DeviceConfig("Pixel 6", 31, "aosp"),
DeviceConfig("Pixel C", 30, "aosp-atd"),
)
val pixel4 = DeviceConfig("Pixel 4", 30, "aosp-atd")
val pixel6 = DeviceConfig("Pixel 6", 31, "aosp")
val pixelC = DeviceConfig("Pixel C", 30, "aosp-atd")

val allDevices = listOf(pixel4, pixel6, pixelC)
val ciDevices = listOf(pixel4, pixelC)

commonExtension.testOptions {
managedDevices {
devices {
deviceConfigs.forEach { deviceConfig ->
allDevices.forEach { deviceConfig ->
maybeCreate(deviceConfig.taskName, ManagedVirtualDevice::class.java).apply {
device = deviceConfig.device
apiLevel = deviceConfig.apiLevel
systemImageSource = deviceConfig.systemImageSource
}
}
}
groups {
maybeCreate("ci").apply {
ciDevices.forEach { deviceConfig ->
targetDevices.add(devices[deviceConfig.taskName])
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ import com.merxury.blocker.core.model.data.ControllerType.SHIZUKU
import com.merxury.blocker.core.model.preference.ComponentShowPriority.DISABLED_COMPONENTS_FIRST
import com.merxury.blocker.core.model.preference.ComponentShowPriority.ENABLED_COMPONENTS_FIRST
import com.merxury.blocker.core.model.preference.ComponentShowPriority.NONE
import com.merxury.blocker.core.model.preference.ComponentSorting
import com.merxury.blocker.core.model.preference.ComponentSorting.COMPONENT_NAME
import com.merxury.blocker.core.model.preference.ComponentSorting.PACKAGE_NAME
import com.merxury.blocker.core.model.preference.ComponentSortingOrder
import com.merxury.blocker.core.model.preference.ComponentSortingOrder.ASCENDING
import com.merxury.blocker.core.model.preference.ComponentSortingOrder.DESCENDING
import com.merxury.blocker.core.rule.entity.RuleWorkResult
Expand Down Expand Up @@ -366,32 +364,29 @@ class AppDetailViewModel @Inject constructor(
},
)
}
.sortedWith(componentComparator(sorting, order))
.apply {
.let { origList ->
when (sorting) {
COMPONENT_NAME -> when (order) {
ASCENDING -> origList.sortedBy { it.simpleName.lowercase() }
DESCENDING -> origList.sortedByDescending { it.simpleName.lowercase() }
}

PACKAGE_NAME -> when (order) {
ASCENDING -> origList.sortedBy { it.name.lowercase() }
DESCENDING -> origList.sortedByDescending { it.name.lowercase() }
}
}
}
.let { sortedList ->
when (userData.componentShowPriority) {
NONE -> return@apply
DISABLED_COMPONENTS_FIRST -> sortedBy { it.enabled() }
ENABLED_COMPONENTS_FIRST -> sortedByDescending { it.enabled() }
NONE -> sortedList
DISABLED_COMPONENTS_FIRST -> sortedList.sortedBy { it.enabled() }
ENABLED_COMPONENTS_FIRST -> sortedList.sortedByDescending { it.enabled() }
}
}
.sortedByDescending { it.isRunning }
.toMutableStateList()
}

private fun componentComparator(
sorting: ComponentSorting,
order: ComponentSortingOrder,
): Comparator<ComponentItem> {
val nameComparator: Comparator<ComponentItem> = when (sorting) {
COMPONENT_NAME -> compareBy { it.simpleName }
PACKAGE_NAME -> compareBy { it.packageName }
}
return when (order) {
ASCENDING -> nameComparator
DESCENDING -> nameComparator.reversed()
}
}

private fun updateSearchKeyword() {
val keyword = appDetailArgs.searchKeyword
.map { it.trim() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ class AppListViewModel @Inject constructor(
)
}.sortedWith(
appComparator(sortType),
).apply {
).let { sortedList ->
if (preference.showRunningAppsOnTop) {
sortedByDescending { it.isRunning }
sortedList.sortedByDescending { it.isRunning }
} else {
sortedList
}
}.toMutableStateList()
_appListFlow.value = _appList
Expand Down Expand Up @@ -187,6 +189,9 @@ class AppListViewModel @Inject constructor(
.collect { sorting ->
val newList = _appList.toMutableList()
newList.sortWith(appComparator(sorting))
if (userDataRepository.userData.first().showRunningAppsOnTop) {
newList.sortByDescending { it.isRunning }
}
_appList = newList.toMutableStateList()
_appListFlow.value = _appList
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
accompanist = "0.30.1"
androidDesugarJdkLibs = "2.0.3"
androidGradlePlugin = "8.0.0"
androidGradlePlugin = "8.0.1"
androidxActivity = "1.7.1"
androidxAppCompat = "1.6.1"
androidxBrowser = "1.5.0"
Expand Down Expand Up @@ -45,7 +45,7 @@ kotlinxDatetime = "0.4.0"
kotlinxSerializationJson = "1.5.0"
ksp = "1.8.20-1.0.11"
libsu = "5.0.5"
lint = "31.0.0"
lint = "31.0.1"
okhttp = "4.11.0"
protobuf = "3.22.3"
protobufPlugin = "0.9.3"
Expand Down

0 comments on commit 4ecc9d8

Please sign in to comment.