mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 15:13:50 +00:00
committed by
Moxie Marlinspike
parent
142f84703b
commit
0f572d1e5d
@@ -16,22 +16,14 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
|
||||
@@ -40,20 +32,11 @@ import org.thoughtcrime.securesms.preferences.AppearancePreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.StoragePreferenceFragment;
|
||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.Dialogs;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
||||
import org.thoughtcrime.securesms.util.ResUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.AuthorizationFailedException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The Activity for application preference display and management.
|
||||
@@ -74,8 +57,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
private static final String PREFERENCE_CATEGORY_STORAGE = "preference_category_storage";
|
||||
private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
|
||||
|
||||
private static final String PUSH_MESSAGING_PREF = "pref_toggle_push_messaging";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
@@ -146,11 +127,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
initializePushMessagingToggle();
|
||||
|
||||
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS));
|
||||
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
|
||||
@@ -228,89 +206,5 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePushMessagingToggle() {
|
||||
CheckBoxPreference preference = (CheckBoxPreference)this.findPreference(PUSH_MESSAGING_PREF);
|
||||
preference.setChecked(TextSecurePreferences.isPushRegistered(getActivity()));
|
||||
preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
|
||||
}
|
||||
|
||||
private class PushMessagingClickListener implements Preference.OnPreferenceChangeListener {
|
||||
private static final int SUCCESS = 0;
|
||||
private static final int NETWORK_ERROR = 1;
|
||||
|
||||
private class DisablePushMessagesTask extends ProgressDialogAsyncTask<Void, Void, Integer> {
|
||||
private final CheckBoxPreference checkBoxPreference;
|
||||
|
||||
public DisablePushMessagesTask(final CheckBoxPreference checkBoxPreference) {
|
||||
super(getActivity(), R.string.ApplicationPreferencesActivity_unregistering, R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication);
|
||||
this.checkBoxPreference = checkBoxPreference;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer result) {
|
||||
super.onPostExecute(result);
|
||||
switch (result) {
|
||||
case NETWORK_ERROR:
|
||||
Toast.makeText(getActivity(),
|
||||
R.string.ApplicationPreferencesActivity_error_connecting_to_server,
|
||||
Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case SUCCESS:
|
||||
checkBoxPreference.setChecked(false);
|
||||
TextSecurePreferences.setPushRegistered(getActivity(), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void... params) {
|
||||
try {
|
||||
Context context = getActivity();
|
||||
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
|
||||
|
||||
accountManager.setGcmId(Optional.<String>absent());
|
||||
GoogleCloudMessaging.getInstance(context).unregister();
|
||||
|
||||
return SUCCESS;
|
||||
} catch (AuthorizationFailedException afe) {
|
||||
Log.w(TAG, afe);
|
||||
return SUCCESS;
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
return NETWORK_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
if (((CheckBoxPreference)preference).isChecked()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setIcon(ResUtil.getDrawable(getActivity(), R.attr.dialog_info_icon));
|
||||
builder.setTitle(R.string.ApplicationPreferencesActivity_disable_push_messages);
|
||||
builder.setMessage(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
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new DisablePushMessagesTask((CheckBoxPreference)preference).execute();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
} else {
|
||||
Intent nextIntent = new Intent(getActivity(), ApplicationPreferencesActivity.class);
|
||||
nextIntent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret"));
|
||||
|
||||
Intent intent = new Intent(getActivity(), RegistrationActivity.class);
|
||||
intent.putExtra("cancel_button", true);
|
||||
intent.putExtra("next_intent", nextIntent);
|
||||
intent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret"));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.LogSubmitActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.RegistrationActivity;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
||||
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
||||
import org.thoughtcrime.securesms.util.ResUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.AuthorizationFailedException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AdvancedPreferenceFragment extends PreferenceFragment {
|
||||
private static final String TAG = AdvancedPreferenceFragment.class.getSimpleName();
|
||||
|
||||
private static final String PUSH_MESSAGING_PREF = "pref_toggle_push_messaging";
|
||||
private static final String SUBMIT_DEBUG_LOG_PREF = "pref_submit_debug_logs";
|
||||
|
||||
private static final int PICK_IDENTITY_CONTACT = 1;
|
||||
@@ -28,6 +45,7 @@ public class AdvancedPreferenceFragment extends PreferenceFragment {
|
||||
super.onCreate(paramBundle);
|
||||
addPreferencesFromResource(R.xml.preferences_advanced);
|
||||
|
||||
initializePushMessagingToggle();
|
||||
initializeIdentitySelection();
|
||||
|
||||
this.findPreference(SUBMIT_DEBUG_LOG_PREF)
|
||||
@@ -50,6 +68,12 @@ public class AdvancedPreferenceFragment extends PreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePushMessagingToggle() {
|
||||
CheckBoxPreference preference = (CheckBoxPreference)this.findPreference(PUSH_MESSAGING_PREF);
|
||||
preference.setChecked(TextSecurePreferences.isPushRegistered(getActivity()));
|
||||
preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
|
||||
}
|
||||
|
||||
private void initializeIdentitySelection() {
|
||||
ContactIdentityManager identity = ContactIdentityManager.getInstance(getActivity());
|
||||
|
||||
@@ -97,4 +121,82 @@ public class AdvancedPreferenceFragment extends PreferenceFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class PushMessagingClickListener implements Preference.OnPreferenceChangeListener {
|
||||
private static final int SUCCESS = 0;
|
||||
private static final int NETWORK_ERROR = 1;
|
||||
|
||||
private class DisablePushMessagesTask extends ProgressDialogAsyncTask<Void, Void, Integer> {
|
||||
private final CheckBoxPreference checkBoxPreference;
|
||||
|
||||
public DisablePushMessagesTask(final CheckBoxPreference checkBoxPreference) {
|
||||
super(getActivity(), R.string.ApplicationPreferencesActivity_unregistering, R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication);
|
||||
this.checkBoxPreference = checkBoxPreference;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer result) {
|
||||
super.onPostExecute(result);
|
||||
switch (result) {
|
||||
case NETWORK_ERROR:
|
||||
Toast.makeText(getActivity(),
|
||||
R.string.ApplicationPreferencesActivity_error_connecting_to_server,
|
||||
Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case SUCCESS:
|
||||
checkBoxPreference.setChecked(false);
|
||||
TextSecurePreferences.setPushRegistered(getActivity(), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void... params) {
|
||||
try {
|
||||
Context context = getActivity();
|
||||
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
|
||||
|
||||
accountManager.setGcmId(Optional.<String>absent());
|
||||
GoogleCloudMessaging.getInstance(context).unregister();
|
||||
|
||||
return SUCCESS;
|
||||
} catch (AuthorizationFailedException afe) {
|
||||
Log.w(TAG, afe);
|
||||
return SUCCESS;
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
return NETWORK_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
if (((CheckBoxPreference)preference).isChecked()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setIcon(ResUtil.getDrawable(getActivity(), R.attr.dialog_info_icon));
|
||||
builder.setTitle(R.string.ApplicationPreferencesActivity_disable_push_messages);
|
||||
builder.setMessage(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
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new DisablePushMessagesTask((CheckBoxPreference)preference).execute();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
} else {
|
||||
Intent nextIntent = new Intent(getActivity(), ApplicationPreferencesActivity.class);
|
||||
nextIntent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret"));
|
||||
|
||||
Intent intent = new Intent(getActivity(), RegistrationActivity.class);
|
||||
intent.putExtra("cancel_button", true);
|
||||
intent.putExtra("next_intent", nextIntent);
|
||||
intent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret"));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,29 +81,23 @@ public class SmsMmsPreferenceFragment extends PreferenceFragment {
|
||||
}
|
||||
|
||||
public static CharSequence getSummary(Context context) {
|
||||
return getIncomingSmsSummary(context);
|
||||
}
|
||||
final String on = context.getString(R.string.ApplicationPreferencesActivity_on);
|
||||
final String onCaps = context.getString(R.string.ApplicationPreferencesActivity_On);
|
||||
final String off = context.getString(R.string.ApplicationPreferencesActivity_off);
|
||||
final String offCaps = context.getString(R.string.ApplicationPreferencesActivity_Off);
|
||||
final int smsMmsSummaryResId = R.string.ApplicationPreferencesActivity_sms_mms_summary;
|
||||
|
||||
private static CharSequence getIncomingSmsSummary(Context context) {
|
||||
final int onResId = R.string.ApplicationPreferencesActivity_on;
|
||||
final int offResId = R.string.ApplicationPreferencesActivity_off;
|
||||
final int smsResId = R.string.ApplicationPreferencesActivity_sms;
|
||||
final int mmsResId = R.string.ApplicationPreferencesActivity_mms;
|
||||
final int incomingSmsResId = R.string.ApplicationPreferencesActivity_incoming_sms_summary;
|
||||
|
||||
final int incomingSmsSummary;
|
||||
boolean postKitkatSMS = Util.isDefaultSmsProvider(context);
|
||||
boolean preKitkatSMS = TextSecurePreferences.isInterceptAllSmsEnabled(context);
|
||||
boolean preKitkatMMS = TextSecurePreferences.isInterceptAllMmsEnabled(context);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (postKitkatSMS) incomingSmsSummary = onResId;
|
||||
else incomingSmsSummary = offResId;
|
||||
if (postKitkatSMS) return onCaps;
|
||||
else return offCaps;
|
||||
} else {
|
||||
if (preKitkatSMS && preKitkatMMS) incomingSmsSummary = onResId;
|
||||
else if (preKitkatSMS && !preKitkatMMS) incomingSmsSummary = smsResId;
|
||||
else if (!preKitkatSMS && preKitkatMMS) incomingSmsSummary = mmsResId;
|
||||
else incomingSmsSummary = offResId;
|
||||
if (preKitkatSMS && preKitkatMMS) return onCaps;
|
||||
else if (preKitkatSMS && !preKitkatMMS) return context.getString(smsMmsSummaryResId, on, off);
|
||||
else if (!preKitkatSMS && preKitkatMMS) return context.getString(smsMmsSummaryResId, off, on);
|
||||
else return offCaps;
|
||||
}
|
||||
return context.getString(incomingSmsResId, context.getString(incomingSmsSummary));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user