2019-10-02 18:32:59 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2020-05-21 22:16:31 +02:00
|
|
|
import android.content.Intent;
|
2019-10-30 15:04:49 +01:00
|
|
|
import android.graphics.BitmapFactory;
|
2020-03-09 17:13:40 +01:00
|
|
|
import android.graphics.Typeface;
|
2019-10-30 15:04:49 +01:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2020-05-21 22:16:31 +02:00
|
|
|
import android.net.Uri;
|
2019-10-02 18:32:59 +02:00
|
|
|
import android.os.Bundle;
|
2019-10-17 19:47:27 +02:00
|
|
|
import android.text.method.ScrollingMovementMethod;
|
2019-10-30 15:04:49 +01:00
|
|
|
import android.util.Base64;
|
2019-10-02 18:32:59 +02:00
|
|
|
import android.util.Log;
|
2020-03-09 17:13:40 +01:00
|
|
|
import android.view.Gravity;
|
2020-03-08 06:53:00 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2019-10-02 18:32:59 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
2020-03-04 17:15:57 +01:00
|
|
|
import android.widget.LinearLayout;
|
2019-10-02 18:32:59 +02:00
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
2020-05-21 22:16:31 +02:00
|
|
|
import androidx.annotation.Nullable;
|
2019-10-02 18:32:59 +02:00
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2020-01-30 19:00:31 +01:00
|
|
|
import com.github.barteksc.pdfviewer.PDFView;
|
|
|
|
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
2019-10-30 15:04:49 +01:00
|
|
|
import com.github.chrisbanes.photoview.PhotoView;
|
2020-03-16 10:25:15 +01:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2019-10-02 18:32:59 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2020-03-08 06:53:00 +01:00
|
|
|
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
2019-10-02 18:32:59 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2020-04-30 08:28:27 +02:00
|
|
|
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
|
|
|
import org.mian.gitnex.helpers.highlightjs.models.Theme;
|
2019-10-02 18:32:59 +02:00
|
|
|
import org.mian.gitnex.models.Files;
|
|
|
|
import org.mian.gitnex.util.AppUtil;
|
|
|
|
import org.mian.gitnex.util.TinyDB;
|
2020-03-08 06:53:00 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-05-21 22:16:31 +02:00
|
|
|
import java.io.OutputStream;
|
2019-12-13 09:55:58 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLDecoder;
|
2020-03-08 06:53:00 +01:00
|
|
|
import java.util.Objects;
|
2019-10-02 18:32:59 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-08 06:53:00 +01:00
|
|
|
public class FileViewActivity extends BaseActivity implements BottomSheetFileViewerFragment.BottomSheetListener {
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private TextView singleFileContents;
|
|
|
|
private LinearLayout singleFileContentsFrame;
|
|
|
|
private HighlightJsView singleCodeContents;
|
|
|
|
private PhotoView imageView;
|
|
|
|
final Context ctx = this;
|
2020-04-28 15:47:25 +02:00
|
|
|
private Context appCtx;
|
2020-04-13 17:23:31 +02:00
|
|
|
private ProgressBar mProgressBar;
|
|
|
|
private byte[] imageData;
|
|
|
|
private PDFView pdfView;
|
|
|
|
private LinearLayout pdfViewFrame;
|
|
|
|
private byte[] decodedPdf;
|
|
|
|
private Boolean pdfNightMode;
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
@Override
|
|
|
|
protected int getLayoutResourceId() {
|
2020-03-04 17:15:57 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
return R.layout.activity_file_view;
|
|
|
|
}
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2020-04-28 15:47:25 +02:00
|
|
|
appCtx = getApplicationContext();
|
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2020-04-13 17:23:31 +02:00
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
ImageView closeActivity = findViewById(R.id.close);
|
|
|
|
singleFileContents = findViewById(R.id.singleFileContents);
|
|
|
|
singleCodeContents = findViewById(R.id.singleCodeContents);
|
|
|
|
imageView = findViewById(R.id.imageView);
|
|
|
|
mProgressBar = findViewById(R.id.progress_bar);
|
|
|
|
pdfView = findViewById(R.id.pdfView);
|
|
|
|
pdfViewFrame = findViewById(R.id.pdfViewFrame);
|
|
|
|
singleFileContentsFrame = findViewById(R.id.singleFileContentsFrame);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
String singleFileName = getIntent().getStringExtra("singleFileName");
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
|
|
|
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
2020-03-08 08:46:31 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
2019-12-13 09:55:58 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
tinyDb.putString("downloadFileContents", "");
|
2019-12-13 09:55:58 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
try {
|
2019-12-25 20:14:33 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
singleFileName = URLDecoder.decode(singleFileName, "UTF-8");
|
|
|
|
singleFileName = singleFileName.replaceAll("//", "/");
|
|
|
|
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
catch(UnsupportedEncodingException e) {
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
assert singleFileName != null;
|
|
|
|
Log.i("singleFileName", singleFileName);
|
2020-03-06 14:46:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
toolbar_title.setText(singleFileName);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename) {
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
Call<Files> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getSingleFileContents(token, owner, repo, filename);
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
call.enqueue(new Callback<Files>() {
|
2020-03-08 06:53:00 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
if(response.code() == 200) {
|
2019-11-05 09:34:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
AppUtil appUtil = new AppUtil();
|
|
|
|
assert response.body() != null;
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
if(!response.body().getContent().equals("")) {
|
2019-11-05 09:34:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
String fileExtension = FileUtils.getExtension(filename);
|
|
|
|
mProgressBar.setVisibility(View.GONE);
|
2019-11-05 09:34:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
// download file meta
|
|
|
|
tinyDb.putString("downloadFileName", filename);
|
|
|
|
tinyDb.putString("downloadFileContents", response.body().getContent());
|
2019-11-05 09:34:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
if(appUtil.imageExtension(fileExtension)) { // file is image
|
2020-01-30 19:00:31 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
singleFileContentsFrame.setVisibility(View.GONE);
|
|
|
|
singleCodeContents.setVisibility(View.GONE);
|
|
|
|
pdfViewFrame.setVisibility(View.GONE);
|
|
|
|
imageView.setVisibility(View.VISIBLE);
|
2020-01-30 19:00:31 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
|
|
|
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
|
|
|
imageView.setImageDrawable(imageDrawable);
|
2020-03-06 14:46:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
2020-01-30 19:00:31 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
imageView.setVisibility(View.GONE);
|
|
|
|
singleFileContentsFrame.setVisibility(View.GONE);
|
|
|
|
pdfViewFrame.setVisibility(View.GONE);
|
|
|
|
singleCodeContents.setVisibility(View.VISIBLE);
|
2020-03-09 17:13:40 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
switch(tinyDb.getInt("fileviewerSourceCodeThemeId")) {
|
|
|
|
case 1:
|
|
|
|
singleCodeContents.setTheme(Theme.ARDUINO_LIGHT);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
singleCodeContents.setTheme(Theme.GITHUB);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
singleCodeContents.setTheme(Theme.FAR);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
singleCodeContents.setTheme(Theme.IR_BLACK);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
singleCodeContents.setTheme(Theme.ANDROID_STUDIO);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
|
|
|
}
|
2020-03-09 17:13:40 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
2020-03-09 17:13:40 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
else if(appUtil.pdfExtension(fileExtension)) { // file is pdf
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
imageView.setVisibility(View.GONE);
|
|
|
|
singleFileContentsFrame.setVisibility(View.GONE);
|
|
|
|
singleCodeContents.setVisibility(View.GONE);
|
|
|
|
pdfViewFrame.setVisibility(View.VISIBLE);
|
2019-11-05 09:34:22 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
pdfNightMode = tinyDb.getBoolean("enablePdfMode");
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
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(pdfNightMode).load();
|
2019-10-30 15:04:49 +01:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
else if(appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
imageView.setVisibility(View.GONE);
|
|
|
|
singleCodeContents.setVisibility(View.GONE);
|
|
|
|
pdfViewFrame.setVisibility(View.GONE);
|
|
|
|
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
singleFileContents.setText(getResources().getString(R.string.excludeFilesInFileviewer));
|
|
|
|
singleFileContents.setGravity(Gravity.CENTER);
|
|
|
|
singleFileContents.setTypeface(null, Typeface.BOLD);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
else { // file type not known - plain text view
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
imageView.setVisibility(View.GONE);
|
|
|
|
singleCodeContents.setVisibility(View.GONE);
|
|
|
|
pdfViewFrame.setVisibility(View.GONE);
|
|
|
|
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
singleFileContents.setText("");
|
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(response.code() == 403) {
|
|
|
|
|
|
|
|
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
|
|
|
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
Toasty.info(ctx, getString(R.string.labelGeneralError));
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
|
|
|
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
case R.id.genericMenu:
|
|
|
|
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
|
|
|
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonClicked(String text) {
|
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
if("downloadFile".equals(text)) {
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
requestFileDownload();
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestFileDownload() {
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
int CREATE_REQUEST_CODE = 40;
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
intent.setType("*/*");
|
|
|
|
intent.putExtra(Intent.EXTRA_TITLE, outputFileName.getName());
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
startActivityForResult(intent, CREATE_REQUEST_CODE);
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2020-04-28 15:47:25 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.waitLoadingDownloadFile));
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
if (requestCode == 40 && resultCode == RESULT_OK) {
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
assert data != null;
|
|
|
|
Uri uri = data.getData();
|
|
|
|
|
|
|
|
assert uri != null;
|
|
|
|
OutputStream outputStream = getContentResolver().openOutputStream(uri);
|
|
|
|
|
|
|
|
byte[] dataAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
|
|
|
|
|
|
|
|
assert outputStream != null;
|
|
|
|
outputStream.write(dataAsBytes);
|
|
|
|
outputStream.close();
|
|
|
|
|
|
|
|
Toasty.info(ctx, getString(R.string.downloadFileSaved));
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
|
|
|
}
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
}
|
2020-05-21 22:16:31 +02:00
|
|
|
|
2020-04-13 17:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
onClickListener = view -> {
|
2020-04-13 17:23:31 +02:00
|
|
|
|
2020-05-21 22:16:31 +02:00
|
|
|
getIntent().removeExtra("singleFileName");
|
|
|
|
finish();
|
2020-04-13 17:23:31 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
2019-10-02 18:32:59 +02:00
|
|
|
|
2020-03-08 06:53:00 +01:00
|
|
|
}
|