fix crash in SearchFragment (#1266)

This commit is contained in:
Konrad Pozniak 2019-05-18 16:52:48 +02:00 committed by GitHub
parent 3f957a09c5
commit c8bf07ea77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View file

@ -101,7 +101,7 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
if (position >= accountList.size()) { if (position >= accountList.size()) {
if(position >= accountList.size() + concreteStatusList.size()) { if(position >= accountList.size() + concreteStatusList.size()) {
HashtagViewHolder holder = (HashtagViewHolder) viewHolder; HashtagViewHolder holder = (HashtagViewHolder) viewHolder;
int index = position - accountList.size() - statusList.size(); int index = position - accountList.size() - concreteStatusList.size();
holder.setup(hashtagList.get(index), linkListener); holder.setup(hashtagList.get(index), linkListener);
} else { } else {
StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusViewHolder holder = (StatusViewHolder) viewHolder;
@ -141,9 +141,11 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
return concreteStatusList.get(position - accountList.size()); return concreteStatusList.get(position - accountList.size());
} }
public void updateStatusAtPosition(StatusViewData.Concrete status, int position) { public void updateStatusAtPosition(StatusViewData.Concrete status, int position, boolean doNotify) {
concreteStatusList.set(position - accountList.size(), status); concreteStatusList.set(position - accountList.size(), status);
notifyItemChanged(position); if(doNotify) {
notifyItemChanged(position);
}
} }
public void removeStatusAtPosition(int position) { public void removeStatusAtPosition(int position) {
@ -155,6 +157,7 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
if (results != null) { if (results != null) {
accountList = results.getAccounts(); accountList = results.getAccounts();
statusList = results.getStatuses(); statusList = results.getStatuses();
concreteStatusList.clear();
for(Status status: results.getStatuses()) { for(Status status: results.getStatuses()) {
concreteStatusList.add(ViewDataUtils.statusToViewData( concreteStatusList.add(ViewDataUtils.statusToViewData(
status, status,

View file

@ -147,7 +147,8 @@ class SearchFragment : SFragment(), StatusActionListener {
status, status,
alwaysShowSensitiveMedia alwaysShowSensitiveMedia
), ),
position position,
false
) )
}, { t -> Log.d(TAG, "Failed to reblog status " + status.id, t) }) }, { t -> Log.d(TAG, "Failed to reblog status " + status.id, t) })
} }
@ -166,7 +167,8 @@ class SearchFragment : SFragment(), StatusActionListener {
status, status,
alwaysShowSensitiveMedia alwaysShowSensitiveMedia
), ),
position position,
false
) )
}, { t -> Log.d(TAG, "Failed to favourite status " + status.id, t) }) }, { t -> Log.d(TAG, "Failed to favourite status " + status.id, t) })
} }
@ -200,7 +202,7 @@ class SearchFragment : SFragment(), StatusActionListener {
if (status != null) { if (status != null) {
val newStatus = StatusViewData.Builder(status) val newStatus = StatusViewData.Builder(status)
.setIsExpanded(expanded).createStatusViewData() .setIsExpanded(expanded).createStatusViewData()
searchAdapter.updateStatusAtPosition(newStatus, position) searchAdapter.updateStatusAtPosition(newStatus, position, false)
} }
} }
@ -209,7 +211,7 @@ class SearchFragment : SFragment(), StatusActionListener {
if (status != null) { if (status != null) {
val newStatus = StatusViewData.Builder(status) val newStatus = StatusViewData.Builder(status)
.setIsShowingSensitiveContent(isShowing).createStatusViewData() .setIsShowingSensitiveContent(isShowing).createStatusViewData()
searchAdapter.updateStatusAtPosition(newStatus, position) searchAdapter.updateStatusAtPosition(newStatus, position, true)
} }
} }
@ -228,7 +230,7 @@ class SearchFragment : SFragment(), StatusActionListener {
val updatedStatus = StatusViewData.Builder(status) val updatedStatus = StatusViewData.Builder(status)
.setCollapsed(isCollapsed) .setCollapsed(isCollapsed)
.createStatusViewData() .createStatusViewData()
searchAdapter.updateStatusAtPosition(updatedStatus, position) searchAdapter.updateStatusAtPosition(updatedStatus, position, false)
searchRecyclerView.post { searchAdapter.notifyItemChanged(position, updatedStatus) } searchRecyclerView.post { searchAdapter.notifyItemChanged(position, updatedStatus) }
} }
@ -257,7 +259,7 @@ class SearchFragment : SFragment(), StatusActionListener {
val newViewData = StatusViewData.Builder(viewData) val newViewData = StatusViewData.Builder(viewData)
.setPoll(poll) .setPoll(poll)
.createStatusViewData() .createStatusViewData()
searchAdapter.updateStatusAtPosition(newViewData, position) searchAdapter.updateStatusAtPosition(newViewData, position, true)
}, { t -> Log.d(TAG, "Failed to vote in poll " + status.id, t) }) }, { t -> Log.d(TAG, "Failed to vote in poll " + status.id, t) })
} }