diff options
author | lookshe <github@lookshe.org> | 2015-10-05 13:55:43 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-10-05 13:55:43 +0200 |
commit | b98478e57c088efc63fd470e429f791dd664707a (patch) | |
tree | e722ed48ee2ec125d8ad9250f79d8e1ca95666a7 /src/main/java/de/thedevstack/conversationsplus/ui/adapter | |
parent | 5850cbcf9c3e72580f3288c582737a04e8148b79 (diff) | |
parent | 6f17b06ad008cc7ac89174ba7ac7cc96ee0881eb (diff) |
Merge branch 'trz/rename' into trz/rebase
Conflicts:
build.gradle
src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/adapter')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java new file mode 100644 index 00000000..0b5cb897 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java @@ -0,0 +1,63 @@ +package de.thedevstack.conversationsplus.ui.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Map; + +import de.thedevstack.conversationsplus.R; +import de.thedevstack.conversationsplus.entities.Presences; +import de.thedevstack.conversationsplus.utils.UIHelper; + +/** + * Created by tzur on 27.09.2015. + */ +public class PresencesArrayAdapter extends ArrayAdapter<Presence> { + private final Context context; + private final Presence[] values; + + public PresencesArrayAdapter(Context context, Presences presences) { + super(context, R.layout.dialog_resources_status); + this.context = context; + this.values = getPresenceArray(presences); + addAll(this.values); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rowView = inflater.inflate(R.layout.dialog_resources_status, parent, false); + TextView textView = (TextView) rowView.findViewById(R.id.dlg_res_stat_resource_name); + textView.setText(this.values[position].resource); + textView.setTextColor(Color.parseColor(UIHelper.getStatusColor(this.values[position].status))); + + return rowView; + } + + private static Presence[] getPresenceArray(Presences presences) { + ArrayList<Presence> presenceArrayList = new ArrayList<>(); + if (null != presences && null != presences.getPresences() && !presences.getPresences().isEmpty()) { + for (Map.Entry<String, Integer> entry : presences.getPresences().entrySet()) { + Presence p = new Presence(); + p.resource = entry.getKey(); + p.status = entry.getValue(); + presenceArrayList.add(p); + } + presenceArrayList.trimToSize(); + } + return presenceArrayList.toArray(new Presence[0]); + } +} + +class Presence { + String resource; + int status; +} |