mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Create dialog address to add more address
This commit is contained in:
@@ -60,4 +60,5 @@ dependencies {
|
||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||
implementation 'com.github.ome450901:SimpleRatingBar:1.5.1'
|
||||
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
|
||||
implementation 'com.github.slavce14:SJ-Dialog:1.5'
|
||||
}
|
||||
Binary file not shown.
@@ -4,23 +4,47 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Model.Address.Address;
|
||||
import com.capstone.foodify.Model.Address.AddressAdapter;
|
||||
import com.capstone.foodify.Model.DistrictWard.DistrictWardResponse;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.sjapps.library.customdialog.CustomViewDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AddressManagerActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView recycler_view_address;
|
||||
private AddressAdapter adapter;
|
||||
private Button add_address_button;
|
||||
private ImageView back_image;
|
||||
|
||||
private List<Address> listAddress = new ArrayList<>();
|
||||
Spinner wardSpinner, districtSpinner;
|
||||
|
||||
private static final ArrayList<String> wardList = new ArrayList<>();
|
||||
private static final ArrayList<String> districtList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -30,6 +54,7 @@ public class AddressManagerActivity extends AppCompatActivity {
|
||||
//Init Component
|
||||
recycler_view_address = findViewById(R.id.recycler_view_address);
|
||||
add_address_button = findViewById(R.id.add_address_button);
|
||||
back_image = findViewById(R.id.back_image);
|
||||
|
||||
//Set layout recyclerview
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
@@ -39,6 +64,21 @@ public class AddressManagerActivity extends AppCompatActivity {
|
||||
|
||||
getAddressList();
|
||||
|
||||
//Set event image view on click
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
|
||||
add_address_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showAddAddressDialog();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void getAddressList(){
|
||||
@@ -50,4 +90,159 @@ public class AddressManagerActivity extends AppCompatActivity {
|
||||
adapter.setData(listAddress);
|
||||
recycler_view_address.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void showAddAddressDialog(){
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.add_address_dialog,null);
|
||||
Typeface bebas= Typeface.createFromAsset(getAssets(), "font/opensans.ttf");
|
||||
|
||||
//Init component
|
||||
TextInputLayout textInputLayout = view.findViewById(R.id.textInput_address);
|
||||
wardSpinner = view.findViewById(R.id.ward);
|
||||
districtSpinner = view.findViewById(R.id.district);
|
||||
|
||||
//Set font
|
||||
textInputLayout.setTypeface(bebas);
|
||||
|
||||
//Load district and ward
|
||||
if(districtList.size() == 0){
|
||||
getListDistrict();
|
||||
} else {
|
||||
setAdapter(districtList, "---Quận", districtSpinner);
|
||||
}
|
||||
getListWard(0);
|
||||
|
||||
//Set event when click on district spinner
|
||||
districtSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
getListWard(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
CustomViewDialog customViewDialog = new CustomViewDialog();
|
||||
|
||||
//Create dialog
|
||||
customViewDialog.Builder(this);
|
||||
//Set title
|
||||
customViewDialog.setTitle("Thêm địa chỉ");
|
||||
//Create dialog width two buttons
|
||||
customViewDialog.dialogWithTwoButtons();
|
||||
//Add custom view
|
||||
customViewDialog.addCustomView(view);
|
||||
//Set left button text
|
||||
customViewDialog.setLeftButtonText("Trở về");
|
||||
//Set right button text
|
||||
customViewDialog.setRightButtonText("Thêm");
|
||||
//Set color for left button
|
||||
customViewDialog.setLeftButtonColor(getResources().getColor(R.color.gray, null));
|
||||
//Set color for right button
|
||||
customViewDialog.setRightButtonColor(getResources().getColor(R.color.primaryColor, null));
|
||||
|
||||
|
||||
customViewDialog.show();
|
||||
}
|
||||
|
||||
private void getListDistrict() {
|
||||
|
||||
districtList.add("---Quận");
|
||||
|
||||
FoodApi.apiService.districtResponse().enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> districtResponse = response.body();
|
||||
if(districtResponse != null){
|
||||
for(DistrictWardResponse tempDistrict: districtResponse){
|
||||
districtList.add(tempDistrict.getName());
|
||||
}
|
||||
}
|
||||
|
||||
setAdapter(districtList, "---Quận", districtSpinner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(AddressManagerActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getListWard(int districtCode) {
|
||||
|
||||
if(wardList.size() > 1)
|
||||
wardList.clear();
|
||||
|
||||
if(wardList.size() == 0)
|
||||
wardList.add("---Phường");
|
||||
|
||||
wardSpinner.setEnabled(false);
|
||||
|
||||
if(districtCode != 0){
|
||||
FoodApi.apiService.wardResponse(districtCode).enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> wardData = response.body();
|
||||
|
||||
if(wardData != null){
|
||||
for(DistrictWardResponse tempWard: wardData){
|
||||
wardList.add(tempWard.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if(wardList.size() <= 1){
|
||||
wardSpinner.setEnabled(false);
|
||||
} else {
|
||||
wardSpinner.setEnabled(true);
|
||||
}
|
||||
setAdapter(wardList, "---Phường", wardSpinner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(AddressManagerActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setAdapter(wardList, "---Phường", wardSpinner);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAdapter(ArrayList<String> data, String defaultItem, Spinner dataSpinner){
|
||||
MySpinnerAdapter adapterWard = new MySpinnerAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, data);
|
||||
dataSpinner.setAdapter(adapterWard); // this will set list of values to spinner
|
||||
dataSpinner.setSelection(data.indexOf(defaultItem));//set selected value in spinner
|
||||
}
|
||||
|
||||
private static class MySpinnerAdapter extends ArrayAdapter<String> {
|
||||
// Initialise custom font, for example:
|
||||
Typeface font = Typeface.createFromAsset(getContext().getAssets(),
|
||||
"font/bebas.ttf");
|
||||
|
||||
// (In reality I used a manager which caches the Typeface objects)
|
||||
// Typeface font = FontManager.getInstance().getFont(getContext(), BLAMBOT);
|
||||
|
||||
private MySpinnerAdapter(Context context, int resource, List<String> items) {
|
||||
super(context, resource, items);
|
||||
}
|
||||
|
||||
// Affects default (closed) state of the spinner
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView view = (TextView) super.getView(position, convertView, parent);
|
||||
view.setTypeface(font);
|
||||
return view;
|
||||
}
|
||||
|
||||
// Affects opened state of the spinner
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
TextView view = (TextView) super.getDropDownView(position, convertView, parent);
|
||||
view.setTypeface(font);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,6 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
hideRecyclerViewAndShowNotificationEmpty();
|
||||
}
|
||||
|
||||
Toast.makeText(getContext(), "List Basket: " + Common.LIST_BASKET_FOOD.size(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Set layout recyclerview
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView_basket_food.setLayoutManager(linearLayoutManager);
|
||||
|
||||
@@ -10,6 +10,17 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_image"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/back_button"
|
||||
android:background="@drawable/circle_button"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="25dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:text="quản lý địa chỉ"
|
||||
@@ -20,7 +31,7 @@
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/back_image"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
>
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -30,22 +29,21 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_image"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/back_button"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:background="@drawable/circle_button"
|
||||
android:translationZ="90dp"
|
||||
android:padding="8dp"/>
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_image"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/back_button"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:background="@drawable/circle_button"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/food_detail"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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"
|
||||
android:background="@drawable/bg_white_corner_16"
|
||||
>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="10dp"
|
||||
android:hint="Địa chỉ"
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:startIconDrawable="@drawable/baseline_home_24"
|
||||
app:startIconTint="@color/primaryColor">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edt_address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="text" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout_district_ward"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_address"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/district"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:textAlignment="viewEnd"
|
||||
android:gravity="end"
|
||||
android:paddingEnd="25dp"
|
||||
android:contentDescription="district"
|
||||
android:layout_weight="0.4"
|
||||
/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/ward"
|
||||
android:textAlignment="viewEnd"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end"
|
||||
android:paddingEnd="25dp"
|
||||
android:contentDescription="ward"
|
||||
android:layout_weight="0.6"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user