From ff6b0bf01d328047c49afcb5cba3c89f9afc08a0 Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 13 Dec 2018 21:42:35 +0800 Subject: [PATCH] Remove ZipGalleryProvider --- .../gallery/ArchiveGalleryProvider.java | 4 +- .../ehviewer/gallery/ZipGalleryProvider.java | 228 ------------------ .../hippo/ehviewer/ui/GalleryActivity.java | 6 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-ja/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 12 files changed, 6 insertions(+), 245 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/gallery/ZipGalleryProvider.java diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java b/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java index 82ff6701d..5954a0964 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java @@ -42,7 +42,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable { - private static final String TAG = ZipGalleryProvider.class.getSimpleName(); + private static final String TAG = ArchiveGalleryProvider.class.getSimpleName(); private static final AtomicInteger sIdGenerator = new AtomicInteger(); private final UniFile file; @@ -154,7 +154,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable } if (archive == null) { size = STATE_ERROR; - error = GetText.getString(R.string.error_invalid_zip_file); + error = GetText.getString(R.string.error_invalid_archive); notifyDataChanged(); return; } diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/ZipGalleryProvider.java b/app/src/main/java/com/hippo/ehviewer/gallery/ZipGalleryProvider.java deleted file mode 100644 index 92765e256..000000000 --- a/app/src/main/java/com/hippo/ehviewer/gallery/ZipGalleryProvider.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2016 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.gallery; - -import android.os.Process; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.Log; - -import com.hippo.ehviewer.GetText; -import com.hippo.ehviewer.R; -import com.hippo.glgallery.GalleryPageView; -import com.hippo.image.Image; -import com.hippo.unifile.UniFile; -import com.hippo.yorozuya.StringUtils; -import com.hippo.yorozuya.thread.PriorityThread; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Stack; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -public class ZipGalleryProvider extends GalleryProvider2 implements Runnable { - - private static final String TAG = ZipGalleryProvider.class.getSimpleName(); - private static final AtomicInteger sIdGenerator = new AtomicInteger(); - - private final File mFile; - private final Stack mRequests = new Stack<>(); - private final AtomicInteger mDecodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX); - @Nullable - private Thread mBgThread; - private volatile int mSize = STATE_WAIT; - private String mError; - - public ZipGalleryProvider(File file) { - mFile = file; - } - - @Override - public void start() { - super.start(); - - mBgThread = new PriorityThread(this, TAG + '-' + sIdGenerator.incrementAndGet(), - Process.THREAD_PRIORITY_BACKGROUND); - mBgThread.start(); - } - - @Override - public void stop() { - super.stop(); - - if (mBgThread != null) { - mBgThread.interrupt(); - mBgThread = null; - } - } - - @Override - public int size() { - return mSize; - } - - @Override - protected void onRequest(int index) { - synchronized (mRequests) { - if (!mRequests.contains(index) && index != mDecodingIndex.get()) { - mRequests.add(index); - mRequests.notify(); - } - } - notifyPageWait(index); - } - - @Override - protected void onForceRequest(int index) { - onRequest(index); - } - - @Override - protected void onCancelRequest(int index) { - synchronized (mRequests) { - mRequests.remove(Integer.valueOf(index)); - } - } - - @Override - public String getError() { - return mError; - } - - @NonNull - @Override - public String getImageFilename(int index) { - // TODO - return Integer.toString(index); - } - - @Override - public boolean save(int index, @NonNull UniFile file) { - // TODO - return false; - } - - @Nullable - @Override - public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) { - // TODO - return null; - } - - @Override - public void run() { - ZipFile zipFile = null; - try { - zipFile = new ZipFile(mFile); - } catch (ZipException e) { - mError = GetText.getString(R.string.error_invalid_zip_file); - } catch (FileNotFoundException e) { - mError = GetText.getString(R.string.error_not_found); - } catch (IOException e) { - mError = GetText.getString(R.string.error_reading_failed); - } - - // Check zip file null - if (zipFile == null) { - mSize = STATE_ERROR; - - // Notify to to show error - notifyDataChanged(); - - Log.i(TAG, "ImageDecoder end with error"); - return; - } - - // Get all image name - List filenames = new ArrayList<>(zipFile.size()); - Enumeration enumeration = zipFile.entries(); - while (enumeration.hasMoreElements()) { - ZipEntry zipEntry = enumeration.nextElement(); - String filename = zipEntry.getName(); - if (!zipEntry.isDirectory() && StringUtils.endsWith(filename, SUPPORT_IMAGE_EXTENSIONS)) { - filenames.add(filename); - } - } - Collections.sort(filenames); - - // Update size and notify changed - mSize = filenames.size(); - notifyDataChanged(); - - while (!Thread.currentThread().isInterrupted()) { - int index; - synchronized (mRequests) { - if (mRequests.isEmpty()) { - try { - mRequests.wait(); - } catch (InterruptedException e) { - // Interrupted - break; - } - continue; - } - index = mRequests.pop(); - mDecodingIndex.lazySet(index); - } - - // Check index valid - if (index < 0 || index >= filenames.size()) { - mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX); - notifyPageFailed(index, GetText.getString(R.string.error_out_of_range)); - continue; - } - - try { - ZipEntry zipEntry = zipFile.getEntry(filenames.get(index)); - if (zipEntry != null) { - InputStream is = zipFile.getInputStream(zipEntry); - Image image = Image.decode(is, true); - mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX); - if (image != null) { - notifyPageSucceed(index, image); - } else { - notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed)); - } - } else { - mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX); - notifyPageFailed(index, GetText.getString(R.string.error_reading_failed)); - } - } catch (IOException e) { - mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX); - notifyPageFailed(index, GetText.getString(R.string.error_reading_failed)); - } - } - - // Clear - try { - zipFile.close(); - } catch (IOException e) { - // Ignore - } - - Log.i(TAG, "ImageDecoder end"); - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java index 6916dfc30..0af2fe536 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java @@ -58,7 +58,6 @@ import com.hippo.ehviewer.gallery.ArchiveGalleryProvider; import com.hippo.ehviewer.gallery.DirGalleryProvider; import com.hippo.ehviewer.gallery.EhGalleryProvider; import com.hippo.ehviewer.gallery.GalleryProvider2; -import com.hippo.ehviewer.gallery.ZipGalleryProvider; import com.hippo.ehviewer.widget.GalleryGuideView; import com.hippo.ehviewer.widget.ReversibleSeekBar; import com.hippo.glgallery.GalleryPageView; @@ -87,7 +86,6 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan GalleryView.Listener { public static final String ACTION_DIR = "dir"; - public static final String ACTION_ZIP = "zip"; public static final String ACTION_EH = "eh"; public static final String KEY_ACTION = "action"; @@ -204,10 +202,6 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan if (mFilename != null) { mGalleryProvider = new DirGalleryProvider(UniFile.fromFile(new File(mFilename))); } - } else if (ACTION_ZIP.equals(mAction)) { - if (mFilename != null) { - mGalleryProvider = new ZipGalleryProvider(new File(mFilename)); - } } else if (ACTION_EH.equals(mAction)) { if (mGalleryInfo != null) { mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6a531d1a2..b9272a08a 100755 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -44,7 +44,6 @@ Dekodierung fehlgeschlagen Nicht gefunden Leer - Die ZIP Datei wurde nicht gefunden Lesefehler Außer Reichweite Schreibfehler diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index e239fc855..e2e1880c2 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -67,7 +67,6 @@ Decodificacion fallida No encontrado Vacio - Archivo ZIP invalido Lectura Fallida Fuera de rango Falla en la escritura diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 26cc0e28a..b34d27d91 100755 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -71,7 +71,6 @@ Échec de décodage Introuvable Vide - Fiche ZIP invalide Échec de lecture Hors de portée Échec d\'écriture diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1b84948b8..bb4d1453c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -70,7 +70,6 @@ デコードに失敗しました。 見つかりませんでした。 空 - 無効なzipファイルです。 読み込めませんでした。 範囲外です。 書き込めませんでした diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 272215585..b91a61402 100755 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -70,7 +70,6 @@ 디코딩 실패 찾을 수 없음 비어 있음 - 잘못된 압축 파일 읽기 실패 범위 초과 쓰기 실패 diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1fa1e35d8..2fa404ab4 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -78,7 +78,7 @@ 解码失败 未找到 空 - 无效 zip 文件 + 无效的压缩包 读取失败 越界 写入失败 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 38d986742..511f1303a 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -78,7 +78,7 @@ 解碼失敗 未找到 空 - 無效 zip 文件 + 無效的壓縮包 讀取失敗 越界 寫入失敗 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 03f91cdfd..880a76aeb 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -78,7 +78,7 @@ 解碼失敗 沒能找到 空 - 無效的 zip 檔案 + 無效的壓縮包 讀取失敗 超出範圍 寫入失敗 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef39e5db2..cdce4e925 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -120,7 +120,7 @@ Decoding failed Not found Empty - Invalid zip file + Invalid archive Reading Failed Out of range Write failed