Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I've added a menu to share when long-pressing a video #1222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.widget.PopupMenu;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
Expand All @@ -21,7 +27,9 @@
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;
import io.lbry.browser.model.Claim;
import io.lbry.browser.model.LbryFile;
Expand All @@ -32,6 +40,7 @@
import lombok.Setter;

public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.ViewHolder> {
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
Expand Down Expand Up @@ -369,6 +378,11 @@ public void onClick(View view) {
vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {

if (original != null) {
showClaimPopupMenu(view, original);
}

if (!canEnterSelectionMode) {
return false;
}
Expand Down Expand Up @@ -519,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);
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/menu/menu_claim_popup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/menu_claim_popup_share"
android:title="@string/share" />

<item android:id="@+id/menu_claim_popup_support"
android:title="@string/support" />

<item android:id="@+id/menu_claim_popup_repost"
android:title="@string/repost" />

<item android:id="@+id/menu_claim_popup_download"
android:title="@string/download" />

<item android:id="@+id/menu_claim_popup_report"
android:title="@string/report" />
</menu>
6 changes: 6 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<item name="windowActionModeOverlay">true</item>
<item name="android:windowBackground">@color/colorPrimaryDark</item>
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowStyle</item>
<item name="popupMenuStyle">@style/ClaimPopupMenu</item>
<!--item name="android:windowLightStatusBar">true</item-->
</style>

Expand All @@ -32,4 +33,9 @@
<item name="color">@color/actionBarForeground</item>
</style>

<style name="ClaimPopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:dropDownHorizontalOffset">-8dp</item>
<item name="android:dropDownVerticalOffset">8dp</item>
</style>

</resources>