Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/view-item-add-tag' into view-ite…
Browse files Browse the repository at this point in the history
…m-add-tag
  • Loading branch information
ldbonkowski committed Dec 1, 2023
2 parents a1712ff + 96f3c13 commit 8ae3b77
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 62 deletions.
38 changes: 13 additions & 25 deletions app/src/main/java/com/example/househomey/tags/ApplyTagFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.os.BundleCompat;

import com.example.househomey.Item;
Expand All @@ -30,50 +30,41 @@
public class ApplyTagFragment extends TagFragment implements Serializable {
private ArrayList<Item> selectedItems;


/**
* Called to create the dialog, initializing UI components and setting up button listeners.
*
* @param savedInstanceState Bundle containing the saved state of the fragment.
* @return The created AlertDialog.
*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View rootView = requireActivity().getLayoutInflater().inflate(R.layout.fragment_apply_tags, null);
this.tagRef = ((MainActivity) requireActivity()).getTagRef();
selectedItems = BundleCompat.getParcelableArrayList(getArguments(), "itemList", Item.class);

Bundle args = getArguments();
selectedItems = BundleCompat.getParcelableArrayList(args, "itemList", Item.class);

// Initialize AlertDialog builder
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// Inflate the layout for this fragment
LayoutInflater inflater = requireActivity().getLayoutInflater();
View rootView = inflater.inflate(R.layout.fragment_apply_tags, null);

// Initialize UI components
chipGroup = rootView.findViewById(R.id.chip_group_labels);

getTagCollection();

return builder
return new AlertDialog.Builder(getActivity())
.setView(rootView)
.setTitle("Tags")
.setTitle("Select Tags")
.setNeutralButton("Cancel", null)
.setNegativeButton("Manage", (d, w) -> {
ManageTagFragment manageTagFragment = new ManageTagFragment();

Bundle tagArgs = new Bundle();
tagArgs.putParcelableArrayList("itemList", selectedItems);
manageTagFragment.setArguments(tagArgs);
manageTagFragment.show(requireActivity().getSupportFragmentManager(),"tagDialog");
manageTagFragment.show(requireActivity().getSupportFragmentManager(), "tagDialog");
})
.setPositiveButton("Apply Tags", (dialog, which) -> applyItemsToTag(rootView, selectedItems))
.setPositiveButton("Apply", (dialog, which) -> applyItemsToTag(rootView, selectedItems))
.create();
}

/**
* Creates a new chip for the new tag
*
* @param label Name of the tag for the new chip
*/
protected void makeTagChip(String label) {
Expand All @@ -82,11 +73,12 @@ protected void makeTagChip(String label) {

/**
* Save items to Firestore for the given tags.
*
* @param selectedItems Items to which the tags will be applied
*/
private void applyItemsToTag(View rootView, ArrayList<Item> selectedItems) {
ArrayList<String> selectedTags = new ArrayList<>();
for (int id: chipGroup.getCheckedChipIds()) {
for (int id : chipGroup.getCheckedChipIds()) {
Chip chip = rootView.findViewById(id);
selectedTags.add(chip.getText().toString());
}
Expand All @@ -100,12 +92,8 @@ private void applyItemsToTag(View rootView, ArrayList<Item> selectedItems) {
"items", FieldValue.arrayUnion(idList.toArray()));
}
batch.commit()
.addOnSuccessListener((result) -> {
Log.i("Firestore", "Items successfully applied to tag");
})
.addOnFailureListener((error) -> {
Log.e("Firestore", "Failed to apply items to tag.", error);
});
.addOnSuccessListener((result) -> Log.i("Firestore", "Items successfully applied to tag"))
.addOnFailureListener((error) -> Log.e("Firestore", "Failed to apply items to tag.", error));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Expand Down Expand Up @@ -33,19 +31,12 @@ public class ManageTagFragment extends TagFragment {
* @param savedInstanceState Bundle containing the saved state of the fragment.
* @return The created AlertDialog.
*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View rootView = requireActivity().getLayoutInflater().inflate(R.layout.fragment_manage_tags, null);
this.tagRef = ((MainActivity) requireActivity()).getTagRef();

Bundle args = getArguments();
final ArrayList<Item> selectedItems = BundleCompat.getParcelableArrayList(args, "itemList", Item.class);

// Initialize AlertDialog builder
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// Inflate the layout for this fragment
LayoutInflater inflater = requireActivity().getLayoutInflater();
View rootView = inflater.inflate(R.layout.fragment_manage_tags, null);
final ArrayList<Item> selectedItems = BundleCompat.getParcelableArrayList(getArguments(), "itemList", Item.class);

// Initialize UI components
chipGroup = rootView.findViewById(R.id.chip_group_labels);
Expand All @@ -61,18 +52,20 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

getTagCollection();

return builder
// Build the dialog window
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setView(rootView)
.setTitle("Manage Tags")
.setPositiveButton("Done", (dialog, which) -> {
.setPositiveButton("Done", (d, which) -> {
ApplyTagFragment applyTagFragment = new ApplyTagFragment();

Bundle tagArgs = new Bundle();
tagArgs.putParcelableArrayList("itemList", selectedItems);
applyTagFragment.setArguments(tagArgs);
applyTagFragment.show(requireActivity().getSupportFragmentManager(),"tagDialog");
})
.create();
dialog.setCanceledOnTouchOutside(false);
return dialog;
}

/**
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/res/layout/fragment_apply_tags.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<ScrollView

<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_labels"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleLine="false">
</com.google.android.material.chip.ChipGroup>
</ScrollView>
</LinearLayout>
android:layout_height="wrap_content"
app:chipSpacingVertical="0dp"
app:singleLine="false"/>
</ScrollView>
18 changes: 11 additions & 7 deletions app/src/main/res/layout/fragment_manage_tags.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,47 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal">

<com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="New tag"
android:layout_weight="1"
android:hint="New Tag"
app:hintEnabled="true">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tag_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/add_tag_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="30dp"
android:layout_height="30dp"
android:padding="0dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:padding="0dp"
app:icon="@drawable/baseline_add_24"
app:iconSize="30dp"
app:iconTint="@color/black" />
</LinearLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleLine="false">
</com.google.android.material.chip.ChipGroup>
app:chipSpacingVertical="0dp"
app:singleLine="false"></com.google.android.material.chip.ChipGroup>
</ScrollView>

</LinearLayout>
7 changes: 3 additions & 4 deletions app/src/main/res/layout/select_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/done"
android:textSize="20sp"
android:padding="16sp"
android:textStyle="bold"
android:backgroundTint="@color/subTitle" />
android:textSize="16sp"
android:textColor="@color/black"
android:backgroundTint="#1D1B201F" />

<LinearLayout
android:id="@+id/select_state_tools"
Expand Down

0 comments on commit 8ae3b77

Please sign in to comment.