Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Add default collection #206

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;

import com.adevinta.android.barista.assertion.BaristaListAssertions;
import com.adevinta.android.barista.interaction.BaristaClickInteractions;
import com.adevinta.android.barista.interaction.BaristaListInteractions;
import com.github.sdp.mediato.DatabaseTests.DataBaseTestUtil;
import com.github.sdp.mediato.data.CollectionsDatabase;
import com.github.sdp.mediato.data.UserDatabase;
Expand Down Expand Up @@ -256,45 +259,16 @@ public void testCollectionListState() {
collectionListRecyclerView.check(matches(isDisplayed()));

// Check that the collection list has exactly one item
collectionListRecyclerView.check(matches(hasItemCount(1)));
collectionListRecyclerView.check(matches(hasItemCount(2)));

// Check that the collection list displays the correct collection
collectionListRecyclerView.check(matches(hasDescendant(withText(COLLECTION_NAME))));
}

// Test that the collection downloaded from the database is displayed correctly (buttons and reviews)
@Test
public void testCollectionState() {
// Check that the collection is displayed
defaultCollection.check(matches(isDisplayed()));

// Check that the collection title is correct
defaultCollection.check(matches(hasDescendant(withText(COLLECTION_NAME))));

// Check that the collection has an AddMedia button
defaultCollection.check(matches(hasDescendant(withId(R.id.add_media_button))));

// Check that the collection has a delete collection button
defaultCollection.check(matches(hasDescendant(withId(R.id.delete_collection_button))));

// Check that the collection has a recycler view to display collections
defaultCollection.check(matches(hasDescendant(withId(R.id.collection_recycler_view))));

// Check that the recycler view contains the review
recyclerView.check(matches(hasItemCount(1)));

// Check that the review displays the correct title
recyclerView.check(matches(hasDescendant(withText(MOVIE_TITLE))));
}

// Test that a click on the add media button opens the search
@Test
public void testAddMediaButton() {
int initialItemCount = getRecyclerViewItemCount(R.id.collection_recycler_view);

// Check that the collection is displayed and click on the add media button
collectionRecyclerView.check(matches(hasItemCount(initialItemCount)));
addMediaButton.perform(click());
BaristaListInteractions.clickListItemChild(R.id.collection_list_recycler_view, 0, R.id.add_media_button);

// Check that the search is displayed
movieSearchCategory.check(matches(isDisplayed()));
Expand Down Expand Up @@ -354,8 +328,8 @@ public void testEnterValidCollectionAndCancelDoesNotAddCollection() {
public void testCancelingDeleteCollectionDoesNotRemoveCollection() {
int initialItemCount = getRecyclerViewItemCount(R.id.collection_list_recycler_view);

collectionListRecyclerView.check(matches(hasItemCount(initialItemCount)));
deleteCollectionButton.perform(click());
BaristaListInteractions.clickListItemChild(R.id.collection_list_recycler_view, 1, R.id.delete_collection_button);

clickAlertDialogButton(CANCEL);
collectionListRecyclerView.check(matches(hasItemCount(initialItemCount)));
}
Expand All @@ -365,8 +339,7 @@ public void testCancelingDeleteCollectionDoesNotRemoveCollection() {
public void testConfirmDeleteCollectionRemovesCollection() {
int initialItemCount = getRecyclerViewItemCount(R.id.collection_list_recycler_view);

collectionListRecyclerView.check(matches(hasItemCount(initialItemCount)));
deleteCollectionButton.perform(click());
BaristaListInteractions.clickListItemChild(R.id.collection_list_recycler_view, 1, R.id.delete_collection_button);
clickAlertDialogButton(YES);
searchMenuItem.perform(click());
profileMenuItem.perform(click());
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/github/sdp/mediato/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private User(UserBuilder builder) {
this.email = builder.email;
this.registerDate = builder.registerDate;
this.location = builder.location;
this.collections.put("Favorite", new Collection("Favorite"));
}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void setDefaultFragment(String username) {
// Give the username as an argument to the profile page and switch to it
args.putString("username", username);
args.putString("general_search", "true");
args.putString("collection", "Recently watched");
args.putString("collection", getString(R.string.default_collection));

argsFeed.putString("username", username);
argsMyReviews.putString("username", username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.sdp.mediato.R;
import com.github.sdp.mediato.data.CollectionsDatabase;
import com.github.sdp.mediato.data.UserDatabase;
import com.github.sdp.mediato.model.Review;
import com.github.sdp.mediato.model.media.Collection;
import com.github.sdp.mediato.ui.viewmodel.MyProfileViewModel;
import com.github.sdp.mediato.utility.PhotoPicker;
import com.github.sdp.mediato.utility.adapters.CollectionListAdapter;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

Expand Down Expand Up @@ -66,6 +69,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

// Set up collections
fetchCollectionsFromDatabaseWithRetry(0).thenAccept(collections -> {

collectionlistAdapter = setupCollections(collectionListRecyclerView, collections);
// Observe the view model's live data to update UI components
observeCollections(collectionlistAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
onAddMediaButtonClickListener,
adapter -> adapter.notifyItemInserted(adapter.getItemCount()));

if (collection.getCollectionName().equals(context.getResources().getString(R.string.default_collection))) {
deleteCollection.button.setVisibility(View.GONE);
}

setUpButton(deleteCollection, collection, collectionAdapter);
setUpButton(addMedia, collection, collectionAdapter);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="profile">Profile</string>

<!--User Profile-->
<string name="default_collection">Favorite</string>
<string name="username">Username</string>
<string name="recently_watched">Recently watched</string>
<string name="title">Title</string>
Expand Down