|
1 | 1 | package io.lbry.browser.adapter; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import android.content.Intent; |
4 | 5 | import android.text.format.DateUtils; |
5 | 6 | import android.util.Log; |
| 7 | +import android.view.Gravity; |
6 | 8 | import android.view.LayoutInflater; |
| 9 | +import android.view.MenuItem; |
7 | 10 | import android.view.View; |
8 | 11 | import android.view.ViewGroup; |
9 | 12 | import android.widget.ImageView; |
10 | 13 | import android.widget.ProgressBar; |
11 | 14 | import android.widget.TextView; |
12 | 15 | import android.widget.Toast; |
13 | 16 |
|
| 17 | +import androidx.appcompat.widget.PopupMenu; |
14 | 18 | import androidx.recyclerview.widget.RecyclerView; |
15 | 19 |
|
16 | 20 | import com.bumptech.glide.Glide; |
|
23 | 27 | import java.util.List; |
24 | 28 | import java.util.Map; |
25 | 29 |
|
| 30 | +import io.lbry.browser.MainActivity; |
26 | 31 | import io.lbry.browser.R; |
27 | 32 | import io.lbry.browser.exceptions.LbryUriException; |
28 | 33 | import io.lbry.browser.listener.SelectionModeListener; |
@@ -374,19 +379,8 @@ public void onClick(View view) { |
374 | 379 | @Override |
375 | 380 | public boolean onLongClick(View view) { |
376 | 381 |
|
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); |
390 | 384 | } |
391 | 385 |
|
392 | 386 | if (!canEnterSelectionMode) { |
@@ -539,6 +533,79 @@ private void toggleSelectedClaim(Claim claim) { |
539 | 533 | notifyDataSetChanged(); |
540 | 534 | } |
541 | 535 |
|
| 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 | + |
542 | 609 | public interface ClaimListItemListener { |
543 | 610 | void onClaimClicked(Claim claim); |
544 | 611 | } |
|
0 commit comments