diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/MoviesHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/MoviesHelper.java new file mode 100644 index 0000000..f0c4900 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/MoviesHelper.java @@ -0,0 +1,44 @@ +package org.communiquons.android.comunic.client.data.helpers; + +import android.content.Context; +import android.support.annotation.NonNull; + +import org.communiquons.android.comunic.client.data.models.Movie; +import org.json.JSONException; +import org.json.JSONObject; + + +/** + * Movies helper + * + * @author Pierre HUBERT + */ + +public class MoviesHelper extends BaseHelper { + + MoviesHelper(Context context) { + super(context); + } + + /** + * Parse a JSON object into a movie object + * + * @param object The object to parse + * @return Parsed movie object + * @throws JSONException If JSON object could not be correctly read + */ + Movie parse_json_object(@NonNull JSONObject object) throws JSONException { + + Movie movie = new Movie(); + + movie.setId(object.getInt("id")); + movie.setUrl(object.getString("url")); + movie.setUserID(object.getInt("userID")); + movie.setName(object.getString("name")); + movie.setFileType(object.getString("file_type")); + movie.setSize(object.getInt("size")); + + return movie; + + } +} 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 31bd23b..20cb86f 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 @@ -380,6 +380,11 @@ public class PostsHelper { post.setFile_path_url(json.getString("file_path_url")); } + //Get information about movie (if any) + if(!json.isNull("video_info")) + post.setMovie(new MoviesHelper(mContext) + .parse_json_object(json.getJSONObject("video_info"))); + return post; } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/Movie.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/Movie.java new file mode 100644 index 0000000..e960faf --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/Movie.java @@ -0,0 +1,65 @@ +package org.communiquons.android.comunic.client.data.models; + +/** + * Movie model + * + * @author Pierre HUBERT + */ +public class Movie { + + //Private properties + private int id; + private String url; + private int userID; + private String name; + private String fileType; + private int size; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getUserID() { + return userID; + } + + public void setUserID(int userID) { + this.userID = userID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } +} 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 74b7d8c..ae4cf35 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 @@ -43,6 +43,9 @@ public class Post { //Files specific private String file_path_url; + //Movie + private Movie movie; + //Set and get the ID of the post public void setId(int id) { @@ -194,5 +197,19 @@ public class Post { public String getFile_path_url() { return file_path_url; } + + + //Set and get movie information + public Movie getMovie() { + return movie; + } + + public boolean hasMovie(){ + return movie != null; + } + + public void setMovie(Movie movie) { + this.movie = movie; + } } 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 e9a4bf4..a8edcee 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 @@ -4,6 +4,7 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.ArrayMap; +import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -26,6 +27,7 @@ import org.communiquons.android.comunic.client.ui.utils.UiUtils; import org.communiquons.android.comunic.client.data.utils.Utilities; import org.communiquons.android.comunic.client.ui.views.EditCommentContentView; import org.communiquons.android.comunic.client.ui.views.LikeButtonView; +import org.communiquons.android.comunic.client.ui.views.MovieView; import org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView; import org.communiquons.android.comunic.client.ui.views.WebImageView; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; @@ -176,6 +178,20 @@ public class PostsAdapter extends ArrayAdapter{ } + + //Set post movie (if any) + MovieView movieView = convertView.findViewById(R.id.post_movie); + + if(post.getType() == PostTypes.MOVIE){ + movieView.setVisibility(View.VISIBLE); + movieView.setMovie(post.getMovie()); + } + + else { + movieView.setVisibility(View.GONE); + } + + //Set post file PDF (if any) PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/MovieView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/MovieView.java new file mode 100644 index 0000000..c15a469 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/MovieView.java @@ -0,0 +1,83 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.MediaController; +import android.widget.VideoView; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.models.Movie; + +/** + * Movie view + * + * This view is used to display a movie + * + * @author Pierre HUBERT + */ +public class MovieView extends FrameLayout { + + /** + * Current movie in view + */ + private Movie mMovie; + + /** + * VideoView that contains the video + */ + private VideoView mVideoView; + + /** + * Related media controller + */ + private MediaController mMediaController; + + public MovieView(@NonNull Context context) { + super(context); + init(); + } + + public MovieView(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(); + } + + public MovieView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public MovieView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + + private void init(){ + + View view = inflate(getContext(), R.layout.view_movie, null); + addView(view); + + mVideoView = view.findViewById(R.id.video); + mMediaController = new MediaController(getContext()); + mMediaController.setAnchorView(mVideoView); + mMediaController.setMediaPlayer(mVideoView); + mVideoView.setMediaController(mMediaController); + } + + /** + * Set (apply) a new movie in the view + * + * @param movie The movie to apply + */ + public void setMovie(@NonNull Movie movie) { + this.mMovie = movie; + + mVideoView.setVideoURI(Uri.parse(mMovie.getUrl())); + } +} diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index ee1784b..e6397c3 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -78,6 +78,13 @@ android:contentDescription="@string/post_image_description" android:scaleType="centerInside" /> + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a020925..9c6b6a5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -82,6 +82,12 @@ center_vertical + + +