Commit 76e62401 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

Merge branch 'feature/clear_cache' into develop

parents 8f4943c3 ab7bae22
......@@ -125,6 +125,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.2'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.0'
......
......@@ -30,6 +30,8 @@ class FilesContractModule @Inject constructor(
return FileModule.getDirectory(context,d)
}
override fun deleteAllFiles() = files.deleteAllCacheObservable()
override fun getPlansSize() = getFile<FileModule.FileDirectory.PlanTypeDir>().folderSize
override fun getToursSize() = getFile<FileModule.FileDirectory.ToursDir>().folderSize
......
......@@ -6,6 +6,8 @@ import android.os.Environment
import com.biganto.visual.roompark.util.extensions.asInt
import com.google.gson.JsonElement
import dagger.Module
import io.reactivex.Observable
import kotlinx.io.IOException
import timber.log.Timber
import java.io.File
import javax.inject.Inject
......@@ -61,7 +63,24 @@ class FileModule @Inject constructor(val context: Application) {
fun deleteFile(uri:String)= getFile(uri).delete()
fun deleteAllCacheObservable() =
Observable.create<Pair<Int, Int>> {emitter ->
val foldersToDelete = listOf(
FileDirectory.Albums(),
FileDirectory.FeedsDir(),
FileDirectory.PlanTypeDir(),
FileDirectory.ToursDir()
)
foldersToDelete.forEachIndexed { index, dir ->
if (getDirectory(context,dir).deleteRecursively())
emitter.onNext(Pair(index, foldersToDelete.size-1))
else emitter.onError(IOException("Error occurred on files deleting!"))
}
emitter.onComplete()
}
val getCoreCacheDirectory:String
get(){
return rootFolder.absolutePath
}
......
package com.biganto.visual.roompark.di.dagger
import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
import com.bumptech.glide.module.AppGlideModule
/**
* Created by Vladislav Bogdashkin on 19.03.2020.
*/
@GlideModule
class RoomParkGlideModule : AppGlideModule() {
// fun applyOptions(@NonNull context: Context?, @NonNull builder: GlideBuilder) {
// super.applyOptions(context, builder)
// builder.setDefaultRequestOptions(RequestOptions().format(DecodeFormat.PREFER_ARGB_8888))
// }
override fun applyOptions(context: Context, builder: GlideBuilder) {
val filderName = "../files/photos"
builder.setDiskCache(
InternalCacheDiskCacheFactory(
context,filderName,1024L*1024L*256L)
)
}
//
// fun registerComponents(
// @NonNull context: Context?, @NonNull glide: Glide?, @NonNull registry: Registry
// ) {
// registry.append(Photo::class.java, InputStream::class.java, Factory())
// }
// Disable manifest parsing to avoid adding similar modules twice.
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
\ No newline at end of file
package com.biganto.visual.roompark.domain.contract
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
......@@ -11,4 +13,5 @@ interface FilesContract{
fun getFeedSize(): Long
fun getToursSize(): Long
fun getPlansSize(): Long
fun deleteAllFiles(): Observable<Pair<Int, Int>>
}
\ No newline at end of file
......@@ -47,6 +47,8 @@ class SettingsInteractor @Inject constructor(
CachedDataModel(activity.resources.getString(R.string.overall_cache),it,0)
}
fun deleteCacheFiles() = settingsUseCase.clearAllCache()
fun getCacheInfo() =
Observable.concatArray(plans, tours, feeds, albums, overall).toList().toObservable()
......
......@@ -16,6 +16,8 @@ class SettingsUseCase @Inject constructor(
){
fun signOut() = authContract.signOut()
fun clearAllCache() = fileContract.deleteAllFiles()
val planTypesSize
get() = Observable.just(fileContract.getPlansSize())
......
......@@ -9,6 +9,7 @@ import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
/**
......@@ -40,6 +41,7 @@ class AlbumsHeaderViewHolder(itemView: View) : CommonViewHolder<AlbumPreviewMode
.load(model.previewUrl)
.centerCrop()
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(preview)
}
}
......@@ -13,6 +13,7 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyc
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.detaches
import com.jakewharton.rxrelay2.BehaviorRelay
......@@ -90,6 +91,7 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView)
.load(it.url)
.centerCrop()
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(photoPreview)
}}
}
......
......@@ -17,6 +17,7 @@ import com.biganto.visual.roompark.presentation.screen.article.util.HtmlPageAdap
import com.biganto.visual.roompark.presentation.screen.article.util.HtmlTag
import com.biganto.visual.roompark.util.extensions.formatToSimple
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView
import jp.wasabeef.glide.transformations.BlurTransformation
import timber.log.Timber
......@@ -123,10 +124,12 @@ class ArticleScreenController :
Glide.with(blurPreview)
.load(viewState.item.previewUrl)
.transform(BlurTransformation(40,4))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(blurPreview)
Glide.with(articlePreview)
.load(viewState.item.previewUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(articlePreview)
}
......
......@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView
/**
......@@ -94,6 +95,7 @@ class HtmlImageViewHolder(itemView: View) :HtmlTagViewHolder<HtmlTag.ImageSource
Glide.with(itemView)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(itemView as ImageView)
}
}
......
......@@ -23,6 +23,7 @@ import com.biganto.visual.roompark.util.view_utils.status_progress_view.StatusPr
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxbinding3.view.scrollChangeEvents
......@@ -212,6 +213,7 @@ class DealScreenController :
viewState.estate.estate.multitourPreview?.let {
Glide.with(tourScreen)
.load(it)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(tourScreen)
}
......
......@@ -19,6 +19,7 @@ import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
import com.biganto.visual.roompark.util.view_utils.status_progress_view.StatusProgressAnimationState
import com.biganto.visual.roompark.util.view_utils.status_progress_view.StatusProgressCeil
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import io.reactivex.Observable
......@@ -98,12 +99,10 @@ class DealViewHolder(itemView: View) : CommonViewHolder<DealPreviewModel>(itemVi
statusLayout.addView(currentStatusText,0)
statusLayout.invalidate()
model.tourPreview?.let {
Glide.with(tourScreen)
.load(it)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(tourScreen)
}
}
......
......@@ -10,6 +10,7 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyc
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.biganto.visual.roompark.util.extensions.setGone
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.*
......@@ -46,6 +47,7 @@ class ArticleViewHolder(itemView: View) : CommonViewHolder<ArticlePreviewModel>(
Glide.with(preview)
.load(model.previewUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(preview)
}
......
......@@ -9,5 +9,7 @@ import io.reactivex.Observable
interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> {
fun signOut(): Observable<Int>
fun clearCache(): Observable<Int>
fun refreshCacheInfo(): Observable<Int>
}
......@@ -16,13 +16,16 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListA
import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController
import com.biganto.visual.roompark.util.extensions.bytesToSize
import com.biganto.visual.roompark.util.extensions.setGone
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxrelay2.BehaviorRelay
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
......@@ -40,6 +43,15 @@ class SettingsScreenController :
.map { Timber.d("Clicked sign out button"); 1 }
.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())
private val refreshEmitter = BehaviorRelay.create<Int>()
override fun refreshCacheInfo(): Observable<Int> = refreshEmitter
override fun injectDependencies() {
getComponent()
}
......@@ -72,6 +84,12 @@ class SettingsScreenController :
@BindView(R.id.signOutButton)
lateinit var signOutButton:MaterialTextView
@BindView(R.id.clear_cache_button)
lateinit var clearCacheButton:MaterialTextView
@BindView(R.id.progress_lock_background)
lateinit var progressShame:View
private fun setToolbar(){
toolBar.appBar.liftOnScrollTargetViewId = R.id.nestedScrollContainer
pushRecycler.isNestedScrollingEnabled = false
......@@ -112,6 +130,7 @@ class SettingsScreenController :
is SettingsScreenViewState.LoadSettingsList -> render(viewState)
is SettingsScreenViewState.SomeError -> render(viewState)
is SettingsScreenViewState.SignOut -> render(viewState)
is SettingsScreenViewState.OnCacheDeleting -> render(viewState)
}
}
......@@ -119,7 +138,16 @@ class SettingsScreenController :
showError(viewState.exception)
private fun render(viewState: SettingsScreenViewState.Idle){
progressShame.setGone(true)
clearCacheButton.setGone(false)
}
private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){
val isProgressed = viewState.progress>=1f
progressShame.setGone(isProgressed)
clearCacheButton.setGone(!isProgressed)
refreshEmitter.accept(1)
}
private fun render(viewState: SettingsScreenViewState.SignOut){
......
......@@ -43,9 +43,28 @@ class SettingsScreenPresenter @Inject constructor(
}
val refreshInfo = intent(SettingsScreen::refreshCacheInfo)
.flatMap {fetchSettings}
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
.mergeWith(fetchSettings)
.mergeWith(onSignOut)
.mergeWith(onClearCache)
.mergeWith(refreshInfo)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.onErrorReturn(::parseError)
......
......@@ -15,4 +15,5 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
// class LoadCachedInfo(val cached:SettingsModel) : SettingsScreenViewState()
class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
}
\ No newline at end of file
......@@ -123,10 +123,33 @@
tools:listitem="@layout/text_description_viewholder" />
<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_height="48dp"
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:layout_margin="32dp" />
android:indeterminate="true"
android:layout_gravity="center"/>
</FrameLayout>
<com.google.android.material.textview.MaterialTextView
......@@ -142,10 +165,10 @@
<com.google.android.material.textview.MaterialTextView
android:id="@+id/signOutButton"
style="@style/Default_TextView.Cancel_Text"
style="@style/Default_TextView.Sign_Out_Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:text="СМЕНИТЬ АККАУНТ" />
android:layout_margin="32dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
......@@ -317,6 +317,19 @@
<item name="android:textColor">@color/colorError</item>
</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">
<item name="android:textColor">@color/colorNoticeText</item>
</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