fix crash in SearchFragment (#1266)
This commit is contained in:
parent
3f957a09c5
commit
c8bf07ea77
|
@ -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,10 +141,12 @@ 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);
|
||||||
|
if(doNotify) {
|
||||||
notifyItemChanged(position);
|
notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeStatusAtPosition(int position) {
|
public void removeStatusAtPosition(int position) {
|
||||||
concreteStatusList.remove(position - accountList.size());
|
concreteStatusList.remove(position - accountList.size());
|
||||||
|
@ -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,
|
||||||
|
|
|
@ -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) })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue