Commit 5f42ed50 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Fix crash on fast change page with swipeToRefresh progress.

parent 83246dfd
package ru.terrakok.gitlabclient.ui.global
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.ViewGroup
import com.arellomobile.mvp.MvpAppCompatFragment
......@@ -15,6 +16,8 @@ abstract class BaseFragment : MvpAppCompatFragment() {
private var instanceStateSaved: Boolean = false
private val viewHandler = Handler()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(layoutRes, container, false)
......@@ -23,6 +26,17 @@ abstract class BaseFragment : MvpAppCompatFragment() {
instanceStateSaved = false
}
//fix for async views (like swipeToRefresh and RecyclerView)
//if synchronously call actions on swipeToRefresh in sequence show and hide then swipeToRefresh will not hidden
protected fun postViewAction(action: () -> Unit) {
viewHandler.post(action)
}
override fun onDestroyView() {
super.onDestroyView()
viewHandler.removeCallbacksAndMessages(null)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
instanceStateSaved = true
......
......@@ -58,7 +58,7 @@ class MyEventsFragment : BaseFragment(), MyEventsView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -66,11 +66,11 @@ class MyEventsFragment : BaseFragment(), MyEventsView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -85,7 +85,7 @@ class MyEventsFragment : BaseFragment(), MyEventsView {
override fun showEvents(show: Boolean, events: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(events) }
postViewAction { adapter.setData(events) }
}
override fun showMessage(message: String) {
......
......@@ -82,7 +82,7 @@ class MyIssuesFragment : BaseFragment(), MyIssuesView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -90,11 +90,11 @@ class MyIssuesFragment : BaseFragment(), MyIssuesView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -109,7 +109,7 @@ class MyIssuesFragment : BaseFragment(), MyIssuesView {
override fun showIssues(show: Boolean, issues: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(issues) }
postViewAction { adapter.setData(issues) }
}
override fun showMessage(message: String) {
......
......@@ -82,7 +82,7 @@ class MyMergeRequestsFragment : BaseFragment(), MyMergeRequestListView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -90,11 +90,11 @@ class MyMergeRequestsFragment : BaseFragment(), MyMergeRequestListView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -109,7 +109,7 @@ class MyMergeRequestsFragment : BaseFragment(), MyMergeRequestListView {
override fun showMergeRequests(show: Boolean, mergeRequests: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(mergeRequests) }
postViewAction { adapter.setData(mergeRequests) }
}
override fun showMessage(message: String) {
......
......@@ -71,7 +71,7 @@ class MyTodosFragment : BaseFragment(), MyTodoListView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -79,11 +79,11 @@ class MyTodosFragment : BaseFragment(), MyTodoListView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -98,7 +98,7 @@ class MyTodosFragment : BaseFragment(), MyTodoListView {
override fun showTodos(show: Boolean, todos: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(todos) }
postViewAction { adapter.setData(todos) }
}
override fun showMessage(message: String) {
......
......@@ -76,7 +76,7 @@ class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -84,11 +84,11 @@ class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -103,7 +103,7 @@ class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
override fun showIssues(show: Boolean, issues: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(issues) }
postViewAction { adapter.setData(issues) }
}
override fun showMessage(message: String) {
......
......@@ -76,7 +76,7 @@ class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -84,11 +84,11 @@ class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showPageProgress(show: Boolean) {
recyclerView.post { adapter.showProgress(show) }
postViewAction { adapter.showProgress(show) }
}
override fun showEmptyView(show: Boolean) {
......@@ -103,7 +103,7 @@ class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
override fun showMergeRequests(show: Boolean, mergeRequests: List<TargetHeader>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(mergeRequests) }
postViewAction { adapter.setData(mergeRequests) }
}
override fun showMessage(message: String) {
......
......@@ -66,7 +66,7 @@ class ProjectsListFragment : BaseFragment(), ProjectsListView {
}
override fun showRefreshProgress(show: Boolean) {
swipeToRefresh.post { swipeToRefresh?.isRefreshing = show }
postViewAction { swipeToRefresh.isRefreshing = show }
}
override fun showEmptyProgress(show: Boolean) {
......@@ -74,7 +74,7 @@ class ProjectsListFragment : BaseFragment(), ProjectsListView {
//trick for disable and hide swipeToRefresh on fullscreen progress
swipeToRefresh.visible(!show)
swipeToRefresh.post { swipeToRefresh.isRefreshing = false }
postViewAction { swipeToRefresh.isRefreshing = false }
}
override fun showEmptyView(show: Boolean) {
......@@ -89,7 +89,7 @@ class ProjectsListFragment : BaseFragment(), ProjectsListView {
override fun showProjects(show: Boolean, projects: List<Project>) {
recyclerView.visible(show)
recyclerView.post { adapter.setData(projects) }
postViewAction { adapter.setData(projects) }
}
override fun showMessage(message: String) {
......@@ -97,7 +97,7 @@ class ProjectsListFragment : BaseFragment(), ProjectsListView {
}
override fun showPageProgress(isVisible: Boolean) {
recyclerView.post { adapter.showProgress(isVisible) }
postViewAction { adapter.showProgress(isVisible) }
}
override fun onBackPressed() = presenter.onBackPressed()
......
buildscript {
ext.kotlinVersion = '1.2.61'
ext.kotlinVersion = '1.2.70'
repositories {
jcenter()
google()
......@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha10'
classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.0.1'
classpath 'io.fabric.tools:gradle:1.25.4'
......
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