mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Fix bug and add alert dialog update
This commit is contained in:
@@ -10,7 +10,7 @@ android {
|
|||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 30
|
targetSdk 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "73.0"
|
versionName "75.0"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,10 +155,9 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
btnPlace.setOnClickListener(new View.OnClickListener() {
|
btnPlace.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (cart.size() > 0){
|
if (cart.size() > 0) {
|
||||||
showAlertDialog();
|
showAlertDialog();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
Toast.makeText(Cart.this, "Giỏ hàng của bạn đang trống!!!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(Cart.this, "Giỏ hàng của bạn đang trống!!!", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -167,7 +166,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
|
|
||||||
//Location
|
//Location
|
||||||
|
|
||||||
if(Common.currentLocation == null) {
|
if (Common.currentLocation == null) {
|
||||||
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
||||||
mSettingsClient = LocationServices.getSettingsClient(this);
|
mSettingsClient = LocationServices.getSettingsClient(this);
|
||||||
|
|
||||||
@@ -199,7 +198,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionDenied(PermissionDeniedResponse response) {
|
public void onPermissionDenied(PermissionDeniedResponse response) {
|
||||||
if(response.isPermanentlyDenied()){
|
if (response.isPermanentlyDenied()) {
|
||||||
openSettings();
|
openSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,8 +254,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
rdiAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
rdiAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked)
|
if (isChecked) {
|
||||||
{
|
|
||||||
edtAddress.setText("");
|
edtAddress.setText("");
|
||||||
edtAddress.setEnabled(true);
|
edtAddress.setEnabled(true);
|
||||||
}
|
}
|
||||||
@@ -265,11 +263,11 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Add event
|
//Add event
|
||||||
if(Common.currentAddress == null) {
|
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
||||||
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
if (isChecked) {
|
||||||
if (isChecked) {
|
if (Common.currentAddress == null) {
|
||||||
mGoogleMapService.getAddressName(String.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSyCqmoLlawoQzmwjZI2_Yo_V33An_nNZADs",
|
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.getLatitude(),
|
||||||
Common.currentLocation.getLongitude()))
|
Common.currentLocation.getLongitude()))
|
||||||
@@ -297,15 +295,14 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
Log.i("LOCATION", "" + t.getMessage());
|
Log.i("LOCATION", "" + t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
edtAddress.setText(Common.currentAddress);
|
||||||
|
edtAddress.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
edtAddress.setText(Common.currentAddress);
|
|
||||||
edtAddress.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
alertDialog.setView(order_address_comment);
|
alertDialog.setView(order_address_comment);
|
||||||
alertDialog.setIcon(R.drawable.ic_baseline_shopping_cart_24);
|
alertDialog.setIcon(R.drawable.ic_baseline_shopping_cart_24);
|
||||||
@@ -440,7 +437,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
|
|
||||||
//Location
|
//Location
|
||||||
|
|
||||||
private void openSettings(){
|
private void openSettings() {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
|
Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
|
||||||
@@ -449,7 +446,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLocationUpdates(){
|
private void startLocationUpdates() {
|
||||||
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
|
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Override
|
@Override
|
||||||
@@ -461,14 +458,14 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Exception e) {
|
public void onFailure(@NonNull Exception e) {
|
||||||
int statusCode = ((ApiException) e).getStatusCode();
|
int statusCode = ((ApiException) e).getStatusCode();
|
||||||
switch (statusCode){
|
switch (statusCode) {
|
||||||
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
|
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
|
||||||
Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade location settings");
|
Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade location settings");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResolvableApiException rae = (ResolvableApiException) e;
|
ResolvableApiException rae = (ResolvableApiException) e;
|
||||||
rae.startResolutionForResult(Cart.this, REQUEST_CHECK_SETTINGS);
|
rae.startResolutionForResult(Cart.this, REQUEST_CHECK_SETTINGS);
|
||||||
}catch (IntentSender.SendIntentException sie){
|
} catch (IntentSender.SendIntentException sie) {
|
||||||
Log.i(TAG, "PendingIntent unable to execute request");
|
Log.i(TAG, "PendingIntent unable to execute request");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -482,11 +479,11 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopLocationUpdates(){
|
private void stopLocationUpdates() {
|
||||||
mFusedLocationClient.removeLocationUpdates(mLocationCallBack).addOnCompleteListener(this, task -> Log.d(TAG, "Location updates stopped!"));
|
mFusedLocationClient.removeLocationUpdates(mLocationCallBack).addOnCompleteListener(this, task -> Log.d(TAG, "Location updates stopped!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkPermission(){
|
private boolean checkPermission() {
|
||||||
int permissionState = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
|
int permissionState = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
|
||||||
return permissionState == PackageManager.PERMISSION_GRANTED;
|
return permissionState == PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
@@ -494,7 +491,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if(mRequestingLocationUpdates && checkPermission()){
|
if (mRequestingLocationUpdates && checkPermission()) {
|
||||||
startLocationUpdates();
|
startLocationUpdates();
|
||||||
}
|
}
|
||||||
visibilityTextEmpty();
|
visibilityTextEmpty();
|
||||||
@@ -503,13 +500,13 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if(mRequestingLocationUpdates){
|
if (mRequestingLocationUpdates) {
|
||||||
stopLocationUpdates();
|
stopLocationUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visibilityTextEmpty(){
|
private void visibilityTextEmpty() {
|
||||||
if(cart.size() > 0){
|
if (cart.size() > 0) {
|
||||||
txtEmptyCart.setVisibility(View.GONE);
|
txtEmptyCart.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
txtEmptyCart.setVisibility(View.VISIBLE);
|
txtEmptyCart.setVisibility(View.VISIBLE);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import java.util.Locale;
|
|||||||
public class Common {
|
public class Common {
|
||||||
public static User currentUser;
|
public static User currentUser;
|
||||||
|
|
||||||
|
public static String versionAppNewest = "";
|
||||||
|
|
||||||
public static String PHONE_TEXT = "userPhone";
|
public static String PHONE_TEXT = "userPhone";
|
||||||
|
|
||||||
public static Location currentLocation;
|
public static Location currentLocation;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.waterbase.foodify;
|
package com.waterbase.foodify;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@@ -70,15 +68,13 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import dmax.dialog.SpotsDialog;
|
import dmax.dialog.SpotsDialog;
|
||||||
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 io.paperdb.Paper;
|
import io.paperdb.Paper;
|
||||||
|
|
||||||
|
|
||||||
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
|
String versionNameApp = BuildConfig.VERSION_NAME;
|
||||||
|
|
||||||
FirebaseDatabase database;
|
FirebaseDatabase database;
|
||||||
DatabaseReference category;
|
DatabaseReference category;
|
||||||
|
|
||||||
@@ -177,6 +173,11 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
database = FirebaseDatabase.getInstance();
|
database = FirebaseDatabase.getInstance();
|
||||||
category = database.getReference("Category");
|
category = database.getReference("Category");
|
||||||
|
|
||||||
|
if(Double.parseDouble(versionNameApp) < Double.parseDouble(Common.versionAppNewest)){
|
||||||
|
alertDialogUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>()
|
FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>()
|
||||||
.setQuery(category, Category.class)
|
.setQuery(category, Category.class)
|
||||||
.build();
|
.build();
|
||||||
@@ -238,6 +239,32 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void alertDialogUpdate() {
|
||||||
|
AlertDialog alertDialog = new AlertDialog.Builder(Home.this)
|
||||||
|
.setTitle("Thông báo!")
|
||||||
|
.setMessage("Hiện tại đã có phiên bản mới hơn! Vui lòng cập nhật ứng dụng để mang đến những trải nghiệm tốt nhất!")
|
||||||
|
.setPositiveButton("Đồng ý", null)
|
||||||
|
.setNegativeButton("Để sau", null)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||||
|
@Override
|
||||||
|
public void onShow(DialogInterface dialog) {
|
||||||
|
Button agree = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
|
||||||
|
agree.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Uri uri = Uri.parse("https://drive.google.com/uc?id=1uDUvpzJt8p96iDNMdNrsR9lqVAT06gqk&export=download");
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
|
alertDialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void showNotificationAlertDialog(String msg) {
|
private void showNotificationAlertDialog(String msg) {
|
||||||
AlertDialog alertDialog = new AlertDialog.Builder(Home.this)
|
AlertDialog alertDialog = new AlertDialog.Builder(Home.this)
|
||||||
.setTitle("Thông báo!")
|
.setTitle("Thông báo!")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.google.firebase.database.DataSnapshot;
|
import com.google.firebase.database.DataSnapshot;
|
||||||
@@ -31,6 +32,9 @@ public class Welcome extends AppCompatActivity {
|
|||||||
Button btnSignIn, btnSignUp;
|
Button btnSignIn, btnSignUp;
|
||||||
TextView txtSlogan, txtAppName;
|
TextView txtSlogan, txtAppName;
|
||||||
|
|
||||||
|
FirebaseDatabase database;
|
||||||
|
DatabaseReference version;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -46,6 +50,23 @@ public class Welcome extends AppCompatActivity {
|
|||||||
Paper.init(this);
|
Paper.init(this);
|
||||||
|
|
||||||
|
|
||||||
|
database = FirebaseDatabase.getInstance();
|
||||||
|
version = database.getReference("Version");
|
||||||
|
|
||||||
|
version.addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
String value = snapshot.getValue(String.class);
|
||||||
|
Common.versionAppNewest = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
Toast.makeText(Welcome.this, "Không thể truy xuất phiên bản app!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<external-path name="external_files" path="."/>
|
||||||
|
</paths>
|
||||||
Reference in New Issue
Block a user