diff --git a/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt b/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt index 8c6f372b..8fddb2fc 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt @@ -22,7 +22,6 @@ import android.annotation.SuppressLint import android.app.ActivityOptions import android.content.Intent import android.graphics.Typeface -import android.graphics.drawable.Drawable import android.os.Build import android.os.Bundle import android.text.Spannable @@ -46,7 +45,6 @@ import com.njlabs.showjava.decompilers.BaseDecompiler.Companion.isAvailable import com.njlabs.showjava.utils.ktx.sourceDir import com.njlabs.showjava.utils.ktx.toBundle import io.reactivex.Observable -import io.reactivex.ObservableEmitter import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_decompiler.* @@ -121,8 +119,8 @@ class DecompilerActivity : BaseActivity() { } disposables.add( - Observable.create { emitter: ObservableEmitter -> - emitter.onNext(packageInfo.loadIcon(context)) + Observable.fromCallable { + packageInfo.loadIcon(context) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -196,9 +194,11 @@ class DecompilerActivity : BaseActivity() { BaseDecompiler.start(inputMap) - firebaseAnalytics.logEvent(Constants.EVENTS.SELECT_DECOMPILER, hashMapOf( - FirebaseAnalytics.Param.VALUE to decompiler - ).toBundle()) + firebaseAnalytics.logEvent( + Constants.EVENTS.SELECT_DECOMPILER, hashMapOf( + FirebaseAnalytics.Param.VALUE to decompiler + ).toBundle() + ) firebaseAnalytics.logEvent(Constants.EVENTS.DECOMPILE_APP, inputMap.toBundle()) diff --git a/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorActivity.kt b/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorActivity.kt index 98d46abc..4fa2489e 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorActivity.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/navigator/NavigatorActivity.kt @@ -104,7 +104,11 @@ class NavigatorActivity : BaseActivity() { disposables.add(navigationHandler.loadFiles(startDirectory) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnError { Timber.e(it) } + .onErrorReturn { + Timber.e(it) + Toast.makeText(context, R.string.errorLoadingFiles, Toast.LENGTH_SHORT).show() + ArrayList() + } .subscribe { updateList(it) swipeRefresh.isRefreshing = false @@ -226,7 +230,12 @@ class NavigatorActivity : BaseActivity() { return currentDirectory?.canonicalPath == selectedApp?.sourceDirectory?.canonicalPath } - private fun shareArchive(file: File) { + private fun shareArchive(file: File?) { + if (file == null) { + Toast.makeText(context, R.string.genericError, Toast.LENGTH_SHORT).show() + return + } + dismissProgressDialog() val shareIntent = Intent() shareIntent.action = Intent.ACTION_SEND @@ -277,7 +286,10 @@ class NavigatorActivity : BaseActivity() { ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnError { Timber.e(it) } + .onErrorReturn { + Timber.e(it) + null + } .subscribe { sourceArchive = it shareArchive(it) diff --git a/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/viewer/CodeViewerActivity.kt b/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/viewer/CodeViewerActivity.kt index f4bde549..c9855f9c 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/viewer/CodeViewerActivity.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/activities/explorer/viewer/CodeViewerActivity.kt @@ -28,14 +28,11 @@ import android.view.MenuItem import android.view.View import com.njlabs.showjava.R import com.njlabs.showjava.activities.BaseActivity -import com.njlabs.showjava.utils.rx.ProcessStatus import com.njlabs.showjava.utils.views.CodeView import io.reactivex.Observable -import io.reactivex.ObservableEmitter import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_code_viewer.* -import timber.log.Timber import java.io.File class CodeViewerActivity : BaseActivity(), CodeView.OnHighlightListener { @@ -105,9 +102,11 @@ class CodeViewerActivity : BaseActivity(), CodeView.OnHighlightListener { loadFile(file) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnError { error -> Timber.e(error) } - .subscribe { status -> - codeView.setCode(status.result) + .onErrorReturn { + it.localizedMessage + } + .subscribe { fileContent -> + codeView.setCode(fileContent) .setLanguage(language) .setWrapLine(wrapLine) .setDarkMode(invertColors) @@ -120,10 +119,9 @@ class CodeViewerActivity : BaseActivity(), CodeView.OnHighlightListener { ) } - private fun loadFile(fileToLoad: File): Observable> { - return Observable.create { emitter: ObservableEmitter> -> - emitter.onNext(ProcessStatus(fileToLoad.readText())) - emitter.onComplete() + private fun loadFile(fileToLoad: File): Observable { + return Observable.fromCallable { + fileToLoad.readText() } } diff --git a/app/src/main/kotlin/com/njlabs/showjava/activities/landing/LandingActivity.kt b/app/src/main/kotlin/com/njlabs/showjava/activities/landing/LandingActivity.kt index 4f200a3b..4ca357e1 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/activities/landing/LandingActivity.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/activities/landing/LandingActivity.kt @@ -172,7 +172,10 @@ class LandingActivity : BaseActivity() { disposables.add(landingHandler.loadHistory() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnError { Timber.e(it) } + .onErrorReturn { + Timber.e(it) + ArrayList() + } .subscribe { historyItems = it swipeRefresh.isRefreshing = false diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e0fb61bf..facd7f52 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -174,4 +174,6 @@ (ID: %1$s) Only positive integers are allowed Error loading input file + An unexpected error occurred + An error occurred while loading files