Skip to content

Commit

Permalink
Delete Item button (#50)
Browse files Browse the repository at this point in the history
* Delete Item button

* PR changes
  • Loading branch information
ldbonkowski authored Nov 8, 2023
1 parent 4bd9b10 commit a403f48
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
10 changes: 1 addition & 9 deletions app/src/main/java/com/example/househomey/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public class HomeFragment extends Fragment implements FilterCallback {
private Set<Filter> appliedFilters = new HashSet<>();
private ArrayAdapter<Item> itemAdapter;

/**
* This constructs a new HomeFragment with the appropriate list of items
* @param itemRef A reference to the firestore collection containing the items to display
*/
public HomeFragment(CollectionReference itemRef) {
this.itemRef = itemRef;
itemList = new ArrayList<>();
}

/**
* @param inflater The LayoutInflater object that can be used to inflate
* any views in the fragment,
Expand All @@ -63,6 +54,7 @@ public HomeFragment(CollectionReference itemRef) {
*/
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
this.itemRef = ((MainActivity) requireActivity()).getItemRef();
// Inflate the fragment's layout
View rootView = inflater.inflate(R.layout.fragment_home, container, false);

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/example/househomey/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ protected void onCreate(Bundle savedInstanceState) {
}

// Init home fragment
navigateToFragmentPage(this, new HomeFragment(getItemRef()));
navigateToFragmentPage(this, new HomeFragment());

BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnItemSelectedListener(item -> {
int id = item.getItemId();
Fragment fragment;
if (id == R.id.action_home) {
// Go to Home page
fragment = new HomeFragment(getItemRef());
fragment = new HomeFragment();
} else if (id == R.id.action_add) {
// Go to Add Item page
fragment = new AddItemFragment();
} else {
// TODO: Go to Profile Page
fragment = new HomeFragment(getItemRef());
fragment = new HomeFragment();
}
navigateToFragmentPage(this, fragment);
return true;
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/example/househomey/ViewItemFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.example.househomey.utils.FragmentUtils.navigateToFragmentPage;
import static java.util.Optional.ofNullable;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -14,6 +15,8 @@

import com.example.househomey.form.EditItemFragment;

import java.util.Collection;

/**
* This fragment is for the "View Item Page" - which currently displays the details and comment linked
* to the item
Expand All @@ -34,6 +37,7 @@ public class ViewItemFragment extends Fragment {
*
* @return view item fragment
*/
@SuppressLint("SetTextI18n")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_item, container, false);

Expand All @@ -57,11 +61,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
});

// On edit button click, pass item to EditItemFragment
Button editButton = rootView.findViewById(R.id.edit_button);
editButton.setOnClickListener(v ->
rootView.findViewById(R.id.edit_button).setOnClickListener(v ->
navigateToFragmentPage(getContext(), new EditItemFragment(item))
);

rootView.findViewById(R.id.delete_button).setOnClickListener(v ->
{
((MainActivity) requireActivity()).getItemRef().document(item.getId()).delete();
navigateToFragmentPage(getContext(), new HomeFragment());
}
);

return rootView;
}
}
37 changes: 30 additions & 7 deletions app/src/main/res/layout/fragment_view_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,36 @@
android:text="Comment"
android:textSize="15sp" />
</LinearLayout>

<Button
android:id="@+id/edit_button"
android:layout_width="150dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:text="Edit Item" />
android:orientation="horizontal"
android:layout_marginTop="16dp">

<Button
android:id="@+id/edit_button"
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Edit Item"
android:layout_marginStart="64dp"
android:layout_marginEnd="32dp"
android:layout_weight="1"/>

<Button
android:id="@+id/delete_button"
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_gravity="center"
android:layout_marginStart="32dp"
android:layout_marginEnd="64dp"
android:text="Delete"
android:backgroundTint="@color/red"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/edit_button"
android:layout_weight="1"/>
</LinearLayout>

</LinearLayout>

0 comments on commit a403f48

Please sign in to comment.