- Share ability

This commit is contained in:
Stefan Schueller 2018-12-15 14:24:11 +01:00
parent 82c1d19abd
commit 6a50094fda
7 changed files with 107 additions and 17 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "net.schueller.peertube"
minSdkVersion 23
targetSdkVersion 28
versionCode 105
versionName "1.0.5"
versionCode 106
versionName "1.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -3,10 +3,12 @@ package net.schueller.peertube.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
@ -16,6 +18,7 @@ import net.schueller.peertube.R;
import net.schueller.peertube.activity.VideoPlayActivity;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.helper.MetaDataHelper;
import net.schueller.peertube.intents.Intents;
import net.schueller.peertube.model.Avatar;
import net.schueller.peertube.model.Video;
@ -91,6 +94,23 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
});
holder.moreButton.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, v);
popup.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.menu_share:
Intents.Share(context, videoList.get(position));
return true;
default:
return false;
}
});
popup.inflate(R.menu.menu_video_row_mode);
popup.show();
});
}
public void setData(ArrayList<Video> data) {
@ -112,6 +132,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
TextView name, videoMeta, videoOwner;
ImageView thumb, avatar;
ImageButton moreButton;
View mView;
VideoViewHolder(View itemView) {
@ -121,6 +142,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
avatar = itemView.findViewById(R.id.avatar);
videoMeta = itemView.findViewById(R.id.videoMeta);
videoOwner = itemView.findViewById(R.id.videoOwner);
moreButton = itemView.findViewById(R.id.moreButton);
mView = itemView;
}
}

View File

@ -23,4 +23,8 @@ public class APIUrlHelper{
public static String getUrlWithVersion(Context context) {
return APIUrlHelper.getUrl(context) + "/api/v1/";
}
public static String getShareUrl(Context context, String videoUuid) {
return APIUrlHelper.getUrl(context) + "/videos/watch/" + videoUuid;
}
}

View File

@ -0,0 +1,29 @@
package net.schueller.peertube.intents;
import android.content.Context;
import android.content.Intent;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.Video;
public class Intents {
/**
* https://troll.tv/videos/watch/6edbd9d1-e3c5-4a6c-8491-646e2020469c
*
* @param context context
* @param video video
*/
public static void Share(Context context, Video video) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, video.getName());
intent.putExtra(Intent.EXTRA_TEXT, APIUrlHelper.getShareUrl(context, video.getUuid()) );
intent.setType("text/plain");
context.startActivity(intent);
}
}

View File

@ -19,38 +19,45 @@
android:id="@+id/thumb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxHeight="300dp"
android:contentDescription="@string/video_row_video_thumbnail"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
android:contentDescription="@string/video_row_video_thumbnail"
android:maxHeight="300dp"
android:scaleType="fitXY" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/avatar"
android:layout_width="60dp"
android:layout_height="60dp"
android:paddingTop="12dp"
android:paddingEnd="12dp"
android:layout_below="@+id/thumb"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:contentDescription="@string/video_row_account_avatar"
android:layout_below="@id/thumb"
android:layout_alignParentStart="true"/>
android:paddingStart="12dp"
android:paddingTop="12dp"
android:paddingEnd="12dp" />
<TextView
android:id="@+id/name"
android:paddingTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/thumb"
android:layout_toEndOf="@id/avatar"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_toEndOf="@+id/avatar"
android:layout_marginEnd="12dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:id="@+id/videoMeta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_toEndOf="@id/avatar"
android:layout_below="@+id/name"
android:layout_marginStart="12dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/avatar"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" />
<TextView
@ -58,8 +65,27 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/videoMeta"
android:layout_marginStart="12dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_toEndOf="@id/avatar"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" />
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
/>
<ImageButton
android:id="@+id/moreButton"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_below="@+id/thumb"
android:layout_marginStart="-16dp"
android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/name"
android:background="@null"
android:contentDescription="@string/descr_overflow_button"
android:src="@drawable/ic_action_more_vert" />
</RelativeLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_share"
android:icon="@drawable/ic_action_share"
android:title="@string/menu_share" />
</menu>

View File

@ -56,5 +56,7 @@
<string name="search_hint">Search PeerTube</string>
<string name="title_activity_search">Search</string>
<string name="no_data_available">No Results</string>
<string name="descr_overflow_button">More</string>
<string name="menu_share">Share</string>
</resources>