use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class DirectMessageRefreshService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Context context = getApplicationContext();
AppSettings settings = AppSettings.getInstance(context);
// if they have mobile data on and don't want to sync over mobile data
if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
return;
}
boolean update = false;
int numberNew = 0;
try {
Twitter twitter = Utils.getTwitter(context, settings);
int currentAccount = sharedPrefs.getInt("current_account", 1);
User user = twitter.verifyCredentials();
long lastId = sharedPrefs.getLong("last_direct_message_id_" + currentAccount, 0);
Paging paging;
if (lastId != 0) {
paging = new Paging(1).sinceId(lastId);
} else {
paging = new Paging(1, 500);
}
List<DirectMessage> dm = twitter.getDirectMessages(paging);
List<DirectMessage> sent = twitter.getSentDirectMessages(paging);
if (dm.size() != 0) {
sharedPrefs.edit().putLong("last_direct_message_id_" + currentAccount, dm.get(0).getId()).commit();
numberNew = dm.size();
} else {
numberNew = 0;
}
DMDataSource dataSource = DMDataSource.getInstance(context);
int inserted = 0;
for (DirectMessage directMessage : dm) {
try {
dataSource.createDirectMessage(directMessage, currentAccount);
} catch (Exception e) {
dataSource = DMDataSource.getInstance(context);
dataSource.createDirectMessage(directMessage, currentAccount);
}
inserted++;
}
for (DirectMessage directMessage : sent) {
try {
dataSource.createDirectMessage(directMessage, currentAccount);
} catch (Exception e) {
dataSource = DMDataSource.getInstance(context);
dataSource.createDirectMessage(directMessage, currentAccount);
}
}
sharedPrefs.edit().putBoolean("refresh_me", true).commit();
sharedPrefs.edit().putBoolean("refresh_me_dm", true).commit();
if (settings.notifications && settings.dmsNot && inserted > 0) {
int currentUnread = sharedPrefs.getInt("dm_unread_" + currentAccount, 0);
sharedPrefs.edit().putInt("dm_unread_" + currentAccount, numberNew + currentUnread).commit();
NotificationUtils.refreshNotification(context);
}
if (settings.syncSecondMentions) {
startService(new Intent(context, SecondDMRefreshService.class));
}
sendBroadcast(new Intent("com.klinker.android.twitter.NEW_DIRECT_MESSAGE"));
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class PreCacheService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
if (DEBUG) {
Log.v("talon_pre_cache", "starting the service, current time: " + Calendar.getInstance().getTime().toString());
}
// if they want it only over wifi and they are on mobile data
if (getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).getBoolean("pre_cache_wifi_only", false) && Utils.getConnectionStatus(this)) {
if (DEBUG) {
Log.v("talon_pre_cache", "quit for connection");
}
// just quit because we don't want it to happen
return;
}
BitmapLruCache mCache = App.getInstance(this).getBitmapCache();
AppSettings settings = AppSettings.getInstance(this);
Cursor cursor = HomeDataSource.getInstance(this).getUnreadCursor(settings.currentAccount);
if (cursor.moveToFirst()) {
if (DEBUG) {
Log.v("talon_pre_cache", "found database and moved to first picture. cursor size: " + cursor.getCount());
}
boolean cont = true;
do {
String profilePic = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PRO_PIC));
String imageUrl = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PIC_URL));
if (!mCache.contains(profilePic)) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(profilePic).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
if (settings.roundContactImages) {
image = ImageUtils.getCircle(image, this);
}
mCache.put(profilePic, image);
} catch (Throwable e) {
if (DEBUG) {
Log.v("talon_pre_cache", "found an exception while downloading profile pic");
e.printStackTrace();
}
// just stop I guess
cont = false;
}
}
if (!imageUrl.equals("")) {
if (!mCache.contains(imageUrl)) {
try {
if (!imageUrl.contains(" ")) {
HttpURLConnection conn = (HttpURLConnection) new URL(imageUrl).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
mCache.put(imageUrl, image);
} else {
String[] pics = imageUrl.split(" ");
Bitmap[] bitmaps = new Bitmap[pics.length];
// need to download all of them, then combine them
for (int i = 0; i < pics.length; i++) {
String s = pics[i];
// The bitmap isn't cached so download from the web
HttpURLConnection conn = (HttpURLConnection) new URL(s).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
// Add to cache
try {
mCache.put(s, b);
// throw it into our bitmap array for later
bitmaps[i] = b;
} catch (Exception e) {
}
}
// now that we have all of them, we need to put them together
Bitmap combined = ImageUtils.combineBitmaps(this, bitmaps);
try {
mCache.put(imageUrl, combined);
} catch (Exception e) {
}
}
} catch (Throwable e) {
if (DEBUG) {
Log.v("talon_pre_cache", "found an exception while downloading image");
e.printStackTrace();
}
// just stop I guess
cont = false;
}
}
}
} while (cursor.moveToNext() && cont);
if (DEBUG) {
Log.v("talon_pre_cache", "done with service. time: " + Calendar.getInstance().getTime().toString());
}
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class SecondActivityRefreshService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
AppSettings settings = AppSettings.getInstance(this);
ActivityUtils utils = new ActivityUtils(this, true);
if (Utils.getConnectionStatus(this) && !settings.syncMobile) {
return;
}
boolean newActivity = utils.refreshActivity();
if (settings.notifications && settings.activityNot && newActivity) {
utils.postNotification(ActivityUtils.SECOND_NOTIFICATION_ID);
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class SecondMentionsRefreshService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Context context = getApplicationContext();
AppSettings settings = AppSettings.getInstance(context);
// if they have mobile data on and don't want to sync over mobile data
if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
return;
}
boolean update = false;
int numberNew = 0;
try {
Twitter twitter = Utils.getSecondTwitter(context);
int currentAccount = sharedPrefs.getInt("current_account", 1);
if (currentAccount == 1) {
currentAccount = 2;
} else {
currentAccount = 1;
}
MentionsDataSource dataSource = MentionsDataSource.getInstance(context);
long lastId = dataSource.getLastIds(currentAccount)[0];
Paging paging;
paging = new Paging(1, 200);
if (lastId > 0) {
paging.sinceId(lastId);
}
List<Status> statuses = twitter.getMentionsTimeline(paging);
numberNew = MentionsDataSource.getInstance(context).insertTweets(statuses, currentAccount);
if (numberNew > 0) {
sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit();
if (settings.notifications && settings.mentionsNot) {
NotificationUtils.notifySecondMentions(context, currentAccount);
}
sendBroadcast(new Intent("com.klinker.android.twitter.REFRESH_SECOND_MENTIONS"));
}
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class SendQueue method onStartCommand.
@Override
public int onStartCommand(Intent intent, int i, int x) {
Log.v("talon_queued", "starting to send queued tweets");
final Context context = this;
final AppSettings settings = AppSettings.getInstance(this);
try {
if (intent == null) {
return START_NOT_STICKY;
}
} catch (Exception e) {
// null pointer... what the hell...
}
final String[] queued = QueuedDataSource.getInstance(context).getQueuedTweets(AppSettings.getInstance(context).currentAccount);
new Thread(new Runnable() {
@Override
public void run() {
for (String s : queued) {
sendingNotification();
boolean sent = sendTweet(settings, context, s);
if (sent) {
finishedTweetingNotification();
QueuedDataSource.getInstance(context).deleteQueuedTweet(s);
} else {
makeFailedNotification(s, settings);
}
}
stopSelf();
}
}).start();
return START_STICKY;
}
Aggregations