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();
}
}
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;
}
Aggregations