From 686d34b928ef7b09045d351f3896ff3c7a5d5da1 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sat, 27 Jun 2020 23:28:52 +0200 Subject: [PATCH] - Updated Preferences to new version - https://github.com/sschueller/peertube-android/issues/187 , https://github.com/sschueller/peertube-android/issues/177 - Fixed layouts missing appbar - https://github.com/sschueller/peertube-android/issues/183 - Cleaned up manifest --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 31 +-- .../peertube/activity/MeActivity.java | 2 - .../activity/SelectServerActivity.java | 17 +- .../activity/ServerAddressBookActivity.java | 16 ++ .../peertube/activity/SettingsActivity.java | 205 +----------------- app/src/main/res/layout/activity_account.xml | 2 +- app/src/main/res/layout/activity_me.xml | 2 - .../layout/activity_server_address_book.xml | 16 ++ .../res/layout/activity_server_selection.xml | 55 ++--- app/src/main/res/layout/activity_settings.xml | 9 + app/src/main/res/values/strings.xml | 10 + app/src/main/res/xml/backup_descriptor.xml | 4 + app/src/main/res/xml/root_preferences.xml | 84 +++++++ 14 files changed, 217 insertions(+), 238 deletions(-) create mode 100644 app/src/main/res/layout/activity_settings.xml create mode 100644 app/src/main/res/xml/backup_descriptor.xml create mode 100644 app/src/main/res/xml/root_preferences.xml diff --git a/app/build.gradle b/app/build.gradle index 6016cfa..8ccfc90 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -85,6 +85,7 @@ android { } dependencies { + def room_version = "2.2.5" def archLifecycleVersion = '2.1.0' @@ -104,4 +105,5 @@ dependencies { implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion" annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$archLifecycleVersion" + implementation 'androidx.preference:preference:1.1.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 32125e5..ee09a9b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,19 +2,26 @@ - + + + + + + + + android:theme="@style/AppTheme.NoActionBar" /> - + + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:label="@string/title_activity_select_server" + android:theme="@style/AppTheme.NoActionBar" /> + android:label="@string/title_activity_me" + android:theme="@style/AppTheme.NoActionBar" /> - - - - - + \ No newline at end of file diff --git a/app/src/main/java/net/schueller/peertube/activity/MeActivity.java b/app/src/main/java/net/schueller/peertube/activity/MeActivity.java index 572bb68..9e0c6da 100644 --- a/app/src/main/java/net/schueller/peertube/activity/MeActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/MeActivity.java @@ -20,7 +20,6 @@ package net.schueller.peertube.activity; import android.content.Intent; import android.net.Uri; -import android.nfc.Tag; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -108,7 +107,6 @@ public class MeActivity extends CommonActivity { logout.setOnClickListener(view -> { Session.getInstance().invalidate(); account.setVisibility(View.GONE); - }); getUserData(); 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 26d56f2..a4c6186 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java @@ -19,6 +19,7 @@ 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; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; @@ -48,11 +49,12 @@ 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 AppCompatActivity { +public class SelectServerActivity extends CommonActivity { private ServerAdapter serverAdapter; private SwipeRefreshLayout swipeRefreshLayout; @@ -65,11 +67,24 @@ public class SelectServerActivity extends AppCompatActivity { private boolean isLoading = false; + @Override + public boolean onSupportNavigateUp() { + finish(); // close this activity as oppose to navigating up + return false; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_server_selection); + // Attaching the layout to the toolbar object + Toolbar toolbar = findViewById(R.id.tool_bar_server_selection); + // Setting toolbar as the ActionBar with setSupportActionBar() call + setSupportActionBar(toolbar); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_baseline_close_24); + loadList(); } diff --git a/app/src/main/java/net/schueller/peertube/activity/ServerAddressBookActivity.java b/app/src/main/java/net/schueller/peertube/activity/ServerAddressBookActivity.java index 8d2f934..3cbe68d 100644 --- a/app/src/main/java/net/schueller/peertube/activity/ServerAddressBookActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/ServerAddressBookActivity.java @@ -21,12 +21,15 @@ import android.app.AlertDialog; import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.widget.EditText; import com.google.android.material.floatingactionbutton.FloatingActionButton; import androidx.annotation.NonNull; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; @@ -40,6 +43,7 @@ import net.schueller.peertube.database.Server; import net.schueller.peertube.database.ServerViewModel; import net.schueller.peertube.fragment.AddServerFragment; +import java.util.Objects; public class ServerAddressBookActivity extends CommonActivity implements AddServerFragment.OnFragmentInteractionListener { @@ -51,11 +55,23 @@ public class ServerAddressBookActivity extends CommonActivity implements AddServ private FloatingActionButton floatingActionButton; private FragmentManager fragmentManager; + @Override + public boolean onSupportNavigateUp() { + finish(); // close this activity as oppose to navigating up + return false; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_server_address_book); + // Attaching the layout to the toolbar object + Toolbar toolbar = findViewById(R.id.tool_bar_server_address_book); + // Setting toolbar as the ActionBar with setSupportActionBar() call + setSupportActionBar(toolbar); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_baseline_close_24); mServerViewModel = new ViewModelProvider(this).get(ServerViewModel.class); diff --git a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java index c8be62b..52db457 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java @@ -15,220 +15,39 @@ * 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.annotation.TargetApi; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; -import android.preference.Preference; import androidx.appcompat.app.ActionBar; - -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; -import android.view.MenuItem; -import android.widget.Toast; +import androidx.appcompat.widget.Toolbar; +import androidx.preference.PreferenceFragmentCompat; import net.schueller.peertube.R; -import java.util.List; +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 SettingsActivity extends AppCompatPreferenceActivity { - - private static String previousThemeColorValue = ""; - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - this.finish(); - return true; - } - return super.onOptionsItemSelected(item); - } - - private static String getSelectedColor(Context context, String colorId) { - - String res = "Color not found"; - String[] themeArray = context.getResources().getStringArray(R.array.themeValues); - String[] colorArray = context.getResources().getStringArray(R.array.themeArray); - - for (int i = 0; i < themeArray.length; i++) { - if (themeArray[i].equals(colorId)) { - res = colorArray[i]; - break; - } - } - return res; - } - - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = (preference, value) -> { - String stringValue = value.toString(); - - // check URL is valid -// if (preference.getKey().equals("pref_api_base") && !Patterns.WEB_URL.matcher(stringValue).matches()) { -// Toast.makeText(preference.getContext(), R.string.invalid_url, Toast.LENGTH_LONG).show(); -// return false; -// } - // Check if Theme color has change & Provide selected color - if (preference.getKey().equals("pref_theme")) { - - stringValue = getSelectedColor(preference.getContext(), stringValue); - - if (!previousThemeColorValue.equals("") && !previousThemeColorValue.equals(stringValue)) { - Toast.makeText(preference.getContext(), R.string.pref_description_app_theme, Toast.LENGTH_LONG).show(); - } - - previousThemeColorValue = stringValue; - preference.setSummary(stringValue); - return true; - } - - preference.setSummary(stringValue); - - return true; - }; - - /** - * Helper method to determine if the device has an extra-large screen. For - * example, 10" tablets are extra-large. - */ - private static boolean isXLargeTablet(Context context) { - return (context.getResources().getConfiguration().screenLayout - & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; - } - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - * @see #sBindPreferenceSummaryToValueListener - */ - private static void bindPreferenceSummaryToValue(Preference preference) { - // Set the listener to watch for value changes. - preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } +public class SettingsActivity extends CommonActivity { @Override protected void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - setupActionBar(); - getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit(); - } - - /** - * Set up the {@link android.app.ActionBar}, if the API is available. - */ - private void setupActionBar() { + setContentView(R.layout.activity_settings); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.settings, new SettingsFragment()) + .commit(); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { - // Show the Up button in the action bar. actionBar.setDisplayHomeAsUpEnabled(true); } } - /** - * {@inheritDoc} - */ - @Override - public boolean onIsMultiPane() { - return isXLargeTablet(this); - } - - /** - * {@inheritDoc} - */ - @Override - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void onBuildHeaders(List
target) { - //loadHeadersFromResource(R.xml.pref_headers, target); - } - - /** - * This method stops fragment injection in malicious applications. - * Make sure to deny any unknown fragments here. - */ - protected boolean isValidFragment(String fragmentName) { - return PreferenceFragment.class.getName().equals(fragmentName) - || GeneralPreferenceFragment.class.getName().equals(fragmentName); - } - - /** - * This fragment shows general preferences only. It is used when the - * activity is showing a two-pane mainmenu UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class GeneralPreferenceFragment extends PreferenceFragment { + public static class SettingsFragment extends PreferenceFragmentCompat { @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_general); - setHasOptionsMenu(true); - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - //bindPreferenceSummaryToValue(findPreference("pref_api_base")); - bindPreferenceSummaryToValue(findPreference("pref_theme")); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, - Preference preference) { -// String key = preference.getKey(); -// if ("pref_api_base".equals(key)) { -// Intent intentServer = new Intent(preference.getContext(), SelectServerActivity.class); -// startActivity(intentServer); -// return true; -// } - return false; - } - - @Override - public void onResume() { - setPreferenceScreen(null); - addPreferencesFromResource(R.xml.pref_general); - //bindPreferenceSummaryToValue(findPreference("pref_api_base")); - - super.onResume(); + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.root_preferences, rootKey); } } - } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index 0a1283b..15c39b9 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -18,7 +18,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="4dp" - app:layout_scrollFlags="scroll|enterAlways" /> + /> diff --git a/app/src/main/res/layout/activity_me.xml b/app/src/main/res/layout/activity_me.xml index 6c694c0..ac01ec2 100644 --- a/app/src/main/res/layout/activity_me.xml +++ b/app/src/main/res/layout/activity_me.xml @@ -5,7 +5,6 @@ android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".activity.MeActivity" - android:orientation="vertical"> diff --git a/app/src/main/res/layout/activity_server_address_book.xml b/app/src/main/res/layout/activity_server_address_book.xml index b085710..5de5eb8 100644 --- a/app/src/main/res/layout/activity_server_address_book.xml +++ b/app/src/main/res/layout/activity_server_address_book.xml @@ -7,6 +7,22 @@ tools:context=".activity.ServerAddressBookActivity" android:id="@+id/server_book"> + + + + + + + - + android:orientation="vertical"> - + android:layout_height="wrap_content" + android:elevation="4dp" + app:layout_scrollFlags="scroll|enterAlways" /> - + - + - + - + - + + + - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000..de6591a --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 123efdd..9a70782 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -363,6 +363,16 @@ Remove Server Are you sure you want to remove this server from the address book? + Select Server + Account + SettingsActivity2 + + Video List + Video Playback + About + + + pref_token_access pref_token_refresh diff --git a/app/src/main/res/xml/backup_descriptor.xml b/app/src/main/res/xml/backup_descriptor.xml new file mode 100644 index 0000000..6fd6103 --- /dev/null +++ b/app/src/main/res/xml/backup_descriptor.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml new file mode 100644 index 0000000..e60c6cf --- /dev/null +++ b/app/src/main/res/xml/root_preferences.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file