Fix cross actions - #11 add bookmark support

This commit is contained in:
Thomas 2022-05-01 11:14:23 +02:00
parent d2e70ff182
commit ca9c9cfcab
7 changed files with 181 additions and 32 deletions

View file

@ -178,18 +178,32 @@ public class CrossActionHelper {
assert statusesVM != null;
statusesVM.favourite(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_favourite), Toasty.LENGTH_SHORT).show());
break;
case UNFAVOURITE_ACTION:
assert statusesVM != null;
statusesVM.unFavourite(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unfavourite), Toasty.LENGTH_SHORT).show());
break;
case BOOKMARK_ACTION:
assert statusesVM != null;
statusesVM.bookmark(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_bookmark), Toasty.LENGTH_SHORT).show());
break;
case UNBOOKMARK_ACTION:
assert statusesVM != null;
statusesVM.unBookmark(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unbookmark), Toasty.LENGTH_SHORT).show());
break;
case REBLOG_ACTION:
assert statusesVM != null;
statusesVM.reblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id, null)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_reblog), Toasty.LENGTH_SHORT).show());
break;
case UNREBLOG_ACTION:
assert statusesVM != null;
statusesVM.unReblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unreblog), Toasty.LENGTH_SHORT).show());
break;
}
}
@ -202,6 +216,8 @@ public class CrossActionHelper {
UNBLOCK_ACTION,
FAVOURITE_ACTION,
UNFAVOURITE_ACTION,
BOOKMARK_ACTION,
UNBOOKMARK_ACTION,
REBLOG_ACTION,
UNREBLOG_ACTION
}

View file

@ -207,15 +207,20 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonFavorite.pressOnTouch(false);
holder.binding.actionButtonBoost.pressOnTouch(false);
holder.binding.actionButtonBookmark.pressOnTouch(false);
holder.binding.actionButtonFavorite.setActiveImage(R.drawable.ic_baseline_star_24);
holder.binding.actionButtonFavorite.setInactiveImage(R.drawable.ic_star_outline);
holder.binding.actionButtonBookmark.setInactiveImage(R.drawable.ic_baseline_bookmark_border_24);
holder.binding.actionButtonFavorite.setDisableCircle(true);
holder.binding.actionButtonBoost.setDisableCircle(true);
holder.binding.actionButtonBookmark.setDisableCircle(true);
holder.binding.actionButtonFavorite.setActiveImageTint(R.color.marked_icon);
holder.binding.actionButtonBoost.setActiveImageTint(R.color.boost_icon);
holder.binding.actionButtonBookmark.setActiveImageTint(R.color.marked_icon);
holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBoost.setColors(R.color.marked_icon, R.color.marked_icon);
//holder.binding.actionButtonBoost.setColors(R.color.marked_icon, R.color.marked_icon);
if (theme_text_header_2_line != -1) {
Pattern hashAcct;
@ -310,7 +315,54 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtons.setVisibility(View.GONE);
} else {
holder.binding.actionButtons.setVisibility(View.VISIBLE);
//Hide or display bookmark button when status is focused
if (status.isFocused) {
holder.binding.actionButtonBookmark.setVisibility(View.VISIBLE);
} else {
holder.binding.actionButtonBookmark.setVisibility(View.GONE);
}
//--- ACTIONS ---
holder.binding.actionButtonBookmark.setChecked(statusToDeal.bookmarked);
//---> BOOKMARK/UNBOOKMARK
holder.binding.actionButtonBookmark.setOnLongClickListener(v -> {
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, null, statusToDeal);
return true;
});
holder.binding.actionButtonBookmark.setOnClickListener(v -> {
if (remote) {
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.bookmarked = _status.bookmarked;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
if (statusToDeal.bookmarked) {
statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.bookmarked = _status.bookmarked;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
((SparkButton) v).playAnimation();
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.bookmarked = _status.bookmarked;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
}
}
});
holder.binding.actionButtonFavorite.setChecked(statusToDeal.favourited);
holder.binding.statusUserInfo.setOnClickListener(v -> {
if (remote) {
@ -445,23 +497,41 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
AlertDialog alert = alt_bld.create();
alert.show();
} else {
if (statusToDeal.reblogged) {
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged;
statusToDeal.reblogs_count = _status.reblogs_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, status));
if (remote) {
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged;
statusToDeal.reblogs_count = _status.reblogs_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
((SparkButton) v).playAnimation();
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged;
statusToDeal.reblogs_count = _status.reblogs_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, status));
});
if (statusToDeal.reblogged) {
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged;
statusToDeal.reblogs_count = _status.reblogs_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
((SparkButton) v).playAnimation();
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id, null)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged;
statusToDeal.reblogs_count = _status.reblogs_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
}
}
}
});
@ -492,7 +562,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
alt_bld.setMessage(context.getString(R.string.favourite_add));
}
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
if (remote) {
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
@ -534,23 +603,40 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
AlertDialog alert = alt_bld.create();
alert.show();
} else {
if (status.favourited) {
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited;
statusToDeal.favourites_count = _status.favourites_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
if (remote) {
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited;
statusToDeal.favourites_count = _status.favourites_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
((SparkButton) v).playAnimation();
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited;
statusToDeal.favourites_count = _status.favourites_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
if (status.favourited) {
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited;
statusToDeal.favourites_count = _status.favourites_count;
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
} else {
((SparkButton) v).playAnimation();
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
.observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited;
statusToDeal.favourites_count = _status.favourites_count;
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
});
}
}
}
});

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z" />
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M17,3L7,3c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z" />
</vector>

View file

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:fillType="evenOdd"
android:pathData="M16,9V4l1,0c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1H7C6.45,2 6,2.45 6,3v0c0,0.55 0.45,1 1,1l1,0v5c0,1.66 -1.34,3 -3,3h0v2h5.97v7l1,1l1,-1v-7H19v-2h0C17.34,12 16,10.66 16,9z" />
</vector>

View file

@ -419,6 +419,20 @@
app:sparkbutton_primaryColor="@color/boost_icon"
app:sparkbutton_secondaryColor="@color/boost_icon" />
<com.varunest.sparkbutton.SparkButton
android:id="@+id/action_button_bookmark"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginStart="12dp"
android:adjustViewBounds="true"
android:visibility="gone"
app:sparkbutton_activeImage="@drawable/ic_baseline_bookmark_24"
app:sparkbutton_animationSpeed="1.5"
app:sparkbutton_iconSize="24dp"
app:sparkbutton_inActiveImage="@drawable/ic_baseline_bookmark_border_24"
app:sparkbutton_primaryColor="@color/marked_icon"
app:sparkbutton_secondaryColor="@color/marked_icon" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"

View file

@ -272,6 +272,8 @@
<string name="toast_unreblog">The toot is no longer boosted!</string>
<string name="toast_favourite">The toot was added to your favourites!</string>
<string name="toast_unfavourite">The toot was removed from your favourites!</string>
<string name="toast_bookmark">The toot was added to your bookmarks!</string>
<string name="toast_unbookmark">The toot was removed from your bookmarks!</string>
<string name="toast_report">The toot was reported!</string>
<string name="toast_unstatus">The toot was deleted!</string>
<string name="toast_pin">The toot was pinned!</string>