Search in sources :

Example 1 with InboxManager

use of net.dean.jraw.managers.InboxManager in project Slide by ccrama.

the class Inbox method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case (R.id.home):
            onBackPressed();
            break;
        case (R.id.notifs):
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.inboxfrequency, null);
            SettingsGeneral.setupNotificationSettings(dialoglayout, Inbox.this);
            break;
        case (R.id.compose):
            Intent i = new Intent(Inbox.this, SendMessage.class);
            startActivity(i);
            break;
        case (R.id.read):
            changed = false;
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        new InboxManager(Authentication.reddit).setAllRead();
                        changed = true;
                    } catch (Exception ignored) {
                        ignored.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    if (changed) {
                        // restart the fragment
                        adapter.notifyDataSetChanged();
                        try {
                            final int CURRENT_TAB = tabs.getSelectedTabPosition();
                            adapter = new OverviewPagerAdapter(getSupportFragmentManager());
                            pager.setAdapter(adapter);
                            tabs.setupWithViewPager(pager);
                            scrollToTabAfterLayout(CURRENT_TAB);
                            pager.setCurrentItem(CURRENT_TAB);
                        } catch (Exception e) {
                        }
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : InboxManager(net.dean.jraw.managers.InboxManager) LayoutInflater(android.view.LayoutInflater) Intent(android.content.Intent) View(android.view.View)

Example 2 with InboxManager

use of net.dean.jraw.managers.InboxManager in project Slide by ccrama.

the class MarkAsReadService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.cancel(intent.getIntExtra(NOTIFICATION_ID, -1));
    String[] messages = null;
    Bundle extras = intent.getExtras();
    if (extras != null)
        messages = extras.getStringArray(CheckForMail.MESSAGE_EXTRA);
    InboxManager inboxManager = new InboxManager(Authentication.reddit);
    if (messages != null && NetworkUtil.isConnected(getBaseContext())) {
        for (String message : messages) {
            try {
                inboxManager.setRead(message, true);
            } catch (NetworkException e) {
                e.printStackTrace();
                return;
            }
        }
    }
}
Also used : InboxManager(net.dean.jraw.managers.InboxManager) NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) NetworkException(net.dean.jraw.http.NetworkException)

Aggregations

InboxManager (net.dean.jraw.managers.InboxManager)2 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 NetworkException (net.dean.jraw.http.NetworkException)1