Convert SavedState to Kotlin and use the Parcelize annotation.

pull/4377/head
Isira Seneviratne 2020-10-04 07:05:40 +05:30
rodzic 15fed32d92
commit 6e68ab19f9
4 zmienionych plików z 28 dodań i 76 usunięć

Wyświetl plik

@ -48,7 +48,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
implements ListViewContract<I, N>, 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;

Wyświetl plik

@ -17,7 +17,7 @@ import java.util.Queue;
public abstract class PlaylistDialog extends DialogFragment implements StateSaver.WriteRead {
private List<StreamEntity> streamEntities;
private StateSaver.SavedState savedState;
private org.schabi.newpipe.util.SavedState savedState;
protected void setInfo(final List<StreamEntity> entities) {
this.streamEntities = entities;

Wyświetl plik

@ -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"
}

Wyświetl plik

@ -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<Object> 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<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
@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;
}
}
}