Add address manager screen

This commit is contained in:
Nezumi
2023-03-06 16:23:47 +07:00
parent 77d8818786
commit c51300e6ef
7 changed files with 349 additions and 1 deletions
+3
View File
@@ -15,6 +15,9 @@
android:theme="@style/Theme.Foodify"
tools:replace="android:theme"
tools:targetApi="31">
<activity
android:name=".Activity.AddressManagerActivity"
android:exported="false" />
<activity
android:name=".Activity.ChangePasswordActivity"
android:exported="false" />
@@ -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);
}
}
}
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.AddressManagerActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:text="quản lý địa chỉ"
android:fontFamily="@font/bebas"
android:textSize="40sp"
android:textColor="@color/black"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/item_address"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="@+id/add_address_button"
android:text="Thêm địa chỉ"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:layout_marginEnd="70dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
app:layout_constraintTop_toBottomOf="@id/recycler_view_address"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
+103
View File
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp"
>
<TextView
android:id="@+id/text_view_address"
android:text="Hẻm 215, đường Phạm Như Xương, phường Hoà Khánh Nam, quận Liên Chiểu, thành phố Đà Nẵng"
android:textSize="16sp"
android:fontFamily="@font/opensans"
android:textColor="@color/gray"
android:textStyle="italic|bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/default_text_view"
android:text="Mặc định"
android:textSize="13sp"
android:fontFamily="@font/opensans"
android:textColor="@color/primaryColor"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:visibility="visible"
/>
<TextView
android:id="@+id/blank_text_view"
android:textSize="13sp"
android:fontFamily="@font/opensans"
android:textColor="@color/primaryColor"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:visibility="gone"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical|right"
>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/edit_button"
android:text="Sửa"
android:textSize="11sp"
android:fontFamily="@font/opensans"
android:backgroundTint="@color/green"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/delete_button"
android:text="Xoá"
android:textSize="11sp"
android:backgroundTint="@color/primaryColor"
style="@style/ShapeAppearance.FoodifyApp.Button.Rounded"
android:fontFamily="@font/opensans"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>