From d9d22198d51389e71b302e8bde9857bbf0013200 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 21 Jan 2024 19:18:43 +0900 Subject: [PATCH] =?UTF-8?q?FeatureSwitch=E5=AE=9F=E8=A3=85WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/MainActivity.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/src/main/java/one/nem/lacerta/MainActivity.java b/app/src/main/java/one/nem/lacerta/MainActivity.java index 6dec2e80..397921c7 100644 --- a/app/src/main/java/one/nem/lacerta/MainActivity.java +++ b/app/src/main/java/one/nem/lacerta/MainActivity.java @@ -10,19 +10,27 @@ import androidx.navigation.ui.NavigationUI; import android.graphics.Color; import android.os.Bundle; import android.util.Log; +import android.view.Menu; import android.widget.Toast; +import one.nem.lacerta.utils.FeatureSwitch; + import com.google.android.material.bottomnavigation.BottomNavigationView; import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.utils.repository.SharedPrefUtils; + import javax.inject.Inject; @AndroidEntryPoint public class MainActivity extends AppCompatActivity { + @Inject + SharedPrefUtils sharedPrefUtils; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,4 +58,28 @@ public class MainActivity extends AppCompatActivity { // Set status bar color 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); + } }