diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 76675bfd..e8aff7c2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
+
= 23)
+ {
+ if (checkPermission())
+ {
+ requestFileDownload();
+ }
+ else {
+ requestPermission();
+ }
+ }
+ else
+ {
+ requestFileDownload();
+ }
+ break;
+
+ }
+
+ }
+
+ private void requestFileDownload() {
+
+ final TinyDB tinyDb = new TinyDB(getApplicationContext());
+
+ if(!tinyDb.getString("downloadFileContents").isEmpty()) {
+
+ File outputFileName = new File(tinyDb.getString("downloadFileName"));
+ final File downloadFilePath = new File(Environment.getExternalStorageDirectory().getPath() + "/Download/" + outputFileName.getName());
+
+ byte[] pdfAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
+ FileOutputStream fileOutputStream = null;
+
+ try {
+
+ fileOutputStream = new FileOutputStream(downloadFilePath, false);
+ Objects.requireNonNull(fileOutputStream).write(pdfAsBytes);
+ fileOutputStream.flush();
+ fileOutputStream.close();
+ Toasty.info(getApplicationContext(), getString(R.string.downloadFileSaved));
+
+ }
+ catch (IOException e) {
+ Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
+ }
+
+ }
+ else {
+ Toasty.error(getApplicationContext(), getString(R.string.waitLoadingDownloadFile));
+ }
+
+ }
+
+ private boolean checkPermission() {
+ int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ return result == PackageManager.PERMISSION_GRANTED;
+ }
+
+ private void requestPermission() {
+ ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case PERMISSION_REQUEST_CODE:
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ Log.i("PermissionsCheck", "Permission Granted");
+ }
+ else {
+ Log.e("PermissionsCheck", "Permission Denied");
+ }
+ break;
+ }
+ }
+
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
@@ -249,4 +390,4 @@ public class FileViewActivity extends BaseActivity {
};
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java
new file mode 100644
index 00000000..b8ea4c4b
--- /dev/null
+++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java
@@ -0,0 +1,57 @@
+package org.mian.gitnex.fragments;
+
+import android.content.Context;
+import android.os.Bundle;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
+import org.mian.gitnex.R;
+
+/**
+ * Author M M Arif
+ */
+
+public class BottomSheetFileViewerFragment extends BottomSheetDialogFragment {
+
+ private BottomSheetFileViewerFragment.BottomSheetListener bmListener;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+
+ View v = inflater.inflate(R.layout.bottom_sheet_file_viewer, container, false);
+
+ TextView downloadFile = v.findViewById(R.id.downloadFile);
+
+ downloadFile.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ bmListener.onButtonClicked("downloadFile");
+ dismiss();
+ }
+ });
+
+ return v;
+ }
+
+ public interface BottomSheetListener {
+ void onButtonClicked(String text);
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+
+ try {
+ bmListener = (BottomSheetFileViewerFragment.BottomSheetListener) context;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(context.toString()
+ + " must implement BottomSheetListener");
+ }
+ }
+
+}
diff --git a/app/src/main/java/org/mian/gitnex/helpers/Toasty.java b/app/src/main/java/org/mian/gitnex/helpers/Toasty.java
index df68e5f1..f8080296 100644
--- a/app/src/main/java/org/mian/gitnex/helpers/Toasty.java
+++ b/app/src/main/java/org/mian/gitnex/helpers/Toasty.java
@@ -28,4 +28,19 @@ public class Toasty {
}
+ public static void error(Context context, String message) {
+
+ LayoutInflater inflater = LayoutInflater.from(context);
+ View view = inflater.inflate( context.getResources().getLayout(R.layout.custom_toast_error), null );
+
+ TextView text = view.findViewById(R.id.toastText);
+ text.setText(message);
+
+ Toast toast = new Toast(context);
+ toast.setDuration(Toast.LENGTH_LONG);
+ toast.setView(view);
+ toast.show();
+
+ }
+
}
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 647e27c5..71451f9f 100644
--- a/app/src/main/java/org/mian/gitnex/util/AppUtil.java
+++ b/app/src/main/java/org/mian/gitnex/util/AppUtil.java
@@ -218,7 +218,8 @@ public class AppUtil {
"coffee", "rc", "rs", "rust", "basic", "clj", "css", "dart", "lisp", "erl", "hs", "lsp", "rkt",
"ss", "llvm", "ll", "lua", "matlab", "pascal", "r", "scala", "sql", "latex", "tex", "vb", "vbs",
"vhd", "tcl", "wiki.meta", "yaml", "yml", "markdown", "xml", "proto", "regex", "py", "pl", "js",
- "html", "htm", "volt", "ini", "htaccess", "conf", "gitignore", "gradle", "txt", "properties", "bat"};
+ "html", "htm", "volt", "ini", "htaccess", "conf", "gitignore", "gradle", "txt", "properties", "bat",
+ "twig"};
return Arrays.asList(extValues).contains(ext);
@@ -240,6 +241,16 @@ public class AppUtil {
}
+ public Boolean excludeFilesInFileViewerExtension(String ext) {
+
+ String[] extValues = new String[] {"doc", "docx", "ppt", "pptx", "xls", "xlsx", "xlsm", "odt",
+ "ott", "odf", "ods", "ots", "exe", "jar", "odg", "otg", "odp", "otp", "bin", "dmg", "psd",
+ "xcf"};
+
+ return Arrays.asList(extValues).contains(ext);
+
+ }
+
public String getLastCharactersOfWord( String str, int count ) {
return str.substring(str.length() - count);
diff --git a/app/src/main/res/drawable/ic_file_download_24dp.xml b/app/src/main/res/drawable/ic_file_download_24dp.xml
new file mode 100644
index 00000000..ffc2a2ff
--- /dev/null
+++ b/app/src/main/res/drawable/ic_file_download_24dp.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/bottom_sheet_file_viewer.xml b/app/src/main/res/layout/bottom_sheet_file_viewer.xml
new file mode 100644
index 00000000..180ffd3d
--- /dev/null
+++ b/app/src/main/res/layout/bottom_sheet_file_viewer.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/custom_toast_error.xml b/app/src/main/res/layout/custom_toast_error.xml
new file mode 100644
index 00000000..7bd724f3
--- /dev/null
+++ b/app/src/main/res/layout/custom_toast_error.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1af444d0..1660770a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -551,4 +551,8 @@
Pull Request was merged successfully
Pull Request is not available for merge
+ Download This File
+ Please wait for the file to load to memory
+ File is saved to Download directory
+ This file type is not supported in file viewer. Download it instead from the three dotted menu?