Bookmarks (#1560)
* add bookmarks to timelines * add Bookmarks to main menu * cleanup * handle BookmarkEvent * fix tests * fix bookmark handling in NotificationsFragment * add bookmark accessibility actions
This commit is contained in:
parent
d6ec5ca8d3
commit
d9694df0c2
44 changed files with 1235 additions and 122 deletions
|
|
@ -45,6 +45,7 @@ import com.keylesspalace.tusky.R;
|
|||
import com.keylesspalace.tusky.ViewThreadActivity;
|
||||
import com.keylesspalace.tusky.adapter.ThreadAdapter;
|
||||
import com.keylesspalace.tusky.appstore.BlockEvent;
|
||||
import com.keylesspalace.tusky.appstore.BookmarkEvent;
|
||||
import com.keylesspalace.tusky.appstore.EventHub;
|
||||
import com.keylesspalace.tusky.appstore.FavoriteEvent;
|
||||
import com.keylesspalace.tusky.appstore.ReblogEvent;
|
||||
|
|
@ -186,6 +187,8 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
handleFavEvent((FavoriteEvent) event);
|
||||
} else if (event instanceof ReblogEvent) {
|
||||
handleReblogEvent((ReblogEvent) event);
|
||||
} else if (event instanceof BookmarkEvent) {
|
||||
handleBookmarkEvent((BookmarkEvent) event);
|
||||
} else if (event instanceof BlockEvent) {
|
||||
removeAllByAccountId(((BlockEvent) event).getAccountId());
|
||||
} else if (event instanceof StatusComposedEvent) {
|
||||
|
|
@ -239,7 +242,7 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
.as(autoDisposable(from(this)))
|
||||
.subscribe(
|
||||
(newStatus) -> updateStatus(position, newStatus),
|
||||
(t) -> Log.d(getClass().getSimpleName(),
|
||||
(t) -> Log.d(TAG,
|
||||
"Failed to reblog status: " + status.getId(), t)
|
||||
);
|
||||
}
|
||||
|
|
@ -253,11 +256,25 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
.as(autoDisposable(from(this)))
|
||||
.subscribe(
|
||||
(newStatus) -> updateStatus(position, newStatus),
|
||||
(t) -> Log.d(getClass().getSimpleName(),
|
||||
(t) -> Log.d(TAG,
|
||||
"Failed to favourite status: " + status.getId(), t)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmark(final boolean bookmark, final int position) {
|
||||
final Status status = statuses.get(position);
|
||||
|
||||
timelineCases.bookmark(statuses.get(position), bookmark)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this)))
|
||||
.subscribe(
|
||||
(newStatus) -> updateStatus(position, newStatus),
|
||||
(t) -> Log.d(TAG,
|
||||
"Failed to bookmark status: " + status.getId(), t)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateStatus(int position, Status status) {
|
||||
if (position >= 0 && position < statuses.size()) {
|
||||
|
||||
|
|
@ -267,6 +284,7 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
.setReblogged(actionableStatus.getReblogged())
|
||||
.setReblogsCount(actionableStatus.getReblogsCount())
|
||||
.setFavourited(actionableStatus.getFavourited())
|
||||
.setBookmarked(actionableStatus.getBookmarked())
|
||||
.setFavouritesCount(actionableStatus.getFavouritesCount())
|
||||
.createStatusViewData();
|
||||
statuses.setPairedItem(position, viewData);
|
||||
|
|
@ -621,6 +639,28 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
adapter.setItem(posAndStatus.first, newViewData, true);
|
||||
}
|
||||
|
||||
private void handleBookmarkEvent(BookmarkEvent event) {
|
||||
Pair<Integer, Status> posAndStatus = findStatusAndPos(event.getStatusId());
|
||||
if (posAndStatus == null) return;
|
||||
|
||||
boolean bookmark = event.getBookmark();
|
||||
posAndStatus.second.setBookmarked(bookmark);
|
||||
|
||||
if (posAndStatus.second.getReblog() != null) {
|
||||
posAndStatus.second.getReblog().setBookmarked(bookmark);
|
||||
}
|
||||
|
||||
StatusViewData.Concrete viewdata = statuses.getPairedItem(posAndStatus.first);
|
||||
|
||||
StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder((viewdata));
|
||||
viewDataBuilder.setBookmarked(bookmark);
|
||||
|
||||
StatusViewData.Concrete newViewData = viewDataBuilder.createStatusViewData();
|
||||
|
||||
statuses.setPairedItem(posAndStatus.first, newViewData);
|
||||
adapter.setItem(posAndStatus.first, newViewData, true);
|
||||
}
|
||||
|
||||
private void handleStatusComposedEvent(StatusComposedEvent event) {
|
||||
Status eventStatus = event.getStatus();
|
||||
if (eventStatus.getInReplyToId() == null) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue