Commit f5c98235 authored by topjohnwu's avatar topjohnwu

Remove online section in modules fragment

parent f98c68a2
......@@ -232,7 +232,7 @@ dependencies {
implementation("androidx.navigation:navigation-ui-ktx:${vNav}")
implementation("androidx.biometric:biometric:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.4")
implementation("androidx.constraintlayout:constraintlayout:2.1.0")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("androidx.browser:browser:1.3.0")
implementation("androidx.preference:preference:1.1.1")
......
......@@ -19,7 +19,6 @@ import com.topjohnwu.magisk.ktx.deviceProtectedContext
import com.topjohnwu.magisk.ui.home.HomeViewModel
import com.topjohnwu.magisk.ui.install.InstallViewModel
import com.topjohnwu.magisk.ui.log.LogViewModel
import com.topjohnwu.magisk.ui.module.ModuleViewModel
import com.topjohnwu.magisk.ui.settings.SettingsViewModel
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
import com.topjohnwu.magisk.ui.surequest.SuRequestViewModel
......@@ -61,7 +60,6 @@ object ServiceLocator {
return when (clz) {
HomeViewModel::class.java -> HomeViewModel(networkService)
LogViewModel::class.java -> LogViewModel(logRepo)
ModuleViewModel::class.java -> ModuleViewModel(repoDB, repoUpdater)
SettingsViewModel::class.java -> SettingsViewModel(repoDB)
SuperuserViewModel::class.java -> SuperuserViewModel(policyDB)
InstallViewModel::class.java -> InstallViewModel(networkService)
......
......@@ -10,8 +10,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.BaseUIFragment
import com.topjohnwu.magisk.arch.ReselectionTarget
import com.topjohnwu.magisk.arch.ViewEvent
import com.topjohnwu.magisk.core.download.BaseDownloader
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
import com.topjohnwu.magisk.di.viewModel
import com.topjohnwu.magisk.ktx.*
......@@ -42,13 +40,10 @@ class ModuleFragment : BaseUIFragment<ModuleViewModel, FragmentModuleMd2Binding>
super.onStart()
setHasOptionsMenu(true)
activity.title = resources.getString(R.string.modules)
BaseDownloader.observeProgress(this, viewModel::onProgressUpdate)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setEndlessScroller()
setEndlessSearch()
binding.moduleFilterToggle.setOnClickListener {
isFilterVisible = true
......@@ -116,13 +111,6 @@ class ModuleFragment : BaseUIFragment<ModuleViewModel, FragmentModuleMd2Binding>
// ---
override fun onEventDispatched(event: ViewEvent) = when (event) {
is EndlessRecyclerScrollListener.ResetState -> listeners.forEach { it.resetState() }
else -> super.onEventDispatched(event)
}
// ---
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_module_md2, menu)
}
......@@ -137,32 +125,12 @@ class ModuleFragment : BaseUIFragment<ModuleViewModel, FragmentModuleMd2Binding>
// ---
override fun onReselected() {
binding.moduleList
.also { it.scrollToPosition(10) }
.let { binding.moduleList }
.also { it.post { it.smoothScrollToPosition(0) } }
binding.moduleList.scrollToPosition(10)
binding.moduleList.also { it.post { it.smoothScrollToPosition(0) } }
}
// ---
override fun onPreBind(binding: FragmentModuleMd2Binding) = Unit
private fun setEndlessScroller() {
val lama = binding.moduleList.layoutManager ?: return
lama.isAutoMeasureEnabled = false
val listener = EndlessRecyclerScrollListener(lama, viewModel::loadRemote)
binding.moduleList.addOnScrollListener(listener)
listeners.add(listener)
}
private fun setEndlessSearch() {
val lama = binding.moduleFilterInclude.moduleFilterList.layoutManager ?: return
lama.isAutoMeasureEnabled = false
val listener = EndlessRecyclerScrollListener(lama, viewModel::loadMoreQuery)
binding.moduleFilterInclude.moduleFilterList.addOnScrollListener(listener)
listeners.add(listener)
}
}
......@@ -39,34 +39,27 @@ class SectionTitle(
override fun contentSameAs(other: SectionTitle): Boolean = this === other
}
sealed class RepoItem(val item: OnlineModule) : ObservableItem<RepoItem>() {
class OnlineModuleRvItem(val item: OnlineModule) : ObservableItem<OnlineModuleRvItem>() {
override val layoutRes: Int = R.layout.item_repo_md2
@get:Bindable
var progress = 0
set(value) = set(value, field, { field = it }, BR.progress)
abstract val isUpdate: Boolean
var hasUpdate = false
override fun contentSameAs(other: RepoItem): Boolean = item == other.item
override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id
override fun contentSameAs(other: OnlineModuleRvItem): Boolean = item == other.item
override fun itemSameAs(other: OnlineModuleRvItem): Boolean = item.id == other.item.id
class Update(item: OnlineModule) : RepoItem(item) {
override val isUpdate get() = true
}
class Remote(item: OnlineModule) : RepoItem(item) {
override val isUpdate get() = false
}
}
class ModuleItem(val item: LocalModule) : ObservableItem<ModuleItem>() {
class LocalModuleRvItem(val item: LocalModule) : ObservableItem<LocalModuleRvItem>() {
override val layoutRes = R.layout.item_module_md2
@get:Bindable
var repo: OnlineModule? = null
set(value) = set(value, field, { field = it }, BR.repo)
var online: OnlineModule? = null
set(value) = set(value, field, { field = it }, BR.online)
@get:Bindable
var isEnabled = item.enable
......@@ -88,11 +81,10 @@ class ModuleItem(val item: LocalModule) : ObservableItem<ModuleItem>() {
viewModel.updateActiveState()
}
override fun contentSameAs(other: ModuleItem): Boolean = item.version == other.item.version
override fun contentSameAs(other: LocalModuleRvItem): Boolean = item.version == other.item.version
&& item.versionCode == other.item.versionCode
&& item.description == other.item.description
&& item.name == other.item.name
override fun itemSameAs(other: ModuleItem): Boolean = item.id == other.item.id
override fun itemSameAs(other: LocalModuleRvItem): Boolean = item.id == other.item.id
}
......@@ -11,7 +11,7 @@
<variable
name="item"
type="com.topjohnwu.magisk.ui.module.ModuleItem" />
type="com.topjohnwu.magisk.ui.module.LocalModuleRvItem" />
<variable
name="viewModel"
......@@ -120,7 +120,7 @@
<ImageView
android:id="@+id/module_info"
style="@style/WidgetFoundation.Icon"
gone="@{item.repo == null}"
gone="@{item.online == null}"
android:layout_width="wrap_content"
android:alpha=".5"
android:clickable="true"
......
......@@ -9,7 +9,7 @@
<variable
name="item"
type="com.topjohnwu.magisk.ui.module.RepoItem" />
type="com.topjohnwu.magisk.ui.module.OnlineModuleRvItem" />
<variable
name="viewModel"
......@@ -25,7 +25,6 @@
android:clickable="true"
android:focusable="true"
android:nextFocusRight="@id/module_info"
android:onClick="@{() -> viewModel.downloadPressed(item)}"
tools:layout_gravity="center"
tools:layout_marginBottom="@dimen/l1"
tools:layout_marginEnd="@dimen/l1">
......@@ -102,7 +101,7 @@
android:layout_width="wrap_content"
android:alpha=".5"
android:nextFocusLeft="@id/module_card"
android:onClick="@{() -> viewModel.infoPressed(item)}"
android:onClick="@{() -> viewModel.infoPressed(item.item)}"
android:paddingEnd="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="@+id/module_download"
app:layout_constraintEnd_toStartOf="@+id/module_download"
......@@ -113,11 +112,11 @@
android:id="@+id/module_download"
style="@style/WidgetFoundation.Icon.Primary"
isEnabled="@{!(item.progress == -100 || (item.progress > 0 &amp;&amp; item.progress &lt; 100))}"
srcCompat="@{item.isUpdate ? R.drawable.ic_update_md2 : R.drawable.ic_download_md2}"
srcCompat="@{item.hasUpdate ? R.drawable.ic_update_md2 : R.drawable.ic_download_md2}"
android:layout_width="wrap_content"
android:contentDescription="@string/download"
android:nextFocusLeft="@id/module_info"
android:onClick="@{() -> viewModel.downloadPressed(item)}"
android:onClick="@{() -> viewModel.downloadPressed(item.item)}"
android:paddingStart="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
......@@ -154,4 +153,3 @@
</com.google.android.material.card.MaterialCardView>
</layout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment