diff --git a/app/build.gradle b/app/build.gradle index be1b9e414..67c001535 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,6 @@ dependencies { implementation 'com.github.TeamNewPipe:NewPipeExtractor:77a74b8' - testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:1.10.19' @@ -66,7 +65,6 @@ dependencies { implementation "com.android.support:recyclerview-v7:$supportLibVersion" implementation "com.android.support:preference-v14:$supportLibVersion" - implementation 'com.google.code.gson:gson:2.8.2' implementation 'ch.acra:acra:4.9.2' implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java index a64ed7ff4..962ec8a36 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -32,7 +32,6 @@ public class AboutActivity extends AppCompatActivity { new SoftwareComponent("Giga Get", "2014", "Peter Cai", "https://github.com/PaperAirplane-Dev-Team/GigaGet", StandardLicenses.GPL2), new SoftwareComponent("NewPipe Extractor", "2017", "Christian Schabesberger", "https://github.com/TeamNewPipe/NewPipeExtractor", StandardLicenses.GPL3), new SoftwareComponent("Jsoup", "2017", "Jonathan Hedley", "https://github.com/jhy/jsoup", StandardLicenses.MIT), - new SoftwareComponent("Google Gson", "2008", "Google Inc", "https://github.com/google/gson", StandardLicenses.APACHE2), new SoftwareComponent("Rhino", "2015", "Mozilla", "https://www.mozilla.org/rhino/", StandardLicenses.MPL2), new SoftwareComponent("ACRA", "2013", "Kevin Gaudin", "http://www.acra.ch", StandardLicenses.APACHE2), new SoftwareComponent("Universal Image Loader", "2011 - 2015", "Sergey Tarasevich", "https://github.com/nostra13/Android-Universal-Image-Loader", StandardLicenses.APACHE2), diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayerState.java b/app/src/main/java/org/schabi/newpipe/player/PlayerState.java index 4b76f986e..8ffcb6b29 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayerState.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayerState.java @@ -2,17 +2,12 @@ package org.schabi.newpipe.player; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; - -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; import org.schabi.newpipe.player.playqueue.PlayQueue; import java.io.Serializable; public class PlayerState implements Serializable { - private final static String TAG = "PlayerState"; @NonNull private final PlayQueue playQueue; private final int repeatMode; @@ -41,21 +36,6 @@ public class PlayerState implements Serializable { // Serdes //////////////////////////////////////////////////////////////////////////*/ - @Nullable - public static PlayerState fromJson(@NonNull final String json) { - try { - return new Gson().fromJson(json, PlayerState.class); - } catch (JsonSyntaxException error) { - Log.e(TAG, "Failed to deserialize PlayerState from json=[" + json + "]", error); - return null; - } - } - - @NonNull - public String toJson() { - return new Gson().toJson(this); - } - /*////////////////////////////////////////////////////////////////////////// // Getters //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java b/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java index acbd41680..ecd3ce562 100755 --- a/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java @@ -3,8 +3,6 @@ package us.shandian.giga.get; import android.support.annotation.Nullable; import android.util.Log; -import com.google.gson.Gson; - import java.io.File; import java.io.FilenameFilter; import java.io.RandomAccessFile; @@ -156,16 +154,8 @@ public class DownloadManagerImpl implements DownloadManager { for (File sub : subs) { if (sub.isFile() && sub.getName().endsWith(".giga")) { - String str = Utility.readFromFile(sub.getAbsolutePath()); - if (str != null && !str.trim().equals("")) { - - if (DEBUG) { - Log.d(TAG, "loading mission " + sub.getName()); - Log.d(TAG, str); - } - - DownloadMission mis = new Gson().fromJson(str, DownloadMission.class); - + DownloadMission mis = Utility.readFromFile(sub.getAbsolutePath()); + if (mis != null) { if (mis.finished) { if (!sub.delete()) { Log.w(TAG, "Unable to delete .giga file: " + sub.getPath()); diff --git a/app/src/main/java/us/shandian/giga/get/DownloadMission.java b/app/src/main/java/us/shandian/giga/get/DownloadMission.java index 9938d2d86..c48e5ffbc 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadMission.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadMission.java @@ -4,9 +4,8 @@ import android.os.Handler; import android.os.Looper; import android.util.Log; -import com.google.gson.Gson; - import java.io.File; +import java.io.Serializable; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; @@ -18,7 +17,9 @@ import us.shandian.giga.util.Utility; import static org.schabi.newpipe.BuildConfig.DEBUG; -public class DownloadMission { +public class DownloadMission implements Serializable { + private static final long serialVersionUID = 0L; + private static final String TAG = DownloadMission.class.getSimpleName(); public interface MissionListener { @@ -79,7 +80,6 @@ public class DownloadMission { private transient boolean mWritingToFile; private static final int NO_IDENTIFIER = -1; - private long db_identifier = NO_IDENTIFIER; public DownloadMission() { } @@ -308,7 +308,7 @@ public class DownloadMission { */ private void doWriteThisToFile() { synchronized (blockState) { - Utility.writeToFile(getMetaFilename(), new Gson().toJson(this)); + Utility.writeToFile(getMetaFilename(), this); } } diff --git a/app/src/main/java/us/shandian/giga/util/Utility.java b/app/src/main/java/us/shandian/giga/util/Utility.java index 1d7b629e4..2d44e8c15 100644 --- a/app/src/main/java/us/shandian/giga/util/Utility.java +++ b/app/src/main/java/us/shandian/giga/util/Utility.java @@ -5,6 +5,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.widget.Toast; @@ -16,6 +17,9 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -51,57 +55,47 @@ public class Utility { } } - public static void writeToFile(String fileName, String content) { + public static void writeToFile(@NonNull String fileName, @NonNull Serializable serializable) { + ObjectOutputStream objectOutputStream = null; + try { - writeToFile(fileName, content.getBytes("UTF-8")); + objectOutputStream = new ObjectOutputStream(new FileOutputStream(fileName)); + objectOutputStream.writeObject(serializable); } catch (Exception e) { - + //nothing to do } - } - public static void writeToFile(String fileName, byte[] content) { - File f = new File(fileName); - - if (!f.exists()) { + if(objectOutputStream != null) { try { - f.createNewFile(); + objectOutputStream.close(); } catch (Exception e) { - + //nothing to do } } - - try { - FileOutputStream opt = new FileOutputStream(f, false); - opt.write(content, 0, content.length); - opt.close(); - } catch (Exception e) { - - } } - public static String readFromFile(String file) { + @Nullable + @SuppressWarnings("unchecked") + public static T readFromFile(String file) { + T object = null; + ObjectInputStream objectInputStream = null; + try { - File f = new File(file); - - if (!f.exists() || !f.canRead()) { - return null; - } - - BufferedInputStream ipt = new BufferedInputStream(new FileInputStream(f)); - - byte[] buf = new byte[512]; - StringBuilder sb = new StringBuilder(); - - while (ipt.available() > 0) { - int len = ipt.read(buf, 0, 512); - sb.append(new String(buf, 0, len, "UTF-8")); - } - - ipt.close(); - return sb.toString(); + objectInputStream = new ObjectInputStream(new FileInputStream(file)); + object = (T) objectInputStream.readObject(); } catch (Exception e) { - return null; + //nothing to do } + + if(objectInputStream != null){ + try { + objectInputStream .close(); + } catch (Exception e) { + //nothing to do + } + } + + return object; } @Nullable