From 082c482e471d2f33011089cef1a4e2a37403fd5f Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 16:12:35 +0200 Subject: [PATCH] Code cleanup --- .../peertube/activity/CommonActivity.java | 4 +- .../peertube/activity/VideoListActivity.java | 7 +- .../peertube/activity/VideoPlayActivity.java | 2 +- .../peertube/adapter/ServerListAdapter.java | 2 +- .../fragment/VideoMenuQualityFragment.java | 4 +- .../fragment/VideoOptionsFragment.java | 2 +- .../fragment/VideoPlayerFragment.java | 4 +- .../peertube/helper/APIUrlHelper.java | 2 +- app/src/main/res/values/constants.xml | 25 +++++- app/src/main/res/xml/pref_general.xml | 78 ------------------- app/src/main/res/xml/root_preferences.xml | 14 ++-- 11 files changed, 41 insertions(+), 103 deletions(-) delete mode 100644 app/src/main/res/xml/pref_general.xml 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 9f7ada0..c0fdaff 100644 --- a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java @@ -38,7 +38,7 @@ public class CommonActivity extends AppCompatActivity { // Set Night Mode SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? + AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean(getString(R.string.pref_dark_mode_key), false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); // Set theme @@ -52,7 +52,7 @@ public class CommonActivity extends AppCompatActivity { ); // Set language - String countryCode = sharedPref.getString("pref_language_app", "en"); + String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), "en"); assert countryCode != null; Locale locale = new Locale(countryCode); diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index c4ca315..b00bfa5 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -50,7 +50,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; @@ -320,8 +319,8 @@ public class VideoListActivity extends CommonActivity { isLoading = true; SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - String nsfw = sharedPref.getBoolean("pref_show_nsfw", false) ? "both" : "false"; - Set languages = sharedPref.getStringSet("pref_language", null); + String nsfw = sharedPref.getBoolean(getString(R.string.pref_show_nsfw_key), false) ? "both" : "false"; + Set languages = sharedPref.getStringSet(getString(R.string.pref_video_language_key), null); String apiBaseURL = APIUrlHelper.getUrlWithVersion(this); GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetVideoDataService.class); @@ -383,7 +382,7 @@ public class VideoListActivity extends CommonActivity { // only check when we actually need the permission SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && - sharedPref.getBoolean("pref_torrent_player", false)) { + sharedPref.getBoolean(getString(R.string.pref_torrent_player_key), false)) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); } } 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 159b942..398312f 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -407,7 +407,7 @@ public class VideoPlayActivity extends AppCompatActivity { return; } // pause video if pref is enabled - if (sharedPref.getBoolean("pref_back_pause", true)) { + if (sharedPref.getBoolean(getString(R.string.pref_back_pause_key), true)) { videoPlayerFragment.pauseVideo(); } diff --git a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java index cbefba9..1e8ba2f 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ServerListAdapter.java @@ -86,7 +86,7 @@ public class ServerListAdapter extends RecyclerView.Adapter { // Log.v(TAG, file.getResolution().getLabel()); SharedPreferences.Editor editor = sharedPref.edit(); - editor.putInt("pref_quality", file.getResolution().getId()); + editor.putInt(getString(R.string.pref_quality_key), file.getResolution().getId()); editor.apply(); for (File fileV : mFiles) { diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index e9357c8..b0fb6d2 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -108,7 +108,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { private String getCurrentVideoQuality(ArrayList files) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); - Integer videoQuality = sharedPref.getInt("pref_quality", 0); + Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 0); for (File file : files) { if (videoQuality.equals(file.getResolution().getId())) { diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 16c75cf..3ac32ba 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -220,7 +220,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); - if (sharedPref.getBoolean("pref_torrent_player", false)) { + if (sharedPref.getBoolean(getString(R.string.pref_torrent_player_key), false)) { torrentStatus.setVisibility(View.VISIBLE); String stream = video.getFiles().get(0).getTorrentUrl(); Log.v(TAG, "getTorrentUrl : " + video.getFiles().get(0).getTorrentUrl()); @@ -228,7 +228,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL torrentStream.startStream(stream); } else { - Integer videoQuality = sharedPref.getInt("pref_quality", 0); + Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 0); //get video qualities String urlToPlay = video.getFiles().get(0).getFileUrl(); diff --git a/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java b/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java index cf24b2f..2a436af 100644 --- a/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java @@ -32,7 +32,7 @@ public class APIUrlHelper{ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // validate URL is valid - String URL = sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url)); + String URL = sharedPref.getString(context.getString(R.string.pref_api_base_key), context.getResources().getString(R.string.pref_default_api_base_url)); if (!URLUtil.isValidUrl(URL)) { return "http://invalid"; } diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml index ecfcc8e..962059e 100644 --- a/app/src/main/res/values/constants.xml +++ b/app/src/main/res/values/constants.xml @@ -3,22 +3,39 @@ Thorium + + pref_language_app + pref_theme + pref_dark_mode + + pref_show_nsfw + pref_language + + pref_back_pause + pref_background_behavior + pref_torrent_player + + + https://troll.tv + AppTheme.BLUE + + pref_token_access pref_token_refresh pref_token_expiration pref_token_type pref_auth_username pref_auth_password - pref_background_behavior + pref_api_base + pref_quality + + backgroundAudio backgroundStop backgroundFloat - https://troll.tv - pref_theme 1.0.0-alpha.7 - AppTheme.BLUE BACKGROUND_AUDIO none diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml deleted file mode 100644 index 71d4806..0000000 --- a/app/src/main/res/xml/pref_general.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - /> - - - /> - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index ba7b0e3..131d9f1 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -6,7 +6,7 @@ app:defaultValue="@array/empty_array" app:entries="@array/supportedLanguagesArray" app:entryValues="@array/supportedLanguagesValues" - app:key="pref_language_app" + app:key="@string/pref_language_app_key" app:summary="@string/pref_description_language_app" app:title="@string/pref_language_app" app:iconSpaceReserved="false"/> @@ -15,14 +15,14 @@ app:defaultValue="AppTheme.BLUE" app:entries="@array/themeArray" app:entryValues="@array/themeValues" - app:key="pref_theme" + app:key="@string/pref_theme_key" app:summary="@string/pref_description_app_theme" app:title="@string/pref_title_app_theme" app:iconSpaceReserved="false"/> @@ -33,7 +33,7 @@ @@ -42,7 +42,7 @@ app:defaultValue="@array/empty_array" app:entries="@array/languageArray" app:entryValues="@array/languageValues" - app:key="pref_language" + app:key="@string/pref_video_language_key" app:summary="@string/pref_description_language" app:title="@string/pref_language" app:iconSpaceReserved="false"/> @@ -53,7 +53,7 @@ @@ -69,7 +69,7 @@