diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/PostTypes.java b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/PostTypes.java index 79e4d81..4df704e 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/enums/PostTypes.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/enums/PostTypes.java @@ -44,6 +44,11 @@ public enum PostTypes { */ SURVEY, + /** + * YouTube video + */ + YOUTUBE, + /** * Unknown type */ diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java index 1cd8e27..826ad0b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java @@ -436,6 +436,11 @@ public class PostsHelper { post.setNumberLike(json.getInt("likes")); post.setLiking(json.getBoolean("userlike")); + + //Get file path (if any) + if(json.getString("file_path") != null) + post.setFilePath(json.getString("file_path")); + //Get file path url (if any) if(json.getString("file_path_url") != null){ post.setFile_path_url(json.getString("file_path_url")); @@ -524,6 +529,9 @@ public class PostsHelper { case "survey": return PostTypes.SURVEY; + case "youtube": + return PostTypes.YOUTUBE; + default: return PostTypes.UNKNOWN; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/Post.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/Post.java index c88b924..a32dabd 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/models/Post.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/Post.java @@ -41,6 +41,7 @@ public class Post { private ArrayList comments_list; //Files specific + private String file_path; private String file_path_url; //Movie @@ -198,6 +199,15 @@ public class Post { return getUser_access_level() == PostUserAccess.FULL_ACCESS; } + //Get and set file path + public String getFilePath() { + return file_path; + } + + public void setFilePath(String file_path) { + this.file_path = file_path; + } + //Set and get file path url public void setFile_path_url(String file_path_url) { this.file_path_url = file_path_url; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java index e28ad97..a853001 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/Constants.java @@ -7,6 +7,13 @@ package org.communiquons.android.comunic.client.ui; */ public final class Constants { + + /** + * YouTube videos prefix + */ + public static final String YOUTUBE_VIDEOS_URL_PREFIX = "https://youtube.com/watch?v="; + + /** * Intents request codes */ diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java index 259fb5c..993fe55 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java @@ -34,6 +34,7 @@ import org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView; import org.communiquons.android.comunic.client.ui.views.SurveyView; import org.communiquons.android.comunic.client.ui.views.WebLinkView; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; +import org.communiquons.android.comunic.client.ui.views.YouTubeVideoView; import java.util.ArrayList; @@ -61,6 +62,7 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { private static final int VIEW_TYPE_POST_WEBLINK = 4; private static final int VIEW_TYPE_POST_COUNTDOWN = 5; private static final int VIEW_TYPE_POST_SURVEY = 6; + private static final int VIEW_TYPE_POST_YOUTUBE = 7; /** * Posts list @@ -129,6 +131,9 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { case SURVEY: return VIEW_TYPE_POST_SURVEY; + case YOUTUBE: + return VIEW_TYPE_POST_YOUTUBE; + case TEXT: default: return VIEW_TYPE_POST_TEXT; @@ -158,6 +163,9 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { case VIEW_TYPE_POST_COUNTDOWN: return new CountdownPostHolder(view); + case VIEW_TYPE_POST_YOUTUBE: + return new YouTubePostHolder(view); + case VIEW_TYPE_POST_SURVEY: return new SurveyPostHolder(view); @@ -307,12 +315,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mPostVisibility.setImageDrawable(drawable); //Set post actions - mPostActions.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mListener.showPostActions(v, position, getPost(position)); - } - }); + mPostActions.setOnClickListener( + v -> mListener.showPostActions(v, position, getPost(position))); //Set post content @@ -326,12 +330,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { //Post likes mLikeButton.setNumberLikes(post.getNumberLike()); mLikeButton.setIsLiking(post.isLiking()); - mLikeButton.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() { - @Override - public void OnLikeUpdate(boolean isLiking) { - mListener.onPostLikeUpdate(getPost(position), isLiking); - } - }); + mLikeButton.setUpdateListener( + isLiking -> mListener.onPostLikeUpdate(getPost(position), isLiking)); //Post comments @@ -371,24 +371,16 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mEditCommentContentView.setPostID(post.getId()); mEditCommentContentView.setText(""); - mSendCommentButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - sendComment(); - } - }); + mSendCommentButton.setOnClickListener(v -> sendComment()); } - mEditCommentContentView.setOnKeyListener(new View.OnKeyListener() { - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - if(event.getAction() == KeyEvent.ACTION_DOWN - && keyCode == KeyEvent.KEYCODE_ENTER) - sendComment(); + mEditCommentContentView.setOnKeyListener((v, keyCode, event) -> { + if(event.getAction() == KeyEvent.ACTION_DOWN + && keyCode == KeyEvent.KEYCODE_ENTER) + sendComment(); - return false; - } + return false; }); } } @@ -549,4 +541,29 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mSurveyView.setSurvey(getPost(position).getSurvey()); } } + + /** + * YouTube video post holder + */ + private class YouTubePostHolder extends TextPostHolder { + + private YouTubeVideoView mYouTubeVideoView; + + YouTubePostHolder(@NonNull View itemView) { + super(itemView); + + mYouTubeVideoView = new YouTubeVideoView(getContext(), null, R.style.PostYouTubeView); + getAdditionalViewsLayout().addView(mYouTubeVideoView, + new LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + } + + @Override + void bind(int position) { + super.bind(position); + + mYouTubeVideoView.setVideoID(getPost(position).getFilePath()); + } + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/YouTubeVideoView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/YouTubeVideoView.java new file mode 100644 index 0000000..ae9446a --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/YouTubeVideoView.java @@ -0,0 +1,67 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; + +import org.communiquons.android.comunic.client.R; + +import static org.communiquons.android.comunic.client.ui.Constants.YOUTUBE_VIDEOS_URL_PREFIX; + +/** + * YouTube video view + * + * @author Pierre HUBERT + */ +public class YouTubeVideoView extends BaseFrameLayoutView implements View.OnClickListener { + + /** + * YouTube video ID + */ + private String mVideoID; + + public YouTubeVideoView(@NonNull Context context) { + this(context, null); + } + + public YouTubeVideoView(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public YouTubeVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public YouTubeVideoView(@NonNull Context context, @Nullable AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + + super(context, attrs, defStyleAttr, defStyleRes); + + View v = LayoutInflater.from(getContext()).inflate(R.layout.view_youtube_video, this, false); + addView(v); + + v.setOnClickListener(this); + } + + public void setVideoID(String youTubeID) { + this.mVideoID = youTubeID; + } + + public String getVideoID() { + return mVideoID; + } + + @Override + public void onClick(View v) { + + //Open the video + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(YOUTUBE_VIDEOS_URL_PREFIX + getVideoID())); + getContext().startActivity(intent); + + } +} diff --git a/app/src/main/res/drawable/ic_local_movies.xml b/app/src/main/res/drawable/ic_local_movies.xml new file mode 100644 index 0000000..c2c2403 --- /dev/null +++ b/app/src/main/res/drawable/ic_local_movies.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/view_youtube_video.xml b/app/src/main/res/layout/view_youtube_video.xml new file mode 100644 index 0000000..1a57f69 --- /dev/null +++ b/app/src/main/res/layout/view_youtube_video.xml @@ -0,0 +1,35 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e327413..8ae3bab 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -344,4 +344,5 @@ Cet appel n\'est relié à aucun pair ! Impossible de créer le fichier d\'enregistrement ! Une erreur a survenue lors de l\'initialisation de l\'enregistrement vidéo ! + Vidéo YouTube \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c20c141..225c58b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -343,4 +343,5 @@ This call is not connected to any peer! Can not create record file! Could not initialize video call recording! + YouTube Movie diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 93d34fa..983f61c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -127,6 +127,11 @@ center_horizontal + + +