Fix bug and add alert dialog update

This commit is contained in:
phanhuuloi27
2022-07-12 15:27:40 +07:00
parent cb1a266dae
commit b10e4c6269
6 changed files with 87 additions and 36 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ android {
minSdk 23
targetSdk 30
versionCode 1
versionName "73.0"
versionName "75.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -155,10 +155,9 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
btnPlace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cart.size() > 0){
if (cart.size() > 0) {
showAlertDialog();
}
else
} else
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
if(Common.currentLocation == null) {
if (Common.currentLocation == null) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mSettingsClient = LocationServices.getSettingsClient(this);
@@ -199,7 +198,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
@Override
public void onPermissionDenied(PermissionDeniedResponse response) {
if(response.isPermanentlyDenied()){
if (response.isPermanentlyDenied()) {
openSettings();
}
}
@@ -255,8 +254,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
rdiAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
{
if (isChecked) {
edtAddress.setText("");
edtAddress.setEnabled(true);
}
@@ -265,11 +263,11 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
});
//Add event
if(Common.currentAddress == null) {
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rdiShipToAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean 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",
Common.currentLocation.getLatitude(),
Common.currentLocation.getLongitude()))
@@ -297,15 +295,14 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
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.setIcon(R.drawable.ic_baseline_shopping_cart_24);
@@ -440,7 +437,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
//Location
private void openSettings(){
private void openSettings() {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
@@ -449,7 +446,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
startActivity(intent);
}
private void startLocationUpdates(){
private void startLocationUpdates() {
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
@SuppressLint("MissingPermission")
@Override
@@ -461,14 +458,14 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch (statusCode){
switch (statusCode) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade location settings");
try {
ResolvableApiException rae = (ResolvableApiException) e;
rae.startResolutionForResult(Cart.this, REQUEST_CHECK_SETTINGS);
}catch (IntentSender.SendIntentException sie){
} catch (IntentSender.SendIntentException sie) {
Log.i(TAG, "PendingIntent unable to execute request");
}
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!"));
}
private boolean checkPermission(){
private boolean checkPermission() {
int permissionState = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
return permissionState == PackageManager.PERMISSION_GRANTED;
}
@@ -494,7 +491,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
@Override
protected void onResume() {
super.onResume();
if(mRequestingLocationUpdates && checkPermission()){
if (mRequestingLocationUpdates && checkPermission()) {
startLocationUpdates();
}
visibilityTextEmpty();
@@ -503,13 +500,13 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
@Override
protected void onPause() {
super.onPause();
if(mRequestingLocationUpdates){
if (mRequestingLocationUpdates) {
stopLocationUpdates();
}
}
private void visibilityTextEmpty(){
if(cart.size() > 0){
private void visibilityTextEmpty() {
if (cart.size() > 0) {
txtEmptyCart.setVisibility(View.GONE);
} else {
txtEmptyCart.setVisibility(View.VISIBLE);
@@ -17,6 +17,8 @@ import java.util.Locale;
public class Common {
public static User currentUser;
public static String versionAppNewest = "";
public static String PHONE_TEXT = "userPhone";
public static Location currentLocation;
@@ -1,7 +1,5 @@
package com.waterbase.foodify;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
@@ -70,15 +68,13 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
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;
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
String versionNameApp = BuildConfig.VERSION_NAME;
FirebaseDatabase database;
DatabaseReference category;
@@ -177,6 +173,11 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
database = FirebaseDatabase.getInstance();
category = database.getReference("Category");
if(Double.parseDouble(versionNameApp) < Double.parseDouble(Common.versionAppNewest)){
alertDialogUpdate();
}
FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(category, Category.class)
.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) {
AlertDialog alertDialog = new AlertDialog.Builder(Home.this)
.setTitle("Thông báo!")
@@ -10,6 +10,7 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.database.DataSnapshot;
@@ -31,6 +32,9 @@ public class Welcome extends AppCompatActivity {
Button btnSignIn, btnSignUp;
TextView txtSlogan, txtAppName;
FirebaseDatabase database;
DatabaseReference version;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -46,6 +50,23 @@ public class Welcome extends AppCompatActivity {
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() {
@Override
public void onClick(View v) {
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>