diff --git a/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionFragment.kt b/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionFragment.kt index ed14a22..f9fae6d 100644 --- a/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionFragment.kt +++ b/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionFragment.kt @@ -35,9 +35,11 @@ class ResolutionFragment : Fragment() { private lateinit var windowManager: WindowManager + private var userId = 0 + companion object { lateinit var iWindowManager: Any - lateinit var iUserManager: Any + lateinit var iUserManager: Any } override fun onCreateView( @@ -57,6 +59,10 @@ class ResolutionFragment : Fragment() { resolutionViewModel.fetchScreenResolution(windowManager) resolutionViewModel.fetchUsers() + val textView = binding.textResolution + resolutionViewModel.text.observe(viewLifecycleOwner) { + textView.text = it + } val textHeight = binding.textHeight.editText!! val textWidth = binding.textWidth.editText!! val textDpi = binding.textDpi.editText!! @@ -68,17 +74,20 @@ class ResolutionFragment : Fragment() { val chipGroup = binding.chipGroup resolutionViewModel.usersList.observe(viewLifecycleOwner) { Log.d("usersRecved", it.toString()) - chipGroup.addView(Chip(chipGroup.context).apply { - text = "${it["name"]} (${it["id"]})" - isCheckable = true - isCheckedIconVisible = true - }) - } - val textView = binding.textResolution - resolutionViewModel.text.observe(viewLifecycleOwner) { - textView.text = it + for (user in it) { + chipGroup.addView(Chip(chipGroup.context).apply { + text = "${user["name"]} (${user["id"]})" + isCheckable = true + isCheckedIconVisible = true + }) + } } + chipGroup.setOnCheckedChangeListener { group, index -> + Log.d("index", index.toString()) + val currentUser = resolutionViewModel.usersList.value!![index] as Map + userId = currentUser["id"] as Int + } binding.btApply.setOnClickListener { applyResolution(textHeight.text.toString().toInt(), textWidth.text.toString().toInt(), @@ -104,7 +113,6 @@ class ResolutionFragment : Fragment() { "setForcedDisplaySize", Display.DEFAULT_DISPLAY, width, height) // TODO: apply dpi for each user - val userId = 0 HiddenApiBypass.invoke(iWindowManager::class.java, iWindowManager, "setForcedDisplayDensityForUser", Display.DEFAULT_DISPLAY, dpi, userId) diff --git a/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionViewModel.kt b/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionViewModel.kt index 9bbe962..e9f6596 100644 --- a/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionViewModel.kt +++ b/app/src/main/java/top/jiecs/screener/ui/resolution/ResolutionViewModel.kt @@ -37,8 +37,8 @@ class ResolutionViewModel : ViewModel() { "dpi" to 520) } - val usersList: MutableLiveData> by lazy { - MutableLiveData>() + val usersList: MutableLiveData>> by lazy { + MutableLiveData>>() } fun fetchUsers() { val userManager = ResolutionFragment.iUserManager @@ -61,14 +61,15 @@ class ResolutionViewModel : ViewModel() { // TODO - usersList.setValue(mapOf( - "id" to 0, - "name" to "jiesou" - )) - usersList.setValue(mapOf( - "id" to 10, - "name" to "second user" - )) + usersList.setValue( + listOf(mapOf( + "id" to 0, + "name" to "jiesou" + ), mapOf( + "id" to 10, + "name" to "second user") + ) + ) } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4cfc592..2c2f02d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.0.0' apply false - id 'com.android.library' version '8.0.0' apply false + id 'com.android.application' version '8.1.1' apply false + id 'com.android.library' version '8.1.1' apply false id 'org.jetbrains.kotlin.android' version '1.8.21' apply false }