Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit b7e1ac4

Browse files
committed
Add equals method in the narrow filter interface.
1 parent 7b58a7b commit b7e1ac4

File tree

7 files changed

+73
-8
lines changed

7 files changed

+73
-8
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,13 +1896,14 @@ public void onNarrowFillSendBoxStream(String stream, String subject, boolean ope
18961896
}
18971897

18981898
public void onNarrow(NarrowFilter narrowFilter) {
1899-
if (narrowedList == null || narrowFilter != narrowedList.filter)
1900-
doNarrow(narrowFilter);
1899+
if (narrowedList == null || !narrowedList.filter.equals(narrowFilter)) {
1900+
doNarrow(narrowFilter);
1901+
}
19011902
}
19021903

19031904

19041905
public void onNarrow(NarrowFilter narrowFilter, int messageId) {
1905-
if (narrowedList == null || narrowFilter != narrowedList.filter) {
1906+
if (narrowedList == null || !narrowedList.filter.equals(narrowFilter)) {
19061907
doNarrow(narrowFilter, messageId);
19071908
}
19081909
}
@@ -1941,7 +1942,7 @@ private boolean prepareSearchView(Menu menu) {
19411942
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
19421943
@Override
19431944
public boolean onQueryTextSubmit(String s) {
1944-
doNarrow(new NarrowFilterSearch(s));
1945+
onNarrow(new NarrowFilterSearch(s));
19451946
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
19461947
mSearchMenuItem.collapseActionView();
19471948
}
@@ -2003,7 +2004,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
20032004
public void onClick(
20042005
DialogInterface dialogInterface, int i) {
20052006
String query = editText.getText().toString();
2006-
doNarrow(new NarrowFilterSearch(query));
2007+
onNarrow(new NarrowFilterSearch(query));
20072008
}
20082009
});
20092010
builder.show();
@@ -2032,19 +2033,19 @@ public void onClick(
20322033
if (menu != null && menu.getItem(2).getSubMenu().getItem(0).getTitle().equals(getString(R.string.menu_one_day_before))) {
20332034
//user selected One Day Before
20342035
calendar.add(Calendar.DATE, -1);
2035-
doNarrow(new NarrowFilterByDate(calendar.getTime()));
2036+
onNarrow(new NarrowFilterByDate(calendar.getTime()));
20362037
break;
20372038
}
20382039
//else Narrow to Today
2039-
doNarrow(new NarrowFilterByDate());
2040+
onNarrow(new NarrowFilterByDate());
20402041
break;
20412042
case R.id.enterDate:
20422043
//show Dialog with calendar date as selected to pick Date
20432044
DatePickerDialog datePickerDialog = new DatePickerDialog(ZulipActivity.this, new DatePickerDialog.OnDateSetListener() {
20442045
@Override
20452046
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
20462047
calendar.set(year, month, dayOfMonth);
2047-
doNarrow(new NarrowFilterByDate(calendar.getTime()));
2048+
onNarrow(new NarrowFilterByDate(calendar.getTime()));
20482049
}
20492050
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
20502051
//set max date to today so future dates are not selectable

app/src/main/java/com/zulip/android/filters/NarrowFilter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ public Where<Message, Object> modWhere(Where<Message, Object> where)
5151
* A filter to apply when fetching additional messages from the server
5252
*/
5353
public String getJsonFilter() throws JSONException;
54+
55+
/**
56+
* Check if the current narrow filter matches the passed filter
57+
*/
58+
public boolean equals(NarrowFilter filter);
5459
}

app/src/main/java/com/zulip/android/filters/NarrowFilterAllPMs.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public String getJsonFilter() throws JSONException {
9595
return ret.toString();
9696
}
9797

98+
@Override
99+
public boolean equals(NarrowFilter filter) {
100+
if (filter instanceof NarrowFilterAllPMs) {
101+
return filter.getTitle().equals("All private messages");
102+
} else {
103+
return false;
104+
}
105+
}
106+
98107
@Override
99108
public String toString() {
100109
try {

app/src/main/java/com/zulip/android/filters/NarrowFilterByDate.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public void writeToParcel(Parcel dest, int flags) {
4848
dest.writeLong(date.getTime());
4949
}
5050

51+
public Date getDate() {
52+
return this.date;
53+
}
54+
5155
@Override
5256
public Where<Message, Object> modWhere(Where<Message, Object> where)
5357
throws SQLException {
@@ -97,6 +101,17 @@ public String getJsonFilter() throws JSONException {
97101
return "{}";
98102
}
99103

104+
@Override
105+
public boolean equals(NarrowFilter filter) {
106+
if (filter instanceof NarrowFilterByDate) {
107+
NarrowFilterByDate filterByDate = (NarrowFilterByDate) filter;
108+
return NarrowFilterByDate.isSameDay(this.getDate(),
109+
filterByDate.getDate());
110+
} else {
111+
return false;
112+
}
113+
}
114+
100115
@Override
101116
public String toString() {
102117
return "{}";

app/src/main/java/com/zulip/android/filters/NarrowFilterPM.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ public String getJsonFilter() throws JSONException {
110110
TextUtils.join(",", emails)))).toString();
111111
}
112112

113+
@Override
114+
public boolean equals(NarrowFilter filter) {
115+
if (filter instanceof NarrowFilterPM) {
116+
NarrowFilterPM filterPM = (NarrowFilterPM) filter;
117+
return this.getTitle().equals(filterPM.getTitle());
118+
} else {
119+
return false;
120+
}
121+
}
122+
113123
@Override
114124
public String toString() {
115125
try {

app/src/main/java/com/zulip/android/filters/NarrowFilterSearch.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public String getJsonFilter() throws JSONException {
7878
return filter.toString();
7979
}
8080

81+
@Override
82+
public boolean equals(NarrowFilter filter) {
83+
if (filter instanceof NarrowFilterSearch) {
84+
NarrowFilterSearch filterSearch = (NarrowFilterSearch) filter;
85+
return this.getTitle().equals(filterSearch.getTitle());
86+
} else {
87+
return false;
88+
}
89+
}
90+
8191
@Override
8292
public String toString() {
8393
try {

app/src/main/java/com/zulip/android/filters/NarrowFilterStream.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,19 @@ public String getJsonFilter() throws JSONException {
104104
}
105105
return filter.toString();
106106
}
107+
108+
@Override
109+
public boolean equals(NarrowFilter filter) {
110+
if (filter instanceof NarrowFilterStream) {
111+
NarrowFilterStream filterStream = (NarrowFilterStream) filter;
112+
if (filterStream.getSubtitle() == null) {
113+
return this.getSubtitle() == null && filterStream.getTitle().equals(this.getTitle());
114+
} else {
115+
return (filterStream.getTitle().equals(this.getTitle()) &&
116+
filterStream.getSubtitle().equals(this.getSubtitle()));
117+
}
118+
} else {
119+
return false;
120+
}
121+
}
107122
}

0 commit comments

Comments
 (0)