From 338751ef2bb848dd06c96b06ae90f8ad92438a63 Mon Sep 17 00:00:00 2001 From: tarsin Date: Tue, 23 Aug 2022 19:34:04 +0800 Subject: [PATCH] Drop unused code --- .../java/com/hippo/conaco/ConacoTask.java | 104 +----------------- .../java/com/hippo/conaco/DataContainer.java | 52 --------- .../ehviewer/ui/scene/DownloadsScene.java | 72 +----------- .../com/hippo/scene/TransitionHelper.java | 27 ----- .../java/com/hippo/widget/LoadImageView.java | 20 +--- 5 files changed, 8 insertions(+), 267 deletions(-) delete mode 100644 app/src/main/java/com/hippo/conaco/DataContainer.java delete mode 100644 app/src/main/java/com/hippo/scene/TransitionHelper.java diff --git a/app/src/main/java/com/hippo/conaco/ConacoTask.java b/app/src/main/java/com/hippo/conaco/ConacoTask.java index b063ef183..dc943c843 100644 --- a/app/src/main/java/com/hippo/conaco/ConacoTask.java +++ b/app/src/main/java/com/hippo/conaco/ConacoTask.java @@ -51,7 +51,6 @@ public final class ConacoTask { private final WeakReference> mUnikeryWeakReference; private final String mKey; private final String mUrl; - private final DataContainer mDataContainer; private final boolean mUseMemoryCache; private final boolean mUseDiskCache; private final boolean mUseNetwork; @@ -73,7 +72,6 @@ public final class ConacoTask { mUnikeryWeakReference = new WeakReference<>(builder.mUnikery); mKey = builder.mKey; mUrl = builder.mUrl; - mDataContainer = builder.mDataContainer; mUseMemoryCache = builder.mUseMemoryCache; mUseDiskCache = builder.mUseDiskCache; mUseNetwork = builder.mUseNetwork; @@ -85,42 +83,6 @@ public final class ConacoTask { mConaco = builder.mConaco; } - private static void putFromDiskCacheToDataContainer(String key, ValueCache cache, DataContainer container) { - SimpleDiskCache diskCache = cache.getDiskCache(); - if (diskCache != null) { - InputStreamPipe pipe = diskCache.getInputStreamPipe(key); - if (pipe != null) { - try { - pipe.obtain(); - container.save(pipe.open(), -1L, null, null); - } catch (IOException e) { - Log.d(TAG, "Can't save value from disk cache to data container"); - e.printStackTrace(); - container.remove(); - } finally { - pipe.close(); - pipe.release(); - } - } - } - } - - private static void putFromDataContainerToDiskCache(String key, ValueCache cache, DataContainer container) { - InputStreamPipe pipe = container.get(); - if (pipe != null) { - try { - pipe.obtain(); - cache.putRawToDisk(key, pipe.open()); - } catch (IOException e) { - Log.w(TAG, "Can't save value from data container to disk cache", e); - cache.removeFromDisk(key); - } finally { - pipe.close(); - pipe.release(); - } - } - } - int getId() { return mId; } @@ -219,7 +181,6 @@ public final class ConacoTask { private Unikery mUnikery; private String mKey; private String mUrl; - private DataContainer mDataContainer; private boolean mUseMemoryCache = true; private boolean mUseDiskCache = true; private boolean mUseNetwork = true; @@ -262,11 +223,6 @@ public final class ConacoTask { return this; } - public Builder setDataContainer(DataContainer dataContainer) { - mDataContainer = dataContainer; - return this; - } - boolean isUseMemoryCache() { return mUseMemoryCache; } @@ -332,7 +288,7 @@ public final class ConacoTask { if (mUnikery == null) { throw new IllegalStateException("Must set unikery"); } - if (mKey == null && mUrl == null && mDataContainer == null) { + if (mKey == null && mUrl == null) { throw new IllegalStateException("At least one of mKey and mUrl and mDataContainer have to not be null"); } } @@ -352,26 +308,13 @@ public final class ConacoTask { } else { V value = null; - // First check data container - if (mDataContainer != null && mDataContainer.isEnabled()) { - InputStreamPipe isp = mDataContainer.get(); - if (isp != null) { - value = mHelper.decode(isp); - } - } - // Then check disk cache if (mKey != null) { if (value == null && mUseDiskCache) { value = mCache.getFromDisk(mKey); - // Put back to data container - if (value != null && mDataContainer != null && mDataContainer.isEnabled()) { - putFromDiskCacheToDataContainer(mKey, mCache, mDataContainer); - } } if (value != null && mUseMemoryCache && mHelper.useMemoryCache(mKey, value)) { - // Put it to memory mCache.putToMemory(mKey, value); } } @@ -451,18 +394,6 @@ public final class ConacoTask { } } - private boolean putToDataContainer(InputStream is, ResponseBody body) { - // Get media type - String mediaType; - MediaType mt = body.contentType(); - if (mt != null) { - mediaType = mt.type() + '/' + mt.subtype(); - } else { - mediaType = null; - } - return mDataContainer.save(is, body.contentLength(), mediaType, this); - } - @Override protected V doInBackground(Void... params) { if (isNotNecessary(this)) { @@ -489,7 +420,7 @@ public final class ConacoTask { return null; } - if ((mDataContainer == null || !mDataContainer.isEnabled()) && mKey != null) { + if (mKey != null) { if (putToDiskCache(is, body.contentLength())) { // Get object from disk cache value = mCache.getFromDisk(mKey); @@ -506,37 +437,6 @@ public final class ConacoTask { mCache.removeFromDisk(mKey); return null; } - } else if (mDataContainer != null && mDataContainer.isEnabled()) { - // Check url Moved - HttpUrl requestHttpUrl = request.url(); - HttpUrl responseHttpUrl = response.request().url(); - if (!responseHttpUrl.equals(requestHttpUrl)) { - mDataContainer.onUrlMoved(mUrl, responseHttpUrl.url().toString()); - } - - // Put to data container - if (!putToDataContainer(is, body)) { - return null; - } - - // Get value from data container - InputStreamPipe isp = mDataContainer.get(); - if (isp == null) { - return null; - } - value = mHelper.decode(isp); - if (value == null) { - mDataContainer.remove(); - } else if (mKey != null) { - // Put to disk cache - putFromDataContainerToDiskCache(mKey, mCache, mDataContainer); - - if (mUseMemoryCache && mHelper.useMemoryCache(mKey, value)) { - // Put it to memory - mCache.putToMemory(mKey, value); - } - } - return value; } else { return null; } diff --git a/app/src/main/java/com/hippo/conaco/DataContainer.java b/app/src/main/java/com/hippo/conaco/DataContainer.java deleted file mode 100644 index 3513111d5..000000000 --- a/app/src/main/java/com/hippo/conaco/DataContainer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015-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.conaco; - -import androidx.annotation.Nullable; - -import com.hippo.streampipe.InputStreamPipe; - -import java.io.InputStream; - -public interface DataContainer { - - /** - * Returns the enabled status for this DataContainer. - */ - boolean isEnabled(); - - /** - * Get 304 or something like that - */ - void onUrlMoved(String requestUrl, String responseUrl); - - /** - * Save the {@code InputStream} - */ - boolean save(InputStream is, long length, @Nullable String mediaType, @Nullable ProgressNotifier notify); - - /** - * Get {@code InputStreamPipe} for saved before - */ - @Nullable - InputStreamPipe get(); - - /** - * Remove saved stuff - */ - void remove(); -} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.java index 9c5dddeef..a9ec35439 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.java @@ -55,8 +55,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.hippo.app.CheckBoxDialogBuilder; import com.hippo.app.EditTextDialogBuilder; -import com.hippo.conaco.DataContainer; -import com.hippo.conaco.ProgressNotifier; import com.hippo.easyrecyclerview.EasyRecyclerView; import com.hippo.easyrecyclerview.FastScroller; import com.hippo.easyrecyclerview.HandlerDrawable; @@ -885,73 +883,6 @@ public class DownloadsScene extends ToolbarScene } } - private static class ThumbDataContainer implements DataContainer { - - private final DownloadInfo mInfo; - @Nullable - private UniFile mFile; - - public ThumbDataContainer(@NonNull DownloadInfo info) { - mInfo = info; - } - - private void ensureFile() { - if (mFile == null) { - UniFile dir = SpiderDen.getGalleryDownloadDir(mInfo); - if (dir != null && dir.isDirectory()) { - mFile = dir.createFile(".thumb"); - } - } - } - - @Override - public boolean isEnabled() { - ensureFile(); - return mFile != null; - } - - @Override - public void onUrlMoved(String requestUrl, String responseUrl) { - } - - @Override - public boolean save(InputStream is, long length, String mediaType, ProgressNotifier notify) { - ensureFile(); - if (mFile == null) { - return false; - } - - OutputStream os = null; - try { - os = mFile.openOutputStream(); - IOUtils.copy(is, os); - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } finally { - IOUtils.closeQuietly(os); - } - } - - @Override - public InputStreamPipe get() { - ensureFile(); - if (mFile != null) { - return new UniFileInputStreamPipe(mFile); - } else { - return null; - } - } - - @Override - public void remove() { - if (mFile != null) { - mFile.delete(); - } - } - } - private class DownloadLabelAdapter extends RecyclerView.Adapter { private final LayoutInflater mInflater; @@ -1230,8 +1161,7 @@ public class DownloadsScene extends ToolbarScene return; } DownloadInfo info = mList.get(position); - holder.thumb.load(EhCacheKeyFactory.getThumbKey(info.gid), info.thumb, - new ThumbDataContainer(info), true); + holder.thumb.load(EhCacheKeyFactory.getThumbKey(info.gid), info.thumb, true); holder.title.setText(EhUtils.getSuitableTitle(info)); holder.uploader.setText(info.uploader); holder.rating.setRating(info.rating); diff --git a/app/src/main/java/com/hippo/scene/TransitionHelper.java b/app/src/main/java/com/hippo/scene/TransitionHelper.java deleted file mode 100644 index 6852526bf..000000000 --- a/app/src/main/java/com/hippo/scene/TransitionHelper.java +++ /dev/null @@ -1,27 +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.scene; - -import android.content.Context; - -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentTransaction; - -public interface TransitionHelper { - - boolean onTransition(Context context, FragmentTransaction transaction, Fragment exit, Fragment enter); -} diff --git a/app/src/main/java/com/hippo/widget/LoadImageView.java b/app/src/main/java/com/hippo/widget/LoadImageView.java index d0f4467d4..f470d08bf 100644 --- a/app/src/main/java/com/hippo/widget/LoadImageView.java +++ b/app/src/main/java/com/hippo/widget/LoadImageView.java @@ -34,7 +34,6 @@ import androidx.core.content.ContextCompat; import com.hippo.conaco.Conaco; import com.hippo.conaco.ConacoTask; -import com.hippo.conaco.DataContainer; import com.hippo.conaco.Unikery; import com.hippo.drawable.PreciselyClipDrawable; import com.hippo.ehviewer.EhApplication; @@ -56,7 +55,6 @@ public class LoadImageView extends FixedAspectImageView implements Unikery mConaco; private String mKey; private String mUrl; - private DataContainer mContainer; private boolean mUseNetwork; private int mOffsetX = Integer.MIN_VALUE; private int mOffsetY = Integer.MIN_VALUE; @@ -109,7 +107,7 @@ public class LoadImageView extends FixedAspectImageView implements Unikery builder = new ConacoTask.Builder() .setUnikery(this) .setKey(key) .setUrl(url) - .setDataContainer(container) .setUseNetwork(useNetwork); mConaco.load(builder); } @@ -255,7 +247,6 @@ public class LoadImageView extends FixedAspectImageView implements Unikery