Browse Source

fix not deleting draft when stopping activity after clicking send;

fix edits not being saved when editing a post and scrolling up and down
pull/61/merge
oogee 6 years ago
parent
commit
be7e0c8382
  1. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 32
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

13
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -531,6 +531,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
replyFAB.setTag(true); replyFAB.setTag(true);
bottomNavBar.setVisibility(View.VISIBLE); bottomNavBar.setVisibility(View.VISIBLE);
viewModel.setWritingReply(false); viewModel.setWritingReply(false);
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key),
Context.MODE_PRIVATE);
drafts.edit().remove(String.valueOf(viewModel.getTopicId())).apply();
if ((((Post) topicItems.get(topicItems.size() - 1)).getPostNumber() + 1) % 15 == 0) { if ((((Post) topicItems.get(topicItems.size() - 1)).getPostNumber() + 1) % 15 == 0) {
Timber.i("Reply was posted in new page. Switching to last page."); Timber.i("Reply was posted in new page. Switching to last page.");
viewModel.loadUrl(ParseHelpers.getBaseURL(viewModel.getTopicUrl()) + "." + 2147483647); viewModel.loadUrl(ParseHelpers.getBaseURL(viewModel.getTopicUrl()) + "." + 2147483647);
@ -541,6 +546,14 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
case NEW_REPLY_WHILE_POSTING: case NEW_REPLY_WHILE_POSTING:
Timber.i("New reply while writing a reply"); Timber.i("New reply while writing a reply");
//cache reply
if (viewModel.isWritingReply()) {
SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply();
viewModel.setWritingReply(false);
}
Runnable addReply = () -> { Runnable addReply = () -> {
AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this,
R.style.AppTheme_Dark_Dialog); R.style.AppTheme_Dark_Dialog);

32
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -721,6 +721,38 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editEditor.getText().toString()); viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editEditor.getText().toString());
}); });
holder.editSubject.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString());
}
});
holder.editEditor.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString());
}
});
if (backPressHidden) { if (backPressHidden) {
holder.editEditor.requestEditTextFocus(); holder.editEditor.requestEditTextFocus();
backPressHidden = false; backPressHidden = false;

Loading…
Cancel
Save