use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class SendScheduledTweet method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
Log.v("talon_scheduled_tweet", "started service");
final String text = intent.getStringExtra(ViewScheduledTweets.EXTRA_TEXT);
final int account = intent.getIntExtra("account", 1);
final int alarmId = intent.getIntExtra("alarm_id", 0);
final Context context = this;
final AppSettings settings = AppSettings.getInstance(context);
new Thread(new Runnable() {
@Override
public void run() {
sendingNotification();
boolean sent = sendTweet(settings, context, text, account);
if (sent) {
finishedTweetingNotification();
QueuedDataSource.getInstance(context).deleteScheduledTweet(alarmId);
} else {
makeFailedNotification(text, settings);
}
}
}).start();
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class ViewUsersPopup method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);
Utils.setUpPopupTheme(this, AppSettings.getInstance(this));
setUpWindow();
setContentView(R.layout.search_pager);
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setPadding(0, 0, 0, 0);
UserListPagerAdapter adapter = new UserListPagerAdapter(getFragmentManager(), this, getIntent().getLongExtra("id", 0l));
mViewPager.setAdapter(adapter);
mViewPager.setOffscreenPageLimit(2);
AppSettings settings = AppSettings.getInstance(this);
if (settings.addonTheme) {
PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
strip.setBackgroundColor(settings.pagerTitleInt);
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class IOUtils method trimDatabase.
public static boolean trimDatabase(Context context, int account) {
try {
AppSettings settings = AppSettings.getInstance(context);
SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
InteractionsDataSource interactions = InteractionsDataSource.getInstance(context);
Cursor inters = interactions.getCursor(account);
if (inters.getCount() > 50) {
if (inters.moveToPosition(inters.getCount() - 50)) {
do {
interactions.deleteInteraction(inters.getLong(inters.getColumnIndex(InteractionsSQLiteHelper.COLUMN_ID)));
} while (inters.moveToPrevious());
}
}
inters.close();
HomeDataSource home = HomeDataSource.getInstance(context);
home.deleteDups(settings.currentAccount);
Cursor timeline = home.getTrimmingCursor(account);
Log.v("trimming", "timeline size: " + timeline.getCount());
Log.v("trimming", "timeline settings size: " + settings.timelineSize);
if (timeline.getCount() > settings.timelineSize) {
if (timeline.moveToPosition(timeline.getCount() - settings.timelineSize)) {
Log.v("trimming", "in the trim section");
do {
home.deleteTweet(timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
} while (timeline.moveToPrevious());
}
}
timeline.close();
// trimming the lists
ListDataSource lists = ListDataSource.getInstance(context);
int account1List1 = sharedPrefs.getInt("account_" + account + "_list_1", 0);
int account1List2 = sharedPrefs.getInt("account_" + account + "_list_2", 0);
lists.deleteDups(account1List1);
lists.deleteDups(account1List2);
Cursor list1 = lists.getTrimmingCursor(account1List1);
Log.v("trimming", "lists size: " + list1.getCount());
Log.v("trimming", "lists settings size: " + 400);
if (list1.getCount() > 400) {
if (list1.moveToPosition(list1.getCount() - 400)) {
Log.v("trimming", "in the trim section");
do {
lists.deleteTweet(list1.getLong(list1.getColumnIndex(ListSQLiteHelper.COLUMN_TWEET_ID)));
} while (list1.moveToPrevious());
}
}
list1.close();
Cursor list2 = lists.getTrimmingCursor(account1List2);
Log.v("trimming", "lists size: " + list2.getCount());
Log.v("trimming", "lists settings size: " + 400);
if (list2.getCount() > 400) {
if (list2.moveToPosition(list2.getCount() - 400)) {
Log.v("trimming", "in the trim section");
do {
lists.deleteTweet(list2.getLong(list2.getColumnIndex(ListSQLiteHelper.COLUMN_TWEET_ID)));
} while (list2.moveToPrevious());
}
}
list2.close();
MentionsDataSource mentions = MentionsDataSource.getInstance(context);
mentions.deleteDups(settings.currentAccount);
timeline = mentions.getTrimmingCursor(account);
Log.v("trimming", "mentions size: " + timeline.getCount());
Log.v("trimming", "mentions settings size: " + settings.mentionsSize);
if (timeline.getCount() > settings.mentionsSize) {
if (timeline.moveToPosition(timeline.getCount() - settings.mentionsSize)) {
do {
mentions.deleteTweet(timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
} while (timeline.moveToPrevious());
}
}
timeline.close();
DMDataSource dm = DMDataSource.getInstance(context);
dm.deleteDups(settings.currentAccount);
timeline = dm.getCursor(account);
Log.v("trimming", "dm size: " + timeline.getCount());
Log.v("trimming", "dm settings size: " + settings.dmSize);
if (timeline.getCount() > settings.dmSize) {
if (timeline.moveToPosition(timeline.getCount() - settings.dmSize)) {
do {
dm.deleteTweet(timeline.getLong(timeline.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)));
} while (timeline.moveToPrevious());
}
}
timeline.close();
HashtagDataSource hashtag = HashtagDataSource.getInstance(context);
timeline = hashtag.getCursor("");
Log.v("trimming", "hashtag size: " + timeline.getCount());
if (timeline.getCount() > 300) {
if (timeline.moveToPosition(timeline.getCount() - 300)) {
do {
hashtag.deleteTag(timeline.getString(timeline.getColumnIndex(HashtagSQLiteHelper.COLUMN_TAG)));
} while (timeline.moveToPrevious());
}
}
timeline.close();
ActivityDataSource activity = ActivityDataSource.getInstance(context);
Cursor actCurs = activity.getCursor(account);
Log.v("trimming", "activity size: " + actCurs.getCount());
Log.v("trimming", "activity settings size: " + 200);
if (actCurs.getCount() > 200) {
int toDelete = actCurs.getCount() - 200;
if (actCurs.moveToFirst()) {
do {
activity.deleteItem(actCurs.getLong(actCurs.getColumnIndex(ActivitySQLiteHelper.COLUMN_ID)));
toDelete--;
} while (timeline.moveToNext() && toDelete > 0);
}
}
actCurs.close();
FavoriteTweetsDataSource favtweets = FavoriteTweetsDataSource.getInstance(context);
favtweets.deleteDups(settings.currentAccount);
timeline = favtweets.getCursor(account);
Log.v("trimming", "favtweets size: " + timeline.getCount());
Log.v("trimming", "favtweets settings size: " + 200);
if (timeline.getCount() > 200) {
if (timeline.moveToPosition(timeline.getCount() - 200)) {
do {
favtweets.deleteTweet(timeline.getLong(timeline.getColumnIndex(FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID)));
} while (timeline.moveToPrevious());
}
}
timeline.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class NotificationUtils method getMentionsInboxStyle.
private static NotificationCompat.InboxStyle getMentionsInboxStyle(int numberNew, int accountNumber, Context context, String title) {
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
Cursor cursor = MentionsDataSource.getInstance(context).getCursor(accountNumber);
if (!cursor.moveToLast()) {
return style;
}
AppSettings settings = AppSettings.getInstance(context);
if (numberNew > 5) {
if (numberNew - 5 == 1) {
style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mention));
} else {
style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mentions));
}
for (int i = 0; i < 5; i++) {
String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
String longText = "<b>@" + handle + "</b>: " + text;
style.addLine(Html.fromHtml(settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));
cursor.moveToPrevious();
}
} else {
for (int i = 0; i < numberNew; i++) {
String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
String longText = "<b>@" + handle + "</b>: " + text;
style.addLine(Html.fromHtml(settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));
cursor.moveToPrevious();
}
}
style.setBigContentTitle(title);
return style;
}
use of com.klinker.android.twitter.settings.AppSettings in project Talon-for-Twitter by klinker24.
the class NotificationUtils method notifySecondMentions.
public static void notifySecondMentions(Context context, int secondAccount) {
MentionsDataSource data = MentionsDataSource.getInstance(context);
int numberNew = data.getUnreadCount(secondAccount);
int smallIcon = R.drawable.ic_stat_icon;
Bitmap largeIcon;
Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
NotificationCompat.Builder mBuilder;
String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc);
;
String name = null;
String message;
String messageLong;
String tweetText = null;
NotificationCompat.Action replyAction = null;
if (numberNew == 1) {
name = data.getNewestName(secondAccount);
SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
// then just quit
if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) {
return;
}
message = context.getResources().getString(R.string.mentioned_by) + " @" + name;
tweetText = data.getNewestMessage(secondAccount);
messageLong = "<b>@" + name + "</b>: " + tweetText;
largeIcon = getImage(context, name);
Intent reply = new Intent(context, NotificationComposeSecondAcc.class);
sharedPrefs.edit().putString("from_notification_second", "@" + name).commit();
long id = data.getLastIds(secondAccount)[0];
PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
sharedPrefs.edit().putLong("from_notification_long_second", id).commit();
sharedPrefs.edit().putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))).commit();
// Create the remote input
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build();
// Create the notification action
replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
} else {
// more than one mention
message = numberNew + " " + context.getResources().getString(R.string.new_mentions);
messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions);
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
}
Intent markRead = new Intent(context, MarkReadSecondAccService.class);
PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
AppSettings settings = AppSettings.getInstance(context);
Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class);
mBuilder = new NotificationCompat.Builder(context, TALON_SERVICE_CHANNEL_ID).setContentTitle(title).setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon).setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
if (numberNew == 1) {
mBuilder.addAction(replyAction);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong)));
} else {
NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings));
mBuilder.setStyle(inbox);
}
if (settings.vibrate) {
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
}
if (settings.sound) {
try {
mBuilder.setSound(Uri.parse(settings.ringtone));
} catch (Exception e) {
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
}
}
if (settings.led)
mBuilder.setLights(0xFFFFFF, 1000, 1000);
if (settings.notifications) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(9, mBuilder.build());
// if we want to wake the screen on a new message
if (settings.wakeScreen) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
wakeLock.acquire(5000);
}
// Pebble notification
if (context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).getBoolean("pebble_notification", false)) {
sendAlertToPebble(context, title, messageLong);
}
// Light Flow notification
sendToLightFlow(context, title, messageLong);
}
}
Aggregations