Code cleanup

This commit is contained in:
Stefan Schueller 2020-07-05 14:15:48 +02:00
parent a56dc55921
commit db560bb340
7 changed files with 65 additions and 230 deletions

View File

@ -1,145 +0,0 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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<RemoteAction> 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())
);

View File

@ -1,25 +0,0 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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";
}

View File

@ -1,9 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">Thorium</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_expiration" translatable="false">pref_token_expiration</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_password" translatable="false">pref_auth_password</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_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="app_default_theme" translatable="false">AppTheme.BLUE</string>
<string name="app_background_audio" translatable="false">BACKGROUND_AUDIO</string>
<string name="video_rating_none" translatable="false">none</string>
<string name="video_rating_like" translatable="false">like</string>
<string name="video_rating_dislike" translatable="false">dislike</string>
<string name="video_option_speed_icon" translatable="false">{faw-play-circle}</string>
<string name="video_option_quality_icon" translatable="false">{faw-cog}</string>
<string name="video_speed_active_icon" translatable="false">{faw-check}</string>
<string name="video_quality_active_icon" translatable="false">{faw-check}</string>
<string name="video_expand_icon" translatable="false">{faw-expand}</string>
<string name="video_compress_icon" translatable="false">{faw-compress}</string>
<string name="video_more_icon" translatable="false">{faw-ellipsis-v}</string>
<string name="video_thumbs_up_icon" translatable="false">{faw-thumbs-up}</string>
<string name="video_thumbs_down_icon" translatable="false">{faw-thumbs-down}</string>
<string name="video_share_icon" translatable="false">{faw-share}</string>
<string name="video_download_icon" translatable="false">{faw-download}</string>
<string name="video_save_icon" translatable="false">{faw-save}</string>
<string name="meta_data_owner_seperator" translatable="false">\@</string>
<string name="meta_data_seperator" translatable="false">\u0020-\u0020</string>
<string name="title_activity_video_play" translatable="false">VideoPlayActivity</string>
<string name="playback_channel_name" translatable="false">PeerTube</string>
<string name="peertube_instance_search_default_description" translatable="false">PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.</string>
<string-array name="backgroundBehavior">
<item>@string/pref_background_audio</item>
@ -478,7 +519,7 @@
<item>zh-rTW</item>
</string-array>
<string-array name = "supportedLanguagesArray">
<string-array name="supportedLanguagesArray">
<item>@string/ar</item>
<item>@string/bn</item>
<item>@string/bn_rBD</item>
@ -505,7 +546,7 @@
</string-array>
<string-array name="empty_array"/>
<string-array name="empty_array" />
<string-array name="quality">
<item>Low</item>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">Thorium</string>
<string name="title_activity_video_play" translatable="false">VideoPlayActivity</string>
<string name="title_activity_settings">Settings</string>
<string name="title_activity_login">Sign in</string>
<!-- Strings related to login -->
@ -29,9 +28,7 @@
<string name="bottom_nav_title_account">Account</string>
<!-- Strings related to Settings -->
<!-- Strings related to Video meta data -->
<string name="meta_data_seperator" translatable="false">\u0020-\u0020</string>
<string name="meta_data_views">\u0020Views</string>
<string name="meta_data_owner_seperator" translatable="false">\@</string>
<string name="video_row_video_thumbnail">Video Thumbnail</string>
<string name="video_row_account_avatar">Account Avatar</string>
<string name="title_activity_url_video_play">UrlVideoPlayActivity</string>
@ -40,7 +37,6 @@
<string name="no_data_available">No Results</string>
<string name="descr_overflow_button">More</string>
<string name="menu_share">Share</string>
<string name="playback_channel_name" translatable="false">PeerTube</string>
<string name="invalid_url">Invalid URL.</string>
<!-- settings/preferences -->
<string name="pref_title_dark_mode">Dark Mode</string>
@ -56,7 +52,6 @@
<string name="pref_description_show_nsfw">Show NSFW content</string>
<string name="pref_language">Language filter</string>
<string name="pref_description_language">Select a video language, instead of showing all videos in all languages.</string>
<string name="pref_default_api_base_url" formatted="false" translatable="false">https://troll.tv</string>
<string name="pref_title_peertube_server">PeerTube Server</string>
<string name="pref_title_background_play">Background Playback</string>
<string name="pref_description_background_play">If enabled, continues to play video in background.</string>
@ -292,18 +287,7 @@
<string name="video_speed_10">Normal</string>
<string name="video_speed_15">1.5x</string>
<string name="video_speed_20">2x</string>
<string name="video_option_speed_icon" translatable="false">{faw-play-circle}</string>
<string name="video_option_quality_icon" translatable="false">{faw-cog}</string>
<string name="video_speed_active_icon" translatable="false">{faw-check}</string>
<string name="video_quality_active_icon" translatable="false">{faw-check}</string>
<string name="video_expand_icon" translatable="false">{faw-expand}</string>
<string name="video_compress_icon" translatable="false">{faw-compress}</string>
<string name="video_more_icon" translatable="false">{faw-ellipsis-v}</string>
<string name="video_thumbs_up_icon" translatable="false">{faw-thumbs-up}</string>
<string name="video_thumbs_down_icon" translatable="false">{faw-thumbs-down}</string>
<string name="video_share_icon" translatable="false">{faw-share}</string>
<string name="video_download_icon" translatable="false">{faw-download}</string>
<string name="video_save_icon" translatable="false">{faw-save}</string>
<string name="action_set_url">Select Server</string>
<string name="server_selection_signup_allowed">Signup Allowed: %s</string>
<string name="server_selection_signup_allowed_yes">Yes</string>
@ -352,10 +336,7 @@
<string name="server_book_add_password">Password</string>
<string name="server_book_add_add_button">Add</string>
<string name="server_book_list_has_login">Has Login</string>
<string name="video_rating_none" translatable="false">none</string>
<string name="video_rating_like" translatable="false">like</string>
<string name="video_rating_dislike" translatable="false">dislike</string>
<string name="peertube_required_server_version" translatable="false">1.0.0-alpha.7</string>
<string name="login_current_server_hint">Current Server</string>
<string name="title_activity_server_address_book">Address Book</string>
<string name="video_speed_075">0.75x</string>
@ -372,18 +353,9 @@
<string name="settings_activity_about_category_title">About</string>
<string name="settings_activity_look_and_feel_category_title"><![CDATA[Look & Feel]]></string>
<string name="peertube_instance_search_default_description" translatable="false">PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.</string>
<string name="server_selection_nsfw_instance">NSFW Instance</string>
<string name="server_selection_video_totals">Videos: %s, Local Videos: %s</string>
<!-- Constants, Don't translate -->
<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_expiration" translatable="false">pref_token_expiration</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_password" translatable="false">pref_auth_password</string>
<string name="menu_video_options_quality_automated">Automated</string>