From 8a1a3050f4619a6edf26abccb22eeb636614d988 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 19 Jul 2018 08:00:59 +0200 Subject: [PATCH] Can open posts PDFs. --- app/build.gradle | 3 + app/src/main/AndroidManifest.xml | 11 ++- .../comunic/client/data/enums/PostTypes.java | 5 ++ .../client/data/helpers/PostsHelper.java | 4 + .../client/ui/activities/PDFActivity.java | 52 +++++++++++ .../client/ui/adapters/PostsAdapter.java | 13 +++ .../client/ui/views/PDFLinkButtonView.java | 84 ++++++++++++++++++ app/src/main/res/drawable/file_pdf.png | Bin 0 -> 1424 bytes app/src/main/res/layout/activity_pdf.xml | 13 +++ app/src/main/res/layout/post_item.xml | 7 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 5 ++ 12 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/communiquons/android/comunic/client/ui/activities/PDFActivity.java create mode 100644 app/src/main/java/org/communiquons/android/comunic/client/ui/views/PDFLinkButtonView.java create mode 100755 app/src/main/res/drawable/file_pdf.png create mode 100644 app/src/main/res/layout/activity_pdf.xml diff --git a/app/build.gradle b/app/build.gradle index b0e38a0..7ce4b87 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,9 @@ android { //Connexion to Crash Reporter buildConfigField "String", "crash_reporter_url", "\"http://devweb.local/CrashReporterWeb/project/api/v1/push\"" buildConfigField "String", "crash_reporter_key", "\"KSyqOzkfJasDTxE0wrXYnUPl8dV1veBc\"" + + //Connexion to PDF viewer + buildConfigField "String", "pdf_view_url", "\"http://devweb.local/pdfviewer/?file=\"" } release { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 304827f..e3d4fd2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,12 +32,17 @@ + android:label="@string/activity_searchuser_title" /> - + + + \ No newline at end of file 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 e8c5c31..b1d5841 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, + /** + * PDF + */ + PDF, + /** * Unknown type */ 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 5052dd4..218f67f 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 @@ -367,6 +367,10 @@ public class PostsHelper { post.setType(PostTypes.MOVIE); break; + case "pdf": + post.setType(PostTypes.PDF); + break; + default: post.setType(PostTypes.UNKNOWN); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/PDFActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/PDFActivity.java new file mode 100644 index 0000000..58ee2a1 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/PDFActivity.java @@ -0,0 +1,52 @@ + +package org.communiquons.android.comunic.client.ui.activities; + +import android.net.Uri; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.webkit.WebView; + +import org.communiquons.android.comunic.client.BuildConfig; +import org.communiquons.android.comunic.client.R; + + +/** + * PDF Activity + * + * This activity is used to display remote PDF + * + * @author Pierre HUBERT + */ +public class PDFActivity extends AppCompatActivity { + + /** + * The WebView of the layout + */ + private WebView mWebView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_pdf); + + //Get and setup WebView + mWebView = (WebView) findViewById(R.id.webview); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setAllowFileAccess(false); + mWebView.getSettings().setAllowFileAccessFromFileURLs(false); + mWebView.getSettings().setGeolocationEnabled(false); + + } + + @Override + protected void onStart() { + super.onStart(); + + //Determine and open appropriate URL + Uri data = getIntent().getData(); + assert data != null; + + String url = BuildConfig.pdf_view_url + data.getQueryParameter("url"); + mWebView.loadUrl(url); + } +} 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 8500a8a..c9837c7 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 @@ -12,6 +12,7 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper; @@ -25,6 +26,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.PDFLinkButtonView; import org.communiquons.android.comunic.client.ui.views.WebImageView; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; @@ -170,6 +172,17 @@ public class PostsAdapter extends ArrayAdapter{ } + //Set post file PDF (if any) + PDFLinkButtonView pdfLinkButtonView = convertView.findViewById(R.id.btn_pdf_link); + + if(post.getType() != PostTypes.PDF) + pdfLinkButtonView.setVisibility(View.GONE); + else { + pdfLinkButtonView.setVisibility(View.VISIBLE); + pdfLinkButtonView.setPDFUrl(post.getFile_path_url()); + } + + //Set posts likes LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button); likeButtonView.setNumberLikes(post.getNumberLike()); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/PDFLinkButtonView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/PDFLinkButtonView.java new file mode 100644 index 0000000..b75d874 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/PDFLinkButtonView.java @@ -0,0 +1,84 @@ + +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.util.AttributeSet; +import android.view.View; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.ui.activities.PDFActivity; +import org.communiquons.android.comunic.client.ui.utils.UiUtils; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +/** + * PDF button link widget + * + * This button is used to offer the user to open a PDF by clicking on it. + * + * @author Pierre HUBERT + */ +public class PDFLinkButtonView extends android.support.v7.widget.AppCompatImageButton implements View.OnClickListener { + + /** + * The URL of the target PDF + */ + private String mPDFUrl = null; + + public PDFLinkButtonView(Context context) { + super(context); + init(); + } + + public PDFLinkButtonView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public PDFLinkButtonView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + /** + * Initialize the button + */ + private void init(){ + + //Set the drawable + setImageDrawable(UiUtils.getDrawable(getContext(), R.drawable.file_pdf)); + + setOnClickListener(this); + } + + public String getPDFUrl() { + return mPDFUrl; + } + + public boolean hasPDFUrl(){ + return mPDFUrl != null; + } + + public void setPDFUrl(String PDFUrl) { + this.mPDFUrl = PDFUrl; + } + + @Override + public void onClick(View view) { + + if(!hasPDFUrl()) + return; + + try { + Intent intent = new Intent(getContext(), PDFActivity.class); + intent.setData(Uri.parse("?url=" + URLEncoder.encode(getPDFUrl(), "UTF-8"))); + getContext().startActivity(intent); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + + } +} diff --git a/app/src/main/res/drawable/file_pdf.png b/app/src/main/res/drawable/file_pdf.png new file mode 100755 index 0000000000000000000000000000000000000000..04423b4965028b395ce314a15fe2e7c55f562677 GIT binary patch literal 1424 zcmV;B1#kL^P)1RCwC7S8GgMMH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qg>=Li<@j#b?VF zO|?s(9ESgB2VBw?>7jxos35V+xT{>#(9MY1hYkSWJ8!~#g7}?oJM#Atdox!$$F#z9 z+51>2wfwR3c1=3bgUF!|xVq&4fCO5OpcvK4AAf>6GXym>4A-Ut`|4g%PQJBtJrMg} z0tUW?D`3}#XcbX0nckq&8yt8k-w$i5h7KXvkv>Ajg>qN~{J@nf_SpV?h$mua7jXDf zx~SNBZsg|yUhg`XkdY?lKcjElMIUW}m2n<>bf?XT!r8+>Db4gLc|EU51^<`WD0000 + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index c09d95a..ee1784b 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" /> + + + An error occurred while trying to retrieve the list of latest posts! You do not have any latest posts to display here. Search user + View PDF diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 7a9e3bd..13fc489 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -69,6 +69,11 @@ center_vertical + + +