-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFoundItemsPage UPDATE1
145 lines (119 loc) · 6 KB
/
FoundItemsPage UPDATE1
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
package com.example.bilkentcompanion;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class FoundItemsPage extends AppCompatActivity {
TextView title;
String category;
int days;
//Item item;
ListView list;
ArrayAdapter adapter;
private String TAG;
SearchView searchView;
ArrayList<String> names, description, keys , dates, uids;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_found_items_page);
searchView = findViewById(R.id.searchBar); // inititate a search view
Intent intent = getIntent();
category = intent.getStringExtra("category");
days = intent.getIntExtra("days", 0);
list = findViewById(R.id.itemsList);
initialize();
//make items clickable
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*
//TODO if(currentUserID.equals()) burayı bilemedim
{
Intent i = new Intent(FoundItemsPage.this, EditPageFound.class);
i.putExtra("name", names.get(position));
i.putExtra("description", description.get(position));
i.putExtra("key", keys.get(position));
startActivity(i);
}
else
{
//BURASI CHATE BAĞLANACAK
*/
}
});
}
private void initialize() {
names = new ArrayList<>();
description = new ArrayList<>();
dates = new ArrayList<>();
keys = new ArrayList<>();
uids = new ArrayList<>();
FirebaseDatabase.getInstance().getReference().child("LostPost")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
if( snapshot.hasChild("category") ) {
String cat = snapshot.child("category").getValue().toString();
if (category.equals(cat) || category.equals("all"))
{
if(days == - 1)
{
names.add(snapshot.child("name").getValue().toString());
description.add(snapshot.child("tags").getValue().toString());
dates.add(snapshot.child("date").getValue().toString());
keys.add(snapshot.child("key").getValue().toString());
uids.add(snapshot.child("uid").getValue().toString());
}
else
{
if (snapshot.hasChild("date"))
{
String date = snapshot.child("date").getValue().toString();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date dateUpload = formatter.parse(date, new ParsePosition(0));
Date dateToday = new Date();
String dateString = formatter.format(dateToday);
Log.i("days", dateString);
dateToday = formatter.parse(dateString, new ParsePosition(0));
long diff =dateToday.getTime() - dateUpload.getTime();
float daysDifference = (diff / (1000*60*60*24));
Log.i("days", daysDifference + "");
Log.i("days", date + " " + diff + " " + dateToday.toString());
if(daysDifference <= days)
{
names.add(snapshot.child("name").getValue().toString());
description.add(snapshot.child("tags").getValue().toString());
dates.add(snapshot.child("date").getValue().toString());
keys.add(snapshot.child("key").getValue().toString());
uids.add(snapshot.child("uid").getValue().toString());
}
}
}
}
}
CustomFound custom = new CustomFound(FoundItemsPage.this, names, description, dates, uids);
list.setAdapter(custom);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}