gabrielemariotti / cardslib

Android Library to build a UI Card
4.66k stars 1.19k forks source link

How to show count down timer on card title ? #501

Closed fatihturgut closed 9 years ago

fatihturgut commented 9 years ago

Hi ! @gabrielemariotti When i try to show timer on card , it shows the number once and do nothings. It is not updating seconds. Could you help me to overcome this issue please?

*This is my code:

    long day, hour, min, sec;
    MyCard card;
    ArrayList<Card> cards = new ArrayList<Card>();
    card = new MyCard(getActivity());
    card.mainHeader= "Main Header";
    card.mainTitle = "Main Title";

new CountDownTimer(86500000, 1000) { // adjust the milli seconds here

    public void onTick(long millisUntilFinished) {

    card.secondaryTitle = day + " day, " + hour + " hour, " + min + " minute, " + sec + " second";
        day = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
        hour = TimeUnit.MILLISECONDS.toHours(millisUntilFinished) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millisUntilFinished));
        min = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished));
        sec = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished));

    }
    public void onFinish() {card.secondaryTitle = ("done!");}
}.start();

    card.resourceIdThumb = R.drawable.ic_school_black_48dp;

    CardHeader header = new CardHeader(getActivity());
    header.setTitle(card.mainHeader);
    //Add Header to card
    card.addCardHeader(header);

    //Add the thumbnail
    CardThumbnail thumb = new CardThumbnail(getActivity());
    thumb.setDrawableResource(card.resourceIdThumb);
    card.addCardThumbnail(thumb);

    card.setOnClickListener(listener);

    cards.add(card);

*This is my card: untitled

fatihturgut commented 9 years ago

I solved my problem by using setupInnerViewElements method, I put CountDownTimer class into this method and it's worked. Thank you anyway sir @gabrielemariotti . Great library! This is my java code:

    public MyCard1(Context context) {
            super(context, R.layout.home_card_inner_content1);
    }

    @Override
    public void setupInnerViewElements(ViewGroup parent, View view) {

        TextView mTitleTextView1 = (TextView) parent.findViewById(R.id.home_card_main_inner_title1);
        final TextView mSecondaryTitleTextView1 = (TextView) parent.findViewById(R.id.home_card_main_inner_subtitle1);

            new CountDownTimer(86500000, 1000) { // adjust the milli seconds here

                public void onTick(long millisUntilFinished) {

                    day1 = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
                    hour1 = TimeUnit.MILLISECONDS.toHours(millisUntilFinished)- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millisUntilFinished));
                    min1 = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished));
                    sec1 = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished));
                    mSecondaryTitleTextView1.setText(day1 + " day, " + hour1 + " hour, " + min1 + " minute, " + sec1 + " second");
                }
                public void onFinish() {mSecondaryTitleTextView1.setText("done!");}
            }.start();

        if (mTitleTextView1 != null)
            mTitleTextView1.setText(mainTitle1);

        if (mSecondaryTitleTextView1 != null)
            mSecondaryTitleTextView1.setText(secondaryTitle1);
    }
}