Search in sources :

Example 1 with I2PBote

use of i2p.bote.I2PBote in project i2p.i2p-bote by i2p.

the class EmailListFragment method onRefresh.

// SwipeRefreshLayout.OnRefreshListener
public void onRefresh() {
    // If we are already checking, do nothing else
    if (mCheckingTask != null)
        return;
    I2PBote bote = I2PBote.getInstance();
    if (bote.isConnected()) {
        try {
            if (!bote.isCheckingForMail())
                bote.checkForMail();
            mCheckingTask = new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    while (I2PBote.getInstance().isCheckingForMail()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                        }
                        if (isCancelled()) {
                            break;
                        }
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    super.onPostExecute(result);
                    mAdapter.setIncompleteEmails(I2PBote.getInstance().getNumIncompleteEmails());
                    // Notify PullToRefreshLayout that the refresh has finished
                    mSwipeRefreshLayout.setRefreshing(false);
                    getActivity().supportInvalidateOptionsMenu();
                }
            };
            mCheckingTask.execute();
        } catch (PasswordException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        mSwipeRefreshLayout.setRefreshing(false);
        Toast.makeText(getActivity(), R.string.bote_needs_to_be_connected, Toast.LENGTH_SHORT).show();
    }
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) I2PBote(i2p.bote.I2PBote) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 2 with I2PBote

use of i2p.bote.I2PBote in project i2p.i2p-bote by i2p.

the class BoteService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    mRouterChoice = (RouterChoice) intent.getSerializableExtra(ROUTER_CHOICE);
    if (mRouterChoice == RouterChoice.INTERNAL)
        new Thread(new RouterStarter()).start();
    I2PBote bote = I2PBote.getInstance();
    if (mRouterChoice == RouterChoice.ANDROID) {
        bote.getConfiguration().setI2CPDomainSocket(DomainSocketFactory.I2CP_SOCKET_ADDRESS);
    }
    bote.startUp();
    bote.addNewEmailListener(this);
    if (mRouterChoice == RouterChoice.ANDROID) {
        // Bind to I2P Android
        mTriedBindState = (new I2PAndroidHelper(this)).bind(mStateConnection, 0);
    } else if (mRouterChoice == RouterChoice.REMOTE)
        bote.connectNow();
    mStatusBuilder = new NotificationCompat.Builder(this).setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.drawable.ic_notif).setOngoing(true).setOnlyAlertOnce(true);
    Intent ni = new Intent(this, EmailListActivity.class);
    ni.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(this, 0, ni, PendingIntent.FLAG_UPDATE_CURRENT);
    mStatusBuilder.setContentIntent(pi);
    updateServiceNotifText();
    startForeground(NOTIF_ID_SERVICE, mStatusBuilder.build());
    bote.addNetworkStatusListener(this);
    return START_REDELIVER_INTENT;
}
Also used : I2PBote(i2p.bote.I2PBote) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) I2PAndroidHelper(net.i2p.android.ui.I2PAndroidHelper)

Aggregations

I2PBote (i2p.bote.I2PBote)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 I2PAndroidHelper (net.i2p.android.ui.I2PAndroidHelper)1