Can open posts PDFs.

This commit is contained in:
Pierre HUBERT 2018-07-19 08:00:59 +02:00
parent 5660e6b573
commit 8a1a3050f4
12 changed files with 195 additions and 3 deletions

View File

@ -22,6 +22,9 @@ android {
//Connexion to Crash Reporter //Connexion to Crash Reporter
buildConfigField "String", "crash_reporter_url", "\"http://devweb.local/CrashReporterWeb/project/api/v1/push\"" buildConfigField "String", "crash_reporter_url", "\"http://devweb.local/CrashReporterWeb/project/api/v1/push\""
buildConfigField "String", "crash_reporter_key", "\"KSyqOzkfJasDTxE0wrXYnUPl8dV1veBc\"" buildConfigField "String", "crash_reporter_key", "\"KSyqOzkfJasDTxE0wrXYnUPl8dV1veBc\""
//Connexion to PDF viewer
buildConfigField "String", "pdf_view_url", "\"http://devweb.local/pdfviewer/?file=\""
} }
release { release {

View File

@ -32,12 +32,17 @@
<!-- Search user activity --> <!-- Search user activity -->
<activity <activity
android:name=".ui.activities.SearchUserActivity" android:name=".ui.activities.SearchUserActivity"
android:label="@string/activity_searchuser_title"/> android:label="@string/activity_searchuser_title" />
<!-- Notifications background refresh service --> <!-- Notifications background refresh service -->
<service android:name=".data.services.NotificationsService" <service
android:exported="false"/> android:name=".data.services.NotificationsService"
android:exported="false" />
<!-- PDF Viewer activity -->
<activity
android:name=".ui.activities.PDFActivity"
android:label="@string/activity_view_pdf_label"/>
</application> </application>
</manifest> </manifest>

View File

@ -24,6 +24,11 @@ public enum PostTypes {
*/ */
MOVIE, MOVIE,
/**
* PDF
*/
PDF,
/** /**
* Unknown type * Unknown type
*/ */

View File

@ -367,6 +367,10 @@ public class PostsHelper {
post.setType(PostTypes.MOVIE); post.setType(PostTypes.MOVIE);
break; break;
case "pdf":
post.setType(PostTypes.PDF);
break;
default: default:
post.setType(PostTypes.UNKNOWN); post.setType(PostTypes.UNKNOWN);

View File

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

View File

@ -12,6 +12,7 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper; 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.data.utils.Utilities;
import org.communiquons.android.comunic.client.ui.views.EditCommentContentView; 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.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.WebImageView;
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
@ -170,6 +172,17 @@ public class PostsAdapter extends ArrayAdapter<Post>{
} }
//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 //Set posts likes
LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button); LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button);
likeButtonView.setNumberLikes(post.getNumberLike()); likeButtonView.setNumberLikes(post.getNumberLike());

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.PDFActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>

View File

@ -78,6 +78,13 @@
android:contentDescription="@string/post_image_description" android:contentDescription="@string/post_image_description"
android:scaleType="centerInside" /> android:scaleType="centerInside" />
<!-- Related PDF (if any) -->
<org.communiquons.android.comunic.client.ui.views.PDFLinkButtonView
android:id="@+id/btn_pdf_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/PostPDFButton"/>
<!-- Post content --> <!-- Post content -->
<TextView <TextView
android:id="@+id/post_content" android:id="@+id/post_content"

View File

@ -190,4 +190,5 @@
<string name="err_get_latest_posts">An error occurred while trying to retrieve the list of latest posts!</string> <string name="err_get_latest_posts">An error occurred while trying to retrieve the list of latest posts!</string>
<string name="notice_no_latest_posts">You do not have any latest posts to display here.</string> <string name="notice_no_latest_posts">You do not have any latest posts to display here.</string>
<string name="main_menu_search_user">Search user</string> <string name="main_menu_search_user">Search user</string>
<string name="activity_view_pdf_label">View PDF</string>
</resources> </resources>

View File

@ -69,6 +69,11 @@
<item name="android:layout_gravity">center_vertical</item> <item name="android:layout_gravity">center_vertical</item>
</style> </style>
<!-- Post PDF button (when required) -->
<style name="PostPDFButton">
<item name="android:layout_gravity">center_horizontal</item>
</style>
<!-- Post content --> <!-- Post content -->
<style name="PostContent"> <style name="PostContent">
<item name="android:textAlignment">center</item> <item name="android:textAlignment">center</item>