Commit 5ca5f65d authored by jyx's avatar jyx

下载试玩页面样式修改,代码优化

parent a839dedc
package com.mints.goodmoney.ad.tz_ad;
import android.content.Context;
import androidx.annotation.Nullable;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.manager.UserManager;
import com.tz.sdk.coral.ad.CoralAD;
import com.tz.sdk.coral.callback.CoralADListener;
......@@ -22,11 +21,15 @@ import java.util.List;
*/
public final class CoralDownload {
private Context mContext;
public static final int RELEASE_TASK_TYPE = 103;
private int mTaskType;
public CoralDownload(Context context, int taskType) {
mContext = context;
/**
*
* taskType 珊瑚的任务类型 103正式环境 134测试环境
*/
public CoralDownload(int taskType) {
mTaskType = taskType;
}
......@@ -37,13 +40,11 @@ public final class CoralDownload {
*
* @return
*/
public com.mints.goodmoney.ad.tz_ad.ADType getADType() {
return com.mints.goodmoney.ad.tz_ad.ADType.CoralDownload;
}
// public com.mints.goodmoney.ad.tz_ad.ADType getADType() {
// return com.mints.goodmoney.ad.tz_ad.ADType.CoralDownload;
// }
public void pull() {
new ADLoader(mContext)
new ADLoader(MintsApplication.getContext())
.get(ADType.APP_DOWNLOAD)
.from(ADSource.CORAL)
.count(1)
......@@ -80,7 +81,6 @@ public final class CoralDownload {
mOnAdLoadListener.onGetDownloadProcess(downloadProcess);
}
// downloadProcess.reportDownloadStart();
return false;
}
......@@ -147,6 +147,10 @@ public final class CoralDownload {
return this;
}
public void destroy() {
mOnAdLoadListener = null;
}
public interface OnAdLoadListener {
void onLoadSuccess(List<CoralAD> dataList);
......
......@@ -4,6 +4,8 @@ import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Build
import android.provider.Settings
......@@ -20,6 +22,7 @@ import com.mints.goodmoney.utils.ForegroundOrBackground
import com.mints.goodmoney.utils.MD5
import java.io.File
/**
* apk下载管理
*/
......@@ -51,13 +54,14 @@ object DownloadApkManager {
* name:应用名称
*/
fun downloadApk(url: String, name: String) {
this.apkName = "$name.apk"
// 判断apk是否存在
if (isFileExist("$name.apk")) {
installApk()
preInstallApk()
return
}
this.apkName = "$name.apk"
mDownloadListener?.onDownloadStart()
this.download(url)
}
......@@ -74,7 +78,7 @@ object DownloadApkManager {
try {
if (canOnceInstallApk && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val context = MintsApplication.getContext()
val haveInstallPermission = context.getPackageManager().canRequestPackageInstalls()
val haveInstallPermission = context.packageManager.canRequestPackageInstalls()
if (haveInstallPermission) {
installApk()
canOnceInstallApk = false
......@@ -168,21 +172,40 @@ object DownloadApkManager {
* 安装apk包
*/
private fun installApk() {
try {
val context = ForegroundOrBackground.getApp_activity()
val intent = Intent(Intent.ACTION_VIEW)
val file = File(cachePath + apkName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val apkUri: Uri
if (Build.VERSION.SDK_INT >= 24) {
val apkUri: Uri = FileProvider.getUriForFile(context, context.packageName + ".fileprovider", file)
apkUri = FileProvider.getUriForFile(context, context.packageName + ".fileprovider", file)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
} else {
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive")
apkUri = Uri.fromFile(file)
}
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
// 华为手机适配
// 查询所有符合 intent 跳转目标应用类型的应用,注意此方法必须放置在 setDataAndType 方法之后
val resolveLists: List<ResolveInfo> = context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
// 然后全部授权
for (resolveInfo in resolveLists) {
val packageName = resolveInfo.activityInfo.packageName
context.grantUriPermission(packageName, apkUri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
}
context.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
fun destroy() {
this.downloadProgressDialog = null
this.mDownloadListener = null
}
fun setOnMyDownloadListener(onMyDownloadListener: OnMyDownloadListener) {
fun setOnMyDownloadListener(onMyDownloadListener: OnMyDownloadListener?) {
this.mDownloadListener = onMyDownloadListener
}
......
......@@ -77,7 +77,7 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
mCoralDownload = CoralDownload(this, 103).setOnAdLoadListener(this)
mCoralDownload = CoralDownload(CoralDownload.RELEASE_TASK_TYPE).setOnAdLoadListener(this)
initView()
initListener()
......@@ -86,9 +86,9 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
private fun initView() {
val gridLayoutManager = GridLayoutManager(this, 2)
val gridLayoutManager = GridLayoutManager(this, 3)
recy_task.layoutManager = gridLayoutManager
recy_task.addItemDecoration(SpacesItemDecoration(2, SpacesItemDecoration.px2dp(10f)))
recy_task.addItemDecoration(SpacesItemDecoration(3, SpacesItemDecoration.px2dp(10f)))
mTaskAdapter = TaskAdapter(mFakeTaskList, this)
recy_task.adapter = mTaskAdapter
recy_task.setItemViewCacheSize(20)
......@@ -197,11 +197,15 @@ class TaskActivity : BaseActivity(), OnItemClickListener, OnRefreshListener, Cor
}
override fun onDestroy() {
super.onDestroy()
mCoralDownload?.destroy()
mDownloadProcess = null
DownloadApkManager.destroy()
if (mReceiverBroadcastReceiver != null) {
mContext.stopService(Intent(context, AppInstallService::class.java))
mContext.unregisterReceiver(mReceiverBroadcastReceiver)
}
super.onDestroy()
}
override fun onBackPressed() {
......
......@@ -99,6 +99,8 @@ class WebActivity : BaseActivity(), View.OnClickListener {
}
override fun onDestroy() {
DownloadApkManager.destroy()
super.onDestroy()
CacheUtil.clearAllCache(context)
......
......@@ -7,7 +7,6 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
import com.mints.goodmoney.mvp.model.TzTaskBean
......@@ -26,7 +25,7 @@ class TaskAdapter(val dataList: List<TzTaskBean>, val context: Context) : Recycl
val ivAvatar: ImageView = view.findViewById(R.id.item_iv_avatar)
val tvTitle: TextView = view.findViewById(R.id.item_tv_title)
val tvCoin: TextView = view.findViewById(R.id.item_tv_coin)
val tvText: TextView = view.findViewById(R.id.item_tv_text)
// val tvText: TextView = view.findViewById(R.id.item_tv_text)
val btnSubmit: Button = view.findViewById(R.id.item_btn_submit)
}
......@@ -50,19 +49,19 @@ class TaskAdapter(val dataList: List<TzTaskBean>, val context: Context) : Recycl
}
//当前选中
if (getPosition() == position) {
holder.tvTitle.setTextColor(ContextCompat.getColor(context, R.color.white))
holder.tvCoin.setTextColor(ContextCompat.getColor(context, R.color.white))
holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.white))
holder.itemView.setBackgroundResource(R.drawable.shape_vip_adapter_none)
holder.btnSubmit.setBackgroundResource(R.drawable.shape_my_red)
} else {
holder.tvTitle.setTextColor(ContextCompat.getColor(context, R.color.black))
holder.tvCoin.setTextColor(ContextCompat.getColor(context, R.color.color_FF9837))
holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.gray))
holder.itemView.setBackgroundResource(R.drawable.shape_dialog_bg)
holder.btnSubmit.setBackgroundResource(R.drawable.shape_btn_switch)
}
// if (getPosition() == position) {
// holder.tvTitle.setTextColor(ContextCompat.getColor(context, R.color.white))
// holder.tvCoin.setTextColor(ContextCompat.getColor(context, R.color.white))
// holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.white))
// holder.itemView.setBackgroundResource(R.drawable.shape_vip_adapter_none)
// holder.btnSubmit.setBackgroundResource(R.drawable.shape_my_red)
// } else {
// holder.tvTitle.setTextColor(ContextCompat.getColor(context, R.color.black))
// holder.tvCoin.setTextColor(ContextCompat.getColor(context, R.color.color_FF9837))
// holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.gray))
// holder.itemView.setBackgroundResource(R.drawable.shape_dialog_bg)
// holder.btnSubmit.setBackgroundResource(R.drawable.shape_btn_switch)
// }
if (::mOnItemClickListener.isInitialized) {
holder.itemView.setOnClickListener {
......
......@@ -136,9 +136,6 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
homePresenter.userLogin()
}
registerPlayerCallBack()
littleVideoFragment?.onResume()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
// 好兔视频已加载 且 红包已转满
......@@ -147,6 +144,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
}
registerPlayerCallBack()
littleVideoFragment?.onResume()
}
}
......
......@@ -35,8 +35,8 @@ public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
outRect.right = space;
outRect.top = space;
if (parent.getChildLayoutPosition(view) % column == 0) {
outRect.right = 0;
if (parent.getChildLayoutPosition(view) % column != 0) {
outRect.left = 0;
}
}
......
......@@ -60,7 +60,7 @@ public final class Utils {
}
private static String getBytesToMBString(long bytes) {
return String.format(Locale.ENGLISH, "%.2fMb", bytes / (1024.00 * 1024.00));
return String.format(Locale.ENGLISH, "%.2fMB", bytes / (1024.00 * 1024.00));
}
......
......@@ -48,7 +48,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="应用下载中,请等待..."
android:text="应用下载中,请稍候..."
android:textColor="@color/black"
android:textSize="14sp" />
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_dialog_bg">
android:background="@drawable/shape_dialog_bg"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/item_iv_avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:src="@mipmap/ic_launcher_main"
app:layout_constraintEnd_toStartOf="@+id/item_tv_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:src="@mipmap/ic_launcher_main" />
<TextView
android:id="@+id/item_tv_title"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="10dp"
android:layout_toEndOf="@id/item_iv_avatar"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="2"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="@+id/item_iv_avatar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_iv_avatar"
app:layout_constraintTop_toTopOf="@+id/item_iv_avatar" />
android:lines="1"
android:maxLines="1" />
<TextView
android:id="@+id/item_tv_coin"
......@@ -39,34 +30,23 @@
android:layout_marginTop="10dp"
android:text="+300金币"
android:textColor="@color/color_FF9837"
app:layout_constraintEnd_toStartOf="@+id/item_tv_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_iv_avatar" />
android:textSize="18sp" />
<TextView
android:id="@+id/item_tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_iv_avatar"
android:layout_marginStart="5dp"
android:layout_toEndOf="@id/item_tv_coin"
android:text="剩余99+份"
android:textColor="@color/color_ccc"
app:layout_constraintBottom_toBottomOf="@+id/item_tv_coin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_tv_coin"
app:layout_constraintTop_toTopOf="@+id/item_tv_coin" />
android:textSize="12sp" />
<Button
android:id="@+id/item_btn_submit"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_width="70dp"
android:layout_height="32dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_tv_coin" />
android:background="@drawable/shape_btn_switch"
android:textColor="@color/white" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</LinearLayout>
\ 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