@@ -327,9 +327,11 @@ protected void onCreate(Bundle savedInstanceState) {
327
327
@ Override
328
328
public void onClick (View v ) {
329
329
//set default people list
330
- setUpPeopleList (true );
331
- //set visibility of this image false
332
- ivSearchPeopleCancel .setVisibility (View .GONE );
330
+ try {
331
+ peopleAdapter .changeCursor (getPeopleCursorGenerator ().call ());
332
+ } catch (Exception e ) {
333
+ e .printStackTrace ();
334
+ }
333
335
//set search editText text empty
334
336
etSearchPeople .setText ("" );
335
337
}
@@ -379,7 +381,7 @@ public void onDrawerOpened(View drawerView) {
379
381
peopleDrawer = (ListView ) findViewById (R .id .people_drawer );
380
382
381
383
//set up people list
382
- setUpPeopleList (true );
384
+ setUpPeopleList ();
383
385
384
386
peopleDrawer .setOnItemClickListener (new OnItemClickListener () {
385
387
@ Override
@@ -563,23 +565,67 @@ public void afterTextChanged(Editable s) {
563
565
});
564
566
}
565
567
566
- private void setUpPeopleList (final boolean isDefault , final String ... filterKeyWord ) {
568
+ private void setUpPeopleList () {
569
+ try {
570
+ this .peopleAdapter = new RefreshableCursorAdapter (
571
+ this .getApplicationContext (), R .layout .stream_tile ,
572
+ getPeopleCursorGenerator ().call (), getPeopleCursorGenerator (), new String []{
573
+ Person .NAME_FIELD , Person .EMAIL_FIELD }, new int []{
574
+ R .id .name , R .id .stream_dot }, 0 );
575
+ peopleAdapter .setViewBinder (peopleBinder );
576
+
577
+ peopleDrawer .setAdapter (peopleAdapter );
578
+ } catch (SQLException e ) {
579
+ throw new RuntimeException (e );
580
+ } catch (Exception e ) {
581
+ ZLog .logException (e );
582
+ }
583
+ }
584
+
585
+ private void onTextChangeOfPeopleSearchEditText () {
586
+ etSearchPeople .addTextChangedListener (new TextWatcher () {
587
+ @ Override
588
+ public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
589
+
590
+ }
591
+
592
+ @ Override
593
+ public void onTextChanged (CharSequence s , int start , int before , int count ) {
594
+ try {
595
+ peopleAdapter .changeCursor (getPeopleCursorGenerator ().call ());
596
+ } catch (Exception e ) {
597
+ e .printStackTrace ();
598
+ }
599
+ }
600
+
601
+ @ Override
602
+ public void afterTextChanged (Editable s ) {
603
+
604
+ }
605
+ });
606
+ }
607
+
608
+ private Callable <Cursor > getPeopleCursorGenerator () {
567
609
Callable <Cursor > peopleGenerator = new Callable <Cursor >() {
568
610
569
611
@ Override
570
612
public Cursor call () throws Exception {
571
613
// TODO Auto-generated method stub
572
614
List <Person > people ;
573
- if (isDefault ) {
615
+ if (etSearchPeople . getText (). toString (). equals ( "" ) || etSearchPeople . getText (). toString (). isEmpty () ) {
574
616
people = app .getDao (Person .class ).queryBuilder ()
575
617
.where ().eq (Person .ISBOT_FIELD , false ).and ()
576
618
.eq (Person .ISACTIVE_FIELD , true ).query ();
619
+ //set visibility of this image false
620
+ ivSearchPeopleCancel .setVisibility (View .GONE );
577
621
}else
578
622
{
579
623
people = app .getDao (Person .class ).queryBuilder ()
580
624
.where ().eq (Person .ISBOT_FIELD , false ).and ()
581
- .like (Person .NAME_FIELD ,"%" +filterKeyWord [ 0 ] +"%" ).and ()
625
+ .like (Person .NAME_FIELD ,"%" +etSearchPeople . getText (). toString () +"%" ).and ()
582
626
.eq (Person .ISACTIVE_FIELD , true ).query ();
627
+ //set visibility of this image false
628
+ ivSearchPeopleCancel .setVisibility (View .VISIBLE );
583
629
}
584
630
585
631
Person .sortByPresence (app , people );
@@ -609,51 +655,7 @@ public Cursor call() throws Exception {
609
655
}
610
656
611
657
};
612
- try {
613
- this .peopleAdapter = new RefreshableCursorAdapter (
614
- this .getApplicationContext (), R .layout .stream_tile ,
615
- peopleGenerator .call (), peopleGenerator , new String []{
616
- Person .NAME_FIELD , Person .EMAIL_FIELD }, new int []{
617
- R .id .name , R .id .stream_dot }, 0 );
618
- peopleAdapter .setViewBinder (peopleBinder );
619
-
620
- peopleDrawer .setAdapter (peopleAdapter );
621
- } catch (SQLException e ) {
622
- throw new RuntimeException (e );
623
- } catch (Exception e ) {
624
- ZLog .logException (e );
625
- }
626
- }
627
-
628
- private void onTextChangeOfPeopleSearchEditText () {
629
- etSearchPeople .addTextChangedListener (new TextWatcher () {
630
- @ Override
631
- public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
632
-
633
- }
634
-
635
- @ Override
636
- public void onTextChanged (CharSequence s , int start , int before , int count ) {
637
- if (etSearchPeople .getText ().toString ().equals ("" ) || etSearchPeople .getText ().toString ().isEmpty ())
638
- {
639
- //set default people list
640
- setUpPeopleList (true );
641
- //set visibility of this image false
642
- ivSearchPeopleCancel .setVisibility (View .GONE );
643
- }else
644
- {
645
- //filter people list
646
- setUpPeopleList (false ,etSearchPeople .getText ().toString ());
647
- //set visibility of this image false
648
- ivSearchPeopleCancel .setVisibility (View .VISIBLE );
649
- }
650
- }
651
-
652
- @ Override
653
- public void afterTextChanged (Editable s ) {
654
-
655
- }
656
- });
658
+ return peopleGenerator ;
657
659
}
658
660
659
661
@ Override
0 commit comments