1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-09 17:00:32 +00:00

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 ef91214085
commit f78983b16b
8 changed files with 114 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.download; package org.schabi.newpipe.download;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -53,6 +54,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.settings.NewPipeSettings; import org.schabi.newpipe.settings.NewPipeSettings;
import org.schabi.newpipe.streams.io.NoFileManagerHelper;
import org.schabi.newpipe.streams.io.StoredDirectoryHelper; import org.schabi.newpipe.streams.io.StoredDirectoryHelper;
import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.streams.io.StoredFileHelper;
import org.schabi.newpipe.util.FilePickerActivityHelper; import org.schabi.newpipe.util.FilePickerActivityHelper;
@ -687,7 +689,12 @@ public class DownloadDialog extends DialogFragment
} }
private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) { private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) {
launcher.launch(StoredDirectoryHelper.getPicker(context)); try {
launcher.launch(StoredDirectoryHelper.getPicker(context));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch directory-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
} }
private void prepareSelectedDownload() { private void prepareSelectedDownload() {
@ -766,8 +773,13 @@ public class DownloadDialog extends DialogFragment
initialPath = Uri.parse(initialSavePath.getAbsolutePath()); initialPath = Uri.parse(initialSavePath.getAbsolutePath());
} }
requestDownloadSaveAsLauncher.launch(StoredFileHelper.getNewPicker(context, try {
filenameTmp, mimeTmp, initialPath)); requestDownloadSaveAsLauncher.launch(StoredFileHelper.getNewPicker(context,
filenameTmp, mimeTmp, initialPath));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch file-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
return; return;
} }

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.local.subscription package org.schabi.newpipe.local.subscription
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
@ -8,6 +9,7 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuInflater 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_MODE
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE 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.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.streams.io.StoredFileHelper
import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.OnClickGesture import org.schabi.newpipe.util.OnClickGesture
@ -179,16 +182,26 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
} }
private fun onImportPreviousSelected() { 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() { private fun onExportSelected() {
val date = SimpleDateFormat("yyyyMMddHHmm", Locale.ENGLISH).format(Date()) val date = SimpleDateFormat("yyyyMMddHHmm", Locale.ENGLISH).format(Date())
val exportName = "newpipe_subscriptions_$date.json" val exportName = "newpipe_subscriptions_$date.json"
requestExportLauncher.launch( try {
StoredFileHelper.getNewPicker(activity, exportName, JSON_MIME_TYPE, null) 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() { private fun openReorderDialog() {

View File

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

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -25,6 +26,7 @@ import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.streams.io.NoFileManagerHelper;
import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.streams.io.StoredFileHelper;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PicassoHelper; import org.schabi.newpipe.util.PicassoHelper;
@ -73,19 +75,29 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
final Preference importDataPreference = requirePreference(R.string.import_data); final Preference importDataPreference = requirePreference(R.string.import_data);
importDataPreference.setOnPreferenceClickListener((Preference p) -> { importDataPreference.setOnPreferenceClickListener((Preference p) -> {
requestImportPathLauncher.launch( try {
StoredFileHelper.getPicker(requireContext(), requestImportPathLauncher.launch(
ZIP_MIME_TYPE, getImportExportDataUri())); StoredFileHelper.getPicker(requireContext(),
ZIP_MIME_TYPE, getImportExportDataUri()));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch file-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
return true; return true;
}); });
final Preference exportDataPreference = requirePreference(R.string.export_data); final Preference exportDataPreference = requirePreference(R.string.export_data);
exportDataPreference.setOnPreferenceClickListener((final Preference p) -> { exportDataPreference.setOnPreferenceClickListener((final Preference p) -> {
requestExportPathLauncher.launch( try {
StoredFileHelper.getNewPicker(requireContext(), requestExportPathLauncher.launch(
"NewPipeData-" + exportDateFormat.format(new Date()) + ".zip", StoredFileHelper.getNewPicker(requireContext(),
ZIP_MIME_TYPE, getImportExportDataUri())); "NewPipeData-" + exportDateFormat.format(new Date()) + ".zip",
ZIP_MIME_TYPE, getImportExportDataUri()));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch file-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
return true; return true;
}); });

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -21,6 +22,7 @@ import androidx.preference.SwitchPreferenceCompat;
import com.nononsenseapps.filepicker.Utils; import com.nononsenseapps.filepicker.Utils;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.streams.io.NoFileManagerHelper;
import org.schabi.newpipe.streams.io.StoredDirectoryHelper; import org.schabi.newpipe.streams.io.StoredDirectoryHelper;
import org.schabi.newpipe.util.FilePickerActivityHelper; import org.schabi.newpipe.util.FilePickerActivityHelper;
@ -214,7 +216,12 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
} }
private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) { private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) {
launcher.launch(StoredDirectoryHelper.getPicker(ctx)); try {
launcher.launch(StoredDirectoryHelper.getPicker(ctx));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch directory-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
} }
private void requestDownloadVideoPathResult(final ActivityResult result) { private void requestDownloadVideoPathResult(final ActivityResult result) {

View File

@ -0,0 +1,31 @@
package org.schabi.newpipe.streams.io;
import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import org.schabi.newpipe.R;
/**
* Helper for when no file-manager/activity was found.
*/
public final class NoFileManagerHelper {
private NoFileManagerHelper() {
// No impl
}
/**
* Shows an alert dialog when no file-manager is found.
* @param context Context
*/
public static void showActivityNotFoundAlert(final Context context) {
new AlertDialog.Builder(context)
.setTitle(R.string.no_app_to_open_intent)
.setMessage(
context.getString(
R.string.no_appropriate_file_manager_message,
context.getString(R.string.downloads_storage_use_saf_title)))
.setPositiveButton(R.string.ok, null)
.show();
}
}

View File

@ -1,6 +1,7 @@
package us.shandian.giga.ui.fragment; package us.shandian.giga.ui.fragment;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -10,6 +11,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -32,6 +34,7 @@ import com.nononsenseapps.filepicker.Utils;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.settings.NewPipeSettings; import org.schabi.newpipe.settings.NewPipeSettings;
import org.schabi.newpipe.streams.io.NoFileManagerHelper;
import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.streams.io.StoredFileHelper;
import org.schabi.newpipe.util.FilePickerActivityHelper; import org.schabi.newpipe.util.FilePickerActivityHelper;
@ -46,6 +49,7 @@ import us.shandian.giga.ui.adapter.MissionAdapter;
public class MissionsFragment extends Fragment { public class MissionsFragment extends Fragment {
private static final String TAG = "MissionsFragment";
private static final int SPAN_SIZE = 2; private static final int SPAN_SIZE = 2;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
@ -257,9 +261,14 @@ public class MissionsFragment extends Fragment {
initialPath = Uri.parse(initialSavePath.getAbsolutePath()); initialPath = Uri.parse(initialSavePath.getAbsolutePath());
} }
requestDownloadSaveAsLauncher.launch( try {
StoredFileHelper.getNewPicker(mContext, mission.storage.getName(), requestDownloadSaveAsLauncher.launch(
mission.storage.getType(), initialPath)); StoredFileHelper.getNewPicker(mContext, mission.storage.getName(),
mission.storage.getType(), initialPath));
} catch (final ActivityNotFoundException aex) {
Log.w(TAG, "Unable to launch file-picker", aex);
NoFileManagerHelper.showActivityNotFoundAlert(getContext());
}
} }
@Override @Override

View File

@ -671,6 +671,7 @@
<string name="recent">Recent</string> <string name="recent">Recent</string>
<string name="chapters">Chapters</string> <string name="chapters">Chapters</string>
<string name="no_app_to_open_intent">No app on your device can open this</string> <string name="no_app_to_open_intent">No app on your device can open this</string>
<string name="no_appropriate_file_manager_message">No appropriate file-manager was found for this action.\nPlease install a file-manager or try to enable/disable \'%s\' in the download-settings.</string>
<string name="georestricted_content">This content is not available in your country.</string> <string name="georestricted_content">This content is not available in your country.</string>
<string name="soundcloud_go_plus_content">This is a SoundCloud Go+ track, at least in your country, so it cannot be streamed or downloaded by NewPipe.</string> <string name="soundcloud_go_plus_content">This is a SoundCloud Go+ track, at least in your country, so it cannot be streamed or downloaded by NewPipe.</string>
<string name="private_content">This content is private, so it cannot be streamed or downloaded by NewPipe.</string> <string name="private_content">This content is private, so it cannot be streamed or downloaded by NewPipe.</string>