|
|
|
@ -10,8 +10,10 @@ import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.updatePadding
|
|
|
|
import androidx.core.view.updatePadding
|
|
|
|
import coil.ImageLoader
|
|
|
|
import coil.ImageLoader
|
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.ui.BaseActivity
|
|
|
|
import org.koitharu.kotatsu.core.ui.BaseActivity
|
|
|
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
|
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
|
|
|
@ -21,6 +23,7 @@ import org.koitharu.kotatsu.core.util.ext.observeEvent
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.toLocale
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.toLocale
|
|
|
|
import org.koitharu.kotatsu.databinding.ActivitySourcesCatalogBinding
|
|
|
|
import org.koitharu.kotatsu.databinding.ActivitySourcesCatalogBinding
|
|
|
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
|
|
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.settings.newsources.NewSourcesDialogFragment
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
@AndroidEntryPoint
|
|
|
|
@ -31,6 +34,8 @@ class SourcesCatalogActivity : BaseActivity<ActivitySourcesCatalogBinding>(),
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
lateinit var coil: ImageLoader
|
|
|
|
lateinit var coil: ImageLoader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var newSourcesSnackbar: Snackbar? = null
|
|
|
|
|
|
|
|
|
|
|
|
override val appBar: AppBarLayout
|
|
|
|
override val appBar: AppBarLayout
|
|
|
|
get() = viewBinding.appbar
|
|
|
|
get() = viewBinding.appbar
|
|
|
|
|
|
|
|
|
|
|
|
@ -45,6 +50,7 @@ class SourcesCatalogActivity : BaseActivity<ActivitySourcesCatalogBinding>(),
|
|
|
|
val tabMediator = TabLayoutMediator(viewBinding.tabs, viewBinding.pager, pagerAdapter)
|
|
|
|
val tabMediator = TabLayoutMediator(viewBinding.tabs, viewBinding.pager, pagerAdapter)
|
|
|
|
tabMediator.attach()
|
|
|
|
tabMediator.attach()
|
|
|
|
viewModel.content.observe(this, pagerAdapter)
|
|
|
|
viewModel.content.observe(this, pagerAdapter)
|
|
|
|
|
|
|
|
viewModel.hasNewSources.observe(this, ::onHasNewSourcesChanged)
|
|
|
|
viewModel.onActionDone.observeEvent(
|
|
|
|
viewModel.onActionDone.observeEvent(
|
|
|
|
this,
|
|
|
|
this,
|
|
|
|
ReversibleActionObserver(viewBinding.pager),
|
|
|
|
ReversibleActionObserver(viewBinding.pager),
|
|
|
|
@ -80,4 +86,31 @@ class SourcesCatalogActivity : BaseActivity<ActivitySourcesCatalogBinding>(),
|
|
|
|
viewModel.performSearch(null)
|
|
|
|
viewModel.performSearch(null)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun onHasNewSourcesChanged(hasNewSources: Boolean) {
|
|
|
|
|
|
|
|
if (hasNewSources) {
|
|
|
|
|
|
|
|
if (newSourcesSnackbar?.isShownOrQueued == true) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val snackbar = Snackbar.make(viewBinding.pager, R.string.new_sources_text, Snackbar.LENGTH_INDEFINITE)
|
|
|
|
|
|
|
|
snackbar.setAction(R.string.explore) {
|
|
|
|
|
|
|
|
NewSourcesDialogFragment.show(supportFragmentManager)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
snackbar.addCallback(
|
|
|
|
|
|
|
|
object : Snackbar.Callback() {
|
|
|
|
|
|
|
|
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
|
|
|
|
|
|
|
super.onDismissed(transientBottomBar, event)
|
|
|
|
|
|
|
|
if (event == DISMISS_EVENT_SWIPE) {
|
|
|
|
|
|
|
|
viewModel.skipNewSources()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
snackbar.show()
|
|
|
|
|
|
|
|
newSourcesSnackbar = snackbar
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
newSourcesSnackbar?.dismiss()
|
|
|
|
|
|
|
|
newSourcesSnackbar = null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|