diff --git a/app/build.gradle b/app/build.gradle index af2eae6..3f464a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,8 +36,8 @@ android { applicationId "com.wbrawner.simplemarkdown" minSdkVersion 19 targetSdkVersion 27 - versionCode 4 - versionName "0.3.0" + versionCode 5 + versionName "0.3.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java b/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java index 1a7106d..39952fd 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java @@ -1,6 +1,6 @@ package com.wbrawner.simplemarkdown.model; -import com.wbrawner.simplemarkdown.Utils; +import com.wbrawner.simplemarkdown.utility.Utils; import java.io.BufferedReader; import java.io.File; @@ -11,7 +11,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.util.Scanner; /** * This class serves as a wrapper to manage the manage the file input and output operations, as well diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java index 181ec28..89dea67 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java @@ -7,8 +7,8 @@ import android.os.Handler; import android.provider.OpenableColumns; import com.commonsware.cwac.anddown.AndDown; -import com.wbrawner.simplemarkdown.Utils; import com.wbrawner.simplemarkdown.model.MarkdownFile; +import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.MarkdownEditView; import com.wbrawner.simplemarkdown.view.MarkdownPreviewView; diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/utility/MarkdownObserver.java b/app/src/main/java/com/wbrawner/simplemarkdown/utility/MarkdownObserver.java new file mode 100644 index 0000000..3524b6a --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/utility/MarkdownObserver.java @@ -0,0 +1,45 @@ +package com.wbrawner.simplemarkdown.utility; + +import com.crashlytics.android.Crashlytics; +import com.wbrawner.simplemarkdown.BuildConfig; +import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter; + +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; + +public class MarkdownObserver implements Observer { + private MarkdownPresenter presenter; + private Observable obs; + + public MarkdownObserver(MarkdownPresenter presenter, Observable obs) { + this.presenter = presenter; + this.obs = obs; + } + + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(String markdown) { + presenter.onMarkdownEdited(markdown); + } + + @Override + public void onError(Throwable e) { + System.err.println("An error occurred while handling the markdown"); + e.printStackTrace(); + // TODO: Remove this once the error is confirmed to have disappeared + if (!BuildConfig.DEBUG) { + Crashlytics.logException(e); + } + obs.subscribe(this); + } + + @Override + public void onComplete() { + + } +} diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/Utils.java b/app/src/main/java/com/wbrawner/simplemarkdown/utility/Utils.java similarity index 97% rename from app/src/main/java/com/wbrawner/simplemarkdown/Utils.java rename to app/src/main/java/com/wbrawner/simplemarkdown/utility/Utils.java index c464501..eb6b4de 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/Utils.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/utility/Utils.java @@ -1,4 +1,4 @@ -package com.wbrawner.simplemarkdown; +package com.wbrawner.simplemarkdown.utility; import android.content.Context; import android.content.SharedPreferences; @@ -9,7 +9,6 @@ import com.wbrawner.simplemarkdown.view.activity.SettingsActivity; import java.io.Closeable; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.util.Locale; import java.util.regex.Matcher; diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java index c759c5b..950a09b 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java @@ -16,7 +16,7 @@ import android.widget.ListView; import android.widget.SimpleAdapter; import com.wbrawner.simplemarkdown.R; -import com.wbrawner.simplemarkdown.Utils; +import com.wbrawner.simplemarkdown.utility.Utils; import java.io.File; import java.util.ArrayList; @@ -25,8 +25,6 @@ import java.util.List; import java.util.Locale; import java.util.TreeSet; -import io.reactivex.annotations.BackpressureSupport; - public class ExplorerActivity extends AppCompatActivity { private Handler fileHandler = new Handler(); private ListView listView; diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java index 16c97e3..67cbb0a 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java @@ -6,12 +6,12 @@ import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.Configuration; import android.os.Build; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.TabLayout; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -19,8 +19,8 @@ import android.widget.Toast; import com.wbrawner.simplemarkdown.MarkdownApplication; import com.wbrawner.simplemarkdown.R; -import com.wbrawner.simplemarkdown.Utils; import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter; +import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.DisableableViewPager; import com.wbrawner.simplemarkdown.view.adapter.EditPagerAdapter; diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SplashActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SplashActivity.java index 28fe09a..285d623 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SplashActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/SplashActivity.java @@ -6,8 +6,8 @@ import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.wbrawner.simplemarkdown.MarkdownApplication; -import com.wbrawner.simplemarkdown.Utils; import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter; +import com.wbrawner.simplemarkdown.utility.Utils; import javax.inject.Inject; diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java index c2b22f6..7027cdc 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java @@ -14,8 +14,9 @@ import android.widget.Toast; import com.jakewharton.rxbinding2.widget.RxTextView; import com.wbrawner.simplemarkdown.MarkdownApplication; import com.wbrawner.simplemarkdown.R; -import com.wbrawner.simplemarkdown.Utils; import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter; +import com.wbrawner.simplemarkdown.utility.MarkdownObserver; +import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.MarkdownEditView; import java.util.concurrent.TimeUnit; @@ -51,10 +52,11 @@ public class EditFragment extends Fragment implements MarkdownEditView { ((MarkdownApplication) activity.getApplication()).getComponent().inject(this); } Observable obs = RxTextView.textChanges(markdownEditor) - .debounce(50, TimeUnit.MILLISECONDS).map(CharSequence::toString); - obs.subscribeOn(Schedulers.io()); - obs.observeOn(AndroidSchedulers.mainThread()); - obs.subscribe(markdown -> presenter.onMarkdownEdited(markdown)); + .debounce(50, TimeUnit.MILLISECONDS) + .map(CharSequence::toString) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + obs.subscribe(new MarkdownObserver(presenter, obs)); return view; } diff --git a/app/src/test/java/com/wbrawner/simplemarkdown/UtilsTest.java b/app/src/test/java/com/wbrawner/simplemarkdown/UtilsTest.java index 60b2305..f7258f7 100644 --- a/app/src/test/java/com/wbrawner/simplemarkdown/UtilsTest.java +++ b/app/src/test/java/com/wbrawner/simplemarkdown/UtilsTest.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.activity.SettingsActivity; import org.junit.After; @@ -16,7 +17,9 @@ import org.robolectric.RuntimeEnvironment; import java.io.File; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith(RobolectricTestRunner.class) @SuppressWarnings("ResultOfMethodCallIgnored")