mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[UI/Login] Add refresh button in platform list.
This commit is contained in:
parent
f39d0c595d
commit
477730708f
@ -47,6 +47,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var timeoutJob: Job
|
private lateinit var timeoutJob: Job
|
||||||
|
private lateinit var adapter: LoginPlatformAdapter
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
if (!isAdded) return
|
if (!isAdded) return
|
||||||
@ -57,12 +58,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
|||||||
val loginMode = arguments?.getInt("loginMode") ?: return
|
val loginMode = arguments?.getInt("loginMode") ?: return
|
||||||
val mode = register.loginModes.firstOrNull { it.loginMode == loginMode } ?: return
|
val mode = register.loginModes.firstOrNull { it.loginMode == loginMode } ?: return
|
||||||
|
|
||||||
timeoutJob = startCoroutineTimer(5000L) {
|
adapter = LoginPlatformAdapter(activity) { platform ->
|
||||||
b.timeoutText.isVisible = true
|
|
||||||
timeoutJob.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
val adapter = LoginPlatformAdapter(activity) { platform ->
|
|
||||||
nav.navigate(R.id.loginFormFragment, Bundle(
|
nav.navigate(R.id.loginFormFragment, Bundle(
|
||||||
"loginType" to platform.loginType,
|
"loginType" to platform.loginType,
|
||||||
"loginMode" to platform.loginMode,
|
"loginMode" to platform.loginMode,
|
||||||
@ -73,7 +69,30 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
|||||||
), activity.navOptions)
|
), 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 {
|
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]
|
val platforms = LoginInfo.platformList[mode.name]
|
||||||
?: run {
|
?: run {
|
||||||
api.runCatching(activity) {
|
api.runCatching(activity) {
|
||||||
@ -87,14 +106,11 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
|||||||
|
|
||||||
adapter.items = platforms
|
adapter.items = platforms
|
||||||
b.list.adapter = adapter
|
b.list.adapter = adapter
|
||||||
b.list.apply {
|
|
||||||
setHasFixedSize(true)
|
|
||||||
layoutManager = LinearLayoutManager(context)
|
|
||||||
addItemDecoration(SimpleDividerItemDecoration(context))
|
|
||||||
}
|
|
||||||
timeoutJob.cancel()
|
timeoutJob.cancel()
|
||||||
b.loadingLayout.isVisible = false
|
b.loadingLayout.isVisible = false
|
||||||
b.list.isVisible = true
|
b.list.isVisible = true
|
||||||
|
b.reloadButton.isEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,15 @@
|
|||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
</LinearLayout>
|
</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
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user