always show contact permission explain dialog on Quicksy
Until now Conversations and Quicksy would only disply the dialog that explains why we want contact read permissions after the user rejected the request once (following Android design guidelines and `shouldShowRequestPermissionRationale()`) However for PlayStore policy this is no longer enough and the app needs to explain and ask for consent before starting to upload the data. This commit now displays the explain dialog immediately before asking for the first time.
This commit is contained in:
parent
f9b292fd6a
commit
ec061bedc1
|
@ -39,6 +39,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
@ -731,7 +732,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||||
if (mRequestedContactsPermission.compareAndSet(false, true)) {
|
if (mRequestedContactsPermission.compareAndSet(false, true)) {
|
||||||
if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
|
if (QuickConversationsService.isQuicksy() || shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
final AtomicBoolean requestPermission = new AtomicBoolean(false);
|
final AtomicBoolean requestPermission = new AtomicBoolean(false);
|
||||||
builder.setTitle(R.string.sync_with_contacts);
|
builder.setTitle(R.string.sync_with_contacts);
|
||||||
|
@ -740,20 +741,26 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
} else {
|
} else {
|
||||||
builder.setMessage(getString(R.string.sync_with_contacts_long, getString(R.string.app_name)));
|
builder.setMessage(getString(R.string.sync_with_contacts_long, getString(R.string.app_name)));
|
||||||
}
|
}
|
||||||
builder.setPositiveButton(R.string.next, (dialog, which) -> {
|
@StringRes int confirmButtonText;
|
||||||
|
if (QuickConversationsService.isConversations()) {
|
||||||
|
confirmButtonText = R.string.next;
|
||||||
|
} else {
|
||||||
|
confirmButtonText = R.string.confirm;
|
||||||
|
}
|
||||||
|
builder.setPositiveButton(confirmButtonText, (dialog, which) -> {
|
||||||
if (requestPermission.compareAndSet(false, true)) {
|
if (requestPermission.compareAndSet(false, true)) {
|
||||||
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setOnDismissListener(dialog -> {
|
builder.setOnDismissListener(dialog -> {
|
||||||
if (requestPermission.compareAndSet(false, true)) {
|
if (QuickConversationsService.isConversations() && requestPermission.compareAndSet(false, true)) {
|
||||||
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setCancelable(false);
|
builder.setCancelable(QuickConversationsService.isQuicksy());
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
dialog.setCanceledOnTouchOutside(QuickConversationsService.isQuicksy());
|
||||||
dialog.setOnShowListener(dialogInterface -> {
|
dialog.setOnShowListener(dialogInterface -> {
|
||||||
final TextView tv = dialog.findViewById(android.R.id.message);
|
final TextView tv = dialog.findViewById(android.R.id.message);
|
||||||
if (tv != null) {
|
if (tv != null) {
|
||||||
|
|
Loading…
Reference in a new issue