From f61eeb5eca52f16790c025c1008e05b52e062763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Fri, 4 Jan 2019 23:19:10 +0100 Subject: [PATCH] - Moved video metadata into fragment --- .../peertube/activity/VideoPlayActivity.java | 72 +--- .../fragment/VideoMetaDataFragment.java | 240 +++++++++++ .../peertube/network/GetVideoDataService.java | 12 + .../main/res/layout/activity_video_play.xml | 83 +--- .../main/res/layout/fragment_video_meta.xml | 375 ++++++++++++++++++ app/src/main/res/menu/menu_video_more.xml | 9 + app/src/main/res/values/strings.xml | 28 +- 7 files changed, 670 insertions(+), 149 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java create mode 100644 app/src/main/res/layout/fragment_video_meta.xml create mode 100644 app/src/main/res/menu/menu_video_more.xml diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index b747553..6fba30d 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -62,6 +62,7 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.mikepenz.iconics.Iconics; import com.squareup.picasso.Picasso; import net.schueller.peertube.R; +import net.schueller.peertube.fragment.VideoMetaDataFragment; import net.schueller.peertube.fragment.VideoOptionsFragment; import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.helper.MetaDataHelper; @@ -282,83 +283,22 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere // TODO: remove this code duplication, similar code as in video list rows - TextView videoName = findViewById(R.id.name); - TextView videoDescription = findViewById(R.id.description); - TextView videoOwner = findViewById(R.id.videoOwner); - TextView videoMeta = findViewById(R.id.videoMeta); - ImageView avatarView = findViewById(R.id.avatar); - TextView moreButton = findViewById(R.id.moreButton); - TextView videoOptions = findViewById(R.id.exo_more); - Video video = response.body(); mService.setCurrentVideo(video); - String baseUrl = APIUrlHelper.getUrl(context); - - if(video == null){ + if (video == null){ Toast.makeText(VideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); return; } - Account account = video.getAccount(); - if(account == null){ - Toast.makeText(VideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); - return; - } - Avatar avatar = account.getAvatar(); - if (avatar != null) { - String avatarPath = avatar.getPath(); - Picasso.with(context) - .load(baseUrl + avatarPath) - .into(avatarView); - } - videoName.setText(video.getName()); - videoMeta.setText( - MetaDataHelper.getMetaString( - video.getCreatedAt(), - video.getViews(), - getBaseContext() - ) - ); - videoOwner.setText( - MetaDataHelper.getOwnerString(video.getAccount().getName(), - video.getAccount().getHost(), - context - ) - ); - videoDescription.setText(video.getDescription()); + VideoMetaDataFragment videoMetaDataFragment = (VideoMetaDataFragment) + getSupportFragmentManager().findFragmentById(R.id.video_meta_data_fragment); - moreButton.setText(R.string.video_more_icon); - new Iconics.IconicsBuilder().ctx(context).on(moreButton).build(); + assert videoMetaDataFragment != null; + videoMetaDataFragment.updateVideoMeta(video, mService); - moreButton.setOnClickListener(v -> { - PopupMenu popup = new PopupMenu(context, v); - popup.setOnMenuItemClickListener(menuItem -> { - switch (menuItem.getItemId()) { - case R.id.menu_share: - Intents.Share(context, video); - return true; - default: - return false; - } - }); - popup.inflate(R.menu.menu_video_row_mode); - popup.show(); - }); - - // video player options - videoOptions.setText(R.string.video_more_icon); - new Iconics.IconicsBuilder().ctx(context).on(videoOptions).build(); - - videoOptions.setOnClickListener(v -> { - - VideoOptionsFragment videoOptionsFragment = - VideoOptionsFragment.newInstance(mService); - videoOptionsFragment.show(getSupportFragmentManager(), - "video_options_fragment"); - }); Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java new file mode 100644 index 0000000..6184bcd --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -0,0 +1,240 @@ +package net.schueller.peertube.fragment; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.util.ArrayMap; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.mikepenz.fontawesome_typeface_library.FontAwesome; +import com.mikepenz.iconics.Iconics; +import com.mikepenz.iconics.IconicsDrawable; +import com.squareup.picasso.Picasso; + +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.Account; +import net.schueller.peertube.model.Avatar; +import net.schueller.peertube.model.Video; +import net.schueller.peertube.network.GetVideoDataService; +import net.schueller.peertube.network.RetrofitInstance; +import net.schueller.peertube.network.Session; +import net.schueller.peertube.service.VideoPlayerService; + +import org.json.JSONObject; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.PopupMenu; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class VideoMetaDataFragment extends Fragment { + + private static final String TAG = "VideoMetaDataFragment"; + + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_video_meta, container, false); + } + + public void updateVideoMeta(Video video, VideoPlayerService mService) { + + Context context = getContext(); + Activity activity = getActivity(); + + + // Thumbs up + Button thumbsUpButton = activity.findViewById(R.id.video_thumbs_up); + thumbsUpButton.setText(R.string.video_thumbs_up_icon); + new Iconics.IconicsBuilder().ctx(context).on(thumbsUpButton).build(); + thumbsUpButton.setOnClickListener(v -> { + + if (Session.getInstance().isLoggedIn()) { + + RequestBody body = RequestBody.create( + okhttp3.MediaType.parse("application/json; charset=utf-8"), + "{rating: \"none\"}" + ); + + String apiBaseURL = APIUrlHelper.getUrlWithVersion(context); + GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetVideoDataService.class); + + Call call = service.rateVideo(video.getId(), body); + + call.enqueue(new Callback() { + + @Override + public void onResponse(Call call, Response response) { + + Log.v(TAG, response.toString() ); + + } + + @Override + public void onFailure(Call call, Throwable t) { + Toast.makeText(context, "Rating Failed", Toast.LENGTH_SHORT).show(); + } + }); + } else { + Toast.makeText(context, "You must login to use this service", Toast.LENGTH_SHORT).show(); + + } + + }); + + TextView thumbsUpButtonTotal = activity.findViewById(R.id.video_thumbs_up_total); + thumbsUpButtonTotal.setText(video.getLikes().toString()); + + // Thumbs Down + TextView thumbsDownButton = activity.findViewById(R.id.video_thumbs_down); + thumbsDownButton.setText(R.string.video_thumbs_down_icon); + new Iconics.IconicsBuilder().ctx(context).on(thumbsDownButton).build(); + thumbsDownButton.setOnClickListener(v -> Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show()); + + TextView thumbsDownButtonTotal = activity.findViewById(R.id.video_thumbs_down_total); + thumbsDownButtonTotal.setText(video.getDislikes().toString()); + + // Share + TextView videoShareButton = activity.findViewById(R.id.video_share); + videoShareButton.setText(R.string.video_share_icon); + new Iconics.IconicsBuilder().ctx(context).on(videoShareButton).build(); + videoShareButton.setOnClickListener(v -> Intents.Share(context, video)); + + // Download + TextView videoDownloadButton = activity.findViewById(R.id.video_download); + videoDownloadButton.setText(R.string.video_download_icon); + new Iconics.IconicsBuilder().ctx(context).on(videoDownloadButton).build(); + videoDownloadButton.setOnClickListener(v -> Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show()); + + // add to playlist + TextView videoSaveButton = activity.findViewById(R.id.video_save); + videoSaveButton.setText(R.string.video_save_icon); + new Iconics.IconicsBuilder().ctx(context).on(videoSaveButton).build(); + videoSaveButton.setOnClickListener(v -> Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show()); + + + Account account = video.getAccount(); + + // owner / creator Avatar + Avatar avatar = account.getAvatar(); + if (avatar != null) { + ImageView avatarView = activity.findViewById(R.id.avatar); + String baseUrl = APIUrlHelper.getUrl(context); + String avatarPath = avatar.getPath(); + Picasso.with(context) + .load(baseUrl + avatarPath) + .into(avatarView); + } + + + // title / name + TextView videoName = activity.findViewById(R.id.name); + videoName.setText(video.getName()); + + // created at / views + TextView videoMeta = activity.findViewById(R.id.videoMeta); + videoMeta.setText( + MetaDataHelper.getMetaString( + video.getCreatedAt(), + video.getViews(), + context + ) + ); + + // owner / creator + TextView videoOwner = activity.findViewById(R.id.videoOwner); + videoOwner.setText( + MetaDataHelper.getOwnerString(video.getAccount().getName(), + video.getAccount().getHost(), + context + ) + ); + + // description + TextView videoDescription = activity.findViewById(R.id.description); + videoDescription.setText(video.getDescription()); + + + // video privacy + TextView videoPrivacy = activity.findViewById(R.id.video_privacy); + videoPrivacy.setText(video.getPrivacy().getLabel()); + + // video category + TextView videoCategory = activity.findViewById(R.id.video_category); + videoCategory.setText(video.getCategory().getLabel()); + + // video privacy + TextView videoLicense = activity.findViewById(R.id.video_license); + videoLicense.setText(video.getLicence().getLabel()); + + // video langauge + TextView videoLanguage = activity.findViewById(R.id.video_language); + videoLanguage.setText(video.getLanguage().getLabel()); + + // video privacy + TextView videoTags = activity.findViewById(R.id.video_tags); + videoTags.setText(android.text.TextUtils.join(", ", video.getTags())); + + + // more button + TextView moreButton = activity.findViewById(R.id.moreButton); + moreButton.setText(R.string.video_more_icon); + new Iconics.IconicsBuilder().ctx(context).on(moreButton).build(); + + moreButton.setOnClickListener(v -> { + PopupMenu popup = new PopupMenu(context, v); + popup.setOnMenuItemClickListener(menuItem -> { + switch (menuItem.getItemId()) { + case R.id.video_more_report: + Log.v(TAG, "Report" ); + Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show(); + return true; + case R.id.video_more_blacklist: + Log.v(TAG, "Blacklist" ); + Toast.makeText(context, "Not Implemented", Toast.LENGTH_SHORT).show(); + return true; + default: + return false; + } + }); + popup.inflate(R.menu.menu_video_more); + popup.show(); + }); + + // video player options + TextView videoOptions = activity.findViewById(R.id.exo_more); + videoOptions.setText(R.string.video_more_icon); + new Iconics.IconicsBuilder().ctx(context).on(videoOptions).build(); + + videoOptions.setOnClickListener(v -> { + + VideoOptionsFragment videoOptionsFragment = + VideoOptionsFragment.newInstance(mService); + videoOptionsFragment.show(getActivity().getSupportFragmentManager(), + "video_options_fragment"); + }); + + } + +} diff --git a/app/src/main/java/net/schueller/peertube/network/GetVideoDataService.java b/app/src/main/java/net/schueller/peertube/network/GetVideoDataService.java index 2159070..e88afbc 100644 --- a/app/src/main/java/net/schueller/peertube/network/GetVideoDataService.java +++ b/app/src/main/java/net/schueller/peertube/network/GetVideoDataService.java @@ -22,8 +22,13 @@ import net.schueller.peertube.model.VideoList; import java.util.Set; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.Field; import retrofit2.http.GET; +import retrofit2.http.PUT; import retrofit2.http.Path; import retrofit2.http.Query; @@ -53,4 +58,11 @@ public interface GetVideoDataService { @Query("filter") String filter, @Query("languageOneOf") Set languages ); + + @PUT("videos/{id}/rate") + Call rateVideo( + @Path(value = "id", encoded = true) Integer id, + @Body RequestBody params + ); + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_video_play.xml b/app/src/main/res/layout/activity_video_play.xml index 2a2d293..efd7e37 100644 --- a/app/src/main/res/layout/activity_video_play.xml +++ b/app/src/main/res/layout/activity_video_play.xml @@ -18,8 +18,8 @@ android:layout_width="match_parent" android:layout_height="250dp" android:background="@color/videoBackgroundColor" - app:resize_mode="fixed_width" app:controller_layout_id="@layout/video_playback_controls" + app:resize_mode="fixed_width" /> @@ -32,89 +32,26 @@ android:indeterminate="false" android:max="100" /> + - - - - - - - - - - - + android:layout_height="match_parent"> + + - diff --git a/app/src/main/res/layout/fragment_video_meta.xml b/app/src/main/res/layout/fragment_video_meta.xml new file mode 100644 index 0000000..6032ba7 --- /dev/null +++ b/app/src/main/res/layout/fragment_video_meta.xml @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + + + + + + +