mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
Support pdf files in file viewer (#259)
auto convert EOL this fix it for me fix layout implement support for pdf files in file viewer Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/259 Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
ec62e3cebf
commit
1293e8be27
6 changed files with 62 additions and 3 deletions
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"};
|
||||
|
|
|
@ -71,6 +71,22 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_marginTop="55dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorPrimary"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.barteksc.pdfviewer.PDFView
|
||||
android:id="@+id/pdfView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/black"
|
||||
android:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.pddstudio.highlightjs.HighlightJsView
|
||||
android:id="@+id/singleCodeContents"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -95,4 +111,4 @@
|
|||
android:indeterminate="true"
|
||||
android:visibility="visible" />
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue