Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #212 from SwengGolfTeam/fb-sorted-offers
Browse files Browse the repository at this point in the history
Sort list of offers by creation date
  • Loading branch information
robinmamie committed Dec 17, 2018
2 parents 080f07b + 4a600d5 commit ab18742
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PolyTroc *(temporary name)*
# PolyTroc
## team Sweng_Golf

*Development of an Android app in the context of the Software Engineering course taught at EPFL in Fall 2018.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.hasMinimumChildCount;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
Expand All @@ -66,10 +67,10 @@ public class ListOfferActivityTest {
public final IntentsTestRule<MainMenuActivity> mActivityRule =
new IntentsTestRule<>(MainMenuActivity.class, false, false);
private static final Offer offer1 = (new Offer.Builder()).setUserId("user_id")
.setTitle("This is a title")
.setTitle("This is a title").setCreationDate(1)
.setDescription(LOREM).setUuid("idoftheoffer1").build();
private static final Offer offer2 = (new Offer.Builder()).setUserId("user_id")
.setTitle("This is a title 2")
.setTitle("This is a title 2").setCreationDate(0)
.setDescription(LOREM).setUuid("idoftheoffer2").build();

public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) {
Expand Down Expand Up @@ -242,4 +243,11 @@ private void clickOnCategoryInMenu(Category cat) {
public void displaysOnlyNonClosedOffers() {
onView(withId(R.id.offers_recycler_view)).check(matches(hasChildCount(2)));
}

@Test
public void sortedByCreationDate() {
RecyclerViewMatcher offersMatcher = new RecyclerViewMatcher(R.id.offers_recycler_view);
onView(offersMatcher.atPosition(1))
.check(matches(hasDescendant(withText(offer2.getTitle()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
+ "images/f/ff/Sandcrawler.png/"
+ "revision/latest?cb=20130812001443")
.setUuid("01").setTag(Category.values()[0])
.setCreationDate(DATE).setEndDate(DATE).setLocation(getLocation()).build(),
.setCreationDate(13).setEndDate(DATE).setLocation(getLocation()).build(),

new Offer.Builder().setUserId("13")
.setTitle("Defense against the droids")
Expand All @@ -129,15 +129,15 @@ public final class FilledFakeDatabase extends FakeDatabase {
+ "databank_battledroid_01_169_1524f145.jpeg?"
+ "region=0%2C0%2C1560%2C878&width=768")
.setUuid("02").setTag(Category.values()[1])
.setCreationDate(DATE).setEndDate(DATE).setLocation(getLocation()).build(),
.setCreationDate(12).setEndDate(DATE).setLocation(getLocation()).build(),

new Offer.Builder().setUserId("8")
.setTitle("Chosen one")
.setDescription("Someone out there is the chosen one ?"
+ " If you are I can train you !"
+ " Warning, last apprentice got bad burns !")
.setUuid("03").setTag(Category.values()[1])
.setCreationDate(DATE).setEndDate(DATE).build(),
.setCreationDate(11).setEndDate(DATE).build(),

new Offer.Builder().setUserId("15")
.setTitle("Great Price to find a friend")
Expand All @@ -147,7 +147,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture("https://cdn3.whatculture.com/"
+ "images/2014/12/Star-Wars-Special-Edition-Jabba-600x400.jpg")
.setUuid("04").setTag(Category.values()[2])
.setCreationDate(DATE).setEndDate(DATE).build(),
.setCreationDate(10).setEndDate(DATE).build(),

new Offer.Builder().setUserId("7")
.setTitle("Defeat Dark Sidious I must")
Expand All @@ -157,7 +157,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture(WIKIA_NO_COOKIE + STARWARS
+ "images/2/23/Gngf.jpg/revision/latest?cb=20080326171911")
.setUuid("05").setTag(Category.values()[2])
.setCreationDate(DATE).setEndDate(DATE).build(),
.setCreationDate(9).setEndDate(DATE).build(),

new Offer.Builder().setUserId("4")
.setTitle("Help to get the senate")
Expand All @@ -166,20 +166,21 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture(LUMIERE
+ "galactic-senate-3_9351812c.jpeg?region=0%2C0%2C800%2C342")
.setUuid("06").setTag(Category.values()[1])
.setCreationDate(DATE).setEndDate(DATE).build(),
.setCreationDate(8).setEndDate(DATE).build(),

new Offer.Builder().setUserId("5")
.setTitle("Prepare Surprise for a friend")
.setDescription("Someone would like to help me prepare a surprise "
+ "for a friend ? Create a display with \"NOT YET !\""
+ " on it. I'll invite you to a beer then.")
.setUuid("07").setTag(Category.values()[2])
.setCreationDate(DATE).setEndDate(DATE).build(),
.setCreationDate(7).setEndDate(DATE).build(),

new Offer.Builder().setUserId("10")
.setTitle("Take revenge on my apprentice")
.setDescription("Need someone to find my apprentice, some \"bat\" guy. "
+ "I'll show you the League of Shadows !")
.setCreationDate(6)
.setUuid("08").build(),

new Offer.Builder().setUserId("9")
Expand All @@ -188,7 +189,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture(LUMIERE
+ "jawas_42e63e07.jpeg?region=866%2C10%2C1068%2C601&width=768")
.setTag(Category.values()[3])
.setCreationDate(DATE)
.setCreationDate(5)
.setEndDate(DATE)
.setUuid("09").build(),

Expand All @@ -199,7 +200,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture(LUMIERE
+ "Death-Star-II_b5760154.jpeg?region=0%2C0%2C2160%2C1215&width=768")
.setTag(Category.values()[3])
.setCreationDate(DATE)
.setCreationDate(4)
.setEndDate(DATE)
.setUuid("10").build(),

Expand All @@ -208,17 +209,20 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setDescription("I need help to rebuild my spaceship in exchange I can help "
+ "with farm work since I'm pretty good at farm stuff !")
.setLinkPicture("https://www.jedidefender.com/collect92/lukexwing%20anh.jpg")
.setCreationDate(3)
.setUuid("11").build(),

new Offer.Builder().setUserId("17")
.setTitle("Lightsaber to find Jedi")
.setDescription("I'm looking for a bold general, care to help me ?")
.setCreationDate(2)
.setUuid("12").build(),

new Offer.Builder().setUserId("2")
.setTitle("Transport some important data")
.setDescription("I have some nice crew of people that can help you "
+ "do anything if you are okay to transport some data !")
.setCreationDate(1)
.setUuid("13").setIsClosed(true).build(),

new Offer.Builder().setUserId("14")
Expand All @@ -228,6 +232,7 @@ public final class FilledFakeDatabase extends FakeDatabase {
.setLinkPicture(WIKIA_NO_COOKIE
+ "a2a264e8-38e0-4c5e-b11d-7232c1f808ce/"
+ "scale-to-width-down/800")
.setCreationDate(0)
.setUuid("14").setIsClosed(true).build(),

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import ch.epfl.sweng.swenggolf.R;
Expand Down Expand Up @@ -68,20 +71,34 @@ public int getItemCount() {
/**
* Update the list of offers of the RecyclerView.
* Doesn't update the view if offers are null.
* Sorts the list in descending order of creation date.
*
* @param offers a list of offers
* @return whether displayed offers are empty or not.
*/
public boolean add(@NonNull List<Offer> offers) {
if (!offers.isEmpty()) {
offerList.addAll(offers);
Collections.sort(offerList,creationDateComparator);
filteredOfferList.clear();
fillFilteredList();
notifyDataSetChanged();
}
return filteredOfferList.isEmpty();
}

private static final Comparator<Offer> creationDateComparator = new Comparator<Offer>() {
@Override
public int compare(Offer o1, Offer o2) {
if(o1.getCreationDate() < o2.getCreationDate()) {
return 1;
} else if(o1.getCreationDate() > o2.getCreationDate()) {
return -1;
}
return 0;
}
};

/**
* Remove all the data in the adapter.
*/
Expand Down

0 comments on commit ab18742

Please sign in to comment.