Skip to content

Commit a7a438c

Browse files
author
hussienalrubaye
committed
tracker
1 parent 3069056 commit a7a438c

File tree

3 files changed

+120
-12
lines changed

3 files changed

+120
-12
lines changed

FindMyPhone Assets/snaped_code.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,53 @@ public void onCancelled(DatabaseError error) {
133133
// Log.w(TAG, "Failed to read value.", error.toException());
134134
}
135135
});
136+
//Global file
137+
Context context;
138+
SharedPreferences ShredRef;
139+
public GlobalInfo(Context context){
140+
this.context=context;
141+
ShredRef=context.getSharedPreferences("myRef",Context.MODE_PRIVATE);
142+
}
143+
144+
void SaveData(){
145+
String MyTrackersList="" ;
146+
for (Map.Entry m:GlobalInfo.MyTrackers.entrySet()){
147+
if (MyTrackersList.length()==0)
148+
MyTrackersList=m.getKey() + "%" + m.getValue();
149+
else
150+
MyTrackersList+= m.getKey() + "%" + m.getValue();
151+
152+
}
153+
154+
if (MyTrackersList.length()==0)
155+
MyTrackersList="empty";
156+
157+
158+
SharedPreferences.Editor editor=ShredRef.edit();
159+
editor.putString("MyTrackers",MyTrackersList);
160+
editor.putString("PhoneNumber",PhoneNumber);
161+
editor.commit();
162+
}
136163

164+
void LoadData(){
165+
MyTrackers.clear();
166+
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
167+
String MyTrackersList= ShredRef.getString("MyTrackers","empty");
168+
if (!MyTrackersList.equals("empty")){
169+
String[] users=MyTrackersList.split("%");
170+
for (int i=0;i<users.length;i=i+2){
171+
MyTrackers.put(users[i],users[i+1]);
172+
}
173+
}
174+
175+
176+
if (PhoneNumber.equals("empty")){
177+
178+
Intent intent=new Intent(context, Login.class);
179+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
180+
context.startActivity(intent);
181+
}
182+
183+
}
137184

138185

MyTracker/app/src/main/java/com/alrubaye/mytracker/GlobalInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void SaveData(){
7272

7373
void LoadData(){
7474
MyTrackers.clear();
75-
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
75+
PhoneNumber= ShredRef.getString("PhoneNumber","empty");
7676
String MyTrackersList= ShredRef.getString("MyTrackers","empty");
7777
if (!MyTrackersList.equals("empty")){
7878
String[] users=MyTrackersList.split("%");

MyTracker/app/src/main/java/com/alrubaye/mytracker/MainActivity.java

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)