Search in sources :

Example 11 with Mail

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

the class MailsAdapter method findMail.

/**
 * Searches for an equal mail (compares mail id) in the adapter.
 *
 * @return A {@link MailInAdapterResult} containing the information if the adapter contains that
 * mail and at which index position. If the adapter doesn't contain this mail, then the result
 * will contain the index position where the mail would be.
 */
public MailInAdapterResult findMail(Mail mail) {
    int indexPosition = Collections.binarySearch(items, mail, MailComparator.INSTANCE);
    boolean containsMail = false;
    Mail found = null;
    if (indexPosition < 0) {
        indexPosition = ~indexPosition;
    } else {
        found = items.get(indexPosition);
        if (found.getId() == mail.getId()) {
            containsMail = true;
        } else {
            containsMail = false;
            found = null;
        }
    }
    return new MailInAdapterResult(containsMail, found, indexPosition);
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail)

Example 12 with Mail

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

the class DetailsPresenter method markAsRead.

private void markAsRead(final Mail mail) {
    // We assume that this call could never fail
    eventBus.post(new MailReadEvent(mail, true));
    mailProvider.markAsRead(mail, true).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
}
Also used : MailReadEvent(com.hannesdorfmann.mosby3.sample.mail.model.event.MailReadEvent)

Example 13 with Mail

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

the class LabelLayout method init.

private void init() {
    View.inflate(getContext(), R.layout.view_label_layout, this);
    LayoutTransition transition = new LayoutTransition();
    transition.enableTransitionType(LayoutTransition.CHANGING);
    this.setLayoutTransition(transition);
    adapter = new LabelAdapter(getContext());
    popUpWindow = new ListPopupWindow(getContext());
    popUpWindow.setAnchorView(this);
    popUpWindow.setAdapter(adapter);
    popUpWindow.setWidth(DimensUtils.dpToPx(getContext(), 140));
    popUpWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            showLabel();
        }
    });
    popUpWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Label label = (Label) adapter.getItem(position);
            if (!label.getName().equals(mail.getLabel())) {
                presenter.setLabel(mail, label.getName());
                popUpWindow.dismiss();
            }
        }
    });
    setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            loadData(false);
        }
    });
}
Also used : PopupWindow(android.widget.PopupWindow) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Label(com.hannesdorfmann.mosby3.sample.mail.model.mail.Label) LayoutTransition(android.animation.LayoutTransition) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListPopupWindow(android.support.v7.widget.ListPopupWindow) AdapterView(android.widget.AdapterView)

Example 14 with Mail

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

the class WriteActivity method onSendClicked.

@OnClick(R.id.send)
public void onSendClicked() {
    String email = receiver.getText().toString();
    if (TextUtils.isEmpty(email) || !emailPattern.matcher(email).matches()) {
        Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
        receiver.startAnimation(shake);
        return;
    }
    String sub = subject.getText().toString();
    if (TextUtils.isEmpty(sub)) {
        Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
        subject.startAnimation(shake);
        return;
    }
    Person receiver = null;
    if (email.equals(Person.BARNEY.getEmail())) {
        receiver = Person.BARNEY;
    } else if (email.equals(Person.LILY.getEmail())) {
        receiver = Person.LILY;
    } else if (email.equals(Person.MARSHALL.getEmail())) {
        receiver = Person.MARSHALL;
    } else if (email.equals(Person.ROBIN.getEmail())) {
        receiver = Person.ROBIN;
    } else {
        String name = email.split("@")[0];
        receiver = new Person(23, name, email, R.drawable.unknown, null, 0);
    }
    String text = message.getText().toString();
    Mail mail = new Mail().date(new Date()).label(Label.SENT).sender(Person.TED).receiver(receiver).subject(sub).text(text);
    presenter.writeMail(getApplicationContext(), mail);
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) Animation(android.view.animation.Animation) Person(com.hannesdorfmann.mosby3.sample.mail.model.contact.Person) Date(java.util.Date) OnClick(butterknife.OnClick)

Example 15 with Mail

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

the class MailReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_RECEIVE)) {
        Mail mail = intent.getParcelableExtra(EXTRA_MAIL);
        Intent gcmIntent = new Intent(context, GcmFakeIntentService.class);
        gcmIntent.putExtra(GcmFakeIntentService.KEY_MAIL, mail);
        context.startService(gcmIntent);
    }
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) Intent(android.content.Intent)

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