mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Create-new-list dialog added to item details page
This commit is contained in:
parent
5fe666fbbb
commit
ea9eabd398
@ -0,0 +1,68 @@
|
|||||||
|
package com.example.listify;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
|
||||||
|
public class CreateListDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public interface OnNewListListener {
|
||||||
|
void sendNewListName(String name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnNewListListener onNewListListener;
|
||||||
|
|
||||||
|
EditText etNewListName;
|
||||||
|
|
||||||
|
public CreateListDialogFragment() {}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
// Get the layout inflater
|
||||||
|
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||||
|
|
||||||
|
// Inflate and set the layout for the dialog
|
||||||
|
// Pass null as the parent view because its going in the dialog layout
|
||||||
|
View root = inflater.inflate(R.layout.dialog_create_list, null);
|
||||||
|
builder.setView(root)
|
||||||
|
// Add action buttons
|
||||||
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
onNewListListener.sendNewListName(etNewListName.getText().toString());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
CreateListDialogFragment.this.getDialog().cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
etNewListName = (EditText) root.findViewById(R.id.et_new_list_name);
|
||||||
|
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required to extend DialogFragment
|
||||||
|
@Override
|
||||||
|
public void onAttach(@NonNull Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
try {
|
||||||
|
onNewListListener = (OnNewListListener) getActivity();
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
Log.e("CreateListDialogFragment", "onAttach: ClassCastException: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,7 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.amazonaws.services.cognitoidentityprovider.model.TooManyFailedAttemptsException;
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.example.listify.adapter.DisplayShoppingListsAdapter;
|
|
||||||
import com.example.listify.model.Product;
|
import com.example.listify.model.Product;
|
||||||
import com.example.listify.model.ShoppingList;
|
import com.example.listify.model.ShoppingList;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
@ -16,10 +13,9 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ItemDetails extends AppCompatActivity implements ListPickerDialogFragment.OnListPickListener {
|
public class ItemDetails extends AppCompatActivity implements ListPickerDialogFragment.OnListPickListener, CreateListDialogFragment.OnNewListListener {
|
||||||
private Product curProduct;
|
private Product curProduct;
|
||||||
private LinearLayout linAddItem;
|
private LinearLayout linAddItem;
|
||||||
private LinearLayout linCreateList;
|
private LinearLayout linCreateList;
|
||||||
@ -79,8 +75,10 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
|||||||
linCreateList.setOnClickListener(new View.OnClickListener() {
|
linCreateList.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Toast.makeText(ItemDetails.this, "create", Toast.LENGTH_SHORT).show();
|
|
||||||
closeFABMenu();
|
closeFABMenu();
|
||||||
|
|
||||||
|
CreateListDialogFragment createListDialogFragment = new CreateListDialogFragment();
|
||||||
|
createListDialogFragment.show(getSupportFragmentManager(), "Create New List");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -134,6 +132,11 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendListSelection(int selectedListIndex, int quantity) {
|
public void sendListSelection(int selectedListIndex, int quantity) {
|
||||||
Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendNewListName(String name) {
|
||||||
|
Toast.makeText(this, String.format("%s created", name), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,15 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/add_item_to_list"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="5dp"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/user_lists"
|
android:id="@+id/user_lists"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
@ -20,20 +29,20 @@
|
|||||||
android:id="@+id/btn_minus"
|
android:id="@+id/btn_minus"
|
||||||
android:layout_width="60dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:text="-"/>
|
android:text="@string/minus"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/et_quantity"
|
android:id="@+id/et_quantity"
|
||||||
android:layout_width="60dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:text="1"
|
android:text="@string/_1"
|
||||||
android:inputType="number"/>
|
android:inputType="number"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_plus"
|
android:id="@+id/btn_plus"
|
||||||
android:layout_width="60dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:text="+"/>
|
android:text="@string/plus"/>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
22
Listify/app/src/main/res/layout/dialog_create_list.xml
Normal file
22
Listify/app/src/main/res/layout/dialog_create_list.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/create_a_new_list"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:layout_marginTop="5dp"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_new_list_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_marginHorizontal="15dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:hint="@string/new_list_name"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@ -37,4 +37,10 @@
|
|||||||
<string name="default__00_00">$00.00</string>
|
<string name="default__00_00">$00.00</string>
|
||||||
<string name="default_description">Description</string>
|
<string name="default_description">Description</string>
|
||||||
<string name="product_image_description">Product Image</string>
|
<string name="product_image_description">Product Image</string>
|
||||||
|
<string name="add_item_to_list">Add item to List</string>
|
||||||
|
<string name="minus">-</string>
|
||||||
|
<string name="_1">1</string>
|
||||||
|
<string name="plus">+</string>
|
||||||
|
<string name="create_a_new_list">Create a new list</string>
|
||||||
|
<string name="new_list_name">New list name</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue
Block a user