Completely remove return activity, now outdated

This commit is contained in:
Stypox 2021-01-09 16:33:59 +01:00
parent 0263125e11
commit 463dd8ea74
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
27 changed files with 98 additions and 132 deletions

View File

@ -227,7 +227,7 @@ public class App extends MultiDexApplication {
ACRA.init(this, acraConfig);
} catch (final ACRAConfigurationException exception) {
exception.printStackTrace();
ErrorActivity.reportError(this, null, null, new ErrorInfo(exception,
ErrorActivity.reportError(this, new ErrorInfo(exception,
UserAction.SOMETHING_ELSE, "Could not initialize ACRA crash report"));
}
}

View File

@ -63,7 +63,7 @@ public final class CheckForNewAppVersion {
packageInfo = application.getPackageManager().getPackageInfo(
application.getPackageName(), PackageManager.GET_SIGNATURES);
} catch (final PackageManager.NameNotFoundException e) {
ErrorActivity.reportError(application, null, null, new ErrorInfo(e,
ErrorActivity.reportError(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not find package info"));
return "";
}
@ -76,7 +76,7 @@ public final class CheckForNewAppVersion {
final CertificateFactory cf = CertificateFactory.getInstance("X509");
c = (X509Certificate) cf.generateCertificate(input);
} catch (final CertificateException e) {
ErrorActivity.reportError(application, null, null, new ErrorInfo(e,
ErrorActivity.reportError(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Certificate error"));
return "";
}
@ -86,7 +86,7 @@ public final class CheckForNewAppVersion {
final byte[] publicKey = md.digest(c.getEncoded());
return byte2HexFormatted(publicKey);
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
ErrorActivity.reportError(application, null, null, new ErrorInfo(e,
ErrorActivity.reportError(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not retrieve SHA1 key"));
return "";
}

View File

@ -153,7 +153,7 @@ public class MainActivity extends AppCompatActivity {
try {
setupDrawer();
} catch (final Exception e) {
ErrorActivity.reportUiError(this, null, "Setting up drawer", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up drawer", e);
}
if (DeviceUtils.isTv(this)) {
@ -238,7 +238,7 @@ public class MainActivity extends AppCompatActivity {
try {
tabSelected(item);
} catch (final Exception e) {
ErrorActivity.reportUiError(this, null, "Selecting main page tab", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Selecting main page tab", e);
}
break;
case R.id.menu_options_about_group:
@ -340,7 +340,7 @@ public class MainActivity extends AppCompatActivity {
try {
showTabs();
} catch (final Exception e) {
ErrorActivity.reportUiError(this, null, "Showing main page tabs", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Showing main page tabs", e);
}
}
}
@ -487,7 +487,7 @@ public class MainActivity extends AppCompatActivity {
drawerHeaderBinding.drawerHeaderActionButton.setContentDescription(
getString(R.string.drawer_header_description) + selectedServiceName);
} catch (final Exception e) {
ErrorActivity.reportUiError(this, null, "Setting up service toggle", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up service toggle", e);
}
final SharedPreferences sharedPreferences
@ -796,7 +796,7 @@ public class MainActivity extends AppCompatActivity {
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
}
} catch (final Exception e) {
ErrorActivity.reportUiError(this, null, "Handling intent", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Handling intent", e);
}
}

View File

@ -219,7 +219,7 @@ public class RouterActivity extends AppCompatActivity {
// unfortunately we cannot tell if the error is really caused by an unsupported url
((RouterActivity) context).showUnsupportedUrlDialog(errorInfo.getRequest());
} else {
ErrorActivity.reportError(context, MainActivity.class, null, errorInfo);
ErrorActivity.reportError(context, errorInfo);
}
if (context instanceof RouterActivity) {

View File

@ -693,7 +693,7 @@ public class DownloadDialog extends DialogFragment
mainStorage.getTag());
}
} catch (final Exception e) {
ErrorActivity.reportError(context, null, null,
ErrorActivity.reportErrorInSnackbar(this,
new ErrorInfo(e, UserAction.DOWNLOAD_FAILED, "Getting storage"));
return;
}

View File

@ -33,7 +33,7 @@ public class AcraReportSender implements ReportSender {
@Override
public void send(@NonNull final Context context, @NonNull final CrashReportData report) {
ErrorActivity.reportError(context, null, null, new ErrorInfo(
ErrorActivity.reportError(context, new ErrorInfo(
new String[]{report.getString(ReportField.STACK_TRACE)},
UserAction.UI_ERROR,
ErrorInfo.SERVICE_NONE,

View File

@ -8,7 +8,6 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@ -18,7 +17,7 @@ import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NavUtils;
import androidx.fragment.app.Fragment;
import com.google.android.material.snackbar.Snackbar;
import com.grack.nanojson.JsonWriter;
@ -74,64 +73,67 @@ public class ErrorActivity extends AppCompatActivity {
= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
/**
* Singleton:
* Used to send data between certain Activity/Services within the same process.
* This can be considered as an ugly hack inside the Android universe.
**/
@Nullable private static Class savedReturnActivity = null;
private ErrorInfo errorInfo;
private String currentTimeStamp;
private ActivityErrorBinding activityErrorBinding;
public static void reportUiError(final Context context,
@Nullable final View rootView,
final String request,
final Throwable throwable) {
reportError(context, (context instanceof Activity ? context.getClass() : null), rootView,
new ErrorInfo(throwable, UserAction.UI_ERROR, request));
}
public static void reportError(final Context context,
final Class returnActivity,
@Nullable final View rootView,
final ErrorInfo errorInfo) {
if (rootView != null) {
Snackbar.make(rootView, R.string.error_snackbar_message, Snackbar.LENGTH_LONG)
.setActionTextColor(Color.YELLOW)
.setAction(context.getString(R.string.error_snackbar_action).toUpperCase(), v ->
startErrorActivity(returnActivity, context, errorInfo)).show();
} else {
startErrorActivity(returnActivity, context, errorInfo);
}
}
// async call
public static void reportError(final Handler handler,
final Context context,
final Class returnActivity,
final View rootView,
final ErrorInfo errorInfo) {
handler.post(() -> reportError(context, returnActivity, rootView, errorInfo));
}
////////////////////////////////////////////////////////////////////////
// UTILS
////////////////////////////////////////////////////////////////////////
private static void startErrorActivity(@Nullable final Class returnActivity,
final Context context,
final ErrorInfo errorInfo) {
savedReturnActivity = returnActivity;
public static void reportError(final Context context, final ErrorInfo errorInfo) {
final Intent intent = new Intent(context, ErrorActivity.class);
intent.putExtra(ERROR_INFO, errorInfo);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public static void reportErrorInSnackbar(final Context context, final ErrorInfo errorInfo) {
final View rootView = context instanceof Activity
? ((Activity) context).findViewById(android.R.id.content) : null;
reportErrorInSnackbar(context, rootView, errorInfo);
}
public static void reportErrorInSnackbar(final Fragment fragment, final ErrorInfo errorInfo) {
View rootView = fragment.getView();
if (rootView == null && fragment.getActivity() != null) {
rootView = fragment.getActivity().findViewById(android.R.id.content);
}
reportErrorInSnackbar(fragment.requireContext(), rootView, errorInfo);
}
public static void reportUiErrorInSnackbar(final Context context,
final String request,
final Throwable throwable) {
reportErrorInSnackbar(context, new ErrorInfo(throwable, UserAction.UI_ERROR, request));
}
public static void reportUiErrorInSnackbar(final Fragment fragment,
final String request,
final Throwable throwable) {
reportErrorInSnackbar(fragment, new ErrorInfo(throwable, UserAction.UI_ERROR, request));
}
////////////////////////////////////////////////////////////////////////
// Utils
////////////////////////////////////////////////////////////////////////
private static void reportErrorInSnackbar(final Context context,
@Nullable final View rootView,
final ErrorInfo errorInfo) {
if (rootView != null) {
Snackbar.make(rootView, R.string.error_snackbar_message, Snackbar.LENGTH_LONG)
.setActionTextColor(Color.YELLOW)
.setAction(context.getString(R.string.error_snackbar_action).toUpperCase(), v ->
reportError(context, errorInfo)).show();
} else {
reportError(context, errorInfo);
}
}
////////////////////////////////////////////////////////////////////////
// Activity lifecycle
////////////////////////////////////////////////////////////////////////
@Override
protected void onCreate(final Bundle savedInstanceState) {
assureCorrectAppLanguage(this);
@ -189,7 +191,7 @@ public class ErrorActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(final MenuItem item) {
final int id = item.getItemId();
if (id == android.R.id.home) {
goToReturnActivity();
onBackPressed();
} else if (id == R.id.menu_item_share_error) {
ShareUtils.shareText(this, getString(R.string.error_report_title), buildJson());
} else {
@ -258,18 +260,6 @@ public class ErrorActivity extends AppCompatActivity {
return checkedReturnActivity;
}
private void goToReturnActivity() {
final Class<? extends Activity> checkedReturnActivity =
getReturnActivity(savedReturnActivity);
if (checkedReturnActivity == null) {
super.onBackPressed();
} else {
final Intent intent = new Intent(this, checkedReturnActivity);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, intent);
}
}
private void buildInfo(final ErrorInfo info) {
String text = "";
@ -409,10 +399,4 @@ public class ErrorActivity extends AppCompatActivity {
text += "\n" + getString(R.string.guru_meditation);
activityErrorBinding.errorSorryView.setText(text);
}
@Override
public void onBackPressed() {
//super.onBackPressed();
goToReturnActivity();
}
}

View File

@ -74,12 +74,7 @@ class ErrorPanelHelper(
} else {
errorButtonAction.setText(R.string.error_snackbar_action)
errorButtonAction.setOnClickListener {
ErrorActivity.reportError(
context,
MainActivity::class.java,
null,
errorInfo
)
ErrorActivity.reportError(context, errorInfo)
}
// hide retry button by default, then show only if not unavailable/unsupported content

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.fragments;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -10,7 +9,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
@ -157,7 +155,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
errorPanelHelper.showError(errorInfo);
}
public final void showTextError(final @NonNull String errorString) {
public final void showTextError(@NonNull final String errorString) {
handleError();
if (isDetached() || isRemoving()) {
@ -180,7 +178,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
/**
* Show a SnackBar and only call
* {@link ErrorActivity#reportError(Context, Class, View, ErrorInfo)}
* {@link ErrorActivity.reportErrorInSnackbar(androidx.fragment.app.Fragment, ErrorInfo)}
* IF we a find a valid view (otherwise the error screen appears).
*
* @param errorInfo The error information
@ -189,14 +187,6 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
if (DEBUG) {
Log.d(TAG, "showSnackBarError() called with: errorInfo = [" + errorInfo + "]");
}
View rootView = activity != null ? activity.findViewById(android.R.id.content) : null;
if (rootView == null) {
rootView = getView();
}
if (rootView == null) {
return;
}
ErrorActivity.reportError(requireContext(), MainActivity.class, rootView, errorInfo);
ErrorActivity.reportErrorInSnackbar(this, errorInfo);
}
}

View File

@ -147,7 +147,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
NavigationHelper.openSearchFragment(getFM(),
ServiceHelper.getSelectedServiceId(activity), "");
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Opening search fragment", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Opening search fragment", e);
}
return true;
}
@ -238,7 +238,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
}
if (throwable != null) {
ErrorActivity.reportUiError(context, null, "Getting fragment item", throwable);
ErrorActivity.reportUiErrorInSnackbar(context, "Getting fragment item", throwable);
return new BlankFragment();
}

View File

@ -523,7 +523,7 @@ public final class VideoDetailFragment
NavigationHelper.openChannelFragment(getFM(), currentInfo.getServiceId(),
subChannelUrl, subChannelName);
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Opening channel fragment", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Opening channel fragment", e);
}
}
@ -1596,8 +1596,7 @@ public final class VideoDetailFragment
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
} catch (final Exception e) {
ErrorActivity.reportError(activity, activity.getClass(),
activity.findViewById(android.R.id.content),
ErrorActivity.reportErrorInSnackbar(activity,
new ErrorInfo(e, UserAction.DOWNLOAD_OPEN_DIALOG, "Showing download dialog",
currentInfo));
}

View File

@ -291,7 +291,8 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
selectedItem.getUrl(),
selectedItem.getName());
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Opening channel fragment", e);
ErrorActivity.reportUiErrorInSnackbar(
BaseListFragment.this, "Opening channel fragment", e);
}
}
});
@ -306,7 +307,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
selectedItem.getUrl(),
selectedItem.getName());
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null,
ErrorActivity.reportUiErrorInSnackbar(BaseListFragment.this,
"Opening playlist fragment", e);
}
}

View File

@ -403,8 +403,7 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
currentInfo.getParentChannelUrl(),
currentInfo.getParentChannelName());
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null,
"Opening channel fragment", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Opening channel fragment", e);
}
} else if (DEBUG) {
Log.i(TAG, "Can't open parent channel because we got no channel URL");

View File

@ -286,8 +286,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
NavigationHelper.openChannelFragment(getFM(), result.getServiceId(),
result.getUploaderUrl(), result.getUploaderName());
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null,
"Opening channel fragment", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Opening channel fragment", e);
}
});
}

View File

@ -257,8 +257,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
try {
service = NewPipe.getService(serviceId);
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(),
requireActivity().findViewById(android.R.id.content),
ErrorActivity.reportUiErrorInSnackbar(this,
"Getting service for id " + serviceId, e);
}

View File

@ -179,7 +179,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
item.getUploaderUrl(),
item.getUploaderName());
} catch (final Exception e) {
ErrorActivity.reportUiError(activity, null, "Opening channel fragment", e);
ErrorActivity.reportUiErrorInSnackbar(activity, "Opening channel fragment", e);
}
}

View File

@ -84,7 +84,7 @@ public class SubscriptionsImportFragment extends BaseFragment {
setupServiceVariables();
if (supportedSources.isEmpty() && currentServiceId != Constants.NO_SERVICE_ID) {
ErrorActivity.reportError(activity, null, null,
ErrorActivity.reportErrorInSnackbar(activity,
new ErrorInfo(new String[]{}, UserAction.SUBSCRIPTION_IMPORT_EXPORT,
NewPipe.getNameOfService(currentServiceId),
"Service does not support importing subscriptions",

View File

@ -153,7 +153,7 @@ public abstract class BaseImportExportService extends Service {
protected void stopAndReportError(final Throwable throwable, final String request) {
stopService();
ErrorActivity.reportError(this, null, null, new ErrorInfo(
ErrorActivity.reportError(this, new ErrorInfo(
throwable, UserAction.SUBSCRIPTION_IMPORT_EXPORT, request));
}

View File

@ -196,7 +196,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Exporting database", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e);
}
}
@ -241,7 +241,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
System.exit(0);
}
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Importing database", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Importing database", e);
}
}
}

View File

@ -69,8 +69,8 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.watch_history_states_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context, SettingsActivity.class,
null, new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
throwable -> ErrorActivity.reportError(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete playback states")));
}
@ -81,8 +81,8 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.watch_history_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context, SettingsActivity.class,
null, new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
throwable -> ErrorActivity.reportError(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete from history")));
}
@ -92,8 +92,8 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> { },
throwable -> ErrorActivity.reportError(context, SettingsActivity.class,
null, new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
throwable -> ErrorActivity.reportError(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Clear orphaned records")));
}
@ -104,8 +104,8 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.subscribe(
howManyDeleted -> Toast.makeText(context,
R.string.search_history_deleted, Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(context, SettingsActivity.class,
null, new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
throwable -> ErrorActivity.reportError(context,
new ErrorInfo(throwable, UserAction.DELETE_FROM_HISTORY,
"Delete search history")));
}

View File

@ -162,7 +162,7 @@ public class SelectChannelFragment extends DialogFragment {
@Override
public void onError(@NonNull final Throwable exception) {
ErrorActivity.reportUiError(requireContext(), null,
ErrorActivity.reportUiErrorInSnackbar(SelectChannelFragment.this,
"Loading subscription", exception);
}

View File

@ -80,7 +80,7 @@ public class SelectKioskFragment extends DialogFragment {
try {
selectKioskAdapter = new SelectKioskAdapter();
} catch (final Exception e) {
ErrorActivity.reportUiError(getActivity(), null, "Selecting kiosk", e);
ErrorActivity.reportUiErrorInSnackbar(this, "Selecting kiosk", e);
}
recyclerView.setAdapter(selectKioskAdapter);

View File

@ -115,7 +115,7 @@ public class SelectPlaylistFragment extends DialogFragment {
protected void onError(final Throwable e) {
final Activity activity = requireActivity();
ErrorActivity.reportError(activity, activity.getClass(), null, new ErrorInfo(e,
ErrorActivity.reportErrorInSnackbar(activity, new ErrorInfo(e,
UserAction.UI_ERROR, "Loading playlists"));
}

View File

@ -95,7 +95,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, SettingMigrations.class, null, new ErrorInfo(
ErrorActivity.reportError(context, new ErrorInfo(
e,
UserAction.PREFERENCES_MIGRATION,
"Migrating preferences from version " + lastPrefVersion + " to "

View File

@ -183,7 +183,7 @@ public class ChooseTabsFragment extends Fragment {
final Tab.Type type = typeFrom(tabId);
if (type == null) {
ErrorActivity.reportError(requireContext(), null, null,
ErrorActivity.reportErrorInSnackbar(this,
new ErrorInfo(new IllegalStateException("Tab id not found: " + tabId),
UserAction.SOMETHING_ELSE, "Choosing tabs on settings"));
return;

View File

@ -483,7 +483,7 @@ public abstract class Tab {
final StreamingService service = NewPipe.getService(kioskServiceId);
kioskId = service.getKioskList().getDefaultKioskId();
} catch (final ExtractionException e) {
ErrorActivity.reportError(context, null, null, new ErrorInfo(e,
ErrorActivity.reportErrorInSnackbar(context, new ErrorInfo(e,
UserAction.REQUESTED_KIOSK, "Loading default kiosk for selected service"));
}
return kioskId;

View File

@ -586,7 +586,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
service = ErrorInfo.SERVICE_NONE;
}
ErrorActivity.reportError(mContext, null, null,
ErrorActivity.reportError(mContext,
new ErrorInfo(ErrorInfo.Companion.throwableToStringList(mission.errObject), action,
service, request.toString(), reason, null));
}