[Android] Remove visual selection background in nav menu
Geoffrey Métais
git at videolan.org
Fri Oct 19 15:04:27 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Oct 19 14:43:52 2018 +0200| [9058e266520418b53ebdf54deea689cc4873f128] | committer: Geoffrey Métais
Remove visual selection background in nav menu
> https://code.videolan.org/videolan/vlc-android/commit/9058e266520418b53ebdf54deea689cc4873f128
---
vlc-android/res/menu/navigation.xml | 2 +-
.../src/org/videolan/vlc/gui/MainActivity.java | 29 +++++++++++-----------
.../src/org/videolan/vlc/gui/helpers/Navigator.kt | 25 +++++++------------
3 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/vlc-android/res/menu/navigation.xml b/vlc-android/res/menu/navigation.xml
index aaf6b7d9c..f06684488 100644
--- a/vlc-android/res/menu/navigation.xml
+++ b/vlc-android/res/menu/navigation.xml
@@ -3,7 +3,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/scrollable_group"
- android:checkableBehavior="all"
+ android:checkableBehavior="none"
android:orderInCategory="1">
<item
android:id="@+id/nav_video"
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index ebc6297bf..6a55a871b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -29,19 +29,12 @@ import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import com.google.android.material.navigation.NavigationView;
-import androidx.fragment.app.Fragment;
-import androidx.core.view.GravityCompat;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.ActionBarDrawerToggle;
-import androidx.appcompat.view.ActionMode;
-import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.widget.FilterQueryProvider;
+import com.google.android.material.navigation.NavigationView;
+
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.BuildConfig;
@@ -70,6 +63,14 @@ import org.videolan.vlc.util.Util;
import java.util.List;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.ActionBarDrawerToggle;
+import androidx.appcompat.view.ActionMode;
+import androidx.core.view.GravityCompat;
+import androidx.fragment.app.Fragment;
+
public class MainActivity extends ContentActivity implements FilterQueryProvider, ExtensionManagerService.ExtensionManagerActivity {
public final static String TAG = "VLC/MainActivity";
@@ -111,7 +112,6 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
}
}, 500);
}
- mNavigator.reloadPreferences();
}
/* Set up the action bar */
@@ -420,10 +420,11 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
return;
default:
final int currentId = mNavigator.getCurrentFragmentId();
- if (id != currentId && mNavigationView.getMenu().findItem(id) != null) {
- if (mNavigationView.getMenu().findItem(currentId) != null)
- mNavigationView.getMenu().findItem(currentId).setChecked(false);
- mNavigationView.getMenu().findItem(id).setChecked(true);
+ final MenuItem target = mNavigationView.getMenu().findItem(id);
+ if (id != currentId && target != null) {
+ final MenuItem current = mNavigationView.getMenu().findItem(currentId);
+ if (current != null) current.setChecked(false);
+ target.setChecked(true);
/* Save the tab status in pref */
mSettings.edit().putInt("fragment_id", id).apply();
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index 2ab7a4ff5..d503668f2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -23,18 +23,13 @@
package org.videolan.vlc.gui.helpers
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.LifecycleObserver
-import androidx.lifecycle.OnLifecycleEvent
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
-import com.google.android.material.navigation.NavigationView
-import androidx.fragment.app.Fragment
-import androidx.fragment.app.FragmentManager
-import androidx.collection.SimpleArrayMap
-import android.util.Log
import android.view.MenuItem
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.OnLifecycleEvent
import org.videolan.vlc.R
import org.videolan.vlc.extensions.ExtensionManagerService
import org.videolan.vlc.extensions.api.VLCExtensionItem
@@ -67,13 +62,16 @@ class Navigator(private val activity: MainActivity,
state?.let {
val fm = activity.supportFragmentManager
currentFragment = fm.getFragment(it, "current_fragment")
- currentFragmentId = it.getInt("current", settings.getInt("fragment_id", defaultFragmentId))
- Log.d(TAG, "init currentFragmentId $currentFragmentId, default $defaultFragmentId")
//Restore fragments stack
restoreFragmentsStack(fm)
}
}
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
+ fun onStart() {
+ if (currentFragment === null && !currentIdIsExtension()) showFragment(settings.getInt("fragment_id", defaultFragmentId))
+ }
+
private fun getNewFragment(id: Int): androidx.fragment.app.Fragment {
return when (id) {
R.id.nav_audio -> AudioBrowserFragment()
@@ -121,11 +119,6 @@ class Navigator(private val activity: MainActivity,
}
}
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- fun onStart() {
- if (currentFragment === null && !currentIdIsExtension()) showFragment(currentFragmentId)
- }
-
/**
* Show a secondary fragment.
*/
@@ -141,7 +134,7 @@ class Navigator(private val activity: MainActivity,
fun currentIdIsExtension() = idIsExtension(currentFragmentId)
- private fun idIsExtension(id: Int) = id <= 100
+ private fun idIsExtension(id: Int) = id in 1..100
private fun clearBackstackFromClass(clazz: Class<*>) {
val fm = activity.supportFragmentManager
More information about the Android
mailing list