diff --git a/app/build.gradle b/app/build.gradle index 48bc5882..4acae130 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ apply plugin: "kotlin-android-extensions" apply plugin: "kotlinx-serialization" apply plugin: "com.google.android.gms.oss-licenses-plugin" -if (file("google-services.json").exists() && file("src/debug/google-services.json").exists()) { +if (file("google-services.json").exists()) { logger.lifecycle("Firebase Enabled") apply plugin: "com.google.gms.google-services" apply plugin: "com.google.firebase.crashlytics" @@ -38,7 +38,7 @@ android { minSdkVersion 16 targetSdkVersion 30 versionCode 63 - versionName "5.1.6-hotfix7" + versionName "5.1.7" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } @@ -77,15 +77,15 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"]) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0-M1" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1" implementation "androidx.appcompat:appcompat:1.2.0" implementation "androidx.activity:activity-ktx:1.2.0-beta01" implementation "androidx.fragment:fragment-ktx:1.3.0-beta01" implementation "androidx.preference:preference-ktx:1.1.1" implementation "androidx.recyclerview:recyclerview:1.1.0" - implementation "androidx.constraintlayout:constraintlayout:2.0.2" + implementation "androidx.constraintlayout:constraintlayout:2.0.4" implementation "androidx.gridlayout:gridlayout:1.0.0" implementation "androidx.biometric:biometric:1.0.1" implementation "androidx.work:work-runtime-ktx:2.4.0" @@ -94,10 +94,10 @@ dependencies { implementation "com.google.android.material:material:1.3.0-alpha03" - implementation "com.google.firebase:firebase-core:17.5.1" - implementation "com.google.firebase:firebase-analytics:17.6.0" - implementation "com.google.firebase:firebase-crashlytics:17.2.2" - implementation "com.google.firebase:firebase-perf:19.0.9" + implementation "com.google.firebase:firebase-core:18.0.0" + implementation "com.google.firebase:firebase-analytics:18.0.0" + implementation "com.google.firebase:firebase-crashlytics:17.3.0" + implementation "com.google.firebase:firebase-perf:19.0.10" implementation "com.google.android.gms:play-services-oss-licenses:17.0.0" implementation "com.google.android.gms:play-services-mlkit-face-detection:16.1.1" @@ -127,7 +127,7 @@ dependencies { implementation "xyz.quaver:documentfilex:0.4-alpha02" implementation "xyz.quaver:floatingsearchview:1.0.7" - testImplementation "junit:junit:4.13" + testImplementation "junit:junit:4.13.1" androidTestImplementation "androidx.test.ext:junit:1.1.2" androidTestImplementation "androidx.test:rules:1.3.0" androidTestImplementation "androidx.test:runner:1.3.0" diff --git a/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt b/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt index f56c42b1..efcfbb11 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt @@ -22,14 +22,11 @@ import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.graphics.drawable.Drawable -import android.util.Log -import android.util.SparseBooleanArray import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.Toast -import androidx.cardview.widget.CardView import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import androidx.vectordrawable.graphics.drawable.Animatable2Compat @@ -39,6 +36,7 @@ import com.daimajia.swipe.adapters.RecyclerSwipeAdapter import com.daimajia.swipe.interfaces.SwipeAdapterInterface import com.github.piasy.biv.loader.ImageLoader import kotlinx.android.synthetic.main.item_galleryblock.view.* +import kotlinx.android.synthetic.main.view_progress_card.view.* import kotlinx.coroutines.* import xyz.quaver.hitomi.getGallery import xyz.quaver.hitomi.getReader @@ -47,6 +45,7 @@ import xyz.quaver.pupil.R import xyz.quaver.pupil.favoriteTags import xyz.quaver.pupil.favorites import xyz.quaver.pupil.types.Tag +import xyz.quaver.pupil.ui.view.ProgressCard import xyz.quaver.pupil.util.Preferences import xyz.quaver.pupil.util.downloader.Cache import xyz.quaver.pupil.util.downloader.DownloadManager @@ -76,62 +75,34 @@ class GalleryBlockAdapter(private val galleries: List) : RecyclerSwipeAdapt } } - private fun updateProgress(context: Context) { - val cache = Cache.getInstance(context, galleryID) + private fun updateProgress(context: Context) = CoroutineScope(Dispatchers.Main).launch { + with(view.galleryblock_card) { + val imageList = Cache.getInstance(context, galleryID).metadata.imageList - CoroutineScope(Dispatchers.Main).launch { - if (cache.metadata.reader == null) { - view.galleryblock_progressbar_layout.visibility = View.GONE - view.galleryblock_progress_complete.visibility = View.INVISIBLE - return@launch + if (imageList == null) { + max = 0 + return@with } - with(view.galleryblock_progressbar) { - val imageList = cache.metadata.imageList!! + progress = imageList.count { it != null } + max = imageList.size - progress = imageList.count { it != null } - max = imageList.size - - with(view.galleryblock_progressbar_layout) { - if (visibility == View.GONE) - visibility = View.VISIBLE - } - - view.galleryblock_id.setOnClickListener { - (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip( - ClipData.newPlainText("gallery_id", galleryID.toString()) - ) - Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() - } - - if (!imageList.contains(null)) { - val downloadManager = DownloadManager.getInstance(context) - - if (completeFlag.get(galleryID, false)) { - with(view.galleryblock_progress_complete) { - setImageResource( - if (downloadManager.getDownloadFolder(galleryID) != null) - R.drawable.ic_progressbar - else R.drawable.ic_progressbar_cache - ) - visibility = View.VISIBLE - } - } else { - with(view.galleryblock_progress_complete) { - setImageDrawable(AnimatedVectorDrawableCompat.create(context, - if (downloadManager.getDownloadFolder(galleryID) != null) - R.drawable.ic_progressbar_complete - else R.drawable.ic_progressbar_complete_cache - ).apply { - this?.start() - }) - visibility = View.VISIBLE - } - completeFlag.put(galleryID, true) - } - } else - view.galleryblock_progress_complete.visibility = View.INVISIBLE + view.galleryblock_id.setOnClickListener { + (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip( + ClipData.newPlainText("gallery_id", galleryID.toString()) + ) + Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() } + + type = if (!imageList.contains(null)) { + val downloadManager = DownloadManager.getInstance(context) + + if (downloadManager.getDownloadFolder(galleryID) == null) + ProgressCard.Type.CACHE + else + ProgressCard.Type.DOWNLOAD + } else + ProgressCard.Type.LOADING } } @@ -326,8 +297,6 @@ class GalleryBlockAdapter(private val galleries: List) : RecyclerSwipeAdapt } } - val completeFlag = SparseBooleanArray() - val onChipClickedHandler = ArrayList<((Tag) -> Unit)>() var onDownloadClickedHandler: ((Int) -> Unit)? = null var onDeleteClickedHandler: ((Int) -> Unit)? = null @@ -341,7 +310,7 @@ class GalleryBlockAdapter(private val galleries: List) : RecyclerSwipeAdapt return when(ViewType.values()[type]) { ViewType.NEXT -> NextViewHolder(view as LinearLayout) ViewType.PREV -> PrevViewHolder(view as LinearLayout) - ViewType.GALLERY -> GalleryViewHolder(view as CardView) + ViewType.GALLERY -> GalleryViewHolder(view as ProgressCard) } } @@ -361,30 +330,21 @@ class GalleryBlockAdapter(private val galleries: List) : RecyclerSwipeAdapt holder.bind(galleryID) - with(holder.view.galleryblock_primary) { - setOnClickListener { - holder.view.performClick() - } - setOnLongClickListener { - holder.view.performLongClick() - } - } - - holder.view.galleryblock_download.setOnClickListener { + holder.view.galleryblock_card.download.setOnClickListener { onDownloadClickedHandler?.invoke(position) } - holder.view.galleryblock_delete.setOnClickListener { + holder.view.galleryblock_card.delete.setOnClickListener { onDeleteClickedHandler?.invoke(position) } mItemManger.bindView(holder.view, position) - holder.view.galleryblock_swipe_layout.addSwipeListener(object: SwipeLayout.SwipeListener { + holder.view.galleryblock_card.swipe_layout.addSwipeListener(object: SwipeLayout.SwipeListener { override fun onStartOpen(layout: SwipeLayout?) { mItemManger.closeAllExcept(layout) - holder.view.galleryblock_download.text = + holder.view.galleryblock_card.download.text = if (DownloadManager.getInstance(holder.view.context).isDownloading(galleryID)) holder.view.context.getString(android.R.string.cancel) else @@ -413,5 +373,5 @@ class GalleryBlockAdapter(private val galleries: List) : RecyclerSwipeAdapt }.ordinal } - override fun getSwipeLayoutResourceId(position: Int) = R.id.galleryblock_swipe_layout + override fun getSwipeLayoutResourceId(position: Int) = R.id.swipe_layout } \ No newline at end of file diff --git a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt index c3ba9aaf..a0d1b088 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt @@ -36,6 +36,7 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatDelegate import androidx.cardview.widget.CardView import androidx.core.view.GravityCompat +import androidx.recyclerview.widget.RecyclerView import com.google.android.material.appbar.AppBarLayout import com.google.android.material.navigation.NavigationView import com.google.android.material.snackbar.Snackbar @@ -56,6 +57,7 @@ import xyz.quaver.pupil.services.DownloadService import xyz.quaver.pupil.types.* import xyz.quaver.pupil.ui.dialog.DownloadLocationDialogFragment import xyz.quaver.pupil.ui.dialog.GalleryDialog +import xyz.quaver.pupil.ui.view.ProgressCard import xyz.quaver.pupil.util.ItemClickSupport import xyz.quaver.pupil.util.Preferences import xyz.quaver.pupil.util.checkUpdate @@ -359,14 +361,12 @@ class MainActivity : loadBlocks() } - completeFlag.put(galleryID, false) - closeAllItems() } } ItemClickSupport.addTo(this).apply { onItemClickListener = listener@{ _, position, v -> - if (v !is CardView) + if (v !is ProgressCard) return@listener val intent = Intent(this@MainActivity, ReaderActivity::class.java) @@ -377,7 +377,7 @@ class MainActivity : } onItemLongClickListener = listener@{ _, position, v -> - if (v !is CardView) + if (v !is ProgressCard) return@listener false val galleryID = galleries.getOrNull(position) ?: return@listener true @@ -835,7 +835,6 @@ class MainActivity : with(main_recyclerview.adapter as GalleryBlockAdapter?) { this ?: return@with - this.completeFlag.clear() this.notifyDataSetChanged() } diff --git a/app/src/main/java/xyz/quaver/pupil/ui/view/ProgressCard.kt b/app/src/main/java/xyz/quaver/pupil/ui/view/ProgressCard.kt new file mode 100644 index 00000000..d8c77ff4 --- /dev/null +++ b/app/src/main/java/xyz/quaver/pupil/ui/view/ProgressCard.kt @@ -0,0 +1,70 @@ +package xyz.quaver.pupil.ui.view + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.view.ViewGroup +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.ContextCompat +import androidx.core.graphics.drawable.DrawableCompat +import kotlinx.android.synthetic.main.view_progress_card.view.* +import xyz.quaver.pupil.R + +class ProgressCard @JvmOverloads constructor(context: Context, attr: AttributeSet? = null, defStyle: Int = R.attr.cardViewStyle) : ConstraintLayout(context, attr, defStyle) { + + enum class Type { + LOADING, + CACHE, + DOWNLOAD + } + + var type: Type = Type.LOADING + set(value) { + field = value + + when (field) { + Type.LOADING -> R.color.colorAccent + Type.CACHE -> R.color.material_blue_700 + Type.DOWNLOAD -> R.color.material_green_a700 + }.let { + val color = ContextCompat.getColor(context, it) + DrawableCompat.setTint(progressbar.progressDrawable, color) + } + } + + var progress: Int + get() = progressbar?.progress ?: 0 + set(value) { + progressbar?.progress = value + } + var max: Int + get() = progressbar?.max ?: 0 + set(value) { + progressbar?.max = value + + progressbar.visibility = + if (value == 0) + GONE + else + VISIBLE + } + + init { + inflate(context, R.layout.view_progress_card, this) + + content.setOnClickListener { + performClick() + } + + content.setOnLongClickListener { + performLongClick() + } + } + + override fun addView(child: View?, params: ViewGroup.LayoutParams?) = + if (childCount == 0) + super.addView(child, params) + else + content.addView(child, params) + +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_galleryblock.xml b/app/src/main/res/layout/item_galleryblock.xml index 6f5bd44c..b8fc0792 100644 --- a/app/src/main/res/layout/item_galleryblock.xml +++ b/app/src/main/res/layout/item_galleryblock.xml @@ -17,217 +17,133 @@ ~ along with this program. If not, see . --> - - + + + android:layout_marginTop="8dp" + android:layout_marginLeft="8dp" + app:layout_constraintLeft_toRightOf="@id/galleryblock_thumbnail" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@id/progressbar" /> - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/view_progress_card.xml b/app/src/main/res/layout/view_progress_card.xml new file mode 100644 index 00000000..2b7b65bb --- /dev/null +++ b/app/src/main/res/layout/view_progress_card.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1a8fd9ad..e7191ef0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,15 +6,15 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:4.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - classpath "com.google.gms:google-services:4.3.3" + classpath "com.google.gms:google-services:4.3.4" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath "com.google.firebase:firebase-crashlytics-gradle:2.3.0" - classpath "com.google.firebase:perf-plugin:1.3.2" + classpath "com.google.firebase:firebase-crashlytics-gradle:2.4.1" + classpath "com.google.firebase:perf-plugin:1.3.4" classpath "com.google.android.gms:oss-licenses-plugin:0.10.2" } }