Skip to content

Commit

Permalink
run move folders in seperate thread
Browse files Browse the repository at this point in the history
  • Loading branch information
arranlomas committed Nov 12, 2017
1 parent 11522ae commit ed42fd7
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChangeWorkingDirectoryResult> {
return Observable.create<ChangeWorkingDirectoryResult>({
fun handleChangeDirectory(event: SettingsIntents.UpdateWorkingDirectory, saveWorkingDirectory: (Context, File) -> Unit): PublishSubject<ChangeWorkingDirectoryResult> {
val subject: PublishSubject<ChangeWorkingDirectoryResult> = 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 {
Expand Down

0 comments on commit ed42fd7

Please sign in to comment.