Search in sources :

Example 1 with PresenceTemplateAdapter

use of eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter in project Conversations by siacs.

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(androidx.appcompat.app.AlertDialog) DialogPresenceBinding(eu.siacs.conversations.databinding.DialogPresenceBinding) SharedPreferences(android.content.SharedPreferences) Builder(androidx.appcompat.app.AlertDialog.Builder) PresenceTemplateAdapter(eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter) Builder(androidx.appcompat.app.AlertDialog.Builder) PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Builder (androidx.appcompat.app.AlertDialog.Builder)1 DialogPresenceBinding (eu.siacs.conversations.databinding.DialogPresenceBinding)1 PresenceTemplate (eu.siacs.conversations.entities.PresenceTemplate)1 PresenceTemplateAdapter (eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter)1