Use new result API (#5875)

* remove unused result expectancy for settings screen launch

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* initial refactor to new result api, wip

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* refactor camera launcher

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* revert callback for video handling

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* invoke callbacks when cancelled

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* handle gallery picker result based on preference

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* remove old method of refactoring for file picker

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* remove legacy result handling callback

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* request code used for handling result was never used for launching an activity, hence removed

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* extract voice result handling into function

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* refactor test

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* remove unused tests

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* cleanup

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* fix-docs

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* add space after ,

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

---------

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
Parneet Singh 2024-10-23 18:28:39 +05:30 committed by GitHub
parent f1205c19be
commit 1e7aabad16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 407 additions and 487 deletions

View file

@ -21,6 +21,7 @@ import android.widget.TextView;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
import androidx.preference.ListPreference;
import androidx.preference.MultiSelectListPreference;
import androidx.preference.Preference;
@ -85,6 +86,15 @@ public class SettingsFragment extends PreferenceFragmentCompat {
private View separator;
private ListView languageHistoryListView;
private static final String GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content";
private final ActivityResultLauncher<Intent> cameraPickLauncherForResult =
registerForActivityResult(new StartActivityForResult(),
result -> {
contributionController.handleActivityResultWithCallback(requireActivity(), callbacks -> {
contributionController.onPictureReturnedFromCamera(result, requireActivity(), callbacks);
});
});
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@Override
public void onActivityResult(Map<String, Boolean> result) {
@ -93,7 +103,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
areAllGranted = areAllGranted && b;
}
if (!areAllGranted && shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher);
contributionController.handleShowRationaleFlowCameraLocation(getActivity(), inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult);
}
}
});