Code cleanup

This commit is contained in:
Stefan Schueller 2020-07-05 16:12:35 +02:00
parent e4766c9363
commit 082c482e47
11 changed files with 41 additions and 103 deletions

View File

@ -38,7 +38,7 @@ public class CommonActivity extends AppCompatActivity {
// Set Night Mode // Set Night Mode
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); 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); AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
// Set theme // Set theme
@ -52,7 +52,7 @@ public class CommonActivity extends AppCompatActivity {
); );
// Set language // 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; assert countryCode != null;
Locale locale = new Locale(countryCode); Locale locale = new Locale(countryCode);

View File

@ -50,7 +50,6 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -320,8 +319,8 @@ public class VideoListActivity extends CommonActivity {
isLoading = true; isLoading = true;
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String nsfw = sharedPref.getBoolean("pref_show_nsfw", false) ? "both" : "false"; String nsfw = sharedPref.getBoolean(getString(R.string.pref_show_nsfw_key), false) ? "both" : "false";
Set<String> languages = sharedPref.getStringSet("pref_language", null); Set<String> languages = sharedPref.getStringSet(getString(R.string.pref_video_language_key), null);
String apiBaseURL = APIUrlHelper.getUrlWithVersion(this); String apiBaseURL = APIUrlHelper.getUrlWithVersion(this);
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetVideoDataService.class); 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 // only check when we actually need the permission
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && 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); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
} }
} }

View File

@ -407,7 +407,7 @@ public class VideoPlayActivity extends AppCompatActivity {
return; return;
} }
// pause video if pref is enabled // 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(); videoPlayerFragment.pauseVideo();
} }

View File

@ -86,7 +86,7 @@ public class ServerListAdapter extends RecyclerView.Adapter<ServerListAdapter.Se
String serverUrl = APIUrlHelper.cleanServerUrl(getServerAtPosition(position).getServerHost()); String serverUrl = APIUrlHelper.cleanServerUrl(getServerAtPosition(position).getServerHost());
editor.putString("pref_api_base", serverUrl); editor.putString(mInflater.getContext().getString(R.string.pref_api_base_key), serverUrl);
editor.apply(); editor.apply();
// attempt authentication if we have a username // attempt authentication if we have a username

View File

@ -75,7 +75,7 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
false); false);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); 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 : mFiles) { for (File file : mFiles) {
@ -91,7 +91,7 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
textView.setOnClickListener(view1 -> { textView.setOnClickListener(view1 -> {
// Log.v(TAG, file.getResolution().getLabel()); // Log.v(TAG, file.getResolution().getLabel());
SharedPreferences.Editor editor = sharedPref.edit(); 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(); editor.apply();
for (File fileV : mFiles) { for (File fileV : mFiles) {

View File

@ -108,7 +108,7 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment {
private String getCurrentVideoQuality(ArrayList<File> files) { private String getCurrentVideoQuality(ArrayList<File> files) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); 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) { for (File file : files) {
if (videoQuality.equals(file.getResolution().getId())) { if (videoQuality.equals(file.getResolution().getId())) {

View File

@ -220,7 +220,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); 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); torrentStatus.setVisibility(View.VISIBLE);
String stream = video.getFiles().get(0).getTorrentUrl(); String stream = video.getFiles().get(0).getTorrentUrl();
Log.v(TAG, "getTorrentUrl : " + 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); torrentStream.startStream(stream);
} else { } else {
Integer videoQuality = sharedPref.getInt("pref_quality", 0); Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 0);
//get video qualities //get video qualities
String urlToPlay = video.getFiles().get(0).getFileUrl(); String urlToPlay = video.getFiles().get(0).getFileUrl();

View File

@ -32,7 +32,7 @@ public class APIUrlHelper{
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
// validate URL is valid // 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)) { if (!URLUtil.isValidUrl(URL)) {
return "http://invalid"; return "http://invalid";
} }

View File

@ -3,22 +3,39 @@
<string name="app_name" translatable="false">Thorium</string> <string name="app_name" translatable="false">Thorium</string>
<!-- Prefs Settings-->
<string name="pref_language_app_key" translatable="false">pref_language_app</string>
<string name="pref_theme_key" translatable="false">pref_theme</string>
<string name="pref_dark_mode_key" translatable="false">pref_dark_mode</string>
<string name="pref_show_nsfw_key" translatable="false">pref_show_nsfw</string>
<string name="pref_video_language_key" translatable="false">pref_language</string>
<string name="pref_back_pause_key" translatable="false">pref_back_pause</string>
<string name="pref_background_behavior_key" translatable="false">pref_background_behavior</string>
<string name="pref_torrent_player_key" translatable="false">pref_torrent_player</string>
<!-- defaults -->
<string name="pref_default_api_base_url" formatted="false" translatable="false">https://troll.tv</string>
<string name="app_default_theme" translatable="false">AppTheme.BLUE</string>
<!-- Pref internal -->
<string name="pref_token_access" translatable="false">pref_token_access</string> <string name="pref_token_access" translatable="false">pref_token_access</string>
<string name="pref_token_refresh" translatable="false">pref_token_refresh</string> <string name="pref_token_refresh" translatable="false">pref_token_refresh</string>
<string name="pref_token_expiration" translatable="false">pref_token_expiration</string> <string name="pref_token_expiration" translatable="false">pref_token_expiration</string>
<string name="pref_token_type" translatable="false">pref_token_type</string> <string name="pref_token_type" translatable="false">pref_token_type</string>
<string name="pref_auth_username" translatable="false">pref_auth_username</string> <string name="pref_auth_username" translatable="false">pref_auth_username</string>
<string name="pref_auth_password" translatable="false">pref_auth_password</string> <string name="pref_auth_password" translatable="false">pref_auth_password</string>
<string name="pref_background_behavior_key" translatable="false">pref_background_behavior</string> <string name="pref_api_base_key" translatable="false">pref_api_base</string>
<string name="pref_quality_key" translatable="false">pref_quality</string>
<!-- Pref internal keys -->
<string name="pref_background_audio_key" translatable="false">backgroundAudio</string> <string name="pref_background_audio_key" translatable="false">backgroundAudio</string>
<string name="pref_background_stop_key" translatable="false">backgroundStop</string> <string name="pref_background_stop_key" translatable="false">backgroundStop</string>
<string name="pref_background_float_key" translatable="false">backgroundFloat</string> <string name="pref_background_float_key" translatable="false">backgroundFloat</string>
<string name="pref_default_api_base_url" formatted="false" translatable="false">https://troll.tv</string>
<string name="pref_theme_key" translatable="false">pref_theme</string>
<string name="peertube_required_server_version" translatable="false">1.0.0-alpha.7</string> <string name="peertube_required_server_version" translatable="false">1.0.0-alpha.7</string>
<string name="app_default_theme" translatable="false">AppTheme.BLUE</string>
<string name="app_background_audio" translatable="false">BACKGROUND_AUDIO</string> <string name="app_background_audio" translatable="false">BACKGROUND_AUDIO</string>
<string name="video_rating_none" translatable="false">none</string> <string name="video_rating_none" translatable="false">none</string>

View File

@ -1,78 +0,0 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!--<SwitchPreference-->
<!--android:key="pref_background_play"-->
<!--android:title="@string/pref_title_background_play"-->
<!--android:summary="@string/pref_description_background_play"-->
<!--android:defaultValue="true" />-->
<SwitchPreference
android:key="pref_show_nsfw"
android:title="@string/pref_title_show_nsfw"
android:summary="@string/pref_description_show_nsfw"
android:defaultValue="false" />
<MultiSelectListPreference
android:defaultValue="@array/empty_array"
android:entries="@array/languageArray"
android:entryValues="@array/languageValues"
android:key="pref_language"
android:summary="@string/pref_description_language"
android:title="@string/pref_language" />
<SwitchPreference
android:defaultValue="true"
android:key="pref_back_pause"
android:summary="@string/pref_description_back_pause"
android:title="@string/pref_title_back_pause" />
<ListPreference
android:defaultValue="@array/empty_array"
android:entries="@array/supportedLanguagesArray"
android:entryValues="@array/supportedLanguagesValues"
android:key="pref_language_app"
android:summary="@string/pref_description_language_app"
android:title="@string/pref_language_app" />
/>
<ListPreference
android:defaultValue="@array/empty_array"
android:entries="@array/backgroundBehavior"
android:entryValues="@array/backgroundBehaviorValues"
android:key="pref_background_behavior"
android:summary="@string/pref_background_behavior_summary"
android:title="@string/pref_background_behavior" />
/>
<ListPreference
android:title="@string/pref_title_app_theme"
android:summary="@string/pref_description_app_theme"
android:key="pref_theme"
android:defaultValue="AppTheme.BLUE"
android:entries="@array/themeArray"
android:entryValues="@array/themeValues" />
<SwitchPreference
android:key="pref_dark_mode"
android:title="@string/pref_title_dark_mode"
android:summary="@string/pref_description_dark_mode"
android:defaultValue="false" />
<SwitchPreference
android:key="pref_torrent_player"
android:title="@string/pref_title_torrent_player"
android:summary="@string/pref_description_torrent_player"
android:defaultValue="false" />
<Preference
android:title="@string/pref_title_version"
android:summary="@string/versionName" />
<Preference
android:title="@string/pref_title_license"
android:summary="@string/pref_description_license" />
</PreferenceScreen>

View File

@ -6,7 +6,7 @@
app:defaultValue="@array/empty_array" app:defaultValue="@array/empty_array"
app:entries="@array/supportedLanguagesArray" app:entries="@array/supportedLanguagesArray"
app:entryValues="@array/supportedLanguagesValues" app:entryValues="@array/supportedLanguagesValues"
app:key="pref_language_app" app:key="@string/pref_language_app_key"
app:summary="@string/pref_description_language_app" app:summary="@string/pref_description_language_app"
app:title="@string/pref_language_app" app:title="@string/pref_language_app"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
@ -15,14 +15,14 @@
app:defaultValue="AppTheme.BLUE" app:defaultValue="AppTheme.BLUE"
app:entries="@array/themeArray" app:entries="@array/themeArray"
app:entryValues="@array/themeValues" app:entryValues="@array/themeValues"
app:key="pref_theme" app:key="@string/pref_theme_key"
app:summary="@string/pref_description_app_theme" app:summary="@string/pref_description_app_theme"
app:title="@string/pref_title_app_theme" app:title="@string/pref_title_app_theme"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
<SwitchPreference <SwitchPreference
app:defaultValue="false" app:defaultValue="false"
app:key="pref_dark_mode" app:key="@string/pref_dark_mode_key"
app:summary="@string/pref_description_dark_mode" app:summary="@string/pref_description_dark_mode"
app:title="@string/pref_title_dark_mode" app:title="@string/pref_title_dark_mode"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
@ -33,7 +33,7 @@
<SwitchPreference <SwitchPreference
app:defaultValue="false" app:defaultValue="false"
app:key="pref_show_nsfw" app:key="@string/pref_show_nsfw_key"
app:summary="@string/pref_description_show_nsfw" app:summary="@string/pref_description_show_nsfw"
app:title="@string/pref_title_show_nsfw" app:title="@string/pref_title_show_nsfw"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
@ -42,7 +42,7 @@
app:defaultValue="@array/empty_array" app:defaultValue="@array/empty_array"
app:entries="@array/languageArray" app:entries="@array/languageArray"
app:entryValues="@array/languageValues" app:entryValues="@array/languageValues"
app:key="pref_language" app:key="@string/pref_video_language_key"
app:summary="@string/pref_description_language" app:summary="@string/pref_description_language"
app:title="@string/pref_language" app:title="@string/pref_language"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
@ -53,7 +53,7 @@
<SwitchPreference <SwitchPreference
app:defaultValue="true" app:defaultValue="true"
app:key="pref_back_pause" app:key="@string/pref_back_pause_key"
app:summary="@string/pref_description_back_pause" app:summary="@string/pref_description_back_pause"
app:title="@string/pref_title_back_pause" app:title="@string/pref_title_back_pause"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
@ -69,7 +69,7 @@
<SwitchPreference <SwitchPreference
app:defaultValue="false" app:defaultValue="false"
app:key="pref_torrent_player" app:key="@string/pref_torrent_player_key"
app:summary="@string/pref_description_torrent_player" app:summary="@string/pref_description_torrent_player"
app:title="@string/pref_title_torrent_player" app:title="@string/pref_title_torrent_player"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>