Search in sources :

Example 1 with Phrase

use of com.xabber.android.data.message.phrase.Phrase in project xabber-android by redsolution.

the class PhraseEditorFragment method setValues.

@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
    String text = getString(result, R.string.phrase_text_key);
    String user = getString(result, R.string.phrase_user_key);
    String group = getString(result, R.string.phrase_group_key);
    boolean regexp = getBoolean(result, R.string.phrase_regexp_key);
    Log.i("PhraseEditorFragment", "setValues. text: " + text);
    if (regexp) {
        try {
            Phrase.compile(text);
            Phrase.compile(user);
            Phrase.compile(group);
        } catch (PatternSyntaxException e) {
            Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
            return false;
        }
    }
    Phrase phrase = mListener.getPhrase();
    if (phrase == null && "".equals(text) && "".equals(user) && "".equals(group)) {
        Toast.makeText(getActivity(), R.string.events_phrases_error, Toast.LENGTH_LONG).show();
        return false;
    }
    Log.i("PhraseEditorFragment", "updateOrCreatePhrase");
    PhraseManager.getInstance().updateOrCreatePhrase(phrase, text, user, group, regexp, null);
    mListener.setPhrase(phrase);
    return true;
}
Also used : Phrase(com.xabber.android.data.message.phrase.Phrase) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with Phrase

use of com.xabber.android.data.message.phrase.Phrase in project xabber-android by redsolution.

the class PhraseEditorFragment method getValues.

@Override
protected Map<String, Object> getValues() {
    Phrase phrase = mListener.getPhrase();
    Map<String, Object> source = new HashMap<>();
    putValue(source, R.string.phrase_text_key, phrase == null ? "" : phrase.getText());
    putValue(source, R.string.phrase_user_key, phrase == null ? "" : phrase.getUser());
    putValue(source, R.string.phrase_group_key, phrase == null ? "" : phrase.getGroup());
    putValue(source, R.string.phrase_regexp_key, phrase != null && phrase.isRegexp());
    return source;
}
Also used : HashMap(java.util.HashMap) Phrase(com.xabber.android.data.message.phrase.Phrase)

Example 3 with Phrase

use of com.xabber.android.data.message.phrase.Phrase in project xabber-android by redsolution.

the class PhraseEditor method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    index = getPhraseIndex(getIntent());
    if (index == null) {
        finish();
        return;
    }
    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);
    Toolbar toolbar = ToolbarHelper.setUpDefaultToolbar(this, title);
    toolbar.inflateMenu(R.menu.toolbar_delete);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    BarPainter barPainter = new BarPainter(this, toolbar);
    barPainter.setDefaultColor();
}
Also used : MenuItem(android.view.MenuItem) Phrase(com.xabber.android.data.message.phrase.Phrase) Toolbar(androidx.appcompat.widget.Toolbar) BarPainter(com.xabber.android.ui.color.BarPainter)

Example 4 with Phrase

use of com.xabber.android.data.message.phrase.Phrase in project xabber-android by redsolution.

the class Key method generatePhraseName.

public String generatePhraseName(Context context, Long id) {
    Phrase phrase = PhraseManager.getInstance().getPhrase(id);
    String result = context.getString(R.string.events_phrase);
    if (phrase != null) {
        if (phrase.getText() != null && !phrase.getText().isEmpty())
            result += ": " + phrase.getText();
        else if (phrase.getUser() != null && !phrase.getUser().isEmpty())
            result += ": " + phrase.getUser();
        else if (phrase.getGroup() != null && !phrase.getGroup().isEmpty())
            result += ": " + phrase.getGroup();
    }
    return result;
}
Also used : Phrase(com.xabber.android.data.message.phrase.Phrase)

Example 5 with Phrase

use of com.xabber.android.data.message.phrase.Phrase in project xabber-android by redsolution.

the class PhraseEditorFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    Phrase phrase = mListener.getPhrase();
    Preference notificationPref = findPreference("notification_settings");
    if (phrase != null) {
        notificationPref.setIntent(CustomNotifySettings.createIntent(getActivity(), phrase.getId()));
        notificationPref.setEnabled(true);
    } else {
        notificationPref.setEnabled(false);
        notificationPref.setSummary(R.string.events_use_custom_not_allowed_summary);
    }
}
Also used : Preference(android.preference.Preference) Phrase(com.xabber.android.data.message.phrase.Phrase)

Aggregations

Phrase (com.xabber.android.data.message.phrase.Phrase)6 Preference (android.preference.Preference)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 BarPainter (com.xabber.android.ui.color.BarPainter)1 HashMap (java.util.HashMap)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1