From dfb4c82c59cdb246400e7c63f6b6615a6ba2820f Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 2 Nov 2019 19:57:42 +0100 Subject: [PATCH] Add opml import/export preference in account preferences and open android file dialog --- .../settings/AccountSettingsFragment.java | 30 +++++++++++++++++++ .../main/res/drawable/ic_import_export.xml | 5 ++++ app/src/main/res/values-fr-rFR/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/acount_preferences.xml | 5 ++++ 5 files changed, 42 insertions(+) create mode 100644 app/src/main/res/drawable/ic_import_export.xml diff --git a/app/src/main/java/com/readrops/app/fragments/settings/AccountSettingsFragment.java b/app/src/main/java/com/readrops/app/fragments/settings/AccountSettingsFragment.java index 6f00ac16..1448ffcf 100644 --- a/app/src/main/java/com/readrops/app/fragments/settings/AccountSettingsFragment.java +++ b/app/src/main/java/com/readrops/app/fragments/settings/AccountSettingsFragment.java @@ -2,6 +2,7 @@ package com.readrops.app.fragments.settings; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.widget.Toast; @@ -23,6 +24,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.observers.DisposableCompletableObserver; import io.reactivex.schedulers.Schedulers; +import static android.app.Activity.RESULT_OK; import static com.readrops.app.utils.ReadropsKeys.ACCOUNT; import static com.readrops.app.utils.ReadropsKeys.EDIT_ACCOUNT; @@ -31,6 +33,8 @@ import static com.readrops.app.utils.ReadropsKeys.EDIT_ACCOUNT; */ public class AccountSettingsFragment extends PreferenceFragmentCompat { + public static final int OPEN_OPML_FILE_REQUEST = 1; + private Account account; private AccountViewModel viewModel; @@ -57,10 +61,14 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat { Preference feedsFoldersPref = findPreference("feeds_folders_key"); Preference credentialsPref = findPreference("credentials_key"); Preference deleteAccountPref = findPreference("delete_account_key"); + Preference opmlPref = findPreference("opml_import_export"); if (account.is(AccountType.LOCAL)) credentialsPref.setVisible(false); + if (!account.is(AccountType.LOCAL)) + opmlPref.setVisible(false); + feedsFoldersPref.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(getContext(), ManageFeedsFoldersActivity.class); intent.putExtra(ACCOUNT, account); @@ -83,6 +91,11 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat { deleteAccount(); return true; }); + + opmlPref.setOnPreferenceClickListener(preference -> { + openOPMLFile(); + return true; + }); } @Override @@ -113,4 +126,21 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat { }))) .show(); } + + private void openOPMLFile() { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("application/*"); + + getActivity().startActivityForResult(intent, OPEN_OPML_FILE_REQUEST); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if (requestCode == OPEN_OPML_FILE_REQUEST && requestCode == RESULT_OK && data != null) { + Uri uri = data.getData(); + } + + super.onActivityResult(requestCode, resultCode, data); + } } diff --git a/app/src/main/res/drawable/ic_import_export.xml b/app/src/main/res/drawable/ic_import_export.xml new file mode 100644 index 00000000..99f71b7f --- /dev/null +++ b/app/src/main/res/drawable/ic_import_export.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index 635aa8d0..6afff704 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -93,5 +93,6 @@ Navigateur externe Actualiser Partager le lien + Import/Export OPML \ 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 266784d7..beb47a99 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,4 +101,5 @@ External navigator Actualize Share url + OPML Import/Export diff --git a/app/src/main/res/xml/acount_preferences.xml b/app/src/main/res/xml/acount_preferences.xml index 09213ebc..96ee94b5 100644 --- a/app/src/main/res/xml/acount_preferences.xml +++ b/app/src/main/res/xml/acount_preferences.xml @@ -11,6 +11,11 @@ android:key="credentials_key" android:title="@string/credentials" /> + +