From ed42fd70c02ca7ca03d3ca9f2e7ffbde69185b9d Mon Sep 17 00:00:00 2001 From: arran Date: Sun, 12 Nov 2017 20:52:35 +1000 Subject: [PATCH] run move folders in seperate thread --- .../views/settings/mvi/InteractorSideEffects.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/shwifty/tex/views/settings/mvi/InteractorSideEffects.kt b/app/src/main/java/com/shwifty/tex/views/settings/mvi/InteractorSideEffects.kt index 442b335..441dd0f 100644 --- a/app/src/main/java/com/shwifty/tex/views/settings/mvi/InteractorSideEffects.kt +++ b/app/src/main/java/com/shwifty/tex/views/settings/mvi/InteractorSideEffects.kt @@ -4,27 +4,28 @@ import android.content.Context import android.support.annotation.StringRes import com.shwifty.tex.utils.ValidateChangeWorkingDirectoryResult import com.shwifty.tex.utils.validateWorkingDirectoryCanBeChanged -import rx.Emitter -import rx.Observable +import rx.subjects.PublishSubject import java.io.File /** * Created by arran on 11/11/2017. */ -fun handleChangeDirectory(event: SettingsIntents.UpdateWorkingDirectory, saveWorkingDirectory: (Context, File) -> Unit): Observable { - return Observable.create({ +fun handleChangeDirectory(event: SettingsIntents.UpdateWorkingDirectory, saveWorkingDirectory: (Context, File) -> Unit): PublishSubject { + val subject: PublishSubject = PublishSubject.create() + Thread { val isValid = event.newDirectory.validateWorkingDirectoryCanBeChanged(event.previousDirectory) if (isValid is ValidateChangeWorkingDirectoryResult.Error) { - it.onNext(ChangeWorkingDirectoryResult.CannotChange(isValid.messageRes)) + subject.onNext(ChangeWorkingDirectoryResult.CannotChange(isValid.messageRes)) } else { saveWorkingDirectory.invoke(event.context, event.newDirectory) if (event.moveFiles) { event.previousDirectory.copyRecursively(event.newDirectory, overwrite = true) event.previousDirectory.deleteRecursively() } - it.onNext(ChangeWorkingDirectoryResult.Changed()) + subject.onNext(ChangeWorkingDirectoryResult.Changed()) } - }, Emitter.BackpressureMode.BUFFER) + }.start() + return subject } sealed class ChangeWorkingDirectoryResult {