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 0000000..04423b4 Binary files /dev/null and b/app/src/main/res/drawable/file_pdf.png differ diff --git a/app/src/main/res/layout/activity_pdf.xml b/app/src/main/res/layout/activity_pdf.xml new file mode 100644 index 0000000..d853a27 --- /dev/null +++ b/app/src/main/res/layout/activity_pdf.xml @@ -0,0 +1,13 @@ + + + + + + \ 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 + + +