mirror of https://github.com/readrops/Readrops.git
Use more mime types to open opml files
This commit is contained in:
parent
f7a78df815
commit
594a0a67fa
|
@ -0,0 +1,27 @@
|
||||||
|
package com.readrops.api.opml
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
|
||||||
|
object OPMLHelper {
|
||||||
|
|
||||||
|
const val OPEN_OPML_FILE_REQUEST = 1
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun openFileIntent(activity: Activity) =
|
||||||
|
activity.startActivityForResult(createIntent(), OPEN_OPML_FILE_REQUEST)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun openFileIntent(fragment: Fragment) =
|
||||||
|
fragment.startActivityForResult(createIntent(), OPEN_OPML_FILE_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
private fun createIntent(): Intent {
|
||||||
|
return Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||||
|
addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
|
type = "*/*"
|
||||||
|
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("application/*", "text/*"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.readrops.api.opml.OPMLHelper;
|
||||||
import com.readrops.app.R;
|
import com.readrops.app.R;
|
||||||
import com.readrops.app.adapters.AccountTypeListAdapter;
|
import com.readrops.app.adapters.AccountTypeListAdapter;
|
||||||
import com.readrops.app.databinding.ActivityAccountTypeListBinding;
|
import com.readrops.app.databinding.ActivityAccountTypeListBinding;
|
||||||
|
@ -32,7 +33,7 @@ import io.reactivex.observers.DisposableCompletableObserver;
|
||||||
import io.reactivex.observers.DisposableSingleObserver;
|
import io.reactivex.observers.DisposableSingleObserver;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import static com.readrops.app.fragments.settings.AccountSettingsFragment.OPEN_OPML_FILE_REQUEST;
|
import static com.readrops.api.opml.OPMLHelper.OPEN_OPML_FILE_REQUEST;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT;
|
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT_TYPE;
|
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT_TYPE;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.FROM_MAIN_ACTIVITY;
|
import static com.readrops.app.utils.ReadropsKeys.FROM_MAIN_ACTIVITY;
|
||||||
|
@ -127,11 +128,7 @@ public class AccountTypeListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openOPMLFile(View view) {
|
public void openOPMLFile(View view) {
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
OPMLHelper.openFileIntent(this);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
||||||
intent.setType("application/*");
|
|
||||||
|
|
||||||
startActivityForResult(intent, OPEN_OPML_FILE_REQUEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,6 +22,7 @@ import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.readrops.api.opml.OPMLHelper;
|
||||||
import com.readrops.api.opml.OPMLParser;
|
import com.readrops.api.opml.OPMLParser;
|
||||||
import com.readrops.app.R;
|
import com.readrops.app.R;
|
||||||
import com.readrops.app.ReadropsApp;
|
import com.readrops.app.ReadropsApp;
|
||||||
|
@ -45,6 +46,7 @@ import io.reactivex.observers.DisposableCompletableObserver;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
import static com.readrops.api.opml.OPMLHelper.OPEN_OPML_FILE_REQUEST;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT;
|
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT_ID;
|
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT_ID;
|
||||||
import static com.readrops.app.utils.ReadropsKeys.EDIT_ACCOUNT;
|
import static com.readrops.app.utils.ReadropsKeys.EDIT_ACCOUNT;
|
||||||
|
@ -56,7 +58,6 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
private static final String TAG = AccountSettingsFragment.class.getSimpleName();
|
private static final String TAG = AccountSettingsFragment.class.getSimpleName();
|
||||||
|
|
||||||
public static final int OPEN_OPML_FILE_REQUEST = 1;
|
|
||||||
private static final int WRITE_EXTERNAL_STORAGE_REQUEST = 1;
|
private static final int WRITE_EXTERNAL_STORAGE_REQUEST = 1;
|
||||||
|
|
||||||
private Account account;
|
private Account account;
|
||||||
|
@ -122,7 +123,7 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
||||||
.items(R.array.opml_import_export)
|
.items(R.array.opml_import_export)
|
||||||
.itemsCallback(((dialog, itemView, position, text) -> {
|
.itemsCallback(((dialog, itemView, position, text) -> {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
openOPMLFile();
|
OPMLHelper.openFileIntent(this);
|
||||||
} else {
|
} else {
|
||||||
if (PermissionManager.isPermissionGranted(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
if (PermissionManager.isPermissionGranted(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
||||||
exportAsOPMLFile();
|
exportAsOPMLFile();
|
||||||
|
@ -180,14 +181,6 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
// region opml import
|
// region opml import
|
||||||
|
|
||||||
private void openOPMLFile() {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
||||||
intent.setType("application/*");
|
|
||||||
|
|
||||||
startActivityForResult(intent, OPEN_OPML_FILE_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
if (requestCode == OPEN_OPML_FILE_REQUEST && resultCode == RESULT_OK && data != null) {
|
if (requestCode == OPEN_OPML_FILE_REQUEST && resultCode == RESULT_OK && data != null) {
|
||||||
|
|
|
@ -7,20 +7,18 @@ import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
|
||||||
class PermissionManager {
|
object PermissionManager {
|
||||||
|
|
||||||
companion object {
|
@JvmStatic
|
||||||
@JvmStatic
|
fun isPermissionGranted(context: Context, permission: String): Boolean =
|
||||||
fun isPermissionGranted(context: Context, permission: String): Boolean =
|
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||||
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun requestPermissions(activity: Activity, requestCode: Int, vararg permissions: String) =
|
fun requestPermissions(activity: Activity, requestCode: Int, vararg permissions: String) =
|
||||||
ActivityCompat.requestPermissions(activity, permissions, requestCode)
|
ActivityCompat.requestPermissions(activity, permissions, requestCode)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun requestPermissions(fragment: Fragment, requestCode: Int, vararg permissions: String) =
|
fun requestPermissions(fragment: Fragment, requestCode: Int, vararg permissions: String) =
|
||||||
fragment.requestPermissions(permissions, requestCode)
|
fragment.requestPermissions(permissions, requestCode)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue