Merge branch 'dev' into pr2335

This commit is contained in:
Stypox 2021-12-31 19:20:18 +01:00
commit cd95ec4e12
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
107 changed files with 1434 additions and 832 deletions

View file

@ -18,7 +18,7 @@ import java.util.Objects;
public abstract class BasePreferenceFragment extends PreferenceFragmentCompat {
protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode());
protected final boolean DEBUG = MainActivity.DEBUG;
protected static final boolean DEBUG = MainActivity.DEBUG;
SharedPreferences defaultPreferences;

View file

@ -20,11 +20,12 @@ import androidx.preference.PreferenceManager;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;
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.PicassoHelper;
@ -73,19 +74,28 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
final Preference importDataPreference = requirePreference(R.string.import_data);
importDataPreference.setOnPreferenceClickListener((Preference p) -> {
requestImportPathLauncher.launch(
NoFileManagerSafeGuard.launchSafe(
requestImportPathLauncher,
StoredFileHelper.getPicker(requireContext(),
ZIP_MIME_TYPE, getImportExportDataUri()));
ZIP_MIME_TYPE, getImportExportDataUri()),
TAG,
getContext()
);
return true;
});
final Preference exportDataPreference = requirePreference(R.string.export_data);
exportDataPreference.setOnPreferenceClickListener((final Preference p) -> {
requestExportPathLauncher.launch(
NoFileManagerSafeGuard.launchSafe(
requestExportPathLauncher,
StoredFileHelper.getNewPicker(requireContext(),
"NewPipeData-" + exportDateFormat.format(new Date()) + ".zip",
ZIP_MIME_TYPE, getImportExportDataUri()));
ZIP_MIME_TYPE, getImportExportDataUri()),
TAG,
getContext()
);
return true;
});
@ -205,7 +215,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
saveLastImportExportDataUri(exportDataUri); // save export path only on success
Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e);
ErrorUtil.showUiErrorSnackbar(this, "Exporting database", e);
}
}
@ -247,7 +257,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
finishImport(importDataUri);
}
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Importing database", e);
ErrorUtil.showUiErrorSnackbar(this, "Importing database", e);
}
}

View file

@ -21,6 +21,7 @@ import androidx.preference.SwitchPreferenceCompat;
import com.nononsenseapps.filepicker.Utils;
import org.schabi.newpipe.R;
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard;
import org.schabi.newpipe.streams.io.StoredDirectoryHelper;
import org.schabi.newpipe.util.FilePickerActivityHelper;
@ -214,7 +215,12 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
}
private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) {
launcher.launch(StoredDirectoryHelper.getPicker(ctx));
NoFileManagerSafeGuard.launchSafe(
launcher,
StoredDirectoryHelper.getPicker(ctx),
TAG,
ctx
);
}
private void requestDownloadVideoPathResult(final ActivityResult result) {

View file

@ -9,8 +9,8 @@ import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.InfoCache;
@ -64,7 +64,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.watch_history_states_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context,
throwable -> ErrorUtil.openActivity(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete playback states")));
}
@ -76,7 +76,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.watch_history_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context,
throwable -> ErrorUtil.openActivity(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete from history")));
}
@ -87,7 +87,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> { },
throwable -> ErrorActivity.reportError(context,
throwable -> ErrorUtil.openActivity(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Clear orphaned records")));
}
@ -99,7 +99,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.search_history_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context,
throwable -> ErrorUtil.openActivity(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete search history")));
}

View file

@ -11,8 +11,8 @@ import io.reactivex.rxjava3.disposables.Disposable
import org.schabi.newpipe.R
import org.schabi.newpipe.database.subscription.NotificationMode
import org.schabi.newpipe.database.subscription.SubscriptionEntity
import org.schabi.newpipe.error.ErrorActivity
import org.schabi.newpipe.error.ErrorInfo
import org.schabi.newpipe.error.ErrorUtil
import org.schabi.newpipe.error.UserAction
import org.schabi.newpipe.local.feed.notifications.NotificationHelper
import org.schabi.newpipe.local.feed.notifications.NotificationWorker
@ -118,7 +118,7 @@ class NotificationsSettingsFragment : BasePreferenceFragment(), OnSharedPreferen
}
private fun onError(e: Throwable) {
ErrorActivity.reportErrorInSnackbar(
ErrorUtil.showSnackbar(
this,
ErrorInfo(e, UserAction.SUBSCRIPTION_GET, "Get subscriptions list")
)

View file

@ -16,7 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.local.subscription.SubscriptionManager;
import org.schabi.newpipe.util.PicassoHelper;
import org.schabi.newpipe.util.ThemeHelper;
@ -153,7 +153,7 @@ public class SelectChannelFragment extends DialogFragment {
@Override
public void onError(@NonNull final Throwable exception) {
ErrorActivity.reportUiErrorInSnackbar(SelectChannelFragment.this,
ErrorUtil.showUiErrorSnackbar(SelectChannelFragment.this,
"Loading subscription", exception);
}

View file

@ -16,7 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.util.KioskTranslator;
@ -48,7 +48,6 @@ import java.util.Vector;
*/
public class SelectKioskFragment extends DialogFragment {
private RecyclerView recyclerView = null;
private SelectKioskAdapter selectKioskAdapter = null;
private OnSelectedListener onSelectedListener = null;
@ -76,12 +75,12 @@ public class SelectKioskFragment extends DialogFragment {
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.select_kiosk_fragment, container, false);
recyclerView = v.findViewById(R.id.items_list);
final RecyclerView recyclerView = v.findViewById(R.id.items_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
try {
selectKioskAdapter = new SelectKioskAdapter();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Selecting kiosk", e);
ErrorUtil.showUiErrorSnackbar(this, "Selecting kiosk", e);
}
recyclerView.setAdapter(selectKioskAdapter);

View file

@ -1,6 +1,5 @@
package org.schabi.newpipe.settings;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -21,8 +20,8 @@ import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.PlaylistLocalItem;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
@ -105,8 +104,7 @@ public class SelectPlaylistFragment extends DialogFragment {
}
protected void onError(final Throwable e) {
final Activity activity = requireActivity();
ErrorActivity.reportErrorInSnackbar(activity, new ErrorInfo(e,
ErrorUtil.showSnackbar(requireActivity(), new ErrorInfo(e,
UserAction.UI_ERROR, "Loading playlists"));
}

View file

@ -8,8 +8,8 @@ import android.util.Log;
import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.util.DeviceUtils;
@ -157,7 +157,7 @@ public final class SettingMigrations {
} catch (final Exception e) {
// save the version with the last successful migration and report the error
sp.edit().putInt(lastPrefVersionKey, currentVersion).apply();
ErrorActivity.reportError(context, new ErrorInfo(
ErrorUtil.openActivity(context, new ErrorInfo(
e,
UserAction.PREFERENCES_MIGRATION,
"Migrating preferences from version " + lastPrefVersion + " to "

View file

@ -27,8 +27,8 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.settings.SelectChannelFragment;
@ -182,7 +182,7 @@ public class ChooseTabsFragment extends Fragment {
final Tab.Type type = typeFrom(tabId);
if (type == null) {
ErrorActivity.reportErrorInSnackbar(this,
ErrorUtil.showSnackbar(this,
new ErrorInfo(new IllegalStateException("Tab id not found: " + tabId),
UserAction.SOMETHING_ELSE, "Choosing tabs on settings"));
return;

View file

@ -12,8 +12,8 @@ import com.grack.nanojson.JsonSink;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem.LocalItemType;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
@ -36,6 +36,10 @@ import java.util.Objects;
public abstract class Tab {
private static final String JSON_TAB_ID_KEY = "tab_id";
private static final String NO_NAME = "<no-name>";
private static final String NO_ID = "<no-id>";
private static final String NO_URL = "<no-url>";
Tab() {
}
@ -185,7 +189,9 @@ public abstract class Tab {
@Override
public String getTabName(final Context context) {
return "NewPipe"; //context.getString(R.string.blank_page_summary);
// TODO: find a better name for the blank tab (maybe "blank_tab") or replace it with
// context.getString(R.string.app_name);
return "NewPipe"; // context.getString(R.string.blank_page_summary);
}
@DrawableRes
@ -309,7 +315,7 @@ public abstract class Tab {
private String kioskId;
private KioskTab() {
this(-1, "<no-id>");
this(-1, NO_ID);
}
public KioskTab(final int kioskServiceId, final String kioskId) {
@ -357,7 +363,7 @@ public abstract class Tab {
@Override
protected void readDataFromJson(final JsonObject jsonObject) {
kioskServiceId = jsonObject.getInt(JSON_KIOSK_SERVICE_ID_KEY, -1);
kioskId = jsonObject.getString(JSON_KIOSK_ID_KEY, "<no-id>");
kioskId = jsonObject.getString(JSON_KIOSK_ID_KEY, NO_ID);
}
@Override
@ -395,7 +401,7 @@ public abstract class Tab {
private String channelName;
private ChannelTab() {
this(-1, "<no-url>", "<no-name>");
this(-1, NO_URL, NO_NAME);
}
public ChannelTab(final int channelServiceId, final String channelUrl,
@ -440,8 +446,8 @@ public abstract class Tab {
@Override
protected void readDataFromJson(final JsonObject jsonObject) {
channelServiceId = jsonObject.getInt(JSON_CHANNEL_SERVICE_ID_KEY, -1);
channelUrl = jsonObject.getString(JSON_CHANNEL_URL_KEY, "<no-url>");
channelName = jsonObject.getString(JSON_CHANNEL_NAME_KEY, "<no-name>");
channelUrl = jsonObject.getString(JSON_CHANNEL_URL_KEY, NO_URL);
channelName = jsonObject.getString(JSON_CHANNEL_NAME_KEY, NO_NAME);
}
@Override
@ -506,7 +512,7 @@ public abstract class Tab {
final StreamingService service = NewPipe.getService(kioskServiceId);
kioskId = service.getKioskList().getDefaultKioskId();
} catch (final ExtractionException e) {
ErrorActivity.reportErrorInSnackbar(context, new ErrorInfo(e,
ErrorUtil.showSnackbar(context, new ErrorInfo(e,
UserAction.REQUESTED_KIOSK, "Loading default kiosk for selected service"));
}
return kioskId;
@ -527,7 +533,7 @@ public abstract class Tab {
private LocalItemType playlistType;
private PlaylistTab() {
this(-1, "<no-name>");
this(-1, NO_NAME);
}
public PlaylistTab(final long playlistId, final String playlistName) {
@ -535,7 +541,7 @@ public abstract class Tab {
this.playlistId = playlistId;
this.playlistType = LocalItemType.PLAYLIST_LOCAL_ITEM;
this.playlistServiceId = -1;
this.playlistUrl = "<no-url>";
this.playlistUrl = NO_URL;
}
public PlaylistTab(final int playlistServiceId, final String playlistUrl,
@ -589,8 +595,8 @@ public abstract class Tab {
@Override
protected void readDataFromJson(final JsonObject jsonObject) {
playlistServiceId = jsonObject.getInt(JSON_PLAYLIST_SERVICE_ID_KEY, -1);
playlistUrl = jsonObject.getString(JSON_PLAYLIST_URL_KEY, "<no-url>");
playlistName = jsonObject.getString(JSON_PLAYLIST_NAME_KEY, "<no-name>");
playlistUrl = jsonObject.getString(JSON_PLAYLIST_URL_KEY, NO_URL);
playlistName = jsonObject.getString(JSON_PLAYLIST_NAME_KEY, NO_NAME);
playlistId = jsonObject.getInt(JSON_PLAYLIST_ID_KEY, -1);
playlistType = LocalItemType.valueOf(
jsonObject.getString(JSON_PLAYLIST_TYPE_KEY,