mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-25 13:08:58 +00:00
Posts movies are supported.
This commit is contained in:
parent
9c39112bf7
commit
d8837aa016
@ -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;
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Post>{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//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);
|
||||
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
@ -78,6 +78,13 @@
|
||||
android:contentDescription="@string/post_image_description"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<!-- Post related movie (if any) -->
|
||||
<org.communiquons.android.comunic.client.ui.views.MovieView
|
||||
android:id="@+id/post_movie"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
style="@style/PostMovie"/>
|
||||
|
||||
<!-- Related PDF (if any) -->
|
||||
<org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView
|
||||
android:id="@+id/btn_pdf_link"
|
||||
|
12
app/src/main/res/layout/view_movie.xml
Normal file
12
app/src/main/res/layout/view_movie.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/video"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
</LinearLayout>
|
@ -82,6 +82,12 @@
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<!-- Post Movie (when required) -->
|
||||
<style name="PostMovie">
|
||||
<item name="android:visibility">gone</item>
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
</style>
|
||||
|
||||
<!-- Post PDF button (when required) -->
|
||||
<style name="PostPDFButton">
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
|
Loading…
Reference in New Issue
Block a user