Fix bug on markdown processing

This commit is contained in:
William Brawner 2018-01-28 15:42:21 -06:00 committed by William Brawner
parent 093a989d01
commit a09260de11
10 changed files with 65 additions and 19 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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;

View file

@ -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<String> {
private MarkdownPresenter presenter;
private Observable<String> obs;
public MarkdownObserver(MarkdownPresenter presenter, Observable<String> 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() {
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<String> 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;
}

View file

@ -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")