Skip to content

Commit

Permalink
Merge pull request #34 from Arachnid-27/dev-1.4.x
Browse files Browse the repository at this point in the history
Dev 1.4.x
  • Loading branch information
Arachnid-27 authored Mar 26, 2017
2 parents b7851ac + 9150dd5 commit 090b1da
Show file tree
Hide file tree
Showing 63 changed files with 1,957 additions and 1,491 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.4.6"
versionName "1.4.7"
resConfigs "en", "zh"
}
buildTypes {
Expand All @@ -37,7 +37,7 @@ dependencies {
apt 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.facebook.fresco:fresco:1.1.0'
compile 'com.facebook.fresco:fresco:1.2.0'
compile 'org.jsoup:jsoup:1.10.2'
compile 'org.adw.library:discrete-seekbar:1.0.1'
compile 'io.reactivex:rxjava:1.2.4'
Expand Down
4 changes: 1 addition & 3 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@
}

# fresco
-keepclassmembers class * {
native <methods>;
}
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.common.internal.DoNotStrip *;
}
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn com.facebook.infer.**

# greenDAO
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hiroshi/cimoc/App.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hiroshi.cimoc;

import android.app.Application;
import android.support.v4.provider.DocumentFile;
import android.support.v7.widget.RecyclerView;

import com.facebook.drawee.backends.pipeline.Fresco;
Expand All @@ -14,6 +13,7 @@
import com.hiroshi.cimoc.manager.SourceManager;
import com.hiroshi.cimoc.model.DaoMaster;
import com.hiroshi.cimoc.model.DaoSession;
import com.hiroshi.cimoc.saf.DocumentFile;
import com.hiroshi.cimoc.ui.adapter.GridAdapter;

import org.greenrobot.greendao.identityscope.IdentityScopeType;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/hiroshi/cimoc/core/Backup.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.hiroshi.cimoc.core;

import android.content.ContentResolver;
import android.support.v4.provider.DocumentFile;

import com.hiroshi.cimoc.model.Comic;
import com.hiroshi.cimoc.model.Pair;
import com.hiroshi.cimoc.model.Tag;
import com.hiroshi.cimoc.saf.DocumentFile;
import com.hiroshi.cimoc.utils.DocumentUtils;
import com.hiroshi.cimoc.utils.StringUtils;

Expand Down Expand Up @@ -92,7 +92,7 @@ public static void saveFavoriteAuto(ContentResolver resolver, DocumentFile root,
JSONObject result = new JSONObject();
result.put(JSON_KEY_VERSION, 1);
result.put(JSON_KEY_COMIC_ARRAY, buildComicArray(list));
DocumentFile file = DocumentUtils.createFile(dir, "automatic.".concat(SUFFIX_CFBF));
DocumentFile file = DocumentUtils.getOrCreateFile(dir, "automatic.".concat(SUFFIX_CFBF));
DocumentUtils.writeStringToFile(resolver, file, result.toString());
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -108,7 +108,7 @@ public static int saveFavorite(ContentResolver resolver, DocumentFile root, List
result.put(JSON_KEY_VERSION, 1);
result.put(JSON_KEY_COMIC_ARRAY, buildComicArray(list));
String filename = StringUtils.getDateStringWithSuffix(SUFFIX_CFBF);
DocumentFile file = DocumentUtils.createFile(dir, filename);
DocumentFile file = DocumentUtils.getOrCreateFile(dir, filename);
DocumentUtils.writeStringToFile(resolver, file, result.toString());
return list.size();
} catch (Exception e) {
Expand All @@ -127,7 +127,7 @@ public static int saveTag(final ContentResolver resolver, final DocumentFile roo
result.put(JSON_KEY_TAG_OBJECT, buildTagObject(tag));
result.put(JSON_KEY_COMIC_ARRAY, buildComicArray(list));
String filename = tag.getTitle().concat(".").concat(SUFFIX_CTBF);
DocumentFile file = DocumentUtils.createFile(dir, filename);
DocumentFile file = DocumentUtils.getOrCreateFile(dir, filename);
DocumentUtils.writeStringToFile(resolver, file, result.toString());
return list.size();
} catch (Exception e) {
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/hiroshi/cimoc/core/Download.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.hiroshi.cimoc.core;

import android.content.ContentResolver;
import android.support.v4.provider.DocumentFile;

import com.hiroshi.cimoc.model.Chapter;
import com.hiroshi.cimoc.model.Comic;
import com.hiroshi.cimoc.model.ImageUrl;
import com.hiroshi.cimoc.model.Pair;
import com.hiroshi.cimoc.model.Task;
import com.hiroshi.cimoc.saf.DocumentFile;
import com.hiroshi.cimoc.utils.DecryptionUtils;
import com.hiroshi.cimoc.utils.DocumentUtils;

Expand Down Expand Up @@ -95,15 +95,15 @@ public class Download {

private static void createNoMedia(DocumentFile root) {
DocumentFile home = DocumentUtils.getOrCreateSubDirectory(root, DOWNLOAD);
DocumentUtils.createFile(home, NO_MEDIA);
DocumentUtils.getOrCreateFile(home, NO_MEDIA);
}

private static DocumentFile createComicIndex(DocumentFile root, Comic comic) {
DocumentFile home = DocumentUtils.getOrCreateSubDirectory(root, DOWNLOAD);
DocumentFile source = DocumentUtils.getOrCreateSubDirectory(home, String.valueOf(comic.getSource()));
DocumentFile dir = DocumentUtils.getOrCreateSubDirectory(source, comic.getCid());
if (dir != null) {
return DocumentUtils.createFile(dir, FILE_INDEX);
return DocumentUtils.getOrCreateFile(dir, FILE_INDEX);
}
return null;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public static DocumentFile updateChapterIndex(ContentResolver resolver, Document
DocumentFile dir3 = DocumentUtils.getOrCreateSubDirectory(dir2, task.getCid());
DocumentFile dir4 = DocumentUtils.getOrCreateSubDirectory(dir3, DecryptionUtils.urlDecrypt(task.getPath().replaceAll("/|\\?", "-")));
if (dir4 != null) {
DocumentFile file = DocumentUtils.createFile(dir4, FILE_INDEX);
DocumentFile file = DocumentUtils.getOrCreateFile(dir4, FILE_INDEX);
DocumentUtils.writeStringToFile(resolver, file, "cimoc".concat(jsonString));
return dir4;
}
Expand Down Expand Up @@ -240,7 +240,9 @@ public void call(Subscriber<? super List<ImageUrl>> subscriber) {
if (uri.startsWith("file")) { // content:// 解码会出错 file:// 中文路径如果不解码 Fresco 读取不了
uri = DecryptionUtils.urlDecrypt(uri);
}
list.add(new ImageUrl(i + 1, uri, false));
ImageUrl image = new ImageUrl(i + 1, uri, false);
image.setChapter(chapter.getPath());
list.add(image);
}
subscriber.onNext(list);
subscriber.onCompleted();
Expand Down Expand Up @@ -327,6 +329,7 @@ public static Observable<Pair<Comic, List<Task>>> scan(final ContentResolver res
return Observable.create(new Observable.OnSubscribe<Pair<Comic, List<Task>>>() {
@Override
public void call(Subscriber<? super Pair<Comic, List<Task>>> subscriber) {
root.refresh();
DocumentFile downloadDir = DocumentUtils.getOrCreateSubDirectory(root, DOWNLOAD);
if (downloadDir != null) {
for (DocumentFile sourceDir : downloadDir.listFiles()) {
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/hiroshi/cimoc/core/Manga.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static Observable<Comic> getSearchResult(final Parser parser, final Strin
return Observable.create(new Observable.OnSubscribe<Comic>() {
@Override
public void call(Subscriber<? super Comic> subscriber) {
Request request = parser.getSearchRequest(keyword, page);
Random random = new Random();
try {
Request request = parser.getSearchRequest(keyword, page);
Random random = new Random();
String html = getResponseBody(App.getHttpClient(), request);
SearchIterator iterator = parser.getSearchIterator(html, page);
if (iterator == null || iterator.empty()) {
Expand All @@ -62,8 +62,8 @@ public static Observable<List<Chapter>> getComicInfo(final Parser parser, final
return Observable.create(new Observable.OnSubscribe<List<Chapter>>() {
@Override
public void call(Subscriber<? super List<Chapter>> subscriber) {
Request request = parser.getInfoRequest(comic.getCid());
try {
Request request = parser.getInfoRequest(comic.getCid());
String html = getResponseBody(App.getHttpClient(), request);
parser.parseInfo(html, comic);
request = parser.getChapterRequest(html, comic.getCid());
Expand All @@ -88,8 +88,8 @@ public static Observable<List<Comic>> getCategoryComic(final Parser parser, fina
return Observable.create(new Observable.OnSubscribe<List<Comic>>() {
@Override
public void call(Subscriber<? super List<Comic>> subscriber) {
Request request = parser.getCategoryRequest(format, page);
try {
Request request = parser.getCategoryRequest(format, page);
String html = getResponseBody(App.getHttpClient(), request);
List<Comic> list = parser.parseCategory(html, page);
if (!list.isEmpty()) {
Expand Down Expand Up @@ -117,6 +117,9 @@ public void call(Subscriber<? super List<ImageUrl>> subscriber) {
if (list.isEmpty()) {
throw new Exception();
} else {
for (ImageUrl imageUrl : list) {
imageUrl.setChapter(path);
}
subscriber.onNext(list);
subscriber.onCompleted();
}
Expand Down Expand Up @@ -151,9 +154,9 @@ public static List<ImageUrl> getImageUrls(Parser parser, String cid, String path
}

public static String getLazyUrl(Parser parser, String url) throws InterruptedIOException {
Request request = parser.getLazyRequest(url);
Response response = null;
try {
Request request = parser.getLazyRequest(url);
response = App.getHttpClient().newCall(request).execute();
if (response.isSuccessful()) {
return parser.parseLazy(response.body().string(), url);
Expand Down
70 changes: 49 additions & 21 deletions app/src/main/java/com/hiroshi/cimoc/core/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.provider.DocumentFile;

import com.hiroshi.cimoc.saf.DocumentFile;
import com.hiroshi.cimoc.utils.DocumentUtils;
import com.hiroshi.cimoc.utils.StringUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -43,17 +44,51 @@ public static DocumentFile initRoot(Context context, String uri) {
}
}

private static boolean copyDir(ContentResolver resolver, DocumentFile src, DocumentFile dst, String name) {
private static boolean copyFile(ContentResolver resolver, DocumentFile src,
DocumentFile parent, Subscriber<? super String> subscriber) {
DocumentFile file = DocumentUtils.getOrCreateFile(parent, src.getName());
if (file != null) {
subscriber.onNext(StringUtils.format("正在移动 %s...", src.getUri().getLastPathSegment()));
try {
DocumentUtils.writeBinaryToFile(resolver, src, file);
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}

private static boolean copyDir(ContentResolver resolver, DocumentFile src,
DocumentFile parent, Subscriber<? super String> subscriber) {
if (src.isDirectory()) {
DocumentFile dir = DocumentUtils.getOrCreateSubDirectory(parent, src.getName());
for (DocumentFile file : src.listFiles()) {
if (file.isDirectory()) {
if (!copyDir(resolver, file, dir, subscriber)) {
return false;
}
} else if (!copyFile(resolver, file, dir, subscriber)) {
return false;
}
}
}
return true;
}

private static boolean copyDir(ContentResolver resolver, DocumentFile src,
DocumentFile dst, String name, Subscriber<? super String> subscriber) {
DocumentFile file = src.findFile(name);
if (file != null && file.isDirectory()) {
return DocumentUtils.copyDir(resolver, file, dst);
return copyDir(resolver, file, dst, subscriber);
}
return true;
}

private static void deleteDir(DocumentFile parent, String name) {
private static void deleteDir(DocumentFile parent, String name, Subscriber<? super String> subscriber) {
DocumentFile file = parent.findFile(name);
if (file != null && file.isDirectory()) {
subscriber.onNext(StringUtils.format("正在删除 %s", file.getUri().getLastPathSegment()));
file.delete();
}
}
Expand All @@ -67,22 +102,15 @@ public static Observable<String> moveRootDir(final ContentResolver resolver, fin
return Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
if (dst.canWrite()) {
if (!isDirSame(root, dst)) {
subscriber.onNext("正在移动备份文件");
if (copyDir(resolver, root, dst, BACKUP)) {
subscriber.onNext("正在移动下载文件");
if (copyDir(resolver, root, dst, DOWNLOAD)) {
subscriber.onNext("正在移动截图文件");
if (copyDir(resolver, root, dst, PICTURE)) {
subscriber.onNext("正在删除原文件");
deleteDir(root, BACKUP);
deleteDir(root, DOWNLOAD);
deleteDir(root, PICTURE);
subscriber.onCompleted();
}
}
}
if (dst.canRead() && !isDirSame(root, dst)) {
root.refresh();
if (copyDir(resolver, root, dst, BACKUP, subscriber) &&
copyDir(resolver, root, dst, DOWNLOAD, subscriber) &&
copyDir(resolver, root, dst, PICTURE, subscriber)) {
deleteDir(root, BACKUP, subscriber);
deleteDir(root, DOWNLOAD, subscriber);
deleteDir(root, PICTURE, subscriber);
subscriber.onCompleted();
}
}
subscriber.onError(new Exception());
Expand All @@ -98,7 +126,7 @@ public void call(Subscriber<? super String> subscriber) {
try {
DocumentFile dir = DocumentUtils.getOrCreateSubDirectory(root, PICTURE);
if (dir != null) {
DocumentFile file = dir.createFile("", filename);
DocumentFile file = DocumentUtils.getOrCreateFile(dir, filename);
DocumentUtils.writeBinaryToFile(resolver, file, stream);
subscriber.onNext(file.getUri().toString());
subscriber.onCompleted();
Expand Down

This file was deleted.

Loading

0 comments on commit 090b1da

Please sign in to comment.