Fix onActivityResult deprecation in SubscriptionsImportFragment
This commit is contained in:
parent
aa4e5da146
commit
cae160b5be
|
@ -12,6 +12,9 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
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.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
@ -27,6 +30,7 @@ import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
||||||
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService;
|
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService;
|
||||||
|
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
||||||
import org.schabi.newpipe.util.Constants;
|
import org.schabi.newpipe.util.Constants;
|
||||||
import org.schabi.newpipe.util.ServiceHelper;
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
|
|
||||||
|
@ -34,7 +38,6 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import icepick.State;
|
import icepick.State;
|
||||||
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
|
import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
|
||||||
|
@ -43,8 +46,6 @@ import static org.schabi.newpipe.local.subscription.services.SubscriptionsImport
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE;
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE;
|
||||||
|
|
||||||
public class SubscriptionsImportFragment extends BaseFragment {
|
public class SubscriptionsImportFragment extends BaseFragment {
|
||||||
private static final int REQUEST_IMPORT_FILE_CODE = 666;
|
|
||||||
|
|
||||||
@State
|
@State
|
||||||
int currentServiceId = Constants.NO_SERVICE_ID;
|
int currentServiceId = Constants.NO_SERVICE_ID;
|
||||||
|
|
||||||
|
@ -62,6 +63,9 @@ public class SubscriptionsImportFragment extends BaseFragment {
|
||||||
private EditText inputText;
|
private EditText inputText;
|
||||||
private Button inputButton;
|
private Button inputButton;
|
||||||
|
|
||||||
|
private final ActivityResultLauncher<Intent> requestImportFileLauncher =
|
||||||
|
registerForActivityResult(new StartActivityForResult(), this::requestImportFileResult);
|
||||||
|
|
||||||
public static SubscriptionsImportFragment getInstance(final int serviceId) {
|
public static SubscriptionsImportFragment getInstance(final int serviceId) {
|
||||||
final SubscriptionsImportFragment instance = new SubscriptionsImportFragment();
|
final SubscriptionsImportFragment instance = new SubscriptionsImportFragment();
|
||||||
instance.setInitialData(serviceId);
|
instance.setInitialData(serviceId);
|
||||||
|
@ -173,22 +177,19 @@ public class SubscriptionsImportFragment extends BaseFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onImportFile() {
|
public void onImportFile() {
|
||||||
startActivityForResult(StoredFileHelper.getPicker(activity), REQUEST_IMPORT_FILE_CODE);
|
requestImportFileLauncher.launch(StoredFileHelper.getPicker(activity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void requestImportFileResult(final ActivityResult result) {
|
||||||
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
if (result.getData() == null) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
if (data == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_IMPORT_FILE_CODE
|
if (result.getResultCode() == Activity.RESULT_OK && result.getData().getData() != null) {
|
||||||
&& data.getData() != null) {
|
|
||||||
ImportConfirmationDialog.show(this,
|
ImportConfirmationDialog.show(this,
|
||||||
new Intent(activity, SubscriptionsImportService.class)
|
new Intent(activity, SubscriptionsImportService.class)
|
||||||
.putExtra(KEY_MODE, INPUT_STREAM_MODE)
|
.putExtra(KEY_MODE, INPUT_STREAM_MODE)
|
||||||
.putExtra(KEY_VALUE, data.getData())
|
.putExtra(KEY_VALUE, result.getData().getData())
|
||||||
.putExtra(Constants.KEY_SERVICE_ID, currentServiceId));
|
.putExtra(Constants.KEY_SERVICE_ID, currentServiceId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue