mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 14:28:25 +00:00
Show confirmation box before disabling push messages
This commit is contained in:
parent
367b481d07
commit
2f7c005c23
@ -23,6 +23,11 @@
|
|||||||
<string name="ApplicationPreferencesActivity_disable">Disable</string>
|
<string name="ApplicationPreferencesActivity_disable">Disable</string>
|
||||||
<string name="ApplicationPreferencesActivity_unregistering">Unregistering...</string>
|
<string name="ApplicationPreferencesActivity_unregistering">Unregistering...</string>
|
||||||
<string name="ApplicationPreferencesActivity_unregistering_for_data_based_communication">Unregistering for data based communication</string>
|
<string name="ApplicationPreferencesActivity_unregistering_for_data_based_communication">Unregistering for data based communication</string>
|
||||||
|
<string name="ApplicationPreferencesActivity_disable_push_messages">Disable push messages?</string>
|
||||||
|
<string name="ApplicationPreferencesActivity_this_will_disable_push_messages">
|
||||||
|
This will disable push messages by unregistering you from the server.
|
||||||
|
You will need to re-register your phone number to use push messages again in the future.
|
||||||
|
</string>
|
||||||
<string name="ApplicationPreferencesActivity_error_connecting_to_server">Error connecting to server!</string>
|
<string name="ApplicationPreferencesActivity_error_connecting_to_server">Error connecting to server!</string>
|
||||||
<string name="ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service">You are not registered with the push service...</string>
|
<string name="ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service">You are not registered with the push service...</string>
|
||||||
<string name="ApplicationPreferencesActivity_updating_directory">Updating directory</string>
|
<string name="ApplicationPreferencesActivity_updating_directory">Updating directory</string>
|
||||||
|
@ -324,56 +324,74 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
|||||||
private static final int SUCCESS = 0;
|
private static final int SUCCESS = 0;
|
||||||
private static final int NETWORK_ERROR = 1;
|
private static final int NETWORK_ERROR = 1;
|
||||||
|
|
||||||
|
private class DisablePushMessagesTask extends AsyncTask<Void, Void, Integer> {
|
||||||
|
private ProgressDialog dialog;
|
||||||
|
private final Preference preference;
|
||||||
|
|
||||||
|
public DisablePushMessagesTask(final Preference preference) {
|
||||||
|
this.preference = preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
dialog = ProgressDialog.show(ApplicationPreferencesActivity.this,
|
||||||
|
getString(R.string.ApplicationPreferencesActivity_unregistering),
|
||||||
|
getString(R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication),
|
||||||
|
true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Integer result) {
|
||||||
|
if (dialog != null)
|
||||||
|
dialog.dismiss();
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case NETWORK_ERROR:
|
||||||
|
Toast.makeText(ApplicationPreferencesActivity.this,
|
||||||
|
getString(R.string.ApplicationPreferencesActivity_error_connecting_to_server),
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
|
((CheckBoxPreference)preference).setChecked(false);
|
||||||
|
TextSecurePreferences.setPushRegistered(ApplicationPreferencesActivity.this, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground(Void... params) {
|
||||||
|
try {
|
||||||
|
Context context = ApplicationPreferencesActivity.this;
|
||||||
|
PushServiceSocket socket = PushServiceSocketFactory.create(context);
|
||||||
|
|
||||||
|
socket.unregisterGcmId();
|
||||||
|
GCMRegistrar.unregister(context);
|
||||||
|
return SUCCESS;
|
||||||
|
} catch (AuthorizationFailedException afe) {
|
||||||
|
Log.w("ApplicationPreferencesActivity", afe);
|
||||||
|
return SUCCESS;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
Log.w("ApplicationPreferencesActivity", ioe);
|
||||||
|
return NETWORK_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||||
if (((CheckBoxPreference)preference).isChecked()) {
|
if (((CheckBoxPreference)preference).isChecked()) {
|
||||||
new AsyncTask<Void, Void, Integer>() {
|
AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationPreferencesActivity.this);
|
||||||
private ProgressDialog dialog;
|
builder.setIcon(android.R.drawable.ic_dialog_info);
|
||||||
|
builder.setTitle(getString(R.string.ApplicationPreferencesActivity_disable_push_messages));
|
||||||
|
builder.setMessage(getString(R.string.ApplicationPreferencesActivity_this_will_disable_push_messages));
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, null);
|
||||||
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog = ProgressDialog.show(ApplicationPreferencesActivity.this,
|
new DisablePushMessagesTask(preference).execute();
|
||||||
getString(R.string.ApplicationPreferencesActivity_unregistering),
|
|
||||||
getString(R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication),
|
|
||||||
true, false);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
@Override
|
builder.show();
|
||||||
protected void onPostExecute(Integer result) {
|
|
||||||
if (dialog != null)
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
switch (result) {
|
|
||||||
case NETWORK_ERROR:
|
|
||||||
Toast.makeText(ApplicationPreferencesActivity.this,
|
|
||||||
getString(R.string.ApplicationPreferencesActivity_error_connecting_to_server),
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
break;
|
|
||||||
case SUCCESS:
|
|
||||||
((CheckBoxPreference)preference).setChecked(false);
|
|
||||||
TextSecurePreferences.setPushRegistered(ApplicationPreferencesActivity.this, false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground(Void... params) {
|
|
||||||
try {
|
|
||||||
Context context = ApplicationPreferencesActivity.this;
|
|
||||||
PushServiceSocket socket = PushServiceSocketFactory.create(context);
|
|
||||||
|
|
||||||
socket.unregisterGcmId();
|
|
||||||
GCMRegistrar.unregister(context);
|
|
||||||
return SUCCESS;
|
|
||||||
} catch (AuthorizationFailedException afe) {
|
|
||||||
Log.w("ApplicationPreferencesActivity", afe);
|
|
||||||
return SUCCESS;
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
Log.w("ApplicationPreferencesActivity", ioe);
|
|
||||||
return NETWORK_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(ApplicationPreferencesActivity.this, RegistrationActivity.class);
|
Intent intent = new Intent(ApplicationPreferencesActivity.this, RegistrationActivity.class);
|
||||||
intent.putExtra("master_secret", getIntent().getParcelableExtra("master_secret"));
|
intent.putExtra("master_secret", getIntent().getParcelableExtra("master_secret"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user