Dark/Light/Automatic theme

This commit is contained in:
Thomas 2020-10-13 14:30:08 +02:00
parent 87763a050c
commit 676e540059
16 changed files with 190 additions and 35 deletions

View File

@ -4,10 +4,6 @@
<color name="colorPrimaryDark">#4527A0</color>
<color name="colorAccent">#9C27B0</color>
<color name="colorPrimary_full">#212529</color>
<color name="colorPrimaryDark_full">#000000</color>
<color name="colorAccent_full">#F2690D</color>
<color name="tag_color">#bbF2690D</color>
<color name="tag_color_text">#FAFAFA</color>
<color name="positive_thumbs">#2b90d9</color>

View File

@ -6,7 +6,17 @@
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
<string name="set_video_quality_choice" translatable="false">set_video_quality_choice</string>
<string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string-array name="settings_theme">
<item>Clair</item>
<item>Sombre</item>
<item>Automatique</item>
</string-array>
<string name="set_theme">Thème</string>
<string name="set_theme_description">Permet de changer le thème de l\'application</string>
<string name="federation_issue">La vidéo ne peut pas être fédérée !</string>
<string name="title_home">Locale</string>
<string name="title_local">Locale</string>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent_full" android:state_checked="true" />
<item android:color="@color/colorAccent" android:state_checked="true" />
<item android:color="@android:color/tab_indicator_text" />
</selector>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#212529</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#F2690D</color>
<color name="tag_color">#bbF2690D</color>
<color name="tag_color_text">#FAFAFA</color>
<color name="positive_thumbs">#2b90d9</color>
<color name="negative_thumbs">#F44336</color>
<color name="red_1">#F44336</color>
</resources>

View File

@ -5,7 +5,11 @@
<string name="set_video_language_choice" translatable="false">set_video_language_choice</string>
<string name="set_video_quality_choice" translatable="false">set_video_quality_choice</string>
<string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string name="set_theme">Theme</string>
<string name="set_theme_description">Allow to change app theme</string>
<string name="federation_issue">The video cannot be federated!</string>
<string name="title_home">Home</string>
<string name="title_local">Local</string>
@ -245,6 +249,14 @@
<item>Direct stream</item>
</string-array>
<string-array name="settings_theme">
<item>Light</item>
<item>Dark</item>
<item>Automatic</item>
</string-array>
<string-array name="settings_video_quality">
<item>High</item>
<item>Medium</item>

View File

@ -1,21 +0,0 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary_full</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_full</item>
<item name="colorAccent">@color/colorAccent_full</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary_full</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_full</item>
<item name="colorAccent">@color/colorAccent_full</item>
</style>
<style name="progress" parent="SpinKitView.Circle" />
<style name="progressBottom" parent="SpinKitView.ThreeBounce" />
</resources>

View File

@ -15,12 +15,16 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import net.gotev.uploadservice.UploadService;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.ThemeHelper;
public class FedilabTube extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
@ -29,7 +33,12 @@ public class FedilabTube extends MultiDexApplication {
MultiDex.install(FedilabTube.this);
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int themePref = sharedpreferences.getInt(Helper.SET_THEME, Helper.DEFAULT_MODE);
ThemeHelper.switchTo(themePref);
}
}

View File

@ -22,6 +22,7 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
@ -210,12 +211,15 @@ public class MainActivity extends AppCompatActivity {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, account));
return;
}
runOnUiThread(() -> {
//To avoid a token issue with subscriptions, adding fragment is done when the token is refreshed.
fm.beginTransaction().add(R.id.nav_host_fragment, recentFragment, "4").hide(recentFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "3").hide(trendingFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, subscriptionFragment, "2").hide(subscriptionFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, overviewFragment, "1").commit();
new Handler().post(() -> {
fm.beginTransaction().add(R.id.nav_host_fragment, recentFragment, "4").hide(recentFragment).commitAllowingStateLoss();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "3").hide(trendingFragment).commitAllowingStateLoss();
fm.beginTransaction().add(R.id.nav_host_fragment, subscriptionFragment, "2").hide(subscriptionFragment).commitAllowingStateLoss();
fm.beginTransaction().add(R.id.nav_host_fragment, overviewFragment, "1").commitAllowingStateLoss();
});
});
UserMe userMe = new RetrofitPeertubeAPI(MainActivity.this, instance, token.getAccess_token()).verifyCredentials();

View File

@ -22,6 +22,7 @@ import java.util.Set;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
@ -89,6 +90,25 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
}
}
if (key.compareTo(getString(R.string.set_theme_choice)) == 0) {
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
if (set_theme_choice != null) {
int choice;
switch (set_theme_choice.getValue()) {
case "0":
choice = Helper.LIGHT_MODE;
break;
case "1":
choice = Helper.DARK_MODE;
break;
default:
choice = Helper.DEFAULT_MODE;
}
editor.putInt(Helper.SET_THEME, choice);
editor.apply();
ThemeHelper.switchTo(choice);
}
}
if (key.compareTo(getString(R.string.set_video_quality_choice)) == 0) {
ListPreference set_video_quality_choice = findPreference(getString(R.string.set_video_quality_choice));
if (set_video_quality_choice != null) {
@ -137,12 +157,27 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
return;
}
//****** App theme *******
ListPreference set_theme_choice = findPreference(getString(R.string.set_theme_choice));
List<String> arrayTheme = Arrays.asList(getResources().getStringArray(R.array.settings_theme));
CharSequence[] entriesTheme = arrayTheme.toArray(new CharSequence[0]);
CharSequence[] entryValuesTheme = new CharSequence[3];
final SharedPreferences sharedpref = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int currentTheme = sharedpref.getInt(Helper.SET_THEME, Helper.DEFAULT_MODE);
entryValuesTheme[0] = String.valueOf(Helper.LIGHT_MODE);
entryValuesTheme[1] = String.valueOf(Helper.DARK_MODE);
entryValuesTheme[2] = String.valueOf(Helper.DEFAULT_MODE);
if (set_theme_choice != null) {
set_theme_choice.setEntries(entriesTheme);
set_theme_choice.setEntryValues(entryValuesTheme);
set_theme_choice.setValueIndex(currentTheme);
}
//****** Video mode *******
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode));
CharSequence[] entries = array.toArray(new CharSequence[0]);
CharSequence[] entryValues = new CharSequence[3];
final SharedPreferences sharedpref = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int video_mode = sharedpref.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
entryValues[0] = String.valueOf(Helper.VIDEO_MODE_NORMAL);
entryValues[1] = String.valueOf(Helper.VIDEO_MODE_STREAMING);

View File

@ -72,6 +72,10 @@ public class Helper {
public static final int RELOAD_MYVIDEOS = 10;
public static final String SET_VIDEO_MODE = "set_video_mode";
public static final String SET_QUALITY_MODE = "set_quality_mode";
public static final String SET_THEME = "set_theme";
public static final int LIGHT_MODE = 0;
public static final int DARK_MODE = 1;
public static final int DEFAULT_MODE = 2;
public static final String TIMELINE_TYPE = "timeline_type";
public static final int VIDEO_MODE_NORMAL = 0;
public static final int VIDEO_MODE_STREAMING = 2;
@ -573,7 +577,7 @@ public class Helper {
}
public static int getColorAccent() {
return BuildConfig.full_instances ? R.color.colorAccent_full : R.color.colorAccent;
return R.color.colorAccent;
}

View File

@ -0,0 +1,46 @@
package app.fedilab.fedilabtube.helper;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of TubeLab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.os.Build;
import androidx.appcompat.app.AppCompatDelegate;
import static app.fedilab.fedilabtube.helper.Helper.DARK_MODE;
import static app.fedilab.fedilabtube.helper.Helper.LIGHT_MODE;
public class ThemeHelper {
public static void switchTo(int themePref) {
switch (themePref) {
case LIGHT_MODE: {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
}
case DARK_MODE: {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
}
default: {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
}
break;
}
}
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>

View File

@ -33,15 +33,14 @@
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/theme"
app:popupTheme="@style/popupTheme"
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true"
/>

View File

@ -0,0 +1,28 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">?attr/colorOnBackground</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">?attr/colorOnBackground</item>
</style>
<style name="theme" parent="@style/ThemeOverlay.AppCompat.Dark"/>
<style name="popupTheme" parent="@style/ThemeOverlay.AppCompat.Dark"/>
<style name="progress" parent="SpinKitView.Circle" />
<style name="progressBottom" parent="SpinKitView.ThreeBounce" />
</resources>

View File

@ -7,6 +7,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">?attr/colorOnBackground</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
@ -14,8 +15,13 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">?attr/colorOnBackground</item>
</style>
<style name="theme" parent="@style/ThemeOverlay.AppCompat.Dark"/>
<style name="popupTheme" parent="@style/ThemeOverlay.AppCompat.Light"/>
<style name="progress" parent="SpinKitView.Circle" />
<style name="progressBottom" parent="SpinKitView.ThreeBounce" />
</resources>

View File

@ -31,6 +31,11 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/app_interface">
<androidx.preference.ListPreference
android:icon="@drawable/ic_baseline_color_lens_24"
android:key="@string/set_theme_choice"
android:summary="@string/set_theme_description"
android:title="@string/set_theme" />
<androidx.preference.MultiSelectListPreference
android:icon="@drawable/ic_baseline_language_24"
android:key="@string/set_video_language_choice"