Commit c5f7e373 authored by Grigory Fedorov's avatar Grigory Fedorov

New DebugSettings activity, DebugSettingsFragment and CacheClearDialog.

parent 81682f05
......@@ -361,6 +361,15 @@
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.DebugSettings"
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.ProgressDialog;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.androiddev.R;
public class CacheClearDialog extends DialogPreference {
public CacheClearDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
AccountManager.getInstance().setStatus(StatusMode.unavailable, null);
Application.getInstance().requestToClear();
Application.getInstance().requestToClose();
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getContext().getString(R.string.application_state_closing));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class DebugSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle 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 DebugSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.data.LogManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class DebugSettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_debug);
getPreferenceScreen().findPreference(getString(R.string.debug_log_key)).setEnabled(LogManager.isDebugable());
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
......@@ -14,28 +14,17 @@
*/
package com.xabber.android.ui.preferences;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import com.xabber.android.data.Application;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.connection.CertificateManager;
import com.xabber.android.data.connection.ConnectionManager;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class PreferenceEditor extends ManagedActivity
implements PreferencesFragment.OnPreferencesFragmentInteractionListener,
Preference.OnPreferenceClickListener, ConfirmDialogListener {
implements PreferencesFragment.OnPreferencesFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -57,61 +46,17 @@ public class PreferenceEditor extends ManagedActivity
SettingsManager.chatsAttentionSound();
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(getString(R.string.cache_clear_key))) {
showDialog(R.string.cache_clear_warning);
}
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case R.string.cache_clear_warning:
return new ConfirmDialogBuilder(this, R.string.cache_clear_warning,
this).setMessage(R.string.cache_clear_warning).create();
case R.string.application_state_closing:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog
.setMessage(getString(R.string.application_state_closing));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
default:
return null;
}
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case R.string.cache_clear_warning:
AccountManager.getInstance()
.setStatus(StatusMode.unavailable, null);
((Application) getApplication()).requestToClear();
Application.getInstance().requestToClose();
showDialog(R.string.application_state_closing);
break;
}
}
@Override
public void onDecline(DialogBuilder dialogBuilder) {
}
@Override
public void onCancel(DialogBuilder dialogBuilder) {
}
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
}
@Override
public Preference.OnPreferenceClickListener getOnPreferenceClickListener() {
return this;
public String getVersionName() {
try {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
}
......@@ -2,12 +2,9 @@ package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import com.xabber.android.data.LogManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
......@@ -22,28 +19,11 @@ public class PreferencesFragment extends android.preference.PreferenceFragment {
addPreferencesFromResource(R.xml.preference_editor);
Preference about = getPreferenceScreen().findPreference(getString(R.string.preference_about_key));
about.setSummary(getString(R.string.application_name) + "\n" + getVersionName());
getPreferenceScreen().findPreference(getString(R.string.cache_clear_key))
.setOnPreferenceClickListener(mListener.getOnPreferenceClickListener());
getPreferenceScreen().findPreference(getString(R.string.debug_log_key))
.setEnabled(LogManager.isDebugable());
about.setSummary(getString(R.string.application_name) + "\n" + mListener.getVersionName());
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
private String getVersionName() {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
return pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
......@@ -62,6 +42,6 @@ public class PreferencesFragment extends android.preference.PreferenceFragment {
}
public interface OnPreferencesFragmentInteractionListener {
Preference.OnPreferenceClickListener getOnPreferenceClickListener();
}
String getVersionName();
}
}
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/debug_log"
android:key="@string/debug_log_key"
android:defaultValue="@bool/debug_log_default"
/>
<com.xabber.android.ui.preferences.CacheClearDialog
android:title="@string/cache_clear"
android:key="@string/cache_clear_key"
android:dialogMessage="@string/cache_clear_warning"/>
</PreferenceScreen>
\ No newline at end of file
......@@ -70,20 +70,14 @@
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.SecuritySettings"/>
</Preference>
<PreferenceScreen
<Preference
android:title="@string/preference_debug"
android:key="@string/preference_debug"
>
<CheckBoxPreference
android:title="@string/debug_log"
android:key="@string/debug_log_key"
android:defaultValue="@bool/debug_log_default"
/>
<PreferenceScreen
android:title="@string/cache_clear"
android:key="@string/cache_clear_key"
/>
</PreferenceScreen>
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.DebugSettings"/>
</Preference>
<Preference
android:title="@string/preference_about"
android:key="@string/preference_about_key">
......
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