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