Search in sources :

Example 1 with EmailFolder

use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.

the class EmailListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Set the action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    setSupportActionBar(toolbar);
    // Initialize variables
    mHelper = new I2PAndroidHelper(this);
    mSharedPrefs = getSharedPreferences(Constants.SHARED_PREFS, 0);
    mAccountHeader = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.drawer_header_background).withSelectionListEnabledForSingleProfile(false).addProfiles(getLockedProfile()).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {

        @Override
        public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
            if (profile.getIdentifier() == ID_LOCKED)
                findViewById(R.id.action_log_in).performClick();
            else if (!currentProfile)
                identitySelected(profile);
            return false;
        }
    }).withSavedInstance(savedInstanceState).build();
    IDrawerItem addressBook = new PrimaryDrawerItem().withIdentifier(ID_ADDRESS_BOOK).withName(R.string.address_book).withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_contacts).colorRes(R.color.md_grey_600).sizeDp(24)).withIconTintingEnabled(true).withSelectedIconColorRes(R.color.primary);
    IDrawerItem networkStatus = getNetStatusItem(R.string.network_status, GoogleMaterial.Icon.gmd_cloud_off, R.color.md_grey_600, 0);
    // Set the drawer width per Material design spec
    // http://www.google.com/design/spec/layout/structure.html#structure-side-nav-1
    // Mobile: side nav width = min(screen width - app bar height, 320dp)
    // Desktop: side nav width = min(screen width - app bar height, 400dp)
    int maxWidth = getResources().getDimensionPixelSize(R.dimen.nav_max_width);
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int drawerWidth = Math.min(dm.widthPixels - toolbar.getLayoutParams().height, maxWidth);
    mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withDrawerWidthPx(drawerWidth).withShowDrawerOnFirstLaunch(true).withAccountHeader(mAccountHeader).addStickyDrawerItems(addressBook, networkStatus).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
            long id = iDrawerItem.getIdentifier();
            if (id == ID_ADDRESS_BOOK) {
                mDrawer.setSelection(mSelected, false);
                mDrawer.closeDrawer();
                Intent ai = new Intent(EmailListActivity.this, AddressBookActivity.class);
                startActivity(ai);
                return true;
            } else if (id == ID_NET_STATUS) {
                mDrawer.setSelection(mSelected, false);
                netStatusSelected();
                return true;
            } else {
                drawerFolderSelected((EmailFolder) iDrawerItem.getTag(), mSelected == i);
                mSelected = mDrawer.getCurrentSelection();
                return false;
            }
        }
    }).withSavedInstance(savedInstanceState).build();
    mSelected = mDrawer.getCurrentSelection();
    // Enable ActionBar app icon to behave as action to toggle nav drawer
    // noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    mDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
    if (savedInstanceState == null) {
        EmailListFragment f = EmailListFragment.newInstance("inbox");
        getSupportFragmentManager().beginTransaction().add(R.id.list_fragment, f).commit();
    }
    // If first start, go to introduction and setup wizard
    if (mSharedPrefs.getBoolean(PREF_FIRST_START, true)) {
        mSharedPrefs.edit().putBoolean(PREF_FIRST_START, false).apply();
        Intent i = new Intent(EmailListActivity.this, IntroActivity.class);
        startActivityForResult(i, SHOW_INTRODUCTION);
    }
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) I2PAndroidHelper(net.i2p.android.ui.I2PAndroidHelper) View(android.view.View) AdapterView(android.widget.AdapterView) DisplayMetrics(android.util.DisplayMetrics) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Toolbar(android.support.v7.widget.Toolbar) EmailFolder(i2p.bote.folder.EmailFolder)

Example 2 with EmailFolder

use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.

the class BoteService method emailReceived.

// NewEmailListener
@Override
public void emailReceived(String messageId) {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder b = new NotificationCompat.Builder(this).setAutoCancel(true).setSmallIcon(R.drawable.ic_notif).setDefaults(Notification.DEFAULT_ALL);
    try {
        EmailFolder inbox = I2PBote.getInstance().getInbox();
        // Set the new email as \Recent
        inbox.setRecent(messageId, true);
        // Now display/update notification with all \Recent emails
        List<Email> newEmails = BoteHelper.getRecentEmails(inbox);
        int numNew = newEmails.size();
        switch(numNew) {
            case 0:
                nm.cancel(NOTIF_ID_NEW_EMAIL);
                return;
            case 1:
                Email email = newEmails.get(0);
                String fromAddress = email.getOneFromAddress();
                Bitmap picture = BoteHelper.getPictureForAddress(fromAddress);
                if (picture != null)
                    b.setLargeIcon(picture);
                else if (!email.isAnonymous()) {
                    int width = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_width);
                    int height = getResources().getDimensionPixelSize(R.dimen.notification_large_icon_height);
                    b.setLargeIcon(BoteHelper.getIdenticonForAddress(fromAddress, width, height));
                } else
                    b.setSmallIcon(R.drawable.ic_contact_picture);
                b.setContentTitle(BoteHelper.getNameAndShortDestination(fromAddress));
                b.setContentText(email.getSubject());
                Intent vei = new Intent(this, ViewEmailActivity.class);
                vei.putExtra(ViewEmailActivity.FOLDER_NAME, inbox.getName());
                vei.putExtra(ViewEmailActivity.MESSAGE_ID, email.getMessageID());
                vei.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent pvei = PendingIntent.getActivity(this, 0, vei, PendingIntent.FLAG_UPDATE_CURRENT);
                b.setContentIntent(pvei);
                break;
            default:
                b.setContentTitle(getResources().getQuantityString(R.plurals.n_new_emails, numNew, numNew));
                HashSet<Address> recipients = new HashSet<Address>();
                String bigText = "";
                for (Email ne : newEmails) {
                    recipients.add(BoteHelper.getOneLocalRecipient(ne));
                    bigText += BoteHelper.getNameAndShortDestination(ne.getOneFromAddress());
                    bigText += ": " + ne.getSubject() + "\n";
                }
                b.setContentText(BoteHelper.joinAddressNames(recipients));
                b.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
                Intent eli = new Intent(this, EmailListActivity.class);
                eli.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent peli = PendingIntent.getActivity(this, 0, eli, PendingIntent.FLAG_UPDATE_CURRENT);
                b.setContentIntent(peli);
        }
    } catch (PasswordException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException 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();
    }
    nm.notify(NOTIF_ID_NEW_EMAIL, b.build());
}
Also used : Email(i2p.bote.email.Email) NotificationManager(android.app.NotificationManager) Address(javax.mail.Address) MessagingException(javax.mail.MessagingException) GeneralSecurityException(java.security.GeneralSecurityException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) PasswordException(i2p.bote.fileencryption.PasswordException) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) EmailFolder(i2p.bote.folder.EmailFolder) HashSet(java.util.HashSet)

Example 3 with EmailFolder

use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.

the class MapperFactory method getMailboxes.

/**
 * Maps mailbox names to mailboxes.
 */
private Map<String, BoteMailbox> getMailboxes() {
    // XXX: When user folders are set up, this will need to be updated.
    if (mailboxes.isEmpty()) {
        for (EmailFolder folder : folderManager.getEmailFolders()) {
            String folderName = folder.getName().toLowerCase();
            mailboxes.put(folderName, new BoteMailbox(folder, uidValidity, MessageUid.MIN_VALUE));
        }
    }
    return mailboxes;
}
Also used : EmailFolder(i2p.bote.folder.EmailFolder)

Example 4 with EmailFolder

use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.

the class I2PBote method initializeFolderAccess.

/**
 * Initializes objects for accessing emails and packet files on the filesystem.
 * @param passwordCache
 */
private void initializeFolderAccess(PasswordCache passwordCache) {
    inbox = new EmailFolder(configuration.getInboxDir(), passwordCache);
    outbox = new Outbox(configuration.getOutboxDir(), passwordCache);
    sentFolder = new EmailFolder(configuration.getSentFolderDir(), passwordCache);
    trashFolder = new TrashFolder(configuration.getTrashFolderDir(), passwordCache);
    relayPacketFolder = new RelayPacketFolder(configuration.getRelayPacketDir());
    MessageIdCache messageIdCache = new MessageIdCache(configuration.getMessageIdCacheFile(), configuration.getMessageIdCacheSize());
    incompleteEmailFolder = new IncompleteEmailFolder(configuration.getIncompleteDir(), messageIdCache, inbox);
    emailDhtStorageFolder = new EmailPacketFolder(configuration.getEmailDhtStorageDir());
    indexPacketDhtStorageFolder = new IndexPacketFolder(configuration.getIndexPacketDhtStorageDir());
    directoryDhtFolder = new DirectoryEntryFolder(configuration.getDirectoryEntryDhtStorageDir());
}
Also used : RelayPacketFolder(i2p.bote.folder.RelayPacketFolder) IncompleteEmailFolder(i2p.bote.folder.IncompleteEmailFolder) Outbox(i2p.bote.folder.Outbox) TrashFolder(i2p.bote.folder.TrashFolder) DirectoryEntryFolder(i2p.bote.folder.DirectoryEntryFolder) EmailPacketFolder(i2p.bote.folder.EmailPacketFolder) MessageIdCache(i2p.bote.folder.MessageIdCache) IndexPacketFolder(i2p.bote.folder.IndexPacketFolder) EmailFolder(i2p.bote.folder.EmailFolder) IncompleteEmailFolder(i2p.bote.folder.IncompleteEmailFolder)

Example 5 with EmailFolder

use of i2p.bote.folder.EmailFolder in project i2p.i2p-bote by i2p.

the class AttachmentProviderTests method tearDown.

@After
public void tearDown() throws Exception {
    super.tearDown();
    EmailFolder inbox = I2PBote.getInstance().getInbox();
    for (Email email : BoteHelper.getEmails(inbox, null, true)) {
        inbox.delete(email.getMessageID());
    }
    System.setProperty("i2pbote.initialized", "false");
}
Also used : Email(i2p.bote.email.Email) EmailFolder(i2p.bote.folder.EmailFolder) After(org.junit.After)

Aggregations

EmailFolder (i2p.bote.folder.EmailFolder)8 Intent (android.content.Intent)2 Email (i2p.bote.email.Email)2 IncompleteEmailFolder (i2p.bote.folder.IncompleteEmailFolder)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Bitmap (android.graphics.Bitmap)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Toolbar (android.support.v7.widget.Toolbar)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)1 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)1 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)1 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)1 DerivedKey (i2p.bote.fileencryption.DerivedKey)1 PasswordException (i2p.bote.fileencryption.PasswordException)1