Skip to content

Commit

Permalink
fix: incorrect screen metrics (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Apr 14, 2024
1 parent e663031 commit 3763a07
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ object MainPreferences {
private const val STORAGE_URI = "storageUri"
private const val NOMEDIA_DIALOG = "nomediaDialog"
private const val BLUR = "blur"
private const val IS_BIOMETRIC = "is_biometric"
private const val REMEMBER_SCROLL_POSITION = "remember_scroll_position"
private const val SCROLL_POSITION = "scrollPosition"
private const val CROP_WALLPAPER = "crop_wallpaper"
Expand All @@ -16,6 +15,7 @@ object MainPreferences {
private const val WALLPAPER_SET_FOR = "auto_wallpaper_set_for"
private const val REDUCE_MOTION = "reduce_motion"

const val IS_BIOMETRIC = "is_biometric"
const val SORT = "sort"
const val ORDER = "order"
const val NAME = "is_name"
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/app/simple/peri/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import app.simple.peri.utils.ConditionUtils.isNotNull
import app.simple.peri.utils.FileUtils.toUri
import app.simple.peri.utils.PermissionUtils.isBatteryOptimizationDisabled
import app.simple.peri.utils.PermissionUtils.requestIgnoreBatteryOptimizations
import app.simple.peri.utils.ScreenUtils
import app.simple.peri.utils.ScreenUtils.isLandscape
import app.simple.peri.utils.WallpaperSort
import app.simple.peri.viewmodels.WallpaperViewModel
Expand Down Expand Up @@ -87,8 +88,11 @@ class MainScreen : Fragment(), SharedPreferences.OnSharedPreferenceChangeListene
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward = */ false)
binding?.fab?.transitionName = requireArguments().getString(BundleConstants.FAB_TRANSITION)

displayWidth = requireContext().resources.displayMetrics.widthPixels
displayHeight = requireContext().resources.displayMetrics.heightPixels
with(ScreenUtils.getScreenSize(requireContext())) {
displayWidth = width
displayHeight = height
}

fixNavigationBarOverlap()
itemTouchHelper = ItemTouchHelper(simpleItemTouchCallback)

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/app/simple/peri/ui/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import app.simple.peri.utils.FileUtils.listCompleteFiles
import app.simple.peri.utils.FileUtils.toSize
import app.simple.peri.utils.PermissionUtils.isBatteryOptimizationDisabled
import app.simple.peri.utils.PermissionUtils.requestIgnoreBatteryOptimizations
import app.simple.peri.utils.ScreenUtils
import app.simple.peri.utils.ViewUtils.firstChild
import app.simple.peri.utils.ViewUtils.setPaddingBottom
import app.simple.peri.utils.ViewUtils.setPaddingTop
Expand Down Expand Up @@ -189,8 +190,9 @@ class Preferences : PreferenceFragmentCompat(), SharedPreferences.OnSharedPrefer
it.length()
}

val displayWidth = requireContext().resources.displayMetrics.widthPixels
val displayHeight = requireContext().resources.displayMetrics.heightPixels
val displayWidth = ScreenUtils.getScreenSize(requireContext()).width
val displayHeight = ScreenUtils.getScreenSize(requireContext()).height
Log.d("Preferences", "Display width: $displayWidth, Display height: $displayHeight")
val wallpaperDatabase = WallpaperDatabase.getInstance(requireContext())?.wallpaperDao()

val normalWallpapers = wallpaperDatabase?.getWallpapersByWidthAndHeight(displayWidth, displayHeight)?.size
Expand Down Expand Up @@ -232,7 +234,7 @@ class Preferences : PreferenceFragmentCompat(), SharedPreferences.OnSharedPrefer

override fun onSharedPreferenceChanged(p0: SharedPreferences?, p1: String?) {
when (p1) {
"is_biometric" -> {
MainPreferences.IS_BIOMETRIC -> {
if (p0?.getBoolean(p1, false) == true) {
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(getString(R.string.app_name))
Expand Down

0 comments on commit 3763a07

Please sign in to comment.