-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPricelistActivity.java
197 lines (156 loc) · 7.72 KB
/
PricelistActivity.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package org.tensorflow.lite.examples.banijjosthiti;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
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.util.Date;
public class PricelistActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
String priceApple= " ", priceCarrot = " ", priceOrange= " ", priceBanana = " ";
TextView tvApple, tvOrange, tvCarrot, tvBanana;
String location = "demolocation1";
private Spinner spinner;
private static final String[] paths = {"ডেমো অবস্থান ১", "ডেমো অবস্থান ২", "অবস্থান নির্বাচন করুন"};
FirebaseDatabase database;
TextView tvLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pricelist);
tvApple = (TextView) findViewById(R.id.price_apple);
tvOrange = (TextView) findViewById(R.id.price_orange);
tvCarrot = (TextView) findViewById(R.id.price_carrot);
tvBanana = (TextView) findViewById(R.id.price_banana);
tvLocation = (TextView) findViewById(R.id.current_location);
spinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(PricelistActivity.this,
android.R.layout.simple_spinner_item,paths);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
database = FirebaseDatabase.getInstance();
updatePrice();
String currentDateTimeString = java.text.DateFormat.getDateTimeInstance().format(new Date());
TextView tvDate = (TextView) findViewById(R.id.date);
tvDate.setText(currentDateTimeString);
}
void updatePrice(){
try {
DatabaseReference myRefApple = database.getReference("products/"+location+"/apple/price");
myRefApple.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
priceApple = dataSnapshot.getValue(String.class);
tvApple.setText(priceApple + "টাকা/কেজি");
Log.d( "appleprice","Apple is: " + priceApple);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("appleprice", "Failed to read value.", error.toException());
}
});
}catch (Exception e){
Log.d("Whyerror", e.getMessage());
}
try {
DatabaseReference myRefOrange = database.getReference("products/"+location+"/orange/price");
myRefOrange.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
priceOrange = dataSnapshot.getValue(String.class);
tvOrange.setText(priceOrange + "টাকা/কেজি");
Log.d( "orangeprice","Orange is: " + priceOrange);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("orangeprice", "Failed to read value.", error.toException());
}
});
}catch (Exception e){
Log.d("Whyerror", e.getMessage());
}
try {
DatabaseReference myRefCarrot = database.getReference("products/"+location+"/carrot/price");
myRefCarrot.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
priceCarrot = dataSnapshot.getValue(String.class);
tvCarrot.setText(priceCarrot + "টাকা/কেজি");
Log.d( "carrotprice","Carrot is: " + priceCarrot);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("carrotprice", "Failed to read value.", error.toException());
}
});
}catch (Exception e){
Log.d("Whyerror", e.getMessage());
}
try {
DatabaseReference myRefBanana = database.getReference("products/"+location+"/banana/price");
myRefBanana.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
priceBanana = dataSnapshot.getValue(String.class);
tvBanana.setText(priceBanana + "টাকা/ডজন");
Log.d( "bananaprice","Banana is: " + priceBanana);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("bananaprice", "Failed to read value.", error.toException());
}
});
}catch (Exception e){
Log.d("Whyerror", e.getMessage());
}
}
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
switch (position) {
case 0:
// Whatever you want to happen when the first item gets selected
// editor.putString("demolocation", "demolocation1"); // Storing string
tvLocation.setText("ডেমো লোকেশন ১");
location = "demolocation1";
updatePrice();
// editor.commit(); // commit changes
break;
case 1:
// Whatever you want to happen when the second item gets selected
// editor.putString("demolocation", "demolocation2"); // Storing string
tvLocation.setText("ডেমো লোকেশন ২");
location = "demolocation2";
updatePrice();
// editor.commit(); // commit changes
break;
case 2:
Intent intent = new Intent(PricelistActivity.this, ChooseLocation.class);
startActivity(intent);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}