app/src/main/java/com/mensa/zhmensa/component/PollOptionViewHolder.java
/**
     * Binds the menu to a view.
     * @param viewHolder to view to bind to menu to
     * @param menu to menu
     * @param mensaId
     */
Binds the menu to a view.
Binds the menu to a view .
public static void bind(PollOptionViewHolder viewHolder, final Poll mainPoll, final Poll.PollOption pollOption, @NonNull final Context ctx, final Poll.PollOptionChangedListener listener) {
        IMenu menu = pollOption.getPollMenu();
        if(menu == null)
            return;
        ( viewHolder.itemView.findViewById(R.id.card_title)).setVisibility(View.VISIBLE);
        ( viewHolder.itemView.findViewById(R.id.price_text)).setVisibility(View.VISIBLE);
        ( viewHolder.itemView.findViewById(R.id.card_content)).setVisibility(View.VISIBLE);
        viewHolder.itemView.findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
        viewHolder.itemView.findViewById(R.id.imageButton).setVisibility(View.VISIBLE);
        ((TextView) viewHolder.itemView.findViewById(R.id.card_title)).setText(pollOption.id.mensaName + ": " + menu.getName());
        ((TextView) viewHolder.itemView.findViewById(R.id.price_text)).setText(menu.getPrices());
        ((TextView) viewHolder.itemView.findViewById(R.id.card_content)).setText(menu.getDescription());
        ((TextView) viewHolder.itemView.findViewById(R.id.allergene)).setText(menu.getAllergene(ctx));
        final TextView vegiView =  viewHolder.itemView.findViewById(R.id.vegi_badge);
        final ProgressBar pb = viewHolder.itemView.findViewById(R.id.progressBar);
        pb.setProgress(mainPoll.votes == 0 ? 0 : (int) ( 100.0 * pollOption.vote / mainPoll.votes ));
        final ImageButton likeButton = viewHolder.itemView.findViewById(R.id.imageButton);
        likeButton.setImageResource(pollOption.userVoted ? R.drawable.ic_thumb_up_black_24dp : R.drawable.ic_thumb_up_black_24dp_outline);
        likeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("votecount1", "On click: poll: " + mainPoll.id  + " numbers: " + mainPoll.votes + " option: " + pollOption.id + " number: " + pollOption.vote);
                if(pollOption.userVoted) {
                    MensaManager.getPollManagger(ctx).removeVoteForPollOption(mainPoll, pollOption, ctx, new Function1<Boolean, Void>() {
                        @Override
                        public Void invoke(Boolean sucess) {
                            if(sucess) {
                                likeButton.setImageResource(pollOption.userVoted ? R.drawable.ic_thumb_up_black_24dp : R.drawable.ic_thumb_up_black_24dp_outline);
                                pb.setProgress(mainPoll.votes == 0 ? 0 : (int) ( 100.0 * pollOption.vote / mainPoll.votes ));
                                Log.d("votecount2", "On click: poll: " + mainPoll.id  + " numbers: " + mainPoll.votes + " option: " + pollOption.id + " number: " + pollOption.vote);
                                if(listener != null) {
                                    listener.onPollOptionChanged(pollOption);
                                }
                                Log.d("votecount3", "On click: poll: " + mainPoll.id  + " numbers: " + mainPoll.votes + " option: " + pollOption.id + " number: " + pollOption.vote);
                            } else {
                                Log.e("err", "Error voting for Poll");
                            }
                            return null;
                        }
                    });
                } else {
                    MensaManager.getPollManagger(ctx).voteForPollOption(mainPoll, pollOption, ctx, new Function1<Boolean, Void>() {
                        @Override
                        public Void invoke(Boolean sucess) {
                            if(sucess) {
                                likeButton.setImageResource(pollOption.userVoted ? R.drawable.ic_thumb_up_black_24dp : R.drawable.ic_thumb_up_black_24dp_outline);
                                pb.setProgress(mainPoll.votes == 0 ? 0 : (int) ( 100.0 * pollOption.vote / mainPoll.votes ));
                                Log.d("votecount2", "On click: poll: " + mainPoll.id  + " numbers: " + mainPoll.votes + " option: " + pollOption.id + " number: " + pollOption.vote);
                                if(listener != null) {
                                    listener.onPollOptionChanged(pollOption);
                                }
                                Log.d("votecount3", "On click: poll: " + mainPoll.id  + " numbers: " + mainPoll.votes + " option: " + pollOption.id + " number: " + pollOption.vote);
                            } else {
                                Log.e("err", "Error voting for Poll");
                            }
                            return null;
                        }
                    });
                }
            }
        });
        vegiView.setVisibility(menu.isVegi() ? View.VISIBLE : View.INVISIBLE);
    }
public static void bind ( PollOptionViewHolder viewHolder , final Poll mainPoll , final Poll . PollOption pollOption , @ NonNull final Context ctx , final Poll . PollOptionChangedListener listener ) { IMenu menu = pollOption . getPollMenu ( ) ; if ( menu == null ) return ; ( viewHolder . itemView . findViewById ( R . id . card_title ) ) . setVisibility ( View . VISIBLE ) ; ( viewHolder . itemView . findViewById ( R . id . price_text ) ) . setVisibility ( View . VISIBLE ) ; ( viewHolder . itemView . findViewById ( R . id . card_content ) ) . setVisibility ( View . VISIBLE ) ; viewHolder . itemView . findViewById ( R . id . progressBar ) . setVisibility ( View . VISIBLE ) ; viewHolder . itemView . findViewById ( R . id . imageButton ) . setVisibility ( View . VISIBLE ) ; ( ( TextView ) viewHolder . itemView . findViewById ( R . id . card_title ) ) . setText ( pollOption . id . mensaName + ": " + menu . getName ( ) ) ; ( ( TextView ) viewHolder . itemView . findViewById ( R . id . price_text ) ) . setText ( menu . getPrices ( ) ) ; ( ( TextView ) viewHolder . itemView . findViewById ( R . id . card_content ) ) . setText ( menu . getDescription ( ) ) ; ( ( TextView ) viewHolder . itemView . findViewById ( R . id . allergene ) ) . setText ( menu . getAllergene ( ctx ) ) ; final TextView vegiView = viewHolder . itemView . findViewById ( R . id . vegi_badge ) ; final ProgressBar pb = viewHolder . itemView . findViewById ( R . id . progressBar ) ; pb . setProgress ( mainPoll . votes == 0 ? 0 : ( int ) ( 100.0 * pollOption . vote / mainPoll . votes ) ) ; final ImageButton likeButton = viewHolder . itemView . findViewById ( R . id . imageButton ) ; likeButton . setImageResource ( pollOption . userVoted ? R . drawable . ic_thumb_up_black_24dp : R . drawable . ic_thumb_up_black_24dp_outline ) ; likeButton . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View view ) { Log . d ( "votecount1" , "On click: poll: " + mainPoll . id + " numbers: " + mainPoll . votes + " option: " + pollOption . id + " number: " + pollOption . vote ) ; if ( pollOption . userVoted ) { MensaManager . getPollManagger ( ctx ) . removeVoteForPollOption ( mainPoll , pollOption , ctx , new Function1 < Boolean , Void > ( ) { @ Override public Void invoke ( Boolean sucess ) { if ( sucess ) { likeButton . setImageResource ( pollOption . userVoted ? R . drawable . ic_thumb_up_black_24dp : R . drawable . ic_thumb_up_black_24dp_outline ) ; pb . setProgress ( mainPoll . votes == 0 ? 0 : ( int ) ( 100.0 * pollOption . vote / mainPoll . votes ) ) ; Log . d ( "votecount2" , "On click: poll: " + mainPoll . id + " numbers: " + mainPoll . votes + " option: " + pollOption . id + " number: " + pollOption . vote ) ; if ( listener != null ) { listener . onPollOptionChanged ( pollOption ) ; } Log . d ( "votecount3" , "On click: poll: " + mainPoll . id + " numbers: " + mainPoll . votes + " option: " + pollOption . id + " number: " + pollOption . vote ) ; } else { Log . e ( "err" , "Error voting for Poll" ) ; } return null ; } } ) ; } else { MensaManager . getPollManagger ( ctx ) . voteForPollOption ( mainPoll , pollOption , ctx , new Function1 < Boolean , Void > ( ) { @ Override public Void invoke ( Boolean sucess ) { if ( sucess ) { likeButton . setImageResource ( pollOption . userVoted ? R . drawable . ic_thumb_up_black_24dp : R . drawable . ic_thumb_up_black_24dp_outline ) ; pb . setProgress ( mainPoll . votes == 0 ? 0 : ( int ) ( 100.0 * pollOption . vote / mainPoll . votes ) ) ; Log . d ( "votecount2" , "On click: poll: " + mainPoll . id + " numbers: " + mainPoll . votes + " option: " + pollOption . id + " number: " + pollOption . vote ) ; if ( listener != null ) { listener . onPollOptionChanged ( pollOption ) ; } Log . d ( "votecount3" , "On click: poll: " + mainPoll . id + " numbers: " + mainPoll . votes + " option: " + pollOption . id + " number: " + pollOption . vote ) ; } else { Log . e ( "err" , "Error voting for Poll" ) ; } return null ; } } ) ; } } } ) ; vegiView . setVisibility ( menu . isVegi ( ) ? View . VISIBLE : View . INVISIBLE ) ; }
Binds the menu to a view.
Binds the menu to a view .
//final LinearLayout showMoreLayout = viewHolder.itemView.findViewById(R.id.showmore_layout); //              pollOption.userVoted = !pollOption.userVoted; //                                pollOption.userVoted = !pollOption.userVoted;