Search in sources :

Example 1 with Mail

use of com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail in project mosby by sockeqwe.

the class RandomMailGenerator method generateResponseMail.

@Override
public Mail generateResponseMail(String senderMail) {
    String[] quotes = null;
    Person sender = null;
    if (senderMail.equals(Person.BARNEY.getEmail())) {
        sender = Person.BARNEY;
        quotes = barneyQuotes;
    } else if (senderMail.equals(Person.LILY.getEmail())) {
        quotes = lilyQuotes;
        sender = Person.LILY;
    } else if (senderMail.equals(Person.MARSHALL.getEmail())) {
        quotes = marshallQuotes;
        sender = Person.MARSHALL;
    } else if (senderMail.equals(Person.ROBIN.getEmail())) {
        quotes = robinQuotes;
        sender = Person.ROBIN;
    } else {
        return null;
    }
    return new Mail().id(0).date(new Date()).read(false).receiver(Person.TED).sender(sender).subject(randomString(subjects)).text(generateMsg(quotes));
}
Also used : Person(com.hannesdorfmann.mosby3.sample.mail.model.contact.Person) Date(java.util.Date)

Example 2 with Mail

use of com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail in project mosby by sockeqwe.

the class RandomMailGenerator method generateMails.

@Override
public List<Mail> generateMails() {
    int id = 0;
    int mailSize = 50;
    List<Mail> mails = new ArrayList<>(mailSize);
    long day = 24 * 60 * 60 * 1000;
    long timestamp = System.currentTimeMillis();
    for (int i = 0; i < mailSize; i++, timestamp -= day) {
        String[] quotes = barneyQuotes;
        Person sender = Person.BARNEY;
        switch(i % 5) {
            case 1:
                sender = Person.LILY;
                quotes = lilyQuotes;
                break;
            case 3:
                sender = Person.MARSHALL;
                quotes = marshallQuotes;
                break;
            case 4:
                sender = Person.ROBIN;
                quotes = robinQuotes;
                break;
            default:
                // 0 and 2 is barney
                break;
        }
        String label;
        if (i < 40) {
            label = Label.INBOX;
        } else if (i < 45) {
            label = Label.SPAM;
        } else {
            label = Label.TRASH;
        }
        mails.add(new Mail().id(id++).date(new Date(timestamp)).label(label).read((i % 6) != random.nextInt(6)).receiver(Person.TED).sender(sender).subject(randomString(subjects)).text(generateMsg(quotes)));
    }
    /*
    // SENT
    Person[] receiver = { barney, marshall, lily, robin };
    for (int i = 0; i < 10; i++, timestamp -= day) {
      mails.add(new Mail().id(id++)
          .date(new Date(timestamp))
          .label(Label.SENT)
          .read(true)
          .receiver(receiver[randomIndex(receiver)])
          .sender(ted)
          .subject("RE: " + randomString(subjects))
          .text(generateMsg(tedQuotes)));
    }
    */
    return mails;
}
Also used : ArrayList(java.util.ArrayList) Person(com.hannesdorfmann.mosby3.sample.mail.model.contact.Person) Date(java.util.Date)

Example 3 with Mail

use of com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail in project mosby by sockeqwe.

the class SendMailService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    final Mail mail = intent.getParcelableExtra(KEY_MAIL);
    mail.label(Label.SENT);
    mailProvider.addMailWithDelay(mail).subscribe(new Subscriber<Mail>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            eventBus.post(new MailSentErrorEvent(mail, e));
        }

        @Override
        public void onNext(Mail mail) {
            eventBus.post(new MailSentEvent(mail));
            generateResponse(mail);
        }
    });
}
Also used : MailSentEvent(com.hannesdorfmann.mosby3.sample.mail.model.event.MailSentEvent) Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) MailSentErrorEvent(com.hannesdorfmann.mosby3.sample.mail.model.event.MailSentErrorEvent)

Example 4 with Mail

use of com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail in project mosby by sockeqwe.

the class SendMailService method generateResponse.

private void generateResponse(Mail mail) {
    Mail response = generator.generateResponseMail(mail.getReceiver().getEmail());
    if (response != null) {
        response.subject("RE: " + mail.getSubject());
        Intent gcmIntent = new Intent();
        gcmIntent.setAction(MailReceiver.ACTION_RECEIVE);
        gcmIntent.putExtra(MailReceiver.EXTRA_MAIL, response);
        sendBroadcast(gcmIntent);
    }
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) Intent(android.content.Intent)

Example 5 with Mail

use of com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail in project mosby by sockeqwe.

the class MainActivity method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    String showAction = intent.getStringExtra(KEY_SHOW_ACTION);
    if (KEY_SHOW_ACTION_MAIL_DETAILS.equals(showAction)) {
        Mail mail = intent.getParcelableExtra(KEY_DATA_MAIL_DETAILS);
        showMail(mail);
    } else if (KEY_SHOW_ACTION_MAILS_OF_LABEL.equals(showAction)) {
        Label label = intent.getParcelableExtra(KEY_DATA_MAILS_OF_LABEL);
        showMails(label, true);
    }
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) Label(com.hannesdorfmann.mosby3.sample.mail.model.mail.Label)

Aggregations

Mail (com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail)13 Person (com.hannesdorfmann.mosby3.sample.mail.model.contact.Person)5 View (android.view.View)4 Intent (android.content.Intent)3 BindView (butterknife.BindView)3 Date (java.util.Date)3 TextView (android.widget.TextView)2 MailsAdapter (com.hannesdorfmann.mosby3.sample.mail.mails.MailsAdapter)2 Label (com.hannesdorfmann.mosby3.sample.mail.model.mail.Label)2 LayoutTransition (android.animation.LayoutTransition)1 TargetApi (android.annotation.TargetApi)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 Animation (android.view.animation.Animation)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 PopupWindow (android.widget.PopupWindow)1 OnClick (butterknife.OnClick)1