Search in sources :

Example 1 with PresenceTemplate

use of eu.siacs.conversations.entities.PresenceTemplate in project Conversations by siacs.

the class SetPresenceActivity method onClick.

@Override
public void onClick(View v) {
    PresenceTemplate template = (PresenceTemplate) v.getTag();
    if (template == null) {
        return;
    }
    if (v.getId() == R.id.presence_template) {
        setStatusInSpinner(template.getStatus());
        mStatusMessage.getEditableText().clear();
        mStatusMessage.getEditableText().append(template.getStatusMessage());
        new Handler().post(new Runnable() {

            @Override
            public void run() {
                mScrollView.smoothScrollTo(0, 0);
            }
        });
    } else if (v.getId() == R.id.delete_button) {
        xmppConnectionService.databaseBackend.deletePresenceTemplate(template);
        mTemplates.remove(template);
        redrawTemplates();
    }
}
Also used : PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate) Handler(android.os.Handler)

Example 2 with PresenceTemplate

use of eu.siacs.conversations.entities.PresenceTemplate in project Conversations by siacs.

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) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate) Cursor(android.database.Cursor)

Example 3 with PresenceTemplate

use of eu.siacs.conversations.entities.PresenceTemplate in project Conversations by siacs.

the class SetPresenceActivity method redrawTemplates.

private void redrawTemplates() {
    if (mTemplates == null || mTemplates.size() == 0) {
        mTemplatesView.setVisibility(View.GONE);
    } else {
        mTemplatesView.removeAllViews();
        mTemplatesView.setVisibility(View.VISIBLE);
        LayoutInflater inflater = getLayoutInflater();
        for (PresenceTemplate template : mTemplates) {
            View templateLayout = inflater.inflate(R.layout.presence_template, mTemplatesView, false);
            templateLayout.setTag(template);
            setListItemBackgroundOnView(templateLayout);
            templateLayout.setOnClickListener(this);
            TextView message = (TextView) templateLayout.findViewById(R.id.presence_status_message);
            TextView status = (TextView) templateLayout.findViewById(R.id.status);
            ImageButton button = (ImageButton) templateLayout.findViewById(R.id.delete_button);
            button.setTag(template);
            button.setOnClickListener(this);
            ListItem.Tag tag = UIHelper.getTagForStatus(this, template.getStatus());
            status.setText(tag.getName());
            status.setBackgroundColor(tag.getColor());
            message.setText(template.getStatusMessage());
            mTemplatesView.addView(templateLayout);
        }
    }
}
Also used : ImageButton(android.widget.ImageButton) LayoutInflater(android.view.LayoutInflater) PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate) TextView(android.widget.TextView) ListItem(eu.siacs.conversations.entities.ListItem) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView)

Aggregations

PresenceTemplate (eu.siacs.conversations.entities.PresenceTemplate)3 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Handler (android.os.Handler)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 ListItem (eu.siacs.conversations.entities.ListItem)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1