Search in sources :

Example 1 with PresenceTemplate

use of de.pixart.messenger.entities.PresenceTemplate in project Pix-Art-Messenger by kriztan.

the class DatabaseBackend method getPresenceTemplates.

public List<PresenceTemplate> getPresenceTemplates() {
    ArrayList<PresenceTemplate> templates = new ArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(PresenceTemplate.TABELNAME, null, null, null, null, null, PresenceTemplate.LAST_USED + " desc");
    while (cursor.moveToNext()) {
        templates.add(PresenceTemplate.fromCursor(cursor));
    }
    cursor.close();
    return templates;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) PresenceTemplate(de.pixart.messenger.entities.PresenceTemplate) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 2 with PresenceTemplate

use of de.pixart.messenger.entities.PresenceTemplate 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

PresenceTemplate (de.pixart.messenger.entities.PresenceTemplate)2 Builder (android.app.AlertDialog.Builder)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 AlertDialog (android.support.v7.app.AlertDialog)1 DialogPresenceBinding (de.pixart.messenger.databinding.DialogPresenceBinding)1 PresenceTemplateAdapter (de.pixart.messenger.ui.adapter.PresenceTemplateAdapter)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1