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

provide clear cache functionality

parent 9e3f65bf
...@@ -30,6 +30,8 @@ class FilesContractModule @Inject constructor( ...@@ -30,6 +30,8 @@ class FilesContractModule @Inject constructor(
return FileModule.getDirectory(context,d) return FileModule.getDirectory(context,d)
} }
override fun deleteAllFiles() = files.deleteAllCacheObservable()
override fun getPlansSize() = getFile<FileModule.FileDirectory.PlanTypeDir>().folderSize override fun getPlansSize() = getFile<FileModule.FileDirectory.PlanTypeDir>().folderSize
override fun getToursSize() = getFile<FileModule.FileDirectory.ToursDir>().folderSize override fun getToursSize() = getFile<FileModule.FileDirectory.ToursDir>().folderSize
......
...@@ -6,6 +6,7 @@ import android.os.Environment ...@@ -6,6 +6,7 @@ import android.os.Environment
import com.biganto.visual.roompark.util.extensions.asInt import com.biganto.visual.roompark.util.extensions.asInt
import com.google.gson.JsonElement import com.google.gson.JsonElement
import dagger.Module import dagger.Module
import io.reactivex.Observable
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import javax.inject.Inject import javax.inject.Inject
...@@ -61,7 +62,24 @@ class FileModule @Inject constructor(val context: Application) { ...@@ -61,7 +62,24 @@ class FileModule @Inject constructor(val context: Application) {
fun deleteFile(uri:String)= getFile(uri).delete() fun deleteFile(uri:String)= getFile(uri).delete()
fun deleteAllCacheObservable() =
Observable.create<Pair<Int, Int>> {emitter ->
val foldersToDelete = listOf(
FileDirectory.Albums().dir,
FileDirectory.FeedsDir().dir,
FileDirectory.PlanTypeDir().dir,
FileDirectory.ToursDir().dir
)
foldersToDelete.forEachIndexed{ index,dir ->
if (File(dir).deleteRecursively())
emitter.onNext(Pair(index,foldersToDelete.size))
else emitter.onError(error("Error occurred on files deleting!"))
}
emitter.onComplete()
}
val getCoreCacheDirectory:String val getCoreCacheDirectory:String
get(){ get(){
return rootFolder.absolutePath return rootFolder.absolutePath
} }
......
package com.biganto.visual.roompark.domain.contract package com.biganto.visual.roompark.domain.contract
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 24.09.2019. * Created by Vladislav Bogdashkin on 24.09.2019.
*/ */
...@@ -11,4 +13,5 @@ interface FilesContract{ ...@@ -11,4 +13,5 @@ interface FilesContract{
fun getFeedSize(): Long fun getFeedSize(): Long
fun getToursSize(): Long fun getToursSize(): Long
fun getPlansSize(): Long fun getPlansSize(): Long
fun deleteAllFiles(): Observable<Pair<Int, Int>>
} }
\ No newline at end of file
...@@ -47,6 +47,8 @@ class SettingsInteractor @Inject constructor( ...@@ -47,6 +47,8 @@ class SettingsInteractor @Inject constructor(
CachedDataModel(activity.resources.getString(R.string.overall_cache),it,0) CachedDataModel(activity.resources.getString(R.string.overall_cache),it,0)
} }
fun deleteCacheFiles() = settingsUseCase.clearAllCache()
fun getCacheInfo() = fun getCacheInfo() =
Observable.concatArray(plans, tours, feeds, albums, overall).toList().toObservable() Observable.concatArray(plans, tours, feeds, albums, overall).toList().toObservable()
......
...@@ -16,6 +16,8 @@ class SettingsUseCase @Inject constructor( ...@@ -16,6 +16,8 @@ class SettingsUseCase @Inject constructor(
){ ){
fun signOut() = authContract.signOut() fun signOut() = authContract.signOut()
fun clearAllCache() = fileContract.deleteAllFiles()
val planTypesSize val planTypesSize
get() = Observable.just(fileContract.getPlansSize()) get() = Observable.just(fileContract.getPlansSize())
......
...@@ -9,5 +9,6 @@ import io.reactivex.Observable ...@@ -9,5 +9,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>
} }
...@@ -23,6 +23,7 @@ import com.jakewharton.rxbinding3.view.clicks ...@@ -23,6 +23,7 @@ import com.jakewharton.rxbinding3.view.clicks
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
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -40,6 +41,13 @@ class SettingsScreenController : ...@@ -40,6 +41,13 @@ class SettingsScreenController :
.map { Timber.d("Clicked sign out button"); 1 } .map { Timber.d("Clicked sign out button"); 1 }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
override fun clearCache(): Observable<Int> =
clearCacheButton.clicks()
.debounce ( 500, TimeUnit.MICROSECONDS )
.map { Timber.d("Clicked clear cache button"); 1 }
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
} }
...@@ -72,6 +80,10 @@ class SettingsScreenController : ...@@ -72,6 +80,10 @@ class SettingsScreenController :
@BindView(R.id.signOutButton) @BindView(R.id.signOutButton)
lateinit var signOutButton:MaterialTextView lateinit var signOutButton:MaterialTextView
@BindView(R.id.clear_cache_button)
lateinit var clearCacheButton:MaterialTextView
private fun setToolbar(){ private fun setToolbar(){
toolBar.appBar.liftOnScrollTargetViewId = R.id.nestedScrollContainer toolBar.appBar.liftOnScrollTargetViewId = R.id.nestedScrollContainer
pushRecycler.isNestedScrollingEnabled = false pushRecycler.isNestedScrollingEnabled = false
......
...@@ -42,10 +42,23 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -42,10 +42,23 @@ class SettingsScreenPresenter @Inject constructor(
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
} }
val onClearCache = intent(SettingsScreen::clearCache)
.flatMap {
interactor.deleteCacheFiles()
.map<SettingsScreenViewState>{
SettingsScreenViewState.OnCacheDeleting(
it.first/it.second.toFloat()
)
}
.startWith(SettingsScreenViewState.OnCacheDeleting(0f))
.onErrorReturn(::parseError)
}
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchSettings) .mergeWith(fetchSettings)
.mergeWith(onSignOut) .mergeWith(onSignOut)
.mergeWith(onClearCache)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
......
...@@ -15,4 +15,5 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() { ...@@ -15,4 +15,5 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
// class LoadCachedInfo(val cached:SettingsModel) : SettingsScreenViewState() // class LoadCachedInfo(val cached:SettingsModel) : SettingsScreenViewState()
class SomeError(val exception: ExceptionString) : SettingsScreenViewState() class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState() class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
} }
\ No newline at end of file
...@@ -123,7 +123,8 @@ ...@@ -123,7 +123,8 @@
tools:listitem="@layout/text_description_viewholder" /> tools:listitem="@layout/text_description_viewholder" />
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
style="@style/Default_TextView.Cancel_Text" android:id="@+id/clear_cache_button"
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="wrap_content"
android:layout_margin="32dp" /> android:layout_margin="32dp" />
...@@ -142,10 +143,9 @@ ...@@ -142,10 +143,9 @@
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/signOutButton" android:id="@+id/signOutButton"
style="@style/Default_TextView.Cancel_Text" style="@style/Default_TextView.Sign_Out_Text"
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" />
android:text="СМЕНИТЬ АККАУНТ" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
\ No newline at end of file
...@@ -317,6 +317,19 @@ ...@@ -317,6 +317,19 @@
<item name="android:textColor">@color/colorError</item> <item name="android:textColor">@color/colorError</item>
</style> </style>
<style name="Default_TextView.Clear_Cache_Text">
<item name="android:text">"ОЧИСТИТЬ КЭШ"</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/colorError</item>
</style>
<style name="Default_TextView.Sign_Out_Text">
<item name="android:text">"СМЕНИТЬ АККАУНТ"</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/colorError</item>
</style>
<style name="Default_TextView.Notice_Text"> <style name="Default_TextView.Notice_Text">
<item name="android:textColor">@color/colorNoticeText</item> <item name="android:textColor">@color/colorNoticeText</item>
</style> </style>
......
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