From ddb1ecaa996cd95a472a0905456e3ab35acd91b5 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Mon, 9 Dec 2019 17:24:41 +0100 Subject: [PATCH] [UI/Settings] Add setting for showing drawer on back pressed. --- .../szczodrzynski/edziennik/MainActivity.kt | 27 +++---------------- .../api/v2/events/task/ServerSyncTask.kt | 2 +- .../edziennik/config/ConfigUI.kt | 7 ++++- .../modules/settings/SettingsNewFragment.java | 19 +++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index ebbc11fe..c95d08b7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -1063,30 +1063,11 @@ class MainActivity : AppCompatActivity() { private var targetHomeId: Int = -1 override fun onBackPressed() { if (!b.navView.onBackPressed()) { - - navigateUp() - - /*val currentDestinationId = navController.currentDestination?.id - - if (if (targetHomeId != -1 && targetPopToHomeList.contains(navController.currentDestination?.id)) { - if (!navController.popBackStack(targetHomeId, false)) { - navController.navigateUp() - } - true - } else { - navController.navigateUp() - }) { - val currentId = navController.currentDestination?.id ?: -1 - val drawerSelection = navTargetList - .singleOrNull { - it.navGraphId == currentId - }?.also { - navView.toolbar.setTitle(it.title ?: it.name) - }?.id ?: -1 - drawer.setSelection(drawerSelection, false) + if (App.getConfig().ui.openDrawerOnBackPressed) { + b.navView.drawer.toggle() } else { - super.onBackPressed() - }*/ + navigateUp() + } } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/ServerSyncTask.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/ServerSyncTask.kt index 276971b6..9259042e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/ServerSyncTask.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/events/task/ServerSyncTask.kt @@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull class ServerSyncTask : IApiTask(-1) { override fun prepare(app: App) { - taskName = app.getString(R.string.edziennik_notification_api_notify_title) // TODO text + taskName = app.getString(R.string.edziennik_szkolny_api_sync_title) // TODO text } override fun cancel() { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigUI.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigUI.kt index 58b1e80b..54ede475 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigUI.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigUI.kt @@ -40,6 +40,11 @@ class ConfigUI(private val config: Config) { get() { mMiniMenuButtons = mMiniMenuButtons ?: config.values.getIntList("miniMenuButtons", listOf()); return mMiniMenuButtons ?: listOf() } set(value) { config.set("miniMenuButtons", value); mMiniMenuButtons = value } + private var mOpenDrawerOnBackPressed: Boolean? = null + var openDrawerOnBackPressed: Boolean + get() { mOpenDrawerOnBackPressed = mOpenDrawerOnBackPressed ?: config.values.get("openDrawerOnBackPressed", false); return mOpenDrawerOnBackPressed ?: false } + set(value) { config.set("openDrawerOnBackPressed", value); mOpenDrawerOnBackPressed = value } + private var mAgendaViewType: Int? = null var agendaViewType: Int get() { mAgendaViewType = mAgendaViewType ?: config.values.get("agendaViewType", 0); return mAgendaViewType ?: 0 } @@ -49,4 +54,4 @@ class ConfigUI(private val config: Config) { var homeCards: List get() { mHomeCards = mHomeCards ?: config.values.get("homeCards", listOf(), HomeCardModel::class.java); return mHomeCards ?: listOf() } set(value) { config.set("homeCards", value); mHomeCards = value } -} \ No newline at end of file +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index d43f7cae..6ea1212f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -461,6 +461,21 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) ); + items.add( + new MaterialAboutSwitchItem( + getString(R.string.settings_theme_open_drawer_on_back_pressed_text), + null, + new IconicsDrawable(activity) + .icon(CommunityMaterial.Icon2.cmd_menu_open) + .size(IconicsSize.dp(iconSizeDp)) + .color(IconicsColor.colorInt(iconColor)) + ) + .setChecked(app.config.getUi().getOpenDrawerOnBackPressed()) + .setOnChangeAction((isChecked, tag) -> { + app.config.getUi().setOpenDrawerOnBackPressed(isChecked); + return true; + }) + ); } return items; } @@ -1019,9 +1034,9 @@ public class SettingsNewFragment extends MaterialAboutFragment { .size(IconicsSize.dp(iconSizeDp)) .color(IconicsColor.colorInt(iconColor)) ) - .setChecked(!app.config.getFor(app.profileId).getGrades().getCountZeroToAvg()) + .setChecked(!app.config.getFor(App.profileId).getGrades().getCountZeroToAvg()) .setOnChangeAction((isChecked, tag) -> { - app.config.getFor(app.profileId).getGrades().setCountZeroToAvg(!isChecked); + app.config.getFor(App.profileId).getGrades().setCountZeroToAvg(!isChecked); app.saveConfig("dontCountZeroToAverage"); return true; }) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 956cfa57..dfe8e6e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1059,4 +1059,6 @@ z %s %s%s Pobieranie ocen z zachowania... + Synchronizowanie udostępnionych wydarzeń... + Otwieraj menu przyciskiem wstecz