Updating tracking layout

This commit is contained in:
Jay 2020-03-20 23:16:59 -04:00
parent 4d094105a9
commit 1b6f7deb21
11 changed files with 255 additions and 146 deletions

View File

@ -156,6 +156,7 @@ class MangaDetailsController : BaseController,
private var trackingBottomSheet: TrackingBottomSheet? = null
private var startingDLChapterPos: Int? = null
private var editMangaDialog: EditMangaDialog? = null
var refreshTracker: Int? = null
/**
* Adapter containing a list of chapters.
@ -256,6 +257,7 @@ class MangaDetailsController : BaseController,
})
setPaletteColor()
swipe_refresh.isRefreshing = presenter.isLoading
if (manga?.initialized != true)
swipe_refresh.post { swipe_refresh.isRefreshing = true }
@ -305,7 +307,12 @@ class MangaDetailsController : BaseController,
super.onActivityResumed(activity)
presenter.isLockedFromSearch = SecureActivityDelegate.shouldBeLocked()
presenter.headerItem.isLocked = presenter.isLockedFromSearch
presenter.fetchChapters()
presenter.fetchChapters(refreshTracker == null)
if (refreshTracker != null) {
trackingBottomSheet?.refreshItem(refreshTracker ?: 0)
presenter.refreshTrackers()
refreshTracker = null
}
val isCurrentController = router?.backstack?.lastOrNull()?.controller() ==
this
if (isCurrentController) {
@ -334,7 +341,10 @@ class MangaDetailsController : BaseController,
} else if (type == ControllerChangeType.PUSH_EXIT || type == ControllerChangeType.POP_EXIT) {
if (router.backstack.lastOrNull()?.controller() is DialogController)
return
if (type == ControllerChangeType.POP_EXIT) setHasOptionsMenu(false)
if (type == ControllerChangeType.POP_EXIT) {
setHasOptionsMenu(false)
presenter.cancelScope()
}
colorAnimator?.cancel()
val colorPrimary = activity?.getResourceColor(

View File

@ -90,13 +90,16 @@ class MangaDetailsPresenter(
fun onDestroy() {
downloadManager.removeListener(this)
LibraryUpdateService.removeListener(this)
}
fun cancelScope() {
scope.cancel()
}
fun fetchChapters() {
fun fetchChapters(andTracking: Boolean = true) {
scope.launch {
getChapters()
refreshTracking()
if (andTracking) refreshTracking()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}
}
@ -648,7 +651,7 @@ class MangaDetailsPresenter(
fun refreshTrackers() {
scope.launch {
val list = trackList.filter { it.track != null }.map { item ->
trackList.filter { it.track != null }.map { item ->
withContext(Dispatchers.IO) {
val trackItem = try {
item.service.refresh(item.track!!)

View File

@ -119,6 +119,7 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
activity.toast(R.string.url_not_set)
} else {
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(track.tracking_url)))
controller.refreshTracker = position
}
}
@ -158,6 +159,10 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
refreshTrack(item.service)
}
fun refreshItem(index: Int) {
(track_recycler.findViewHolderForAdapterPosition(index) as? TrackHolder)?.setProgress(true)
}
fun refreshTrack(item: TrackService?) {
val index = adapter?.indexOf(item) ?: -1
if (index > -1) {

View File

@ -2,7 +2,10 @@ package eu.kanade.tachiyomi.ui.manga.track
import android.annotation.SuppressLint
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.track_item.*
@ -11,9 +14,10 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
init {
val listener = adapter.rowClickListener
logo_container.setOnClickListener { listener.onLogoClick(adapterPosition) }
track_set.setOnClickListener { listener.onSetClick(adapterPosition) }
status_container.setOnClickListener { listener.onStatusClick(adapterPosition) }
chapters_container.setOnClickListener { listener.onChaptersClick(adapterPosition) }
add_tracking.setOnClickListener { listener.onSetClick(adapterPosition) }
track_title.setOnClickListener { listener.onSetClick(adapterPosition) }
track_status.setOnClickListener { listener.onStatusClick(adapterPosition) }
track_chapters.setOnClickListener { listener.onChaptersClick(adapterPosition) }
score_container.setOnClickListener { listener.onScoreClick(adapterPosition) }
}
@ -22,11 +26,28 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) {
val track = item.track
track_logo.setImageResource(item.service.getLogo())
logo_container.setBackgroundColor(item.service.getLogoColor())
logo_container.updateLayoutParams<ConstraintLayout.LayoutParams> {
bottomToBottom = if (track != null) divider.id else track_details.id
}
track_logo.contentDescription = item.service.name
track_group.visibleIf(track != null)
add_tracking.visibleIf(track == null)
if (track != null) {
track_chapters.text = "${track.last_chapter_read}/" +
if (track.total_chapters > 0) track.total_chapters else "-"
track_status.text = item.service.getStatus(track.status)
track_title.text = track.title
with(track_chapters) {
text = when {
track.total_chapters > 0 -> context.getString(
R.string.chapter_x_of_y, track.last_chapter_read, track.total_chapters
)
track.last_chapter_read > 0 -> context.getString(
R.string.chapter_x, track.last_chapter_read
)
else -> context.getString(R.string.action_filter_not_started)
}
}
val status = item.service.getStatus(track.status)
if (status.isEmpty()) track_status.setText(R.string.unknown_status)
else track_status.text = item.service.getStatus(track.status)
track_score.text = if (track.score == 0f) "-" else item.service.displayScore(track)
}
}

View File

@ -64,9 +64,7 @@ class TrackSearchDialog : DialogController {
val dialog = MaterialDialog(activity!!).apply {
customView(viewRes = R.layout.track_search_dialog, scrollable = false)
negativeButton(android.R.string.cancel)
positiveButton(
if (wasPreviouslyTracked) R.string.action_clear
else R.string.action_track) { onPositiveButtonClick() }
positiveButton(R.string.action_clear) { onPositiveButtonClick() }
setActionButtonEnabled(WhichButton.POSITIVE, wasPreviouslyTracked)
}
@ -90,9 +88,7 @@ class TrackSearchDialog : DialogController {
selectedItem = null
subscriptions += view.track_search_list.itemClicks().subscribe { position ->
selectedItem = adapter.getItem(position)
(dialog as? MaterialDialog)?.positiveButton(R.string.action_track)
(dialog as? MaterialDialog)?.setActionButtonEnabled(WhichButton.POSITIVE, true)
trackItem(position)
}
// Do an initial search based on the manga's title
@ -103,6 +99,13 @@ class TrackSearchDialog : DialogController {
}
}
private fun trackItem(position: Int) {
selectedItem = adapter?.getItem(position)
bottomSheet.refreshTrack(service)
presenter.registerTracking(selectedItem, service)
dismissDialog()
}
override fun onDestroyView(view: View) {
super.onDestroyView(view)
subscriptions.unsubscribe()
@ -139,9 +142,7 @@ class TrackSearchDialog : DialogController {
view.track_search_list.visibility = View.VISIBLE
adapter?.setItems(results)
if (results.size == 1 && !wasPreviouslyTracked) {
selectedItem = adapter?.getItem(0)
(dialog as? MaterialDialog)?.positiveButton(R.string.action_track)
(dialog as? MaterialDialog)?.setActionButtonEnabled(WhichButton.POSITIVE, true)
trackItem(0)
}
}
@ -154,7 +155,7 @@ class TrackSearchDialog : DialogController {
private fun onPositiveButtonClick() {
bottomSheet.refreshTrack(service)
presenter.registerTracking(selectedItem,
presenter.registerTracking(null,
service)
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/fullRippleColor">
<item android:id="@android:id/mask">
<color android:color="@color/fullRippleColor" />
</item>
<item>
<selector>
<item android:state_selected="true">
<color android:color="@color/fullRippleColor" />
</item>
<item android:state_activated="true">
<color android:color="@color/fullRippleColor" />
</item>
<item android:id="@android:id/mask">
<color android:color="@color/dialog" />
</item>
</selector>
</item>
</ripple>

View File

@ -0,0 +1,5 @@
<vector android:height="12dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

View File

@ -7,28 +7,31 @@
android:padding="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/track_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:minHeight="?attr/actionBarSize">
android:layout_weight="1"
android:background="@color/dialog">
<FrameLayout
android:id="@+id/logo_container"
android:layout_width="48dp"
android:layout_height="0dp"
android:foreground="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintBottom_toBottomOf="parent"
android:foreground="?selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical"
android:padding="4dp"
app:layout_constraintBottom_toBottomOf="@id/status_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/status_container"
app:layout_constraintTop_toTopOf="parent"
tools:background="#2E51A2">
<ImageView
android:id="@+id/track_logo"
android:layout_width="wrap_content"
android:contentDescription="@string/tracking"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:src="@drawable/tracker_mal" />
@ -39,129 +42,164 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:visibility="gone"/>
android:visibility="gone" />
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/status_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/card_item_selector"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/logo_container"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/track_title"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/card_item_selector"
android:ellipsize="end"
android:maxLines="1"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingBottom="16dp"
android:text="@string/title"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="dfdffggjdfigjssdfgidfjgidgjdifgjfdgifdjgid" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:alpha="0.25"
android:background="?android:attr/textColorHint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/logo_container"
app:layout_constraintTop_toBottomOf="@+id/status_container" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/sub_tracking_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider">
<TextView
android:id="@+id/track_status"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/card_item_selector"
android:gravity="center"
android:maxLines="2"
android:paddingStart="6dp"
android:paddingTop="16dp"
android:paddingEnd="6dp"
android:paddingBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/track_chapters"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Currently Reading" />
<TextView
android:id="@+id/track_chapters"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/card_item_selector"
android:gravity="center"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/score_container"
app:layout_constraintStart_toEndOf="@id/track_status"
app:layout_constraintTop_toTopOf="parent"
tools:text="Chapter 12 of 24" />
<FrameLayout
android:id="@+id/score_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/card_item_selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/track_chapters"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/track_score"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableEnd="@drawable/ic_star_12dp"
android:drawableTint="?android:attr/textColorPrimary"
tools:text="10" />
</FrameLayout>
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:alpha="0.25"
android:background="?android:attr/textColorHint"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/track_status"
app:layout_constraintEnd_toStartOf="@id/track_chapters"/>
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:alpha="0.25"
android:background="?android:attr/textColorHint"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/track_chapters"
app:layout_constraintEnd_toStartOf="@id/score_container"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/add_tracking"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:letterSpacing="0.0"
android:text="@string/add_tracking"
android:textAlignment="textStart"
android:visibility="gone"
app:icon="@drawable/ic_edit_white_24dp"
app:iconTint="?colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/logo_container"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<androidx.constraintlayout.widget.Group
android:id="@+id/track_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="chapters_container,status_container,score_container" />
<LinearLayout
android:id="@+id/status_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectable_list_drawable"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:layout_constraintStart_toEndOf="@id/logo_container"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/chapters_container"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingBottom="16dp">
<TextView
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/status" />
<TextView
android:id="@+id/track_status"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:text="Currently Reading" />
</LinearLayout>
<LinearLayout
android:id="@+id/chapters_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constrainedHeight="true"
android:background="?attr/selectable_list_drawable"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/status_container"
app:layout_constraintEnd_toStartOf="@id/score_container"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingEnd="8dp"
android:paddingBottom="16dp">
<TextView
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chapters" />
<TextView
android:id="@+id/track_chapters"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:text="12/24" />
</LinearLayout>
<LinearLayout
android:id="@+id/score_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?attr/selectable_list_drawable"
app:layout_constraintBottom_toBottomOf="parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/chapters_container"
app:layout_constraintEnd_toStartOf="@id/track_set"
android:paddingStart="8dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">
<TextView
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/score" />
<TextView
android:id="@+id/track_score"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:text="10" />
</LinearLayout>
<ImageButton
android:id="@+id/track_set"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/action_edit"
android:padding="8dp"
android:tint="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/score_container"
app:srcCompat="@drawable/ic_edit_white_24dp" />
android:visibility="gone"
app:constraint_referenced_ids="sub_tracking_layout,status_container,divider" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -3,12 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/display_bottom_sheet"
android:layout_width="match_parent"
android:background="@drawable/bg_bottom_sheet_dialog_fragment"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/track_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_bottom_sheet_dialog_fragment"
android:paddingTop="5dp"
tools:listitem="@layout/track_item" />
</FrameLayout>

View File

@ -12,7 +12,7 @@
<color name="cardBackground">#212121</color>
<color name="rippleColor">@color/md_white_1000_20</color>
<color name="fullRippleColor">#707070</color>
<color name="dialogBackground">@color/md_grey_800</color>
<color name="dialogBackground">#171717</color>
<color name="colorAccent">#3399FF</color>
<color name="splashBackground">#212121</color>
<color name="actionModeShadow">@color/md_white_1000_38</color>
@ -28,7 +28,7 @@
<color name="divider">@color/md_white_1000_12</color>
<color name="background">#1C1C1D</color>
<color name="dialog">@color/md_grey_800</color>
<color name="dialog">#212121</color>
<color name="selectorColor">@color/md_blue_A200_50</color>
<color name="iconColor">@color/md_white_1000_54</color>

View File

@ -593,6 +593,9 @@
<string name="track_start_date">Started</string>
<string name="track_type">Type</string>
<string name="url_not_set">Manga URL not set, please click title and select manga again</string>
<string name="add_tracking">Add Tracking</string>
<string name="chapter_x_of_y">Chapter %1$d of %2$d</string>
<string name="chapter_x">Chapter %1$d</string>
<!-- Category activity -->
<string name="error_category_exists">A category with this name already exists!</string>