Added support for YouTube videos

This commit is contained in:
Pierre HUBERT 2019-03-02 12:26:29 +01:00
parent e5f1b8092d
commit fc88894f45
11 changed files with 191 additions and 26 deletions

View File

@ -44,6 +44,11 @@ public enum PostTypes {
*/ */
SURVEY, SURVEY,
/**
* YouTube video
*/
YOUTUBE,
/** /**
* Unknown type * Unknown type
*/ */

View File

@ -436,6 +436,11 @@ public class PostsHelper {
post.setNumberLike(json.getInt("likes")); post.setNumberLike(json.getInt("likes"));
post.setLiking(json.getBoolean("userlike")); 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) //Get file path url (if any)
if(json.getString("file_path_url") != null){ if(json.getString("file_path_url") != null){
post.setFile_path_url(json.getString("file_path_url")); post.setFile_path_url(json.getString("file_path_url"));
@ -524,6 +529,9 @@ public class PostsHelper {
case "survey": case "survey":
return PostTypes.SURVEY; return PostTypes.SURVEY;
case "youtube":
return PostTypes.YOUTUBE;
default: default:
return PostTypes.UNKNOWN; return PostTypes.UNKNOWN;

View File

@ -41,6 +41,7 @@ public class Post {
private ArrayList<Comment> comments_list; private ArrayList<Comment> comments_list;
//Files specific //Files specific
private String file_path;
private String file_path_url; private String file_path_url;
//Movie //Movie
@ -198,6 +199,15 @@ public class Post {
return getUser_access_level() == PostUserAccess.FULL_ACCESS; 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 //Set and get file path url
public void setFile_path_url(String file_path_url) { public void setFile_path_url(String file_path_url) {
this.file_path_url = file_path_url; this.file_path_url = file_path_url;

View File

@ -7,6 +7,13 @@ package org.communiquons.android.comunic.client.ui;
*/ */
public final class Constants { public final class Constants {
/**
* YouTube videos prefix
*/
public static final String YOUTUBE_VIDEOS_URL_PREFIX = "https://youtube.com/watch?v=";
/** /**
* Intents request codes * Intents request codes
*/ */

View File

@ -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.SurveyView;
import org.communiquons.android.comunic.client.ui.views.WebLinkView; 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.WebUserAccountImage;
import org.communiquons.android.comunic.client.ui.views.YouTubeVideoView;
import java.util.ArrayList; 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_WEBLINK = 4;
private static final int VIEW_TYPE_POST_COUNTDOWN = 5; 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_SURVEY = 6;
private static final int VIEW_TYPE_POST_YOUTUBE = 7;
/** /**
* Posts list * Posts list
@ -129,6 +131,9 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
case SURVEY: case SURVEY:
return VIEW_TYPE_POST_SURVEY; return VIEW_TYPE_POST_SURVEY;
case YOUTUBE:
return VIEW_TYPE_POST_YOUTUBE;
case TEXT: case TEXT:
default: default:
return VIEW_TYPE_POST_TEXT; return VIEW_TYPE_POST_TEXT;
@ -158,6 +163,9 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
case VIEW_TYPE_POST_COUNTDOWN: case VIEW_TYPE_POST_COUNTDOWN:
return new CountdownPostHolder(view); return new CountdownPostHolder(view);
case VIEW_TYPE_POST_YOUTUBE:
return new YouTubePostHolder(view);
case VIEW_TYPE_POST_SURVEY: case VIEW_TYPE_POST_SURVEY:
return new SurveyPostHolder(view); return new SurveyPostHolder(view);
@ -307,12 +315,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
mPostVisibility.setImageDrawable(drawable); mPostVisibility.setImageDrawable(drawable);
//Set post actions //Set post actions
mPostActions.setOnClickListener(new View.OnClickListener() { mPostActions.setOnClickListener(
@Override v -> mListener.showPostActions(v, position, getPost(position)));
public void onClick(View v) {
mListener.showPostActions(v, position, getPost(position));
}
});
//Set post content //Set post content
@ -326,12 +330,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
//Post likes //Post likes
mLikeButton.setNumberLikes(post.getNumberLike()); mLikeButton.setNumberLikes(post.getNumberLike());
mLikeButton.setIsLiking(post.isLiking()); mLikeButton.setIsLiking(post.isLiking());
mLikeButton.setUpdateListener(new LikeButtonView.OnLikeUpdateListener() { mLikeButton.setUpdateListener(
@Override isLiking -> mListener.onPostLikeUpdate(getPost(position), isLiking));
public void OnLikeUpdate(boolean isLiking) {
mListener.onPostLikeUpdate(getPost(position), isLiking);
}
});
//Post comments //Post comments
@ -371,24 +371,16 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
mEditCommentContentView.setPostID(post.getId()); mEditCommentContentView.setPostID(post.getId());
mEditCommentContentView.setText(""); mEditCommentContentView.setText("");
mSendCommentButton.setOnClickListener(new View.OnClickListener() { mSendCommentButton.setOnClickListener(v -> sendComment());
@Override
public void onClick(View v) {
sendComment();
}
});
} }
mEditCommentContentView.setOnKeyListener(new View.OnKeyListener() { mEditCommentContentView.setOnKeyListener((v, keyCode, event) -> {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN if(event.getAction() == KeyEvent.ACTION_DOWN
&& keyCode == KeyEvent.KEYCODE_ENTER) && keyCode == KeyEvent.KEYCODE_ENTER)
sendComment(); sendComment();
return false; return false;
}
}); });
} }
} }
@ -549,4 +541,29 @@ public class PostsAdapter extends BaseRecyclerViewAdapter {
mSurveyView.setSurvey(getPost(position).getSurvey()); 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());
}
}
} }

View File

@ -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);
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,3v2h-2L16,3L8,3v2L6,5L6,3L4,3v18h2v-2h2v2h8v-2h2v2h2L20,3h-2zM8,17L6,17v-2h2v2zM8,13L6,13v-2h2v2zM8,9L6,9L6,7h2v2zM18,17h-2v-2h2v2zM18,13h-2v-2h2v2zM18,9h-2L16,7h2v2z"/>
</vector>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
style="@style/Widget.AppCompat.Button">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/youtube_movie"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_local_movies" />
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/youtube_movie"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

View File

@ -344,4 +344,5 @@
<string name="err_call_no_peer_connected">Cet appel n\'est relié à aucun pair !</string> <string name="err_call_no_peer_connected">Cet appel n\'est relié à aucun pair !</string>
<string name="err_can_not_create_record_file">Impossible de créer le fichier d\'enregistrement !</string> <string name="err_can_not_create_record_file">Impossible de créer le fichier d\'enregistrement !</string>
<string name="err_initialize_video_call_recording">Une erreur a survenue lors de l\'initialisation de l\'enregistrement vidéo !</string> <string name="err_initialize_video_call_recording">Une erreur a survenue lors de l\'initialisation de l\'enregistrement vidéo !</string>
<string name="youtube_movie">Vidéo YouTube</string>
</resources> </resources>

View File

@ -343,4 +343,5 @@
<string name="err_call_no_peer_connected">This call is not connected to any peer!</string> <string name="err_call_no_peer_connected">This call is not connected to any peer!</string>
<string name="err_can_not_create_record_file">Can not create record file!</string> <string name="err_can_not_create_record_file">Can not create record file!</string>
<string name="err_initialize_video_call_recording">Could not initialize video call recording!</string> <string name="err_initialize_video_call_recording">Could not initialize video call recording!</string>
<string name="youtube_movie">YouTube Movie</string>
</resources> </resources>

View File

@ -127,6 +127,11 @@
<item name="android:layout_gravity">center_horizontal</item> <item name="android:layout_gravity">center_horizontal</item>
</style> </style>
<!-- Post YouTube movie -->
<style name="PostYouTubeView">
<item name="android:layout_gravity">center_horizontal</item>
</style>
<!-- Post content --> <!-- Post content -->
<style name="PostContent"> <style name="PostContent">
<item name="android:textAlignment">center</item> <item name="android:textAlignment">center</item>