From 135c8233ecd93eb3bae0e8b58e5d8ef3ee97b3f1 Mon Sep 17 00:00:00 2001 From: Aidan Follestad Date: Sat, 18 Apr 2015 10:28:29 -0500 Subject: [PATCH] First-run crash fix, colored nav bar setting should be on for all by default if translucent nav bars are no longer being used, etc. --- .../ui/activities/MainActivity.java | 1 - .../fragments/NavigationDrawerFragment.java | 3 ++- .../gramophone/util/PreferenceUtils.java | 27 ++++++++++++++----- .../com/kabouzeid/gramophone/util/Util.java | 19 ------------- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/pref_ui.xml | 2 +- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/MainActivity.java b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/MainActivity.java index 6af8345a..c5200a82 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/MainActivity.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/MainActivity.java @@ -65,7 +65,6 @@ public class MainActivity extends AbsFabActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks, KabViewsDisableAble { public static final String TAG = MainActivity.class.getSimpleName(); - private static final boolean DEBUG = true; private DrawerLayout drawerLayout; private ActionBarDrawerToggle drawerToggle; diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/NavigationDrawerFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/NavigationDrawerFragment.java index dc29e296..3ab880ac 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/NavigationDrawerFragment.java @@ -8,6 +8,7 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -60,7 +61,7 @@ public class NavigationDrawerFragment extends Fragment { if (!userLearnedDrawer && !fromSavedInstanceState) { - this.drawerLayout.openDrawer(fragmentContainerView); + this.drawerLayout.openDrawer(Gravity.START); userLearnedDrawer = true; PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(AppKeys.SP_USER_LEARNED_DRAWER, true).apply(); } diff --git a/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtils.java b/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtils.java index 002757b0..a705ed8d 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtils.java +++ b/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtils.java @@ -8,6 +8,9 @@ import android.preference.PreferenceManager; import com.kabouzeid.gramophone.R; import com.kabouzeid.gramophone.dialogs.ColorChooserDialog; +import java.util.HashSet; +import java.util.Set; + public final class PreferenceUtils { public static final int DEFAULT_PAGE = 1; @@ -131,18 +134,30 @@ public final class PreferenceUtils { return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_OTHER_SCREENS); } - private final boolean coloredNavigationBarFor(String key) { + @SuppressLint("CommitPrefEdits") + private boolean coloredNavigationBarFor(String key) { + Set defaultVals = new HashSet<>(); + defaultVals.add(COLORED_NAVIGATION_BAR_ALBUM); + defaultVals.add(COLORED_NAVIGATION_BAR_ARTIST); + defaultVals.add(COLORED_NAVIGATION_BAR_CURRENT_PLAYING); + defaultVals.add(COLORED_NAVIGATION_BAR_PLAYIST); + defaultVals.add(COLORED_NAVIGATION_BAR_TAG_EDITOR); + defaultVals.add(COLORED_NAVIGATION_BAR_OTHER_SCREENS); + + if (!mPreferences.contains(COLORED_NAVIGATION_BAR)) + mPreferences.edit().putStringSet(COLORED_NAVIGATION_BAR, defaultVals).commit(); + try { - return mPreferences.getStringSet(COLORED_NAVIGATION_BAR, null).contains(key); + return mPreferences.getStringSet(COLORED_NAVIGATION_BAR, defaultVals).contains(key); } catch (NullPointerException e) { return false; } } - @SuppressLint("CommitPrefEdits") - private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) { - mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit(); - } +// @SuppressLint("CommitPrefEdits") +// private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) { +// mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit(); +// } public final boolean playbackControllerBoxEnabled() { return mPreferences.getBoolean(PLAYBACK_CONTROLLER_BOX, false); diff --git a/app/src/main/java/com/kabouzeid/gramophone/util/Util.java b/app/src/main/java/com/kabouzeid/gramophone/util/Util.java index 374a868a..12285242 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/util/Util.java +++ b/app/src/main/java/com/kabouzeid/gramophone/util/Util.java @@ -205,23 +205,4 @@ public class Util { } return drawable; } - - /** - * Returns a string representation of {@param set}. Used only for debugging purposes. - */ - @NonNull - public static String setToString(@NonNull Set set) { - Iterator i = set.iterator(); - if (!i.hasNext()) { - return "[]"; - } - StringBuilder sb = new StringBuilder().append('['); - while (true) { - sb.append(i.next()); - if (!i.hasNext()) { - return sb.append(']').toString(); - } - sb.append(", "); - } - } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b349c7f..1a6b1511 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,7 +90,7 @@ General theme Audio General - Set where the navigation bar should be colored + Set where the navigation bar should be colored. Colored navigation bar Set default start page Settings diff --git a/app/src/main/res/xml/pref_ui.xml b/app/src/main/res/xml/pref_ui.xml index a4b1bf8b..6df4bd7a 100644 --- a/app/src/main/res/xml/pref_ui.xml +++ b/app/src/main/res/xml/pref_ui.xml @@ -48,7 +48,7 @@ android:entries="@array/pref_navigation_bar_color_titles" android:entryValues="@array/pref_navigation_bar_color_values" android:title="@string/pref_title_navigation_bar" - android:summary="@string/pref_summary_navigation_bar" + android:summary="@string/pref_summary_colored_navigation_bar" android:layout="@layout/preference_custom" />