Commit 839517aa authored by jyx's avatar jyx

代码优化

parent 748a830d
...@@ -10,3 +10,4 @@ ...@@ -10,3 +10,4 @@
app/build app/build
picture_library/build picture_library/build
ucrop/build ucrop/build
videocache/build
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" /> <bytecodeTargetLevel target="15" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -6,9 +6,12 @@ import android.content.DialogInterface; ...@@ -6,9 +6,12 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
...@@ -41,18 +44,25 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base ...@@ -41,18 +44,25 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
try { try {
if (TextUtils.equals(getClass().getSimpleName(), "SplashActivity") || if (TextUtils.equals(getClass().getSimpleName(), "SplashActivity") ||
TextUtils.equals(getClass().getSimpleName(), "GuideActivity") ) { TextUtils.equals(getClass().getSimpleName(), "GuideActivity")) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else if (TextUtils.equals(getClass().getSimpleName(), "VideoActivity")) {
StatusBarUtil.transparencyBar(this); //设置状态栏全透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
getWindow().setNavigationBarColor(Color.BLACK);
}
} else { } else {
StatusBarUtil.transparencyBar(this); //设置状态栏全透明 StatusBarUtil.transparencyBar(this); //设置状态栏全透明
StatusBarUtil.StatusBarLightMode(this); //设置白底黑字 StatusBarUtil.StatusBarLightMode(this); //设置白底黑字
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
getWindow().setNavigationBarColor(Color.TRANSPARENT);
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (isApplyKitKatTranslucency()) { if (isApplyKitKatTranslucency()) {
setSystemBarTintDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sr_primary)); setSystemBarTintDrawable(ContextCompat.getDrawable(getContext(), R.drawable.sr_primary));
} }
...@@ -256,7 +266,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base ...@@ -256,7 +266,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
filter.addAction(Constant.ACTION_EXIT_APP); filter.addAction(Constant.ACTION_EXIT_APP);
filter.addCategory(Intent.CATEGORY_DEFAULT); filter.addCategory(Intent.CATEGORY_DEFAULT);
MintsApplication.getLocalBroadcastManager().unregisterReceiver(mExitReceiver); MintsApplication.getLocalBroadcastManager().unregisterReceiver(mExitReceiver);
}catch (Exception e){ } catch (Exception e) {
} }
......
package com.cwj.updownshortvideo package com.mints.wisdomclean.video
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
...@@ -6,7 +6,6 @@ import android.util.Log ...@@ -6,7 +6,6 @@ import android.util.Log
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import cn.jzvd.JZUtils
import cn.jzvd.Jzvd import cn.jzvd.Jzvd
import cn.jzvd.JzvdStd import cn.jzvd.JzvdStd
import com.mints.wisdomclean.R import com.mints.wisdomclean.R
...@@ -126,6 +125,7 @@ class JzvdStdTikTok : JzvdStd { ...@@ -126,6 +125,7 @@ class JzvdStdTikTok : JzvdStd {
override fun onCompletion() { override fun onCompletion() {
// RxBus.INSTANCE.post(RXCmCWJ(121)) // RxBus.INSTANCE.post(RXCmCWJ(121))
onVideoCompletion?.onVideoCompletion()
} }
...@@ -146,4 +146,16 @@ class JzvdStdTikTok : JzvdStd { ...@@ -146,4 +146,16 @@ class JzvdStdTikTok : JzvdStd {
replayTextView.visibility = View.GONE replayTextView.visibility = View.GONE
} }
} }
fun setOnVideoCompletion(onVideoCompletion: OnVideoCompletion?) {
this.onVideoCompletion = onVideoCompletion
}
private var onVideoCompletion: OnVideoCompletion? = null
interface OnVideoCompletion {
fun onVideoCompletion()
}
} }
package com.cwj.updownshortvideo package com.mints.wisdomclean.video
/** /**
* author : ChenWenJie * author : ChenWenJie
......
...@@ -5,6 +5,7 @@ import android.view.View ...@@ -5,6 +5,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.mints.wisdomclean.video.OnRecyViewListener
/** /**
* author : ChenWenJie * author : ChenWenJie
......
...@@ -25,7 +25,7 @@ class VideoActivity : BaseActivity() { ...@@ -25,7 +25,7 @@ class VideoActivity : BaseActivity() {
override fun isApplyKitKatTranslucency() = false override fun isApplyKitKatTranslucency() = false
fun initView() { fun initView() {
var recyViewLayoutManager = RecyViewLayoutManager( val recyViewLayoutManager = RecyViewLayoutManager(
this, OrientationHelper.VERTICAL this, OrientationHelper.VERTICAL
) )
recy.layoutManager = recyViewLayoutManager recy.layoutManager = recyViewLayoutManager
...@@ -36,11 +36,18 @@ class VideoActivity : BaseActivity() { ...@@ -36,11 +36,18 @@ class VideoActivity : BaseActivity() {
//指定位置其他页面跳转过来。直接定位指定posion 这里不需要。 //指定位置其他页面跳转过来。直接定位指定posion 这里不需要。
// recy.scrollToPosition(postion); // recy.scrollToPosition(postion);
adapter.setOnVideoCompletion(object : JzvdStdTikTok.OnVideoCompletion {
override fun onVideoCompletion() {
recy.smoothScrollToPosition(mCurrentPosition + 1)
}
})
recyViewLayoutManager.setOnViewPagerListener(object : OnRecyViewListener { recyViewLayoutManager.setOnViewPagerListener(object : OnRecyViewListener {
override fun onInitComplete() { override fun onInitComplete() {
mCurrentPosition = 0
//初始化 自动播放 //初始化 自动播放
autoPlayVideo() autoPlayVideo()
} }
override fun onPageRelease(isNext: Boolean, position: Int) { override fun onPageRelease(isNext: Boolean, position: Int) {
...@@ -155,7 +162,6 @@ class VideoActivity : BaseActivity() { ...@@ -155,7 +162,6 @@ class VideoActivity : BaseActivity() {
if (player != null) { if (player != null) {
player.startVideoAfterPreloading() player.startVideoAfterPreloading()
//播放开始,进行倒计时 //播放开始,进行倒计时
} }
} }
......
package com.cwj.updownshortvideo package com.mints.wisdomclean.video
import android.app.Activity import android.app.Activity
import android.net.Uri
import android.util.Log import android.util.Log
import android.widget.ImageView
import cn.jzvd.JZUtils
import cn.jzvd.Jzvd import cn.jzvd.Jzvd
import cn.jzvd.JzvdStd import cn.jzvd.JzvdStd
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
...@@ -33,23 +30,22 @@ class VideoAdapter(var activity: Activity) : ...@@ -33,23 +30,22 @@ class VideoAdapter(var activity: Activity) :
holder.setText(R.id.usertitle_tv, item.video_title) holder.setText(R.id.usertitle_tv, item.video_title)
//缩略图 //缩略图
Glide.with(activity).load(item.video_image) Glide.with(activity).load(item.video_image)
.into(holder?.getView<JzvdStdTikTok>(R.id.jz_video)!!.posterImageView) .into(holder.getView<JzvdStdTikTok>(R.id.jz_video).posterImageView)
//声明 代理服务缓存 //声明 代理服务缓存
val proxy = MintsApplication.StaticParams.getProxy() val proxy = MintsApplication.StaticParams.getProxy()
//这个缓存下一个 //这个缓存下一个
if (holder?.layoutPosition!! + 1 < itemCount) { if (holder.layoutPosition + 1 < itemCount) {
var item1 = getItem(holder?.layoutPosition!! + 1) var item1 = getItem(holder.layoutPosition + 1)
//缓存下一个 10秒 //缓存下一个 10秒
proxy!!.preLoad(item1!!.video_path, 10) proxy!!.preLoad(item1.video_path, 10)
} }
//缓存当前,播放当前 //缓存当前,播放当前
var proxyUrl =proxy?.getProxyUrl(item.video_path).toString() //设置视 var proxyUrl = proxy?.getProxyUrl(item.video_path).toString() //设置视
setPlay(holder.getView(R.id.jz_video), proxyUrl)
setPlay(holder.getView(R.id.jz_video),proxyUrl)
} }
...@@ -61,8 +57,15 @@ class VideoAdapter(var activity: Activity) : ...@@ -61,8 +57,15 @@ class VideoAdapter(var activity: Activity) :
Jzvd.WIFI_TIP_DIALOG_SHOWED = true Jzvd.WIFI_TIP_DIALOG_SHOWED = true
// 清除某个URL进度 // 清除某个URL进度
//JZUtils.clearSavedProgress(activity, path) //JZUtils.clearSavedProgress(activity, path)
jzvdStdTikTok!!.setUp(path, "", JzvdStd.SCREEN_FULLSCREEN) jzvdStdTikTok.setUp(path, "", JzvdStd.SCREEN_FULLSCREEN)
jzvdStdTikTok.setOnVideoCompletion(onVideoCompletion)
}
private var onVideoCompletion: JzvdStdTikTok.OnVideoCompletion? = null
fun setOnVideoCompletion(onVideoCompletion: JzvdStdTikTok.OnVideoCompletion?) {
this.onVideoCompletion = onVideoCompletion
} }
} }
......
package com.cwj.updownshortvideo package com.mints.wisdomclean.video
/** /**
* author : ChenWenJie * author : ChenWenJie
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#77090909"> android:background="#77090909">
<com.cwj.updownshortvideo.JzvdStdTikTok <com.mints.wisdomclean.video.JzvdStdTikTok
android:id="@+id/jz_video" android:id="@+id/jz_video"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
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