diff --git a/app/build.gradle b/app/build.gradle
index 34c8f35..fb131f3 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -91,6 +91,8 @@ android {
}
dependencies {
+ implementation 'androidx.preference:preference-ktx:1.1.1'
+
// Testing
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha02'
androidTestImplementation 'androidx.test:runner:1.3.1-alpha02'
@@ -143,7 +145,7 @@ dependencies {
// Themes
implementation 'com.52inc:scoops:1.0.0'
- implementation 'com.jaredrummler:colorpicker:1.0.2'
+ implementation 'com.jaredrummler:colorpicker:1.1.0'
implementation 'com.github.rubensousa:floatingtoolbar:1.5.1'
// Pager
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt
index a92726b..f3e8e10 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt
@@ -4,7 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.appcompat.app.AppCompatActivity
import android.view.View
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt
index bf61874..f4dd346 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt
@@ -9,7 +9,7 @@ import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import android.view.Menu
import android.view.MenuItem
import android.view.View
@@ -171,8 +171,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
handleThemeBinding()
setSupportActionBar(binding.toolBar)
- supportActionBar!!.setDisplayHomeAsUpEnabled(true)
- supportActionBar!!.setHomeButtonEnabled(true)
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ supportActionBar?.setHomeButtonEnabled(true)
val mDrawerToggle = ActionBarDrawerToggle(this, binding.drawerContainer, binding.toolBar, R.string.material_drawer_open, R.string.material_drawer_close)
binding.drawerContainer.addDrawerListener(mDrawerToggle)
mDrawerToggle.syncState()
@@ -514,13 +514,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
iconRes = R.drawable.ic_settings_black_24dp
isIconTinted = true
onDrawerItemClickListener = { _, _, _ ->
- startActivityForResult(
- Intent(
- this@HomeActivity,
- SettingsActivity::class.java
- ),
- MENU_PREFERENCES
- )
+ startActivity(Intent(this@HomeActivity, SettingsActivity::class.java))
false
}
})
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MainActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MainActivity.kt
index d857b1b..a92179a 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/MainActivity.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MainActivity.kt
@@ -2,9 +2,7 @@ package apps.amine.bou.readerforselfoss
import android.content.Intent
import android.os.Bundle
-import android.preference.PreferenceManager
import androidx.appcompat.app.AppCompatActivity
-import apps.amine.bou.readerforselfoss.databinding.ActivityAddSourceBinding
import apps.amine.bou.readerforselfoss.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt
index 1414b74..d44d688 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt
@@ -6,7 +6,7 @@ import android.content.Context
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import android.widget.ImageView
import androidx.multidex.MultiDexApplication
import apps.amine.bou.readerforselfoss.utils.Config
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt
index 3c0419f..8837081 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt
@@ -8,7 +8,7 @@ import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.core.content.ContextCompat
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt
index 80a9da3..492f22c 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt
@@ -5,14 +5,13 @@ import android.content.Intent
import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import android.widget.Toast
import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
import apps.amine.bou.readerforselfoss.api.selfoss.Source
-import apps.amine.bou.readerforselfoss.databinding.ActivityImageBinding
import apps.amine.bou.readerforselfoss.databinding.ActivitySourcesBinding
import apps.amine.bou.readerforselfoss.themes.AppColors
import apps.amine.bou.readerforselfoss.themes.Toppings
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt
index 1f0ba92..59d5648 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt
@@ -5,7 +5,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
import androidx.core.app.NotificationCompat.PRIORITY_LOW
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt
index 11d8503..0514036 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt
@@ -11,7 +11,7 @@ import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import android.view.*
import android.webkit.*
import android.widget.Toast
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java
deleted file mode 100644
index 81eed38..0000000
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/AppCompatPreferenceActivity.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package apps.amine.bou.readerforselfoss.settings;
-
-import android.content.res.Configuration;
-import android.os.Build;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import androidx.annotation.LayoutRes;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import com.google.android.material.appbar.AppBarLayout;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.appcompat.widget.Toolbar;
-import android.view.LayoutInflater;
-import android.view.MenuInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-
-import com.ftinc.scoop.Scoop;
-
-import apps.amine.bou.readerforselfoss.R;
-import apps.amine.bou.readerforselfoss.themes.AppColors;
-import apps.amine.bou.readerforselfoss.themes.Toppings;
-
-
-/**
- * A {@link 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) {
- new AppColors(this);
-
- getDelegate().installViewFactory();
- getDelegate().onCreate(savedInstanceState);
- super.onCreate(savedInstanceState);
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
-
- LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
- AppBarLayout bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- Toolbar toolbar = bar.findViewById(R.id.toolbar);
-
- Scoop scoop = Scoop.getInstance();
- scoop.bind(this, Toppings.PRIMARY.getValue(), toolbar);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.getValue());
- }
-
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setDisplayShowHomeEnabled(true);
-
- root.addView(bar, 0);
-
- getDelegate().onPostCreate(savedInstanceState);
- }
-
- ActionBar getSupportActionBar() {
- return getDelegate().getSupportActionBar();
- }
-
- public void setSupportActionBar(@Nullable Toolbar toolbar) {
- getDelegate().setSupportActionBar(toolbar);
- }
-
- @NonNull
- @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();
- }
-
- @Override
- 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/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java
deleted file mode 100644
index d7ef47b..0000000
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java
+++ /dev/null
@@ -1,345 +0,0 @@
-package apps.amine.bou.readerforselfoss.settings;
-
-
-import android.annotation.TargetApi;
-import android.content.ClipData;
-import android.content.ClipboardManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceFragment;
-import android.preference.PreferenceManager;
-import android.preference.SwitchPreference;
-import androidx.appcompat.app.ActionBar;
-import android.text.Editable;
-import android.text.InputFilter;
-import android.text.Spanned;
-import android.text.TextWatcher;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.widget.Toast;
-
-import java.util.List;
-
-import apps.amine.bou.readerforselfoss.R;
-import apps.amine.bou.readerforselfoss.themes.AppColors;
-import apps.amine.bou.readerforselfoss.utils.Config;
-
-
-/**
- * A {@link PreferenceActivity} that presents a set of application settings. On
- * handset devices, settings are presented as a single list. On tablets,
- * settings are split by category, with category headers shown to the left of
- * the list of settings.
- *
- * See
- * Android Design: Settings for design guidelines and the Settings
- * API Guide for more information on developing a Settings UI.
- */
-public class SettingsActivity extends AppCompatPreferenceActivity {
- /**
- * A preference value change listener that updates the preference's summary
- * to reflect its new value.
- */
- private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object value) {
- String stringValue = value.toString();
- 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(), ""));
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- new AppColors(this);
- super.onCreate(savedInstanceState);
- setupActionBar();
- }
-
- /**
- * Set up the {@link android.app.ActionBar}, if the API is available.
- */
- private void setupActionBar() {
- 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);
-
- AppColors appColors = new AppColors(this);
- if (appColors != null && appColors.isDarkTheme()) {
- for (Header header : target) {
- tryLoadIconDark(header);
- }
- }
- }
-
- private void tryLoadIconDark(Header header){
- try{
- if (header.fragmentArguments != null) {
- String iconDark = header.fragmentArguments.getString("iconDark");
- int iconDarkId = getResources().getIdentifier(iconDark, "drawable", getPackageName());
- if (iconDarkId != 0) {
- header.iconRes = iconDarkId;
- }
- }
- } catch (Exception e) {
- Log.e("SettingsActivity", "Can not load dark icon", e);
- }
- }
-
- /**
- * This method stops fragment injection in malicious applications.
- * Make sure to deny any unknown fragments here.
- */
- @Override
- protected boolean isValidFragment(String fragmentName) {
- return PreferenceFragment.class.getName().equals(fragmentName)
- || GeneralPreferenceFragment.class.getName().equals(fragmentName)
- || ArticleViewerPreferenceFragment.class.getName().equals(fragmentName)
- || OfflinePreferenceFragment.class.getName().equals(fragmentName)
- || ExperimentalPreferenceFragment.class.getName().equals(fragmentName)
- || LinksPreferenceFragment.class.getName().equals(fragmentName)
- || ThemePreferenceFragment.class.getName().equals(fragmentName);
- }
-
- /**
- * This fragment shows general preferences only. It is used when the
- * activity is showing a two-pane settings UI.
- */
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class GeneralPreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_general);
- setHasOptionsMenu(true);
-
- EditTextPreference itemsNumber = (EditTextPreference) findPreference("prefer_api_items_number");
- itemsNumber.getEditText().setFilters(new InputFilter[]{
- new InputFilter() {
-
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
- try {
- int input = Integer.parseInt(dest.toString() + source.toString());
- if (input <= 200 && input > 0)
- return null;
- } catch (NumberFormatException nfe) {
- Toast.makeText(getActivity(), R.string.items_number_should_be_number, Toast.LENGTH_LONG).show();
- }
- return "";
- }
- }
- });
-
- }
- }
-
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class ArticleViewerPreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_viewer);
- setHasOptionsMenu(true);
-
- final EditTextPreference fontSize = (EditTextPreference) findPreference("reader_font_size");
- fontSize.getEditText().addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
-
- @Override
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
-
- @Override
- public void afterTextChanged(Editable editable) {
- try {
- fontSize.getEditText().setTextSize(Integer.parseInt(editable.toString()));
- } catch (NumberFormatException e) {}
- }
- });
- fontSize.getEditText().setFilters(new InputFilter[]{
- new InputFilter() {
-
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
- try {
- int input = Integer.parseInt(dest.toString() + source.toString());
- if (input > 0)
- return null;
- } catch (NumberFormatException nfe) {}
- return "";
- }
- }
- });
- }
- }
-
- /**
- * This fragment shows general preferences only. It is used when the
- * activity is showing a two-pane settings UI.
- */
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class LinksPreferenceFragment extends PreferenceFragment {
- public void openUrl(Uri uri) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(browserIntent);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_links);
- setHasOptionsMenu(true);
-
- findPreference("trackerLink").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- openUrl(Uri.parse(Config.trackerUrl));
- return true;
- }
- });
-
- findPreference("sourceLink").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- openUrl(Uri.parse(Config.sourceUrl));
- return false;
- }
- });
-
- findPreference("translation").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- openUrl(Uri.parse(Config.translationUrl));
- return false;
- }
- });
- }
- }
-
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class ThemePreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_theme);
- setHasOptionsMenu(true);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- if (id == R.id.clear) {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
- SharedPreferences.Editor editor = pref.edit();
- editor.remove("color_primary");
- editor.remove("color_primary_dark");
- editor.remove("color_accent");
- editor.remove("color_accent_dark");
- editor.remove("dark_theme");
- editor.apply();
- getActivity().recreate();
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.settings_theme, menu);
- }
- }
-
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class OfflinePreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_offline);
- setHasOptionsMenu(true);
- }
- }
-
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class ExperimentalPreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_experimental);
- setHasOptionsMenu(true);
- }
- }
-
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- if (id == android.R.id.home) {
- super.onBackPressed();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt
new file mode 100644
index 0000000..6bbdd61
--- /dev/null
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.kt
@@ -0,0 +1,212 @@
+package apps.amine.bou.readerforselfoss.settings
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.text.*
+import androidx.preference.EditTextPreference
+import androidx.preference.PreferenceManager
+import android.view.*
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.widget.addTextChangedListener
+import androidx.preference.Preference
+import androidx.preference.PreferenceFragmentCompat
+import apps.amine.bou.readerforselfoss.R
+import apps.amine.bou.readerforselfoss.utils.Config
+import java.lang.NumberFormatException
+
+private const val TITLE_TAG = "settingsActivityTitle"
+
+class SettingsActivity : AppCompatActivity(),
+ PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) {
+ setTheme(R.style.NoBarDark)
+ }
+ setContentView(R.layout.activity_settings)
+ if (savedInstanceState == null) {
+ supportFragmentManager
+ .beginTransaction()
+ .replace(R.id.settings, MainPreferenceFragment())
+ .commit()
+ } else {
+ title = savedInstanceState.getCharSequence(TITLE_TAG)
+ }
+ supportFragmentManager.addOnBackStackChangedListener {
+ if (supportFragmentManager.backStackEntryCount == 0) {
+ setTitle(R.string.title_activity_settings)
+ }
+ }
+
+ setSupportActionBar(findViewById(R.id.toolbar))
+
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ supportActionBar?.setDisplayShowHomeEnabled(true)
+ supportActionBar?.title = title
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ // Save current activity title so we can set it again after a configuration change
+ outState.putCharSequence(TITLE_TAG, title)
+ }
+
+ override fun onSupportNavigateUp(): Boolean {
+ if (supportFragmentManager.popBackStackImmediate()) {
+ supportActionBar?.title = getText(R.string.title_activity_settings)
+ return true
+ }
+ return super.onSupportNavigateUp()
+ }
+
+ override fun onPreferenceStartFragment(
+ caller: PreferenceFragmentCompat,
+ pref: Preference
+ ): Boolean {
+ // Instantiate the new Fragment
+ val args = pref.extras
+ val fragment = supportFragmentManager.fragmentFactory.instantiate(
+ classLoader,
+ pref.fragment
+ ).apply {
+ arguments = args
+ setTargetFragment(caller, 0)
+ }
+ // Replace the existing Fragment with the new Fragment
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.settings, fragment)
+ .addToBackStack(null)
+ .commit()
+ title = pref.title
+ supportActionBar?.title = title
+ return true
+ }
+
+ class MainPreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_main, rootKey)
+ }
+ }
+
+ class GeneralPreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_general, rootKey)
+
+ val editTextPreference = preferenceManager.findPreference("prefer_api_items_number")
+ editTextPreference?.setOnBindEditTextListener { editText ->
+ editText.inputType = InputType.TYPE_CLASS_NUMBER
+ editText.filters = arrayOf(
+ InputFilter { source, _, _, dest, _, _ ->
+ try {
+ val input: Int = (dest.toString() + source.toString()).toInt()
+ if (input in 1..200) return@InputFilter null
+ } catch (nfe: NumberFormatException) {
+ Toast.makeText(activity, R.string.items_number_should_be_number, Toast.LENGTH_LONG).show()
+ }
+ ""
+ }
+ )
+ }
+ }
+ }
+
+ class ArticleViewerPreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_viewer, rootKey)
+
+ val fontSize = preferenceManager.findPreference("reader_font_size")
+ fontSize?.setOnBindEditTextListener { editText ->
+ editText.inputType = InputType.TYPE_CLASS_NUMBER
+ editText.addTextChangedListener { object : TextWatcher {
+ override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
+ override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
+ override fun afterTextChanged(editable: Editable) {
+ try {
+ editText.textSize = editable.toString().toInt().toFloat()
+ } catch (e: NumberFormatException) {
+ }
+ }
+ } }
+ editText.filters = arrayOf(
+ InputFilter { source, _, _, dest, _, _ ->
+ try {
+ val input = (dest.toString() + source.toString()).toInt()
+ if (input > 0) return@InputFilter null
+ } catch (nfe: NumberFormatException) {
+ }
+ ""
+ }
+ )
+ }
+ }
+ }
+
+ class OfflinePreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_offline, rootKey)
+ }
+ }
+
+ class ThemePreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_theme, rootKey)
+ setHasOptionsMenu(true)
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+ super.onCreateOptionsMenu(menu, inflater)
+ inflater.inflate(R.menu.settings_theme, menu)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ val id = item.itemId
+ if (id == R.id.clear) {
+ val pref = PreferenceManager.getDefaultSharedPreferences(activity)
+ val editor = pref.edit()
+ editor.remove("color_primary")
+ editor.remove("color_primary_dark")
+ editor.remove("color_accent")
+ editor.remove("color_accent_dark")
+ editor.remove("dark_theme")
+ editor.apply()
+ requireActivity().recreate()
+ }
+ return super.onOptionsItemSelected(item)
+ }
+ }
+
+ class LinksPreferenceFragment : PreferenceFragmentCompat() {
+ private fun openUrl(uri: Uri?) {
+ val browserIntent = Intent(Intent.ACTION_VIEW, uri)
+ startActivity(browserIntent)
+ }
+
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_links, rootKey)
+
+ preferenceManager.findPreference("trackerLink")?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ openUrl(Uri.parse(Config.trackerUrl))
+ true
+ }
+
+ preferenceManager.findPreference("sourceLink")?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ openUrl(Uri.parse(Config.sourceUrl))
+ false
+ }
+
+ preferenceManager.findPreference("translation")?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
+ openUrl(Uri.parse(Config.translationUrl))
+ false
+ }
+ }
+ }
+
+ class ExperimentalPreferenceFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.pref_experimental, rootKey)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt
index 85edf56..7eaf998 100644
--- a/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt
+++ b/app/src/main/java/apps/amine/bou/readerforselfoss/themes/AppColors.kt
@@ -2,7 +2,7 @@ package apps.amine.bou.readerforselfoss.themes
import android.app.Activity
import android.content.Context
-import android.preference.PreferenceManager
+import androidx.preference.PreferenceManager
import androidx.annotation.ColorInt
import androidx.appcompat.view.ContextThemeWrapper
import android.util.TypedValue
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..f8bf459
--- /dev/null
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/settings_toolbar.xml b/app/src/main/res/layout/settings_toolbar.xml
deleted file mode 100644
index c9f9325..0000000
--- a/app/src/main/res/layout/settings_toolbar.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index fe98405..f5d5e4a 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -17,6 +17,7 @@
- @style/App.materialDrawerStyle
- @style/Widget.MaterialDrawerHeaderStyle
- @style/ThemeOverlay.AppCompat.Light
+ - @style/PreferenceStyle
@@ -50,5 +52,10 @@
- ?android:textColorPrimary
- ?android:textColorPrimary
+
+
+
diff --git a/app/src/main/res/xml/pref_experimental.xml b/app/src/main/res/xml/pref_experimental.xml
index aa43f30..bc7569e 100644
--- a/app/src/main/res/xml/pref_experimental.xml
+++ b/app/src/main/res/xml/pref_experimental.xml
@@ -1,9 +1,11 @@
-
+
+ android:title="@string/pref_api_timeout"
+ app:iconSpaceReserved="false"/>
diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml
index d4324f1..450f81e 100644
--- a/app/src/main/res/xml/pref_general.xml
+++ b/app/src/main/res/xml/pref_general.xml
@@ -1,4 +1,5 @@
-
+
@@ -10,7 +11,8 @@
android:key="prefer_api_items_number"
android:selectAllOnFocus="true"
android:singleLine="true"
- android:title="@string/pref_api_items_number_title" />
+ android:title="@string/pref_api_items_number_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/pref_hidden_tags"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/pref_general_infinite_loading_title"
+ app:iconSpaceReserved="false"/>
@@ -33,21 +37,24 @@
android:key="prefer_internal_browser"
android:summaryOff="@string/pref_general_internal_browser_off"
android:summaryOn="@string/pref_general_internal_browser_on"
- android:title="@string/pref_general_internal_browser_title" />
+ android:title="@string/pref_general_internal_browser_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/prefer_article_viewer_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/reader_static_bar_title"
+ app:iconSpaceReserved="false"/>
@@ -57,29 +64,34 @@
android:defaultValue="false"
android:key="account_header_displaying"
android:summary="@string/display_header_drawer_summary"
- android:title="@string/display_header_drawer_title" />
+ android:title="@string/display_header_drawer_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/pref_switch_card_view_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/card_height_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/switch_unread_count_title"
+ app:iconSpaceReserved="false"/>
+ android:title="@string/display_all_counts_title"
+ app:iconSpaceReserved="false"/>
diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml
deleted file mode 100644
index 9197971..0000000
--- a/app/src/main/res/xml/pref_headers.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/xml/pref_links.xml b/app/src/main/res/xml/pref_links.xml
index 262feaa..7d8387f 100644
--- a/app/src/main/res/xml/pref_links.xml
+++ b/app/src/main/res/xml/pref_links.xml
@@ -1,13 +1,17 @@
-
+
+ android:key="trackerLink"
+ app:iconSpaceReserved="false"/>
+ android:key="sourceLink"
+ app:iconSpaceReserved="false"/>
+ android:key="translation"
+ app:iconSpaceReserved="false"/>
\ No newline at end of file
diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml
new file mode 100644
index 0000000..87c566c
--- /dev/null
+++ b/app/src/main/res/xml/pref_main.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/pref_offline.xml b/app/src/main/res/xml/pref_offline.xml
index 875b3e4..a5418f4 100644
--- a/app/src/main/res/xml/pref_offline.xml
+++ b/app/src/main/res/xml/pref_offline.xml
@@ -1,7 +1,9 @@
-
+
+
@@ -10,6 +12,7 @@
android:defaultValue="false"
android:key="periodic_refresh"
android:dependency="items_caching"
+ app:iconSpaceReserved="false"
android:summaryOff="@string/pref_switch_periodic_refresh_off"
android:summaryOn="@string/pref_switch_periodic_refresh_on"
android:title="@string/pref_switch_periodic_refresh" />
@@ -18,6 +21,7 @@
android:dependency="periodic_refresh"
android:defaultValue="360"
android:inputType="number"
+ app:iconSpaceReserved="false"
android:key="periodic_refresh_minutes"
android:selectAllOnFocus="true"
android:singleLine="true"
@@ -25,18 +29,21 @@
diff --git a/app/src/main/res/xml/pref_theme.xml b/app/src/main/res/xml/pref_theme.xml
index 69565f4..fb86ec3 100644
--- a/app/src/main/res/xml/pref_theme.xml
+++ b/app/src/main/res/xml/pref_theme.xml
@@ -1,29 +1,35 @@
-
+
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/xml/pref_viewer.xml b/app/src/main/res/xml/pref_viewer.xml
index 47889af..55a6dcc 100644
--- a/app/src/main/res/xml/pref_viewer.xml
+++ b/app/src/main/res/xml/pref_viewer.xml
@@ -1,7 +1,9 @@
-
+
@@ -10,6 +12,7 @@
android:defaultValue="16"
android:inputType="number"
android:key="reader_font_size"
+ app:iconSpaceReserved="false"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_content_reader_font_size" />
@@ -18,5 +21,6 @@
android:entries="@array/preloaded_fonts_values"
android:entryValues="@array/preloaded_fonts_keys"
android:key="reader_font"
+ app:iconSpaceReserved="false"
android:title="@string/settings_reader_font" />