Search in sources :

Example 1 with Reaction

use of com.meisolsson.githubsdk.model.Reaction in project gh4a by slapperwan.

the class ReactionBar method toggleReaction.

private static Single<Optional<Reaction>> toggleReaction(String content, long id, List<Reaction> existingDetails, Callback callback, Item item, ReactionDetailsCache cache) {
    final Single<Optional<Reaction>> resultSingle;
    if (id == 0) {
        resultSingle = callback.addReaction(item, content).map(Optional::of);
    } else {
        ReactionService service = ServiceFactory.get(ReactionService.class, false);
        resultSingle = service.deleteReaction(id).map(response -> Optional.absent());
    }
    return resultSingle.compose(RxUtils::doInBackground).doOnSuccess(reactionOpt -> {
        if (reactionOpt.isPresent()) {
            existingDetails.add(reactionOpt.get());
        } else {
            for (int i = 0; i < existingDetails.size(); i++) {
                Reaction reaction = existingDetails.get(i);
                if (reaction.id() == id) {
                    existingDetails.remove(i);
                    break;
                }
            }
        }
        cache.putEntry(item, existingDetails);
    });
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) MenuBuilder(android.support.v7.view.menu.MenuBuilder) DrawableCompat(android.support.v4.graphics.drawable.DrawableCompat) ImageView(android.widget.ImageView) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) Drawable(android.graphics.drawable.Drawable) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UserActivity(com.gh4a.activities.UserActivity) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) User(com.meisolsson.githubsdk.model.User) AttributeSet(android.util.AttributeSet) Reaction(com.meisolsson.githubsdk.model.Reaction) AvatarHandler(com.gh4a.utils.AvatarHandler) MenuPopupHelper(android.support.v7.view.menu.MenuPopupHelper) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) Reactions(com.meisolsson.githubsdk.model.Reactions) Log(android.util.Log) Parcelable(android.os.Parcelable) ApiHelpers(com.gh4a.utils.ApiHelpers) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) LayoutInflater(android.view.LayoutInflater) PopupMenu(android.support.v7.widget.PopupMenu) TextUtils(android.text.TextUtils) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) IdRes(android.support.annotation.IdRes) ColorInt(android.support.annotation.ColorInt) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) BaseAdapter(android.widget.BaseAdapter) Gh4Application(com.gh4a.Gh4Application) LayoutRes(android.support.annotation.LayoutRes) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Optional(com.gh4a.utils.Optional) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) Reaction(com.meisolsson.githubsdk.model.Reaction)

Aggregations

Context (android.content.Context)1 PorterDuff (android.graphics.PorterDuff)1 Drawable (android.graphics.drawable.Drawable)1 Parcelable (android.os.Parcelable)1 ColorInt (android.support.annotation.ColorInt)1 IdRes (android.support.annotation.IdRes)1 LayoutRes (android.support.annotation.LayoutRes)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 DrawableCompat (android.support.v4.graphics.drawable.DrawableCompat)1 MenuBuilder (android.support.v7.view.menu.MenuBuilder)1 MenuPopupHelper (android.support.v7.view.menu.MenuPopupHelper)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 PopupMenu (android.support.v7.widget.PopupMenu)1 TextUtils (android.text.TextUtils)1 AttributeSet (android.util.AttributeSet)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1