This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProfileAdapter.java
69 lines (55 loc) · 1.96 KB
/
ProfileAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.touchirc.adapter;
import org.touchirc.R;
import org.touchirc.TouchIrc;
import org.touchirc.db.Database;
import org.touchirc.model.Profile;
import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ProfileAdapter extends BaseAdapter {
private SparseArray<Profile> profilesList;
private Context c;
public ProfileAdapter (SparseArray<Profile> profiles_AL, Context c){
this.profilesList = profiles_AL;
this.c = c;
}
public int getCount() {
return profilesList.size();
}
public Profile getItem(int position) {
return profilesList.valueAt(position);
}
public long getItemId(int position) {
return profilesList.keyAt(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Profile profile = profilesList.valueAt(position); // Collect the profile concerned
if (v == null){
LayoutInflater vi = (LayoutInflater) this.c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_list, null);
}
TextView default_TV = (TextView) v.findViewById(R.id.textView_DEFAULT);
// Checking if the current profile is by default
Database db = new Database(c);
if(TouchIrc.getInstance().getIdDefaultProfile() == getItemId(position)){
default_TV.setBackgroundResource(R.drawable.object_border);
default_TV.setText(R.string.DEFAULT);
}
else{
// To ensure the fact that when the method is recalled the resources are corrects
default_TV.setBackgroundResource(0);
default_TV.setText("");
}
db.close();
TextView profileName_TV = (TextView) v.findViewById(R.id.textView_itemName);
profileName_TV.setText(profile.getProfile_name());
TextView firstNickName_TV = (TextView) v.findViewById(R.id.textView_itemSecondInfo);
firstNickName_TV.setText(profile.getFirstNick());
return v;
}
}