1
1
package com .simcoder .uber ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .support .v7 .app .AppCompatActivity ;
4
5
import android .os .Bundle ;
5
6
import android .support .v7 .widget .LinearLayoutManager ;
6
7
import android .support .v7 .widget .RecyclerView ;
7
8
import android .text .format .DateFormat ;
9
+ import android .view .View ;
10
+ import android .widget .TextView ;
8
11
9
12
import com .google .firebase .auth .FirebaseAuth ;
10
13
import com .google .firebase .database .DataSnapshot ;
@@ -27,11 +30,17 @@ public class HistoryActivity extends AppCompatActivity {
27
30
private RecyclerView .Adapter mHistoryAdapter ;
28
31
private RecyclerView .LayoutManager mHistoryLayoutManager ;
29
32
33
+ private TextView mBalance ;
34
+
35
+ private Double Balance = 0.0 ;
36
+
30
37
@ Override
31
38
protected void onCreate (Bundle savedInstanceState ) {
32
39
super .onCreate (savedInstanceState );
33
40
setContentView (R .layout .activity_history );
34
41
42
+ mBalance = findViewById (R .id .balance );
43
+
35
44
mHistoryRecyclerView = (RecyclerView ) findViewById (R .id .historyRecyclerView );
36
45
mHistoryRecyclerView .setNestedScrollingEnabled (false );
37
46
mHistoryRecyclerView .setHasFixedSize (true );
@@ -44,6 +53,10 @@ protected void onCreate(Bundle savedInstanceState) {
44
53
customerOrDriver = getIntent ().getExtras ().getString ("customerOrDriver" );
45
54
userId = FirebaseAuth .getInstance ().getCurrentUser ().getUid ();
46
55
getUserHistoryIds ();
56
+
57
+ if (customerOrDriver .equals ("Drivers" )){
58
+ mBalance .setVisibility (View .VISIBLE );
59
+ }
47
60
}
48
61
49
62
private void getUserHistoryIds () {
@@ -66,16 +79,29 @@ public void onCancelled(DatabaseError databaseError) {
66
79
private void FetchRideInformation (String rideKey ) {
67
80
DatabaseReference historyDatabase = FirebaseDatabase .getInstance ().getReference ().child ("history" ).child (rideKey );
68
81
historyDatabase .addListenerForSingleValueEvent (new ValueEventListener () {
82
+ @ SuppressLint ("SetTextI18n" )
69
83
@ Override
70
84
public void onDataChange (DataSnapshot dataSnapshot ) {
71
85
if (dataSnapshot .exists ()){
72
86
String rideId = dataSnapshot .getKey ();
73
87
Long timestamp = 0L ;
74
- for (DataSnapshot child : dataSnapshot .getChildren ()){
75
- if (child .getKey ().equals ("timestamp" )){
76
- timestamp = Long .valueOf (child .getValue ().toString ());
88
+ String distance = "" ;
89
+ Double ridePrice = 0.0 ;
90
+
91
+ if (dataSnapshot .child ("timestamp" ).getValue () != null ){
92
+ timestamp = Long .valueOf (dataSnapshot .child ("timestamp" ).getValue ().toString ());
93
+ }
94
+
95
+ if (dataSnapshot .child ("customerPaid" ).getValue () != null && dataSnapshot .child ("driverPaidOut" ).getValue () == null ){
96
+ if (dataSnapshot .child ("distance" ).getValue () != null ){
97
+ distance = dataSnapshot .child ("distance" ).getValue ().toString ();
98
+ ridePrice = (Double .valueOf (distance ) * 0.4 );
99
+ Balance += ridePrice ;
100
+ mBalance .setText ("Balance: " + String .valueOf (Balance ) + " $" );
77
101
}
78
102
}
103
+
104
+
79
105
HistoryObject obj = new HistoryObject (rideId , getDate (timestamp ));
80
106
resultsHistory .add (obj );
81
107
mHistoryAdapter .notifyDataSetChanged ();
0 commit comments