Commit 8f2b80f5 authored by Grigory Fedorov's avatar Grigory Fedorov

Contact list settings moved to separate preferences activity, fragment and dialog.

parent 9606bf63
......@@ -316,6 +316,15 @@
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.ContactListSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<service android:name="com.xabber.android.service.XabberService" />
<service
android:name="com.xabber.android.service.SyncAdapterService"
......
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.os.Bundle;
import com.xabber.androiddev.R;
public class ContactListSettings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
getActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ContactListSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ContactListSettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences_contact_list);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.contacts_show_accounts_key))
|| key.equals(getString(R.string.contacts_show_groups_key))) {
changeGrouping();
}
}
private void changeGrouping() {
boolean grouped = SettingsManager.contactsShowAccounts()
|| SettingsManager.contactsShowGroups();
((CheckBoxPreference) getPreferenceScreen().findPreference(
getString(R.string.contacts_stay_active_chats_key)))
.setChecked(grouped);
getPreferenceScreen().findPreference(getString(R.string.contacts_show_empty_groups_key))
.setEnabled(grouped);
}
}
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.xabber.android.data.roster.GroupManager;
public class ContactResetOfflineSettingsDialog extends DialogPreference {
public ContactResetOfflineSettingsDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
GroupManager.getInstance().resetShowOfflineModes();
}
}
}
......@@ -65,9 +65,6 @@ public class PreferenceEditor extends Activity
} else if (preference.getKey().equals(
getString(R.string.security_clear_certificate_key))) {
showDialog(R.string.security_clear_certificate_warning);
} else if (preference.getKey().equals(
getString(R.string.contacts_reset_offline_key))) {
showDialog(R.string.contacts_reset_offline_warning);
}
return false;
}
......@@ -84,10 +81,6 @@ public class PreferenceEditor extends Activity
R.string.security_clear_certificate_warning, this)
.setMessage(R.string.security_clear_certificate_warning)
.create();
case R.string.contacts_reset_offline_warning:
return new ConfirmDialogBuilder(this,
R.string.contacts_reset_offline_warning, this).setMessage(
R.string.contacts_reset_offline_warning).create();
case R.string.application_state_closing:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog
......@@ -114,9 +107,6 @@ public class PreferenceEditor extends Activity
CertificateManager.getInstance().removeCertificates();
ConnectionManager.getInstance().updateConnections(true);
break;
case R.string.contacts_reset_offline_warning:
GroupManager.getInstance().resetShowOfflineModes();
break;
}
}
......
......@@ -2,21 +2,16 @@ package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class PreferencesFragment extends android.preference.PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
public class PreferencesFragment extends android.preference.PreferenceFragment {
private OnPreferencesFragmentInteractionListener mListener;
......@@ -33,8 +28,6 @@ public class PreferencesFragment extends android.preference.PreferenceFragment
.setOnPreferenceClickListener(mListener.getOnPreferenceClickListener());
getPreferenceScreen().findPreference(getString(R.string.security_clear_certificate_key))
.setOnPreferenceClickListener(mListener.getOnPreferenceClickListener());
getPreferenceScreen().findPreference(getString(R.string.contacts_reset_offline_key))
.setOnPreferenceClickListener(mListener.getOnPreferenceClickListener());
getPreferenceScreen().findPreference(getString(R.string.debug_log_key))
.setEnabled(LogManager.isDebugable());
......@@ -51,38 +44,6 @@ public class PreferencesFragment extends android.preference.PreferenceFragment
return "";
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.contacts_show_accounts_key))) {
changeGrouping();
} else if (key.equals(getString(R.string.contacts_show_groups_key))) {
changeGrouping();
}
}
private void changeGrouping() {
boolean grouped = SettingsManager.contactsShowAccounts()
|| SettingsManager.contactsShowGroups();
((CheckBoxPreference) getPreferenceScreen().findPreference(
getString(R.string.contacts_stay_active_chats_key)))
.setChecked(grouped);
getPreferenceScreen().findPreference(getString(R.string.contacts_show_empty_groups_key))
.setEnabled(grouped);
}
@Override
......
......@@ -30,63 +30,14 @@
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ThemeSettings"/>
</Preference>
<PreferenceScreen
<Preference
android:title="@string/preference_contacts"
android:key="@string/preference_contacts"
>
<CheckBoxPreference
android:title="@string/contacts_show_panel"
android:key="@string/contacts_show_panel_key"
android:defaultValue="@bool/contacts_show_panel_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_avatars"
android:key="@string/contacts_show_avatars_key"
android:defaultValue="@bool/contacts_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_offline"
android:key="@string/contacts_show_offline_key"
android:defaultValue="@bool/contacts_show_offline_default"
/>
<PreferenceScreen
android:title="@string/contacts_reset_offline"
android:key="@string/contacts_reset_offline_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_groups"
android:key="@string/contacts_show_groups_key"
android:defaultValue="@bool/contacts_show_groups_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_accounts"
android:key="@string/contacts_show_accounts_key"
android:defaultValue="@bool/contacts_show_accounts_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_active_chats"
android:key="@string/contacts_show_active_chats_key"
android:defaultValue="@bool/contacts_show_active_chats_default"
/>
<CheckBoxPreference
android:title="@string/contacts_stay_active_chats"
android:key="@string/contacts_stay_active_chats_key"
android:defaultValue="@bool/contacts_stay_active_chats_default"
android:dependency="@string/contacts_show_active_chats_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_empty_groups"
android:key="@string/contacts_show_empty_groups_key"
android:defaultValue="@bool/contacts_show_empty_groups_default"
/>
<ListPreference
android:title="@string/contacts_order"
android:key="@string/contacts_order_key"
android:entries="@array/contacts_order_entries"
android:entryValues="@array/contacts_order_entryvalues"
android:defaultValue="@string/contacts_order_default"
/>
</PreferenceScreen>
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ContactListSettings"/>
</Preference>
<PreferenceScreen
android:title="@string/preference_chats"
android:key="@string/preference_chats"
......
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/contacts_show_panel"
android:key="@string/contacts_show_panel_key"
android:defaultValue="@bool/contacts_show_panel_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_avatars"
android:key="@string/contacts_show_avatars_key"
android:defaultValue="@bool/contacts_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_offline"
android:key="@string/contacts_show_offline_key"
android:defaultValue="@bool/contacts_show_offline_default"
/>
<com.xabber.android.ui.preferences.ContactResetOfflineSettingsDialog
android:title="@string/contacts_reset_offline"
android:key="@string/contacts_reset_offline_key"
android:dialogMessage="@string/contacts_reset_offline_warning"/>
<CheckBoxPreference
android:title="@string/contacts_show_groups"
android:key="@string/contacts_show_groups_key"
android:defaultValue="@bool/contacts_show_groups_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_accounts"
android:key="@string/contacts_show_accounts_key"
android:defaultValue="@bool/contacts_show_accounts_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_active_chats"
android:key="@string/contacts_show_active_chats_key"
android:defaultValue="@bool/contacts_show_active_chats_default"
/>
<CheckBoxPreference
android:title="@string/contacts_stay_active_chats"
android:key="@string/contacts_stay_active_chats_key"
android:defaultValue="@bool/contacts_stay_active_chats_default"
android:dependency="@string/contacts_show_active_chats_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_empty_groups"
android:key="@string/contacts_show_empty_groups_key"
android:defaultValue="@bool/contacts_show_empty_groups_default"
/>
<ListPreference
android:title="@string/contacts_order"
android:key="@string/contacts_order_key"
android:entries="@array/contacts_order_entries"
android:entryValues="@array/contacts_order_entryvalues"
android:defaultValue="@string/contacts_order_default"
/>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment