From 77a0904abca124c2e963e9c687d9b53a91389c6c Mon Sep 17 00:00:00 2001 From: jiesou Date: Sat, 17 Feb 2024 22:33:00 +0800 Subject: [PATCH] WIP: add resolution_editor fragment --- .idea/inspectionProfiles/Project_Default.xml | 68 ++++++++ .../java/top/jiecs/screener/MainActivity.kt | 1 + .../displaymode/DisplayModeDialogFragment.kt | 28 ++++ .../ui/displaymode/DisplayModeFragment.kt | 33 ++++ .../ui/resolution/ResolutionFragment.kt | 2 +- .../screener/ui/settings/SettingsFragment.kt | 2 + app/src/main/res/drawable/baseline_add_24.xml | 5 + .../res/layout/fragment_display_mode_item.xml | 24 ++- .../main/res/layout/fragment_resolution.xml | 153 +++++------------- app/src/main/res/layout/resolution_editor.xml | 92 +++++++++++ .../res/menu/display_mode_action_menu.xml | 10 ++ app/src/main/res/values/strings.xml | 1 + 12 files changed, 299 insertions(+), 120 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeDialogFragment.kt create mode 100644 app/src/main/res/drawable/baseline_add_24.xml create mode 100644 app/src/main/res/layout/resolution_editor.xml create mode 100644 app/src/main/res/menu/display_mode_action_menu.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..ee9f695 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,68 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/top/jiecs/screener/MainActivity.kt b/app/src/main/java/top/jiecs/screener/MainActivity.kt index 3900686..a1eea9a 100644 --- a/app/src/main/java/top/jiecs/screener/MainActivity.kt +++ b/app/src/main/java/top/jiecs/screener/MainActivity.kt @@ -12,6 +12,7 @@ import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupWithNavController import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.google.android.material.color.DynamicColors import com.google.android.material.snackbar.Snackbar import rikka.shizuku.Shizuku diff --git a/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeDialogFragment.kt b/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeDialogFragment.kt new file mode 100644 index 0000000..4e07a93 --- /dev/null +++ b/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeDialogFragment.kt @@ -0,0 +1,28 @@ +package top.jiecs.screener.ui.displaymode + +import android.app.Dialog +import android.content.DialogInterface +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import top.jiecs.screener.R +import top.jiecs.screener.units.ApiCaller + +class DisplayModeDialogFragment : DialogFragment() { + private lateinit var dialog: AlertDialog + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + isCancelable = false + dialog = MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.display_modes)) + .setMessage(getString(R.string.reset_hint)) + .setPositiveButton(getString(R.string.looks_fine), null) + .setNegativeButton(getString(R.string.undo_changes)) { _: DialogInterface, _: Int -> + val apiCaller = ApiCaller() + apiCaller.resetResolution(0) + } + .create() + return dialog + } +} \ No newline at end of file diff --git a/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeFragment.kt b/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeFragment.kt index 5ac555c..e2f33a9 100644 --- a/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeFragment.kt +++ b/app/src/main/java/top/jiecs/screener/ui/displaymode/DisplayModeFragment.kt @@ -1,12 +1,20 @@ package top.jiecs.screener.ui.displaymode +import android.annotation.SuppressLint import android.os.Bundle import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.PopupMenu +import androidx.core.view.MenuHost +import androidx.core.view.MenuProvider +import androidx.lifecycle.Lifecycle import top.jiecs.screener.R /** @@ -26,6 +34,31 @@ class DisplayModeFragment : Fragment() { adapter = DisplayModeRecyclerViewAdapter(DisplayModeContent.DISPLAY_MODES) } } + + // The usage of an interface lets you inject your own implementation + val menuHost: MenuHost = requireActivity() + + // Add menu items without using the Fragment Menu APIs + // Note how we can tie the MenuProvider to the viewLifecycleOwner + // and an optional Lifecycle.State (here, RESUMED) to indicate when + // the menu should be visible + menuHost.addMenuProvider(object : MenuProvider { + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { + // Add menu items here + menuInflater.inflate(R.menu.display_mode_action_menu, menu) + } + + override fun onMenuItemSelected(menuItem: MenuItem): Boolean { + // Handle the menu selection + return when (menuItem.itemId) { + R.id.new_display_mode -> { + // dialog to add a new display mode + true + } + else -> false + } + } + }, viewLifecycleOwner, Lifecycle.State.RESUMED) return view } } \ No newline at end of file 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 4852a82..f8a8b8b 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 @@ -42,7 +42,7 @@ class ResolutionFragment : Fragment() { private val userId: Int get() { val usersList = resolutionViewModel.usersList.value ?: return 0 - val checkedChipId = binding.chipGroup.checkedChipId + val checkedChipId = binding.resolution_editor.chipGroup.checkedChipId val user = usersList.getOrNull(checkedChipId - 1) ?: return 0 return user["id"] as Int diff --git a/app/src/main/java/top/jiecs/screener/ui/settings/SettingsFragment.kt b/app/src/main/java/top/jiecs/screener/ui/settings/SettingsFragment.kt index 26f9262..6ac49d5 100644 --- a/app/src/main/java/top/jiecs/screener/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/top/jiecs/screener/ui/settings/SettingsFragment.kt @@ -1,6 +1,8 @@ package top.jiecs.screener.ui.settings import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater import androidx.preference.PreferenceFragmentCompat import top.jiecs.screener.R diff --git a/app/src/main/res/drawable/baseline_add_24.xml b/app/src/main/res/drawable/baseline_add_24.xml new file mode 100644 index 0000000..89633bb --- /dev/null +++ b/app/src/main/res/drawable/baseline_add_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_display_mode_item.xml b/app/src/main/res/layout/fragment_display_mode_item.xml index c0c9512..18c4b92 100644 --- a/app/src/main/res/layout/fragment_display_mode_item.xml +++ b/app/src/main/res/layout/fragment_display_mode_item.xml @@ -1,8 +1,9 @@ - - \ No newline at end of file + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="3200x1440 @ 520dpi" /> + +