Show an alert/dialog when no appropriate file-manager was found

This commit is contained in:
litetex 2021-11-27 15:52:54 +01:00
parent aec26e951a
commit 9285958b4f
8 changed files with 114 additions and 20 deletions

View file

@ -1,6 +1,7 @@
package org.schabi.newpipe.local.subscription
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.BroadcastReceiver
import android.content.Context
import android.content.DialogInterface
@ -8,6 +9,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
@ -55,6 +57,7 @@ import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_MODE
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.PREVIOUS_EXPORT_MODE
import org.schabi.newpipe.streams.io.NoFileManagerHelper
import org.schabi.newpipe.streams.io.StoredFileHelper
import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.OnClickGesture
@ -179,16 +182,26 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
}
private fun onImportPreviousSelected() {
requestImportLauncher.launch(StoredFileHelper.getPicker(activity, JSON_MIME_TYPE))
try {
requestImportLauncher.launch(StoredFileHelper.getPicker(activity, JSON_MIME_TYPE))
} catch (aex: ActivityNotFoundException) {
Log.w(TAG, "Unable to launch file-picker", aex)
NoFileManagerHelper.showActivityNotFoundAlert(context)
}
}
private fun onExportSelected() {
val date = SimpleDateFormat("yyyyMMddHHmm", Locale.ENGLISH).format(Date())
val exportName = "newpipe_subscriptions_$date.json"
requestExportLauncher.launch(
StoredFileHelper.getNewPicker(activity, exportName, JSON_MIME_TYPE, null)
)
try {
requestExportLauncher.launch(
StoredFileHelper.getNewPicker(activity, exportName, JSON_MIME_TYPE, null)
)
} catch (aex: ActivityNotFoundException) {
Log.w(TAG, "Unable to launch file-picker", aex)
NoFileManagerHelper.showActivityNotFoundAlert(context)
}
}
private fun openReorderDialog() {

View file

@ -1,10 +1,12 @@
package org.schabi.newpipe.local.subscription;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -30,6 +32,7 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService;
import org.schabi.newpipe.streams.io.NoFileManagerHelper;
import org.schabi.newpipe.streams.io.StoredFileHelper;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ServiceHelper;
@ -175,8 +178,14 @@ public class SubscriptionsImportFragment extends BaseFragment {
}
public void onImportFile() {
// leave */* mime type to support all services with different mime types and file extensions
requestImportFileLauncher.launch(StoredFileHelper.getPicker(activity, "*/*"));
try {
// leave */* mime type to support all services
// with different mime types and file extensions
requestImportFileLauncher.launch(StoredFileHelper.getPicker(activity, "*/*"));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch file-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
}
private void requestImportFileResult(final ActivityResult result) {