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

Commit ec1afe9

Browse files
jainkuniyatimabbott
authored andcommitted
Fixes: #264 Implemented One day before
1 parent b21fe7a commit ec1afe9

File tree

6 files changed

+144
-86
lines changed

6 files changed

+144
-86
lines changed

app/src/androidTest/java/com/zulip/android/activities/RecyclerViewTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import com.zulip.android.R;
1111
import com.zulip.android.ZulipApp;
12-
import com.zulip.android.filters.NarrowFilterToday;
12+
import com.zulip.android.filters.NarrowFilterByDate;
1313
import com.zulip.android.helper.ViewAssertions;
1414
import com.zulip.android.models.MessageType;
1515
import com.zulip.android.util.ZLog;
@@ -193,7 +193,7 @@ public void checkTodaysFilter() {
193193
mActivityTestRule.runOnUiThread(new Runnable() {
194194
@Override
195195
public void run() {
196-
mActivityTestRule.getActivity().doNarrow(new NarrowFilterToday());
196+
mActivityTestRule.getActivity().doNarrow(new NarrowFilterByDate());
197197
}
198198
});
199199
} catch (Throwable throwable) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ public void onMessages(Message[] messages, LoadPosition pos,
420420
}
421421

422422
loadingMessages = false;
423+
//check size of messageList
424+
if (messageList.size()==0)
425+
showEmptyView();
426+
else
427+
showRecyclerView();
428+
}
429+
430+
/**
431+
* hides TextView with no message
432+
* show recyclerView
433+
*/
434+
private void showRecyclerView() {
435+
recyclerView.setVisibility(View.VISIBLE);
436+
emptyTextView.setVisibility(View.GONE);
423437
}
424438

425439
public void onMessageError(LoadPosition pos) {

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
import com.zulip.android.filters.NarrowFilterPM;
7676
import com.zulip.android.filters.NarrowFilterSearch;
7777
import com.zulip.android.filters.NarrowFilterStream;
78-
import com.zulip.android.filters.NarrowFilterToday;
78+
import com.zulip.android.filters.NarrowFilterByDate;
7979
import com.zulip.android.filters.NarrowListener;
8080
import com.zulip.android.gcm.GcmBroadcastReceiver;
8181
import com.zulip.android.gcm.Notifications;
@@ -106,6 +106,7 @@
106106
import java.text.SimpleDateFormat;
107107
import java.util.ArrayList;
108108
import java.util.Arrays;
109+
import java.util.Calendar;
109110
import java.util.HashMap;
110111
import java.util.List;
111112
import java.util.concurrent.Callable;
@@ -187,6 +188,8 @@ public void onReceive(Context contenxt, Intent intent) {
187188
private ImageView cameraBtn;
188189
private String mCurrentPhotoPath;
189190
private Uri mPhotoURI;
191+
private Menu menu;
192+
private Calendar calendar;
190193

191194
@Override
192195
public void removeChatBox(boolean animToRight) {
@@ -543,11 +546,28 @@ public Cursor runQuery(CharSequence charSequence) {
543546
handleSentImage(intent);
544547
}
545548
}
546-
547549
// if device doesn't have camera, disable camera button
548550
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
549551
cameraBtn.setEnabled(false);
550552
}
553+
handleOnFragmentChange();
554+
calendar = Calendar.getInstance();
555+
}
556+
557+
private void handleOnFragmentChange() {
558+
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
559+
@Override
560+
public void onBackStackChanged() {
561+
if (menu == null)
562+
return;
563+
if (narrowedList==null) {
564+
calendar = Calendar.getInstance();
565+
menu.getItem(2).getSubMenu().getItem(0).setTitle(R.string.menu_today);
566+
} else if (narrowedList.filter instanceof NarrowFilterByDate) {
567+
menu.getItem(2).getSubMenu().getItem(0).setTitle(R.string.menu_one_day_before);
568+
}
569+
}
570+
});
551571
}
552572

553573
/**
@@ -1767,6 +1787,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
17671787
if (this.logged_in) {
17681788
getMenuInflater().inflate(R.menu.options, menu);
17691789
prepareSearchView(menu);
1790+
this.menu = menu;
17701791
return true;
17711792
}
17721793

@@ -1857,7 +1878,12 @@ public void onClick(
18571878
onRefresh();
18581879
break;
18591880
case R.id.today:
1860-
doNarrow(new NarrowFilterToday());
1881+
if (menu != null && menu.getItem(2).getSubMenu().getItem(0).getTitle().equals(getString(R.string.menu_one_day_before))) {
1882+
calendar.add(Calendar.DATE, -1);
1883+
doNarrow(new NarrowFilterByDate(calendar.getTime()));
1884+
break;
1885+
}
1886+
doNarrow(new NarrowFilterByDate());
18611887
break;
18621888
case R.id.logout:
18631889
logout();
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.zulip.android.filters;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
import com.j256.ormlite.stmt.SelectArg;
7+
import com.j256.ormlite.stmt.Where;
8+
import com.zulip.android.models.Message;
9+
import com.zulip.android.models.Stream;
10+
11+
import org.json.JSONException;
12+
13+
import java.sql.SQLException;
14+
import java.text.SimpleDateFormat;
15+
import java.util.Date;
16+
17+
public class NarrowFilterByDate implements NarrowFilter {
18+
19+
private Date date = new Date();
20+
21+
public static final Parcelable.Creator<NarrowFilterByDate> CREATOR = new Parcelable.Creator<NarrowFilterByDate>() {
22+
public NarrowFilterByDate createFromParcel(Parcel in) {
23+
24+
return new NarrowFilterByDate();
25+
}
26+
27+
public NarrowFilterByDate[] newArray(int size) {
28+
return new NarrowFilterByDate[size];
29+
}
30+
};
31+
32+
public NarrowFilterByDate() {
33+
}
34+
35+
public NarrowFilterByDate(Date date) {
36+
this.date =date;
37+
}
38+
39+
public int describeContents() {
40+
return 0;
41+
}
42+
43+
public void writeToParcel(Parcel dest, int flags) {
44+
}
45+
46+
@Override
47+
public Where<Message, Object> modWhere(Where<Message, Object> where)
48+
throws SQLException {
49+
where.like(Message.TIMESTAMP_FIELD, new SelectArg( date));
50+
return where;
51+
}
52+
53+
@Override
54+
public boolean matches(Message msg) {
55+
return isSameDay(date.getTime(),msg.getTimestamp().getTime());
56+
}
57+
58+
@Override
59+
public String getTitle() {
60+
return isSameDay(date.getTime(),new Date().getTime()) ?"Today Messages" : "Messages";
61+
}
62+
63+
@Override
64+
public String getSubtitle() {
65+
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
66+
return dateFormat.format(date);
67+
}
68+
69+
@Override
70+
public Stream getComposeStream() {
71+
return null;
72+
}
73+
74+
@Override
75+
public String getComposePMRecipient() {
76+
return null;
77+
}
78+
79+
@Override
80+
public String getJsonFilter() throws JSONException {
81+
return "{}";
82+
}
83+
84+
@Override
85+
public String toString() {
86+
return "{}";
87+
}
88+
89+
/**
90+
* Checks two dates are of same day or not
91+
* @param date1 long date1 to be compared with date2
92+
* @param date2 long date2 to be compared with date1
93+
* @return boolean
94+
*/
95+
private static boolean isSameDay(long date1, long date2) {
96+
return date1/86400000 == date2/86400000;
97+
}
98+
}

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

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

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@
114114
<string name="delete_content_desp">delete</string>
115115
<string name="cancel_content_desp" tools:ignore="ButtonCase">cancel</string>
116116
<string name="camera_content_desp">take photo</string>
117+
<string name="menu_one_day_before">One Day Before</string>
117118
</resources>

0 commit comments

Comments
 (0)