mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Added support for YouTube videos
This commit is contained in:
parent
e5f1b8092d
commit
fc88894f45
@ -44,6 +44,11 @@ public enum PostTypes {
|
||||
*/
|
||||
SURVEY,
|
||||
|
||||
/**
|
||||
* YouTube video
|
||||
*/
|
||||
YOUTUBE,
|
||||
|
||||
/**
|
||||
* Unknown type
|
||||
*/
|
||||
|
@ -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;
|
||||
|
||||
|
@ -41,6 +41,7 @@ public class Post {
|
||||
private ArrayList<Comment> 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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
9
app/src/main/res/drawable/ic_local_movies.xml
Normal file
9
app/src/main/res/drawable/ic_local_movies.xml
Normal 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>
|
35
app/src/main/res/layout/view_youtube_video.xml
Normal file
35
app/src/main/res/layout/view_youtube_video.xml
Normal 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>
|
@ -344,4 +344,5 @@
|
||||
<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_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>
|
@ -343,4 +343,5 @@
|
||||
<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_initialize_video_call_recording">Could not initialize video call recording!</string>
|
||||
<string name="youtube_movie">YouTube Movie</string>
|
||||
</resources>
|
||||
|
@ -127,6 +127,11 @@
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
</style>
|
||||
|
||||
<!-- Post YouTube movie -->
|
||||
<style name="PostYouTubeView">
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
</style>
|
||||
|
||||
<!-- Post content -->
|
||||
<style name="PostContent">
|
||||
<item name="android:textAlignment">center</item>
|
||||
|
Loading…
Reference in New Issue
Block a user