Fix onActivityResult deprecation in MissionsFragment
This commit is contained in:
parent
7d69dfa62a
commit
dce874bbc7
|
@ -17,6 +17,9 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResult;
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
@ -44,7 +47,6 @@ import us.shandian.giga.ui.adapter.MissionAdapter;
|
||||||
public class MissionsFragment extends Fragment {
|
public class MissionsFragment extends Fragment {
|
||||||
|
|
||||||
private static final int SPAN_SIZE = 2;
|
private static final int SPAN_SIZE = 2;
|
||||||
private static final int REQUEST_DOWNLOAD_SAVE_AS = 0x1230;
|
|
||||||
|
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
private boolean mLinear;
|
private boolean mLinear;
|
||||||
|
@ -64,7 +66,8 @@ public class MissionsFragment extends Fragment {
|
||||||
private boolean mForceUpdate;
|
private boolean mForceUpdate;
|
||||||
|
|
||||||
private DownloadMission unsafeMissionTarget = null;
|
private DownloadMission unsafeMissionTarget = null;
|
||||||
|
private final ActivityResultLauncher<Intent> requestDownloadSaveAsLauncher =
|
||||||
|
registerForActivityResult(new StartActivityForResult(), this::requestDownloadSaveAsResult);
|
||||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -254,8 +257,9 @@ public class MissionsFragment extends Fragment {
|
||||||
initialPath = Uri.parse(initialSavePath.getAbsolutePath());
|
initialPath = Uri.parse(initialSavePath.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivityForResult(StoredFileHelper.getNewPicker(mContext, mission.storage.getName(),
|
requestDownloadSaveAsLauncher.launch(
|
||||||
mission.storage.getType(), initialPath), REQUEST_DOWNLOAD_SAVE_AS);
|
StoredFileHelper.getNewPicker(mContext, mission.storage.getName(),
|
||||||
|
mission.storage.getType(), initialPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -289,18 +293,17 @@ public class MissionsFragment extends Fragment {
|
||||||
if (mBinder != null) mBinder.enableNotifications(true);
|
if (mBinder != null) mBinder.enableNotifications(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void requestDownloadSaveAsResult(final ActivityResult result) {
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
if (result.getResultCode() != Activity.RESULT_OK) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (requestCode != REQUEST_DOWNLOAD_SAVE_AS || resultCode != Activity.RESULT_OK) return;
|
if (unsafeMissionTarget == null || result.getData() == null) {
|
||||||
|
|
||||||
if (unsafeMissionTarget == null || data.getData() == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri fileUri = data.getData();
|
Uri fileUri = result.getData().getData();
|
||||||
if (fileUri.getAuthority() != null && FilePickerActivityHelper.isOwnFileUri(mContext, fileUri)) {
|
if (fileUri.getAuthority() != null && FilePickerActivityHelper.isOwnFileUri(mContext, fileUri)) {
|
||||||
fileUri = Uri.fromFile(Utils.getFileForUri(fileUri));
|
fileUri = Uri.fromFile(Utils.getFileForUri(fileUri));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue