Search in sources :

Example 1 with InteractionsDataSource

use of com.klinker.android.twitter.data.sq_lite.InteractionsDataSource in project Talon-for-Twitter by klinker24.

the class InteractionClickListener method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    HoloTextView title = (HoloTextView) view.findViewById(R.id.title);
    String mTitle = title.getText().toString();
    HoloTextView text = (HoloTextView) view.findViewById(R.id.text);
    String mText = text.getText().toString();
    // get the datasource ready to read/write
    InteractionsDataSource data = InteractionsDataSource.getInstance(context);
    if (mTitle.contains(context.getResources().getString(R.string.mentioned_by))) {
        // this is a mention
        if (MainDrawerArrayAdapter.current < 3) {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    try {
                        drawer.closeDrawer(Gravity.END);
                    } catch (Exception e) {
                    // landscape mode
                    }
                }
            }, 300);
            viewPager.setCurrentItem((mentionsPage), true);
        } else {
            final int pos = i;
            try {
                drawer.closeDrawer(Gravity.END);
            } catch (Exception e) {
            // landscape mode
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    Intent intent = new Intent(context, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    intent.putExtra("page_to_open", mentionsPage);
                    intent.putExtra("from_drawer", true);
                    sharedPreferences.edit().putBoolean("should_refresh", false).commit();
                    try {
                        Thread.sleep(400);
                    } catch (Exception e) {
                    }
                    try {
                        context.startActivity(intent);
                        ((Activity) context).overridePendingTransition(0, 0);
                        ((Activity) context).finish();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    } else if (mTitle.contains(context.getResources().getString(R.string.retweeted)) || mTitle.contains(context.getResources().getString(R.string.favorited)) || mTitle.contains(context.getResources().getString(R.string.quoted)) || mTitle.contains(context.getResources().getString(R.string.new_favorites)) || mTitle.contains(context.getResources().getString(R.string.new_retweets)) || mTitle.contains(context.getResources().getString(R.string.new_quotes))) {
        try {
            drawer.closeDrawer(Gravity.END);
        } catch (Exception e) {
        // landscape mode
        }
        // open up the dialog with the users that retweeted it
        final String[] fItems = data.getUsers(sharedPreferences.getInt("current_account", 1), i, DrawerActivity.oldInteractions.getText().toString().equals(context.getResources().getString(R.string.old_interactions))).split(" ");
        LayoutInflater factory = LayoutInflater.from(context);
        View content = factory.inflate(R.layout.interaction_dialog, null);
        TextView textView = (TextView) content.findViewById(R.id.text);
        textView.setText(mText);
        ListView lv = (ListView) content.findViewById(R.id.list);
        lv.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_selectable_list_item, fItems));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
                String touched = fItems[item];
                Intent user = new Intent(context, ProfilePager.class);
                user.putExtra("screenname", touched.replace("@", "").replace(" ", ""));
                user.putExtra("proPic", "");
                context.startActivity(user);
            }
        });
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(content);
        AlertDialog alert = builder.create();
        alert.show();
    } else if (mTitle.contains(context.getResources().getString(R.string.followed))) {
        try {
            drawer.closeDrawer(Gravity.END);
        } catch (Exception e) {
        // landscape mode
        }
        // a new follower, open up the followers profile
        String username = mTitle.substring(mTitle.indexOf("@") + 1, mTitle.indexOf(" "));
        Intent user = new Intent(context, ProfilePager.class);
        user.putExtra("screenname", username);
        user.putExtra("proPic", "");
        context.startActivity(user);
    } else if (mTitle.contains(context.getResources().getString(R.string.tweeted))) {
        try {
            drawer.closeDrawer(Gravity.END);
        } catch (Exception e) {
        // landscape mode
        }
        // a new follower, open up the followers profile
        String username = mTitle.substring(mTitle.indexOf("@") + 1, mTitle.indexOf(" "));
        Intent user = new Intent(context, ProfilePager.class);
        user.putExtra("screenname", username);
        user.putExtra("proPic", "");
        context.startActivity(user);
    }
    // mark it read in the sql database
    data.markRead(sharedPreferences.getInt("current_account", 1), i);
    // tell the system to refresh the notifications when the user opens the drawer again
    sharedPreferences.edit().putBoolean("new_notification", true).commit();
}
Also used : AlertDialog(android.app.AlertDialog) Handler(android.os.Handler) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) MainActivity(com.klinker.android.twitter.activities.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent) HoloTextView(com.klinker.android.twitter.views.HoloTextView) HoloTextView(com.klinker.android.twitter.views.HoloTextView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) InteractionsDataSource(com.klinker.android.twitter.data.sq_lite.InteractionsDataSource) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) ProfilePager(com.klinker.android.twitter.activities.profile_viewer.ProfilePager) HoloTextView(com.klinker.android.twitter.views.HoloTextView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) MainDrawerArrayAdapter(com.klinker.android.twitter.adapters.MainDrawerArrayAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with InteractionsDataSource

use of com.klinker.android.twitter.data.sq_lite.InteractionsDataSource 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;
    }
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) Cursor(android.database.Cursor) MentionsDataSource(com.klinker.android.twitter.data.sq_lite.MentionsDataSource) ListDataSource(com.klinker.android.twitter.data.sq_lite.ListDataSource) DMDataSource(com.klinker.android.twitter.data.sq_lite.DMDataSource) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FavoriteTweetsDataSource(com.klinker.android.twitter.data.sq_lite.FavoriteTweetsDataSource) InteractionsDataSource(com.klinker.android.twitter.data.sq_lite.InteractionsDataSource) ActivityDataSource(com.klinker.android.twitter.data.sq_lite.ActivityDataSource) HomeDataSource(com.klinker.android.twitter.data.sq_lite.HomeDataSource)

Aggregations

InteractionsDataSource (com.klinker.android.twitter.data.sq_lite.InteractionsDataSource)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Handler (android.os.Handler)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 MainActivity (com.klinker.android.twitter.activities.MainActivity)1 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)1 ProfilePager (com.klinker.android.twitter.activities.profile_viewer.ProfilePager)1 MainDrawerArrayAdapter (com.klinker.android.twitter.adapters.MainDrawerArrayAdapter)1 ActivityDataSource (com.klinker.android.twitter.data.sq_lite.ActivityDataSource)1 DMDataSource (com.klinker.android.twitter.data.sq_lite.DMDataSource)1 FavoriteTweetsDataSource (com.klinker.android.twitter.data.sq_lite.FavoriteTweetsDataSource)1