Commit e3b2429e authored by Grigory Fedorov's avatar Grigory Fedorov

Key phrase adding implemented as "full screen" dialog with "close" and "save"...

Key phrase adding implemented as "full screen" dialog with "close" and "save" buttons on the action bar.
Separate activities PhraseAdder for phrase adding, PhraseEditor - for editing, BasePhrasePreferences - base activity for both.
BaseSettingsFragment: preferences don't saved on pause! derived class should call saveChanges explicitly.
parent a7909405
......@@ -294,6 +294,16 @@
android:value="com.xabber.android.ui.preferences.PhraseList" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.PhraseAdder"
android:parentActivityName="com.xabber.android.ui.preferences.PhraseList">
<!-- 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.PhraseList" />
</activity>
<activity
android:name="com.xabber.android.ui.ReconnectionActivity"
/>
......
......@@ -49,6 +49,12 @@ public class AccountEditorFragment extends BaseSettingsFragment
AccountManager.getInstance().removeAuthorizationError(mListener.getAccount());
}
@Override
public void onPause() {
super.onPause();
saveChanges();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (getString(R.string.account_port_key).equals(preference.getKey()))
......
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public abstract class BasePhrasePreferences extends ManagedActivity
implements PhraseEditorFragment.OnPhraseEditorFragmentInteractionListener {
private Phrase phrase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_preferences);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
}
}
@Override
public Phrase getPhrase() {
return phrase;
}
@Override
public void setPhrase(Phrase phrase) {
this.phrase = phrase;
}
}
......@@ -16,7 +16,8 @@ import com.xabber.android.ui.widget.RingtonePreference;
import java.util.HashMap;
import java.util.Map;
public abstract class BaseSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
public abstract class BaseSettingsFragment extends PreferenceFragment
implements Preference.OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -43,12 +44,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragment implements
}
}
@Override
public void onPause() {
super.onPause();
operation(Operation.save);
}
/**
* Inflates layout.
*
......@@ -189,7 +184,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragment implements
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
result.put(preference.getKey(), getPrefecence(preference, source));
result.put(preference.getKey(), getPreference(preference, source));
}
return result;
}
......@@ -201,11 +196,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragment implements
* @param source
* @return
*/
protected Object getPrefecence(Preference preference,
Map<String, Object> source) {
if (preference instanceof PreferenceScreen)
protected Object getPreference(Preference preference, Map<String, Object> source) {
if (preference instanceof PreferenceScreen) {
return null;
else if (preference instanceof EditTextPreference) {
} else if (preference instanceof EditTextPreference) {
String value = ((EditTextPreference) preference).getText();
if (source.get(preference.getKey()) instanceof Integer)
try {
......@@ -234,4 +228,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragment implements
*/
protected abstract boolean setValues(Map<String, Object> source, Map<String, Object> result);
protected boolean saveChanges() {
return operation(Operation.save);
}
}
......@@ -29,6 +29,12 @@ public class ChatEditorFragment extends BaseSettingsFragment {
}
}
@Override
public void onPause() {
super.onPause();
saveChanges();
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> map = new HashMap<>();
......
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.androiddev.R;
public class PhraseAdder extends BasePhrasePreferences {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.phrase_add);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.save, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_save:
boolean success = ((PhraseEditorFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container)).saveChanges();
if (success) {
finish();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public static Intent createIntent(Context context) {
return new SegmentIntentBuilder<>(context, PhraseAdder.class).build();
}
}
......@@ -22,13 +22,9 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class PhraseEditor extends ManagedActivity
implements PhraseEditorFragment.OnPhraseEditorFragmentInteractionListener {
private Phrase phrase;
public class PhraseEditor extends BasePhrasePreferences {
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -36,44 +32,34 @@ public class PhraseEditor extends ManagedActivity
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Integer index = getPhraseIndex(getIntent());
if (index == null) {
phrase = null;
setTitle(R.string.phrase_add);
} else {
phrase = PhraseManager.getInstance().getPhrase(index);
if (phrase == null) {
finish();
return;
}
String title = phrase.getText();
if ("".equals(title))
title = Application.getInstance().getString(
R.string.phrase_empty);
setTitle(title);
finish();
return;
}
setContentView(R.layout.activity_preferences);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
Phrase phrase = PhraseManager.getInstance().getPhrase(index);
if (phrase == null) {
finish();
return;
}
setPhrase(phrase);
String title = phrase.getText();
if ("".equals(title))
title = Application.getInstance().getString(
R.string.phrase_empty);
setTitle(title);
}
@Override
protected void onPause() {
super.onPause();
public static Intent createIntent(Context context) {
return createIntent(context, null);
}
public static Intent createIntent(Context context, Integer phraseIndex) {
SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<>(
context, PhraseEditor.class);
if (phraseIndex != null)
builder.addSegment(phraseIndex.toString());
return builder.build();
((PhraseEditorFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container)).saveChanges();
}
private Integer getPhraseIndex(Intent intent) {
......@@ -84,13 +70,11 @@ public class PhraseEditor extends ManagedActivity
return Integer.valueOf(value);
}
@Override
public Phrase getPhrase() {
return phrase;
}
@Override
public void setPhrase(Phrase phrase) {
this.phrase = phrase;
public static Intent createIntent(Context context, Integer phraseIndex) {
SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<>(
context, PhraseEditor.class);
if (phraseIndex != null)
builder.addSegment(phraseIndex.toString());
return builder.build();
}
}
......@@ -44,14 +44,14 @@ public class PhraseList extends BaseListEditor<Integer> {
}
@Override
protected Intent getAddIntent() {
return PhraseEditor.createIntent(this);
}
protected Intent getAddIntent() {
return PhraseAdder.createIntent(this);
}
@Override
protected Intent getEditIntent(Integer actionWith) {
return PhraseEditor.createIntent(this, actionWith);
}
@Override
protected Intent getEditIntent(Integer actionWith) {
return PhraseEditor.createIntent(this, actionWith);
}
@Override
protected int getRemoveTextResourceId() {
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_save"
android:title="@string/save"
app:showAsAction="always"
/>
</menu>
\ No newline at end of file
......@@ -26,4 +26,6 @@
<string name="required">Обязательно</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/preference_editor_security_otr.png -->
<string name="auto">Автоматически</string>
<string name="save">Сохранить</string>
</resources>
\ No newline at end of file
......@@ -26,4 +26,6 @@
<string name="required">Required</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/preference_editor_security_otr.png -->
<string name="auto">Automatically</string>
<string name="save">Save</string>
</resources>
\ 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