Polls part 1 - displaying in timelines and voting (#1200)
* add entity classes * change data models and add database migration * add polls to StatusViewData * show poll results * add methods for vote handling * add voting interface * enable voting in TimelineFragment * update polls immediately * enable custom emojis for poll options * enable voting from search fragment * add voting layout to detailed statuses * fix tests * enable voting in ViewThreadFragment * enable voting in ConversationsFragment * small refactor for StatusBaseViewHolder
This commit is contained in:
parent
82d547caf8
commit
fd7471f2ab
36 changed files with 1637 additions and 68 deletions
|
|
@ -45,6 +45,7 @@ import com.keylesspalace.tusky.appstore.UnfollowEvent;
|
|||
import com.keylesspalace.tusky.db.AccountManager;
|
||||
import com.keylesspalace.tusky.di.Injectable;
|
||||
import com.keylesspalace.tusky.entity.Filter;
|
||||
import com.keylesspalace.tusky.entity.Poll;
|
||||
import com.keylesspalace.tusky.entity.Status;
|
||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
||||
import com.keylesspalace.tusky.interfaces.ReselectableFragment;
|
||||
|
|
@ -620,6 +621,34 @@ public class TimelineFragment extends SFragment implements
|
|||
updateAdapter();
|
||||
}
|
||||
|
||||
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
|
||||
final Status status = statuses.get(position).asRight();
|
||||
|
||||
setVoteForPoll(position, status, status.getPoll().votedCopy(choices));
|
||||
|
||||
timelineCases.voteInPoll(status, choices)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this)))
|
||||
.subscribe(
|
||||
(newPoll) -> setVoteForPoll(position, status, newPoll),
|
||||
(t) -> Log.d(TAG,
|
||||
"Failed to vote in poll: " + status.getId(), t)
|
||||
);
|
||||
}
|
||||
|
||||
private void setVoteForPoll(int position, Status status, Poll newPoll) {
|
||||
Pair<StatusViewData.Concrete, Integer> actual =
|
||||
findStatusAndPosition(position, status);
|
||||
if (actual == null) return;
|
||||
|
||||
StatusViewData newViewData = new StatusViewData
|
||||
.Builder(actual.first)
|
||||
.setPoll(newPoll)
|
||||
.createStatusViewData();
|
||||
statuses.setPairedItem(actual.second, newViewData);
|
||||
updateAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMore(@NonNull View view, final int position) {
|
||||
super.more(statuses.get(position).asRight(), view, position);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue