Convert MissionRecoveryInfo to Kotlin and use the Parcelize annotation.
This commit is contained in:
parent
ec1e746a22
commit
897c754dd4
|
@ -160,11 +160,11 @@ public class DownloadInitializer extends Thread {
|
||||||
MissionRecoveryInfo recovery = mMission.recoveryInfo[mMission.current];
|
MissionRecoveryInfo recovery = mMission.recoveryInfo[mMission.current];
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(entityTag)) {
|
if (!TextUtils.isEmpty(entityTag)) {
|
||||||
recovery.validateCondition = entityTag;
|
recovery.setValidateCondition(entityTag);
|
||||||
} else if (!TextUtils.isEmpty(lastModified)) {
|
} else if (!TextUtils.isEmpty(lastModified)) {
|
||||||
recovery.validateCondition = lastModified;// Note: this is less precise
|
recovery.setValidateCondition(lastModified);// Note: this is less precise
|
||||||
} else {
|
} else {
|
||||||
recovery.validateCondition = null;
|
recovery.setValidateCondition(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,10 +129,10 @@ public class DownloadMissionRecover extends Thread {
|
||||||
|
|
||||||
String url = null;
|
String url = null;
|
||||||
|
|
||||||
switch (mRecovery.kind) {
|
switch (mRecovery.getKind()) {
|
||||||
case 'a':
|
case 'a':
|
||||||
for (AudioStream audio : mExtractor.getAudioStreams()) {
|
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();
|
url = audio.getUrl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -140,21 +140,21 @@ public class DownloadMissionRecover extends Thread {
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
List<VideoStream> videoStreams;
|
List<VideoStream> videoStreams;
|
||||||
if (mRecovery.desired2)
|
if (mRecovery.isDesired2())
|
||||||
videoStreams = mExtractor.getVideoOnlyStreams();
|
videoStreams = mExtractor.getVideoOnlyStreams();
|
||||||
else
|
else
|
||||||
videoStreams = mExtractor.getVideoStreams();
|
videoStreams = mExtractor.getVideoStreams();
|
||||||
for (VideoStream video : videoStreams) {
|
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();
|
url = video.getUrl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
for (SubtitlesStream subtitles : mExtractor.getSubtitles(mRecovery.format)) {
|
for (SubtitlesStream subtitles : mExtractor.getSubtitles(mRecovery.getFormat())) {
|
||||||
String tag = subtitles.getLanguageTag();
|
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();
|
url = subtitles.getUrl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -168,11 +168,11 @@ public class DownloadMissionRecover extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolve(String url) throws IOException, HttpError {
|
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");
|
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);
|
recover(url, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ public class DownloadMissionRecover extends Thread {
|
||||||
/////////////////////
|
/////////////////////
|
||||||
try {
|
try {
|
||||||
mConn = mMission.openConnection(url, true, mMission.length - 10, mMission.length);
|
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);
|
mMission.establishConnection(mID, mConn);
|
||||||
|
|
||||||
int code = mConn.getResponseCode();
|
int code = mConn.getResponseCode();
|
||||||
|
|
|
@ -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<MissionRecoveryInfo> CREATOR = new Parcelable.Creator<MissionRecoveryInfo>() {
|
|
||||||
@Override
|
|
||||||
public MissionRecoveryInfo createFromParcel(Parcel source) {
|
|
||||||
return new MissionRecoveryInfo(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MissionRecoveryInfo[] newArray(int size) {
|
|
||||||
return new MissionRecoveryInfo[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue