Commit a46b75dc authored by jyx's avatar jyx

代码优化

parent ef10c020
......@@ -168,6 +168,7 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.google.code.gson:gson:2.8.5'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation('jp.wasabeef:glide-transformations:4.3.0')
// 65536
implementation 'androidx.multidex:multidex:2.0.1'
// 附件下载更新
......
......@@ -22,4 +22,6 @@ public class AppConfig {
// 进入过支付界面
public static boolean enterVipAct = false;
public static long splashTime = 0L;
}
package com.mints.helivideo.ui.widgets
import android.app.Activity
import android.app.Dialog
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import com.mints.helivideo.R
import com.mints.helivideo.common.AppConfig
import com.mints.helivideo.utils.MilliCountDownTimer
class VipPayCancelDialog(
val activity: Activity,
private val listener: DialogListener
) :
Dialog(activity, R.style.dialog) {
private var milliCountDownTimer: MilliCountDownTimer? = null
private val lp: WindowManager.LayoutParams
init {
setContentView(R.layout.dialog_vip_pay_cancel)
// 设置window属性
lp = window!!.attributes
lp.gravity = Gravity.CENTER
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimFade
window!!.attributes = lp
// 设置外部不可关闭
setCancelable(false)
setCanceledOnTouchOutside(false)
setOnKeyListener { dialogInterface, i, keyEvent ->
i == KeyEvent.KEYCODE_BACK
}
findViewById<View>(R.id.iv_back).setOnClickListener {
dismiss()
}
listener.setDialog(this)
findViewById<View>(R.id.btn).setOnClickListener(listener)
milliCountDownTimer =
MilliCountDownTimer(getShowTime(), findViewById(R.id.tv_count_down))
milliCountDownTimer?.start()
}
override fun dismiss() {
if (activity.isFinishing) return
super.dismiss()
milliCountDownTimer?.cancel()
milliCountDownTimer = null
}
/**
* 获取倒计时时间
*/
fun getShowTime(): Long {
var showTime = 0L
val currentTime = System.currentTimeMillis()
val diff = (currentTime - AppConfig.splashTime) / 1000 / 60 //获取两个时间相差的分钟
if (diff < 60) {
showTime = 60 - diff
} else {
showTime = 59
AppConfig.splashTime = currentTime
}
return showTime * 60 * 1000
}
}
\ No newline at end of file
package com.mints.helivideo.utils;
import android.os.CountDownTimer;
import android.widget.TextView;
/**
* 简单 时,分,秒,毫秒倒计时
* <p>
* 精确到毫秒
*/
public class MilliCountDownTimer extends CountDownTimer {
// 默认倒计时间隔
private static final long DEFAULT_INTERVAL = 100L;
/**
* 秒,分,时对应的毫秒数
*/
private int sec = 1000, min = sec * 60, hr = min * 60;
/**
* 显示时间的视图
*/
private TextView tvDisplay;
/**
* 结束监听
*/
private static OnFinishListener onFinishListener;
/**
* @param millisInFuture 倒计时总时间 单位:毫秒
* The number of millis in the future from the call
* to {@link #start()} until the countdown is done and {@link #onFinish()}
* is called.
* @param countDownInterval 倒计时间隔 单位:毫秒
* The interval along the way to receive
* {@link #onTick(long)} callbacks.
* @param tvDisplay 显示时间的视图
*/
public MilliCountDownTimer(long millisInFuture, long countDownInterval, TextView tvDisplay) {
super(millisInFuture, countDownInterval);
this.tvDisplay = tvDisplay;
}
/**
* @param millisInFuture 倒计时总时间 单位:毫秒
* The number of millis in the future from the call
* to {@link #start()} until the countdown is done and {@link #onFinish()}
* is called.
* @param tvDisplay 显示时间的视图
*/
public MilliCountDownTimer(long millisInFuture, TextView tvDisplay) {
super(millisInFuture, DEFAULT_INTERVAL);
this.tvDisplay = tvDisplay;
}
/**
* 每一次间隔时间到后调用
*
* @param millisUntilFinished 剩余总时间 单位:毫秒
*/
@Override
public void onTick(long millisUntilFinished) {
// 剩余的小时,分钟,秒,毫秒
long lHr = millisUntilFinished / hr;
long lMin = (millisUntilFinished - lHr * hr) / min;
long lSec = (millisUntilFinished - lHr * hr - lMin * min) / sec;
long lMs = millisUntilFinished - lHr * hr - lMin * min - lSec * sec;
String strLHr = getTime(lHr);
String strLMin = getTime(lMin);
String strLSec = getTime(lSec);
String strLMs = getMs(lMs);
// 依次拼接时间 时:分:秒:毫秒
tvDisplay.setText(strLHr + "时" + strLMin + "分" + strLSec + "秒" + strLMs);
}
/**
* 根据毫秒换算成相应单位后是否大于10来返回相应时间
*/
private String getTime(long time) {
return time > 10 ? String.valueOf(time) : "0" + time;
}
/**
* 获取毫秒
*/
private String getMs(long time) {
String strMs = String.valueOf(time);
return time > 100 ? strMs.substring(0, strMs.length() - 1) : "00";
}
/**
* 结束监听,可以在倒计时结束时做一些事
*/
public interface OnFinishListener {
void onFinish();
}
/**
* 设置结束监听
*
* @param onFinishListener 结束监听对象
*/
public MilliCountDownTimer setOnFinishListener(OnFinishListener onFinishListener) {
MilliCountDownTimer.onFinishListener = onFinishListener;
return this;
}
/**
* 倒计时结束时调用
*/
@Override
public void onFinish() {
tvDisplay.setText("00:00:00");
if (onFinishListener != null)
onFinishListener.onFinish();
}
}
......@@ -19,6 +19,7 @@ import com.bumptech.glide.request.target.ViewTarget
import com.bumptech.glide.request.transition.Transition
import com.bumptech.glide.signature.ObjectKey
import com.mints.helivideo.utils.BubbleUtils
import jp.wasabeef.glide.transformations.BlurTransformation
/**
* 描述:GlideUtils
......@@ -67,12 +68,12 @@ object GlideUtils {
//加载Gif*****
fun loadRoundImageViewGif(mContext: Context, drawable: Int, imageView: ImageView) {
val options = RequestOptions()
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.DATA)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.DATA)
Glide.with(mContext)
.load(drawable)
.apply(options)
.into(imageView)
.load(drawable)
.apply(options)
.into(imageView)
}
//默认加载
......@@ -116,6 +117,24 @@ object GlideUtils {
.into(imageView)
}
fun loadImageViewGifForCenterCrop(
mContext: Context,
drawable: String,
imageView: ImageView,
dp: Int
) {
val options = RequestOptions()
.transform(
CenterCrop(),
RoundedCorners(BubbleUtils.dp2px(dp))
)
.diskCacheStrategy(DiskCacheStrategy.DATA)
Glide.with(mContext)
.load(drawable)
.apply(options)
.into(imageView)
}
fun loadImageViewGifForCenterInside(mContext: Context, drawable: String, imageView: ImageView) {
val options = RequestOptions()
.transform(
......@@ -199,4 +218,12 @@ object GlideUtils {
.apply(RequestOptions().skipMemoryCache(true))
.into(imageView)
}
//加载毛玻璃图片
fun loadBlurImageView(mContext: Context, url: String, imageView: ImageView) {
Glide.with(mContext).load(url)
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 4)))
.into(imageView)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#FBF5D2"
android:startColor="@color/white" />
<corners android:radius="100dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="390dp"
android:layout_gravity="center"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp">
<ImageView
android:id="@+id/iv_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_vip_back"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_marginTop="30dp"
android:src="@mipmap/bg_vip_cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@mipmap/ic_vip_pay_cancel_btn"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline3" />
<TextView
android:id="@+id/tv_count_down"
android:layout_width="160dp"
android:layout_height="36dp"
android:background="@drawable/shape_linear_yellow"
android:gravity="center"
android:textColor="@color/color_FD7E0E"
app:layout_constraintBottom_toTopOf="@id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline2" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="170dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="314dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_vip_selected"
android:scaleType="fitXY" />
<TextView
android:id="@+id/bannerTitle"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="60dp"
android:background="@mipmap/ic_vip_lable"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/color_815136"
android:textSize="12sp" />
</RelativeLayout>
\ No newline at end of file
......@@ -30,5 +30,7 @@
<color name="color_2F155E">#2F155E</color>
<color name="color_8D8F90">#7F8182</color>
<color name="color_FD7E0E">#FD7E0E</color>
<color name="color_815136">#815136</color>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment