From db560bb3405ea54f295030fa9991e2df8b70dcdf Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 14:15:48 +0200 Subject: [PATCH] Code cleanup --- .../activity/AppCompatPreferenceActivity.java | 145 ------------------ .../peertube/activity/CommonActivity.java | 20 ++- .../activity/SelectServerActivity.java | 12 -- .../peertube/activity/VideoPlayActivity.java | 14 +- .../schueller/peertube/helper/Constants.java | 25 --- app/src/main/res/values/constants.xml | 45 +++++- app/src/main/res/values/strings.xml | 34 +--- 7 files changed, 65 insertions(+), 230 deletions(-) delete mode 100644 app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java delete mode 100644 app/src/main/java/net/schueller/peertube/helper/Constants.java diff --git a/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java b/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java deleted file mode 100644 index 36d5fe0..0000000 --- a/app/src/main/java/net/schueller/peertube/activity/AppCompatPreferenceActivity.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2018 Stefan Schüller - * - * License: GPL-3.0+ - * 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. - * - * This program 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 this program. If not, see . - */ - -package net.schueller.peertube.activity; - -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Bundle; -import android.preference.PreferenceActivity; -import androidx.annotation.LayoutRes; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatDelegate; - -import android.preference.PreferenceManager; -import android.view.MenuInflater; -import android.view.View; -import android.view.ViewGroup; - -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; - -/** - * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls - * to be used with AppCompat. - */ -public abstract class AppCompatPreferenceActivity extends PreferenceActivity { - - private AppCompatDelegate mDelegate; - - @Override - protected void onCreate(Bundle savedInstanceState) { - getDelegate().installViewFactory(); - getDelegate().onCreate(savedInstanceState); - super.onCreate(savedInstanceState); - - // TODO: cleanup this duplication - - // Set Night Mode - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? - AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); - - // Set theme - setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), - "style", - getPackageName()) - ); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - getDelegate().onPostCreate(savedInstanceState); - } - - public ActionBar getSupportActionBar() { - return getDelegate().getSupportActionBar(); - } - -// public void setSupportActionBar(@Nullable Toolbar toolbar) { -// getDelegate().setSupportActionBar(toolbar); -// } - - @Override - public MenuInflater getMenuInflater() { - return getDelegate().getMenuInflater(); - } - - @Override - public void setContentView(@LayoutRes int layoutResID) { - getDelegate().setContentView(layoutResID); - } - - @Override - public void setContentView(View view) { - getDelegate().setContentView(view); - } - - @Override - public void setContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().setContentView(view, params); - } - - @Override - public void addContentView(View view, ViewGroup.LayoutParams params) { - getDelegate().addContentView(view, params); - } - - @Override - protected void onPostResume() { - super.onPostResume(); - getDelegate().onPostResume(); - } - - @Override - protected void onTitleChanged(CharSequence title, int color) { - super.onTitleChanged(title, color); - getDelegate().setTitle(title); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - getDelegate().onConfigurationChanged(newConfig); - } - - @Override - protected void onStop() { - super.onStop(); - getDelegate().onStop(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - getDelegate().onDestroy(); - } - - public void invalidateOptionsMenu() { - getDelegate().invalidateOptionsMenu(); - } - - private AppCompatDelegate getDelegate() { - if (mDelegate == null) { - mDelegate = AppCompatDelegate.create(this, null); - } - return mDelegate; - } -} diff --git a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java index a733fca..9f7ada0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java @@ -26,10 +26,9 @@ import android.preference.PreferenceManager; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; -import java.util.Locale; +import net.schueller.peertube.R; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; +import java.util.Locale; public class CommonActivity extends AppCompatActivity { @@ -44,18 +43,23 @@ public class CommonActivity extends AppCompatActivity { // Set theme setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), + sharedPref.getString( + getString(R.string.pref_theme_key), + getString(R.string.app_default_theme) + ), "style", getPackageName()) ); // Set language - String countryCode=sharedPref.getString("pref_language_app","en"); - Locale locale=new Locale(countryCode);; + String countryCode = sharedPref.getString("pref_language_app", "en"); + assert countryCode != null; + Locale locale = new Locale(countryCode); + //Neither Chinese language choice was working, found this fix on stack overflow - if(countryCode.equals("zh-rCN")) + if (countryCode.equals("zh-rCN")) locale = Locale.SIMPLIFIED_CHINESE; - if(countryCode.equals("zh-rTW")) + if (countryCode.equals("zh-rTW")) locale = Locale.TRADITIONAL_CHINESE; Locale.setDefault(locale); diff --git a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java index a4c6186..1706108 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java @@ -18,7 +18,6 @@ package net.schueller.peertube.activity; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -27,33 +26,22 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import android.util.Log; -import android.util.Patterns; import android.view.View; -import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import net.schueller.peertube.R; import net.schueller.peertube.adapter.ServerAdapter; -import net.schueller.peertube.adapter.VideoAdapter; import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.model.ServerList; -import net.schueller.peertube.model.VideoList; import net.schueller.peertube.network.GetServerListDataService; -import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; import java.util.ArrayList; import java.util.Objects; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; - public class SelectServerActivity extends CommonActivity { private ServerAdapter serverAdapter; diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index e76ba92..9460e74 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -65,9 +65,6 @@ import androidx.fragment.app.FragmentTransaction; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; -import static net.schueller.peertube.helper.Constants.BACKGROUND_AUDIO; -import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; -import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; public class VideoPlayActivity extends AppCompatActivity { @@ -86,7 +83,7 @@ public class VideoPlayActivity extends AppCompatActivity { ArrayList actions = new ArrayList<>(); - Intent actionIntent = new Intent(BACKGROUND_AUDIO); + Intent actionIntent = new Intent(getString(R.string.app_background_audio)); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); @SuppressLint({"NewApi", "LocalSuppress"}) Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); @SuppressLint({"NewApi", "LocalSuppress"}) RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); @@ -137,7 +134,7 @@ public class VideoPlayActivity extends AppCompatActivity { filter.addAction(ACTION_STOP); filter.addAction(ACTION_PAUSE); filter.addAction(ACTION_PLAY); - filter.addAction((BACKGROUND_AUDIO)); + filter.addAction((getString(R.string.app_background_audio))); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -152,7 +149,7 @@ public class VideoPlayActivity extends AppCompatActivity { makePipControls(); } - if (action.equals(BACKGROUND_AUDIO)) { + if (action.equals(getString(R.string.app_background_audio))) { unregisterReceiver(receiver); finish(); } @@ -189,7 +186,10 @@ public class VideoPlayActivity extends AppCompatActivity { // Set theme SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), + sharedPref.getString( + getString(R.string.pref_theme_key), + getString(R.string.app_default_theme) + ), "style", getPackageName()) ); diff --git a/app/src/main/java/net/schueller/peertube/helper/Constants.java b/app/src/main/java/net/schueller/peertube/helper/Constants.java deleted file mode 100644 index 0e87a3f..0000000 --- a/app/src/main/java/net/schueller/peertube/helper/Constants.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2018 Stefan Schüller - * - * License: GPL-3.0+ - * 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. - * - * This program 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 this program. If not, see . - */ -package net.schueller.peertube.helper; - -public class Constants { - public static final String THEME_PREF_KEY = "pref_theme"; - public static final String DEFAULT_THEME = "AppTheme.BLUE"; - public static final String BACKGROUND_PLAY_PREF_KEY = "pref_background_play"; - public static final String BACKGROUND_AUDIO = "BACKGROUND_AUDIO"; -} diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml index ce3bf6e..0cfa51f 100644 --- a/app/src/main/res/values/constants.xml +++ b/app/src/main/res/values/constants.xml @@ -1,9 +1,50 @@ + Thorium + + pref_token_access + pref_token_refresh + pref_token_expiration + pref_token_type + pref_auth_username + pref_auth_password backgroundAudio backgroundStop backgroundFloat + https://troll.tv + pref_theme + + 1.0.0-alpha.7 + + AppTheme.BLUE + BACKGROUND_AUDIO + + none + like + dislike + + {faw-play-circle} + {faw-cog} + {faw-check} + {faw-check} + {faw-expand} + {faw-compress} + {faw-ellipsis-v} + {faw-thumbs-up} + {faw-thumbs-down} + {faw-share} + {faw-download} + {faw-save} + + \@ + \u0020-\u0020 + + VideoPlayActivity + + PeerTube + + PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular. @string/pref_background_audio @@ -478,7 +519,7 @@ zh-rTW - + @string/ar @string/bn @string/bn_rBD @@ -505,7 +546,7 @@ - + Low diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f000c8c..d66a185 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,6 @@ - Thorium - VideoPlayActivity + Settings Sign in @@ -29,9 +28,7 @@ Account - \u0020-\u0020 \u0020Views - \@ Video Thumbnail Account Avatar UrlVideoPlayActivity @@ -40,7 +37,6 @@ No Results More Share - PeerTube Invalid URL. Dark Mode @@ -56,7 +52,6 @@ Show NSFW content Language filter Select a video language, instead of showing all videos in all languages. - https://troll.tv PeerTube Server Background Playback If enabled, continues to play video in background. @@ -292,18 +287,7 @@ Normal 1.5x 2x - {faw-play-circle} - {faw-cog} - {faw-check} - {faw-check} - {faw-expand} - {faw-compress} - {faw-ellipsis-v} - {faw-thumbs-up} - {faw-thumbs-down} - {faw-share} - {faw-download} - {faw-save} + Select Server Signup Allowed: %s Yes @@ -352,10 +336,7 @@ Password Add Has Login - none - like - dislike - 1.0.0-alpha.7 + Current Server Address Book 0.75x @@ -372,18 +353,9 @@ About - PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular. NSFW Instance Videos: %s, Local Videos: %s - - - pref_token_access - pref_token_refresh - pref_token_expiration - pref_token_type - pref_auth_username - pref_auth_password Automated