refine long-clicks
and disable long-click for multiple accounts when logged in to single account
This commit is contained in:
@@ -60,7 +60,14 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
private static final Animation opacityOut, opacityIn;
|
private static final Animation opacityOut, opacityIn;
|
||||||
|
|
||||||
private View touchingView = null;
|
private View touchingView = null;
|
||||||
private final Runnable longClickRunnable = () -> { if (touchingView != null) touchingView.performLongClick(); };
|
private boolean longClickPerformed = false;
|
||||||
|
private final Runnable longClickRunnable = () -> {
|
||||||
|
longClickPerformed = touchingView != null && touchingView.performLongClick();
|
||||||
|
if (longClickPerformed && touchingView != null) {
|
||||||
|
touchingView.startAnimation(opacityIn);
|
||||||
|
touchingView.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){
|
private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +84,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
opacityOut.setInterpolator(CubicBezierInterpolator.DEFAULT);
|
opacityOut.setInterpolator(CubicBezierInterpolator.DEFAULT);
|
||||||
opacityOut.setFillAfter(true);
|
opacityOut.setFillAfter(true);
|
||||||
opacityIn = new AlphaAnimation(0.55f, 1);
|
opacityIn = new AlphaAnimation(0.55f, 1);
|
||||||
opacityIn.setDuration(300);
|
opacityIn.setDuration(500);
|
||||||
opacityIn.setInterpolator(CubicBezierInterpolator.DEFAULT);
|
opacityIn.setInterpolator(CubicBezierInterpolator.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,15 +154,15 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
boolean disabled = !v.isEnabled() || (v instanceof FrameLayout parentFrame &&
|
boolean disabled = !v.isEnabled() || (v instanceof FrameLayout parentFrame &&
|
||||||
parentFrame.getChildCount() > 0 && !parentFrame.getChildAt(0).isEnabled());
|
parentFrame.getChildCount() > 0 && !parentFrame.getChildAt(0).isEnabled());
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
long eventDuration = event.getEventTime() - event.getDownTime();
|
|
||||||
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
||||||
touchingView = null;
|
touchingView = null;
|
||||||
v.removeCallbacks(longClickRunnable);
|
v.removeCallbacks(longClickRunnable);
|
||||||
v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
if (!longClickPerformed) v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
||||||
if (disabled) return true;
|
if (disabled) return true;
|
||||||
if (action == MotionEvent.ACTION_UP && eventDuration <= ViewConfiguration.getLongPressTimeout()) v.performClick();
|
if (action == MotionEvent.ACTION_UP && !longClickPerformed) v.performClick();
|
||||||
else v.startAnimation(opacityIn);
|
else if (!longClickPerformed) v.startAnimation(opacityIn);
|
||||||
} else if (action == MotionEvent.ACTION_DOWN) {
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
longClickPerformed = false;
|
||||||
touchingView = v;
|
touchingView = v;
|
||||||
// 20dp to center in middle of icon, because: (icon width = 24dp) / 2 + (paddingStart = 8dp)
|
// 20dp to center in middle of icon, because: (icon width = 24dp) / 2 + (paddingStart = 8dp)
|
||||||
v.setPivotX(V.dp(20));
|
v.setPivotX(V.dp(20));
|
||||||
@@ -176,6 +183,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean onReplyLongClick(View v) {
|
private boolean onReplyLongClick(View v) {
|
||||||
|
if (AccountSessionManager.getInstance().getLoggedInAccounts().size() < 2) return false;
|
||||||
UiUtils.pickAccount(v.getContext(), item.accountID, R.string.sk_reply_as, R.drawable.ic_fluent_arrow_reply_24_regular, session -> {
|
UiUtils.pickAccount(v.getContext(), item.accountID, R.string.sk_reply_as, R.drawable.ic_fluent_arrow_reply_24_regular, session -> {
|
||||||
Bundle args=new Bundle();
|
Bundle args=new Bundle();
|
||||||
String accountID = session.getID();
|
String accountID = session.getID();
|
||||||
@@ -288,6 +296,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean onFavoriteLongClick(View v) {
|
private boolean onFavoriteLongClick(View v) {
|
||||||
|
if (AccountSessionManager.getInstance().getLoggedInAccounts().size() < 2) return false;
|
||||||
UiUtils.pickInteractAs(v.getContext(),
|
UiUtils.pickInteractAs(v.getContext(),
|
||||||
item.accountID, item.status,
|
item.accountID, item.status,
|
||||||
s -> s.favourited,
|
s -> s.favourited,
|
||||||
@@ -308,6 +317,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean onBookmarkLongClick(View v) {
|
private boolean onBookmarkLongClick(View v) {
|
||||||
|
if (AccountSessionManager.getInstance().getLoggedInAccounts().size() < 2) return false;
|
||||||
UiUtils.pickInteractAs(v.getContext(),
|
UiUtils.pickInteractAs(v.getContext(),
|
||||||
item.accountID, item.status,
|
item.accountID, item.status,
|
||||||
s -> s.bookmarked,
|
s -> s.bookmarked,
|
||||||
|
|||||||
@@ -140,12 +140,6 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
|
|||||||
avatar.setOutlineProvider(roundCornersOutline);
|
avatar.setOutlineProvider(roundCornersOutline);
|
||||||
avatar.setClipToOutline(true);
|
avatar.setClipToOutline(true);
|
||||||
more.setOnClickListener(this::onMoreClick);
|
more.setOnClickListener(this::onMoreClick);
|
||||||
more.setOnLongClickListener((v) -> {
|
|
||||||
PopupMenu popup = new PopupMenu(itemView.getContext(), v);
|
|
||||||
populateAccountsMenu(popup.getMenu());
|
|
||||||
popup.show();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
visibility.setOnClickListener(v->item.parentFragment.onVisibilityIconClick(this));
|
visibility.setOnClickListener(v->item.parentFragment.onVisibilityIconClick(this));
|
||||||
deleteNotification.setOnClickListener(v->UiUtils.confirmDeleteNotification(activity, item.parentFragment.getAccountID(), item.notification, ()->{
|
deleteNotification.setOnClickListener(v->UiUtils.confirmDeleteNotification(activity, item.parentFragment.getAccountID(), item.notification, ()->{
|
||||||
if (item.parentFragment instanceof NotificationsListFragment fragment) {
|
if (item.parentFragment instanceof NotificationsListFragment fragment) {
|
||||||
@@ -159,12 +153,6 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
|
|||||||
Account account=item.user;
|
Account account=item.user;
|
||||||
int id=menuItem.getItemId();
|
int id=menuItem.getItemId();
|
||||||
|
|
||||||
SubMenu accountsMenu=id==R.id.open_with_account ? menuItem.getSubMenu() : null;
|
|
||||||
if (accountsMenu != null) {
|
|
||||||
accountsMenu.clear();
|
|
||||||
populateAccountsMenu(accountsMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(id==R.id.edit || id==R.id.delete_and_redraft) {
|
if(id==R.id.edit || id==R.id.delete_and_redraft) {
|
||||||
final Bundle args=new Bundle();
|
final Bundle args=new Bundle();
|
||||||
args.putString("account", item.parentFragment.getAccountID());
|
args.putString("account", item.parentFragment.getAccountID());
|
||||||
@@ -335,9 +323,22 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateOptionsMenu(){
|
private void updateOptionsMenu(){
|
||||||
Account account=item.user;
|
boolean hasMultipleAccounts = AccountSessionManager.getInstance().getLoggedInAccounts().size() > 1;
|
||||||
Menu menu=optionsMenu.getMenu();
|
Menu menu=optionsMenu.getMenu();
|
||||||
|
|
||||||
|
MenuItem openWithAccounts = menu.findItem(R.id.open_with_account);
|
||||||
|
SubMenu accountsMenu = openWithAccounts != null ? openWithAccounts.getSubMenu() : null;
|
||||||
|
if (hasMultipleAccounts && accountsMenu != null) {
|
||||||
|
openWithAccounts.setVisible(true);
|
||||||
|
accountsMenu.clear();
|
||||||
|
populateAccountsMenu(accountsMenu);
|
||||||
|
} else if (openWithAccounts != null) {
|
||||||
|
openWithAccounts.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Account account=item.user;
|
||||||
boolean isOwnPost=AccountSessionManager.getInstance().isSelf(item.parentFragment.getAccountID(), account);
|
boolean isOwnPost=AccountSessionManager.getInstance().isSelf(item.parentFragment.getAccountID(), account);
|
||||||
|
menu.findItem(R.id.open_with_account).setVisible(hasMultipleAccounts);
|
||||||
menu.findItem(R.id.edit).setVisible(item.status!=null && isOwnPost);
|
menu.findItem(R.id.edit).setVisible(item.status!=null && isOwnPost);
|
||||||
menu.findItem(R.id.delete).setVisible(item.status!=null && isOwnPost);
|
menu.findItem(R.id.delete).setVisible(item.status!=null && isOwnPost);
|
||||||
menu.findItem(R.id.delete_and_redraft).setVisible(item.status!=null && isOwnPost);
|
menu.findItem(R.id.delete_and_redraft).setVisible(item.status!=null && isOwnPost);
|
||||||
|
|||||||
Reference in New Issue
Block a user