Skip to content

Commit

Permalink
add setting to show nav bar at the bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Jul 14, 2024
1 parent 77e76ef commit 04c3eaa
Show file tree
Hide file tree
Showing 35 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class SettingsBlock {
DisplayEnablePomodoroMode,
DisplayPomodoroModeActivities,
DisplayGoalsOnSeparateTabs,
DisplayNavBarAtTheBottom,
DisplayKeepScreenOn,
DisplayWidgetBackground,
DisplayMilitaryFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ class PrefsRepoImpl @Inject constructor(
KEY_DEFAULT_TYPES_HIDDEN, false,
)

override var isNavBarAtTheBottom: Boolean by prefs.delegate(
KEY_IS_NAV_BAR_AT_THE_BOTTOM, false,
)

override fun setWidget(widgetId: Int, recordType: Long) {
val key = KEY_WIDGET + widgetId
logPrefsDataAccess("set $key")
Expand Down Expand Up @@ -556,6 +560,7 @@ class PrefsRepoImpl @Inject constructor(
private const val KEY_REPEAT_BUTTON_TYPE = "repeatButtonType"
private const val KEY_WIDGET_TRANSPARENCY_PERCENT = "widgetTransparencyPercent"
private const val KEY_DEFAULT_TYPES_HIDDEN = "defaultTypesHidden"
private const val KEY_IS_NAV_BAR_AT_THE_BOTTOM = "isNavBarAtTheBottom"
private const val KEY_WIDGET = "widget_"
private const val KEY_STATISTICS_WIDGET_FILTERED_TYPES = "statistics_widget_filtered_types_"
private const val KEY_STATISTICS_WIDGET_FILTERED_CATEGORIES = "statistics_widget_filtered_categories_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,14 @@ class PrefsInteractor @Inject constructor(
prefsRepo.defaultTypesHidden = value
}

suspend fun getIsNavBarAtTheBottom(): Boolean = withContext(Dispatchers.IO) {
prefsRepo.isNavBarAtTheBottom
}

suspend fun setIsNavBarAtTheBottom(value: Boolean) = withContext(Dispatchers.IO) {
prefsRepo.isNavBarAtTheBottom = value
}

suspend fun clear() = withContext(Dispatchers.IO) {
prefsRepo.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ interface PrefsRepo {

var defaultTypesHidden: Boolean

var isNavBarAtTheBottom: Boolean

fun setWidget(widgetId: Int, recordType: Long)

fun getWidget(widgetId: Int): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.annotation.AttrRes
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.fragment.app.activityViewModels
Expand All @@ -17,11 +18,11 @@ import com.example.util.simpletimetracker.core.sharedViewModel.MainTabsViewModel
import com.example.util.simpletimetracker.core.utils.SHORTCUT_NAVIGATION_KEY
import com.example.util.simpletimetracker.core.view.SafeFragmentStateAdapter
import com.example.util.simpletimetracker.domain.extension.orZero
import com.example.util.simpletimetracker.feature_views.extension.getThemedAttr
import com.example.util.simpletimetracker.feature_main.R
import com.example.util.simpletimetracker.feature_main.adapter.MainContentAdapter
import com.example.util.simpletimetracker.feature_main.provider.MainTabsProvider
import com.example.util.simpletimetracker.feature_main.viewModel.MainViewModel
import com.example.util.simpletimetracker.feature_views.extension.getThemedAttr
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -61,6 +62,7 @@ class MainFragment : BaseFragment<Binding>() {

override fun initViewModel() {
viewModel.initialize
viewModel.isNavBatAtTheBottom.observe(::updateNavBarPosition)
}

private fun setupPager() = with(binding) {
Expand Down Expand Up @@ -107,6 +109,29 @@ class MainFragment : BaseFragment<Binding>() {
mainPager.setCurrentItem(mainPagePosition, false)
}

private fun updateNavBarPosition(isAtTheBottom: Boolean) = with(binding) {
val set = ConstraintSet()
set.clone(binding.containerMain)
if (isAtTheBottom) {
set.clear(R.id.mainTabs, ConstraintSet.TOP)
set.connect(R.id.mainTabs, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
set.connect(R.id.mainPager, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)
set.connect(R.id.mainPager, ConstraintSet.BOTTOM, R.id.mainTabs, ConstraintSet.TOP)
} else {
set.clear(R.id.mainTabs, ConstraintSet.BOTTOM)
set.connect(R.id.mainTabs, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)
set.connect(R.id.mainPager, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
set.connect(R.id.mainPager, ConstraintSet.TOP, R.id.mainTabs, ConstraintSet.BOTTOM)
}
set.applyTo(binding.containerMain)

if (isAtTheBottom) {
TabLayout.INDICATOR_GRAVITY_TOP
} else {
TabLayout.INDICATOR_GRAVITY_BOTTOM
}.let(mainTabs::setSelectedTabIndicatorGravity)
}

private fun getOnBackPressedCallback(): OnBackPressedCallback {
return object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.util.simpletimetracker.feature_main.viewModel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import com.example.util.simpletimetracker.core.base.BaseViewModel
import com.example.util.simpletimetracker.core.extension.lazySuspend
import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.WearInteractor
import com.example.util.simpletimetracker.domain.interactor.WidgetInteractor
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -14,9 +17,11 @@ class MainViewModel @Inject constructor(
private val notificationTypeInteractor: NotificationTypeInteractor,
private val widgetInteractor: WidgetInteractor,
private val wearInteractor: WearInteractor,
) : ViewModel() {
private val prefsInteractor: PrefsInteractor,
) : BaseViewModel() {

val initialize: Unit by lazy { syncState() }
val isNavBatAtTheBottom: LiveData<Boolean> by lazySuspend { loadIsNavBatAtTheBottom() }

private fun syncState() {
viewModelScope.launch {
Expand All @@ -25,4 +30,8 @@ class MainViewModel @Inject constructor(
wearInteractor.update()
}
}

private suspend fun loadIsNavBatAtTheBottom(): Boolean {
return prefsInteractor.getIsNavBarAtTheBottom()
}
}
3 changes: 3 additions & 0 deletions features/feature_main/src/main/res/layout/main_fragment.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/containerMain"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -12,10 +13,12 @@
app:tabIndicatorColor="?appTabSelectedColor"
app:tabRippleColor="@color/tab_ripple" />

<!-- Small margin is added to prevent shared transition going under new screen -->
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/mainPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="0.1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/mainTabs" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ class SettingsDisplayViewDataInteractor @Inject constructor(
bottomSpaceIsVisible = true,
dividerIsVisible = true,
)
result += SettingsCheckboxViewData(
block = SettingsBlock.DisplayNavBarAtTheBottom,
title = resourceRepo.getString(R.string.settings_show_nav_bar_at_the_bottom),
subtitle = "",
isChecked = prefsInteractor.getIsNavBarAtTheBottom(),
bottomSpaceIsVisible = true,
dividerIsVisible = true,
)
result += SettingsCheckboxViewData(
block = SettingsBlock.DisplayKeepScreenOn,
title = resourceRepo.getString(R.string.settings_keep_screen_on),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class SettingsViewModel @Inject constructor(
displayDelegate.onAllowMultipleActivityFiltersClicked()
SettingsBlock.DisplayGoalsOnSeparateTabs ->
displayDelegate.onShowGoalsSeparatelyClicked()
SettingsBlock.DisplayNavBarAtTheBottom ->
displayDelegate.onShowNavBarAtTheBottomClicked()
SettingsBlock.DisplayKeepScreenOn ->
displayDelegate.onKeepScreenOnClicked()
SettingsBlock.DisplayMilitaryFormat ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ class SettingsDisplayViewModelDelegate @Inject constructor(
}
}

fun onShowNavBarAtTheBottomClicked() {
delegateScope.launch {
val newValue = !prefsInteractor.getIsNavBarAtTheBottom()
prefsInteractor.setIsNavBarAtTheBottom(newValue)
parent?.updateContent()
router.restartApp()
}
}

fun onUseMilitaryTimeClicked() {
delegateScope.launch {
val newValue = !prefsInteractor.getUseMilitaryTimeFormat()
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">في حالة التعطيل، سيؤدي تحديد عامل التصفية إلى تعطيل عوامل تصفية الأنشطة الأخرى.</string>
<string name="settings_enable_pomodoro_mode">إظهار زر بومودورو على الشاشة الرئيسية</string>
<string name="settings_show_goals_separately">إظهار الأهداف في علامة تبويب منفصلة</string>
<string name="settings_show_nav_bar_at_the_bottom">إظهار شريط التنقل في الأسفل</string>
<string name="settings_allow_multitasking">السماح بتعدد المهام</string>
<string name="settings_allow_multitasking_hint">ًإذا كان غير مفعل، فبدء تشغيل مهمة جديدة سيوقف الأنشطة الأخرى تلقائيا.</string>
<string name="settings_show_notifications">إظهار إشعارات المؤقت</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Si està desactivat, seleccionar un filtre desactivarà altres filtres d\'activitat.</string>
<string name="settings_enable_pomodoro_mode">Mostra el botó Pomodoro a la pantalla principal</string>
<string name="settings_show_goals_separately">Mostra els objectius en una pestanya separada</string>
<string name="settings_show_nav_bar_at_the_bottom">Mostra la barra de navegació a la part inferior</string>
<string name="settings_allow_multitasking">Permet la multitasca</string>
<string name="settings_allow_multitasking_hint">Si és desactivat, en començar un nou temporitzador s\'aturaran automàticament les altres activitats.</string>
<string name="settings_show_notifications">Mostra notificacions del temporitzador</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Wenn die Option deaktiviert ist, werden durch die Auswahl eines Filters andere Aktivitätsfilter deaktiviert.</string>
<string name="settings_enable_pomodoro_mode">Pomodoro-Schaltfläche auf dem Hauptbildschirm anzeigen</string>
<string name="settings_show_goals_separately">Ziele auf einer separaten Registerkarte anzeigen</string>
<string name="settings_show_nav_bar_at_the_bottom">Navigationsleiste unten anzeigen</string>
<string name="settings_allow_multitasking">Multitasking erlauben</string>
<string name="settings_allow_multitasking_hint">Wenn diese Funktion deaktiviert ist, werden beim Starten eines neuen Timers andere Aktivitäten automatisch gestoppt.</string>
<string name="settings_show_notifications">Timer-Benachrichtigungen anzeigen</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Si está deshabilitado, al seleccionar un filtro se deshabilitarán otros filtros de actividad.</string>
<string name="settings_enable_pomodoro_mode">Mostrar el botón Pomodoro en la pantalla principal</string>
<string name="settings_show_goals_separately">Mostrar objetivos en una pestaña separada</string>
<string name="settings_show_nav_bar_at_the_bottom">Mostrar barra de navegación en la parte inferior</string>
<string name="settings_allow_multitasking">Permitir el registro multitarea</string>
<string name="settings_allow_multitasking_hint">Si está deshabilitado, al iniciar un nuevo temporizador se detendrá automáticamente el de las otras actividades.</string>
<string name="settings_show_notifications">Mostrar notificaciones del temporizador</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">اگر غیرفعال باشد، انتخاب فیلتر، سایر فیلترهای فعالیت را غیرفعال می کند.</string>
<string name="settings_enable_pomodoro_mode">نمایش دکمه Pomodoro در صفحه اصلی</string>
<string name="settings_show_goals_separately">نمایش اهداف در یک برگه جداگانه</string>
<string name="settings_show_nav_bar_at_the_bottom">نمایش نوار پیمایش در پایین</string>
<string name="settings_allow_multitasking">انجام دادن همزمان فعالیت ها</string>
<string name="settings_allow_multitasking_hint">اگر غیر فعال باشد شروع تایمر های جدید فعالیت های دیگر را متوقف می کند</string>
<string name="settings_show_notifications">تایمر را در اعلان ها نمایش بده</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">S\'il est désactivé, la sélection d\'un filtre désactivera les autres filtres d\'activité.</string>
<string name="settings_enable_pomodoro_mode">Afficher le bouton Pomodoro sur l\'écran principal</string>
<string name="settings_show_goals_separately">Afficher les objectifs dans un onglet séparé</string>
<string name="settings_show_nav_bar_at_the_bottom">Afficher la barre de navigation en bas</string>
<string name="settings_allow_multitasking">Autoriser le multitâche</string>
<string name="settings_allow_multitasking_hint">Si désactivé, le démarrage d\'une nouvelle activité arrêtera automatiquement les autres activités en cours.</string>
<string name="settings_show_notifications">Afficher les notifications d\'activité</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">यदि अक्षम किया गया है, तो फ़िल्टर का चयन करने से अन्य गतिविधि फ़िल्टर अक्षम हो जाएंगे।</string>
<string name="settings_enable_pomodoro_mode">मुख्य स्क्रीन पर पोमोडोरो बटन दिखाएँ</string>
<string name="settings_show_goals_separately">एक अलग टैब पर लक्ष्य दिखाएँ</string>
<string name="settings_show_nav_bar_at_the_bottom">सबसे नीचे नेविगेशन बार दिखाएँ</string>
<string name="settings_allow_multitasking">मल्टीटास्किंग की अनुमति दें</string>
<string name="settings_allow_multitasking_hint">यदि बंद हे तो नया टाइमर शुरू होने पर यह अन्य स्वचालित गतिविधियों को रोक देगा।</string>
<string name="settings_show_notifications">टाइमर नोटिफिकेशन दिखाएं</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Jika dinonaktifkan, memilih filter akan menonaktifkan filter aktivitas lainnya.</string>
<string name="settings_enable_pomodoro_mode">Tampilkan tombol Pomodoro di layar utama</string>
<string name="settings_show_goals_separately">Tampilkan sasaran di tab terpisah</string>
<string name="settings_show_nav_bar_at_the_bottom">Tampilkan bilah navigasi di bagian bawah</string>
<string name="settings_allow_multitasking">Izinkan tugas ganda</string>
<string name="settings_allow_multitasking_hint">Jika dinonaktifkan memulai pewaktu baru akan secara otomatis menghentikan kegiatan-kegiatan lain.</string>
<string name="settings_show_notifications">Tampilkan notifikasi pewaktu</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Se disabilitato, la selezione di un filtro disabiliterà gli altri filtri di attività.</string>
<string name="settings_enable_pomodoro_mode">Mostra il pulsante Pomodoro sulla schermata principale</string>
<string name="settings_show_goals_separately">Mostra gli obiettivi in una scheda separata</string>
<string name="settings_show_nav_bar_at_the_bottom">Mostra la barra di navigazione in basso</string>
<string name="settings_allow_multitasking">Abilita multitasking</string>
<string name="settings_allow_multitasking_hint">Se disabilitato, avviare un nuovo timer fermerà automaticamente le altre attività.</string>
<string name="settings_show_notifications">Mostra le notifiche relative al timer.</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">無効にした場合、フィルターを選択すると他のアクティビティ フィルターが無効になります。</string>
<string name="settings_enable_pomodoro_mode">メイン画面にポモドーロボタンを表示</string>
<string name="settings_show_goals_separately">別のタブに目標を表示する</string>
<string name="settings_show_nav_bar_at_the_bottom">下部にナビゲーションバーを表示</string>
<string name="settings_allow_multitasking">マルチタスクを可能にする</string>
<string name="settings_allow_multitasking_hint">無効の場合、新しいタイマーを開始すると、他のアクティビティが自動的に停止します。</string>
<string name="settings_show_notifications">タイマーの通知を表示する</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">비활성화된 경우 필터를 선택하면 다른 활동 필터가 비활성화됩니다.</string>
<string name="settings_enable_pomodoro_mode">메인 화면에 뽀모도로 버튼 표시</string>
<string name="settings_show_goals_separately">목표 탭 분리</string>
<string name="settings_show_nav_bar_at_the_bottom">하단에 탐색바 표시</string>
<string name="settings_allow_multitasking">멀티태스킹 활성화</string>
<string name="settings_allow_multitasking_hint">비활성화시, 새로운 활동을 시작하면 기존의 활동 기록을 멈춥니다.</string>
<string name="settings_show_notifications">타이머 알림 표기</string>
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<string name="settings_allow_multiple_activity_filters_hint">Indien uitgeschakeld, zal het selecteren van een filter andere activiteitsfilters uitschakelen.</string>
<string name="settings_enable_pomodoro_mode">Toon de Pomodoro-knop op het hoofdscherm</string>
<string name="settings_show_goals_separately">Toon doelen op een apart tabblad</string>
<string name="settings_show_nav_bar_at_the_bottom">Toon navigatiebalk onderaan</string>
<string name="settings_allow_multitasking">Multitasking toestaan</string>
<string name="settings_allow_multitasking_hint">Indien uitgeschakeld, zal het starten van een nieuwe timer automatisch andere activiteiten stoppen.</string>
<string name="settings_show_notifications">Timer-meldingen tonen</string>
Expand Down
Loading

0 comments on commit 04c3eaa

Please sign in to comment.