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.

This commit is contained in:
Aidan Follestad 2015-04-18 10:28:29 -05:00
commit 135c8233ec
6 changed files with 25 additions and 29 deletions

View file

@ -65,7 +65,6 @@ public class MainActivity extends AbsFabActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, KabViewsDisableAble { implements NavigationDrawerFragment.NavigationDrawerCallbacks, KabViewsDisableAble {
public static final String TAG = MainActivity.class.getSimpleName(); public static final String TAG = MainActivity.class.getSimpleName();
private static final boolean DEBUG = true;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;

View file

@ -8,6 +8,7 @@ import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -60,7 +61,7 @@ public class NavigationDrawerFragment extends Fragment {
if (!userLearnedDrawer && !fromSavedInstanceState) { if (!userLearnedDrawer && !fromSavedInstanceState) {
this.drawerLayout.openDrawer(fragmentContainerView); this.drawerLayout.openDrawer(Gravity.START);
userLearnedDrawer = true; userLearnedDrawer = true;
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(AppKeys.SP_USER_LEARNED_DRAWER, true).apply(); PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(AppKeys.SP_USER_LEARNED_DRAWER, true).apply();
} }

View file

@ -8,6 +8,9 @@ import android.preference.PreferenceManager;
import com.kabouzeid.gramophone.R; import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.ColorChooserDialog; import com.kabouzeid.gramophone.dialogs.ColorChooserDialog;
import java.util.HashSet;
import java.util.Set;
public final class PreferenceUtils { public final class PreferenceUtils {
public static final int DEFAULT_PAGE = 1; public static final int DEFAULT_PAGE = 1;
@ -131,18 +134,30 @@ public final class PreferenceUtils {
return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_OTHER_SCREENS); return coloredNavigationBarFor(COLORED_NAVIGATION_BAR_OTHER_SCREENS);
} }
private final boolean coloredNavigationBarFor(String key) { @SuppressLint("CommitPrefEdits")
private boolean coloredNavigationBarFor(String key) {
Set<String> 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 { try {
return mPreferences.getStringSet(COLORED_NAVIGATION_BAR, null).contains(key); return mPreferences.getStringSet(COLORED_NAVIGATION_BAR, defaultVals).contains(key);
} catch (NullPointerException e) { } catch (NullPointerException e) {
return false; return false;
} }
} }
@SuppressLint("CommitPrefEdits") // @SuppressLint("CommitPrefEdits")
private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) { // private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) {
mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit(); // mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit();
} // }
public final boolean playbackControllerBoxEnabled() { public final boolean playbackControllerBoxEnabled() {
return mPreferences.getBoolean(PLAYBACK_CONTROLLER_BOX, false); return mPreferences.getBoolean(PLAYBACK_CONTROLLER_BOX, false);

View file

@ -205,23 +205,4 @@ public class Util {
} }
return drawable; return drawable;
} }
/**
* Returns a string representation of {@param set}. Used only for debugging purposes.
*/
@NonNull
public static String setToString(@NonNull Set<String> set) {
Iterator<String> 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(", ");
}
}
} }

View file

@ -90,7 +90,7 @@
<string name="pref_title_general_theme">General theme</string> <string name="pref_title_general_theme">General theme</string>
<string name="pref_header_audio">Audio</string> <string name="pref_header_audio">Audio</string>
<string name="pref_header_general">General</string> <string name="pref_header_general">General</string>
<string name="pref_summary_navigation_bar">Set where the navigation bar should be colored</string> <string name="pref_summary_colored_navigation_bar">Set where the navigation bar should be colored.</string>
<string name="pref_title_navigation_bar">Colored navigation bar</string> <string name="pref_title_navigation_bar">Colored navigation bar</string>
<string name="pref_title_set_default_start_page">Set default start page</string> <string name="pref_title_set_default_start_page">Set default start page</string>
<string name="title_activity_settings">Settings</string> <string name="title_activity_settings">Settings</string>

View file

@ -48,7 +48,7 @@
android:entries="@array/pref_navigation_bar_color_titles" android:entries="@array/pref_navigation_bar_color_titles"
android:entryValues="@array/pref_navigation_bar_color_values" android:entryValues="@array/pref_navigation_bar_color_values"
android:title="@string/pref_title_navigation_bar" 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" /> android:layout="@layout/preference_custom" />
</com.kabouzeid.gramophone.prefs.DynamicPreferenceCategory> </com.kabouzeid.gramophone.prefs.DynamicPreferenceCategory>