diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.kt b/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.kt index fa60dcddb..d95d82c08 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.kt @@ -55,7 +55,7 @@ class NormalPreviewSet( } override fun size(): Int { - return mPositionList.size() + return mPositionList.size } override fun getPosition(index: Int): Int { diff --git a/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.kt b/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.kt index b88255cf4..cc965728b 100644 --- a/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.kt +++ b/app/src/main/java/com/hippo/ehviewer/download/DownloadManager.kt @@ -269,7 +269,7 @@ class DownloadManager : OnSpiderListener { fun startRangeDownload(gidList: LongList) { var update = false - for (i in 0 until gidList.size()) { + for (i in 0 until gidList.size) { val gid = gidList[i] val info = mAllInfoMap[gid] if (null == info) { @@ -503,7 +503,7 @@ class DownloadManager : OnSpiderListener { fun deleteRangeDownload(gidList: LongList) { stopRangeDownloadInternal(gidList) - for (i in 0 until gidList.size()) { + for (i in 0 until gidList.size) { val gid = gidList[i] val info = mAllInfoMap[gid] if (null == info) { @@ -652,8 +652,8 @@ class DownloadManager : OnSpiderListener { // Update mDownloadListener private fun stopRangeDownloadInternal(gidList: LongList) { // Two way - if (gidList.size() < mWaitList.size) { - for (i in 0 until gidList.size()) { + if (gidList.size < mWaitList.size) { + for (i in 0 until gidList.size) { stopDownloadInternal(gidList[i]) } } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt index 3713c635f..4405e11ae 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt @@ -146,7 +146,7 @@ object CommonOperations { toAdd.add(gi) } } - if (!toStart.isEmpty) { + if (!toStart.isEmpty()) { val intent = Intent(activity, DownloadService::class.java) intent.action = DownloadService.ACTION_START_RANGE intent.putExtra(DownloadService.KEY_GID_LIST, toStart) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt index fb323e2fc..413314597 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt @@ -583,7 +583,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe // Delete val builder = CheckBoxDialogBuilder( context, - getString(R.string.download_remove_dialog_message_2, gidList!!.size()), + getString(R.string.download_remove_dialog_message_2, gidList!!.size), getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles() ) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt index 8ef025517..57b0b0180 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt @@ -357,7 +357,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh } BaseDialogBuilder(context) .setItems(menu.toTypedArray()) { _: DialogInterface?, which: Int -> - if (which < 0 || which >= menuId.size()) { + if (which < 0 || which >= menuId.size) { return@setItems } val id = menuId[which] diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index 49907e768..a2d5a5a59 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -1061,7 +1061,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl BaseDialogBuilder(context) .setTitle(tag) .setItems(menu.toTypedArray()) { _: DialogInterface?, which: Int -> - if (which < 0 || which >= menuId.size()) { + if (which < 0 || which >= menuId.size) { return@setItems } when (menuId[which]) { diff --git a/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java b/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java deleted file mode 100644 index 7e3123610..000000000 --- a/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2022 Tarsin Norbin - * - * This file is part of EhViewer - * - * EhViewer is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * EhViewer is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with EhViewer. - * If not, see . - */ - -package com.hippo.yorozuya.collect; - -public class CollectionUtils { - - /** - * An empty immutable {@code boolean} array. - */ - public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0]; - - /** - * An empty immutable {@code int} array. - */ - public static final int[] EMPTY_INT_ARRAY = new int[0]; - - /** - * An empty immutable {@code long} array. - */ - public static final long[] EMPTY_LONG_ARRAY = new long[0]; - - /** - * An empty immutable {@code String} array. - */ - public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - /** - * Appends an element to the end of the array, growing the array if there is no more room. - * - * @param array The array to which to append the element. This must NOT be null. - * @param currentSize The number of elements in the array. Must be less than or equal to - * array.length. - * @param element The element to append. - * @return the array to which the element was appended. This may be different than the given - * array. - */ - public static T[] append(T[] array, int currentSize, T element) { - if (currentSize + 1 > array.length) { - @SuppressWarnings("unchecked") - T[] newArray = (T[]) new Object[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, currentSize); - array = newArray; - } - array[currentSize] = element; - return array; - } - - /** - * Primitive boolean version of {@link #append(Object[], int, Object)}. - */ - public static boolean[] append(boolean[] array, int currentSize, boolean element) { - if (currentSize + 1 > array.length) { - boolean[] newArray = new boolean[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, currentSize); - array = newArray; - } - array[currentSize] = element; - return array; - } - - /** - * Primitive int version of {@link #append(Object[], int, Object)}. - */ - public static int[] append(int[] array, int currentSize, int element) { - if (currentSize + 1 > array.length) { - int[] newArray = new int[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, currentSize); - array = newArray; - } - array[currentSize] = element; - return array; - } - - /** - * Primitive long version of {@link #append(Object[], int, Object)}. - */ - public static long[] append(long[] array, int currentSize, long element) { - if (currentSize + 1 > array.length) { - long[] newArray = new long[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, currentSize); - array = newArray; - } - array[currentSize] = element; - return array; - } - - /** - * Inserts an element into the array at the specified index, growing the array if there is no - * more room. - * - * @param array The array to which to append the element. Must NOT be null. - * @param currentSize The number of elements in the array. Must be less than or equal to - * array.length. - * @param element The element to insert. - * @return the array to which the element was appended. This may be different than the given - * array. - */ - public static T[] insert(T[] array, int currentSize, int index, T element) { - if (currentSize + 1 <= array.length) { - System.arraycopy(array, index, array, index + 1, currentSize - index); - array[index] = element; - return array; - } - - @SuppressWarnings("unchecked") - T[] newArray = (T[]) new Object[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, index); - newArray[index] = element; - System.arraycopy(array, index, newArray, index + 1, array.length - index); - return newArray; - } - - /** - * Primitive boolean version of {@link #insert(Object[], int, int, Object)}. - */ - public static boolean[] insert(boolean[] array, int currentSize, int index, boolean element) { - if (currentSize + 1 <= array.length) { - System.arraycopy(array, index, array, index + 1, currentSize - index); - array[index] = element; - return array; - } - - boolean[] newArray = new boolean[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, index); - newArray[index] = element; - System.arraycopy(array, index, newArray, index + 1, array.length - index); - return newArray; - } - - /** - * Primitive int version of {@link #insert(Object[], int, int, Object)}. - */ - public static int[] insert(int[] array, int currentSize, int index, int element) { - if (currentSize + 1 <= array.length) { - System.arraycopy(array, index, array, index + 1, currentSize - index); - array[index] = element; - return array; - } - - int[] newArray = new int[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, index); - newArray[index] = element; - System.arraycopy(array, index, newArray, index + 1, array.length - index); - return newArray; - } - - /** - * Primitive long version of {@link #insert(Object[], int, int, Object)}. - */ - public static long[] insert(long[] array, int currentSize, int index, long element) { - if (currentSize + 1 <= array.length) { - System.arraycopy(array, index, array, index + 1, currentSize - index); - array[index] = element; - return array; - } - - long[] newArray = new long[growSize(currentSize)]; - System.arraycopy(array, 0, newArray, 0, index); - newArray[index] = element; - System.arraycopy(array, index, newArray, index + 1, array.length - index); - return newArray; - } - - /** - * Given the current size of an array, returns an ideal size to which the array should grow. - * This is typically double the given size, but should not be relied upon to do so in the - * future. - */ - public static int growSize(int currentSize) { - return currentSize <= 4 ? 8 : currentSize * 2; - } -} diff --git a/app/src/main/java/com/hippo/yorozuya/collect/IntList.kt b/app/src/main/java/com/hippo/yorozuya/collect/IntList.kt index b2e204681..617735d1a 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/IntList.kt +++ b/app/src/main/java/com/hippo/yorozuya/collect/IntList.kt @@ -1,217 +1,7 @@ -/* - * Copyright 2015 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.yorozuya.collect -package com.hippo.yorozuya.collect; +import android.os.Parcelable +import kotlinx.parcelize.Parcelize -import android.os.Parcel; -import android.os.Parcelable; - -public class IntList implements Parcelable { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - - @Override - public IntList createFromParcel(Parcel source) { - return new IntList(source); - } - - @Override - public IntList[] newArray(int size) { - return new IntList[size]; - } - }; - private static final int MIN_CAPACITY_INCREMENT = 12; - private int[] mArray; - private int mSize = 0; - - public IntList() { - mArray = CollectionUtils.EMPTY_INT_ARRAY; - } - - public IntList(int capacity) { - mArray = new int[capacity]; - } - - protected IntList(Parcel in) { - this(in.readInt()); - mSize = in.readInt(); - int s = mSize; - int[] a = mArray; - for (int i = 0; i < s; i++) { - a[i] = in.readInt(); - } - } - - static void throwIndexOutOfBoundsException(int index, int size) { - throw new IndexOutOfBoundsException("Invalid index " + index + ", size is " + size); - } - - private static int newCapacity(int currentCapacity) { - int increment = (currentCapacity < (MIN_CAPACITY_INCREMENT / 2) ? - MIN_CAPACITY_INCREMENT : currentCapacity >> 1); - return currentCapacity + increment; - } - - public void add(int value) { - int[] a = mArray; - int s = mSize; - if (s == a.length) { - int[] newArray = new int[s + - (s < (MIN_CAPACITY_INCREMENT / 2) ? - MIN_CAPACITY_INCREMENT : s >> 1)]; - System.arraycopy(a, 0, newArray, 0, s); - mArray = a = newArray; - } - a[s] = value; - mSize = s + 1; - } - - public void add(int location, int value) throws IndexOutOfBoundsException { - int[] a = mArray; - int s = mSize; - if (location > s || location < 0) { - throwIndexOutOfBoundsException(location, s); - } - - if (s < a.length) { - System.arraycopy(a, location, a, location + 1, s - location); - } else { - // assert s == a.length; - int[] newArray = new int[newCapacity(s)]; - System.arraycopy(a, 0, newArray, 0, location); - System.arraycopy(a, location, newArray, location + 1, s - location); - mArray = a = newArray; - } - a[location] = value; - mSize = s + 1; - } - - public void clear() { - mSize = 0; - } - - public boolean contains(int value) { - int[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - return true; - } - } - return false; - } - - public int get(int location) { - if (location >= mSize) { - throwIndexOutOfBoundsException(location, mSize); - } - return mArray[location]; - } - - public int indexOf(int value) { - int[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - return i; - } - } - return -1; - } - - public boolean isEmpty() { - return mSize == 0; - } - - public int removeAt(int location) { - int[] a = mArray; - int s = mSize; - if (location >= s) { - throwIndexOutOfBoundsException(location, s); - } - int result = a[location]; - System.arraycopy(a, location + 1, a, location, --s - location); - mSize = s; - return result; - } - - public boolean remove(int value) { - int[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - System.arraycopy(a, i + 1, a, i, --s - i); - mSize = s; - return true; - } - } - return false; - } - - public int set(int location, int value) { - int[] a = mArray; - if (location >= mSize) { - throwIndexOutOfBoundsException(location, mSize); - } - int result = a[location]; - a[location] = value; - return result; - } - - public int size() { - return mSize; - } - - public int[] getInternalArray() { - return mArray; - } - - @Override - public String toString() { - int[] a = mArray; - if (a == null) { - return "null"; - } - if (mSize == 0) { - return "[]"; - } - StringBuilder sb = new StringBuilder(mSize * 6); - sb.append('['); - sb.append(a[0]); - for (int i = 1; i < mSize; i++) { - sb.append(", "); - sb.append(a[i]); - } - sb.append(']'); - return sb.toString(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - int s = mSize; - int[] a = mArray; - dest.writeInt(a.length); - dest.writeInt(s); - for (int i = 0; i < s; i++) { - dest.writeInt(a[i]); - } - } -} +@Parcelize +class IntList : Parcelable, MutableList by mutableListOf() \ No newline at end of file diff --git a/app/src/main/java/com/hippo/yorozuya/collect/LongList.kt b/app/src/main/java/com/hippo/yorozuya/collect/LongList.kt index d019eaca4..139803f9d 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/LongList.kt +++ b/app/src/main/java/com/hippo/yorozuya/collect/LongList.kt @@ -1,217 +1,7 @@ -/* - * 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.yorozuya.collect -package com.hippo.yorozuya.collect; +import android.os.Parcelable +import kotlinx.parcelize.Parcelize -import android.os.Parcel; -import android.os.Parcelable; - -public class LongList implements Parcelable { - - public static final Creator CREATOR = new Creator() { - - @Override - public LongList createFromParcel(Parcel source) { - return new LongList(source); - } - - @Override - public LongList[] newArray(int size) { - return new LongList[size]; - } - }; - private static final int MIN_CAPACITY_INCREMENT = 12; - private long[] mArray; - private int mSize = 0; - - public LongList() { - mArray = CollectionUtils.EMPTY_LONG_ARRAY; - } - - public LongList(int capacity) { - mArray = new long[capacity]; - } - - protected LongList(Parcel in) { - this(in.readInt()); - mSize = in.readInt(); - int s = mSize; - long[] a = mArray; - for (int i = 0; i < s; i++) { - a[i] = in.readLong(); - } - } - - static void throwIndexOutOfBoundsException(int index, int size) { - throw new IndexOutOfBoundsException("Invalid index " + index + ", size is " + size); - } - - private static int newCapacity(int currentCapacity) { - int increment = (currentCapacity < (MIN_CAPACITY_INCREMENT / 2) ? - MIN_CAPACITY_INCREMENT : currentCapacity >> 1); - return currentCapacity + increment; - } - - public void add(long value) { - long[] a = mArray; - int s = mSize; - if (s == a.length) { - long[] newArray = new long[s + - (s < (MIN_CAPACITY_INCREMENT / 2) ? - MIN_CAPACITY_INCREMENT : s >> 1)]; - System.arraycopy(a, 0, newArray, 0, s); - mArray = a = newArray; - } - a[s] = value; - mSize = s + 1; - } - - public void add(int location, long value) throws IndexOutOfBoundsException { - long[] a = mArray; - int s = mSize; - if (location > s || location < 0) { - throwIndexOutOfBoundsException(location, s); - } - - if (s < a.length) { - System.arraycopy(a, location, a, location + 1, s - location); - } else { - // assert s == a.length; - long[] newArray = new long[newCapacity(s)]; - System.arraycopy(a, 0, newArray, 0, location); - System.arraycopy(a, location, newArray, location + 1, s - location); - mArray = a = newArray; - } - a[location] = value; - mSize = s + 1; - } - - public void clear() { - mSize = 0; - } - - public boolean contains(long value) { - long[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - return true; - } - } - return false; - } - - public long get(int location) { - if (location >= mSize) { - throwIndexOutOfBoundsException(location, mSize); - } - return mArray[location]; - } - - public int indexOf(long value) { - long[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - return i; - } - } - return -1; - } - - public boolean isEmpty() { - return mSize == 0; - } - - public long removeAt(int location) { - long[] a = mArray; - int s = mSize; - if (location >= s) { - throwIndexOutOfBoundsException(location, s); - } - long result = a[location]; - System.arraycopy(a, location + 1, a, location, --s - location); - mSize = s; - return result; - } - - public boolean remove(long value) { - long[] a = mArray; - int s = mSize; - for (int i = 0; i < s; i++) { - if (a[i] == value) { - System.arraycopy(a, i + 1, a, i, --s - i); - mSize = s; - return true; - } - } - return false; - } - - public long set(int location, long value) { - long[] a = mArray; - if (location >= mSize) { - throwIndexOutOfBoundsException(location, mSize); - } - long result = a[location]; - a[location] = value; - return result; - } - - public int size() { - return mSize; - } - - public long[] getInternalArray() { - return mArray; - } - - @Override - public String toString() { - long[] a = mArray; - if (a == null) { - return "null"; - } - if (mSize == 0) { - return "[]"; - } - StringBuilder sb = new StringBuilder(mSize * 6); - sb.append('['); - sb.append(a[0]); - for (int i = 1; i < mSize; i++) { - sb.append(", "); - sb.append(a[i]); - } - sb.append(']'); - return sb.toString(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - int s = mSize; - long[] a = mArray; - dest.writeInt(a.length); - dest.writeInt(s); - for (int i = 0; i < s; i++) { - dest.writeLong(a[i]); - } - } -} +@Parcelize +class LongList : Parcelable, MutableList by mutableListOf() \ No newline at end of file