@@ -343,10 +343,11 @@ public void onClick(View v) {
343
343
@ Override
344
344
public void onClick (View v ) {
345
345
//set default stream list
346
- setupListViewAdapter (true );
347
- //set visibility of this image false
348
- ivSearchStreamCancel .setVisibility (View .GONE );
349
- //set search editText text empty
346
+ try {
347
+ streamsDrawerAdapter .changeCursor (getSteamCursorGenerator ().call ());
348
+ } catch (Exception e ) {
349
+ e .printStackTrace ();
350
+ }
350
351
etSearchStream .setText ("" );
351
352
}
352
353
});
@@ -366,7 +367,7 @@ public void onDrawerClosed(View view) {
366
367
public void onDrawerOpened (View drawerView ) {
367
368
// pass
368
369
try {
369
- streamsDrawerAdapter .changeCursor (streamsGenerator .call ());
370
+ streamsDrawerAdapter .changeCursor (getSteamCursorGenerator () .call ());
370
371
} catch (Exception e ) {
371
372
ZLog .logException (e );
372
373
}
@@ -542,19 +543,10 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
542
543
543
544
@ Override
544
545
public void onTextChanged (CharSequence s , int start , int before , int count ) {
545
- if (etSearchStream .getText ().toString ().equals ("" ) || etSearchStream .getText ().toString ().isEmpty ())
546
- {
547
- //set default stream list
548
- setupListViewAdapter (true );
549
- //set visibility of this image false
550
- ivSearchStreamCancel .setVisibility (View .GONE );
551
- }else
552
- {
553
- //filter stream list
554
- streamSearchFilterKeyword = etSearchStream .getText ().toString ();
555
- setupListViewAdapter (false );
556
- //set visibility of this image false
557
- ivSearchStreamCancel .setVisibility (View .VISIBLE );
546
+ try {
547
+ streamsDrawerAdapter .changeCursor (getSteamCursorGenerator ().call ());
548
+ } catch (Exception e ) {
549
+ e .printStackTrace ();
558
550
}
559
551
}
560
552
@@ -565,6 +557,35 @@ public void afterTextChanged(Editable s) {
565
557
});
566
558
}
567
559
560
+ private Callable <Cursor > getSteamCursorGenerator () {
561
+
562
+ Callable <Cursor > steamCursorGenerator = new Callable <Cursor >() {
563
+ @ Override
564
+ public Cursor call () throws Exception {
565
+ int pointer = app .getPointer ();
566
+ String query ="SELECT s.id as _id, s.name, s.color, count(case when m.id > " + pointer + " or m." + Message .MESSAGE_READ_FIELD
567
+ + " = 0 then 1 end) as " + ExpandableStreamDrawerAdapter .UNREAD_TABLE_NAME
568
+ + " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream " ;
569
+ if (!etSearchStream .getText ().toString ().equals ("" ) && !etSearchStream .getText ().toString ().isEmpty ())
570
+ {
571
+ //append where clause
572
+ query +=" WHERE s.name LIKE '%" + etSearchStream .getText ().toString () + "%'" ;
573
+ //set visibility of this image false
574
+ ivSearchStreamCancel .setVisibility (View .VISIBLE );
575
+ }else
576
+ {
577
+ //set visibility of this image false
578
+ ivSearchStreamCancel .setVisibility (View .GONE );
579
+ }
580
+ //append group by
581
+ query += " group by s.name order by s.name COLLATE NOCASE" ;
582
+
583
+ return ((AndroidDatabaseResults ) app .getDao (Stream .class ).queryRaw (query ).closeableIterator ().getRawResults ()).getRawCursor ();
584
+ }
585
+ };
586
+ return steamCursorGenerator ;
587
+ }
588
+
568
589
private void setUpPeopleList () {
569
590
try {
570
591
this .peopleAdapter = new RefreshableCursorAdapter (
@@ -943,30 +964,10 @@ public void onAnimationRepeat(Animator animator) {
943
964
animator .start ();
944
965
}
945
966
946
- Callable <Cursor > streamsGenerator = new Callable <Cursor >() {
947
- @ Override
948
- public Cursor call () throws Exception {
949
- int pointer = app .getPointer ();
950
- return ((AndroidDatabaseResults ) app .getDao (Stream .class ).queryRaw ("SELECT s.id as _id, s.name, s.color," +
951
- " count(case when m.id > " + pointer + " or m." + Message .MESSAGE_READ_FIELD + " = 0 then 1 end) as " + ExpandableStreamDrawerAdapter .UNREAD_TABLE_NAME
952
- + " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream group by s.name order by s.name COLLATE NOCASE" ).closeableIterator ().getRawResults ()).getRawCursor ();
953
- }
954
- };
955
-
956
- Callable <Cursor > streamsGeneratorWithFilter = new Callable <Cursor >() {
957
- @ Override
958
- public Cursor call () throws Exception {
959
- int pointer = app .getPointer ();
960
- return ((AndroidDatabaseResults ) app .getDao (Stream .class ).queryRaw ("SELECT s.id as _id, s.name, s.color," +
961
- " count(case when m.id > " + pointer + " or m." + Message .MESSAGE_READ_FIELD + " = 0 then 1 end) as " + ExpandableStreamDrawerAdapter .UNREAD_TABLE_NAME
962
- + " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream" +" WHERE s.name LIKE '%" + streamSearchFilterKeyword +"%' group by s.name order by s.name COLLATE NOCASE" ).closeableIterator ().getRawResults ()).getRawCursor ();
963
- }
964
- };
965
-
966
967
/**
967
968
* Setup the streams Drawer which has a {@link ExpandableListView} categorizes the stream and subject
968
969
*/
969
- private void setupListViewAdapter (boolean isDefault ) {
970
+ private void setupListViewAdapter () {
970
971
streamsDrawerAdapter = null ;
971
972
String [] groupFrom = {Stream .NAME_FIELD , Stream .COLOR_FIELD , ExpandableStreamDrawerAdapter .UNREAD_TABLE_NAME };
972
973
int [] groupTo = {R .id .name , R .id .stream_dot , R .id .unread_group };
@@ -976,18 +977,10 @@ private void setupListViewAdapter(boolean isDefault) {
976
977
final ExpandableListView streamsDrawer = (ExpandableListView ) findViewById (R .id .streams_drawer );
977
978
streamsDrawer .setGroupIndicator (null );
978
979
try {
979
- if (isDefault ) {
980
- streamsDrawerAdapter = new ExpandableStreamDrawerAdapter (this , streamsGenerator .call (),
980
+ streamsDrawerAdapter = new ExpandableStreamDrawerAdapter (this , getSteamCursorGenerator ().call (),
981
981
R .layout .stream_tile_new , groupFrom ,
982
982
groupTo , R .layout .stream_tile_child , childFrom ,
983
983
childTo );
984
- }else
985
- {
986
- streamsDrawerAdapter = new ExpandableStreamDrawerAdapter (this , streamsGeneratorWithFilter .call (),
987
- R .layout .stream_tile_new , groupFrom ,
988
- groupTo , R .layout .stream_tile_child , childFrom ,
989
- childTo );
990
- }
991
984
} catch (Exception e ) {
992
985
ZLog .logException (e );
993
986
}
@@ -1090,7 +1083,7 @@ public void onClick(View v) {
1090
1083
* Initiates the streams Drawer if the streams in the drawer is 0.
1091
1084
*/
1092
1085
public void checkAndSetupStreamsDrawer () {
1093
- setupListViewAdapter (true );
1086
+ setupListViewAdapter ();
1094
1087
}
1095
1088
1096
1089
private void sendMessage () {
0 commit comments