This commit is contained in:
r-ca 2024-01-21 19:45:02 +09:00
parent d9d22198d5
commit 676a0e2772
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
7 changed files with 18 additions and 31 deletions

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

View File

@ -11,6 +11,7 @@ import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import one.nem.lacerta.utils.FeatureSwitch; import one.nem.lacerta.utils.FeatureSwitch;
@ -36,13 +37,14 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
// Init navigation // Init navigation
try { try {
FragmentManager supportFragmentManager = getSupportFragmentManager(); FragmentManager supportFragmentManager = getSupportFragmentManager();
NavHostFragment navHostFragment = (NavHostFragment) supportFragmentManager.findFragmentById(R.id.nav_host_fragment); NavHostFragment navHostFragment = (NavHostFragment) supportFragmentManager.findFragmentById(R.id.nav_host_fragment);
assert navHostFragment != null; assert navHostFragment != null;
NavController navController = navHostFragment.getNavController(); NavController navController = navHostFragment.getNavController();
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);
NavigationUI.setupWithNavController(bottomNavigationView, navController); NavigationUI.setupWithNavController(bottomNavigationView, navController);
} }
catch (Exception e) { catch (Exception e) {
@ -52,34 +54,13 @@ public class MainActivity extends AppCompatActivity {
finish(); // Exit app finish(); // Exit app
} }
// bottomNavigation FeatureSwitch
Menu menu = bottomNavigationView.getMenu();
// Set navigation bar color // Set navigation bar color
getWindow().setNavigationBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer)); getWindow().setNavigationBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer));
// Set status bar color // Set status bar color
getWindow().setStatusBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSurface)); getWindow().setStatusBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSurface));
} }
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (!FeatureSwitch.Meta.canOverrideSwitch) {
Log.d("FeatureSwitch", "Switch override is disabled");
if (!FeatureSwitch.FeatureMaster.enableDebugMenu) {
menu.removeItem(one.nem.lacerta.feature.debug.R.id.feature_debug_navigation);
}
if (!FeatureSwitch.FeatureMaster.enableSearch) {
menu.removeItem(one.nem.lacerta.feature.search.R.id.feature_search_navigation);
}
} else {
Log.d("FeatureSwitch", "Switch override is enabled");
if (!FeatureSwitch.FeatureMaster.enableDebugMenu && !sharedPrefUtils.getFeatureSwitchOverride(one.nem.lacerta.model.pref.FeatureSwitchOverride.ENABLE_DEBUG_MENU)) {
menu.removeItem(one.nem.lacerta.feature.debug.R.id.feature_debug_navigation);
}
if (!FeatureSwitch.FeatureMaster.enableSearch && !sharedPrefUtils.getFeatureSwitchOverride(one.nem.lacerta.model.pref.FeatureSwitchOverride.ENABLE_SEARCH)) {
menu.removeItem(one.nem.lacerta.feature.search.R.id.feature_search_navigation);
}
}
return super.onPrepareOptionsMenu(menu);
}
} }

View File

@ -18,7 +18,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/main_nav" app:navGraph="@navigation/main_nav"
tools:layout="@layout/fragment_debug_menu_container" /> tools:layout="@layout/fragment_home_top" />
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav" android:id="@+id/bottom_nav"
@ -31,7 +31,6 @@
app:labelVisibilityMode="selected" app:labelVisibilityMode="selected"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent" />
app:menu="@menu/bottom_nav_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,7 +2,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android" <navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_main_nav" android:id="@+id/app_main_nav"
app:startDestination="@id/feature_debug_navigation"> app:startDestination="@id/feature_home_navigation">
<include app:graph="@navigation/feature_debug_navigation" /> <include app:graph="@navigation/feature_debug_navigation" />

View File

@ -2,8 +2,13 @@ package one.nem.lacerta.utils;
public class FeatureSwitch { public class FeatureSwitch {
public static class Meta {
public static boolean canOverrideSwitch = true;
}
public static class FeatureMaster { public static class FeatureMaster {
public static boolean enableSearch = true; public static boolean enableSearch = true;
public static boolean enableDebugMenu = true;
} }
public static class Setting { public static class Setting {

View File

@ -4,6 +4,8 @@ package one.nem.lacerta.utils.impl;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import javax.inject.Inject;
import dagger.hilt.android.qualifiers.ApplicationContext; import dagger.hilt.android.qualifiers.ApplicationContext;
import one.nem.lacerta.model.pref.FeatureSwitchOverride; import one.nem.lacerta.model.pref.FeatureSwitchOverride;
import one.nem.lacerta.utils.repository.SharedPrefUtils; import one.nem.lacerta.utils.repository.SharedPrefUtils;
@ -12,6 +14,7 @@ public class SharedPrefUtilsImpl implements SharedPrefUtils{
private final Context applicationContext; private final Context applicationContext;
@Inject
public SharedPrefUtilsImpl(@ApplicationContext Context applicationContext) { public SharedPrefUtilsImpl(@ApplicationContext Context applicationContext) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }