mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Fix onActivityResult deprecation in MissionsFragment
This commit is contained in:
parent
ae39b31c68
commit
02b0909829
@ -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
Block a user