Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
WIP: add resolution_editor fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
jiesou committed Feb 17, 2024
1 parent 465deb8 commit 77a0904
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 120 deletions.
68 changes: 68 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/java/top/jiecs/screener/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_add_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
24 changes: 20 additions & 4 deletions app/src/main/res/layout/fragment_display_mode_item.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal">

<TextView
Expand All @@ -11,5 +12,20 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem"
tools:text="3200x1440 @ 520"/>
</LinearLayout>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="3200x1440 @ 520dpi" />

<Button
android:id="@+id/edit_button"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit"
android:layout_marginStart="@dimen/text_margin"
app:layout_constraintBottom_toBottomOf="@+id/display_mode_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/display_mode_text"
app:layout_constraintTop_toTopOf="@+id/display_mode_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 77a0904

Please sign in to comment.