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. 84
      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.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;

84
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.setText(replyText);
holder.replyEditor.getEditText().setSelection(holder.replyEditor.getText().length()); holder.replyEditor.getEditText().setSelection(holder.replyEditor.getText().length());
holder.replyEditor.getEditText().addTextChangedListener(new TextWatcher() { holder.replyEditor.getEditText().addTextChangedListener(createTextWatcher(holder));
@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) {
}
});
if (backPressHidden) { if (backPressHidden) {
holder.replyEditor.requestEditTextFocus(); holder.replyEditor.requestEditTextFocus();
backPressHidden = false; backPressHidden = false;
} }
holder.quickReplySubject.addTextChangedListener(new TextWatcher() { holder.quickReplySubject.addTextChangedListener(createTextWatcher(holder));
@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) {
}
});
} else if (currentHolder instanceof EditMessageViewHolder) { } else if (currentHolder instanceof EditMessageViewHolder) {
final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder; final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder;
@ -767,38 +737,9 @@ 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() { holder.editSubject.addTextChangedListener(createTextWatcher(holder));
@Override holder.editEditor.getEditText().addTextChangedListener(createTextWatcher(holder));
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.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) {
((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
if (backPressHidden) { if (backPressHidden) {
holder.editEditor.requestEditTextFocus(); holder.editEditor.requestEditTextFocus();
backPressHidden = false; backPressHidden = false;
@ -807,6 +748,23 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} }
} }
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) {
int position = holder.getAdapterPosition();
if (position >= 0 && position < topicItems.size())
((Post) topicItems.get(position)).setBbContent(charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) { }
};
}
private void loadAvatar(String imageUrl, ImageView imageView, Context context) { private void loadAvatar(String imageUrl, ImageView imageView, Context context) {
if(imageUrl!=null) if(imageUrl!=null)
imageUrl = imageUrl.trim(); imageUrl = imageUrl.trim();

Loading…
Cancel
Save