Added post web links support

This commit is contained in:
Pierre HUBERT 2018-08-06 15:02:48 +02:00
parent 77c19375fc
commit 84bc2f1fd4
12 changed files with 321 additions and 23 deletions

View File

@ -24,6 +24,11 @@ public enum PostTypes {
*/ */
MOVIE, MOVIE,
/**
* Web link
*/
WEBLINK,
/** /**
* PDF * PDF
*/ */

View File

@ -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.PostUserAccess;
import org.communiquons.android.comunic.client.data.enums.PostVisibilityLevels; 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.arrays.PostsList;
import org.communiquons.android.comunic.client.data.models.WebLink;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -329,28 +330,7 @@ public class PostsHelper {
post.setVisibilityLevel(api_to_visibility_levels(json.getString("visibility_level"))); post.setVisibilityLevel(api_to_visibility_levels(json.getString("visibility_level")));
//Determine the type of the post //Determine the type of the post
switch (json.getString("kind")){ post.setType(api_to_post_types(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);
}
//Determine the user access level to the post //Determine the user access level to the post
switch (json.getString("user_access")){ switch (json.getString("user_access")){
@ -385,6 +365,16 @@ public class PostsHelper {
post.setMovie(new MoviesHelper(mContext) post.setMovie(new MoviesHelper(mContext)
.parse_json_object(json.getJSONObject("video_info"))); .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; 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 * Turn a POST visibility level into a string ready for the API
* *

View File

@ -46,6 +46,9 @@ public class Post {
//Movie //Movie
private Movie movie; private Movie movie;
//Web link
private WebLink webLink;
//Set and get the ID of the post //Set and get the ID of the post
public void setId(int id) { public void setId(int id) {
@ -211,5 +214,19 @@ public class Post {
public void setMovie(Movie movie) { public void setMovie(Movie movie) {
this.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;
}
} }

View File

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

View File

@ -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.MovieView;
import org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView; 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.WebImageView;
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 java.util.ArrayList; import java.util.ArrayList;
@ -192,6 +193,18 @@ public class PostsAdapter extends ArrayAdapter<Post>{
} }
//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) //Set post file PDF (if any)
PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link); PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link);

View File

@ -57,7 +57,7 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
//Reset image loader //Reset image loader
ImageLoadHelper.remove(this); ImageLoadHelper.remove(this);
setImageDrawable(UiUtils.getDrawable(getContext(), mDefaultDrawable)); applyDefaultDrawable();
ImageLoadHelper.load(getContext(), url, this); ImageLoadHelper.load(getContext(), url, this);
//Save image URL //Save image URL
@ -91,6 +91,13 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
this.mDefaultDrawable = defaultDrawable; 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 * Get the current URL used in this image view
* *

View File

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

View File

@ -0,0 +1,14 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--<gradient
android:angle="135"
android:centerColor="#616161"
android:endColor="#455a64"
android:startColor="#9e9e9e"
android:type="linear" />-->
<solid
android:color="#9e9e9e" />
<corners android:radius="5dp" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -85,6 +85,12 @@
android:layout_height="200dp" android:layout_height="200dp"
style="@style/PostMovie"/> style="@style/PostMovie"/>
<!-- Post Web link (if any) -->
<org.communiquons.android.comunic.client.ui.views.WebLinkView
android:id="@+id/post_web_link"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Related PDF (if any) --> <!-- Related PDF (if any) -->
<org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView <org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView
android:id="@+id/btn_pdf_link" android:id="@+id/btn_pdf_link"

View File

@ -0,0 +1,46 @@
<?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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:background="@drawable/bg_weblink">
<org.communiquons.android.comunic.client.ui.views.WebImageView
android:id="@+id/link_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/world"
android:layout_gravity="center_vertical"
android:layout_marginEnd="5dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/link_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Link title"
android:textSize="20sp"/>
<TextView
android:id="@+id/link_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="http://example.com/link"
style="@android:style/TextAppearance.Small"
android:textColor="@android:color/holo_blue_dark"/>
<TextView
android:id="@+id/link_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="A description content with interesting content about the page and its content."/>
</LinearLayout>
</LinearLayout>

View File

@ -88,6 +88,12 @@
<item name="android:layout_gravity">center_horizontal</item> <item name="android:layout_gravity">center_horizontal</item>
</style> </style>
<!-- Post Weblink (if any) -->
<style name="PostWebLink">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:visibility">gone</item>
</style>
<!-- Post PDF button (when required) --> <!-- Post PDF button (when required) -->
<style name="PostPDFButton"> <style name="PostPDFButton">
<item name="android:layout_gravity">center_horizontal</item> <item name="android:layout_gravity">center_horizontal</item>