mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 20:00:53 +00:00
Get Address from location phone and fix UI
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -49,6 +50,10 @@ import com.waterbase.foodify.Remote.APIService;
|
||||
import com.waterbase.foodify.Remote.IGoogleService;
|
||||
import com.waterbase.foodify.ViewHolder.CartAdapter;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -66,6 +71,8 @@ import retrofit2.Response;
|
||||
public class Cart extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
|
||||
LocationListener {
|
||||
|
||||
String address = null;
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
@@ -230,7 +237,14 @@ public class Cart extends AppCompatActivity implements GoogleApiClient.Connectio
|
||||
|
||||
//Radio
|
||||
RadioButton rdiShipToAddress = (RadioButton) order_address_comment.findViewById(R.id.rdiShipToAddress);
|
||||
RadioButton rdiHomeAddress = (RadioButton) order_address_comment.findViewById(R.id.rdiHomeAddress);
|
||||
RadioButton rdiAddress = (RadioButton) order_address_comment.findViewById(R.id.rdiAdress);
|
||||
|
||||
rdiAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
edtAddress.setText("");
|
||||
}
|
||||
});
|
||||
|
||||
//Add event
|
||||
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@@ -238,7 +252,32 @@ public class Cart extends AppCompatActivity implements GoogleApiClient.Connectio
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(isChecked) {
|
||||
if(isChecked){
|
||||
mGoogleMapService.getAddressName(String.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSyCqmoLlawoQzmwjZI2_Yo_V33An_nNZADs",
|
||||
mLastLocation.getLatitude(),
|
||||
mLastLocation.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");
|
||||
|
||||
JSONObject firstObject = resultsArray.getJSONObject(0);
|
||||
|
||||
address = firstObject.getString("formatted_address");
|
||||
edtAddress.setText(address);
|
||||
} 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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,6 +290,12 @@ public class Cart extends AppCompatActivity implements GoogleApiClient.Connectio
|
||||
alertDialog.setPositiveButton("Đặt", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
if(TextUtils.isEmpty(address)){
|
||||
Toast.makeText(Cart.this, "Vui lòng nhập địa chỉ giao hàng!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Create new Request
|
||||
Request request = new Request(
|
||||
Common.currentUser.getPhone(),
|
||||
@@ -269,6 +314,10 @@ public class Cart extends AppCompatActivity implements GoogleApiClient.Connectio
|
||||
|
||||
sendNotificationOrder(order_number);
|
||||
|
||||
//Delete Cart
|
||||
new Database(getBaseContext()).cleanCart();
|
||||
Toast.makeText(Cart.this, "Đặt hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Common {
|
||||
}
|
||||
|
||||
public static IGoogleService getGoogleMapAPI(){
|
||||
return RetrofitClient.getGoogleClient(GOOGLE_API_URL).create(IGoogleService.class);
|
||||
return RetrofitClient.getGoogleApiClient(GOOGLE_API_URL).create(IGoogleService.class);
|
||||
}
|
||||
|
||||
public static final String DELETE = "Xoá";
|
||||
@@ -29,11 +29,11 @@ public class Common {
|
||||
|
||||
public static String convertCodeToStatus(String status) {
|
||||
if(status.equals("0"))
|
||||
return "Placed";
|
||||
return "Đã nhận đơn";
|
||||
else if(status.equals("1"))
|
||||
return "On my way";
|
||||
return "Đang trên đường";
|
||||
else
|
||||
return "Shipped";
|
||||
return "Giao thành công";
|
||||
}
|
||||
|
||||
public static boolean isConnectedToInternet(Context context) {
|
||||
|
||||
@@ -60,7 +60,6 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
DatabaseReference category;
|
||||
|
||||
RecyclerView recyler_menu;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
||||
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
@@ -2,14 +2,16 @@ package com.waterbase.foodify.Remote;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||
|
||||
|
||||
public class RetrofitClient {
|
||||
private static Retrofit retrofit = null;
|
||||
private static Retrofit retrofit = null; //*
|
||||
|
||||
public static Retrofit getClient(String baseURL){
|
||||
|
||||
if (retrofit == null){
|
||||
|
||||
public static Retrofit getClient(String baseURL)
|
||||
{
|
||||
if(retrofit == null) {
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(baseURL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
@@ -18,14 +20,17 @@ public class RetrofitClient {
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
public static Retrofit getGoogleClient(String baseURL)
|
||||
{
|
||||
if(retrofit == null) {
|
||||
retrofit = new Retrofit.Builder()
|
||||
private static Retrofit retrofit2 = null; //*
|
||||
|
||||
public static Retrofit getGoogleApiClient(String baseURL){
|
||||
|
||||
if (retrofit2 == null){
|
||||
|
||||
retrofit2 = new Retrofit.Builder()
|
||||
.baseUrl(baseURL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.build();
|
||||
}
|
||||
return retrofit;
|
||||
return retrofit2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class SignIn extends AppCompatActivity {
|
||||
Paper.book().write(Common.PWD_KEY, edtPassword.getText().toString());
|
||||
}
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
|
||||
mDialog.setMessage("Please waiting...");
|
||||
mDialog.setMessage("Xin vui lòng chờ...");
|
||||
mDialog.show();
|
||||
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class Welcome extends AppCompatActivity {
|
||||
final DatabaseReference table_user = database.getReference("User");
|
||||
|
||||
final ProgressDialog mDialog = new ProgressDialog(Welcome.this);
|
||||
mDialog.setMessage("Please waiting...");
|
||||
mDialog.setMessage("Xin vui lòng chờ...");
|
||||
mDialog.show();
|
||||
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="Total: "
|
||||
android:text="Tổng cộng: "
|
||||
android:textSize="20sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -59,7 +59,7 @@
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="Place Order"
|
||||
android:text="Đặt hàng"
|
||||
android:textColor="@android:color/white"
|
||||
app:cornerRadius="4dp"
|
||||
app:fButtonColor="@color/btnSignActive"
|
||||
|
||||
@@ -46,10 +46,11 @@
|
||||
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
|
||||
android:id="@+id/btn_quantity"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="47dp"
|
||||
android:layout_margin="10dp"
|
||||
app:textSize="8sp"
|
||||
app:backGroundColor="@color/colorAccent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
app:textSize="6sp"
|
||||
app:textColor="@color/purple_500"
|
||||
app:backGroundColor="@color/white"
|
||||
app:initialNumber="1"
|
||||
app:finalNumber="20"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="@drawable/side_nav_bar"
|
||||
android:background="@color/fbutton_color_transparent"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
@@ -28,9 +28,4 @@
|
||||
android:text="@string/nav_header_title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nav_header_subtitle" />
|
||||
</LinearLayout>
|
||||
@@ -61,10 +61,11 @@
|
||||
/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rdiHomeAddress"
|
||||
android:id="@+id/rdiAdress"
|
||||
android:text="Giao hàng đến địa chỉ trên"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
/>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user