mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Remove deprecated startActivity for file download (#737)
Remove deprecated startActivity for file download Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/737
This commit is contained in:
parent
65c0ecaad1
commit
2064c40c7d
@ -1,5 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
@ -21,8 +22,11 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.github.barteksc.pdfviewer.PDFView;
|
||||
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
||||
@ -471,8 +475,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
||||
|
||||
int CREATE_REQUEST_CODE = 40;
|
||||
|
||||
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
@ -481,22 +483,23 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
intent.setType("*/*");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, outputFileName.getName());
|
||||
|
||||
startActivityForResult(intent, CREATE_REQUEST_CODE);
|
||||
|
||||
fileDownloadActivityResultLauncher.launch(intent);
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.waitLoadingDownloadFile));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ActivityResultLauncher<Intent> fileDownloadActivityResultLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
public void onActivityResult(ActivityResult result) {
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
|
||||
if(requestCode == 40 && resultCode == RESULT_OK) {
|
||||
Intent data = result.getData();
|
||||
|
||||
try {
|
||||
|
||||
@ -519,10 +522,9 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user