Skip to content

Commit

Permalink
settings screen improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
queuejw committed Aug 10, 2024
1 parent 4e5eb23 commit eb18128
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 44 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/ru/dimon6018/metrolauncher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -217,9 +218,11 @@ class Main : AppCompatActivity() {
override fun onResume() {
if (PREFS!!.isPrefsChanged) {
PREFS!!.isPrefsChanged = false
Log.d("Main", "Recreate")
recreate()
}
super.onResume()
Log.d("Main", "RESUME")
}

override fun onDestroy() {
Expand All @@ -233,7 +236,6 @@ class Main : AppCompatActivity() {
"ru.dimon6018.metrolauncher" -> {
startActivity(Intent(this@Main, SettingsActivity::class.java))
}

else -> {
startActivity(
Intent(this@Main.packageManager.getLaunchIntentForPackage(app)).addFlags(
Expand All @@ -249,8 +251,11 @@ class Main : AppCompatActivity() {
}

private suspend fun setMainViewModel() {
val isCustomIconsInstalled = PREFS!!.iconPackPackage != "null"
mainViewModel.setAppList(sortApps(setUpApps(this.packageManager, this)))
regenerateIcons()
}
private suspend fun regenerateIcons() {
val isCustomIconsInstalled = PREFS!!.iconPackPackage != "null"
var diskCache = initDiskCache(this)
if (PREFS!!.iconPackChanged) {
PREFS!!.iconPackChanged = false
Expand Down Expand Up @@ -290,7 +295,6 @@ class Main : AppCompatActivity() {
}
diskCache?.let { closeDiskCache(it) }
}

fun generateIcon(
appPackage: String,
isCustomIconsInstalled: Boolean
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/java/ru/dimon6018/metrolauncher/content/NewStart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ class NewStart: Fragment(), OnStartDragListener {
val view = binding.root
mainViewModel = ViewModelProvider(requireActivity())[MainViewModel::class.java]
binding.startFrame.setOnClickListener {
if(mAdapter != null) {
if (mAdapter!!.isEditMode) {
mAdapter!!.disableEditMode()
mAdapter?.apply {
if(isEditMode) {
disableEditMode()
}
}
}
Expand Down Expand Up @@ -141,8 +141,7 @@ class NewStart: Fragment(), OnStartDragListener {
}
private fun setupAdapter() {
mAdapter = NewStartAdapter(requireContext(), tiles!!)
val callback: ItemTouchHelper.Callback = ItemTouchCallback(mAdapter!!)
mItemTouchHelper = ItemTouchHelper(callback)
mItemTouchHelper = ItemTouchHelper(ItemTouchCallback(mAdapter!!))
}

private fun configureRecyclerView() {
Expand Down Expand Up @@ -189,9 +188,9 @@ class NewStart: Fragment(), OnStartDragListener {
)
}
}
mSpannedLayoutManager!!.itemOrderIsStable = true
mSpannedLayoutManager!!.spanSizeLookup =
SpannedGridLayoutManager.SpanSizeLookup { position ->
mSpannedLayoutManager?.apply {
itemOrderIsStable = true
spanSizeLookup = SpannedGridLayoutManager.SpanSizeLookup { position ->
when (tiles!![position].tileSize) {
"small" -> {
SpanSize(1, 1)
Expand All @@ -210,8 +209,8 @@ class NewStart: Fragment(), OnStartDragListener {
}
}
}
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
isLandscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.WindowCompat
Expand Down Expand Up @@ -52,18 +51,20 @@ class SettingsActivity : AppCompatActivity() {
private var job: Job? = null
private val viewList: List<Pair<View, Long>> by lazy {
listOf(
binding.settingsInclude.themeSetting to 200,
binding.settingsInclude.allAppsSetting to 210,
binding.settingsInclude.tilesSetting to 220,
binding.settingsInclude.iconsSetting to 225,
binding.settingsInclude.animSetting to 230,
binding.settingsInclude.feedbackSetting to 235,
binding.settingsInclude.weatherSetting to 240,
binding.settingsInclude.updatesSetting to 245,
binding.settingsInclude.navbarSetting to 250,
binding.settingsInclude.aboutSetting to 255,
binding.settingsInclude.leaks to 260,
binding.settingsInclude.expSetting to 265
binding.settings to 200,
binding.settingsLabel to 250,
binding.settingsInclude.themeSetting to 300,
binding.settingsInclude.allAppsSetting to 310,
binding.settingsInclude.tilesSetting to 320,
binding.settingsInclude.iconsSetting to 330,
binding.settingsInclude.animSetting to 340,
binding.settingsInclude.feedbackSetting to 350,
binding.settingsInclude.weatherSetting to 360,
binding.settingsInclude.updatesSetting to 370,
binding.settingsInclude.navbarSetting to 380,
binding.settingsInclude.aboutSetting to 390,
binding.settingsInclude.leaks to 400,
binding.settingsInclude.expSetting to 410
)
}

Expand All @@ -74,7 +75,7 @@ class SettingsActivity : AppCompatActivity() {
binding = LauncherSettingsMainBinding.inflate(layoutInflater)
setContentView(binding.root)
WindowCompat.setDecorFitsSystemWindows(window, false)
confAnim()
confTouchAnim()
setOnClickers()
applyWindowInsets(binding.root)
prepareMessage()
Expand Down Expand Up @@ -173,7 +174,6 @@ class SettingsActivity : AppCompatActivity() {
viewList.forEach { (view, duration) ->
setupAnimForViews(view, duration)
}
setupAnimForViews(binding.root, 180)
}
private fun setupAnimForViews(view: View, dur: Long) {
if (!PREFS!!.isTransitionAnimEnabled) {
Expand All @@ -182,14 +182,14 @@ class SettingsActivity : AppCompatActivity() {
val animatorSet = AnimatorSet().apply {
playTogether(
ObjectAnimator.ofFloat(view, "alpha", if (isEnter) 1f else 0f, if (isEnter) 0f else 1f),
ObjectAnimator.ofFloat(view, "translationX", if (isEnter) 0f else -500f, if (isEnter) -500f else 0f),
ObjectAnimator.ofFloat(view, "translationX", if (isEnter) 0f else -200f, if (isEnter) -200f else 0f),
ObjectAnimator.ofFloat(view, "rotationY", if (isEnter) 0f else -90f, if (isEnter) -90f else 0f)
)
duration = dur
}
animatorSet.start()
}
private fun confAnim() {
private fun confTouchAnim() {
setViewInteractAnimation(binding.settingsInclude.themeSetting)
setViewInteractAnimation(binding.settingsInclude.allAppsSetting)
setViewInteractAnimation(binding.settingsInclude.tilesSetting)
Expand All @@ -208,14 +208,13 @@ class SettingsActivity : AppCompatActivity() {
setupAnimations()
isEnter = false
CoroutineScope(Dispatchers.Main).launch {
delay(500)
delay(350)
viewList.forEach { (view, _) ->
view.alpha = 1f
}
binding.root.alpha = 1f
cancel()
}
delay(150)
delay(350)
} else {
isEnter = false
}
Expand All @@ -225,7 +224,6 @@ class SettingsActivity : AppCompatActivity() {
viewList.forEach { (view, _) ->
hideAnim(view)
}
hideAnim(binding.root)
}
}
private fun hideAnim(view: View?) {
Expand Down Expand Up @@ -273,15 +271,42 @@ class SettingsActivity : AppCompatActivity() {
}.getOrElse { getString(R.string.iconPackNotSelectedSub) }

if(PREFS!!.isPrefsChanged) {
PREFS!!.isPrefsChanged = false
Toast.makeText(this, getString(R.string.restart_required), Toast.LENGTH_SHORT).show()
exitProcess(0)
job?.cancel()
restartDialog()
} else {
lifecycleScope.launch {
startAnim()
startAnimWithLifecycle()
}
}

private fun restartDialog() {
WPDialog(this).apply {
setTopDialog(true)
setTitle(getString(R.string.settings_app_title))
setMessage(getString(R.string.restart_required))
setPositiveButton(getString(R.string.restart)) {
dismiss()
restartApp()
}
setNegativeButton(getString(R.string.later)) {
dismiss()
startAnimWithLifecycle()
}
setDismissListener {
startAnimWithLifecycle()
}
show()
}
}
private fun startAnimWithLifecycle() {
lifecycleScope.launch {
startAnim()
}
}
private fun restartApp() {
PREFS!!.isPrefsChanged = false
exitProcess(0)
}

override fun onPause() {
super.onPause()
hideViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.dimon6018.metrolauncher.helpers.ui

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.Gravity
import android.view.View
import android.view.WindowManager
Expand Down Expand Up @@ -32,6 +33,7 @@ class WPDialog(private val mContext: Context) {
private var okButtonListener: View.OnClickListener? = null
private var cancelButtonListener: View.OnClickListener? = null
private var neutralListener: View.OnClickListener? = null
private var dismissListener: DialogInterface.OnDismissListener? = null
//Show方法
fun show(): WPDialog {
if(PREFS!!.isLightThemeUsed) {
Expand Down Expand Up @@ -157,6 +159,9 @@ class WPDialog(private val mContext: Context) {
} else {
wpNeutral.setOnClickListener(OnDialogButtonClickListener())
}
if(dismissListener != null) {
setOnDismissListener(dismissListener)
}
}
}
}
Expand All @@ -172,7 +177,10 @@ class WPDialog(private val mContext: Context) {
mView = view
return this
} **/

fun setDismissListener(listener: DialogInterface.OnDismissListener?): WPDialog {
dismissListener = listener
return this
}
fun setPositiveButton(text: String, listener: View.OnClickListener?): WPDialog {
okText = text
okButtonListener = listener
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/launcher_settings_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
android:backgroundTint="?android:attr/colorBackground">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:fontFamily="@font/manrope_bold"
android:text="@string/settings"
android:textColor="@color/textColor"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/textColor"/>
app:fontFamily="@font/manrope_bold" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/settings_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
android:ellipsize="none"
android:singleLine="true"
android:textColor="@color/textColor"
android:text="@string/launcher"
android:textColor="@color/textColor"
android:textSize="52sp" />

</com.google.android.material.appbar.AppBarLayout>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<string name="dark">тёмный</string>
<string name="automatic_repair">Автоматическое восстановление</string>
<string name="not_start_correctly">Лаунчер запущен некорректно</string>
<string name="auto_repair_tip">Нажмите \'Перезагрузить\', чтобы перезапустить лаунчер. Иногда это решает проблему. Также можно нажать \'Дополнительные параметры\' и попробовать другие варианты восстановления лаунчера.</string>
<string name="restart">Перезагрузить</string>
<string name="auto_repair_tip">Нажмите \'Перезапустить\', чтобы перезапустить лаунчер. Иногда это решает проблему. Также можно нажать \'Дополнительные параметры\' и попробовать другие варианты восстановления лаунчера.</string>
<string name="restart">Перезапустить</string>
<string name="advanced_options">Дополнительные параметы</string>
<string name="feedback_limit_0">только последнюю</string>
<string name="feedback_limit_1">последние 5</string>
Expand Down Expand Up @@ -231,4 +231,5 @@
<string name="support">Поддержать</string>
<string name="tipSettingsUpdates">На этом экране вы можете проверить наличие обновлений для лаунчера, чтобы получить исправления и новые функции.</string>
<string name="oobe_apps_warn">Вы не выбрали никаких приложений. Хотите продолжить?</string>
<string name="later">Позже</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@
<string name="support">Support</string>
<string name="tipSettingsUpdates">From this screen, you can check for updates for MPL to get fixes and new features.</string>
<string name="oobe_apps_warn">You have not selected any applications. Do you want to continue?</string>
<string name="later">Later</string>
</resources>

0 comments on commit eb18128

Please sign in to comment.