|
@@ -1,6 +1,8 @@
|
|
|
package com.sikey.skcontact.manager;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
+import android.content.ContentResolver;
|
|
|
+import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
import android.util.Log;
|
|
@@ -11,51 +13,59 @@ import com.sikey.skcontact.utils.Macros;
|
|
|
import com.sikey.skcontact.utils.MetaData;
|
|
|
import com.sikey.skcontact.utils.ToolsUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
public class DatabaseUtils {
|
|
|
- public String TAG = "losion / skcontact :" + getClass().getSimpleName();
|
|
|
+ public static String TAG = "losion / skcontact :" + "DatabaseUtils";
|
|
|
public DatabaseUtils() {}
|
|
|
|
|
|
@SuppressLint("Range")
|
|
|
- public ContactBean loadContact(String userId) {
|
|
|
- Log.d(TAG, "loadContact: ");
|
|
|
+ public static ArrayList<ContactBean> queryContacts(Context context) {
|
|
|
if (Macros.DEBUG) {
|
|
|
- ContactBean bean = new ContactBean();
|
|
|
- bean.userId = userId;
|
|
|
- bean.name = "Father";
|
|
|
- return bean;
|
|
|
+ return testContactList();
|
|
|
} else {
|
|
|
+ ArrayList<ContactBean> arrayList = new ArrayList<>();
|
|
|
+ ContentResolver resolver = context.getContentResolver();
|
|
|
Uri uri = Uri.parse(MetaData.DB_CONTACTS);
|
|
|
- Cursor cursor = ContactApplication.getsContext().getContentResolver().query(uri, null, null, null, null);
|
|
|
+ Cursor cursor = resolver.query(uri, null, null, null, null);
|
|
|
if (cursor == null) {
|
|
|
- Log.d(TAG, "loadContact: cursor == null");
|
|
|
- return null;
|
|
|
+ Log.d(TAG, "queryContacts: cursor == null");
|
|
|
+ return arrayList;
|
|
|
}
|
|
|
if (!cursor.moveToFirst()) {
|
|
|
- Log.d(TAG, "loadContact: cursor.moveToFirst() false");
|
|
|
+ Log.d(TAG, "queryContacts: cursor.moveToFirst() == false");
|
|
|
cursor.close();
|
|
|
- return null;
|
|
|
+ return arrayList;
|
|
|
}
|
|
|
-
|
|
|
- ContactBean bean = new ContactBean();
|
|
|
+ Log.d(TAG, "queryContacts: db ok");
|
|
|
do {
|
|
|
- String uId = cursor.getString(cursor.getColumnIndex("userId"));
|
|
|
- if (uId.equals(userId)) {
|
|
|
- Log.d(TAG, "loadContact: find contact");
|
|
|
- bean._id = cursor.getLong(cursor.getColumnIndex("_id"));
|
|
|
- bean.id = cursor.getString(cursor.getColumnIndex("id"));
|
|
|
- bean.userId = cursor.getString(cursor.getColumnIndex("userId"));
|
|
|
- bean.name = cursor.getString(cursor.getColumnIndex("name"));
|
|
|
- bean.profile = cursor.getString(cursor.getColumnIndex("profile"));
|
|
|
- bean.profilePath = cursor.getString(cursor.getColumnIndex("profilePath"));
|
|
|
- bean.phoneNumber = cursor.getString(cursor.getColumnIndex("phoneNumber"));
|
|
|
- bean.countryPN = cursor.getString(cursor.getColumnIndex("countryPN"));
|
|
|
- bean.type = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("type")));
|
|
|
- bean.rate = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("rate")));
|
|
|
- bean.unRead = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("unRead")));
|
|
|
- }
|
|
|
+ ContactBean bean = new ContactBean();
|
|
|
+ bean.id = cursor.getString(cursor.getColumnIndex("id"));
|
|
|
+ bean.name = cursor.getString(cursor.getColumnIndex("name"));
|
|
|
+ bean.profile = cursor.getString(cursor.getColumnIndex("profile"));
|
|
|
+ bean.profilePath = cursor.getString(cursor.getColumnIndex("profilePath"));
|
|
|
+ bean.phoneNumber = cursor.getString(cursor.getColumnIndex("phoneNumber"));
|
|
|
+ bean.countryPN = cursor.getString(cursor.getColumnIndex("countryPN"));
|
|
|
+ bean.type = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("type")));
|
|
|
+ bean.rate = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("rate")));
|
|
|
+ bean.unRead = ToolsUtils.parseInt(cursor.getString(cursor.getColumnIndex("unRead")));
|
|
|
+ arrayList.add(bean);
|
|
|
} while (cursor.moveToNext());
|
|
|
cursor.close();
|
|
|
- return bean;
|
|
|
+ Log.d(TAG, "queryContacts: " + arrayList.size());
|
|
|
+ return arrayList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ArrayList<ContactBean> testContactList() {
|
|
|
+ ArrayList<ContactBean> arrayList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ ContactBean bean = new ContactBean();
|
|
|
+ bean.id = "2000";
|
|
|
+ bean.name = "abcdefghijk"+ i;
|
|
|
+ bean.phoneNumber = "1111";
|
|
|
+ arrayList.add(bean);
|
|
|
}
|
|
|
+ return arrayList;
|
|
|
}
|
|
|
}
|