mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Add notification alert dialog
This commit is contained in:
@@ -10,7 +10,7 @@ android {
|
|||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 30
|
targetSdk 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "70.0"
|
versionName "71.0"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,9 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
if (!TextUtils.isEmpty(Common.currentUser.getHomeAddress()) || Common.currentUser.getHomeAddress() != null) {
|
if (!TextUtils.isEmpty(Common.currentUser.getHomeAddress()) || Common.currentUser.getHomeAddress() != null) {
|
||||||
edtAddress.setText(Common.currentUser.getHomeAddress());
|
edtAddress.setText(Common.currentUser.getHomeAddress());
|
||||||
|
edtAddress.setEnabled(false);
|
||||||
} else
|
} else
|
||||||
|
edtAddress.setEnabled(false);
|
||||||
Toast.makeText(Cart.this, "Vui lòng điền địa chỉ mặc định của bạn!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(Cart.this, "Vui lòng điền địa chỉ mặc định của bạn!", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -251,7 +253,11 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
@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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -275,6 +281,7 @@ public class Cart extends AppCompatActivity implements RecyclerItemTouchHelperLi
|
|||||||
|
|
||||||
address = firstObject.getString("formatted_address");
|
address = firstObject.getString("formatted_address");
|
||||||
edtAddress.setText(address);
|
edtAddress.setText(address);
|
||||||
|
edtAddress.setEnabled(false);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.waterbase.foodify;
|
package com.waterbase.foodify;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
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;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -16,6 +19,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.view.animation.LayoutAnimationController;
|
import android.view.animation.LayoutAnimationController;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -25,6 +29,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
import androidx.core.view.GravityCompat;
|
import androidx.core.view.GravityCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
@@ -61,6 +66,8 @@ import com.waterbase.foodify.ViewHolder.MenuViewHolder;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import dmax.dialog.SpotsDialog;
|
import dmax.dialog.SpotsDialog;
|
||||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||||
@@ -75,6 +82,8 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
FirebaseDatabase database;
|
FirebaseDatabase database;
|
||||||
DatabaseReference category;
|
DatabaseReference category;
|
||||||
|
|
||||||
|
final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!_])(?=\\S+$).{4,}$";
|
||||||
|
|
||||||
RecyclerView recyler_menu;
|
RecyclerView recyler_menu;
|
||||||
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
||||||
|
|
||||||
@@ -222,6 +231,55 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
//Setup Slider
|
//Setup Slider
|
||||||
setupSlider();
|
setupSlider();
|
||||||
|
|
||||||
|
if(!NotificationManagerCompat.from(this).areNotificationsEnabled()){
|
||||||
|
showNotificationAlertDialog("Hãy bật quyền thông báo trên thiết bị của bạn để chúng thôi có thể cung cấp thông tin cho bạn một cách nhanh nhất!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showNotificationAlertDialog(String msg) {
|
||||||
|
AlertDialog alertDialog = new AlertDialog.Builder(Home.this)
|
||||||
|
.setTitle("Thông báo!")
|
||||||
|
.setMessage(msg)
|
||||||
|
.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) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
|
||||||
|
intent.setData(uri);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
alertDialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button disagree = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||||
|
|
||||||
|
disagree.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Paper.book().write("sub_new", "false");
|
||||||
|
alertDialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alertDialog.show();
|
||||||
|
TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||||
|
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/regular.ttf");
|
||||||
|
textView.setTypeface(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyFontToMenuItem(MenuItem mi) {
|
private void applyFontToMenuItem(MenuItem mi) {
|
||||||
@@ -241,14 +299,12 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
@Override
|
@Override
|
||||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||||
|
|
||||||
for(DataSnapshot postSnapShot: dataSnapshot.getChildren())
|
for (DataSnapshot postSnapShot : dataSnapshot.getChildren()) {
|
||||||
{
|
|
||||||
Banner banner = postSnapShot.getValue(Banner.class);
|
Banner banner = postSnapShot.getValue(Banner.class);
|
||||||
|
|
||||||
image_list.put(banner.getName() + "@@@" + banner.getId(), banner.getImage());
|
image_list.put(banner.getName() + "@@@" + banner.getId(), banner.getImage());
|
||||||
}
|
}
|
||||||
for(String key: image_list.keySet())
|
for (String key : image_list.keySet()) {
|
||||||
{
|
|
||||||
String[] keySplit = key.split("@@@");
|
String[] keySplit = key.split("@@@");
|
||||||
String nameOfFood = keySplit[0];
|
String nameOfFood = keySplit[0];
|
||||||
String idOfFood = keySplit[1];
|
String idOfFood = keySplit[1];
|
||||||
@@ -342,8 +398,7 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
showSettingDialog();
|
showSettingDialog();
|
||||||
} else if (id == R.id.nav_favorites) {
|
} else if (id == R.id.nav_favorites) {
|
||||||
startActivity(new Intent(Home.this, FavoritesActivity.class));
|
startActivity(new Intent(Home.this, FavoritesActivity.class));
|
||||||
}
|
} else if (id == R.id.nav_log_out) {
|
||||||
else if (id == R.id.nav_log_out) {
|
|
||||||
|
|
||||||
//Delete Remember user & password
|
//Delete Remember user & password
|
||||||
Paper.book().destroy();
|
Paper.book().destroy();
|
||||||
@@ -384,14 +439,14 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
if(ckb_subscribe_new.isChecked())
|
if (ckb_subscribe_new.isChecked()) {
|
||||||
{
|
|
||||||
FirebaseMessaging.getInstance().subscribeToTopic(Common.topicName);
|
FirebaseMessaging.getInstance().subscribeToTopic(Common.topicName);
|
||||||
//Write value
|
//Write value
|
||||||
Paper.book().write("sub_new", "true");
|
Paper.book().write("sub_new", "true");
|
||||||
|
if(!NotificationManagerCompat.from(Home.this).areNotificationsEnabled()){
|
||||||
|
showNotificationAlertDialog("Oops, máy bạn chưa được bật thông báo! Bạn có muốn bật để nhận thông báo từ hệ thống báo không?");
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
FirebaseMessaging.getInstance().unsubscribeFromTopic(Common.topicName);
|
FirebaseMessaging.getInstance().unsubscribeFromTopic(Common.topicName);
|
||||||
//Write value
|
//Write value
|
||||||
Paper.book().write("sub_new", "false");
|
Paper.book().write("sub_new", "false");
|
||||||
@@ -451,14 +506,25 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
|
|
||||||
alertDialog.setView(layout_pwd);
|
alertDialog.setView(layout_pwd);
|
||||||
|
|
||||||
//Button
|
alertDialog.setPositiveButton("Đổi mật khẩu", null);
|
||||||
alertDialog.setPositiveButton("Đổi mật khẩu", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
|
|
||||||
|
AlertDialog d = alertDialog.create();
|
||||||
|
d.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||||
|
@Override
|
||||||
|
public void onShow(DialogInterface dialog) {
|
||||||
|
Button changePassword = d.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
changePassword.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
android.app.AlertDialog waitingDialog = new SpotsDialog(Home.this);
|
android.app.AlertDialog waitingDialog = new SpotsDialog(Home.this);
|
||||||
waitingDialog.show();
|
waitingDialog.show();
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(edtPassword.getText().toString()) && !TextUtils.isEmpty(edtNewPassword.getText().toString()) && !TextUtils.isEmpty(edtRepeatPassword.getText().toString())) {
|
||||||
|
//Verify password
|
||||||
|
Pattern patternPassword = Pattern.compile(PASSWORD_PATTERN);
|
||||||
|
Matcher matcherPassword = patternPassword.matcher(edtRepeatPassword.getText().toString());
|
||||||
|
|
||||||
|
if (matcherPassword.matches() && edtRepeatPassword.getText().toString().length() >= 8) {
|
||||||
//Check old password
|
//Check old password
|
||||||
if (edtPassword.getText().toString().equals(Common.currentUser.getPassword())) {
|
if (edtPassword.getText().toString().equals(Common.currentUser.getPassword())) {
|
||||||
|
|
||||||
@@ -475,7 +541,9 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
public void onComplete(@NonNull Task<Void> task) {
|
||||||
waitingDialog.dismiss();
|
waitingDialog.dismiss();
|
||||||
|
Common.currentUser.setPassword(edtNewPassword.getText().toString());
|
||||||
Toast.makeText(Home.this, "Mật khẩu đã được cập nhật!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(Home.this, "Mật khẩu đã được cập nhật!", Toast.LENGTH_SHORT).show();
|
||||||
|
d.dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.addOnFailureListener(new OnFailureListener() {
|
.addOnFailureListener(new OnFailureListener() {
|
||||||
@@ -486,17 +554,31 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
waitingDialog.dismiss();
|
waitingDialog.dismiss();
|
||||||
Toast.makeText(Home.this, "Mật khẩu chưa khớp! Vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
edtRepeatPassword.setError("Mật khẩu chưa khớp! Vui lòng thử lại!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
waitingDialog.dismiss();
|
waitingDialog.dismiss();
|
||||||
Toast.makeText(Home.this, "Sai mật khẩu! Vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
edtPassword.setError("Sai mật khẩu, vui lòng thử lại!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
waitingDialog.dismiss();
|
||||||
|
Toast.makeText(Home.this, "Mật khẩu của bạn cần tối thiểu có 8 ký tự, 1 ký tự viết hoa, 1 số và 1 ký tự đặc biệt!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
waitingDialog.dismiss();
|
||||||
|
if(TextUtils.isEmpty(edtPassword.getText().toString())){
|
||||||
|
edtPassword.setError("Vui lòng điền vào trường này!");
|
||||||
|
} else if(TextUtils.isEmpty(edtNewPassword.getText().toString())){
|
||||||
|
edtNewPassword.setError("Vui lòng điền vào trường này!");
|
||||||
|
} else if(TextUtils.isEmpty(edtRepeatPassword.getText().toString())){
|
||||||
|
edtRepeatPassword.setError("Vui lòng điền vào trường này!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
AlertDialog dialog = alertDialog.create();
|
});
|
||||||
dialog.show();
|
d.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class SignUp extends AppCompatActivity {
|
|||||||
Button btnSignUp;
|
Button btnSignUp;
|
||||||
TextView txtAppName;
|
TextView txtAppName;
|
||||||
|
|
||||||
final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!])(?=\\S+$).{4,}$";
|
final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!_])(?=\\S+$).{4,}$";
|
||||||
final String PHONE_PATTERN = "^0[98753]{1}\\d{8}$";
|
final String PHONE_PATTERN = "^0[98753]{1}\\d{8}$";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,17 +100,16 @@ public class Welcome extends AppCompatActivity {
|
|||||||
startActivity(homeIntent);
|
startActivity(homeIntent);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(Welcome.this, "Số điện thoại hoặc mật khẩu không đúng. Xin vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
Paper.book().destroy();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
Toast.makeText(Welcome.this, "Số điện thoại chưa được đăng ký. Vui lòng đăng ký để sử dụng!", Toast.LENGTH_SHORT).show();
|
Paper.book().destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(DatabaseError databaseError) {
|
public void onCancelled(DatabaseError databaseError) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -136,24 +136,25 @@
|
|||||||
android:fontFamily="@font/regular"
|
android:fontFamily="@font/regular"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textColor="#FBFBFB"
|
android:textColor="#FBFBFB"
|
||||||
|
android:gravity="center"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
app:layout_constraintHorizontal_bias=".3"
|
app:layout_constraintEnd_toStartOf="@+id/textViewB"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/btnSignIn" />
|
app:layout_constraintTop_toBottomOf="@+id/btnSignIn" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/textViewB"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:text="Đăng ký tại đây!"
|
android:text="Đăng ký tại đây!"
|
||||||
android:fontFamily="@font/bold"
|
android:fontFamily="@font/bold"
|
||||||
|
android:gravity="center"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textColor="@color/purple_500"
|
android:textColor="@color/purple_500"
|
||||||
android:onClick="register"
|
android:onClick="register"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/textView"
|
app:layout_constraintStart_toEndOf="@+id/textView"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/btnSignIn" />
|
app:layout_constraintTop_toBottomOf="@+id/btnSignIn" />
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ android {
|
|||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 30
|
targetSdk 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "71.0"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user