Skip to content

Commit d7aea0b

Browse files
- Driver owed payout
1 parent 539360e commit d7aea0b

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

app/src/main/java/com/simcoder/uber/DriverMapActivity.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class DriverMapActivity extends FragmentActivity implements OnMapReadyCal
5959
Location mLastLocation;
6060
LocationRequest mLocationRequest;
6161

62-
private Button mLogout, mSettings, mRideStatus;
62+
private Button mLogout, mSettings, mRideStatus, mHistory;
6363

6464
private Switch mWorkingSwitch;
6565

@@ -118,6 +118,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
118118
mSettings = (Button) findViewById(R.id.settings);
119119
mLogout = (Button) findViewById(R.id.logout);
120120
mRideStatus = (Button) findViewById(R.id.rideStatus);
121+
mHistory = (Button) findViewById(R.id.history);
121122
mRideStatus.setOnClickListener(new View.OnClickListener() {
122123
@Override
123124
public void onClick(View v) {
@@ -161,7 +162,15 @@ public void onClick(View v) {
161162
return;
162163
}
163164
});
164-
165+
mHistory.setOnClickListener(new View.OnClickListener() {
166+
@Override
167+
public void onClick(View v) {
168+
Intent intent = new Intent(DriverMapActivity.this, HistoryActivity.class);
169+
intent.putExtra("customerOrDriver", "Drivers");
170+
startActivity(intent);
171+
return;
172+
}
173+
});
165174
getAssignedCustomer();
166175
}
167176

app/src/main/java/com/simcoder/uber/HistoryActivity.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.simcoder.uber;
22

3+
import android.annotation.SuppressLint;
34
import android.support.v7.app.AppCompatActivity;
45
import android.os.Bundle;
56
import android.support.v7.widget.LinearLayoutManager;
67
import android.support.v7.widget.RecyclerView;
78
import android.text.format.DateFormat;
9+
import android.view.View;
10+
import android.widget.TextView;
811

912
import com.google.firebase.auth.FirebaseAuth;
1013
import com.google.firebase.database.DataSnapshot;
@@ -27,11 +30,17 @@ public class HistoryActivity extends AppCompatActivity {
2730
private RecyclerView.Adapter mHistoryAdapter;
2831
private RecyclerView.LayoutManager mHistoryLayoutManager;
2932

33+
private TextView mBalance;
34+
35+
private Double Balance = 0.0;
36+
3037
@Override
3138
protected void onCreate(Bundle savedInstanceState) {
3239
super.onCreate(savedInstanceState);
3340
setContentView(R.layout.activity_history);
3441

42+
mBalance = findViewById(R.id.balance);
43+
3544
mHistoryRecyclerView = (RecyclerView) findViewById(R.id.historyRecyclerView);
3645
mHistoryRecyclerView.setNestedScrollingEnabled(false);
3746
mHistoryRecyclerView.setHasFixedSize(true);
@@ -44,6 +53,10 @@ protected void onCreate(Bundle savedInstanceState) {
4453
customerOrDriver = getIntent().getExtras().getString("customerOrDriver");
4554
userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
4655
getUserHistoryIds();
56+
57+
if(customerOrDriver.equals("Drivers")){
58+
mBalance.setVisibility(View.VISIBLE);
59+
}
4760
}
4861

4962
private void getUserHistoryIds() {
@@ -66,16 +79,29 @@ public void onCancelled(DatabaseError databaseError) {
6679
private void FetchRideInformation(String rideKey) {
6780
DatabaseReference historyDatabase = FirebaseDatabase.getInstance().getReference().child("history").child(rideKey);
6881
historyDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
82+
@SuppressLint("SetTextI18n")
6983
@Override
7084
public void onDataChange(DataSnapshot dataSnapshot) {
7185
if(dataSnapshot.exists()){
7286
String rideId = dataSnapshot.getKey();
7387
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) + " $");
77101
}
78102
}
103+
104+
79105
HistoryObject obj = new HistoryObject(rideId, getDate(timestamp));
80106
resultsHistory.add(obj);
81107
mHistoryAdapter.notifyDataSetChanged();

app/src/main/res/layout/activity_driver_map.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
android:layout_height="wrap_content"
2424
android:id="@+id/logout"
2525
android:text="logout"/>
26+
<Button
27+
android:layout_weight="1"
28+
android:layout_width="0dp"
29+
android:layout_height="wrap_content"
30+
android:id="@+id/history"
31+
android:text="history"/>
2632
<Button
2733
android:layout_weight="1"
2834
android:layout_gravity="end"
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
tools:context="com.simcoder.uber.HistoryActivity"
8-
android:fitsSystemWindows="true">
9+
android:fitsSystemWindows="true"
10+
android:orientation="vertical">
911
<LinearLayout
10-
android:layout_width="368dp"
11-
android:layout_height="495dp"
12-
android:orientation="vertical"
13-
tools:layout_editor_absoluteY="8dp"
14-
tools:layout_editor_absoluteX="8dp">
15-
<android.support.v4.widget.NestedScrollView
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:orientation="vertical">
15+
<TextView
16+
android:padding="20sp"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:text="Balance: 1000€"
20+
android:id="@+id/balance"
21+
android:visibility="gone"/>
22+
</LinearLayout>
23+
24+
<android.support.v4.widget.NestedScrollView
1625
android:layout_width="match_parent"
1726
android:layout_height="match_parent">
1827
<android.support.v7.widget.RecyclerView
1928
android:layout_width="match_parent"
2029
android:layout_height="wrap_content"
2130
android:id="@+id/historyRecyclerView"
2231
android:scrollbars="vertical">
23-
2432
</android.support.v7.widget.RecyclerView>
2533

2634
</android.support.v4.widget.NestedScrollView>
2735

28-
</LinearLayout>
29-
30-
</android.support.constraint.ConstraintLayout>
36+
</LinearLayout>

0 commit comments

Comments
 (0)