mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Refactor Code
This commit is contained in:
@@ -2,8 +2,11 @@ package com.capstone.foodify;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
@@ -11,12 +14,22 @@ public class ForgotPasswordActivity extends AppCompatActivity {
|
||||
|
||||
TextInputLayout textInput_account;
|
||||
|
||||
|
||||
ImageView back_image;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_forgot_password);
|
||||
|
||||
initComponent();
|
||||
|
||||
//Back button
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(ForgotPasswordActivity.this, SignInActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
setFontUI();
|
||||
}
|
||||
|
||||
@@ -28,4 +41,8 @@ public class ForgotPasswordActivity extends AppCompatActivity {
|
||||
textInput_account.setTypeface(bebas);
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,13 +24,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
initComponent();
|
||||
|
||||
bottomNavigation();
|
||||
}
|
||||
|
||||
private void bottomNavigation() {
|
||||
|
||||
private void initComponent() {
|
||||
bottomNavigationView = findViewById(R.id.bottom_nav);
|
||||
viewPager2 = findViewById(R.id.viewPager);
|
||||
}
|
||||
private void bottomNavigation() {
|
||||
viewPagerAdapter = new ViewPagerAdapter(this);
|
||||
viewPager2.setAdapter(viewPagerAdapter);
|
||||
bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
|
||||
|
||||
@@ -27,13 +27,9 @@ public class SignInActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_in);
|
||||
initComponent();
|
||||
|
||||
setFontUI();
|
||||
|
||||
signUp_textView = (TextView) findViewById(R.id.sign_up_textView);
|
||||
forgotPassword_textView = (TextView) findViewById(R.id.forgotPassword_textView);
|
||||
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -54,12 +50,15 @@ public class SignInActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setFontUI() {
|
||||
Typeface bebas= Typeface.createFromAsset(getAssets(), "font/bebas.ttf");
|
||||
|
||||
private void initComponent() {
|
||||
textInput_account = (TextInputLayout) findViewById(R.id.textInput_account);
|
||||
textInput_password = (TextInputLayout) findViewById(R.id.textInput_password);
|
||||
signUp_textView = (TextView) findViewById(R.id.sign_up_textView);
|
||||
forgotPassword_textView = (TextView) findViewById(R.id.forgotPassword_textView);
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
}
|
||||
private void setFontUI() {
|
||||
Typeface bebas= Typeface.createFromAsset(getAssets(), "font/bebas.ttf");
|
||||
|
||||
textInput_account.setTypeface(bebas);
|
||||
textInput_password.setTypeface(bebas);
|
||||
@@ -67,12 +66,4 @@ public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
// this event will enable the back
|
||||
// function to the button on press
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@@ -42,7 +41,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
TextInputLayout textInput_email, textInput_password, textInput_phone,
|
||||
textInput_address, textInput_repeatPassword, textInput_firstName, textInput_lastName, textInput_birthDay;
|
||||
final Calendar myCalendar= Calendar.getInstance();
|
||||
EditText editText, edt_birthday;
|
||||
EditText edt_birthday;
|
||||
TextView signIn_textView;
|
||||
Spinner wardSpinner, districtSpinner;
|
||||
ImageView back_image;
|
||||
@@ -60,22 +59,17 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_up);
|
||||
|
||||
initComponent();
|
||||
|
||||
setFontUI();
|
||||
chooseDateOfBirth();
|
||||
|
||||
districtSpinner = (Spinner) findViewById(R.id.district);
|
||||
wardSpinner = (Spinner) findViewById(R.id.ward);
|
||||
|
||||
if(districtListData.size() == 0){
|
||||
getListDistrict();
|
||||
} else {
|
||||
setAdapter(districtList, "---Quận", districtSpinner);
|
||||
}
|
||||
|
||||
|
||||
getListWard(0);
|
||||
|
||||
signIn_textView = (TextView) findViewById(R.id.signIn_textView);
|
||||
signIn_textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -83,8 +77,6 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -114,7 +106,27 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
textInput_email= (TextInputLayout) findViewById(R.id.textInput_email);
|
||||
textInput_password = (TextInputLayout) findViewById(R.id.textInput_password);
|
||||
textInput_phone = (TextInputLayout) findViewById(R.id.textInput_phone);
|
||||
textInput_address = (TextInputLayout) findViewById(R.id.textInput_address);
|
||||
textInput_repeatPassword = (TextInputLayout) findViewById(R.id.textInput_confirmPassword);
|
||||
textInput_firstName = (TextInputLayout) findViewById(R.id.textInput_firstName);
|
||||
textInput_lastName = (TextInputLayout) findViewById(R.id.textInput_lastName);
|
||||
textInput_birthDay = (TextInputLayout) findViewById(R.id.textInput_birthDay);
|
||||
|
||||
edt_birthday = (EditText) findViewById(R.id.edt_birthDay);
|
||||
|
||||
districtSpinner = (Spinner) findViewById(R.id.district);
|
||||
wardSpinner = (Spinner) findViewById(R.id.ward);
|
||||
|
||||
signIn_textView = (TextView) findViewById(R.id.signIn_textView);
|
||||
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
|
||||
}
|
||||
|
||||
private void getListDistrict() {
|
||||
@@ -215,7 +227,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
private void chooseDateOfBirth() {
|
||||
//Calendar date of birth
|
||||
editText=(EditText) findViewById(R.id.edt_birthDay);
|
||||
|
||||
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int month, int day) {
|
||||
@@ -225,7 +237,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
updateLabel();
|
||||
}
|
||||
};
|
||||
editText.setOnClickListener(new View.OnClickListener() {
|
||||
edt_birthday.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
new DatePickerDialog(SignUpActivity.this,date,myCalendar.get(Calendar.YEAR),myCalendar.get(Calendar.MONTH),myCalendar.get(Calendar.DAY_OF_MONTH)).show();
|
||||
@@ -236,24 +248,12 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
private void updateLabel(){
|
||||
String myFormat="dd/MM/yyyy";
|
||||
SimpleDateFormat dateFormat=new SimpleDateFormat(myFormat, Locale.US);
|
||||
editText.setText(dateFormat.format(myCalendar.getTime()));
|
||||
edt_birthday.setText(dateFormat.format(myCalendar.getTime()));
|
||||
}
|
||||
|
||||
private void setFontUI() {
|
||||
Typeface bebas= Typeface.createFromAsset(getAssets(), "font/bebas.ttf");
|
||||
|
||||
//Find view ID
|
||||
textInput_email= (TextInputLayout) findViewById(R.id.textInput_email);
|
||||
textInput_password = (TextInputLayout) findViewById(R.id.textInput_password);
|
||||
textInput_phone = (TextInputLayout) findViewById(R.id.textInput_phone);
|
||||
textInput_address = (TextInputLayout) findViewById(R.id.textInput_address);
|
||||
textInput_repeatPassword = (TextInputLayout) findViewById(R.id.textInput_confirmPassword);
|
||||
textInput_firstName = (TextInputLayout) findViewById(R.id.textInput_firstName);
|
||||
textInput_lastName = (TextInputLayout) findViewById(R.id.textInput_lastName);
|
||||
textInput_birthDay = (TextInputLayout) findViewById(R.id.textInput_birthDay);
|
||||
|
||||
edt_birthday = (EditText) findViewById(R.id.edt_birthDay);
|
||||
|
||||
//Set Type face
|
||||
textInput_email.setTypeface(bebas);
|
||||
textInput_password.setTypeface(bebas);
|
||||
|
||||
Reference in New Issue
Block a user