66import android .text .SpannableString ;
77import android .text .Spanned ;
88import android .text .style .ForegroundColorSpan ;
9+ import android .util .Log ;
910import android .view .LayoutInflater ;
1011import android .view .View ;
1112import android .view .ViewGroup ;
@@ -29,6 +30,7 @@ public class AutoRollAdapter extends RecyclerView.Adapter<AutoRollAdapter.BaseVi
2930 HashMap <String , CountDownTimer > timerMap = new HashMap <>();
3031 ArrayList <String > timerKeyList = new ArrayList <>();
3132 private List <GroupBookingEntity > mData ;
33+ HashMap <String , Long > secondsMap = new HashMap <>();
3234
3335
3436 public AutoRollAdapter (List <GroupBookingEntity > list ) {
@@ -53,6 +55,7 @@ public void onBindViewHolder(final BaseViewHolder holder, final int position) {
5355 long endTime = Long .parseLong (data .end_time );
5456 long seconds = endTime - currenTime ;
5557 final String mCollageId = data .id ;
58+ String index = String .valueOf (position );
5659
5760 holder .mLayoutGoGourp .setOnClickListener (new View .OnClickListener () {
5861 @ Override
@@ -65,26 +68,45 @@ public void onClick(View v) {
6568
6669 holder .mTvleaveMembers .setText (spannableString );
6770 String id = data .id ;
68- if (!timerKeyList .contains (id )) {
69- timerKeyList .add (id );
71+ if (!timerKeyList .contains (index )) {
72+ timerKeyList .add (index );
7073 }
7174
7275 // -----一开始初始化数据
7376
7477 if (holder .countDownTimer != null ) {
7578 holder .countDownTimer .cancel ();
7679 }
77- holder .countDownTimer = new CountDownTimer (seconds * 1000 , 1000 ) {
78- public void onTick (long l ) {
79- holder .mTvCountDown .setText (getTimeStr (l ));
80- }
8180
82- public void onFinish () {
83- //倒计时结束
81+
82+ if (secondsMap .get (id ) == null ) {
83+ holder .countDownTimer = new CountDownTimer (seconds * 1000 , 1000 ) {
84+ public void onTick (long l ) {
85+ holder .mTvCountDown .setText (getTimeStr (l ));
86+ Log .e ("aaa" ,l +"" );
87+ secondsMap .put (id , l );
88+ }
89+
90+ public void onFinish () {
91+ //倒计时结束
8492// holder.timeTv.setText("00:00");
85- }
86- }.start ();
87- timerMap .put (id , holder .countDownTimer );
93+ }
94+ }.start ();
95+ } else {
96+ holder .countDownTimer = new CountDownTimer (secondsMap .get (id ) , 1000 ) {
97+ public void onTick (long l ) {
98+ holder .mTvCountDown .setText (getTimeStr (l ));
99+ secondsMap .put (id , l );
100+ Log .e ("ccc" ,l +"" );
101+ }
102+
103+ public void onFinish () {
104+ //倒计时结束
105+ // holder.timeTv.setText("00:00");
106+ }
107+ }.start ();
108+ }
109+ timerMap .put (index , holder .countDownTimer );
88110 }
89111
90112 private String getTimeStr (long l ) {
0 commit comments