Skip to content

Commit

Permalink
Feature: Added Navigation hiding.
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat committed Dec 1, 2024
1 parent 9ac1c29 commit db56cb0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,34 @@ class AppHelper @Inject constructor() {
}
}

fun showNavigationBar(window: Window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// For Android 11 (API 30) and above, use WindowInsetsController to show the navigation bar
window.insetsController?.show(WindowInsets.Type.navigationBars())
} else {
@Suppress("DEPRECATION", "InlinedApi")
// For older versions, show the navigation bar using systemUiVisibility
window.decorView.apply {
systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
}
}

fun hideNavigationBar(window: Window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// For Android 11 (API 30) and above, use WindowInsetsController to hide the navigation bar
window.insetsController?.hide(WindowInsets.Type.navigationBars())
} else {
@Suppress("DEPRECATION")
// For older versions, hide the navigation bar using systemUiVisibility
window.decorView.apply {
systemUiVisibility =
View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}
}
}

fun wordOfTheDay(resources: Resources): String {
val dailyWordsArray =
resources.getStringArray(R.array.settings_appearance_daily_word_default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
get() = prefs.getBoolean(Constants.SHOW_STATUS_BAR, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_STATUS_BAR, value).apply()

var showNavigationBar: Boolean
get() = prefs.getBoolean(Constants.SHOW_NAVIGATION_BAR, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_NAVIGATION_BAR, value).apply()

var showTime: Boolean
get() = prefs.getBoolean(Constants.SHOW_TIME, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_TIME, value).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class MainActivity : AppCompatActivity() {
setupNavController()
setupOrientation()
setupLocationManager()
setLanguage()
}

@Suppress("DEPRECATION")
Expand All @@ -110,6 +109,7 @@ class MainActivity : AppCompatActivity() {
private fun initializeDependencies() {
setLocationPermissionDenied(false)
preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar)
preferenceViewModel.setShowNavigationBar(preferenceHelper.showNavigationBar)
preferenceViewModel.setFirstLaunch(preferenceHelper.firstLaunch)

window.addFlags(FLAG_LAYOUT_NO_LIMITS)
Expand Down Expand Up @@ -214,6 +214,12 @@ class MainActivity : AppCompatActivity() {
if (it) appHelper.showStatusBar(this.window)
else appHelper.hideStatusBar(this.window)
}

preferenceViewModel.setShowNavigationBar(preferenceHelper.showNavigationBar)
preferenceViewModel.showNavigationBarLiveData.observe(this) {
if (it) appHelper.showNavigationBar(this.window)
else appHelper.hideNavigationBar(this.window)
}
}

private fun setupNavController() {
Expand Down Expand Up @@ -288,9 +294,11 @@ class MainActivity : AppCompatActivity() {
when (navController.currentDestination?.id) {
R.id.SettingsFeaturesFragment,
R.id.SettingsLookFeelFragment,
R.id.SettingsWidgetFragment,
R.id.SettingsAdvancedFragment,
R.id.FavoriteFragment,
R.id.HiddenFragment -> {
R.id.HiddenFragment,
-> {
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.Up)
Expand Down Expand Up @@ -338,7 +346,7 @@ class MainActivity : AppCompatActivity() {
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
grantResults: IntArray,
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,9 @@ class HomeFragment : Fragment(),
}

override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
val actionTypeNavOptions: NavOptions =
appHelper.getActionType(Constants.Swipe.DoubleTap)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.DoubleTap)
findNavController().navigate(
R.id.SettingsFragment,
null,
Expand All @@ -554,8 +555,9 @@ class HomeFragment : Fragment(),
if (preferenceHelper.settingsLock) {
fingerHelper.startBiometricSettingsAuth(R.id.SettingsFragment)
} else {
val actionTypeNavOptions: NavOptions =
appHelper.getActionType(Constants.Swipe.DoubleTap)
val actionTypeNavOptions: NavOptions? =
if (preferenceHelper.disableAnimations) null
else appHelper.getActionType(Constants.Swipe.DoubleTap)
findNavController().navigate(
R.id.SettingsFragment,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class SettingsLookFeelFragment : Fragment(),
private fun initializeInjectedDependencies() {
// Set initial values and listeners for switches
binding.apply {
statueBarSwitchCompat.isChecked = preferenceHelper.showStatusBar
statusBarSwitchCompat.isChecked = preferenceHelper.showStatusBar
navBarSwitchCompat.isChecked = preferenceHelper.showNavigationBar
timeSwitchCompat.isChecked = preferenceHelper.showTime
dateSwitchCompat.isChecked = preferenceHelper.showDate
batterySwitchCompat.isChecked = preferenceHelper.showBattery
Expand Down Expand Up @@ -142,12 +143,18 @@ class SettingsLookFeelFragment : Fragment(),
@RequiresApi(Build.VERSION_CODES.Q)
private fun setupSwitchListeners() {
binding.apply {
statueBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
statusBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowStatusBar(isChecked)
val feedbackType = if (isChecked) "on" else "off"
appHelper.triggerHapticFeedback(context, feedbackType)
}

navBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowNavigationBar(isChecked)
val feedbackType = if (isChecked) "on" else "off"
appHelper.triggerHapticFeedback(context, feedbackType)
}

dateSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowDate(isChecked)
val feedbackType = if (isChecked) "on" else "off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ object Constants {
const val SHOW_ALARM_CLOCK = "SHOW_ALARM_CLOCK"
const val SHOW_BATTERY = "SHOW_BATTERY"
const val SHOW_STATUS_BAR = "SHOW_STATUS_BAR"
const val SHOW_NAVIGATION_BAR = "SHOW_NAVIGATION_BAR"


const val SHOW_WEATHER_WIDGET = "SHOW_WEATHER_WIDGET"
const val SHOW_WEATHER_WIDGET_SUN_SET_RISE = "SHOW_WEATHER_WIDGET_SUN_SET_RISE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PreferenceViewModel @Inject constructor(

private val firstLaunchLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showStatusBarLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showNavigationBarLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showTimeLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showDateLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showDailyWordLiveData: MutableLiveData<Boolean> = MutableLiveData()
Expand Down Expand Up @@ -76,6 +77,11 @@ class PreferenceViewModel @Inject constructor(
showStatusBarLiveData.postValue(preferenceHelper.showStatusBar)
}

fun setShowNavigationBar(showNavigationBar: Boolean) {
preferenceHelper.showNavigationBar = showNavigationBar
showNavigationBarLiveData.postValue(preferenceHelper.showNavigationBar)
}

fun setShowTime(showTime: Boolean) {
preferenceHelper.showTime = showTime
showTimeLiveData.postValue(preferenceHelper.showTime)
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/res/layout/fragment_settings_look_feel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
tools:ignore="MissingConstraints">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/statue_bar_text"
android:id="@+id/status_bar_text"
style="@style/TextDefaultStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -73,7 +73,38 @@
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/statue_bar_switchCompat"
android:id="@+id/status_bar_switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.7"
android:scaleY="0.8"
android:thumb="@drawable/shape_switch_thumb"
app:track="@drawable/selector_switch"
tools:ignore="DuplicateSpeakableTextCheck,TouchTargetSizeCheck" />

</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:ignore="MissingConstraints">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/nav_bar_text"
style="@style/TextDefaultStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/settings_display_nav_bar"
android:textSize="@dimen/text_large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/nav_bar_switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.7"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/fragment_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
android:orientation="vertical"
tools:context=".ui.widgets.WidgetFragment">

<FrameLayout
android:id="@+id/touchArea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="20dp" />

<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
Expand Down
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 @@ -95,6 +95,7 @@
<string name="settings_title_others">Others</string>

<string name="settings_display_status_bar">Show Status Bar</string>
<string name="settings_display_nav_bar">Show Navigation Bar</string>
<string name="settings_display_date">Show Date</string>
<string name="settings_display_time">Show Time</string>
<string name="settings_display_battery">Show Battery</string>
Expand Down

0 comments on commit db56cb0

Please sign in to comment.