Commit 9b237c3a authored by 张释方's avatar 张释方

Merge branch 'dev_1.0.0' of http://gitlab.mints-id.com/android/android_street into branche_zsf

 Conflicts:
	app/src/main/java/com/mints/street/adapter/ItemEnterDestinationAdapter.kt
	app/src/main/java/com/mints/street/main/vr/FreeZoneFragment.kt
parents 88a14cdd 918b73af
......@@ -3,6 +3,8 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "kotlin-noarg"
apply plugin: "kotlin-allopen"
android {
......@@ -189,14 +191,9 @@ dependencies {
//room数据库
def room_version = "2.3.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" // use kapt for Kotlin
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
api rootProject.ext.dependencies["room-runtime"]
api rootProject.ext.dependencies["room-rxjava2"]
api rootProject.ext.dependencies["room-guava"]
kapt rootProject.ext.dependencies["room-compiler"]
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import com.fry.base.adapter.AbstractVLayoutBaseAdapter
import com.fry.base.adapter.BindingViewHolder
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.bean.VrmapBean
import com.mints.street.databinding.EnterDestinationAdapterBinding
import com.mints.street.main.vr.FreeZoneViewModel
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter
......@@ -21,8 +22,8 @@ import me.tatarka.bindingcollectionadapter2.ItemBinding
/**
* Created by 冯瑞雨 on 2021/7/9.
*/
class EnterDestinationAdapter(val context: Context):
AbstractVLayoutBaseAdapter<EnterDestinationAdapterBinding, Any>(context,null,1) {
class EnterDestinationAdapter(val context: Context,val bean :List<VrmapBean.Abroad>?):
AbstractVLayoutBaseAdapter<EnterDestinationAdapterBinding, List<VrmapBean.Abroad>?>(context,bean,1) {
private var vLayout: VirtualLayoutManager? = null
......@@ -37,7 +38,7 @@ class EnterDestinationAdapter(val context: Context):
holder.binding.listView.layoutManager = vLayout
holder.binding.listView.adapter = mAdapter
mAdapter?.addAdapter(ItemEnterDestinationAdapter(context,true))
mAdapter?.addAdapter(ItemEnterDestinationAdapter(context,true,bean))
}
......
package com.mints.street.adapter
import android.content.Context
import android.content.Intent
import android.graphics.Point
import android.util.DisplayMetrics
import android.view.Display
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.fry.base.adapter.AbstractVLayoutBaseAdapter
import com.fry.base.adapter.BindingViewHolder
import com.mints.street.R
import com.mints.street.databinding.ItemEnterDestinationAdapterBinding
import com.mints.street.main.my.MoresettingsActivity
import com.mints.street.main.vr.DetailedActivity
import com.mints.street.webview.MintsWebViewActivity
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
/**
......@@ -29,12 +30,6 @@ class ItemEnterDestinationAdapter(val context: Context,val isMultipleLayout:Bool
}else{
bgLayoutParams.width = a.widthPixels
}
holder.itemView.setOnClickListener(){
//点击跳转
val intent=Intent(context, DetailedActivity::class.java)
context.startActivity(intent)
}
}
override fun getItemCount() = 2
......
package com.mints.street.bean
/**
*
* @author 冯瑞雨
* @date 2021/7/23
*/
class UpgradeInfo(var title : String?
,var name : String?
,var content : String?
, var versionName : String?
,var v_code : String?
,var downloadUrl : String
,var apkMd5 : String?
,var isForce : Boolean) {
}
\ No newline at end of file
......@@ -18,41 +18,41 @@ interface ScenicSpotDao {
*/
@Query("SELECT * FROM vr_scenic_spot")
fun getVRFreeZoneAll(): List<ScenicSpotBean>
/**
* 删除 VR 免费专区
*/
@Delete
fun deleteVRFreeZoneAll(list:List<ScenicSpotBean>)
/**
* 获取 国外的 免费专区
*/
@Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 1")
fun getForeignFreeAll(list:List<ForeignScenicSpots>)
/**
* 获取 国外的 收费(精选体验)
*/
@Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 2")
fun getForeignTollAll(list:List<ForeignScenicSpots>)
/**
* 添加 VR 国外
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addForeignAll(list:List<ForeignScenicSpots>)
/**
* 删除 VR 国外免费
*/
@Query("DELETE FROM foreign_scenic_spots WHERE is_free =1")
fun deleteForeignFreeAll()
/**
* 删除 VR 国外收费
*/
@Query("DELETE FROM foreign_scenic_spots WHERE is_free =2")
fun deleteForeignTollAll()
//
// /**
// * 删除 VR 免费专区
// */
// @Delete
// fun deleteVRFreeZoneAll(list:List<ScenicSpotBean>)
//
// /**
// * 获取 国外的 免费专区
// */
// @Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 1")
// fun getForeignFreeAll(list:List<ForeignScenicSpots>)
//
// /**
// * 获取 国外的 收费(精选体验)
// */
// @Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 2")
// fun getForeignTollAll(list:List<ForeignScenicSpots>)
//
// /**
// * 添加 VR 国外
// */
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// fun addForeignAll(list:List<ForeignScenicSpots>)
//
// /**
// * 删除 VR 国外免费
// */
// @Query("DELETE FROM foreign_scenic_spots WHERE is_free =1")
// fun deleteForeignFreeAll()
// /**
// * 删除 VR 国外收费
// */
// @Query("DELETE FROM foreign_scenic_spots WHERE is_free =2")
// fun deleteForeignTollAll()
......
package com.mints.street.eventbean;
/**
* @author 冯瑞雨
* @date 2019/10/23 16:29
*/
public class DownloadEvent {
/**
* apk 的大小
*/
private long apkSize;
/**
* 下载的进度 百分比
*/
private int apkCurrentProgress;
/**
* 下载当前进度
*/
private long apkSchedule;
public long getApkSize() {
return apkSize;
}
public void setApkSize(long apkSize) {
this.apkSize = apkSize;
}
public int getApkCurrentProgress() {
return apkCurrentProgress;
}
public void setApkCurrentProgress(int apkCurrentProgress) {
this.apkCurrentProgress = apkCurrentProgress;
}
public long getApkSchedule() {
return apkSchedule;
}
public void setApkSchedule(long apkSchedule) {
this.apkSchedule = apkSchedule;
}
public DownloadEvent(long apkSize, int apkCurrentProgress, long apkSchedule) {
this.apkSize = apkSize;
this.apkCurrentProgress = apkCurrentProgress;
this.apkSchedule = apkSchedule;
}
}
package com.mints.street.main
import android.Manifest
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
......@@ -15,19 +14,17 @@ import com.fry.base.utils.ImageLoader
import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.bean.UpgradeInfo
import com.mints.street.databinding.ActivityMainBinding
import com.mints.street.main.home.HomeFragment
import com.mints.street.main.home.SearchMapActivity
import com.mints.street.main.my.MyFragment
import com.mints.street.main.vr.VRFragment
import com.mints.street.manager.UmengManager
import com.mints.street.manager.oaid.OaidManager
import com.mints.street.utils.UpdateHelper
import com.tbruyelle.rxpermissions2.RxPermissions
import com.umeng.analytics.MobclickAgent
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.ToastUtils
import me.goldze.mvvmhabit.utils.systembar.StatusBarUtil
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
......@@ -75,6 +72,9 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
.subscribe {
}
UpdateHelper.processUpdate(this@MainActivity, UpgradeInfo("1","2","3","4",
"5","6","7",false))
}
......
......@@ -40,6 +40,6 @@ class FeaturedExperienceFragment:BaseFragment<FragmentFeaturedExperienceBinding
binding.listView.layoutManager = vLayout
binding.listView.adapter = mAdapter
mAdapter?.addAdapter(ItemEnterDestinationAdapter(context!!, false))
mAdapter?.addAdapter(ItemEnterDestinationAdapter(context!!, false,null))
}
}
\ No newline at end of file
......@@ -48,7 +48,7 @@ class FreeZoneFragment : BaseFragment<FragmentFreeZoneBinding, FreeZoneViewModel
binding.listView.layoutManager = vLayout
binding.listView.adapter = mAdapter
mAdapter?.addAdapter(EnterDestinationAdapter(context!!))
mAdapter?.addAdapter(EnterDestinationAdapter(context!! ))
}
......
......@@ -5,6 +5,8 @@ import androidx.lifecycle.MutableLiveData
import com.mints.street.bean.BaseResponse
import com.mints.street.bean.VipBean
import com.mints.street.bean.VrmapBean
import com.mints.street.db.AppDatabase
import com.mints.street.db.ScenicSpotBean
import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl
import me.goldze.mvvmhabit.base.BaseViewModel
......@@ -24,11 +26,19 @@ class FreeZoneViewModel(application: Application):BaseViewModel(application) {
this@FreeZoneViewModel,true){
override fun onBusinessSuccess(response: BaseResponse<VrmapBean>) {
VrmapBean.value=response.result
KLog.e("vrPlaces","请求成功")
val a:MutableList<ScenicSpotBean> = ArrayList()
for (item in response.result.internal!!){
a.add(ScenicSpotBean(name = item.name,url = item.url
,starRating = item.stars,images = item.img))
}
// AppDatabase.instance().scenicSpotDao().addVRFreeZoneAll(a)
// for(item in AppDatabase.instance().scenicSpotDao().getVRFreeZoneAll()){
// KLog.e("AppDatabase.instance().scenicSpotDao().getVRFreeZoneAll()",item.toString())
// }
}
override fun onError(e: Throwable) {
KLog.e("vrPlaces","请求失败")
KLog.e("vrPlaces","请求失败 : $e")
}
}
)
......
package com.mints.street.services;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import com.fry.base.utils.NotificationUtils;
import com.mints.street.BuildConfig;
import com.mints.street.eventbean.DownloadEvent;
import com.mints.street.utils.UpdateHelper;
import java.io.File;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.http.DownLoadManager;
import me.goldze.mvvmhabit.http.download.ProgressCallBack;
import me.goldze.mvvmhabit.utils.AppUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.goldze.mvvmhabit.utils.Utils;
import okhttp3.ResponseBody;
/**
* 升级下载服务
*
* @author 冯瑞雨
* @date 2021/7/23
*/
public class UpdateServices extends Service {
public static final String VERSION_CODE_KEY = "versionCode";
public static final String DOWNLOAD_URL_KEY = "url";
public static final String APK_MD5 = "apkMd5";
public static final String IS_FORCED_UPDATE_KEY = "isForcedUpdate";
private boolean isForcedUpdate;
/***
* 文件存放的路径
*/
private String destFileDir;
/***
* 文件存放的名称
*/
private String destFileName = "last-" + BuildConfig.VERSION_CODE + ".apk";
private String targetVersionName;
private NotificationUtils mNotificationUtils;
private boolean hasDownloading = false;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
@Override
public void onCreate() {
super.onCreate();
destFileDir = UpdateHelper.getDownloadDir(this);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
return super.onStartCommand(intent, flags, startId);
}
if (intent.hasExtra(VERSION_CODE_KEY)) {
targetVersionName = intent.getStringExtra(VERSION_CODE_KEY);
destFileName = UpdateHelper.getFileName(targetVersionName);
}
if (mNotificationUtils == null) {
mNotificationUtils = new NotificationUtils(getBaseContext());
}
//启动线程开始执行下载任务
if (!hasDownloading && intent.hasExtra(DOWNLOAD_URL_KEY)) {
startForeground(1, mNotificationUtils.getNotification("下载", "准备下载").build());
downFile(intent.getStringExtra(DOWNLOAD_URL_KEY));
}
if (intent.hasExtra(IS_FORCED_UPDATE_KEY)) {
isForcedUpdate = intent.getBooleanExtra(IS_FORCED_UPDATE_KEY, false);
}
/**
* 这个常量是{@link #onStartCommand}方法的其中一个返回值:如果这个服务的进程在这个服务
* 已经启动(也就是{@link #onStartCommand}方法已经运行完了)之后因为系统资源紧张等问题
* 被系统关闭了,这个服务会被系统用最近一次启动这个服务所用的Intent重新启动它。这个Intent
* 会被系统一直保存到{@link #stopSelf(int)}方法被调用为止。这种情况下,服务当中的
* {@link #onStartCommand(Intent, int, int)}里面的intent不会是null。因为这种服务只
* 会在所有启动它的intent都执行完了的情况下才不会重新启动。
*/
return Service.START_REDELIVER_INTENT;/*super.onStartCommand(intent, flags, startId);*/
}
@Override
public void onDestroy() {
super.onDestroy();
}
//下载更新文件
private void downFile(final String url) {
if (hasDownloading) {
return;
}
DownLoadManager.getInstance().load(url, new ProgressCallBack<ResponseBody>(destFileDir, destFileName) {
@Override
public void onStart() {
super.onStart();
hasDownloading = true;
ToastUtils.showShort("开始下载!");
}
@Override
public void onSuccess(ResponseBody o) {
//如果md5为空,则不校验文件是否合法
ToastUtils.showShort("文件下载成功!");
installApk(destFileDir + "/" + destFileName);
if (isForcedUpdate) {
RxBus.getDefault().post(new DownloadEvent(0, 100, 0));
}
hasDownloading = false;
//停止掉当前的服务
stopSelf();
}
@Override
public void progress(long progress, long total) {
//更新状态栏上的下载进度信息
int processValue = (int) ((progress / (double) total) * 100);
if (isForcedUpdate) {
RxBus.getDefault().post(new DownloadEvent(total, processValue, progress));
} else {
mNotificationUtils.sendNotificationProgress("升级", "已下载" + processValue + "%", processValue, null);
}
}
@Override
public void onError(Throwable e) {
//如果断网,会抛IO异常
e.printStackTrace();
ToastUtils.showShort("文件下载失败!");
File file = new File(destFileDir + File.separator + destFileName);
if (file.exists()) {
file.delete();
}
// nm.cancel(notificationId);
hasDownloading = false;
//停止掉当前的服务
stopSelf();
// progressDialog.dismiss();
}
@Override
public void onCompleted() {
// progressDialog.dismiss();
//下载完成后清除所有下载信息,执行安装提示
// nm.cancel(notificationId);
hasDownloading = false;
//停止掉当前的服务
stopSelf();
}
});
}
private void installApk(String s) {
AppUtils.installApk(Utils.getContext(), s);
}
}
package com.mints.street.utils;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.mints.street.bean.UpgradeInfo;
import com.mints.street.widget.dialog.UpdateDialog;
import java.io.File;
import androidx.appcompat.app.AppCompatActivity;
import me.goldze.mvvmhabit.utils.AppUtils;
import me.goldze.mvvmhabit.utils.CommonDialogUtils;
/**
* @author jeme
* @date 2019/12/29
*/
public class UpdateHelper {
/***
* 普通升级
*/
public static final int UPDATE = 1;
/***
* 强制升级
*/
public static final int FORCE_UPDATE = 2;
/***
* 处理升级功能
*/
public static void processUpdate(AppCompatActivity appCompatActivity, UpgradeInfo upgradeInfoBean) {
UpdateDialog.showDialog(appCompatActivity, upgradeInfoBean);
}
/***
* 检查升级文件合法性
*/
public static boolean checkUpdateFile(Context context, String appVersionCode, String md5) {
if (TextUtils.isEmpty(md5)) {
return false;
}
String dir = getDownloadDir(context);
File file = new File(String.format("%s%s%s", dir, File.separator, appVersionCode));
if (file.exists()) {
String md5_ = me.goldze.mvvmhabit.utils.FileUtils.getFileMD5(file);
return TextUtils.equals(md5, md5_);
}
return false;
}
public static String getDownloadDir(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath();
} else {
return Environment.getExternalStorageDirectory().getPath();
}
}
public static String getFileName(String newVersionCode) {
return String.format("last-%s.apk", newVersionCode);
}
private static void showInstallDialog(AppCompatActivity activity, String appVersion) {
CommonDialogUtils.showMessage(activity, "安装", "新包已经下载成功,是否直接安装?", "确定", "取消", new OnConfirmListener() {
@Override
public void onConfirm() {
AppUtils.installApk(activity,
String.format("%s%s%s", getDownloadDir(activity),
File.separator, getFileName(appVersion)));
}
},null,false);
/* TDialogHelper.selectDialog(activity,"安装","新包已经下载成功,是否直接安装?")
.setOnViewClickListener(new OnViewClickListener() {
@Override
public void onViewClick(BindViewHolder viewHolder, View view, TDialog tDialog) {
if(view.getId() == R.id.tv_confirm){
AppUtils.installApk(activity,
String.format("%s%s%s",getDownloadDir(activity),
File.separator,getFileName(appVersion)));
}
tDialog.dismiss();
}
}).create().show();*/
}
}
package com.mints.street.widget.dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.mints.street.R;
import com.mints.street.eventbean.DownloadEvent;
import java.text.DecimalFormat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.bus.RxSubscriptions;
import me.goldze.mvvmhabit.utils.Utils;
/**
* @author 冯瑞雨
* @date 2019/10/23 14:54
*/
public class DownloadDialog extends DialogFragment {
private TextView tvDownloadSchedule, tvDownloadSize, tvApkSize;
private ProgressBar progressBar;
private Disposable mSubscribe;
private DecimalFormat df = new DecimalFormat("#.00");
private double apkSize;
public static DownloadDialog newInstance() {
Bundle args = new Bundle();
DownloadDialog fragment = new DownloadDialog();
fragment.setArguments(args);
return fragment;
}
@Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
window.setBackgroundDrawable(new ColorDrawable());
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
window.setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.CENTER;
window.setAttributes(params);
setCancelable(false);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.main_dialog_download_fragment, container, false);
return inflate;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
tvDownloadSchedule = view.findViewById(R.id.tv_download_schedule);
tvDownloadSize = view.findViewById(R.id.tv_download_size);
progressBar = view.findViewById(R.id.pb_progress_bar);
tvApkSize = view.findViewById(R.id.tv_apk_size);
mSubscribe = RxBus.getDefault().toObservable(DownloadEvent.class).subscribe(new Consumer<DownloadEvent>() {
@Override
public void accept(DownloadEvent downloadEvent) throws Exception {
Utils.getHandler().post(new Runnable() {
@Override
public void run() {
if (apkSize == 0){
apkSize = downloadEvent.getApkSize()/(1024f*1024f);
if (tvApkSize != null) {
tvApkSize.setText(String.format("/%sM",df.format(apkSize
)));
}
}
if (tvDownloadSchedule != null) {
tvDownloadSchedule.setText(String.format("下载%s%%", downloadEvent.getApkCurrentProgress()));
}
if (progressBar != null) {
progressBar.setProgress(downloadEvent.getApkCurrentProgress());
}
if (tvDownloadSize != null) {
tvDownloadSize.setText(String.format("%sM",df.format(downloadEvent.getApkSchedule()/(1024f*1024f))));
}
if (downloadEvent.getApkSize() == 0 && downloadEvent.getApkSchedule()==0){
tvDownloadSize.setText(String.format("%sM",df.format(apkSize)));
}
}
});
}
});
RxSubscriptions.add(mSubscribe);
}
@Override
public void onDestroy() {
super.onDestroy();
RxSubscriptions.remove(mSubscribe);
}
}
package com.mints.street.widget.dialog
import android.Manifest
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.text.TextUtils
import android.view.View
import androidx.fragment.app.FragmentActivity
import com.fry.base.utils.SpannableUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.interfaces.SimpleCallback
import com.mints.street.R
import com.mints.street.bean.UpgradeInfo
import com.mints.street.services.UpdateServices
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.main_update_dialog.view.*
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.RxUtils
import me.goldze.mvvmhabit.utils.ToastUtils
/**
*
* @author 冯瑞雨
* @date 2021/7/23
*/
class UpdateDialog(val activity: FragmentActivity, val upgradeInfoBean: UpgradeInfo) : CenterPopupView(activity) {
companion object {
@JvmStatic
fun showDialog(activity: FragmentActivity, upgradeInfoBean: UpgradeInfo): UpdateDialog {
return XPopup.Builder(activity)
.setPopupCallback(object : SimpleCallback() {
override fun onBackPressed(): Boolean {
if (!upgradeInfoBean.isForce) { //非强制升级
return false
}
return true
}
})
.dismissOnBackPressed(!upgradeInfoBean.isForce)
.dismissOnTouchOutside(false/*!upgradeInfoBean.isForce*/)
.asCustom(UpdateDialog(activity, upgradeInfoBean))
.show() as UpdateDialog
}
}
override fun getImplLayoutId() = R.layout.main_update_dialog
override fun onCreate() {
super.onCreate()
initView()
initClick()
}
private fun initView() {
tv_update_content.text = upgradeInfoBean.content
tv_tip.text = SpannableUtils.getGradientTxt(upgradeInfoBean.title,
intArrayOf(0xFFFFDA81.toInt(), 0xFFFFF1D5.toInt(), 0xFFFFEDAA.toInt()), null)
tv_title.text = SpannableUtils.getGradientTxt(upgradeInfoBean.name,
intArrayOf(0xFFFFD56F.toInt(), 0xFFFFF1DA.toInt(), 0xFFFFEC98.toInt()), null)
if (upgradeInfoBean.isForce) { //强制升级
stv_download_next.visibility = View.GONE
} else { //普通升级
stv_download_next.visibility = View.VISIBLE
}
}
private fun initClick() {
stv_download_next.setOnClickListener { this.dismiss() }
RxUtils.onMultiClick(stv_download_now){
permissionStorage()
}
}
@SuppressLint("CheckResult")
private fun permissionStorage() {
//请求存储权限
val rxPermissions = RxPermissions(activity)
rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE
, Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe{ grant: Boolean ->
if (grant) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //  8.0 检测是否允许安装apk
val b: Boolean = activity.packageManager.canRequestPackageInstalls()
if (b) {
startDownload()
} else {
permissionInstall()
}
} else {
startDownload()
}
} else {
if (upgradeInfoBean.isForce) {
AppManager.getAppManager().finishAllActivity()
} else {
dismiss()
}
ToastUtils.showLong("请前往系统设置里允许读写权限")
}
}
}
/**
* 8.0安装新版本APK权限
*/
@TargetApi(Build.VERSION_CODES.O)
@SuppressLint("CheckResult")
private fun permissionInstall() {
//请求安装权限
val rxPermissions = RxPermissions(activity)
rxPermissions.request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
.subscribe { grant: Boolean ->
if (grant) {
startDownload()
} else {
//跳转到安装未知应用界面
val packageURI = Uri.parse("package:" + activity.packageName)
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI)
activity.startActivity(intent)
}
}
}
private fun startDownload() {
if (TextUtils.isEmpty(upgradeInfoBean.downloadUrl)) {
return
}
//打开服务
val intent = Intent(activity, UpdateServices::class.java)
intent.putExtra(UpdateServices.DOWNLOAD_URL_KEY, upgradeInfoBean.downloadUrl)
intent.putExtra(UpdateServices.VERSION_CODE_KEY, upgradeInfoBean.v_code)
if (upgradeInfoBean.isForce) { //强制更新
//弹出新的进度框
intent.putExtra(UpdateServices.IS_FORCED_UPDATE_KEY, true)
DownloadDialog.newInstance().show(activity.supportFragmentManager, "")
} else { //后台下载
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.startForegroundService(intent)
} else {
activity.startService(intent)
}
dismiss()
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@
app:layout_constraintTop_toTopOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试"
tools:text="测试"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
......@@ -34,7 +34,7 @@
android:id="@+id/tv_number_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="人数"
tools:text="人数"
android:drawableStart="@mipmap/search_hot_icon"
android:textColor="@color/black"
android:textSize="12sp"
......@@ -54,7 +54,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/image2"
android:src="@mipmap/bg_fl"
tools:src="@mipmap/bg_fl"
/>
<ImageView
android:layout_marginStart="10dp"
......@@ -64,7 +64,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/image1"
app:layout_constraintEnd_toStartOf="@id/image3"
android:src="@mipmap/bg_fl"
tools:src="@mipmap/bg_fl"
/>
<ImageView
......@@ -75,7 +75,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/image2"
app:layout_constraintEnd_toEndOf="parent"
android:src="@mipmap/bg_fl"
tools:src="@mipmap/bg_fl"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="center"
>
<TextView
android:id="@+id/tv_download_schedule"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下载0%"
android:textSize="14sp"
android:textColor="@color/white"
/>
<ProgressBar
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/tv_download_schedule"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginLeft="10dp"
android:id="@+id/pb_progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="8dp"
android:max="100"
tools:progress="80"
/>
<TextView
android:id="@+id/tv_download_size"
app:layout_constraintTop_toBottomOf="@+id/pb_progress_bar"
app:layout_constraintStart_toStartOf="@+id/pb_progress_bar"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0M"
android:textSize="14sp"
android:textColor="@color/white"
/>
<TextView
android:id="@+id/tv_apk_size"
app:layout_constraintTop_toBottomOf="@+id/pb_progress_bar"
app:layout_constraintStart_toEndOf="@id/tv_download_size"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/0M"
android:textSize="14sp"
android:textColor="@color/white"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@mipmap/ic_update_bg">
<TextView
android:id="@+id/tv_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="27dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:text="发现新版本"
android:textColor="@color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="18dp"
android:layout_height="0.5dp"
android:background="@color/white"
app:layout_constraintTop_toTopOf="@id/tv_tip"
app:layout_constraintBottom_toBottomOf="@id/tv_tip"
app:layout_constraintEnd_toStartOf="@id/tv_tip"/>
<View
android:layout_width="18dp"
android:layout_height="0.5dp"
android:background="@color/white"
app:layout_constraintTop_toTopOf="@id/tv_tip"
app:layout_constraintBottom_toBottomOf="@id/tv_tip"
app:layout_constraintStart_toEndOf="@id/tv_tip"/>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="V3.0.0诚邀更新" />
<!-- <View
android:layout_width="0dp"
android:layout_height="0dp"
app:stv_solid="@color/white"
app:stv_corner="6dp"
app:stv_left_top_corner="false"
app:stv_left_bottom_corner="true"
app:stv_right_top_corner="false"
app:stv_right_bottom_corner="true"
app:layout_constraintTop_toTopOf="@id/sv_update_container"
app:layout_constraintBottom_toBottomOf="parent"/>-->
<androidx.core.widget.NestedScrollView
android:id="@+id/sv_update_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:minHeight="110dp"
app:layout_constraintTop_toBottomOf="@id/tv_title">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_update_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="13sp"
tools:text="1、我的关注,一件找货更方便,我的关注,一件找货更方便\n
1、新增【爱拼团】活动,立享超低\n
1、新增【爱拼团】活动,立享超低\n
1、新增【爱拼团】活动,立享超低" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<TextView
android:id="@+id/stv_download_next"
android:layout_width="0dp"
android:layout_height="42dp"
android:layout_marginStart="20dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:background="@mipmap/ic_update_btn_bg"
android:gravity="center"
android:text="下次再说"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@id/stv_download_now"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sv_update_container"
tools:visibility="gone" />
<com.coorchice.library.SuperTextView
android:id="@+id/stv_download_now"
android:layout_width="0dp"
android:layout_height="42dp"
android:layout_marginStart="5dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:gravity="center"
android:text="现在升级"
android:textColor="@color/white"
android:textSize="16sp"
app:stv_shaderEnable="true"
app:stv_corner="4dp"
app:stv_shaderStartColor="#9A885B"
app:stv_shaderEndColor="#C3B387"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/stv_download_next"
app:layout_constraintTop_toBottomOf="@id/sv_update_container"
app:layout_goneMarginStart="20dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -84,6 +84,11 @@ ext {
//阿里路由框架
"arouter-api" : "com.alibaba:arouter-api:1.5.0",
"arouter-compiler" : "com.alibaba:arouter-compiler:1.2.2",
//room
"room-runtime" : "androidx.room:room-runtime:2.2.5",
"room-rxjava2" : "androidx.room:room-rxjava2:2.2.5",
"room-compiler" : "androidx.room:room-compiler:2.2.5",
"room-guava" : "androidx.room:room-guava:2.2.5",
"constraint-layout" : 'androidx.constraintlayout:constraintlayout:1.1.3',
//图片选择和拍照功能
......
......@@ -22,9 +22,8 @@ android {
}
dependencies {
//implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
api fileTree(include: ['*.jar','*.aar'], dir: 'libs')
compileOnly files('libs\\xpopup-release.aar')
//support
api rootProject.ext.support["support-v4"]
api rootProject.ext.support["appcompat-v7"]
......
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