Skip to content

Commit ad31ff7

Browse files
author
pixel
committed
I'm working to display share button when long press on a claim #1133.
(#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.
1 parent 7c0ad62 commit ad31ff7

2 files changed

Lines changed: 86 additions & 13 deletions

File tree

app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package io.lbry.browser.adapter;
22

33
import android.content.Context;
4+
import android.content.Intent;
45
import android.text.format.DateUtils;
56
import android.util.Log;
7+
import android.view.Gravity;
68
import android.view.LayoutInflater;
9+
import android.view.MenuItem;
710
import android.view.View;
811
import android.view.ViewGroup;
912
import android.widget.ImageView;
1013
import android.widget.ProgressBar;
1114
import android.widget.TextView;
1215
import android.widget.Toast;
1316

17+
import androidx.appcompat.widget.PopupMenu;
1418
import androidx.recyclerview.widget.RecyclerView;
1519

1620
import com.bumptech.glide.Glide;
@@ -23,6 +27,7 @@
2327
import java.util.List;
2428
import java.util.Map;
2529

30+
import io.lbry.browser.MainActivity;
2631
import io.lbry.browser.R;
2732
import io.lbry.browser.exceptions.LbryUriException;
2833
import io.lbry.browser.listener.SelectionModeListener;
@@ -374,19 +379,8 @@ public void onClick(View view) {
374379
@Override
375380
public boolean onLongClick(View view) {
376381

377-
//THIS IS FOR SHARING THE VIDEO ON LONG PRESS
378-
Toast.makeText(context, "LONG CLICKED: " + original.getTitle(), Toast.LENGTH_SHORT).show(); //Don't need, but it's nice to see it on the UI
379-
Log.d(TAG, "LONG CLICKED: " + original.getTitle());
380-
381-
try{
382-
String shareUrl = LbryUri.parse(
383-
!Helper.isNullOrEmpty(original.getCanonicalUrl()) ? original.getCanonicalUrl() :
384-
(!Helper.isNullOrEmpty(original.getShortUrl()) ? original.getShortUrl() : original.getPermanentUrl())).toTvString();
385-
386-
Log.d(TAG, "LONG CLICKED, SHARE " + shareUrl);
387-
388-
} catch (LbryUriException lbryUriException){
389-
lbryUriException.printStackTrace();
382+
if (original != null) {
383+
showClaimPopupMenu(view, original);
390384
}
391385

392386
if (!canEnterSelectionMode) {
@@ -539,6 +533,79 @@ private void toggleSelectedClaim(Claim claim) {
539533
notifyDataSetChanged();
540534
}
541535

536+
public void showClaimPopupMenu(View view, Claim claim) {
537+
538+
Toast.makeText(context, "LONG CLICKED: " + claim.getTitle(), Toast.LENGTH_SHORT).show(); //Don't need, but it's nice to see it on the UI
539+
Log.d(TAG, "LONG CLICKED: " + claim.getTitle());
540+
541+
//do I need to do a check if context is null?
542+
PopupMenu popup = new PopupMenu(context, view);
543+
544+
popup.getMenuInflater().inflate(R.menu.menu_claim_popup, popup.getMenu());
545+
popup.setGravity(Gravity.END);
546+
547+
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
548+
public boolean onMenuItemClick(MenuItem item) {
549+
int i = item.getItemId();
550+
if (i == R.id.menu_claim_popup_share) {
551+
//share the claim
552+
Log.d(TAG, "Let's share: " + claim.getTitle());
553+
try{
554+
String shareUrl = LbryUri.parse(
555+
!Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() :
556+
(!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toTvString();
557+
558+
Intent shareIntent = new Intent();
559+
shareIntent.setAction(Intent.ACTION_SEND);
560+
shareIntent.setType("text/plain");
561+
shareIntent.putExtra(Intent.EXTRA_TEXT, shareUrl);
562+
563+
MainActivity.startingShareActivity = true;
564+
Intent shareUrlIntent = Intent.createChooser(shareIntent, context.getString(R.string.share_lbry_content));
565+
shareUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
566+
567+
context.startActivity(shareUrlIntent);
568+
Log.d(TAG, "Sharing: " + shareUrl);
569+
570+
} catch (LbryUriException lbryUriException){
571+
lbryUriException.printStackTrace();
572+
}
573+
return true;
574+
}
575+
else if (i == R.id.menu_claim_popup_support){
576+
//support the claim
577+
Log.d(TAG, "Let's support: " + claim.getTitle());
578+
579+
return true;
580+
}
581+
else if (i == R.id.menu_claim_popup_repost) {
582+
//repost the claim
583+
Log.d(TAG, "Let's repost: " + claim.getTitle());
584+
585+
return true;
586+
}
587+
else if (i == R.id.menu_claim_popup_download) {
588+
//download the claim
589+
Log.d(TAG, "Let's download: " + claim.getTitle());
590+
591+
return true;
592+
}
593+
else if (i == R.id.menu_claim_popup_report) {
594+
//report the claim
595+
Log.d(TAG, "Let's report: " + claim.getTitle());
596+
597+
return true;
598+
}
599+
else {
600+
return onMenuItemClick(item);
601+
}
602+
}
603+
});
604+
605+
popup.show();
606+
607+
}
608+
542609
public interface ClaimListItemListener {
543610
void onClaimClicked(Claim claim);
544611
}

app/src/main/res/values/styles.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<item name="windowActionModeOverlay">true</item>
1010
<item name="android:windowBackground">@color/colorPrimaryDark</item>
1111
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowStyle</item>
12+
<item name="popupMenuStyle">@style/ClaimPopupMenu</item>
1213
<!--item name="android:windowLightStatusBar">true</item-->
1314
</style>
1415

@@ -32,4 +33,9 @@
3233
<item name="color">@color/actionBarForeground</item>
3334
</style>
3435

36+
<style name="ClaimPopupMenu" parent="Widget.AppCompat.PopupMenu">
37+
<item name="android:dropDownHorizontalOffset">-8dp</item>
38+
<item name="android:dropDownVerticalOffset">8dp</item>
39+
</style>
40+
3541
</resources>

0 commit comments

Comments
 (0)