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