mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-26 13:38:59 +00:00
Can open posts PDFs.
This commit is contained in:
parent
5660e6b573
commit
8a1a3050f4
@ -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 {
|
||||
|
@ -32,12 +32,17 @@
|
||||
<!-- Search user activity -->
|
||||
<activity
|
||||
android:name=".ui.activities.SearchUserActivity"
|
||||
android:label="@string/activity_searchuser_title"/>
|
||||
android:label="@string/activity_searchuser_title" />
|
||||
|
||||
<!-- Notifications background refresh service -->
|
||||
<service android:name=".data.services.NotificationsService"
|
||||
android:exported="false"/>
|
||||
<service
|
||||
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>
|
||||
|
||||
</manifest>
|
@ -24,6 +24,11 @@ public enum PostTypes {
|
||||
*/
|
||||
MOVIE,
|
||||
|
||||
/**
|
||||
* PDF
|
||||
*/
|
||||
PDF,
|
||||
|
||||
/**
|
||||
* Unknown type
|
||||
*/
|
||||
|
@ -367,6 +367,10 @@ public class PostsHelper {
|
||||
post.setType(PostTypes.MOVIE);
|
||||
break;
|
||||
|
||||
case "pdf":
|
||||
post.setType(PostTypes.PDF);
|
||||
break;
|
||||
|
||||
default:
|
||||
post.setType(PostTypes.UNKNOWN);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<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
|
||||
LikeButtonView likeButtonView = convertView.findViewById(R.id.like_button);
|
||||
likeButtonView.setNumberLikes(post.getNumberLike());
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable/file_pdf.png
Executable file
BIN
app/src/main/res/drawable/file_pdf.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
13
app/src/main/res/layout/activity_pdf.xml
Normal file
13
app/src/main/res/layout/activity_pdf.xml
Normal 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>
|
@ -78,6 +78,13 @@
|
||||
android:contentDescription="@string/post_image_description"
|
||||
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 -->
|
||||
<TextView
|
||||
android:id="@+id/post_content"
|
||||
|
@ -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="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="activity_view_pdf_label">View PDF</string>
|
||||
</resources>
|
||||
|
@ -69,6 +69,11 @@
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<!-- Post PDF button (when required) -->
|
||||
<style name="PostPDFButton">
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
</style>
|
||||
|
||||
<!-- Post content -->
|
||||
<style name="PostContent">
|
||||
<item name="android:textAlignment">center</item>
|
||||
|
Loading…
Reference in New Issue
Block a user