diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..6313b56c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto eol=lf
diff --git a/README.md b/README.md
index bbdbc7f1..ff0b46b0 100644
--- a/README.md
+++ b/README.md
@@ -89,5 +89,6 @@ Open source libraries
- Apache/commons-io
- Caverock/androidsvg
- Droidsonroids.gif/android-gif-drawable
+- Barteksc/AndroidPdfViewer
[Follow me on Fediverse - mastodon.social/@mmarif](https://mastodon.social/@mmarif)
diff --git a/app/build.gradle b/app/build.gradle
index 122d0361..01b7034f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,12 +23,12 @@ android {
}
dependencies {
- def lifecycle_version = "2.2.0-rc03"
+ def lifecycle_version = "2.2.0"
final def markwon_version = "4.1.1"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
- implementation "com.google.android.material:material:1.2.0-alpha03"
+ implementation "com.google.android.material:material:1.2.0-alpha04"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
testImplementation "junit:junit:4.12"
@@ -69,4 +69,5 @@ dependencies {
implementation "commons-io:commons-io:2.6"
implementation "com.github.chrisbanes:PhotoView:2.3.0"
implementation "com.pddstudio:highlightjs-android:1.5.0"
+ implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
}
diff --git a/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java b/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java
index 760fe6c6..77ee3ce3 100644
--- a/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java
+++ b/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java
@@ -15,6 +15,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
+import com.github.barteksc.pdfviewer.PDFView;
+import com.github.barteksc.pdfviewer.util.FitPolicy;
import com.github.chrisbanes.photoview.PhotoView;
import com.pddstudio.highlightjs.HighlightJsView;
import com.pddstudio.highlightjs.models.Theme;
@@ -44,6 +46,8 @@ public class FileViewActivity extends AppCompatActivity {
final Context ctx = this;
private ProgressBar mProgressBar;
private byte[] imageData;
+ private PDFView pdfView;
+ private byte[] decodedPdf;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -68,6 +72,7 @@ public class FileViewActivity extends AppCompatActivity {
imageView = findViewById(R.id.imageView);
singleFileContents.setVisibility(View.GONE);
mProgressBar = findViewById(R.id.progress_bar);
+ pdfView = findViewById(R.id.pdfView);
String singleFileName = getIntent().getStringExtra("singleFileName");
@@ -140,6 +145,33 @@ public class FileViewActivity extends AppCompatActivity {
singleCodeContents.setShowLineNumbers(true);
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
+ }
+ else if (appUtil.pdfExtension(fileExtension)) { // file is pdf
+
+ imageView.setVisibility(View.GONE);
+ singleFileContents.setVisibility(View.GONE);
+ singleCodeContents.setVisibility(View.GONE);
+ pdfView.setVisibility(View.VISIBLE);
+
+ decodedPdf = Base64.decode(response.body().getContent(), Base64.DEFAULT);
+ pdfView.fromBytes(decodedPdf)
+ .enableSwipe(true)
+ .swipeHorizontal(false)
+ .enableDoubletap(true)
+ .defaultPage(0)
+ .enableAnnotationRendering(false)
+ .password(null)
+ .scrollHandle(null)
+ .enableAntialiasing(true)
+ .spacing(0)
+ .autoSpacing(true)
+ .pageFitPolicy(FitPolicy.WIDTH)
+ .fitEachPage(true)
+ .pageSnap(false)
+ .pageFling(true)
+ .nightMode(true)
+ .load();
+
}
else { // file type not known - plain text view
diff --git a/app/src/main/java/org/mian/gitnex/util/AppUtil.java b/app/src/main/java/org/mian/gitnex/util/AppUtil.java
index c544924e..cc263395 100644
--- a/app/src/main/java/org/mian/gitnex/util/AppUtil.java
+++ b/app/src/main/java/org/mian/gitnex/util/AppUtil.java
@@ -224,6 +224,14 @@ public class AppUtil {
}
+ public Boolean pdfExtension(String ext) {
+
+ String[] extValues = new String[] {"pdf"};
+
+ return Arrays.asList(extValues).contains(ext);
+
+ }
+
public Boolean imageExtension(String ext) {
String[] extValues = new String[] {"jpg", "jpeg", "gif", "png", "ico"};
diff --git a/app/src/main/res/layout/activity_file_view.xml b/app/src/main/res/layout/activity_file_view.xml
index 05f0e695..0059e546 100644
--- a/app/src/main/res/layout/activity_file_view.xml
+++ b/app/src/main/res/layout/activity_file_view.xml
@@ -71,6 +71,22 @@
+
+
+
+
+
+
-
\ No newline at end of file
+