Refactoring + deduplicated code

This commit is contained in:
litetex 2021-11-28 14:07:45 +01:00
parent 273e0e7f06
commit 625ffba8b7
8 changed files with 134 additions and 112 deletions

View file

@ -1,7 +1,6 @@
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
@ -9,7 +8,6 @@ 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
@ -57,7 +55,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.NoFileManagerSafeGuard
import org.schabi.newpipe.streams.io.StoredFileHelper
import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.OnClickGesture
@ -182,26 +180,24 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
}
private fun onImportPreviousSelected() {
try {
requestImportLauncher.launch(StoredFileHelper.getPicker(activity, JSON_MIME_TYPE))
} catch (aex: ActivityNotFoundException) {
Log.w(TAG, "Unable to launch file picker", aex)
NoFileManagerHelper.showActivityNotFoundAlert(context)
}
NoFileManagerSafeGuard.launchSafe(
requestImportLauncher,
StoredFileHelper.getPicker(activity, JSON_MIME_TYPE),
TAG,
requireContext()
)
}
private fun onExportSelected() {
val date = SimpleDateFormat("yyyyMMddHHmm", Locale.ENGLISH).format(Date())
val exportName = "newpipe_subscriptions_$date.json"
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)
}
NoFileManagerSafeGuard.launchSafe(
requestExportLauncher,
StoredFileHelper.getNewPicker(activity, exportName, JSON_MIME_TYPE, null),
TAG,
requireContext()
)
}
private fun openReorderDialog() {

View file

@ -1,12 +1,10 @@
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;
@ -32,7 +30,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.NoFileManagerSafeGuard;
import org.schabi.newpipe.streams.io.StoredFileHelper;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ServiceHelper;
@ -178,14 +176,14 @@ public class SubscriptionsImportFragment extends BaseFragment {
}
public void onImportFile() {
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());
}
NoFileManagerSafeGuard.launchSafe(
requestImportFileLauncher,
// leave */* mime type to support all services
// with different mime types and file extensions
StoredFileHelper.getPicker(activity, "*/*"),
TAG,
getContext()
);
}
private void requestImportFileResult(final ActivityResult result) {