Commit ab7bae22 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

add refresh call on clear cache

parent 89fe6434
...@@ -10,5 +10,6 @@ import io.reactivex.Observable ...@@ -10,5 +10,6 @@ import io.reactivex.Observable
interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> { interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> {
fun signOut(): Observable<Int> fun signOut(): Observable<Int>
fun clearCache(): Observable<Int> fun clearCache(): Observable<Int>
fun refreshCacheInfo(): Observable<Int>
} }
...@@ -21,6 +21,7 @@ import com.bluelinelabs.conductor.RouterTransaction ...@@ -21,6 +21,7 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxrelay2.BehaviorRelay
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber import timber.log.Timber
...@@ -48,6 +49,8 @@ class SettingsScreenController : ...@@ -48,6 +49,8 @@ class SettingsScreenController :
.map { Timber.d("Clicked clear cache button"); 1 } .map { Timber.d("Clicked clear cache button"); 1 }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
private val refreshEmitter = BehaviorRelay.create<Int>()
override fun refreshCacheInfo(): Observable<Int> = refreshEmitter
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
...@@ -136,11 +139,15 @@ class SettingsScreenController : ...@@ -136,11 +139,15 @@ class SettingsScreenController :
private fun render(viewState: SettingsScreenViewState.Idle){ private fun render(viewState: SettingsScreenViewState.Idle){
progressShame.setGone(true) progressShame.setGone(true)
clearCacheButton.setGone(false)
} }
private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){ private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){
progressShame.setGone(viewState.progress>=1f) val isProgressed = viewState.progress>=1f
progressShame.setGone(isProgressed)
clearCacheButton.setGone(!isProgressed)
refreshEmitter.accept(1)
} }
private fun render(viewState: SettingsScreenViewState.SignOut){ private fun render(viewState: SettingsScreenViewState.SignOut){
......
...@@ -42,6 +42,10 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -42,6 +42,10 @@ class SettingsScreenPresenter @Inject constructor(
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
} }
val refreshInfo = intent(SettingsScreen::refreshCacheInfo)
.flatMap {fetchSettings}
val onClearCache = intent(SettingsScreen::clearCache) val onClearCache = intent(SettingsScreen::clearCache)
.flatMap { .flatMap {
interactor.deleteCacheFiles() interactor.deleteCacheFiles()
...@@ -52,6 +56,7 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -52,6 +56,7 @@ class SettingsScreenPresenter @Inject constructor(
} }
.startWith(SettingsScreenViewState.OnCacheDeleting(0f)) .startWith(SettingsScreenViewState.OnCacheDeleting(0f))
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
} }
...@@ -59,6 +64,7 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -59,6 +64,7 @@ class SettingsScreenPresenter @Inject constructor(
.mergeWith(fetchSettings) .mergeWith(fetchSettings)
.mergeWith(onSignOut) .mergeWith(onSignOut)
.mergeWith(onClearCache) .mergeWith(onClearCache)
.mergeWith(refreshInfo)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
......
...@@ -126,8 +126,30 @@ ...@@ -126,8 +126,30 @@
android:id="@+id/clear_cache_button" android:id="@+id/clear_cache_button"
style="@style/Default_TextView.Clear_Cache_Text" style="@style/Default_TextView.Clear_Cache_Text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_margin="32dp" /> android:layout_margin="16dp"
android:textAlignment="center" />
<FrameLayout
android:id="@+id/progress_lock_background"
android:background="@color/colorOpacityBackgroundInv"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="16dp"
android:backgroundTint="@color/colorPrimary"
android:visibility="gone"
>
<ProgressBar
android:id="@+id/settings_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center"/>
</FrameLayout>
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
...@@ -147,24 +169,6 @@ ...@@ -147,24 +169,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="32dp" /> android:layout_margin="32dp" />
<FrameLayout
android:id="@+id/progress_lock_background"
android:background="@color/colorOpacityBackgroundInv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
>
<ProgressBar
android:id="@+id/settings_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center"/>
</FrameLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
\ No newline at end of file
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