Update function

This commit is contained in:
Nezumi2711
2022-07-15 10:08:05 +07:00
parent f1fd1af8f9
commit c43d3bc3f1
11 changed files with 118 additions and 18 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ android {
minSdk 23
targetSdk 30
versionCode 1
versionName "79.0"
versionName "80.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
+7 -3
View File
@@ -60,13 +60,17 @@
android:exported="false" />
<activity
android:name=".ChangePassword"
android:exported="false" />
android:exported="false"
android:theme="@style/Theme.Foodify.NoActionBar"
/>
<activity
android:name=".ForgotPassword"
android:exported="false" />
android:exported="false"
android:theme="@style/Theme.Foodify.NoActionBar"/>
<activity
android:name=".VerifyPhone"
android:exported="false" />
android:exported="false"
android:theme="@style/Theme.Foodify.NoActionBar"/>
<activity
android:name=".OrderStatus"
android:exported="false" />
@@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.waterbase.foodify.Common.Common;
import com.waterbase.foodify.Model.User;
import java.util.regex.Matcher;
@@ -58,7 +59,7 @@ public class ChangePassword extends AppCompatActivity {
//Check same password
if (edtPassword.getText().toString().equals(edtPasswordVerify.getText().toString())) {
table_user.child(phone).child("password").setValue(edtPasswordVerify.getText().toString());
table_user.child(phone).child("password").setValue(Common.encryptPassword(edtPasswordVerify.getText().toString()));
Toast.makeText(ChangePassword.this, "Đổi mật khẩu thành công. Vui lòng đăng nhập lại để tiếp tục!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(ChangePassword.this, SignIn.class));
finish();
@@ -11,6 +11,9 @@ import com.waterbase.foodify.Remote.APIService;
import com.waterbase.foodify.Remote.IGoogleService;
import com.waterbase.foodify.Remote.RetrofitClient;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Locale;
@@ -82,4 +85,36 @@ public class Common {
DateFormat.format("dd-MM-yyyy HH:mm", calendar).toString());
return date.toString();
}
public static String encryptPassword(String input)
{
try {
// getInstance() method is called with algorithm SHA-1
MessageDigest md = MessageDigest.getInstance("SHA-1");
// digest() method is called
// to calculate message digest of the input string
// returned as array of byte
byte[] messageDigest = md.digest(input.getBytes());
// Convert byte array into signum representation
BigInteger no = new BigInteger(1, messageDigest);
// Convert message digest into hex value
String hashtext = no.toString(16);
// Add preceding 0s to make it 32 bit
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
// return the HashText
return hashtext;
}
// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
@@ -73,6 +73,8 @@ import io.paperdb.Paper;
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private long backPressedTime;
String versionNameApp = BuildConfig.VERSION_NAME;
FirebaseDatabase database;
@@ -471,7 +473,7 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
//Write value
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?");
showNotificationAlertDialog("Oops, máy bạn chưa được cấp quyền thông báo! Bạn có muốn bật để nhận thông báo từ hệ thống không?");
}
} else {
FirebaseMessaging.getInstance().unsubscribeFromTopic(Common.topicName);
@@ -622,4 +624,17 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if(backPressedTime + 2000 > System.currentTimeMillis()) {
super.onBackPressed();
return;
} else {
Toast.makeText(this, "Nhấn BACK 1 lần nữa để thoát!", Toast.LENGTH_SHORT).show();
}
backPressedTime = System.currentTimeMillis();
}
}
@@ -58,7 +58,7 @@ public class SignIn extends AppCompatActivity {
//Save user& password
if(ckbRemember.isChecked()) {
Paper.book().write(Common.USER_KEY, edtPhone.getText().toString());
Paper.book().write(Common.PWD_KEY, edtPassword.getText().toString());
Paper.book().write(Common.PWD_KEY, Common.encryptPassword(edtPassword.getText().toString()));
}
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
mDialog.setMessage("Xin vui lòng chờ...");
@@ -77,7 +77,7 @@ public class SignIn extends AppCompatActivity {
mDialog.dismiss();
User user = dataSnapshot.child(edtPhone.getText().toString()).getValue(User.class);
user.setPhone(edtPhone.getText().toString());
if (user.getPassword().equals(edtPassword.getText().toString())) {
if (user.getPassword().equals(Common.encryptPassword(edtPassword.getText().toString()))) {
Intent homeIntent = new Intent(SignIn.this, Home.class);
Common.currentUser = user;
startActivity(homeIntent);
@@ -125,7 +125,7 @@ public class SignUp extends AppCompatActivity {
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
progressBar.setVisibility(View.GONE);
btnSignUp.setVisibility(View.VISIBLE);
User user = new User(edtName.getText().toString(), edtPassword.getText().toString());
User user = new User(edtName.getText().toString(), Common.encryptPassword(edtPassword.getText().toString()));
Intent intent = new Intent(SignUp.this, VerifyPhone.class);
intent.putExtra("user", user);
intent.putExtra("phone", edtPhone.getText().toString());
@@ -133,6 +133,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chưa có tài khoản Foodify?"
android:layout_marginRight="4dp"
android:fontFamily="@font/regular"
android:textAlignment="center"
android:textColor="#FBFBFB"
@@ -155,27 +155,29 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Đã tạo tài khoản?"
android:layout_marginRight="4dp"
android:fontFamily="@font/regular"
android:textAlignment="center"
android:gravity="center"
android:textColor="#FBFBFB"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias=".3"
app:layout_constraintEnd_toStartOf="@+id/txtSignIn"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/frameLayout" />
<TextView
android:id="@+id/txtSignIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Đăng nhập tại đây!"
android:gravity="center"
android:fontFamily="@font/bold"
android:onClick="login"
android:textAlignment="center"
android:textColor="@color/purple_500"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/frameLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -1,16 +1,58 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Foodify" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Foodify" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.Foodify.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.Foodify.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.Foodify.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="CollapsedAppbar" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">24sp</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textStyle">normal</item>
</style>
<style name="ExpandedAppbar" parent="@android:style/TextAppearance.Material.Title">
<item name="android:textColor">@color/purple_500</item>
<item name="android:textStyle">normal</item>
</style>
<!--Rating Dialog -->
<style name="RatingDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="background">@android:color/white</item>
<item name="android:buttonBarPositiveButtonStyle">@style/RatingDialogButtonStyle</item>
<item name="android:buttonBarNegativeButtonStyle">@style/RatingDialogButtonStyle</item>
</style>
<style name="RatingDialogButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textSize">@dimen/text_size_medium</item>
</style>
<style name="RatingDialogFadeAnim">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
<style name="fontTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">@fonts/</item>
</style>
</resources>
+1 -1
View File
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Foodify" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Foodify" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>