Part 1 of updating source controller

This commit is contained in:
Jay 2020-04-19 04:17:47 -04:00
parent 5e56f80709
commit 83990793a2
13 changed files with 123 additions and 85 deletions

View File

@ -1,14 +0,0 @@
package eu.kanade.tachiyomi.source.online
import eu.kanade.tachiyomi.source.Source
import okhttp3.Response
import rx.Observable
interface LoginSource : Source {
fun isLogged(): Boolean
fun login(username: String, password: String): Observable<Boolean>
fun isAuthenticationSuccessful(response: Response): Boolean
}

View File

@ -75,7 +75,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
var headerHeight = 0
var showingExtenions = false
var showingExtensions = false
/**
* Called when controller is initialized.
@ -85,7 +85,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
}
override fun getTitle(): String? {
return if (showingExtenions)
return if (showingExtensions)
applicationContext?.getString(R.string.extensions)
else applicationContext?.getString(R.string.sources)
}
@ -114,7 +114,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
// Create recycler and set adapter.
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
recycler.adapter = adapter
recycler.addItemDecoration(SourceDividerItemDecoration(view.context))
// recycler.addItemDecoration(SourceDividerItemDecoration(view.context))
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
val array = view.context.obtainStyledAttributes(attrsArray)
val appBarHeight = array.getDimensionPixelSize(0, 0)
@ -135,9 +135,9 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
sheet_layout.alpha = 1 - progress
activity?.appbar?.y = max(activity!!.appbar.y, -headerHeight * (1 - progress))
val oldShow = showingExtenions
showingExtenions = progress > 0.92f
if (oldShow != showingExtenions) {
val oldShow = showingExtensions
showingExtensions = progress > 0.92f
if (oldShow != showingExtensions) {
setTitle()
activity?.invalidateOptionsMenu()
}
@ -149,7 +149,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
state == BottomSheetBehavior.STATE_COLLAPSED) {
sheet_layout.alpha =
if (state == BottomSheetBehavior.STATE_COLLAPSED) 1f else 0f
showingExtenions = state == BottomSheetBehavior.STATE_EXPANDED
showingExtensions = state == BottomSheetBehavior.STATE_EXPANDED
setTitle()
if (state == BottomSheetBehavior.STATE_EXPANDED)
ext_bottom_sheet.fetchOnlineExtensionsIfNeeded()
@ -164,7 +164,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
}
})
if (showingExtenions) {
if (showingExtensions) {
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
}
}
@ -276,7 +276,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
}
override fun expandSearch() {
if (showingExtenions)
if (showingExtensions)
ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
else activity?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView()
}
@ -288,8 +288,8 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
* @param inflater used to load the menu xml.
*/
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
if (onRoot) (activity as? MainActivity)?.setDismissIcon(showingExtenions)
if (showingExtenions) {
if (onRoot) (activity as? MainActivity)?.setDismissIcon(showingExtensions)
if (showingExtensions) {
// Inflate menu
inflater.inflate(R.menu.extension_main, menu)
@ -340,7 +340,7 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
// Initialize option to open catalogue settings.
R.id.action_filter -> {
val controller =
if (showingExtenions)
if (showingExtensions)
SettingsExtensionsController()
else SettingsSourcesController()
router.pushController(

View File

@ -26,8 +26,8 @@ class SourceDividerItemDecoration(context: Context) : androidx.recyclerview.widg
val params = child.layoutParams as androidx.recyclerview.widget.RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + holder.margin
val right = parent.width - parent.paddingEnd - holder.margin
val left = parent.paddingStart // + holder.margin
val right = parent.width - parent.paddingEnd // - holder.margin
divider.setBounds(left, top, right, bottom)
divider.draw(c)

View File

@ -1,33 +1,24 @@
package eu.kanade.tachiyomi.ui.catalogue
import android.view.View
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.roundTextIcon
import eu.kanade.tachiyomi.util.view.visible
import io.github.mthli.slice.Slice
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.*
class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
BaseFlexibleViewHolder(view, adapter),
SlicedHolder {
class SourceHolder(view: View, val adapter: CatalogueAdapter) :
BaseFlexibleViewHolder(view, adapter) {
override val slice = Slice(card).apply {
/*override val slice = Slice(card).apply {
setColor(adapter.cardBackground)
}
override val viewToSlice: View
get() = card
get() = card*/
init {
source_browse.setOnClickListener {
adapter.browseClickListener.onBrowseClick(adapterPosition)
}
source_latest.setOnClickListener {
adapter.latestClickListener.onLatestClick(adapterPosition)
}
@ -35,7 +26,7 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
fun bind(item: SourceItem) {
val source = item.source
setCardEdges(item)
// setCardEdges(item)
// Set source name
title.text = source.name
@ -47,17 +38,10 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
else edit_button.roundTextIcon(source.name)
}
// If source is login, show only login option
if (source is LoginSource && !source.isLogged()) {
source_browse.setText(R.string.login)
source_latest.gone()
if (source.supportsLatest) {
source_latest.visible()
} else {
source_browse.setText(R.string.browse)
if (source.supportsLatest) {
source_latest.visible()
} else {
source_latest.gone()
}
source_latest.gone()
}
}
}

View File

@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCataloguePresenter
import rx.Observable
@ -104,8 +103,8 @@ open class CatalogueSearchPresenter(
val languages = preferencesHelper.enabledLanguages().getOrDefault()
val hiddenCatalogues = preferencesHelper.hiddenCatalogues().getOrDefault()
return sourceManager.getCatalogueSources().filter { it.lang in languages }
.filterNot { it is LoginSource && !it.isLogged() }
return sourceManager.getCatalogueSources()
.filter { it.lang in languages }
.filterNot { it.id.toString() in hiddenCatalogues }
.sortedBy { "(${it.lang}) ${it.name}" }
}

View File

@ -1,13 +1,15 @@
package eu.kanade.tachiyomi.ui.migration
import android.view.View
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
import eu.kanade.tachiyomi.util.view.roundTextIcon
import io.github.mthli.slice.Slice
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.*
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.card
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.edit_button
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.title
import kotlinx.android.synthetic.main.migration_card_item.*
class SourceHolder(view: View, override val adapter: SourceAdapter) :
BaseFlexibleViewHolder(view, adapter),
@ -21,12 +23,10 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) :
get() = card
init {
source_latest.text = view.context.getString(R.string.auto)
source_browse.setText(R.string.select)
source_browse.setOnClickListener {
migration_auto.setOnClickListener {
adapter.selectClickListener?.onSelectClick(adapterPosition)
}
source_latest.setOnClickListener {
migration_select.setOnClickListener {
adapter.autoClickListener?.onAutoClick(adapterPosition)
}
}

View File

@ -21,7 +21,7 @@ data class SourceItem(val source: Source, val header: SelectionHeader? = null) :
* Returns the layout resource of this item.
*/
override fun getLayoutRes(): Int {
return R.layout.catalogue_main_controller_card_item
return R.layout.migration_card_item
}
/**

View File

@ -0,0 +1,8 @@
<!-- drawable/alert_octagram.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M2.2,16.06L3.88,12L2.2,7.94L6.26,6.26L7.94,2.2L12,3.88L16.06,2.2L17.74,6.26L21.8,7.94L20.12,12L21.8,16.06L17.74,17.74L16.06,21.8L12,20.12L7.94,21.8L6.26,17.74L2.2,16.06M13,17V15H11V17H13M13,13V7H11V13H13Z" />
</vector>

View File

@ -7,12 +7,12 @@
<TextView
android:id="@+id/title"
style="@style/TextAppearance.Regular.SubHeading"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="@dimen/material_component_text_fields_padding_above_and_below_label"
android:paddingStart="12dp"
tools:text="Title" />
</FrameLayout>

View File

@ -16,6 +16,7 @@
android:id="@+id/edit_button"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="6dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
@ -31,32 +32,24 @@
android:paddingStart="0dp"
android:paddingEnd="8dp"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.Regular.SubHeading"
android:textColor="?android:textColorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/source_latest"
app:layout_constraintStart_toEndOf="@+id/edit_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/source_latest"
tools:text="Source title"/>
tools:text="Source title" />
<Button
<com.google.android.material.button.MaterialButton
android:id="@+id/source_latest"
style="@style/Theme.Widget.Button.Borderless.Small"
style="@style/Theme.Widget.Button.TextButton"
android:textColor="?colorAccent"
android:layout_marginEnd="12dp"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/latest"
app:layout_constraintEnd_toStartOf="@+id/source_browse"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="@+id/source_browse"
style="@style/Theme.Widget.Button.Borderless.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/browse"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
android:letterSpacing="0.0"
android:text="@string/view_latest"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="@dimen/material_component_lists_two_line_height"
android:background="?attr/selectable_list_drawable">
<ImageView
android:id="@+id/edit_button"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:paddingStart="0dp"
android:paddingEnd="8dp"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.Regular.SubHeading"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/edit_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/migration_auto"
tools:text="Source title"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/migration_auto"
style="@style/Theme.Widget.Button.Borderless.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/auto"
app:layout_constraintEnd_toStartOf="@id/migration_select"
android:layout_marginEnd="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/migration_select"
style="@style/Theme.Widget.Button.Borderless.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View File

@ -206,6 +206,7 @@
<string name="local_library">Local library</string>
<string name="other">Other</string>
<string name="global_search">Global search…</string>
<string name="view_latest">View latest</string>
<string name="latest">Latest</string>
<string name="browse">Browse</string>
<string name="in_library">In Library</string>

View File

@ -214,6 +214,7 @@
</style>
<style name="Theme.Widget.Button.Borderless" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textAllCaps">false</item>
<item name="android:textColor">?attr/colorAccent</item>
<item name="rippleColor">@color/fullRippleColor</item>
</style>
@ -247,7 +248,7 @@
<style name="Theme.Widget.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textAllCaps">false</item>
<item name="rippleColor">@color/fullRippleColor</item>
<item name="android:letterSpacing">0.0</item>
<item name="android:textColor">?colorAccent</item>
</style>