-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomFound SONUPDATE
144 lines (123 loc) · 4.48 KB
/
CustomFound SONUPDATE
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.example.bilkentcompanion;
import android.app.Activity;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
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 com.bumptech.glide.Glide;
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class CustomFound extends ArrayAdapter<String> {
private String[] itemNames;
private String[] desc;
private String[] dates;
//private Integer[] imgId;
private Activity context;
private String[] uids;
private String[] keys;
StorageReference storageReference;
Uri uri;
String url;
//public Custom(Activity context, String[] itemNames, String[] desc, Integer[] imgId) {
public CustomFound(Activity context, ArrayList<String> itemNames, ArrayList<String> desc, ArrayList<String> dates, ArrayList<String> uids, ArrayList<String> keys) {
super(context, R.layout.listview_layout,itemNames);
this.context = context;
storageReference = FirebaseStorage.getInstance().getReference();
this. itemNames = new String[itemNames.size()];
for(int i = 0; i < itemNames.size(); i ++)
{
this.itemNames[i] = itemNames.get(i);
}
this.desc = new String[desc.size()];
for(int i = 0; i < desc.size(); i ++)
{
this.desc[i] = desc.get(i);
}
this. dates = new String[dates.size()];
for(int i = 0; i < dates.size(); i ++)
{
this.dates[i] = dates.get(i);
}
this. uids = new String[uids.size()];
for(int i = 0; i < uids.size(); i ++)
{
this.uids[i] = uids.get(i);
}
this.keys = new String[keys.size()];
for(int i = 0; i < keys.size(); i ++)
{
this.keys[i] = keys.get(i);
}
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View r = convertView;
ViewHolder viewHolder = null;
if (r== null)
{
LayoutInflater layoutInflater = context.getLayoutInflater();
r = layoutInflater.inflate(R.layout.listview_layout, null, true);
viewHolder = new ViewHolder(r);
r.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) r.getTag();
}
//viewHolder.iv.setImageResource(imgId[position]);
viewHolder.tv1.setText("Item name: " + itemNames[position]);
viewHolder.tv2.setText("Description: " + desc[position]);
viewHolder.tv3.setText("Date of upload: " + dates[position]);
viewHolder.tv4.setText("UID: " + uids[position]);
url = keys[position];
Task<Uri> urlTask = storageReference.child(url).getDownloadUrl().continueWithTask(new Continuation<Uri, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<Uri> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
return storageReference.child(url).getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
uri = task.getResult();
if (uri == null)
return;
}
}
});
Picasso.get().load(uri).into(viewHolder.iv);
return r;
}
class ViewHolder {
TextView tv1;
TextView tv2;
TextView tv3;
TextView tv4;
ImageView iv;
ViewHolder(View v)
{
tv1 = v.findViewById(R.id.itemName);
tv2 = v.findViewById(R.id.description);
tv3 = v.findViewById(R.id.extra);
tv4 = v.findViewById(R.id.uid);
iv = v.findViewById(R.id.image);
}
}
}