Search in sources :

Example 1 with PresenceTemplateAdapter

use of de.pixart.messenger.ui.adapter.PresenceTemplateAdapter in project Pix-Art-Messenger by kriztan.

the class EditAccountActivity method changePresence.

private void changePresence() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean manualStatus = sharedPreferences.getBoolean(SettingsActivity.MANUALLY_CHANGE_PRESENCE, getResources().getBoolean(R.bool.manually_change_presence));
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    final DialogPresenceBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_presence, null, false);
    String current = mAccount.getPresenceStatusMessage();
    if (current != null && !current.trim().isEmpty()) {
        binding.statusMessage.append(current);
    }
    setAvailabilityRadioButton(mAccount.getPresenceStatus(), binding);
    binding.show.setVisibility(manualStatus ? View.VISIBLE : View.GONE);
    List<PresenceTemplate> templates = xmppConnectionService.getPresenceTemplates(mAccount);
    PresenceTemplateAdapter presenceTemplateAdapter = new PresenceTemplateAdapter(this, R.layout.simple_list_item, templates);
    binding.statusMessage.setAdapter(presenceTemplateAdapter);
    binding.statusMessage.setOnItemClickListener((parent, view, position, id) -> {
        PresenceTemplate template = (PresenceTemplate) parent.getItemAtPosition(position);
        setAvailabilityRadioButton(template.getStatus(), binding);
    });
    builder.setTitle(R.string.edit_status_message_title);
    builder.setView(binding.getRoot());
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
        PresenceTemplate template = new PresenceTemplate(getAvailabilityRadioButton(binding), binding.statusMessage.getText().toString().trim());
        if (mAccount.getPgpId() != 0 && hasPgp()) {
            generateSignature(null, template);
        } else {
            xmppConnectionService.changeStatus(mAccount, template, null);
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogPresenceBinding(de.pixart.messenger.databinding.DialogPresenceBinding) SharedPreferences(android.content.SharedPreferences) Builder(android.app.AlertDialog.Builder) PresenceTemplateAdapter(de.pixart.messenger.ui.adapter.PresenceTemplateAdapter) Builder(android.app.AlertDialog.Builder) PresenceTemplate(de.pixart.messenger.entities.PresenceTemplate)

Aggregations

Builder (android.app.AlertDialog.Builder)1 SharedPreferences (android.content.SharedPreferences)1 AlertDialog (android.support.v7.app.AlertDialog)1 DialogPresenceBinding (de.pixart.messenger.databinding.DialogPresenceBinding)1 PresenceTemplate (de.pixart.messenger.entities.PresenceTemplate)1 PresenceTemplateAdapter (de.pixart.messenger.ui.adapter.PresenceTemplateAdapter)1