From 5a15932334af3d7c73133c6a95c27e128a4cbb1d Mon Sep 17 00:00:00 2001 From: Yaron Budowski Date: Sun, 28 Jan 2024 18:42:19 -0600 Subject: [PATCH] #1321 - unexpected popup menu for IDs/comments in observation viewer --- iNaturalist/src/main/AndroidManifest.xml | 4 +- .../android/CommentsIdsAdapter.java | 205 ++++++++++-------- 2 files changed, 111 insertions(+), 98 deletions(-) diff --git a/iNaturalist/src/main/AndroidManifest.xml b/iNaturalist/src/main/AndroidManifest.xml index 35a99ad7e..059cb10fe 100644 --- a/iNaturalist/src/main/AndroidManifest.xml +++ b/iNaturalist/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="601" + android:versionName="1.30.8"> diff --git a/iNaturalist/src/main/java/org/inaturalist/android/CommentsIdsAdapter.java b/iNaturalist/src/main/java/org/inaturalist/android/CommentsIdsAdapter.java index b415d5bc3..e57f02c91 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/CommentsIdsAdapter.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/CommentsIdsAdapter.java @@ -120,54 +120,9 @@ public View getView(final int position, View convertView, ViewGroup parent) { final String username = item.getJSONObject("user").getString("login"); Timestamp postDate = item.getTimestamp("updated_at"); if (postDate == null) postDate = item.getTimestamp("created_at"); - - postedOn.setText(String.format(res.getString(item.getString("type").equals("comment") ? R.string.comment_title : R.string.id_title), - username, formatIdDate(mContext, postDate))); - - OnClickListener showUser = new OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(mContext, UserProfile.class); - intent.putExtra("user", new BetterJSONObject(item.getJSONObject("user"))); - mContext.startActivity(intent); - } - }; - - - final ImageView userPic = (ImageView) view.findViewById(R.id.user_pic); - JSONObject user = item.getJSONObject("user"); - String userIconUrl = user.optString("user_icon_url", user.optString("icon")); - boolean hasUserIcon = userIconUrl != null && userIconUrl.length() > 0; - - userPic.setOnClickListener(showUser); - postedOn.setOnClickListener(showUser); - - if (hasUserIcon) { - Picasso.with(mContext) - .load(userIconUrl) - .fit() - .centerCrop() - .placeholder(R.drawable.ic_account_circle_black_24dp) - .transform(new UserActivitiesAdapter.CircleTransform()) - .into(userPic, new Callback() { - @Override - public void onSuccess() { - // Nothing to do here - } - - @Override - public void onError() { - - } - }); - - } else { - userPic.setAlpha(100); - } - - final View moreMenu = view.findViewById(R.id.more_menu); - final boolean isComment = item.getString("type").equals("comment"); final View loading = view.findViewById(R.id.loading); + final boolean isComment = item.getString("type").equals("comment"); + final View moreMenu = view.findViewById(R.id.more_menu); final DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() { @Override @@ -211,59 +166,107 @@ public void onClick(DialogInterface dialogInterface, int i) { } }; - if (moreMenu != null) { - moreMenu.setVisibility(View.GONE); - moreMenu.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (loading.getVisibility() == View.VISIBLE) { - return; - } + OnClickListener popupMenuListener = new OnClickListener() { + @Override + public void onClick(View view) { + if (loading.getVisibility() == View.VISIBLE) { + return; + } - int menuResource = isComment && username.equalsIgnoreCase(mLogin) ? R.menu.comment_menu : R.menu.id_menu; + int menuResource = isComment && username.equalsIgnoreCase(mLogin) ? R.menu.comment_menu : R.menu.id_menu; - boolean restoreId = false; - if (menuResource == R.menu.id_menu) { - Boolean isCurrent = item.getBoolean("current"); - if (((isCurrent == null) || (!isCurrent)) && (username.equalsIgnoreCase(mLogin))) { - restoreId = true; - } - } - - Menu popupMenu; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - PopupMenu popup = new PopupMenu(getContext(), moreMenu); - popup.getMenuInflater().inflate(menuResource, popup.getMenu()); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(android.view.MenuItem menuItem) { - onClick.onClick(null, menuItem.getItemId()); - return true; - } - }); - - popupMenu = popup.getMenu(); - popup.show(); - } else { - BottomSheet sheet = new BottomSheet.Builder((Activity) mContext).sheet(menuResource).listener(onClick).show(); - popupMenu = sheet.getMenu(); + boolean restoreId = false; + if (menuResource == R.menu.id_menu) { + Boolean isCurrent = item.getBoolean("current"); + if (((isCurrent == null) || (!isCurrent)) && (username.equalsIgnoreCase(mLogin))) { + restoreId = true; } + } - if (!isComment) { - if (restoreId) { - // Show restore ID menu option - popupMenu.getItem(0).setVisible(false); - popupMenu.getItem(1).setVisible(true); - } else { - // Show withdraw ID menu option - popupMenu.getItem(0).setVisible(true); - popupMenu.getItem(1).setVisible(false); + Menu popupMenu; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + PopupMenu popup = new PopupMenu(getContext(), moreMenu); + popup.getMenuInflater().inflate(menuResource, popup.getMenu()); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(android.view.MenuItem menuItem) { + onClick.onClick(null, menuItem.getItemId()); + return true; } - } + }); + popupMenu = popup.getMenu(); + popup.show(); + } else { + BottomSheet sheet = new BottomSheet.Builder((Activity) mContext).sheet(menuResource).listener(onClick).show(); + popupMenu = sheet.getMenu(); } - }); + + if (!isComment) { + if (restoreId) { + // Show restore ID menu option + popupMenu.getItem(0).setVisible(false); + popupMenu.getItem(1).setVisible(true); + } else { + // Show withdraw ID menu option + popupMenu.getItem(0).setVisible(true); + popupMenu.getItem(1).setVisible(false); + } + } + + } + }; + + + postedOn.setText(String.format(res.getString(item.getString("type").equals("comment") ? R.string.comment_title : R.string.id_title), + username, formatIdDate(mContext, postDate))); + + OnClickListener showUser = new OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(mContext, UserProfile.class); + intent.putExtra("user", new BetterJSONObject(item.getJSONObject("user"))); + mContext.startActivity(intent); + } + }; + + + final ImageView userPic = (ImageView) view.findViewById(R.id.user_pic); + JSONObject user = item.getJSONObject("user"); + String userIconUrl = user.optString("user_icon_url", user.optString("icon")); + boolean hasUserIcon = userIconUrl != null && userIconUrl.length() > 0; + + userPic.setOnClickListener(showUser); + postedOn.setOnClickListener(showUser); + + if (hasUserIcon) { + Picasso.with(mContext) + .load(userIconUrl) + .fit() + .centerCrop() + .placeholder(R.drawable.ic_account_circle_black_24dp) + .transform(new UserActivitiesAdapter.CircleTransform()) + .into(userPic, new Callback() { + @Override + public void onSuccess() { + // Nothing to do here + } + + @Override + public void onError() { + + } + }); + + } else { + userPic.setAlpha(100); + } + + + if (moreMenu != null) { + moreMenu.setVisibility(View.GONE); + moreMenu.setOnClickListener(null); } showHiddenContent.setOnClickListener(new OnClickListener() { @@ -320,7 +323,10 @@ public void onClick(View view) { comment.setVisibility(View.VISIBLE); idLayout.setVisibility(View.GONE); loading.setVisibility(View.GONE); - if (moreMenu != null) moreMenu.setVisibility(View.VISIBLE); + if (moreMenu != null) { + moreMenu.setVisibility(View.VISIBLE); + moreMenu.setOnClickListener(popupMenuListener); + } idAgreeLayout.setVisibility(View.GONE); comment.setTypeface(null, Typeface.NORMAL); @@ -434,11 +440,17 @@ public void onClick(View v) { idAgreeLayout.setVisibility(View.GONE); } - if (moreMenu != null) moreMenu.setVisibility(View.GONE); + if (moreMenu != null) { + moreMenu.setVisibility(View.GONE); + moreMenu.setOnClickListener(null); + } if ((mLogin != null) && (username.equalsIgnoreCase(mLogin))) { idAgreeLayout.setVisibility(View.GONE); - if (moreMenu != null) moreMenu.setVisibility(View.VISIBLE); + if (moreMenu != null) { + moreMenu.setVisibility(View.VISIBLE); + moreMenu.setOnClickListener(popupMenuListener); + } if ((isCurrent == null) || (!isCurrent)) { // Faded IDs should not have a "Remove" button @@ -501,6 +513,7 @@ public void onClick(View v) { if (moreMenu != null) { if ((mLogin == null) || ((mLogin != null) && (!username.equalsIgnoreCase(mLogin)))) { moreMenu.setVisibility(View.GONE); + moreMenu.setOnClickListener(null); } } } catch (JSONException e) {