Browse Source

TopicAdapter crash fix

pull/70/head
Ezerous 4 years ago
parent
commit
5de855fe0e
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  2. 76
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

1
app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java

@ -21,7 +21,6 @@ import org.jsoup.select.Elements;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Objects;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;

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

@ -696,43 +696,13 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
holder.replyEditor.setText(replyText);
holder.replyEditor.getEditText().setSelection(holder.replyEditor.getText().length());
holder.replyEditor.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) {
((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
holder.replyEditor.getEditText().addTextChangedListener(createTextWatcher(holder));
if (backPressHidden) {
holder.replyEditor.requestEditTextFocus();
backPressHidden = false;
}
holder.quickReplySubject.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) {
((Post) topicItems.get(holder.getAdapterPosition())).setSubject(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
holder.quickReplySubject.addTextChangedListener(createTextWatcher(holder));
} else if (currentHolder instanceof EditMessageViewHolder) {
final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder;
@ -767,44 +737,32 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
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) {
holder.editSubject.addTextChangedListener(createTextWatcher(holder));
holder.editEditor.getEditText().addTextChangedListener(createTextWatcher(holder));
if (backPressHidden) {
holder.editEditor.requestEditTextFocus();
backPressHidden = false;
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
((Post) topicItems.get(holder.getAdapterPosition())).setSubject(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
holder.editEditor.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
private TextWatcher createTextWatcher(@NonNull final RecyclerView.ViewHolder holder){
return 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) {
((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(charSequence.toString());
int position = holder.getAdapterPosition();
if (position >= 0 && position < topicItems.size())
((Post) topicItems.get(position)).setBbContent(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
if (backPressHidden) {
holder.editEditor.requestEditTextFocus();
backPressHidden = false;
}
}
}
public void afterTextChanged(Editable editable) { }
};
}
private void loadAvatar(String imageUrl, ImageView imageView, Context context) {

Loading…
Cancel
Save