diff --git a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java index a3aa28059..09ae5648d 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java @@ -8,7 +8,6 @@ import androidx.test.filters.LargeTest; import org.junit.Test; import org.junit.runner.RunWith; import org.schabi.newpipe.R; -import org.schabi.newpipe.report.ErrorActivity.ErrorInfo; import static org.junit.Assert.assertEquals; @@ -29,10 +28,10 @@ public class ErrorInfoTest { parcel.setDataPosition(0); final ErrorInfo infoFromParcel = ErrorInfo.CREATOR.createFromParcel(parcel); - assertEquals(UserAction.USER_REPORT, infoFromParcel.userAction); - assertEquals("youtube", infoFromParcel.serviceName); - assertEquals("request", infoFromParcel.request); - assertEquals(R.string.general_error, infoFromParcel.message); + assertEquals(UserAction.USER_REPORT, infoFromParcel.getUserAction()); + assertEquals("youtube", infoFromParcel.getServiceName()); + assertEquals("request", infoFromParcel.getRequest()); + assertEquals(R.string.general_error, infoFromParcel.getMessage()); parcel.recycle(); } diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 5fdc1058a..51d0f1016 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -22,6 +22,7 @@ import org.acra.config.CoreConfigurationBuilder; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.ExceptionUtils; @@ -226,7 +227,7 @@ public class App extends MultiDexApplication { ace, null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", + ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", "Could not initialize ACRA crash report", R.string.app_ui_crash)); } } diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index a193149e2..1bec52dcd 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -23,6 +23,7 @@ import com.grack.nanojson.JsonParserException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import java.io.ByteArrayInputStream; @@ -67,7 +68,7 @@ public final class CheckForNewAppVersion { packageInfo = pm.getPackageInfo(packageName, flags); } catch (final PackageManager.NameNotFoundException e) { ErrorActivity.reportError(application, e, null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", + ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", "Could not find package info", R.string.app_ui_crash)); } @@ -82,7 +83,7 @@ public final class CheckForNewAppVersion { c = (X509Certificate) cf.generateCertificate(input); } catch (final CertificateException e) { ErrorActivity.reportError(application, e, null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", + ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", "Certificate error", R.string.app_ui_crash)); } @@ -94,7 +95,7 @@ public final class CheckForNewAppVersion { hexString = byte2HexFormatted(publicKey); } catch (NoSuchAlgorithmException | CertificateEncodingException e) { ErrorActivity.reportError(application, e, null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", + ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", "Could not retrieve SHA1 key", R.string.app_ui_crash)); } diff --git a/app/src/main/java/org/schabi/newpipe/about/License.java b/app/src/main/java/org/schabi/newpipe/about/License.java deleted file mode 100644 index 6670e12ac..000000000 --- a/app/src/main/java/org/schabi/newpipe/about/License.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.schabi.newpipe.about; - -import android.net.Uri; -import android.os.Parcel; -import android.os.Parcelable; - -import java.io.Serializable; - -/** - * Class for storing information about a software license. - */ -public class License implements Parcelable, Serializable { - public static final Creator CREATOR = new Creator() { - @Override - public License createFromParcel(final Parcel source) { - return new License(source); - } - - @Override - public License[] newArray(final int size) { - return new License[size]; - } - }; - private final String abbreviation; - private final String name; - private final String filename; - - public License(final String name, final String abbreviation, final String filename) { - if (name == null) { - throw new NullPointerException("name is null"); - } - if (abbreviation == null) { - throw new NullPointerException("abbreviation is null"); - } - if (filename == null) { - throw new NullPointerException("filename is null"); - } - this.name = name; - this.filename = filename; - this.abbreviation = abbreviation; - } - - protected License(final Parcel in) { - this.filename = in.readString(); - this.abbreviation = in.readString(); - this.name = in.readString(); - } - - public Uri getContentUri() { - return new Uri.Builder() - .scheme("file") - .path("/android_asset") - .appendPath(filename) - .build(); - } - - public String getAbbreviation() { - return abbreviation; - } - - public String getFilename() { - return filename; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeString(this.filename); - dest.writeString(this.abbreviation); - dest.writeString(this.name); - } - - public String getName() { - return name; - } -} diff --git a/app/src/main/java/org/schabi/newpipe/about/License.kt b/app/src/main/java/org/schabi/newpipe/about/License.kt new file mode 100644 index 000000000..00a66c84a --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/about/License.kt @@ -0,0 +1,19 @@ +package org.schabi.newpipe.about + +import android.net.Uri +import android.os.Parcelable +import java.io.Serializable +import kotlinx.android.parcel.Parcelize + +/** + * Class for storing information about a software license. + */ +@Parcelize +class License(val name: String, val abbreviation: String, val filename: String) : Parcelable, Serializable { + val contentUri: Uri + get() = Uri.Builder() + .scheme("file") + .path("/android_asset") + .appendPath(filename) + .build() +} diff --git a/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.java b/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.java deleted file mode 100644 index 946945142..000000000 --- a/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.schabi.newpipe.about; - -import android.os.Parcel; -import android.os.Parcelable; - -public class SoftwareComponent implements Parcelable { - public static final Creator CREATOR = new Creator() { - @Override - public SoftwareComponent createFromParcel(final Parcel source) { - return new SoftwareComponent(source); - } - - @Override - public SoftwareComponent[] newArray(final int size) { - return new SoftwareComponent[size]; - } - }; - - private final License license; - private final String name; - private final String years; - private final String copyrightOwner; - private final String link; - private final String version; - - public SoftwareComponent(final String name, final String years, final String copyrightOwner, - final String link, final License license) { - this.name = name; - this.years = years; - this.copyrightOwner = copyrightOwner; - this.link = link; - this.license = license; - this.version = null; - } - - protected SoftwareComponent(final Parcel in) { - this.name = in.readString(); - this.license = in.readParcelable(License.class.getClassLoader()); - this.copyrightOwner = in.readString(); - this.link = in.readString(); - this.years = in.readString(); - this.version = in.readString(); - } - - public String getName() { - return name; - } - - public String getYears() { - return years; - } - - public String getCopyrightOwner() { - return copyrightOwner; - } - - public String getLink() { - return link; - } - - public String getVersion() { - return version; - } - - public License getLicense() { - return license; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeString(name); - dest.writeParcelable(license, flags); - dest.writeString(copyrightOwner); - dest.writeString(link); - dest.writeString(years); - dest.writeString(version); - } -} diff --git a/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.kt b/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.kt new file mode 100644 index 000000000..2e967ebe8 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/about/SoftwareComponent.kt @@ -0,0 +1,16 @@ +package org.schabi.newpipe.about + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +@Parcelize +class SoftwareComponent +@JvmOverloads +constructor( + val name: String, + val years: String, + val copyrightOwner: String, + val link: String, + val license: License, + val version: String? = null +) : Parcelable diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 93398d990..827da87e1 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -49,6 +49,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.NewPipeSettings; import org.schabi.newpipe.util.FilePickerActivityHelper; @@ -602,7 +603,7 @@ public class DownloadDialog extends DialogFragment Collections.singletonList(e), null, null, - ErrorActivity.ErrorInfo + ErrorInfo .make(UserAction.SOMETHING_ELSE, "-", "-", R.string.general_error) ); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index c687c4a6a..37e4ce465 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -23,6 +23,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExceptionUtils; import org.schabi.newpipe.util.InfoCache; @@ -252,7 +253,7 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC } ErrorActivity.reportError(getContext(), exception, MainActivity.class, null, - ErrorActivity.ErrorInfo.make(userAction, serviceName == null ? "none" : serviceName, + ErrorInfo.make(userAction, serviceName == null ? "none" : serviceName, request == null ? "none" : request, errorId)); } @@ -265,7 +266,7 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC /** * Show a SnackBar and only call - * {@link ErrorActivity#reportError(Context, List, Class, View, ErrorActivity.ErrorInfo)} + * {@link ErrorActivity#reportError(Context, List, Class, View, ErrorInfo)} * IF we a find a valid view (otherwise the error screen appears). * * @param exception List of the exceptions to show @@ -291,6 +292,6 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC } ErrorActivity.reportError(getContext(), exception, MainActivity.class, rootView, - ErrorActivity.ErrorInfo.make(userAction, serviceName, request, errorId)); + ErrorInfo.make(userAction, serviceName, request, errorId)); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index e78bfa7ce..866b324ec 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -27,6 +27,7 @@ import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.tabs.Tab; import org.schabi.newpipe.settings.tabs.TabsManager; @@ -242,7 +243,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } if (throwable != null) { - ErrorActivity.reportError(context, throwable, null, null, ErrorActivity.ErrorInfo + ErrorActivity.reportError(context, throwable, null, null, ErrorInfo .make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); return new BlankFragment(); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 772a291b1..e7c98fe8b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -92,6 +92,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.DeviceUtils; @@ -1630,7 +1631,7 @@ public final class VideoDetailFragment downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog"); } catch (final Exception e) { - final ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + final ErrorInfo info = ErrorInfo.make(UserAction.UI_ERROR, ServiceList.all() .get(currentInfo .getServiceId()) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 41263bc34..5252024c2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -48,7 +48,7 @@ public abstract class BaseListFragment extends BaseStateFragment implements ListViewContract, StateSaver.WriteRead, SharedPreferences.OnSharedPreferenceChangeListener { private static final int LIST_MODE_UPDATE_FLAG = 0x32; - protected StateSaver.SavedState savedState; + protected org.schabi.newpipe.util.SavedState savedState; private boolean useDefaultStateSaving = true; private int updateFlags = 0; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 1452241aa..66e16ff3c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -49,6 +49,7 @@ import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.list.BaseListFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.Constants; @@ -248,7 +249,7 @@ public class SearchFragment extends BaseListFragment streamEntities; - private StateSaver.SavedState savedState; + private org.schabi.newpipe.util.SavedState savedState; protected void setInfo(final List entities) { this.streamEntities = entities; diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 8cd4e4c7e..511e3c7a3 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -34,6 +34,7 @@ import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.NavigationHelper; @@ -183,7 +184,7 @@ public class StatisticsPlaylistFragment throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete view history", @@ -197,7 +198,7 @@ public class StatisticsPlaylistFragment throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete search history", diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java index a2a848b4b..d7a1051e6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java @@ -27,6 +27,7 @@ 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.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.FilePickerActivityHelper; @@ -84,7 +85,7 @@ public class SubscriptionsImportFragment extends BaseFragment { setupServiceVariables(); if (supportedSources.isEmpty() && currentServiceId != Constants.NO_SERVICE_ID) { ErrorActivity.reportError(activity, Collections.emptyList(), null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, + ErrorInfo.make(UserAction.SOMETHING_ELSE, NewPipe.getNameOfService(currentServiceId), "Service don't support importing", R.string.general_error)); activity.finish(); diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java index f485844ea..9b9a55afb 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.local.subscription.SubscriptionManager; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExceptionUtils; @@ -153,7 +154,7 @@ public abstract class BaseImportExportService extends Service { protected void stopAndReportError(@Nullable final Throwable error, final String request) { stopService(); - final ErrorActivity.ErrorInfo errorInfo = ErrorActivity.ErrorInfo + final ErrorInfo errorInfo = ErrorInfo .make(UserAction.SUBSCRIPTION, "unknown", request, R.string.general_error); ErrorActivity.reportError(this, error != null ? Collections.singletonList(error) : Collections.emptyList(), null, null, errorInfo); diff --git a/app/src/main/java/org/schabi/newpipe/report/AcraReportSender.java b/app/src/main/java/org/schabi/newpipe/report/AcraReportSender.java index b31e3a31e..311cb8a80 100644 --- a/app/src/main/java/org/schabi/newpipe/report/AcraReportSender.java +++ b/app/src/main/java/org/schabi/newpipe/report/AcraReportSender.java @@ -33,7 +33,7 @@ public class AcraReportSender implements ReportSender { @Override public void send(@NonNull final Context context, @NonNull final CrashReportData report) { ErrorActivity.reportError(context, report, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, "none", + ErrorInfo.make(UserAction.UI_ERROR, "none", "App crash, UI failure", R.string.app_ui_crash)); } } diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java index 259dff44d..3213821cd 100644 --- a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java @@ -9,8 +9,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.Parcel; -import android.os.Parcelable; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -22,7 +20,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; -import androidx.annotation.StringRes; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -230,8 +227,8 @@ public class ErrorActivity extends AppCompatActivity { // normal bugreport buildInfo(errorInfo); - if (errorInfo.message != 0) { - errorMessageView.setText(errorInfo.message); + if (errorInfo.getMessage() != 0) { + errorMessageView.setText(errorInfo.getMessage()); } else { errorMessageView.setVisibility(View.GONE); findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE); @@ -348,12 +345,12 @@ public class ErrorActivity extends AppCompatActivity { infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n")); - text += getUserActionString(info.userAction) + "\n" - + info.request + "\n" + text += getUserActionString(info.getUserAction()) + "\n" + + info.getRequest() + "\n" + getContentLanguageString() + "\n" + getContentCountryString() + "\n" + getAppLanguage() + "\n" - + info.serviceName + "\n" + + info.getServiceName() + "\n" + currentTimeStamp + "\n" + getPackageName() + "\n" + BuildConfig.VERSION_NAME + "\n" @@ -366,12 +363,12 @@ public class ErrorActivity extends AppCompatActivity { try { return JsonWriter.string() .object() - .value("user_action", getUserActionString(errorInfo.userAction)) - .value("request", errorInfo.request) + .value("user_action", getUserActionString(errorInfo.getUserAction())) + .value("request", errorInfo.getRequest()) .value("content_language", getContentLanguageString()) .value("content_country", getContentCountryString()) .value("app_language", getAppLanguage()) - .value("service", errorInfo.serviceName) + .value("service", errorInfo.getServiceName()) .value("package", getPackageName()) .value("version", BuildConfig.VERSION_NAME) .value("os", getOsString()) @@ -401,12 +398,12 @@ public class ErrorActivity extends AppCompatActivity { htmlErrorReport .append("## Exception") .append("\n* __User Action:__ ") - .append(getUserActionString(errorInfo.userAction)) - .append("\n* __Request:__ ").append(errorInfo.request) + .append(getUserActionString(errorInfo.getUserAction())) + .append("\n* __Request:__ ").append(errorInfo.getRequest()) .append("\n* __Content Country:__ ").append(getContentCountryString()) .append("\n* __Content Language:__ ").append(getContentLanguageString()) .append("\n* __App Language:__ ").append(getAppLanguage()) - .append("\n* __Service:__ ").append(errorInfo.serviceName) + .append("\n* __Service:__ ").append(errorInfo.getServiceName()) .append("\n* __Version:__ ").append(BuildConfig.VERSION_NAME) .append("\n* __OS:__ ").append(getOsString()).append("\n"); @@ -494,57 +491,4 @@ public class ErrorActivity extends AppCompatActivity { return df.format(new Date()); } - public static class ErrorInfo implements Parcelable { - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { - @Override - public ErrorInfo createFromParcel(final Parcel source) { - return new ErrorInfo(source); - } - - @Override - public ErrorInfo[] newArray(final int size) { - return new ErrorInfo[size]; - } - }; - - final UserAction userAction; - public final String request; - final String serviceName; - @StringRes - public final int message; - - private ErrorInfo(final UserAction userAction, final String serviceName, - final String request, @StringRes final int message) { - this.userAction = userAction; - this.serviceName = serviceName; - this.request = request; - this.message = message; - } - - protected ErrorInfo(final Parcel in) { - this.userAction = UserAction.valueOf(in.readString()); - this.request = in.readString(); - this.serviceName = in.readString(); - this.message = in.readInt(); - } - - public static ErrorInfo make(final UserAction userAction, final String serviceName, - final String request, @StringRes final int message) { - return new ErrorInfo(userAction, serviceName, request, message); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeString(this.userAction.name()); - dest.writeString(this.request); - dest.writeString(this.serviceName); - dest.writeInt(this.message); - } - } } diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/report/ErrorInfo.kt new file mode 100644 index 000000000..894506109 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorInfo.kt @@ -0,0 +1,23 @@ +package org.schabi.newpipe.report + +import android.os.Parcelable +import androidx.annotation.StringRes +import kotlinx.android.parcel.Parcelize + +@Parcelize +class ErrorInfo private constructor( + val userAction: UserAction?, + val serviceName: String, + val request: String, + @field:StringRes @param:StringRes val message: Int +) : Parcelable { + companion object { + @JvmStatic + fun make( + userAction: UserAction?, + serviceName: String, + request: String, + @StringRes message: Int + ) = ErrorInfo(userAction, serviceName, request, message) + } +} diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 3fba6890a..17e130967 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -25,6 +25,7 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.FilePickerActivityHelper; import org.schabi.newpipe.util.ZipHelper; @@ -357,7 +358,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { ErrorActivity.reportError(activity, e, activity.getClass(), null, - ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + ErrorInfo.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index 893e7c740..e0cf2e4ad 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -10,6 +10,7 @@ import androidx.preference.Preference; import org.schabi.newpipe.R; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.InfoCache; @@ -64,7 +65,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete playback states", @@ -79,7 +80,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete view history", @@ -93,7 +94,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete search history", @@ -122,7 +123,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete playback states", @@ -148,7 +149,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment { throwable -> ErrorActivity.reportError(getContext(), throwable, SettingsActivity.class, null, - ErrorActivity.ErrorInfo.make( + ErrorInfo.make( UserAction.DELETE_FROM_HISTORY, "none", "Delete search history", diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 96e2781f5..f87b5cd2a 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -22,6 +22,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.SubscriptionEntity; import org.schabi.newpipe.local.subscription.SubscriptionManager; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ThemeHelper; @@ -178,7 +179,7 @@ public class SelectChannelFragment extends DialogFragment { protected void onError(final Throwable e) { final Activity activity = getActivity(); - ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo + ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorInfo .make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 9d0fece4f..fc974607b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.ServiceHelper; @@ -114,7 +115,7 @@ public class SelectKioskFragment extends DialogFragment { protected void onError(final Throwable e) { final Activity activity = getActivity(); - ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo + ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorInfo .make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java index 153adf4c0..f2876f1ee 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java @@ -27,6 +27,7 @@ import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; import org.schabi.newpipe.local.playlist.LocalPlaylistManager; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import java.util.List; @@ -114,7 +115,7 @@ public class SelectPlaylistFragment extends DialogFragment { protected void onError(final Throwable e) { final Activity activity = requireActivity(); - ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo + ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorInfo .make(UserAction.UI_ERROR, "none", "load_playlists", R.string.app_ui_crash)); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java index 26e72722e..9042559c9 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -8,7 +8,7 @@ import androidx.preference.PreferenceManager; import org.schabi.newpipe.R; import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.report.ErrorActivity.ErrorInfo; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import static org.schabi.newpipe.MainActivity.DEBUG; diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java index 44406abac..cbc47392b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java @@ -29,6 +29,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SelectChannelFragment; import org.schabi.newpipe.settings.SelectKioskFragment; @@ -184,7 +185,7 @@ public class ChooseTabsFragment extends Fragment { if (type == null) { ErrorActivity.reportError(requireContext(), new IllegalStateException("Tab id not found: " + tabId), null, null, - ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", + ErrorInfo.make(UserAction.SOMETHING_ELSE, "none", "Choosing tabs on settings", 0)); return; } diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java index aaac03232..ce3874f39 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java @@ -26,6 +26,7 @@ import org.schabi.newpipe.local.history.StatisticsPlaylistFragment; import org.schabi.newpipe.local.playlist.LocalPlaylistFragment; import org.schabi.newpipe.local.subscription.SubscriptionFragment; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.ServiceHelper; @@ -483,7 +484,7 @@ public abstract class Tab { kioskId = service.getKioskList().getDefaultKioskId(); } catch (final ExtractionException e) { ErrorActivity.reportError(context, e, null, null, - ErrorActivity.ErrorInfo.make(UserAction.REQUESTED_KIOSK, "none", + ErrorInfo.make(UserAction.REQUESTED_KIOSK, "none", "Loading default kiosk from selected service", 0)); } return kioskId; diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index e6dffaec4..91a38d8d8 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -51,6 +51,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import java.util.Collections; @@ -298,7 +299,7 @@ public final class ExtractorHelper { : exception instanceof ParsingException ? R.string.parsing_error : R.string.general_error; ErrorActivity.reportError(handler, context, exception, MainActivity.class, null, - ErrorActivity.ErrorInfo.make(userAction, serviceId == -1 ? "none" + ErrorInfo.make(userAction, serviceId == -1 ? "none" : NewPipe.getNameOfService(serviceId), url + (optionalErrorMessage == null ? "" : optionalErrorMessage), errorId)); diff --git a/app/src/main/java/org/schabi/newpipe/util/SavedState.kt b/app/src/main/java/org/schabi/newpipe/util/SavedState.kt new file mode 100644 index 000000000..313d56192 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/SavedState.kt @@ -0,0 +1,25 @@ +package org.schabi.newpipe.util + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +/** + * Information about the saved state on the disk. + */ +@Parcelize +class SavedState( + /** + * Get the prefix of the saved file. + * + * @return the file prefix + */ + val prefixFileSaved: String, + /** + * Get the path to the saved file. + * + * @return the path to the saved file + */ + val pathFileSaved: String +) : Parcelable { + override fun toString() = "$prefixFileSaved > $pathFileSaved" +} diff --git a/app/src/main/java/org/schabi/newpipe/util/StateSaver.java b/app/src/main/java/org/schabi/newpipe/util/StateSaver.java index ba095a4c5..ce31be1e3 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StateSaver.java +++ b/app/src/main/java/org/schabi/newpipe/util/StateSaver.java @@ -22,8 +22,6 @@ package org.schabi.newpipe.util; import android.content.Context; import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; @@ -288,7 +286,7 @@ public final class StateSaver { Log.d(TAG, "onDestroy() called with: savedState = [" + savedState + "]"); } - if (savedState != null && !TextUtils.isEmpty(savedState.getPathFileSaved())) { + if (savedState != null && !savedState.getPathFileSaved().isEmpty()) { STATE_OBJECTS_HOLDER.remove(savedState.getPrefixFileSaved()); try { //noinspection ResultOfMethodCallIgnored @@ -348,75 +346,4 @@ public final class StateSaver { */ void readFrom(@NonNull Queue savedObjects) throws Exception; } - - /*////////////////////////////////////////////////////////////////////////// - // Inner - //////////////////////////////////////////////////////////////////////////*/ - - /** - * Information about the saved state on the disk. - */ - public static class SavedState implements Parcelable { - @SuppressWarnings("unused") - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { - @Override - public SavedState createFromParcel(final Parcel in) { - return new SavedState(in); - } - - @Override - public SavedState[] newArray(final int size) { - return new SavedState[size]; - } - }; - private final String prefixFileSaved; - private final String pathFileSaved; - - public SavedState(final String prefixFileSaved, final String pathFileSaved) { - this.prefixFileSaved = prefixFileSaved; - this.pathFileSaved = pathFileSaved; - } - - protected SavedState(final Parcel in) { - prefixFileSaved = in.readString(); - pathFileSaved = in.readString(); - } - - @Override - public String toString() { - return getPrefixFileSaved() + " > " + getPathFileSaved(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeString(prefixFileSaved); - dest.writeString(pathFileSaved); - } - - /** - * Get the prefix of the saved file. - * - * @return the file prefix - */ - public String getPrefixFileSaved() { - return prefixFileSaved; - } - - /** - * Get the path to the saved file. - * - * @return the path to the saved file - */ - public String getPathFileSaved() { - return pathFileSaved; - } - } - - } diff --git a/app/src/main/java/us/shandian/giga/get/DownloadInitializer.java b/app/src/main/java/us/shandian/giga/get/DownloadInitializer.java index 327278ba3..88168ad91 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadInitializer.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadInitializer.java @@ -160,11 +160,11 @@ public class DownloadInitializer extends Thread { MissionRecoveryInfo recovery = mMission.recoveryInfo[mMission.current]; if (!TextUtils.isEmpty(entityTag)) { - recovery.validateCondition = entityTag; + recovery.setValidateCondition(entityTag); } else if (!TextUtils.isEmpty(lastModified)) { - recovery.validateCondition = lastModified;// Note: this is less precise + recovery.setValidateCondition(lastModified);// Note: this is less precise } else { - recovery.validateCondition = null; + recovery.setValidateCondition(null); } } diff --git a/app/src/main/java/us/shandian/giga/get/DownloadMissionRecover.java b/app/src/main/java/us/shandian/giga/get/DownloadMissionRecover.java index ab158ec51..0e9b9ff00 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadMissionRecover.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadMissionRecover.java @@ -129,10 +129,10 @@ public class DownloadMissionRecover extends Thread { String url = null; - switch (mRecovery.kind) { + switch (mRecovery.getKind()) { case 'a': for (AudioStream audio : mExtractor.getAudioStreams()) { - if (audio.average_bitrate == mRecovery.desiredBitrate && audio.getFormat() == mRecovery.format) { + if (audio.average_bitrate == mRecovery.getDesiredBitrate() && audio.getFormat() == mRecovery.getFormat()) { url = audio.getUrl(); break; } @@ -140,21 +140,21 @@ public class DownloadMissionRecover extends Thread { break; case 'v': List videoStreams; - if (mRecovery.desired2) + if (mRecovery.isDesired2()) videoStreams = mExtractor.getVideoOnlyStreams(); else videoStreams = mExtractor.getVideoStreams(); for (VideoStream video : videoStreams) { - if (video.resolution.equals(mRecovery.desired) && video.getFormat() == mRecovery.format) { + if (video.resolution.equals(mRecovery.getDesired()) && video.getFormat() == mRecovery.getFormat()) { url = video.getUrl(); break; } } break; case 's': - for (SubtitlesStream subtitles : mExtractor.getSubtitles(mRecovery.format)) { + for (SubtitlesStream subtitles : mExtractor.getSubtitles(mRecovery.getFormat())) { String tag = subtitles.getLanguageTag(); - if (tag.equals(mRecovery.desired) && subtitles.isAutoGenerated() == mRecovery.desired2) { + if (tag.equals(mRecovery.getDesired()) && subtitles.isAutoGenerated() == mRecovery.isDesired2()) { url = subtitles.getUrl(); break; } @@ -168,11 +168,11 @@ public class DownloadMissionRecover extends Thread { } private void resolve(String url) throws IOException, HttpError { - if (mRecovery.validateCondition == null) { + if (mRecovery.getValidateCondition() == null) { Log.w(TAG, "validation condition not defined, the resource can be stale"); } - if (mMission.unknownLength || mRecovery.validateCondition == null) { + if (mMission.unknownLength || mRecovery.getValidateCondition() == null) { recover(url, false); return; } @@ -182,7 +182,7 @@ public class DownloadMissionRecover extends Thread { ///////////////////// try { mConn = mMission.openConnection(url, true, mMission.length - 10, mMission.length); - mConn.setRequestProperty("If-Range", mRecovery.validateCondition); + mConn.setRequestProperty("If-Range", mRecovery.getValidateCondition()); mMission.establishConnection(mID, mConn); int code = mConn.getResponseCode(); diff --git a/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.java b/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.java deleted file mode 100644 index e52f35cc6..000000000 --- a/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.java +++ /dev/null @@ -1,115 +0,0 @@ -package us.shandian.giga.get; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.NonNull; - -import org.schabi.newpipe.extractor.MediaFormat; -import org.schabi.newpipe.extractor.stream.AudioStream; -import org.schabi.newpipe.extractor.stream.Stream; -import org.schabi.newpipe.extractor.stream.SubtitlesStream; -import org.schabi.newpipe.extractor.stream.VideoStream; - -import java.io.Serializable; - -public class MissionRecoveryInfo implements Serializable, Parcelable { - private static final long serialVersionUID = 0L; - - MediaFormat format; - String desired; - boolean desired2; - int desiredBitrate; - byte kind; - String validateCondition = null; - - public MissionRecoveryInfo(@NonNull Stream stream) { - if (stream instanceof AudioStream) { - desiredBitrate = ((AudioStream) stream).average_bitrate; - desired2 = false; - kind = 'a'; - } else if (stream instanceof VideoStream) { - desired = ((VideoStream) stream).getResolution(); - desired2 = ((VideoStream) stream).isVideoOnly(); - kind = 'v'; - } else if (stream instanceof SubtitlesStream) { - desired = ((SubtitlesStream) stream).getLanguageTag(); - desired2 = ((SubtitlesStream) stream).isAutoGenerated(); - kind = 's'; - } else { - throw new RuntimeException("Unknown stream kind"); - } - - format = stream.getFormat(); - if (format == null) throw new NullPointerException("Stream format cannot be null"); - } - - @NonNull - @Override - public String toString() { - String info; - StringBuilder str = new StringBuilder(); - str.append("{type="); - switch (kind) { - case 'a': - str.append("audio"); - info = "bitrate=" + desiredBitrate; - break; - case 'v': - str.append("video"); - info = "quality=" + desired + " videoOnly=" + desired2; - break; - case 's': - str.append("subtitles"); - info = "language=" + desired + " autoGenerated=" + desired2; - break; - default: - info = ""; - str.append("other"); - } - - str.append(" format=") - .append(format.getName()) - .append(' ') - .append(info) - .append('}'); - - return str.toString(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int flags) { - parcel.writeInt(this.format.ordinal()); - parcel.writeString(this.desired); - parcel.writeInt(this.desired2 ? 0x01 : 0x00); - parcel.writeInt(this.desiredBitrate); - parcel.writeByte(this.kind); - parcel.writeString(this.validateCondition); - } - - private MissionRecoveryInfo(Parcel parcel) { - this.format = MediaFormat.values()[parcel.readInt()]; - this.desired = parcel.readString(); - this.desired2 = parcel.readInt() != 0x00; - this.desiredBitrate = parcel.readInt(); - this.kind = parcel.readByte(); - this.validateCondition = parcel.readString(); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public MissionRecoveryInfo createFromParcel(Parcel source) { - return new MissionRecoveryInfo(source); - } - - @Override - public MissionRecoveryInfo[] newArray(int size) { - return new MissionRecoveryInfo[size]; - } - }; -} diff --git a/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.kt b/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.kt new file mode 100644 index 000000000..568ae8d13 --- /dev/null +++ b/app/src/main/java/us/shandian/giga/get/MissionRecoveryInfo.kt @@ -0,0 +1,71 @@ +package us.shandian.giga.get + +import android.os.Parcelable +import java.io.Serializable +import kotlinx.android.parcel.Parcelize +import org.schabi.newpipe.extractor.MediaFormat +import org.schabi.newpipe.extractor.stream.AudioStream +import org.schabi.newpipe.extractor.stream.Stream +import org.schabi.newpipe.extractor.stream.SubtitlesStream +import org.schabi.newpipe.extractor.stream.VideoStream + +@Parcelize +class MissionRecoveryInfo( + var format: MediaFormat, + var desired: String? = null, + var isDesired2: Boolean = false, + var desiredBitrate: Int = 0, + var kind: Char = Char.MIN_VALUE, + var validateCondition: String? = null +) : Serializable, Parcelable { + constructor(stream: Stream) : this(format = stream.getFormat()!!) { + when (stream) { + is AudioStream -> { + desiredBitrate = stream.average_bitrate + isDesired2 = false + kind = 'a' + } + is VideoStream -> { + desired = stream.getResolution() + isDesired2 = stream.isVideoOnly() + kind = 'v' + } + is SubtitlesStream -> { + desired = stream.languageTag + isDesired2 = stream.isAutoGenerated + kind = 's' + } + else -> throw RuntimeException("Unknown stream kind") + } + } + + override fun toString(): String { + val info: String + val str = StringBuilder() + str.append("{type=") + when (kind) { + 'a' -> { + str.append("audio") + info = "bitrate=$desiredBitrate" + } + 'v' -> { + str.append("video") + info = "quality=$desired videoOnly=$isDesired2" + } + 's' -> { + str.append("subtitles") + info = "language=$desired autoGenerated=$isDesired2" + } + else -> { + info = "" + str.append("other") + } + } + str.append(" format=") + .append(format.getName()) + .append(' ') + .append(info) + .append('}') + return str.toString() + } +} diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index f3fb64a5d..07fe2fcc4 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -39,6 +39,7 @@ import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.NavigationHelper; @@ -575,7 +576,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb mission.errObject, null, null, - ErrorActivity.ErrorInfo.make(action, service, request.toString(), reason) + ErrorInfo.make(action, service, request.toString(), reason) ); }