Change where edit profile screen requests camera permission.
parent
92ecf2d5de
commit
a3438c4f8d
|
@ -1,6 +1,5 @@
|
||||||
package org.thoughtcrime.securesms.groups.ui.creategroup.details;
|
package org.thoughtcrime.securesms.groups.ui.creategroup.details;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -37,7 +36,6 @@ import org.thoughtcrime.securesms.mediasend.AvatarSelectionBottomSheetDialogFrag
|
||||||
import org.thoughtcrime.securesms.mediasend.Media;
|
import org.thoughtcrime.securesms.mediasend.Media;
|
||||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
|
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
|
||||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
|
@ -253,12 +251,8 @@ public class AddGroupDetailsFragment extends LoggingFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAvatarSelectionBottomSheet() {
|
private void showAvatarSelectionBottomSheet() {
|
||||||
Permissions.with(this)
|
AvatarSelectionBottomSheetDialogFragment.create(viewModel.hasAvatar(), true, REQUEST_CODE_AVATAR, true)
|
||||||
.request(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
.show(getChildFragmentManager(), "BOTTOM");
|
||||||
.ifNecessary()
|
|
||||||
.onAnyResult(() -> AvatarSelectionBottomSheetDialogFragment.create(viewModel.hasAvatar(), true, REQUEST_CODE_AVATAR, true)
|
|
||||||
.show(getChildFragmentManager(), "BOTTOM"))
|
|
||||||
.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package org.thoughtcrime.securesms.mediasend;
|
package org.thoughtcrime.securesms.mediasend;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.AttrRes;
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -21,6 +23,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ClearProfileAvatarActivity;
|
import org.thoughtcrime.securesms.ClearProfileAvatarActivity;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -68,7 +71,7 @@ public class AvatarSelectionBottomSheetDialogFragment extends BottomSheetDialogF
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (getOptionsCount() == 1) {
|
if (getOptionsCount() == 1) {
|
||||||
launchOptionAndDismiss(getOptionsFromArguments().get(0));
|
askForPermissionIfNeededAndLaunch(getOptionsFromArguments().get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +83,12 @@ public class AvatarSelectionBottomSheetDialogFragment extends BottomSheetDialogF
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
RecyclerView recyclerView = view.findViewById(R.id.avatar_selection_bottom_sheet_dialog_fragment_recycler);
|
RecyclerView recyclerView = view.findViewById(R.id.avatar_selection_bottom_sheet_dialog_fragment_recycler);
|
||||||
recyclerView.setAdapter(new SelectionOptionAdapter(getOptionsFromArguments(), this::launchOptionAndDismiss));
|
recyclerView.setAdapter(new SelectionOptionAdapter(getOptionsFromArguments(), this::askForPermissionIfNeededAndLaunch));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@ -95,6 +103,20 @@ public class AvatarSelectionBottomSheetDialogFragment extends BottomSheetDialogF
|
||||||
return Stream.of(optionCodes).map(SelectionOption::fromCode).toList();
|
return Stream.of(optionCodes).map(SelectionOption::fromCode).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void askForPermissionIfNeededAndLaunch(@NonNull SelectionOption option) {
|
||||||
|
if (option == SelectionOption.CAPTURE) {
|
||||||
|
Permissions.with(this)
|
||||||
|
.request(Manifest.permission.CAMERA)
|
||||||
|
.ifNecessary()
|
||||||
|
.onAllGranted(() -> launchOptionAndDismiss(option))
|
||||||
|
.onAnyDenied(() -> Toast.makeText(requireContext(), R.string.AvatarSelectionBottomSheetDialogFragment__taking_a_photo_requires_the_camera_permission, Toast.LENGTH_SHORT)
|
||||||
|
.show())
|
||||||
|
.execute();
|
||||||
|
} else {
|
||||||
|
launchOptionAndDismiss(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void launchOptionAndDismiss(@NonNull SelectionOption option) {
|
private void launchOptionAndDismiss(@NonNull SelectionOption option) {
|
||||||
Intent intent = createIntent(requireContext(), option, requireArguments().getBoolean(ARG_IS_GROUP));
|
Intent intent = createIntent(requireContext(), option, requireArguments().getBoolean(ARG_IS_GROUP));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.thoughtcrime.securesms.profiles.edit;
|
package org.thoughtcrime.securesms.profiles.edit;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -38,7 +37,6 @@ import org.thoughtcrime.securesms.mediasend.AvatarSelectionActivity;
|
||||||
import org.thoughtcrime.securesms.mediasend.AvatarSelectionBottomSheetDialogFragment;
|
import org.thoughtcrime.securesms.mediasend.AvatarSelectionBottomSheetDialogFragment;
|
||||||
import org.thoughtcrime.securesms.mediasend.Media;
|
import org.thoughtcrime.securesms.mediasend.Media;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||||
import org.thoughtcrime.securesms.registration.RegistrationUtil;
|
import org.thoughtcrime.securesms.registration.RegistrationUtil;
|
||||||
|
@ -152,11 +150,6 @@ public class EditProfileFragment extends LoggingFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
||||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
@ -232,11 +225,7 @@ public class EditProfileFragment extends LoggingFragment {
|
||||||
usernameLabel.setVisibility(View.VISIBLE);
|
usernameLabel.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.avatar.setOnClickListener(v -> Permissions.with(this)
|
this.avatar.setOnClickListener(v -> startAvatarSelection());
|
||||||
.request(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
||||||
.ifNecessary()
|
|
||||||
.onAnyResult(this::startAvatarSelection)
|
|
||||||
.execute());
|
|
||||||
|
|
||||||
this.givenName .addTextChangedListener(new AfterTextChanged(s -> {
|
this.givenName .addTextChangedListener(new AfterTextChanged(s -> {
|
||||||
trimInPlace(s, isEditingGroup);
|
trimInPlace(s, isEditingGroup);
|
||||||
|
|
|
@ -387,6 +387,7 @@
|
||||||
<string name="AvatarSelectionBottomSheetDialogFragment__take_photo">Take photo</string>
|
<string name="AvatarSelectionBottomSheetDialogFragment__take_photo">Take photo</string>
|
||||||
<string name="AvatarSelectionBottomSheetDialogFragment__choose_from_gallery">Choose from gallery</string>
|
<string name="AvatarSelectionBottomSheetDialogFragment__choose_from_gallery">Choose from gallery</string>
|
||||||
<string name="AvatarSelectionBottomSheetDialogFragment__remove_photo">Remove photo</string>
|
<string name="AvatarSelectionBottomSheetDialogFragment__remove_photo">Remove photo</string>
|
||||||
|
<string name="AvatarSelectionBottomSheetDialogFragment__taking_a_photo_requires_the_camera_permission">Taking a photo requires the camera permission.</string>
|
||||||
|
|
||||||
<!-- DateUtils -->
|
<!-- DateUtils -->
|
||||||
<string name="DateUtils_just_now">Now</string>
|
<string name="DateUtils_just_now">Now</string>
|
||||||
|
|
Loading…
Reference in New Issue