mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 20:00:53 +00:00
Improve app, add some information about the order status
This commit is contained in:
@@ -87,8 +87,6 @@ import retrofit2.Response;
|
||||
|
||||
public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperListener {
|
||||
|
||||
String address = null;
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
@@ -168,46 +166,51 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
||||
loadListFood();
|
||||
|
||||
//Location
|
||||
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
||||
mSettingsClient = LocationServices.getSettingsClient(this);
|
||||
|
||||
mLocationCallBack = new LocationCallback() {
|
||||
@Override
|
||||
public void onLocationResult(@NonNull LocationResult locationResult) {
|
||||
super.onLocationResult(locationResult);
|
||||
mCurrentLocation = locationResult.getLastLocation();
|
||||
}
|
||||
};
|
||||
if(Common.currentLocation == null) {
|
||||
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
||||
mSettingsClient = LocationServices.getSettingsClient(this);
|
||||
|
||||
mLocationRequest = LocationRequest.create()
|
||||
.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS)
|
||||
.setFastestInterval(FASTEST_UPDATE_IN_MILLISECONDS)
|
||||
.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
|
||||
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
|
||||
builder.addLocationRequest(mLocationRequest);
|
||||
mLocationSettingsRequest = builder.build();
|
||||
mLocationCallBack = new LocationCallback() {
|
||||
@Override
|
||||
public void onLocationResult(@NonNull LocationResult locationResult) {
|
||||
super.onLocationResult(locationResult);
|
||||
mCurrentLocation = locationResult.getLastLocation();
|
||||
Common.currentLocation = mCurrentLocation;
|
||||
}
|
||||
};
|
||||
|
||||
Dexter.withContext(this)
|
||||
.withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
.withListener(new PermissionListener() {
|
||||
@Override
|
||||
public void onPermissionGranted(PermissionGrantedResponse permissionGrantedResponse) {
|
||||
mRequestingLocationUpdates = true;
|
||||
startLocationUpdates();
|
||||
mLocationRequest = LocationRequest.create()
|
||||
.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS)
|
||||
.setFastestInterval(FASTEST_UPDATE_IN_MILLISECONDS)
|
||||
.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
|
||||
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
|
||||
builder.addLocationRequest(mLocationRequest);
|
||||
mLocationSettingsRequest = builder.build();
|
||||
|
||||
Dexter.withContext(this)
|
||||
.withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
.withListener(new PermissionListener() {
|
||||
@Override
|
||||
public void onPermissionGranted(PermissionGrantedResponse permissionGrantedResponse) {
|
||||
mRequestingLocationUpdates = true;
|
||||
startLocationUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied(PermissionDeniedResponse response) {
|
||||
if(response.isPermanentlyDenied()){
|
||||
openSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied(PermissionDeniedResponse response) {
|
||||
if(response.isPermanentlyDenied()){
|
||||
openSettings();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
|
||||
token.continuePermissionRequest();
|
||||
}
|
||||
}).check();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
|
||||
token.continuePermissionRequest();
|
||||
}
|
||||
}).check();
|
||||
|
||||
setTitle("Giỏ hàng");
|
||||
// calling the action bar
|
||||
@@ -262,40 +265,46 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
||||
});
|
||||
|
||||
//Add event
|
||||
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mGoogleMapService.getAddressName(String.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSyCqmoLlawoQzmwjZI2_Yo_V33An_nNZADs",
|
||||
mCurrentLocation.getLatitude(),
|
||||
mCurrentLocation.getLongitude()))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(Call<String> call, Response<String> response) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(response.body());
|
||||
if(Common.currentAddress == null) {
|
||||
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mGoogleMapService.getAddressName(String.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSyCqmoLlawoQzmwjZI2_Yo_V33An_nNZADs",
|
||||
Common.currentLocation.getLatitude(),
|
||||
Common.currentLocation.getLongitude()))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(Call<String> call, Response<String> response) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(response.body());
|
||||
|
||||
JSONArray resultsArray = jsonObject.getJSONArray("results");
|
||||
JSONArray resultsArray = jsonObject.getJSONArray("results");
|
||||
|
||||
JSONObject firstObject = resultsArray.getJSONObject(0);
|
||||
JSONObject firstObject = resultsArray.getJSONObject(0);
|
||||
|
||||
address = firstObject.getString("formatted_address");
|
||||
edtAddress.setText(address);
|
||||
edtAddress.setEnabled(false);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Common.currentAddress = firstObject.getString("formatted_address");
|
||||
edtAddress.setText(Common.currentAddress);
|
||||
edtAddress.setEnabled(false);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<String> call, Throwable t) {
|
||||
Toast.makeText(Cart.this, "Error to get location: " + t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
Log.i("LOCATION", "" + t.getMessage());
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(Call<String> call, Throwable t) {
|
||||
Toast.makeText(Cart.this, "Error to get location: " + t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
Log.i("LOCATION", "" + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
edtAddress.setText(Common.currentAddress);
|
||||
edtAddress.setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
alertDialog.setView(order_address_comment);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.waterbase.foodify.Common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.text.format.DateFormat;
|
||||
@@ -18,6 +19,9 @@ public class Common {
|
||||
|
||||
public static String PHONE_TEXT = "userPhone";
|
||||
|
||||
public static Location currentLocation;
|
||||
public static String currentAddress;
|
||||
|
||||
public static String topicName = "News";
|
||||
|
||||
private static final String BASE_URL = "https://fcm.googleapis.com/";
|
||||
|
||||
@@ -42,10 +42,6 @@ import org.json.JSONObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
|
||||
import io.github.inflationx.viewpump.ViewPump;
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
@@ -84,6 +84,8 @@ public class OrderStatus extends AppCompatActivity {
|
||||
orderViewHolder.txtOrderAddress.setText("Địa chỉ: " + model.getAddress());
|
||||
orderViewHolder.txtOrderDate.setText("Ngày đặt: " + Common.getDate(Long.parseLong(adapter.getRef(i).getKey())));
|
||||
orderViewHolder.txtOrderPayment.setText("Tình trạng thanh toán: " + Common.convertCodePaymentToStatus(model.getPaymentStatus()));
|
||||
orderViewHolder.txtOrderCount.setText("Số lượng món ăn: " + model.getFoods().size());
|
||||
orderViewHolder.txtOrderPrice.setText("Tổng cộng: " + model.getTotal());
|
||||
|
||||
orderViewHolder.btn_detail.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
@@ -61,5 +64,21 @@ public class OrderStatusDetail extends AppCompatActivity {
|
||||
OrderStatusDetailAdapter adapter = new OrderStatusDetailAdapter(request.getFoods(), this);
|
||||
adapter.notifyDataSetChanged();
|
||||
lstFoods.setAdapter(adapter);
|
||||
|
||||
// calling the action bar
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// showing the back button in action bar
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import com.waterbase.foodify.R;
|
||||
|
||||
public class OrderViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView txtOrderId, txtOrderStatus, txtOrderAddress, txtOrderDate, txtOrderPayment;
|
||||
public TextView txtOrderId, txtOrderStatus, txtOrderAddress, txtOrderDate, txtOrderPayment, txtOrderCount, txtOrderPrice;
|
||||
|
||||
public ImageView btn_delete, btn_detail;
|
||||
|
||||
@@ -24,6 +24,9 @@ public class OrderViewHolder extends RecyclerView.ViewHolder {
|
||||
txtOrderStatus = itemView.findViewById(R.id.order_status);
|
||||
txtOrderDate = itemView.findViewById(R.id.order_date);
|
||||
txtOrderPayment = itemView.findViewById(R.id.order_payment);
|
||||
txtOrderCount = itemView.findViewById(R.id.order_count);
|
||||
txtOrderPrice = itemView.findViewById(R.id.order_price);
|
||||
|
||||
btn_delete = itemView.findViewById(R.id.btn_delete);
|
||||
btn_detail = itemView.findViewById(R.id.btn_detail);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,26 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_count"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:fontFamily="@font/italic"
|
||||
android:text="Count of Order"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_price"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:fontFamily="@font/italic"
|
||||
android:text="Order Total Price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_payment"
|
||||
android:layout_marginLeft="10dp"
|
||||
|
||||
Reference in New Issue
Block a user