2014-03-01 22:17:55 +00:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.preference.DialogPreference;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
|
|
|
public class OutgoingSmsPreference extends DialogPreference {
|
|
|
|
private CheckBox dataUsers;
|
|
|
|
private CheckBox askForFallback;
|
2014-12-12 00:10:11 +00:00
|
|
|
private CheckBox neverFallbackMms;
|
2014-03-01 22:17:55 +00:00
|
|
|
private CheckBox nonDataUsers;
|
2014-12-12 00:10:11 +00:00
|
|
|
|
|
|
|
|
2014-03-01 22:17:55 +00:00
|
|
|
public OutgoingSmsPreference(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
setPersistent(false);
|
|
|
|
setDialogLayoutResource(R.layout.outgoing_sms_preference);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onBindDialogView(final View view) {
|
|
|
|
super.onBindDialogView(view);
|
2014-12-12 00:10:11 +00:00
|
|
|
dataUsers = (CheckBox) view.findViewById(R.id.data_users);
|
|
|
|
askForFallback = (CheckBox) view.findViewById(R.id.ask_before_fallback_data);
|
|
|
|
neverFallbackMms = (CheckBox) view.findViewById(R.id.never_send_mms);
|
|
|
|
nonDataUsers = (CheckBox) view.findViewById(R.id.non_data_users);
|
2014-03-01 22:17:55 +00:00
|
|
|
|
2014-06-13 21:22:53 +00:00
|
|
|
dataUsers.setChecked(TextSecurePreferences.isFallbackSmsAllowed(getContext()));
|
|
|
|
askForFallback.setChecked(TextSecurePreferences.isFallbackSmsAskRequired(getContext()));
|
2014-12-12 00:10:11 +00:00
|
|
|
neverFallbackMms.setChecked(!TextSecurePreferences.isFallbackMmsEnabled(getContext()));
|
2014-06-13 21:22:53 +00:00
|
|
|
nonDataUsers.setChecked(TextSecurePreferences.isDirectSmsAllowed(getContext()));
|
2014-03-01 22:17:55 +00:00
|
|
|
|
|
|
|
dataUsers.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-12-12 06:46:59 +00:00
|
|
|
updateEnabledViews();
|
2014-03-01 22:17:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-12 06:46:59 +00:00
|
|
|
updateEnabledViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEnabledViews() {
|
2014-03-01 22:17:55 +00:00
|
|
|
askForFallback.setEnabled(dataUsers.isChecked());
|
2014-12-12 06:46:59 +00:00
|
|
|
neverFallbackMms.setEnabled(dataUsers.isChecked());
|
2014-03-01 22:17:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDialogClosed(boolean positiveResult) {
|
|
|
|
super.onDialogClosed(positiveResult);
|
|
|
|
|
|
|
|
if (positiveResult) {
|
2014-06-13 21:22:53 +00:00
|
|
|
TextSecurePreferences.setFallbackSmsAllowed(getContext(), dataUsers.isChecked());
|
|
|
|
TextSecurePreferences.setFallbackSmsAskRequired(getContext(), askForFallback.isChecked());
|
|
|
|
TextSecurePreferences.setDirectSmsAllowed(getContext(), nonDataUsers.isChecked());
|
2014-12-12 00:10:11 +00:00
|
|
|
TextSecurePreferences.setFallbackMmsEnabled(getContext(), !neverFallbackMms.isChecked());
|
2014-03-01 22:17:55 +00:00
|
|
|
if (getOnPreferenceChangeListener() != null) getOnPreferenceChangeListener().onPreferenceChange(this, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|