mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Added post web links support
This commit is contained in:
parent
77c19375fc
commit
84bc2f1fd4
@ -24,6 +24,11 @@ public enum PostTypes {
|
||||
*/
|
||||
MOVIE,
|
||||
|
||||
/**
|
||||
* Web link
|
||||
*/
|
||||
WEBLINK,
|
||||
|
||||
/**
|
||||
* PDF
|
||||
*/
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<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)
|
||||
PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link);
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
14
app/src/main/res/drawable/bg_weblink.xml
Normal file
14
app/src/main/res/drawable/bg_weblink.xml
Normal 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>
|
BIN
app/src/main/res/drawable/world.png
Normal file
BIN
app/src/main/res/drawable/world.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
@ -85,6 +85,12 @@
|
||||
android:layout_height="200dp"
|
||||
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) -->
|
||||
<org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView
|
||||
android:id="@+id/btn_pdf_link"
|
||||
|
46
app/src/main/res/layout/view_web_link.xml
Normal file
46
app/src/main/res/layout/view_web_link.xml
Normal 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>
|
@ -88,6 +88,12 @@
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
</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) -->
|
||||
<style name="PostPDFButton">
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
|
Loading…
Reference in New Issue
Block a user