ProgressCard
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
70
app/src/main/java/xyz/quaver/pupil/ui/view/ProgressCard.kt
Normal file
70
app/src/main/java/xyz/quaver/pupil/ui/view/ProgressCard.kt
Normal file
@@ -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)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user