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

View File

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