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 b1d5841..c3a3565 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 @@ -24,6 +24,11 @@ public enum PostTypes { */ MOVIE, + /** + * Web link + */ + WEBLINK, + /** * PDF */ 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 20cb86f..f4f1e48 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 @@ -15,6 +15,7 @@ import org.communiquons.android.comunic.client.data.enums.PostTypes; import org.communiquons.android.comunic.client.data.enums.PostUserAccess; import org.communiquons.android.comunic.client.data.enums.PostVisibilityLevels; import org.communiquons.android.comunic.client.data.arrays.PostsList; +import org.communiquons.android.comunic.client.data.models.WebLink; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -329,28 +330,7 @@ public class PostsHelper { post.setVisibilityLevel(api_to_visibility_levels(json.getString("visibility_level"))); //Determine the type of the post - switch (json.getString("kind")){ - - case "text": - post.setType(PostTypes.TEXT); - break; - - case "image": - post.setType(PostTypes.IMAGE); - break; - - case "movie": - post.setType(PostTypes.MOVIE); - break; - - case "pdf": - post.setType(PostTypes.PDF); - break; - - default: - post.setType(PostTypes.UNKNOWN); - - } + post.setType(api_to_post_types(json.getString("kind"))); //Determine the user access level to the post switch (json.getString("user_access")){ @@ -385,6 +365,16 @@ public class PostsHelper { post.setMovie(new MoviesHelper(mContext) .parse_json_object(json.getJSONObject("video_info"))); + //Get information about web link (if any) + if(post.getType() == PostTypes.WEBLINK){ + WebLink webLink = new WebLink(); + webLink.setUrl(json.getString("link_url")); + webLink.setTitle(json.getString("link_title")); + webLink.setDescription(json.getString("link_description")); + webLink.setImageURL(json.getString("link_image")); + post.setWebLink(webLink); + } + return post; } @@ -415,6 +405,37 @@ public class PostsHelper { } } + /** + * Turn API post kind to PostTypes + * + * @param kind The kind to match + */ + private PostTypes api_to_post_types(String kind){ + + switch (kind){ + + case "text": + return PostTypes.TEXT; + + case "image": + return PostTypes.IMAGE; + + case "movie": + return PostTypes.MOVIE; + + case "weblink": + return PostTypes.WEBLINK; + + case "pdf": + return PostTypes.PDF; + + default: + return PostTypes.UNKNOWN; + + } + + } + /** * Turn a POST visibility level into a string ready for the API * 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 ae4cf35..ed90753 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 @@ -46,6 +46,9 @@ public class Post { //Movie private Movie movie; + //Web link + private WebLink webLink; + //Set and get the ID of the post public void setId(int id) { @@ -211,5 +214,19 @@ public class Post { public void setMovie(Movie movie) { this.movie = movie; } + + + //Set and get web link information + public WebLink getWebLink() { + return webLink; + } + + public boolean hasWebLink() { + return webLink != null; + } + + public void setWebLink(WebLink webLink) { + this.webLink = webLink; + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/WebLink.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/WebLink.java new file mode 100644 index 0000000..a5b37fd --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/WebLink.java @@ -0,0 +1,71 @@ +package org.communiquons.android.comunic.client.data.models; + +/** + * Weblink model + * + * @author Pierre HUBERT + */ +public class WebLink { + + //Private fields + private String url; + private String title; + private String description; + private String imageURL; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getTitle() { + return title; + } + + public boolean hasTitle() { + return title != null; + } + + public void setTitle(String title) { + this.title = title; + + if(title != null) + if(title.equals("null")) + this.title = null; + } + + public String getDescription() { + return description; + } + + public boolean hasDescription() { + return description != null; + } + + public void setDescription(String description) { + this.description = description; + + if(description != null) + if(description.equals("null")) + this.description = null; + } + + public String getImageURL() { + return imageURL; + } + + public boolean hasImageURL(){ + return imageURL != null; + } + + public void setImageURL(String imageURL) { + this.imageURL = imageURL; + + if(imageURL != null) + if(imageURL.equals("null")) + this.imageURL = null; + } +} 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 a8edcee..9332be2 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 @@ -30,6 +30,7 @@ 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.WebLinkView; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; import java.util.ArrayList; @@ -192,6 +193,18 @@ public class PostsAdapter extends ArrayAdapter{ } + //Set post weblink (if any) + WebLinkView webLinkView = convertView.findViewById(R.id.post_web_link); + + if(post.hasWebLink()){ + webLinkView.setVisibility(View.VISIBLE); + webLinkView.setLink(post.getWebLink()); + } + else { + webLinkView.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/WebImageView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java index 05c9f93..c23e599 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java @@ -57,7 +57,7 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView { //Reset image loader ImageLoadHelper.remove(this); - setImageDrawable(UiUtils.getDrawable(getContext(), mDefaultDrawable)); + applyDefaultDrawable(); ImageLoadHelper.load(getContext(), url, this); //Save image URL @@ -91,6 +91,13 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView { this.mDefaultDrawable = defaultDrawable; } + /** + * Apply the default drawable to the view + */ + public void applyDefaultDrawable() { + setImageDrawable(UiUtils.getDrawable(getContext(), mDefaultDrawable)); + } + /** * Get the current URL used in this image view * diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebLinkView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebLinkView.java new file mode 100644 index 0000000..a68570c --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebLinkView.java @@ -0,0 +1,92 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.app.SearchManager; +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.View; +import android.widget.FrameLayout; +import android.widget.TextView; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.models.WebLink; + +/** + * WebLink view + * + * Display a web link + * + * @author Pierre HUBERT + */ +public class WebLinkView extends FrameLayout implements View.OnClickListener { + + /** + * Current link associated with the view + */ + private WebLink mLink; + + /** + * Container views + */ + private WebImageView mLinkIcon; + private TextView mLinkTitle; + private TextView mLinkURL; + private TextView mLinkDescription; + + public WebLinkView(@NonNull Context context) { + super(context); + init(); + } + + public WebLinkView(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(); + } + + public WebLinkView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init(){ + + //Initialize view + View view = inflate(getContext(), R.layout.view_web_link, null); + addView(view); + + mLinkIcon = findViewById(R.id.link_image); + mLinkTitle = findViewById(R.id.link_title); + mLinkURL = findViewById(R.id.link_url); + mLinkDescription = findViewById(R.id.link_description); + + mLinkIcon.setDefaultDrawable(R.drawable.world); + mLinkIcon.applyDefaultDrawable(); + + setOnClickListener(this); + } + + public void setLink(@NonNull WebLink link) { + this.mLink = link; + + if(link.hasImageURL()) mLinkIcon.loadURL(link.getImageURL()); + else { + mLinkIcon.removeImage(); + mLinkIcon.applyDefaultDrawable(); + } + + mLinkTitle.setText(link.hasTitle() ? link.getTitle() : ""); + mLinkURL.setText(link.getUrl()); + mLinkDescription.setText(link.hasDescription() ? link.getDescription() : ""); + } + + @Override + public void onClick(View view) { + if(mLink == null) return; + + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mLink.getUrl())); + getContext().startActivity(intent); + } +} diff --git a/app/src/main/res/drawable/bg_weblink.xml b/app/src/main/res/drawable/bg_weblink.xml new file mode 100644 index 0000000..9078934 --- /dev/null +++ b/app/src/main/res/drawable/bg_weblink.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/world.png b/app/src/main/res/drawable/world.png new file mode 100644 index 0000000..644d9d5 Binary files /dev/null and b/app/src/main/res/drawable/world.png differ diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index e6397c3..736d5ac 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -85,6 +85,12 @@ android:layout_height="200dp" style="@style/PostMovie"/> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9c6b6a5..a25497e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -88,6 +88,12 @@ center_horizontal + + +