app/src/main/java/com/kevinrei/chronotrack/AlarmAdapter.java
// Replace the contents of a view (invoked by LayoutManager)
Replace the contents of a view (invoked by LayoutManager)
Replace the contents of a view ( invoked by LayoutManager )
@Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
        final Context context = viewHolder.itemView.getContext();
        final Alarm alarm = alarms.get(position);
        db = new MySQLiteHelper(context);
        Game game = db.getGame(alarm.getGameId());
        if (type == 0) {
            Picasso.with(viewHolder.mGameIcon.getContext())
                    .load(Uri.parse(game.getImage()))
                    .into(viewHolder.mGameIcon);
        } else if (type == 1 && alarm.getCountdown() >= System.currentTimeMillis()) {
            turnAlarmOn(context, viewHolder.mGameIcon);
        } else {
            turnAlarmOff(context, viewHolder.mGameIcon);
        }
        viewHolder.mAlarmLabel.setText(alarm.getLabel());
        String triggerTime = getAlarmTriggerTime(alarm.getTrigger());
        viewHolder.mTriggerTime.setText(triggerTime);
        Countdown mCountdown = new Countdown(viewHolder.mTimeLeft);
        mCountdown.updateTextAndProgress(alarm);
        viewHolder.mGameIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (type == 1) {
                    if (isAlarmActive) {
                        showCancelAlarmDialog(v, alarm, viewHolder.mGameIcon);
                    } else {
                        long newCountdown = System.currentTimeMillis() + alarm.getTrigger();
                        db.updateAlarm(alarm, newCountdown);
                        Log.d("new alarm", alarm.toString());
                        AlarmController controller = new AlarmController();
                        controller.setAlarm(context, db.getAlarm(alarm.getAlarmId()));
                        turnAlarmOn(context, viewHolder.mGameIcon);
                        Snackbar.make(v, "Alarm set.", Snackbar.LENGTH_LONG).show();
                    }
                }
            }
        });
        viewHolder.mAlarmDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDeleteDialog(v, alarm, position);
            }
        });
    }
@ Override public void onBindViewHolder ( final ViewHolder viewHolder , final int position ) { final Context context = viewHolder . itemView . getContext ( ) ; final Alarm alarm = alarms . get ( position ) ; db = new MySQLiteHelper ( context ) ; Game game = db . getGame ( alarm . getGameId ( ) ) ; if ( type == 0 ) { Picasso . with ( viewHolder . mGameIcon . getContext ( ) ) . load ( Uri . parse ( game . getImage ( ) ) ) . into ( viewHolder . mGameIcon ) ; } else if ( type == 1 && alarm . getCountdown ( ) >= System . currentTimeMillis ( ) ) { turnAlarmOn ( context , viewHolder . mGameIcon ) ; } else { turnAlarmOff ( context , viewHolder . mGameIcon ) ; } viewHolder . mAlarmLabel . setText ( alarm . getLabel ( ) ) ; String triggerTime = getAlarmTriggerTime ( alarm . getTrigger ( ) ) ; viewHolder . mTriggerTime . setText ( triggerTime ) ; Countdown mCountdown = new Countdown ( viewHolder . mTimeLeft ) ; mCountdown . updateTextAndProgress ( alarm ) ; viewHolder . mGameIcon . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { if ( type == 1 ) { if ( isAlarmActive ) { showCancelAlarmDialog ( v , alarm , viewHolder . mGameIcon ) ; } else { long newCountdown = System . currentTimeMillis ( ) + alarm . getTrigger ( ) ; db . updateAlarm ( alarm , newCountdown ) ; Log . d ( "new alarm" , alarm . toString ( ) ) ; AlarmController controller = new AlarmController ( ) ; controller . setAlarm ( context , db . getAlarm ( alarm . getAlarmId ( ) ) ) ; turnAlarmOn ( context , viewHolder . mGameIcon ) ; Snackbar . make ( v , "Alarm set." , Snackbar . LENGTH_LONG ) . show ( ) ; } } } } ) ; viewHolder . mAlarmDelete . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { showDeleteDialog ( v , alarm , position ) ; } } ) ; }
Replace the contents of a view (invoked by LayoutManager)
Replace the contents of a view ( invoked by LayoutManager )
// Set game icon // Alarm label // The exact trigger time // Time remaining until alarm is fired