Browse Source
Initial commit for updated flow of themes. (Check description)
Initial commit for updated flow of themes. (Check description)
Removed DayNight theme. Added a 'white' theme for Light, and 'black' theme for Dark. Users will have to set the type of Light or Dark theme they want to use. Default is white for light, black for dark. More themes will be added later.renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
26 changed files with 372 additions and 114 deletions
-
2app/src/main/AndroidManifest.xml
-
4app/src/main/java/awais/instagrabber/activities/BaseLanguageActivity.java
-
3app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
2app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
10app/src/main/java/awais/instagrabber/fragments/settings/BasePreferencesFragment.java
-
5app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java
-
60app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java
-
94app/src/main/java/awais/instagrabber/fragments/settings/ThemePreferencesFragment.java
-
4app/src/main/java/awais/instagrabber/utils/Constants.java
-
9app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
-
50app/src/main/java/awais/instagrabber/utils/ThemeUtils.java
-
33app/src/main/java/awais/instagrabber/utils/Utils.java
-
10app/src/main/res/drawable/ic_format_paint_24.xml
-
1app/src/main/res/drawable/ic_profile.xml
-
7app/src/main/res/drawable/ic_star_24.xml
-
2app/src/main/res/drawable/pref_list_divider_material.xml
-
2app/src/main/res/layout/item_follow.xml
-
2app/src/main/res/layout/item_pref_divider.xml
-
22app/src/main/res/layout/item_suggestion.xml
-
5app/src/main/res/layout/pref_account_switcher.xml
-
10app/src/main/res/navigation/more_nav_graph.xml
-
12app/src/main/res/values/arrays.xml
-
30app/src/main/res/values/color.xml
-
4app/src/main/res/values/strings.xml
-
46app/src/main/res/values/styles.xml
-
57app/src/main/res/values/themes.xml
@ -0,0 +1,94 @@ |
|||
package awais.instagrabber.fragments.settings; |
|||
|
|||
import android.content.Context; |
|||
import android.content.res.TypedArray; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.preference.ListPreference; |
|||
import androidx.preference.Preference; |
|||
import androidx.preference.PreferenceScreen; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.utils.Constants; |
|||
|
|||
public class ThemePreferencesFragment extends BasePreferencesFragment { |
|||
@Override |
|||
void setupPreferenceScreen(final PreferenceScreen screen) { |
|||
final Context context = getContext(); |
|||
if (context == null) return; |
|||
screen.addPreference(getThemePreference(context)); |
|||
screen.addPreference(getLightThemePreference(context)); |
|||
screen.addPreference(getDarkThemePreference(context)); |
|||
} |
|||
|
|||
private Preference getThemePreference(@NonNull final Context context) { |
|||
final ListPreference preference = new ListPreference(context); |
|||
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); |
|||
final int length = getResources().getStringArray(R.array.theme_presets).length; |
|||
final String[] values = new String[length]; |
|||
for (int i = 0; i < length; i++) { |
|||
values[i] = String.valueOf(i); |
|||
} |
|||
preference.setKey(Constants.APP_THEME); |
|||
preference.setTitle(R.string.theme_settings); |
|||
preference.setDialogTitle(R.string.theme_settings); |
|||
preference.setEntries(R.array.theme_presets); |
|||
preference.setIconSpaceReserved(false); |
|||
preference.setEntryValues(values); |
|||
preference.setOnPreferenceChangeListener((preference1, newValue) -> { |
|||
shouldRecreate(); |
|||
return true; |
|||
}); |
|||
return preference; |
|||
} |
|||
|
|||
private Preference getLightThemePreference(final Context context) { |
|||
final ListPreference preference = new ListPreference(context); |
|||
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); |
|||
final TypedArray lightThemeValues = getResources().obtainTypedArray(R.array.light_theme_values); |
|||
final int length = lightThemeValues.length(); |
|||
final String[] values = new String[length]; |
|||
for (int i = 0; i < length; i++) { |
|||
final int resourceId = lightThemeValues.getResourceId(i, -1); |
|||
if (resourceId < 0) continue; |
|||
values[i] = String.valueOf(resourceId); |
|||
} |
|||
lightThemeValues.recycle(); |
|||
preference.setKey(Constants.PREF_LIGHT_THEME); |
|||
preference.setTitle(R.string.light_theme_settings); |
|||
preference.setDialogTitle(R.string.light_theme_settings); |
|||
preference.setEntries(R.array.light_themes); |
|||
preference.setIconSpaceReserved(false); |
|||
preference.setEntryValues(values); |
|||
preference.setOnPreferenceChangeListener((preference1, newValue) -> { |
|||
shouldRecreate(); |
|||
return true; |
|||
}); |
|||
return preference; |
|||
} |
|||
|
|||
private Preference getDarkThemePreference(final Context context) { |
|||
final ListPreference preference = new ListPreference(context); |
|||
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); |
|||
final TypedArray darkThemeValues = getResources().obtainTypedArray(R.array.dark_theme_values); |
|||
final int length = darkThemeValues.length(); |
|||
final String[] values = new String[length]; |
|||
for (int i = 0; i < length; i++) { |
|||
final int resourceId = darkThemeValues.getResourceId(i, -1); |
|||
if (resourceId < 0) continue; |
|||
values[i] = String.valueOf(resourceId); |
|||
} |
|||
darkThemeValues.recycle(); |
|||
preference.setKey(Constants.PREF_DARK_THEME); |
|||
preference.setTitle(R.string.dark_theme_settings); |
|||
preference.setDialogTitle(R.string.dark_theme_settings); |
|||
preference.setEntries(R.array.dark_themes); |
|||
preference.setIconSpaceReserved(false); |
|||
preference.setEntryValues(values); |
|||
preference.setOnPreferenceChangeListener((preference1, newValue) -> { |
|||
shouldRecreate(); |
|||
return true; |
|||
}); |
|||
return preference; |
|||
} |
|||
} |
@ -0,0 +1,50 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.content.Context; |
|||
import android.content.res.Configuration; |
|||
import android.os.Build; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.appcompat.app.AppCompatDelegate; |
|||
|
|||
import awais.instagrabber.R; |
|||
|
|||
import static awais.instagrabber.utils.Utils.settingsHelper; |
|||
|
|||
public final class ThemeUtils { |
|||
private static final String TAG = "ThemeUtils"; |
|||
|
|||
public static void changeTheme(@NonNull final Context context) { |
|||
int themeCode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; // this is fallback / default |
|||
|
|||
if (settingsHelper != null) themeCode = settingsHelper.getThemeCode(false); |
|||
|
|||
if (themeCode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && Build.VERSION.SDK_INT < 29) { |
|||
themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; |
|||
} |
|||
final boolean isNight = isNight(context, themeCode); |
|||
final int themeResId = isNight ? settingsHelper.getInteger(Constants.PREF_DARK_THEME) |
|||
: settingsHelper.getInteger(Constants.PREF_LIGHT_THEME); |
|||
|
|||
final int finalThemeResId; |
|||
if (themeResId <= 0) { |
|||
// Nothing set in settings |
|||
finalThemeResId = isNight ? R.style.AppTheme_Dark_Black |
|||
: R.style.AppTheme_Light_White; |
|||
} else finalThemeResId = themeResId; |
|||
// Log.d(TAG, "changeTheme: finalThemeResId: " + finalThemeResId); |
|||
context.setTheme(finalThemeResId); |
|||
} |
|||
|
|||
public static boolean isNight(final Context context, final int themeCode) { |
|||
// check if setting is set to 'Dark' |
|||
boolean isNight = themeCode == AppCompatDelegate.MODE_NIGHT_YES; |
|||
// if not dark check if themeCode is MODE_NIGHT_FOLLOW_SYSTEM or MODE_NIGHT_AUTO_BATTERY |
|||
if (!isNight && (themeCode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM || themeCode == AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)) { |
|||
// check if resulting theme would be NIGHT |
|||
final int uiMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; |
|||
isNight = uiMode == Configuration.UI_MODE_NIGHT_YES; |
|||
} |
|||
return isNight; |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:width="24dp" |
|||
android:height="24dp" |
|||
android:tint="?attr/colorControlNormal" |
|||
android:viewportWidth="24" |
|||
android:viewportHeight="24"> |
|||
<path |
|||
android:fillColor="@android:color/white" |
|||
android:pathData="M18,4V3c0,-0.55 -0.45,-1 -1,-1H5c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1V6h1v4H9v11c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-9h8V4h-3z" /> |
|||
</vector> |
@ -1,9 +1,10 @@ |
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:width="24dp" |
|||
android:height="24dp" |
|||
android:tint="?attr/colorControlNormal" |
|||
android:viewportWidth="24" |
|||
android:viewportHeight="24"> |
|||
<path |
|||
android:fillColor="@android:color/white" |
|||
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/> |
|||
<path |
|||
android:fillColor="@android:color/white" |
|||
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" /> |
|||
</vector> |
@ -1,19 +1,58 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<resources> |
|||
|
|||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> |
|||
<item name="bottomSheetDialogTheme">@style/AppTheme.BottomSheetDialog</item> |
|||
<item name="android:windowAnimationStyle">@style/AppTheme.WindowAnimationTransition</item> |
|||
<item name="bottomNavigationStyle">@style/AppTheme.BottomNavigationView</item> |
|||
<style name="AppTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar"> |
|||
<!--<item name="bottomSheetDialogTheme">@style/AppTheme.BottomSheetDialog</item>--> |
|||
<!--<item name="android:windowAnimationStyle">@style/AppTheme.WindowAnimationTransition</item>--> |
|||
<!--<item name="bottomNavigationStyle">@style/AppTheme.BottomNavigationView</item>--> |
|||
<item name="windowActionModeOverlay">true</item> |
|||
<item name="actionModeStyle">@style/Widget.App.ActionMode</item> |
|||
<item name="actionModeCloseDrawable">@drawable/ic_close_24</item> |
|||
<item name="actionBarTheme">@style/ThemeOverlay.AppTheme.Dark.ActionBar</item> |
|||
<item name="android:textColorLink">@color/blue_700</item> |
|||
<item name="android:textColorHighlight">@color/blue_300</item> |
|||
<!--<item name="actionModeStyle">@style/Widget.App.ActionMode</item>--> |
|||
<!--<item name="actionBarTheme">@style/ThemeOverlay.AppTheme.Dark.ActionBar</item>--> |
|||
</style> |
|||
|
|||
<style name="Theme.Amoled" parent="AppTheme"> |
|||
<item name="android:colorBackground">@color/background_amoled</item> |
|||
<item name="bottomSheetDialogTheme">@style/AppTheme.BottomSheetDialog.Dark</item> |
|||
<style name="AppTheme" parent="AppTheme.Base" /> |
|||
|
|||
<style name="AppTheme.Light.White" parent="AppTheme.Base"> |
|||
<item name="colorPrimary">@color/white</item> |
|||
<item name="colorOnPrimary">@color/black</item> |
|||
<item name="colorSecondary">@color/white</item> |
|||
<item name="colorOnSecondary">@color/black</item> |
|||
<item name="colorSurface">@color/white</item> |
|||
<item name="colorOnSurface">@color/black</item> |
|||
<item name="colorAccent">@color/black</item> |
|||
<item name="android:windowBackground">@color/white</item> |
|||
<item name="bottomNavigationStyle">@style/Widget.BottomNavigationView.Light.White</item> |
|||
<item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.Light.White</item> |
|||
</style> |
|||
|
|||
<style name="AppTheme.Dark.Black" parent="AppTheme.Base"> |
|||
<item name="colorPrimary">@color/black</item> |
|||
<item name="colorOnPrimary">@color/white</item> |
|||
<item name="colorSecondary">@color/black</item> |
|||
<item name="colorOnSecondary">@color/white</item> |
|||
<item name="colorSurface">@color/black</item> |
|||
<item name="colorOnSurface">@color/white</item> |
|||
<item name="colorAccent">@color/blue_A700</item> |
|||
<item name="colorControlHighlight">@color/grey_600</item> |
|||
<item name="android:textColorPrimary">@color/white</item> |
|||
<item name="android:textColorSecondary">@color/white</item> |
|||
<item name="android:textColorHint">@color/grey_500</item> |
|||
<item name="android:windowBackground">@color/black</item> |
|||
<item name="bottomNavigationStyle">@style/Widget.BottomNavigationView.Dark.Black</item> |
|||
<item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.Dark.Black</item> |
|||
<item name="android:dialogTheme">@style/Widget.Dialog.Dark.Black</item> |
|||
<item name="alertDialogTheme">@style/Widget.AlertDialog.Dark.Black</item> |
|||
<item name="switchStyle">@style/Widget.AppCompat.CompoundButton.Switch.Dark.Black</item> |
|||
<item name="android:dropDownListViewStyle">@style/Widget.AppCompat.ListView.DropDown.Dark.Black</item> |
|||
<item name="preferenceFragmentCompatStyle">@style/PreferenceFragmentCompatStyle.Dark.Black</item> |
|||
</style> |
|||
|
|||
<style name="Theme.Amoled" parent="AppTheme.Base"> |
|||
<!--<item name="android:colorBackground">@color/background_amoled</item>--> |
|||
<!--<item name="bottomSheetDialogTheme">@style/AppTheme.BottomSheetDialog.Dark</item>--> |
|||
</style> |
|||
|
|||
<style name="AppTheme.BottomSheetDialog.Dark" parent="Theme.MaterialComponents.BottomSheetDialog" /> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue