-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGitRepositoryArrayAdapter.java
More file actions
80 lines (72 loc) · 2.59 KB
/
Copy pathGitRepositoryArrayAdapter.java
File metadata and controls
80 lines (72 loc) · 2.59 KB
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
70
71
72
73
74
75
76
77
78
79
80
package com.example.git;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* This adapter is used to fill a given view with single views generated for
* each entry of the Git repository list.
*/
public class GitRepositoryArrayAdapter extends ArrayAdapter<String> {
/**
* The list of repositories to represent in the ListView.
*/
private ArrayList<List<String>> repositoryList = new ArrayList<List<String>>();
/**
* The current context within the application.
*/
private Context currentContext = null;
/**
* Creates a new adapter.
* @param context The current context.
* @param textViewResourceId The resource ID for a layout file containing a TextView to use when instantiating views.
* @param repositories The list of repositories to represent in the ListView.
*/
public GitRepositoryArrayAdapter(Context context, int textViewResourceId, ArrayList<List<String>> repositories) {
super(context, textViewResourceId);
currentContext = context;
if(repositories != null) {
repositoryList = repositories;
}
}
@Override
/**
* Get the view for a specific element of the list.
* @param position The position within the list.
* @param convertView A previously returned view, that can be reused.
* @param parent The parent ViewGroup.
* @return The view for the list item.
*/
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.list_item, parent, false);
}
TextView rowTextView = (TextView) rowView.findViewById(R.id.textview);
List<String> rowData = repositoryList.get(position);
if (rowData != null) {
StringBuffer rowBuffer = new StringBuffer("");
rowBuffer.append(currentContext.getResources().getString(R.string.name) + ": ");
rowBuffer.append(rowData.get(1) + "\n");
rowBuffer.append(currentContext.getResources().getString(R.string.path) + ": ");
rowBuffer.append(rowData.get(0) + "\n");
rowBuffer.append(currentContext.getResources().getString(R.string.creation_date) + ": ");
rowBuffer.append(rowData.get(2));
rowTextView.setText(rowBuffer.toString());
}
return rowView;
}
@Override
/**
* Counts the amount of list items.
* @return The amount of list items.
*/
public int getCount() {
return repositoryList.size();
}
}