use of dev.sagar.smsblocker.tech.service.DBServiceSingleton in project SMSBlocker by sagarpawardev.
the class InboxUtil method bgGetAllSMSFromTo.
private List<SMS> bgGetAllSMSFromTo(String contactNo, int sortingOrder) {
final String methodName = "bgGetAllSMSFromTo(String, int)";
log.justEntered(methodName);
// Reading Saved SMSes
String selection = address + " LIKE ?";
String[] projection = { starredsms_id };
String tableName = DBConstants.TABLE_SAVEDSMS;
String encodedAddress = phoneUtils.encode(contactNo);
String[] selectionArgs = { encodedAddress };
DBHelper helper = new DBHelper(context);
SQLiteDatabase db = helper.getReadableDatabase();
DBServiceSingleton dbService = DBServiceSingleton.getInstance();
Cursor cursor = dbService.query(db, tableName, projection, selection, selectionArgs, null);
log.debug(methodName, "Saved SMS Returned Row Count: " + cursor.getCount() + " Selection: " + selection + " Args: " + selectionArgs[0]);
HashSet<String> set = new HashSet<>();
try {
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndexOrThrow(this.starredsms_id));
set.add(id);
}
} catch (NullPointerException e) {
e.printStackTrace();
} finally {
if (cursor != null)
cursor.close();
db.close();
helper.close();
}
log.debug(methodName, "Saved SMS Set size: " + set.size());
// Reading SMSes from database
Uri uriSmsURI = Telephony.Sms.CONTENT_URI;
selection = address + " = ?";
projection = new String[] { "*" };
selectionArgs = new String[] { contactNo };
String mSortOrder = null;
switch(sortingOrder) {
case SORT_DESC:
mSortOrder = date + " DESC";
break;
case SORT_ASC:
mSortOrder = date + " ASC";
break;
default:
mSortOrder = "";
}
ContentResolver mContentResolver = context.getContentResolver();
Cursor c = dbService.query(mContentResolver, uriSmsURI, projection, selection, selectionArgs, mSortOrder);
ArrayList<SMS> smses = new ArrayList<>();
log.info(methodName, "Reading SMSes... ");
try {
while (c.moveToNext()) {
String from = c.getString(c.getColumnIndexOrThrow(this.address));
String id = c.getString(c.getColumnIndexOrThrow(this._id));
String body = c.getString(c.getColumnIndexOrThrow(this.body));
int subscriptionId = c.getInt(c.getColumnIndexOrThrow(this.subscriptionId));
boolean readState = c.getInt(c.getColumnIndex(this.read)) == 1;
long time = c.getLong(c.getColumnIndexOrThrow(this.date));
long type = c.getLong(c.getColumnIndexOrThrow(this.type));
boolean replySupported = PhoneUtilsSingleton.getInstance().isReplySupported(from);
SMS sms = new SMS();
sms.setId(id);
sms.setAddress(from);
sms.setBody(body);
sms.setRead(readState);
sms.setDateTime(time);
sms.setType(type);
sms.setSubscription(subscriptionId);
sms.setReplySupported(replySupported);
if (set.contains(id))
sms.setSaved(true);
smses.add(sms);
log.debug(methodName, "Address: " + from + " ReplySupported: " + c.getString(c.getColumnIndex(this.replySupported)));
}
} catch (NullPointerException e) {
e.printStackTrace();
} finally {
if (c != null)
c.close();
}
return smses;
}
use of dev.sagar.smsblocker.tech.service.DBServiceSingleton in project SMSBlocker by sagarpawardev.
the class MarkSMSReadHandler method doInBackground.
@Override
protected Void doInBackground(String... strings) {
final String methodName = "doInBackground()";
log.justEntered(methodName);
String fromNumber = strings[0];
log.error(methodName, "Can be improved Here");
Uri uriSMSUri = Telephony.Sms.Inbox.CONTENT_URI;
String selection = address + " = ? ";
String[] selectionArgs = { fromNumber };
ContentValues values = new ContentValues();
values.put(read, true);
DBServiceSingleton dbService = DBServiceSingleton.getInstance();
int updateCount = dbService.update(context, uriSMSUri, values, selection, selectionArgs);
log.info(methodName, "Update Count: " + updateCount);
log.returning(methodName);
return null;
}
Aggregations