@@ -50,12 +50,67 @@ protected void onCreate(Bundle savedInstanceState) {
5050 myadapter =new MyCustomAdapter (listnewsData );
5151 ListView lsNews =(ListView )findViewById (R .id .listView );
5252 lsNews .setAdapter (myadapter );//intisal with data
53- Refesh ();
53+ // Refesh();
5454 }
5555
5656 void Refesh (){
5757 listnewsData .clear ();
58-
58+ databaseReference .child ("Users" ).child (GlobalInfo .PhoneNumber ).
59+ child ("Finders" ).addValueEventListener (new ValueEventListener () {
60+ @ Override
61+ public void onDataChange (DataSnapshot dataSnapshot ) {
62+
63+ Map <String , Object > td = (HashMap <String , Object >) dataSnapshot .getValue ();
64+
65+ listnewsData .clear ();
66+ if (td == null ) //no one allow you to find him
67+ {
68+ listnewsData .add (new AdapterItems ("NoTicket" , "no_desc" ));
69+ myadapter .notifyDataSetChanged ();
70+ return ;
71+ }
72+ // List<Object> values = td.values();
73+
74+
75+ // get all contact to list
76+ ArrayList <AdapterItems > list_contact = new ArrayList <AdapterItems >();
77+ Cursor cursor = getContentResolver ().query (ContactsContract .CommonDataKinds .Phone .CONTENT_URI , null , null , null , null );
78+ while (cursor .moveToNext ()) {
79+ String name = cursor .getString (cursor .getColumnIndex (ContactsContract .CommonDataKinds .Phone .DISPLAY_NAME ));
80+
81+ String phoneNumber = cursor .getString (cursor .getColumnIndex (ContactsContract .CommonDataKinds .Phone .NUMBER ));
82+ list_contact .add (new AdapterItems ( name ,GlobalInfo .FormatPhoneNumber (phoneNumber )
83+ ));
84+
85+
86+ }
87+
88+
89+ // if the name is save chane his text
90+ // case who find me
91+ String tinfo ;
92+ for ( String Numbers : td .keySet ()) {
93+ for (AdapterItems cs : list_contact ) {
94+
95+ //IsFound = SettingSaved.WhoIFindIN.get(cs.Detals); // for case who i could find list
96+ if (cs .PhoneNumber .length () > 0 )
97+ if (Numbers .contains (cs .PhoneNumber )) {
98+ listnewsData .add (new AdapterItems (cs .UserName , cs .PhoneNumber ));
99+ break ;
100+ }
101+
102+ }
103+
104+ }
105+ myadapter .notifyDataSetChanged ();
106+ }
107+
108+ @ Override
109+ public void onCancelled (DatabaseError error ) {
110+ // Failed to read value
111+ // Log.w(TAG, "Failed to read value.", error.toException());
112+ }
113+ });
59114
60115
61116
@@ -165,19 +220,25 @@ public long getItemId(int position) {
165220 }
166221
167222 @ Override
168- public View getView (int position , View convertView , ViewGroup parent )
169- {
223+ public View getView (int position , View convertView , ViewGroup parent ) {
170224 LayoutInflater mInflater = getLayoutInflater ();
171- View myView = mInflater .inflate (R .layout .single_row_conact , null );
172225
173- final AdapterItems s = listnewsDataAdpater .get (position );
226+ final AdapterItems s = listnewsDataAdpater .get (position );
227+ if (s .UserName .equals ("NoTicket" )) {
228+ View myView = mInflater .inflate (R .layout .news_ticket_no_news , null );
229+
230+ return myView ;
174231
175- TextView tv_user_name =( TextView )myView .findViewById (R .id .tv_user_name );
176- tv_user_name .setText (s .UserName );
177- TextView tv_phone =( TextView )myView .findViewById (R .id .tv_phone );
178- tv_phone .setText (s .PhoneNumber );
232+ } else {
233+ View myView = mInflater .inflate (R .layout .single_row_conact , null );
179234
180- return myView ;
235+ TextView tv_user_name = (TextView ) myView .findViewById (R .id .tv_user_name );
236+ tv_user_name .setText (s .UserName );
237+ TextView tv_phone = (TextView ) myView .findViewById (R .id .tv_phone );
238+ tv_phone .setText (s .PhoneNumber );
239+
240+ return myView ;
241+ }
181242 }
182243
183244 }
0 commit comments