mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 04:28:55 +01:00
Replace more usages of Kotlin synthetic views
This commit is contained in:
@@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
@@ -201,7 +200,7 @@ class LibraryController(
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.actionToolbar.offsetAppbarHeight(activity!!)
|
||||
(activity!! as MainActivity).fixViewToBottom(binding.actionToolbar)
|
||||
}
|
||||
|
||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.ui.main
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.SearchManager
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
@@ -21,7 +20,6 @@ import com.bluelinelabs.conductor.Router
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.Migrations
|
||||
import eu.kanade.tachiyomi.R
|
||||
@@ -48,8 +46,6 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.view.applyInsets
|
||||
import kotlinx.android.synthetic.main.main_activity.appbar
|
||||
import kotlinx.android.synthetic.main.main_activity.tabs
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import timber.log.Timber
|
||||
@@ -418,6 +414,19 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to manually offset a view within the activity's child views that might be cut off due to the
|
||||
* collapsing AppBarLayout.
|
||||
*/
|
||||
fun fixViewToBottom(view: View) {
|
||||
binding.appbar.addOnOffsetChangedListener(
|
||||
AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||
val maxAbsOffset = appBarLayout.measuredHeight - binding.tabs.measuredHeight
|
||||
view.translationY = -maxAbsOffset - verticalOffset.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun setBottomNavBehaviorOnScroll() {
|
||||
showBottomNav(visible = true)
|
||||
|
||||
@@ -444,18 +453,3 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||
const val INTENT_SEARCH_FILTER = "filter"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to manually offset a view within the activity's child views that might be cut off due to the
|
||||
* collapsing AppBarLayout.
|
||||
*/
|
||||
fun View.offsetAppbarHeight(activity: Activity) {
|
||||
val appbar: AppBarLayout = activity.appbar
|
||||
val tabs: TabLayout = activity.tabs
|
||||
appbar.addOnOffsetChangedListener(
|
||||
AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||
val maxAbsOffset = appBarLayout.measuredHeight - tabs.measuredHeight
|
||||
translationY = -maxAbsOffset - verticalOffset.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
||||
import eu.kanade.tachiyomi.ui.library.ChangeMangaCoverDialog
|
||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersAdapter
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersSettingsSheet
|
||||
@@ -239,7 +238,7 @@ class MangaController :
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.actionToolbar.offsetAppbarHeight(activity!!)
|
||||
(activity!! as MainActivity).fixViewToBottom(binding.actionToolbar)
|
||||
|
||||
settingsSheet = ChaptersSettingsSheet(router, presenter) { group ->
|
||||
if (group is ChaptersSettingsSheet.Filter.FilterGroup) {
|
||||
|
||||
@@ -2,22 +2,22 @@ package eu.kanade.tachiyomi.ui.reader.viewer
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.text.bold
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.view.isVisible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.ReaderTransitionViewBinding
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
|
||||
import kotlinx.android.synthetic.main.reader_transition_view.view.lower_text
|
||||
import kotlinx.android.synthetic.main.reader_transition_view.view.upper_text
|
||||
import kotlinx.android.synthetic.main.reader_transition_view.view.warning
|
||||
import kotlinx.android.synthetic.main.reader_transition_view.view.warning_text
|
||||
|
||||
class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
LinearLayout(context, attrs) {
|
||||
|
||||
private val binding: ReaderTransitionViewBinding
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.reader_transition_view, this)
|
||||
binding = ReaderTransitionViewBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
@@ -37,20 +37,20 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
|
||||
val prevChapter = transition.to
|
||||
|
||||
val hasPrevChapter = prevChapter != null
|
||||
lower_text.isVisible = hasPrevChapter
|
||||
binding.lowerText.isVisible = hasPrevChapter
|
||||
if (hasPrevChapter) {
|
||||
upper_text.textAlignment = TEXT_ALIGNMENT_TEXT_START
|
||||
upper_text.text = buildSpannedString {
|
||||
binding.upperText.textAlignment = TEXT_ALIGNMENT_TEXT_START
|
||||
binding.upperText.text = buildSpannedString {
|
||||
bold { append(context.getString(R.string.transition_current)) }
|
||||
append("\n${transition.from.chapter.name}")
|
||||
}
|
||||
lower_text.text = buildSpannedString {
|
||||
binding.lowerText.text = buildSpannedString {
|
||||
bold { append(context.getString(R.string.transition_previous)) }
|
||||
append("\n${prevChapter!!.chapter.name}")
|
||||
}
|
||||
} else {
|
||||
upper_text.textAlignment = TEXT_ALIGNMENT_CENTER
|
||||
upper_text.text = context.getString(R.string.transition_no_previous)
|
||||
binding.upperText.textAlignment = TEXT_ALIGNMENT_CENTER
|
||||
binding.upperText.text = context.getString(R.string.transition_no_previous)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,26 +61,26 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
|
||||
val nextChapter = transition.to
|
||||
|
||||
val hasNextChapter = nextChapter != null
|
||||
lower_text.isVisible = hasNextChapter
|
||||
binding.lowerText.isVisible = hasNextChapter
|
||||
if (hasNextChapter) {
|
||||
upper_text.textAlignment = TEXT_ALIGNMENT_TEXT_START
|
||||
upper_text.text = buildSpannedString {
|
||||
binding.upperText.textAlignment = TEXT_ALIGNMENT_TEXT_START
|
||||
binding.upperText.text = buildSpannedString {
|
||||
bold { append(context.getString(R.string.transition_finished)) }
|
||||
append("\n${transition.from.chapter.name}")
|
||||
}
|
||||
lower_text.text = buildSpannedString {
|
||||
binding.lowerText.text = buildSpannedString {
|
||||
bold { append(context.getString(R.string.transition_next)) }
|
||||
append("\n${nextChapter!!.chapter.name}")
|
||||
}
|
||||
} else {
|
||||
upper_text.textAlignment = TEXT_ALIGNMENT_CENTER
|
||||
upper_text.text = context.getString(R.string.transition_no_next)
|
||||
binding.upperText.textAlignment = TEXT_ALIGNMENT_CENTER
|
||||
binding.upperText.text = context.getString(R.string.transition_no_next)
|
||||
}
|
||||
}
|
||||
|
||||
private fun missingChapterWarning(transition: ChapterTransition) {
|
||||
if (transition.to == null) {
|
||||
warning.isVisible = false
|
||||
binding.warning.isVisible = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
|
||||
}
|
||||
|
||||
if (!hasMissingChapters) {
|
||||
warning.isVisible = false
|
||||
binding.warning.isVisible = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
|
||||
is ChapterTransition.Next -> calculateChapterDifference(transition.to, transition.from)
|
||||
}
|
||||
|
||||
warning_text.text = resources.getQuantityString(R.plurals.missing_chapters_warning, chapterDifference.toInt(), chapterDifference.toInt())
|
||||
warning.isVisible = true
|
||||
binding.warningText.text = resources.getQuantityString(R.plurals.missing_chapters_warning, chapterDifference.toInt(), chapterDifference.toInt())
|
||||
binding.warning.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
@@ -109,7 +108,7 @@ class UpdatesController :
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.actionToolbar.offsetAppbarHeight(activity!!)
|
||||
(activity!! as MainActivity).fixViewToBottom(binding.actionToolbar)
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
|
||||
Reference in New Issue
Block a user