diff --git a/app/src/main/res/values/colors.xml b/app/src/acad/res/values/colors.xml
similarity index 71%
rename from app/src/main/res/values/colors.xml
rename to app/src/acad/res/values/colors.xml
index db006a1..9fd2099 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/acad/res/values/colors.xml
@@ -4,10 +4,6 @@
#4527A0
#9C27B0
-
- #212529
- #000000
- #F2690D
#bbF2690D
#FAFAFA
#2b90d9
diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml
index 2589934..00fc2e0 100644
--- a/app/src/acad/res/values/strings.xml
+++ b/app/src/acad/res/values/strings.xml
@@ -6,7 +6,17 @@
set_video_language_choice
set_video_quality_choice
set_video_cache_choice
+ set_theme_choice
+
+
+ - Clair
+ - Sombre
+ - Automatique
+
+
+ Thème
+ Permet de changer le thème de l\'application
La vidéo ne peut pas être fédérée !
Locale
Locale
diff --git a/app/src/full/res/color/bottom_nav_color.xml b/app/src/full/res/color/bottom_nav_color.xml
index edcb7c2..662d3b2 100644
--- a/app/src/full/res/color/bottom_nav_color.xml
+++ b/app/src/full/res/color/bottom_nav_color.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/app/src/full/res/values/colors.xml b/app/src/full/res/values/colors.xml
new file mode 100644
index 0000000..2547404
--- /dev/null
+++ b/app/src/full/res/values/colors.xml
@@ -0,0 +1,12 @@
+
+
+ #212529
+ #000000
+ #F2690D
+ #bbF2690D
+ #FAFAFA
+ #2b90d9
+ #F44336
+
+ #F44336
+
\ No newline at end of file
diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml
index a3cd5f0..2da3caa 100644
--- a/app/src/full/res/values/strings.xml
+++ b/app/src/full/res/values/strings.xml
@@ -5,7 +5,11 @@
set_video_language_choice
set_video_quality_choice
set_video_cache_choice
+ set_theme_choice
+
+ Theme
+ Allow to change app theme
The video cannot be federated!
Home
Local
@@ -245,6 +249,14 @@
- Direct stream
+
+
+ - Light
+ - Dark
+ - Automatic
+
+
+
- High
- Medium
diff --git a/app/src/full/res/values/styles.xml b/app/src/full/res/values/styles.xml
deleted file mode 100644
index 97c4971..0000000
--- a/app/src/full/res/values/styles.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/fedilabtube/FedilabTube.java b/app/src/main/java/app/fedilab/fedilabtube/FedilabTube.java
index 3c2cddf..c941bde 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/FedilabTube.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/FedilabTube.java
@@ -15,12 +15,16 @@ package app.fedilab.fedilabtube;
* see . */
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);
}
+
+
}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java
index 45b0b76..304dde1 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java
@@ -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();
diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java
index 540b096..4e71475 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/SettingsFragment.java
@@ -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 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 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);
diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
index c5aa922..e7550cd 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
@@ -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;
}
diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/ThemeHelper.java
new file mode 100644
index 0000000..6368407
--- /dev/null
+++ b/app/src/main/java/app/fedilab/fedilabtube/helper/ThemeHelper.java
@@ -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 . */
+
+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;
+ }
+ }
+ }
+}
diff --git a/app/src/main/res/drawable/ic_baseline_color_lens_24.xml b/app/src/main/res/drawable/ic_baseline_color_lens_24.xml
new file mode 100644
index 0000000..4bf1550
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_color_lens_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 25a1f0e..2bbecf5 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -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"
>
diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml
new file mode 100644
index 0000000..693dea7
--- /dev/null
+++ b/app/src/main/res/values-night/styles.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/acad/res/values/styles.xml b/app/src/main/res/values/styles.xml
similarity index 73%
rename from app/src/acad/res/values/styles.xml
rename to app/src/main/res/values/styles.xml
index 7e44535..4e30a33 100644
--- a/app/src/acad/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -7,6 +7,7 @@
- @color/colorPrimary
- @color/colorPrimaryDark
- @color/colorAccent
+ - ?attr/colorOnBackground
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index daf3d80..9ddd467 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -31,6 +31,11 @@
+