添加30秒倒计时

This commit is contained in:
18401019693 2022-10-25 15:50:49 +08:00
parent 1ce5ac2c5f
commit 1959a7933b
2 changed files with 56 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.yunbao.live.dialog; package com.yunbao.live.dialog;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -41,6 +42,7 @@ public class VoiceDialog extends AbsDialogFragment {
private GifImageView gifView; private GifImageView gifView;
private SpannableStringBuilder builder = new SpannableStringBuilder(); private SpannableStringBuilder builder = new SpannableStringBuilder();
private boolean isSend = true; private boolean isSend = true;
private Handler handler = new Handler();
public boolean isSend() { public boolean isSend() {
return isSend; return isSend;
@ -85,6 +87,19 @@ public class VoiceDialog extends AbsDialogFragment {
params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER; params.gravity = Gravity.CENTER;
window.setAttributes(params); window.setAttributes(params);
handler.postDelayed(new Runnable() {
@Override
public void run() {
}
}, 30000);
}
@Override
public void dismiss() {
listener = null;
handler.removeCallbacks(timeOut);
super.dismiss();
} }
@Override @Override
@ -99,8 +114,18 @@ public class VoiceDialog extends AbsDialogFragment {
iconWithdraw.setVisibility(View.GONE); iconWithdraw.setVisibility(View.GONE);
gifView.setVisibility(View.GONE); gifView.setVisibility(View.GONE);
voiceFluctuations.setVisibility(View.VISIBLE); voiceFluctuations.setVisibility(View.VISIBLE);
handler.postDelayed(timeOut, 30000);
} }
private Runnable timeOut = new Runnable() {
@Override
public void run() {
if (listener != null) {
listener.timeout();
}
}
};
/** /**
* 上划取消 * 上划取消
*/ */
@ -297,4 +322,15 @@ public class VoiceDialog extends AbsDialogFragment {
} }
return ret.toString(); return ret.toString();
} }
private VoiceListener listener;
public VoiceDialog setListener(VoiceListener listener) {
this.listener = listener;
return this;
}
public interface VoiceListener {
void timeout();
}
} }

View File

@ -329,6 +329,25 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
vibrator.vibrate(100);//震动时间(ms) vibrator.vibrate(100);//震动时间(ms)
if (voiceDialog == null) { if (voiceDialog == null) {
voiceDialog = new VoiceDialog(); voiceDialog = new VoiceDialog();
voiceDialog.setListener(new VoiceDialog.VoiceListener() {
@Override
public void timeout() {
//松开
handler.removeCallbacks(mLongPressed);
Bus.get().post(new LiveAudienceEvent()
.setVoicePress(false)
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
if (voiceDialog != null) {
if (voiceDialog.isSend() && !TextUtils.isEmpty(voiceDialog.sendMessage())) {
((LiveActivity) mContext).sendChatMessage(voiceDialog.sendMessage(), null, null);
}
voiceDialog.dismiss();
voiceDialog = null;
}
}
});
} }
voiceDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "VoiceDialog"); voiceDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "VoiceDialog");
Bus.get().post(new LiveAudienceEvent() Bus.get().post(new LiveAudienceEvent()