-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnSalePage
116 lines (93 loc) · 4.29 KB
/
OnSalePage
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
package com.example.bilkentcompanion;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
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 android.widget.Toast;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
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 OnSalePage extends AppCompatActivity {
TextView title;
String category;
int price;
ListView list;
ArrayAdapter adapter;
private String TAG;
SearchView searchView;
ArrayList<String> names, description, keys , prices, uids;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_on_sale_page);
Intent intent = getIntent();
category = intent.getStringExtra("category");
price = intent.getIntExtra("price", 0);
Log.i("sell", category + price);
list = findViewById(R.id.itemsList);
initialize();
//make items clickable
//TODO pass to chat or the item edit page
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("uid", uids.get(position));
}
});
}
private void initialize() {
names = new ArrayList<>();
description = new ArrayList<>();
prices = new ArrayList<>();
keys = new ArrayList<>();
uids = new ArrayList<>();
FirebaseDatabase.getInstance().getReference().child("SellPost")
.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();
Log.i("sell", cat);
if (category.equals(cat) || category.equals("all")) {
if (snapshot.hasChild("price")) {
String priceString = snapshot.child("price").getValue().toString();
Log.i("sell", priceString);
int itemPrice = Integer.parseInt(priceString);
Log.i("sell", itemPrice + "");
Log.i("sell", "" + (itemPrice <= price));
if (itemPrice <= price) {
names.add(snapshot.child("name").getValue().toString());
description.add(snapshot.child("tags").getValue().toString());
prices.add(snapshot.child("price").getValue().toString());
keys.add(snapshot.child("key").getValue().toString());
uids.add(snapshot.child("uid").getValue().toString());
}
}
}
}
}
Custom custom = new Custom(OnSalePage.this, names, description, prices, uids);
list.setAdapter(custom);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}