Refactored EditFragment to send context to PreviewFragment instead of raw data

This commit is contained in:
William Brawner 2017-07-29 12:28:35 -05:00
parent 66f61ddc65
commit e16a1a12c7

View file

@ -62,8 +62,7 @@ public class EditFragment extends Fragment {
filter filter
); );
mContext = getActivity(); mContext = getActivity();
mFileUtils = new FileUtils(mContext); mFileUtils = new FileUtils(mContext); }
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -79,12 +78,11 @@ public class EditFragment extends Fragment {
mMarkdownEditor.addTextChangedListener(new TextWatcher() { mMarkdownEditor.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
} }
@Override @Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
updatePreview(mMarkdownEditor.getText()); updatePreview(mContext);
} }
@Override @Override
@ -104,13 +102,12 @@ public class EditFragment extends Fragment {
loadTask.execute(FileProvider.getUriForFile(mContext, MainActivity.AUTHORITY, tmpFile)); loadTask.execute(FileProvider.getUriForFile(mContext, MainActivity.AUTHORITY, tmpFile));
} }
} }
updatePreview(mMarkdownEditor.getText());
} }
private void updatePreview(Editable data) { public static void updatePreview(Context context) {
Intent broadcastIntent = new Intent(PreviewFragment.PREVIEW_ACTION); Intent broadcastIntent = new Intent(PreviewFragment.PREVIEW_ACTION);
broadcastIntent.putExtra("markdownData", data.toString()); broadcastIntent.putExtra("markdownData", mMarkdownEditor.getText().toString());
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
manager.sendBroadcast(broadcastIntent); manager.sendBroadcast(broadcastIntent);
} }