Skip to content

Commit 5103fa5

Browse files
author
davedega
committed
Set title
Show search view until list is loaded
1 parent ca34e53 commit 5103fa5

File tree

8 files changed

+99
-36
lines changed

8 files changed

+99
-36
lines changed

app/src/main/java/com/dega/backbase/RnDActivity.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.v4.app.FragmentManager;
5-
import android.support.v7.app.ActionBar;
65
import android.support.v7.app.AppCompatActivity;
7-
import android.support.v7.widget.Toolbar;
8-
import android.util.Log;
9-
import android.view.Menu;
10-
import android.view.MenuInflater;
11-
import android.view.MenuItem;
12-
import android.view.View;
13-
import android.widget.EditText;
146

157
import com.dega.backbase.model.Entry;
168
import com.google.android.gms.maps.CameraUpdateFactory;

app/src/main/java/com/dega/backbase/RnDFragment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import android.support.v4.app.Fragment;
1010
import android.text.Editable;
1111
import android.text.TextWatcher;
12-
import android.util.Log;
1312
import android.view.LayoutInflater;
1413
import android.view.Menu;
1514
import android.view.MenuInflater;
16-
import android.view.MotionEvent;
1715
import android.view.View;
1816
import android.view.ViewGroup;
1917
import android.view.inputmethod.InputMethodManager;
@@ -40,6 +38,7 @@ public class RnDFragment extends Fragment implements RnDContract.View {
4038

4139
private RnDContract.Presenter presenter;
4240

41+
private LinearLayout searchContainer;
4342
private LinearLayout loadingContainer;
4443
private ListView listView;
4544
private ProgressBar progressBar;
@@ -80,6 +79,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
8079
}
8180
});
8281
progressBar = rootView.findViewById(R.id.progressBar);
82+
searchContainer = rootView.findViewById(R.id.searchContainer);
8383
loadingContainer = rootView.findViewById(R.id.loadingContainer);
8484

8585
rootView.findViewById(R.id.clearImageView).setOnClickListener(new View.OnClickListener() {
@@ -151,6 +151,7 @@ public void setPresenter(RnDContract.Presenter presenter) {
151151

152152
@Override
153153
public void showEntriesInList(Context context, List<Entry> loadedEntries) {
154+
showSearchCity();
154155
this.originalentries = new ArrayList<>();
155156
this.originalentries.addAll(loadedEntries);
156157
this.entries = loadedEntries;
@@ -168,7 +169,7 @@ public void showErrorMessage(int message) {
168169

169170
@Override
170171
public void showSearchCity() {
171-
172+
searchContainer.setVisibility(View.VISIBLE);
172173
}
173174

174175
// The Adapter lives within the view since is the only class who access it
@@ -193,6 +194,5 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
193194
textView.setText(entries.get(position).toString());
194195
return rowView;
195196
}
196-
197197
}
198198
}

app/src/main/java/com/dega/backbase/RnDPresenter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,11 @@ public class RnDPresenter implements RnDContract.Presenter {
2727
private RnDContract.View view;
2828
private List<Entry> entries;
2929

30-
31-
public List<Entry> getEntries() {
32-
return entries;
33-
}
34-
35-
public void setEntries(List<Entry> entries) {
30+
void setEntries(List<Entry> entries) {
3631
this.entries = entries;
3732
}
3833

39-
public RnDPresenter() {
34+
RnDPresenter() {
4035
}
4136

4237
RnDPresenter(Context context, RnDContract.View view) {
@@ -120,13 +115,21 @@ protected void onPostExecute(List<Entry> entries) {
120115
}
121116

122117

123-
private List<Entry> sortAlphabetical(List<Entry> entries) {
118+
public List<Entry> sortAlphabetical(List<Entry> entries) {
124119
Collections.sort(entries, new Comparator<Entry>() {
125120
@Override
126121
public int compare(Entry entry1, Entry entry2) {
127122
String s1 = entry1.getName();
128123
String s2 = entry2.getName();
129-
return s1.compareToIgnoreCase(s2);
124+
int i = s1.compareToIgnoreCase(s2);
125+
if(i !=0) return i;
126+
127+
String c1 = entry1.getCountry();
128+
String c2 = entry2.getCountry();
129+
i = c1.compareToIgnoreCase(c2);
130+
131+
return i;
132+
130133
}
131134
});
132135

app/src/main/java/com/dega/backbase/model/EntriesResponse.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/src/main/java/com/dega/backbase/model/Entry.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.dega.backbase.model;
22

3-
import android.support.annotation.NonNull;
4-
5-
import java.util.Comparator;
6-
73
/**
84
* Created by davedega on 25/03/18.
95
*/

app/src/main/res/layout/action_bar_layout.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
android:id="@+id/toolbar"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7+
app:title="@string/app_name"
78
android:background="?attr/colorPrimary"
89
android:minHeight="?attr/actionBarSize"
910
android:theme="?attr/actionBarTheme"
@@ -16,7 +17,7 @@
1617
android:layout_height="wrap_content"
1718
android:gravity="center"
1819
android:orientation="horizontal"
19-
android:visibility="visible">
20+
android:visibility="gone">
2021

2122
<EditText
2223
android:id="@+id/searchEditText"

app/src/test/java/com/dega/backbase/PresenterTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.HashSet;
99
import java.util.LinkedHashSet;
1010
import java.util.Set;
11-
import java.util.TreeSet;
1211

1312
import static org.junit.Assert.*;
1413
import static org.junit.Assert.assertTrue;
@@ -19,8 +18,8 @@
1918
public class PresenterTest {
2019

2120
RnDPresenter presenter = new RnDPresenter();
22-
TreeSet<Entry> entries = new TreeSet<>();
23-
TreeSet<Entry> expected = new TreeSet<>();
21+
HashSet<Entry> entries = new HashSet<>();
22+
HashSet<Entry> expected = new HashSet<>();
2423
Set<Entry> result;
2524

2625

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.dega.backbase;
2+
3+
import com.dega.backbase.model.Entry;
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import java.util.ArrayList;
9+
import java.util.HashSet;
10+
import java.util.List;
11+
import java.util.Set;
12+
13+
import static org.junit.Assert.assertArrayEquals;
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertNotEquals;
17+
import static org.junit.Assert.assertTrue;
18+
19+
/**
20+
* Test requirement: show cities on a scrollable list in alphabetic order (city first, country after)
21+
* "Denver, US" should appear before, "Sydney, Australia"
22+
* "Anaheim, US" should appear before "Denver, US"
23+
* Created by davedega on 27/03/18.
24+
*/
25+
public class SortTest {
26+
27+
RnDPresenter presenter = new RnDPresenter();
28+
List<Entry> entries = new ArrayList<>();
29+
List<Entry> expected = new ArrayList<>();
30+
31+
32+
@Before
33+
public void setUp() {
34+
35+
presenter = new RnDPresenter();
36+
37+
entries.add(new Entry("ZH", "Denver"));
38+
entries.add(new Entry("FG", "Denver"));
39+
entries.add(new Entry("US", "Alabama"));
40+
entries.add(new Entry("RT", "Alabama"));
41+
entries.add(new Entry("AU", "Sydney"));
42+
entries.add(new Entry("US", "Albuquerque"));
43+
entries.add(new Entry("US", "Arizona"));
44+
entries.add(new Entry("US", "Anaheim"));
45+
46+
expected.add(new Entry("RT", "Alabama"));
47+
expected.add(new Entry("US", "Alabama"));
48+
expected.add(new Entry("US", "Albuquerque"));
49+
expected.add(new Entry("US", "Anaheim"));
50+
expected.add(new Entry("US", "Arizona"));
51+
expected.add(new Entry("FG", "Denver"));
52+
expected.add(new Entry("ZH", "Denver"));
53+
expected.add(new Entry("AU", "Sydney"));
54+
55+
}
56+
57+
@Test
58+
public void sortAlphabetical() throws Exception {
59+
60+
List<Entry> sorted = presenter.sortAlphabetical(entries);
61+
62+
assertArrayEquals(sorted.toArray(), expected.toArray());
63+
64+
assertTrue(expected.equals(sorted));
65+
66+
}
67+
68+
@Test
69+
public void sortAlphabeticalFail() throws Exception {
70+
71+
72+
// .toArray(), expected.toArray());
73+
74+
assertFalse(expected.equals(entries));
75+
76+
}
77+
78+
79+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy