From 7c0ad62a9842c823df0188ad003d317e86764c11 Mon Sep 17 00:00:00 2001 From: pixel Date: Tue, 28 Sep 2021 23:08:22 -0400 Subject: [PATCH 1/2] I'm working to display share button when long press on a claim #1133. (https://github.com/lbryio/lbry-android/issues/1133) So far, I've located the longClick method in the claimadapter. I put some Log.d messages to confirm that I can do something when I long press. Evreything's working so it looks like I can progress to implement a menu kind of selection for sharing. --- .../browser/adapter/ClaimListAdapter.java | 20 +++++++++++++++++++ app/src/main/res/menu/menu_claim_popup.xml | 18 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 app/src/main/res/menu/menu_claim_popup.xml diff --git a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java index a3fefc64a..e08f8a8bb 100644 --- a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java @@ -2,12 +2,14 @@ import android.content.Context; import android.text.format.DateUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import androidx.recyclerview.widget.RecyclerView; @@ -22,6 +24,7 @@ import java.util.Map; import io.lbry.browser.R; +import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.SelectionModeListener; import io.lbry.browser.model.Claim; import io.lbry.browser.model.LbryFile; @@ -32,6 +35,7 @@ import lombok.Setter; public class ClaimListAdapter extends RecyclerView.Adapter { + private static final String TAG = ClaimListAdapter.class.getSimpleName(); private static final int VIEW_TYPE_STREAM = 1; private static final int VIEW_TYPE_CHANNEL = 2; private static final int VIEW_TYPE_FEATURED = 3; // featured search result @@ -369,6 +373,22 @@ public void onClick(View view) { vh.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { + + //THIS IS FOR SHARING THE VIDEO ON LONG PRESS + Toast.makeText(context, "LONG CLICKED: " + original.getTitle(), Toast.LENGTH_SHORT).show(); //Don't need, but it's nice to see it on the UI + Log.d(TAG, "LONG CLICKED: " + original.getTitle()); + + try{ + String shareUrl = LbryUri.parse( + !Helper.isNullOrEmpty(original.getCanonicalUrl()) ? original.getCanonicalUrl() : + (!Helper.isNullOrEmpty(original.getShortUrl()) ? original.getShortUrl() : original.getPermanentUrl())).toTvString(); + + Log.d(TAG, "LONG CLICKED, SHARE " + shareUrl); + + } catch (LbryUriException lbryUriException){ + lbryUriException.printStackTrace(); + } + if (!canEnterSelectionMode) { return false; } diff --git a/app/src/main/res/menu/menu_claim_popup.xml b/app/src/main/res/menu/menu_claim_popup.xml new file mode 100644 index 000000000..20719899f --- /dev/null +++ b/app/src/main/res/menu/menu_claim_popup.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + From ad31ff758cd6d735c52fde73bd09e2536e3b2a1b Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 29 Sep 2021 06:57:20 -0400 Subject: [PATCH 2/2] I'm working to display share button when long press on a claim #1133. (https://github.com/lbryio/lbry-android/issues/1133) So far, I've got it working pretty well. Now, there's quite a few ways to implement a menu after a long press. Signal Messenger has a cool UI for when users long click on a message. But other apps like NewPipe just use a dialog to display other options. To keep things simple, I used a popup menu. Now, I added other menu items that you'd see in the FileViewFragment (download, repost, etc.). I added these because only putting "share" in the menu didn't seem like much of a menu. "Share" is the only menu item that actually works right now. --- .../browser/adapter/ClaimListAdapter.java | 93 ++++++++++++++++--- app/src/main/res/values/styles.xml | 6 ++ 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java index e08f8a8bb..2b10c9042 100644 --- a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java @@ -1,9 +1,12 @@ package io.lbry.browser.adapter; import android.content.Context; +import android.content.Intent; import android.text.format.DateUtils; import android.util.Log; +import android.view.Gravity; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -11,6 +14,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -23,6 +27,7 @@ import java.util.List; import java.util.Map; +import io.lbry.browser.MainActivity; import io.lbry.browser.R; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.SelectionModeListener; @@ -374,19 +379,8 @@ public void onClick(View view) { @Override public boolean onLongClick(View view) { - //THIS IS FOR SHARING THE VIDEO ON LONG PRESS - Toast.makeText(context, "LONG CLICKED: " + original.getTitle(), Toast.LENGTH_SHORT).show(); //Don't need, but it's nice to see it on the UI - Log.d(TAG, "LONG CLICKED: " + original.getTitle()); - - try{ - String shareUrl = LbryUri.parse( - !Helper.isNullOrEmpty(original.getCanonicalUrl()) ? original.getCanonicalUrl() : - (!Helper.isNullOrEmpty(original.getShortUrl()) ? original.getShortUrl() : original.getPermanentUrl())).toTvString(); - - Log.d(TAG, "LONG CLICKED, SHARE " + shareUrl); - - } catch (LbryUriException lbryUriException){ - lbryUriException.printStackTrace(); + if (original != null) { + showClaimPopupMenu(view, original); } if (!canEnterSelectionMode) { @@ -539,6 +533,79 @@ private void toggleSelectedClaim(Claim claim) { notifyDataSetChanged(); } + public void showClaimPopupMenu(View view, Claim claim) { + + Toast.makeText(context, "LONG CLICKED: " + claim.getTitle(), Toast.LENGTH_SHORT).show(); //Don't need, but it's nice to see it on the UI + Log.d(TAG, "LONG CLICKED: " + claim.getTitle()); + + //do I need to do a check if context is null? + PopupMenu popup = new PopupMenu(context, view); + + popup.getMenuInflater().inflate(R.menu.menu_claim_popup, popup.getMenu()); + popup.setGravity(Gravity.END); + + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + int i = item.getItemId(); + if (i == R.id.menu_claim_popup_share) { + //share the claim + Log.d(TAG, "Let's share: " + claim.getTitle()); + try{ + String shareUrl = LbryUri.parse( + !Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() : + (!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toTvString(); + + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(Intent.EXTRA_TEXT, shareUrl); + + MainActivity.startingShareActivity = true; + Intent shareUrlIntent = Intent.createChooser(shareIntent, context.getString(R.string.share_lbry_content)); + shareUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + context.startActivity(shareUrlIntent); + Log.d(TAG, "Sharing: " + shareUrl); + + } catch (LbryUriException lbryUriException){ + lbryUriException.printStackTrace(); + } + return true; + } + else if (i == R.id.menu_claim_popup_support){ + //support the claim + Log.d(TAG, "Let's support: " + claim.getTitle()); + + return true; + } + else if (i == R.id.menu_claim_popup_repost) { + //repost the claim + Log.d(TAG, "Let's repost: " + claim.getTitle()); + + return true; + } + else if (i == R.id.menu_claim_popup_download) { + //download the claim + Log.d(TAG, "Let's download: " + claim.getTitle()); + + return true; + } + else if (i == R.id.menu_claim_popup_report) { + //report the claim + Log.d(TAG, "Let's report: " + claim.getTitle()); + + return true; + } + else { + return onMenuItemClick(item); + } + } + }); + + popup.show(); + + } + public interface ClaimListItemListener { void onClaimClicked(Claim claim); } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 7c5e55a25..89067826c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -9,6 +9,7 @@ true @color/colorPrimaryDark @style/AppTheme.DrawerArrowStyle + @style/ClaimPopupMenu @@ -32,4 +33,9 @@ @color/actionBarForeground + +