mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Add address manager screen
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.capstone.foodify.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.capstone.foodify.Model.Address.Address;
|
||||
import com.capstone.foodify.Model.Address.AddressAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddressManagerActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView recycler_view_address;
|
||||
private AddressAdapter adapter;
|
||||
private Button add_address_button;
|
||||
|
||||
private List<Address> listAddress = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_address_manager);
|
||||
|
||||
//Init Component
|
||||
recycler_view_address = findViewById(R.id.recycler_view_address);
|
||||
add_address_button = findViewById(R.id.add_address_button);
|
||||
|
||||
//Set layout recyclerview
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
recycler_view_address.setLayoutManager(linearLayoutManager);
|
||||
|
||||
adapter = new AddressAdapter();
|
||||
|
||||
getAddressList();
|
||||
|
||||
}
|
||||
|
||||
private void getAddressList(){
|
||||
|
||||
for(int i = 1; i <= 10; i++){
|
||||
listAddress.add(new Address(i, "Hẻm 215, đường Phạm Như Xương", "phường Hoà Khánh Nam", "Liên Chiểu"));
|
||||
}
|
||||
|
||||
adapter.setData(listAddress);
|
||||
recycler_view_address.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import android.widget.LinearLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.capstone.foodify.Activity.AccountAndProfileActivity;
|
||||
import com.capstone.foodify.Activity.AddressManagerActivity;
|
||||
import com.capstone.foodify.Activity.SignUpActivity;
|
||||
import com.capstone.foodify.R;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class ProfileFragment extends Fragment {
|
||||
|
||||
Button btnSignUp;
|
||||
|
||||
LinearLayout account_and_profile;
|
||||
LinearLayout account_and_profile, manage_address;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -26,6 +27,8 @@ public class ProfileFragment extends Fragment {
|
||||
View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
btnSignUp = (Button) rootView.findViewById(R.id.sign_up_button);
|
||||
account_and_profile = (LinearLayout) rootView.findViewById(R.id.account_and_profile);
|
||||
manage_address = (LinearLayout) rootView.findViewById(R.id.manage_address);
|
||||
|
||||
btnSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -39,6 +42,13 @@ public class ProfileFragment extends Fragment {
|
||||
startActivity(new Intent(getActivity(), AccountAndProfileActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
manage_address.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(getActivity(), AddressManagerActivity.class));
|
||||
}
|
||||
});
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.capstone.foodify.Model.Address;
|
||||
|
||||
public class Address {
|
||||
private int id;
|
||||
private String address;
|
||||
private String ward;
|
||||
private String district;
|
||||
|
||||
public Address(int id, String address, String ward, String district) {
|
||||
this.id = id;
|
||||
this.address = address;
|
||||
this.ward = ward;
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getWard() {
|
||||
return ward;
|
||||
}
|
||||
|
||||
public void setWard(String ward) {
|
||||
this.ward = ward;
|
||||
}
|
||||
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.capstone.foodify.Model.Address;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Model.Food.FoodAdapter;
|
||||
import com.capstone.foodify.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.AddressViewHolder>{
|
||||
|
||||
private List<Address> listAddress;
|
||||
|
||||
public AddressAdapter() {
|
||||
}
|
||||
|
||||
public void setData(List<Address> listAddress){
|
||||
this.listAddress = listAddress;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AddressViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_address, parent, false);
|
||||
return new AddressViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull AddressViewHolder holder, int position) {
|
||||
Address address = listAddress.get(position);
|
||||
|
||||
if(address == null)
|
||||
return;
|
||||
|
||||
//Create a full address string
|
||||
String fullAddress = address.getAddress() + ", " + address.getWard() + ", " + address.getDistrict();
|
||||
|
||||
//Bind data to component
|
||||
holder.text_view_address.setText(fullAddress);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if(listAddress != null)
|
||||
return listAddress.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class AddressViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private TextView text_view_address, default_text_view, blank_text_view;
|
||||
private Button edit_btn, delete_btn;
|
||||
|
||||
public AddressViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
text_view_address = itemView.findViewById(R.id.text_view_address);
|
||||
default_text_view = itemView.findViewById(R.id.default_text_view);
|
||||
blank_text_view = itemView.findViewById(R.id.blank_text_view);
|
||||
|
||||
edit_btn = itemView.findViewById(R.id.edit_button);
|
||||
delete_btn = itemView.findViewById(R.id.delete_button);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user