[UI/Login] Add refresh button in platform list.

This commit is contained in:
Kuba Szczodrzyński 2020-10-17 23:44:17 +02:00
parent f39d0c595d
commit 477730708f
2 changed files with 36 additions and 11 deletions

View File

@ -47,6 +47,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
}
private lateinit var timeoutJob: Job
private lateinit var adapter: LoginPlatformAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (!isAdded) return
@ -57,12 +58,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
val loginMode = arguments?.getInt("loginMode") ?: return
val mode = register.loginModes.firstOrNull { it.loginMode == loginMode } ?: return
timeoutJob = startCoroutineTimer(5000L) {
b.timeoutText.isVisible = true
timeoutJob.cancel()
}
val adapter = LoginPlatformAdapter(activity) { platform ->
adapter = LoginPlatformAdapter(activity) { platform ->
nav.navigate(R.id.loginFormFragment, Bundle(
"loginType" to platform.loginType,
"loginMode" to platform.loginMode,
@ -73,7 +69,30 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
), activity.navOptions)
}
loadPlatforms(register, mode)
b.reloadButton.isVisible = App.devMode
b.reloadButton.onClick {
LoginInfo.platformList.remove(mode.name)
loadPlatforms(register, mode)
}
b.list.apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(context)
addItemDecoration(SimpleDividerItemDecoration(context))
}
}
private fun loadPlatforms(register: LoginInfo.Register, mode: LoginInfo.Mode) {
launch {
timeoutJob = startCoroutineTimer(5000L) {
b.timeoutText.isVisible = true
timeoutJob.cancel()
}
b.loadingLayout.isVisible = true
b.list.isVisible = false
b.reloadButton.isEnabled = false
val platforms = LoginInfo.platformList[mode.name]
?: run {
api.runCatching(activity) {
@ -87,14 +106,11 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
adapter.items = platforms
b.list.adapter = adapter
b.list.apply {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(context)
addItemDecoration(SimpleDividerItemDecoration(context))
}
timeoutJob.cancel()
b.loadingLayout.isVisible = false
b.list.isVisible = true
b.reloadButton.isEnabled = true
}
}
}

View File

@ -78,6 +78,15 @@
tools:visibility="visible" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/reloadButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/refresh"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"