添加动态分享框的实现
This commit is contained in:
@@ -22,8 +22,11 @@ import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
|
||||
import com.mogo.module.authorize.authprovider.invoke.AuthorizeInvokerConstant;
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener;
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager;
|
||||
import com.mogo.module.common.dialog.BaseFloatDialog;
|
||||
import com.mogo.module.share.bean.StepAfterAuth;
|
||||
import com.mogo.module.share.constant.ShareConstants;
|
||||
import com.mogo.module.share.dialog.FixableShareDialog;
|
||||
import com.mogo.module.share.dialog.GridFixableShareDialog;
|
||||
import com.mogo.module.share.dialog.LaucherShareDialog;
|
||||
import com.mogo.module.share.manager.ServiceApisManager;
|
||||
import com.mogo.module.share.manager.UploadHelper;
|
||||
@@ -95,7 +98,9 @@ public class ShareControl implements IMogoShareManager, IMogoIntentListener, IMo
|
||||
private static final String TAG = "ShareControl";
|
||||
|
||||
private Context mContext;
|
||||
private LaucherShareDialog mShareDialog;
|
||||
// private LaucherShareDialog mShareDialog;
|
||||
|
||||
private BaseFloatDialog mShareDialog;
|
||||
|
||||
private IMogoAuthorizeModuleManager authorizeModuleManager;
|
||||
private IMogoIntentManager intentManager;
|
||||
@@ -125,7 +130,7 @@ public class ShareControl implements IMogoShareManager, IMogoIntentListener, IMo
|
||||
private void realShowDialog() {
|
||||
if (mShareDialog == null) {
|
||||
Logger.d(TAG,"realShowDialog context : " + mContext);
|
||||
mShareDialog = new LaucherShareDialog(mContext);
|
||||
mShareDialog = new GridFixableShareDialog(mContext);
|
||||
mShareDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.mogo.module.share.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.module.share.R
|
||||
import com.mogo.module.share.bean.FixableButton
|
||||
import com.mogo.utils.glide.GlideApp
|
||||
|
||||
/**
|
||||
* 可配置按钮适配器
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class ShareBtnAdapter(val context:Context): RecyclerView.Adapter<ShareBtnAdapter.ShareBtnViewHolder>() {
|
||||
private val btnList = ArrayList<FixableButton>()
|
||||
var btnClickListener:((btn:FixableButton)->Unit)? = null
|
||||
fun setFixableButtonList(btns:ArrayList<FixableButton>) {
|
||||
btnList.clear()
|
||||
btnList.addAll(btns)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShareBtnViewHolder {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.item_share_btn, parent,false)
|
||||
return ShareBtnViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int =btnList.size
|
||||
|
||||
override fun onBindViewHolder(holder: ShareBtnViewHolder, position: Int) = holder.bindData(btnList[position])
|
||||
|
||||
inner class ShareBtnViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){
|
||||
private val ivIcon:ImageView = itemView.findViewById(R.id.ivShareIcon)
|
||||
private val tvContent:TextView = itemView.findViewById(R.id.tvShareContent)
|
||||
fun bindData(btn: FixableButton) {
|
||||
GlideApp.with(context).load(btn.iconRes).into(ivIcon)
|
||||
tvContent.text = btn.content
|
||||
ivIcon.setOnClickListener {
|
||||
btnClickListener?.invoke(btn)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.mogo.module.share.R
|
||||
|
||||
/**
|
||||
* 可配置按钮封装
|
||||
* @author tongchenfei
|
||||
*/
|
||||
data class FixableButton(val id:Int = 0,val iconUrl:String = "", val iconRes:Int = R.drawable.share_block_up, val content:String="拥堵")
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.mogo.module.share.dialog
|
||||
|
||||
import android.content.Context
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.module.common.dialog.BaseFloatDialog
|
||||
import com.mogo.module.common.utils.CarSeries
|
||||
import com.mogo.module.share.R
|
||||
import com.mogo.module.share.adapter.ShareBtnAdapter
|
||||
import com.mogo.module.share.bean.FixableButton
|
||||
import com.mogo.module.share.manager.ISeekHelpListener
|
||||
import com.mogo.module.share.manager.SeekHelpManager.removeSeekHelpListener
|
||||
import com.mogo.module.share.manager.UploadHelper.upload
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.analytics.IMogoAnalytics
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager
|
||||
import com.mogo.service.tanlu.IMogoTanluProvider
|
||||
import com.mogo.service.tanlu.TanluUploadParams
|
||||
import com.mogo.utils.logger.Logger
|
||||
import kotlin.random.Random
|
||||
|
||||
|
||||
/**
|
||||
* 可动态设置内容的Dialog
|
||||
* 由于和左侧Adas冲突,改成了windowManager方式实现,这种实现方式的问题是,无法监测back键的事件
|
||||
* @since 2020-01-10
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class FixableShareDialog(private val mContext: Context) : BaseFloatDialog(mContext) {
|
||||
private val isShown = false
|
||||
private val mAnalytics: IMogoAnalytics
|
||||
private val mStatusManager: IMogoStatusManager
|
||||
private val mApis: IMogoServiceApis
|
||||
private lateinit var btnRecycler: RecyclerView
|
||||
private lateinit var btnAdapter:ShareBtnAdapter
|
||||
|
||||
private fun setWrapContent() {
|
||||
val window = window
|
||||
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD) {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1024
|
||||
lp.height = 600
|
||||
window.attributes = lp
|
||||
}
|
||||
} else if (CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X) {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1920
|
||||
lp.height = 1080
|
||||
window.attributes = lp
|
||||
}
|
||||
} else {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1024
|
||||
lp.height = 600
|
||||
window.attributes = lp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
Logger.d(TAG, "test-------3")
|
||||
setContentView(R.layout.launcher_dialog_share_with_gride)
|
||||
setWrapContent()
|
||||
|
||||
btnRecycler = findViewById(R.id.moduleShareBtnRecyclerView)
|
||||
val manager = GridLayoutManager(mContext, 5, GridLayoutManager.VERTICAL, false)
|
||||
manager.isAutoMeasureEnabled = true
|
||||
btnAdapter = ShareBtnAdapter(mContext)
|
||||
btnRecycler.adapter = btnAdapter
|
||||
btnAdapter.btnClickListener = {
|
||||
Logger.d(TAG, "btn click: $it")
|
||||
randomGenerateBtn()
|
||||
}
|
||||
randomGenerateBtn()
|
||||
}
|
||||
|
||||
private fun randomGenerateBtn(){
|
||||
val random = Random.nextInt(1, 10)
|
||||
val list = ArrayList<FixableButton>()
|
||||
for (i in 0 until random) {
|
||||
list.add(FixableButton())
|
||||
}
|
||||
btnAdapter.setFixableButtonList(list)
|
||||
}
|
||||
|
||||
private val seekListener: ISeekHelpListener = object : ISeekHelpListener {
|
||||
override fun onSeekHelpSuccess() {
|
||||
Logger.d(TAG, "上报求助完成,成功")
|
||||
removeSeekHelpListener(this)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onSeekHelpFail() {
|
||||
Logger.d(TAG, "上报求助完成,失败")
|
||||
removeSeekHelpListener(this)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送广播 1拥堵,2交通检查,3封路
|
||||
*/
|
||||
private fun sendShareReceiver(type: String) {
|
||||
val params = TanluUploadParams(type, IMogoTanluProvider.UPLOAD_FROM_USER)
|
||||
upload(mContext, params, true)
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
Logger.d(TAG, "onShow====")
|
||||
if (!DebugConfig.isLauncher()) {
|
||||
mApis.adasControllerApi.closeADAS()
|
||||
}
|
||||
super.show()
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
Logger.d(TAG, "onDismiss=====")
|
||||
if (!DebugConfig.isLauncher() && mApis.statusManagerApi.isMainPageOnResume) {
|
||||
mApis.adasControllerApi.showADAS()
|
||||
}
|
||||
super.dismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "FixableShareDialog"
|
||||
}
|
||||
|
||||
init {
|
||||
mApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(mContext) as IMogoServiceApis
|
||||
mAnalytics = mApis.analyticsApi
|
||||
mStatusManager = mApis.statusManagerApi
|
||||
initView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.mogo.module.share.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.GridLayout
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.module.common.dialog.BaseFloatDialog
|
||||
import com.mogo.module.common.utils.CarSeries
|
||||
import com.mogo.module.share.R
|
||||
import com.mogo.module.share.adapter.ShareBtnAdapter
|
||||
import com.mogo.module.share.bean.FixableButton
|
||||
import com.mogo.module.share.manager.GridBtnManager
|
||||
import com.mogo.module.share.manager.ISeekHelpListener
|
||||
import com.mogo.module.share.manager.SeekHelpManager
|
||||
import com.mogo.module.share.manager.UploadHelper
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.analytics.IMogoAnalytics
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager
|
||||
import com.mogo.service.tanlu.IMogoTanluProvider
|
||||
import com.mogo.service.tanlu.TanluUploadParams
|
||||
import com.mogo.utils.logger.Logger
|
||||
import kotlin.random.Random
|
||||
|
||||
class GridFixableShareDialog(context:Context):BaseFloatDialog(context) {
|
||||
private val isShown = false
|
||||
private val mAnalytics: IMogoAnalytics
|
||||
private val mStatusManager: IMogoStatusManager
|
||||
private val mApis: IMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
|
||||
|
||||
private fun setWrapContent() {
|
||||
val window = window
|
||||
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD) {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1024
|
||||
lp.height = 600
|
||||
window.attributes = lp
|
||||
}
|
||||
} else if (CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X) {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1920
|
||||
lp.height = 1080
|
||||
window.attributes = lp
|
||||
}
|
||||
} else {
|
||||
if (window != null) {
|
||||
val lp = window.attributes
|
||||
lp.width = 1024
|
||||
lp.height = 600
|
||||
window.attributes = lp
|
||||
}
|
||||
}
|
||||
}
|
||||
private lateinit var gridBtnManager:GridBtnManager
|
||||
private fun initView() {
|
||||
Logger.d(TAG, "test-------3")
|
||||
setContentView(R.layout.dialog_share_with_gridlayout)
|
||||
setWrapContent()
|
||||
gridBtnManager = GridBtnManager(context,findViewById(R.id.moduleShareBtnGridLayout))
|
||||
gridBtnManager.setShareClickListener {
|
||||
Logger.d(TAG, "share btn click: $it")
|
||||
randomGenerateBtn()
|
||||
}
|
||||
randomGenerateBtn()
|
||||
}
|
||||
|
||||
private fun randomGenerateBtn(){
|
||||
val random = Random.nextInt(1, 10)
|
||||
gridBtnManager.resetContainer()
|
||||
for (i in 0 until random) {
|
||||
gridBtnManager.generateShareButton(FixableButton(id = i))
|
||||
}
|
||||
}
|
||||
|
||||
private val seekListener: ISeekHelpListener = object : ISeekHelpListener {
|
||||
override fun onSeekHelpSuccess() {
|
||||
Logger.d(TAG, "上报求助完成,成功")
|
||||
SeekHelpManager.removeSeekHelpListener(this)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onSeekHelpFail() {
|
||||
Logger.d(TAG, "上报求助完成,失败")
|
||||
SeekHelpManager.removeSeekHelpListener(this)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送广播 1拥堵,2交通检查,3封路
|
||||
*/
|
||||
private fun sendShareReceiver(type: String) {
|
||||
val params = TanluUploadParams(type, IMogoTanluProvider.UPLOAD_FROM_USER)
|
||||
UploadHelper.upload(context, params, true)
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
Logger.d(TAG, "onShow====")
|
||||
if (!DebugConfig.isLauncher()) {
|
||||
mApis.adasControllerApi.closeADAS()
|
||||
}
|
||||
super.show()
|
||||
}
|
||||
|
||||
override fun dismiss() {
|
||||
Logger.d(TAG, "onDismiss=====")
|
||||
if (!DebugConfig.isLauncher() && mApis.statusManagerApi.isMainPageOnResume) {
|
||||
mApis.adasControllerApi.showADAS()
|
||||
}
|
||||
super.dismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "GridFixableShareDialog"
|
||||
}
|
||||
|
||||
init {
|
||||
mAnalytics = mApis.analyticsApi
|
||||
mStatusManager = mApis.statusManagerApi
|
||||
initView()
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package com.mogo.module.share.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.dialog.BaseFloatDialog;
|
||||
import com.mogo.module.common.utils.CarSeries;
|
||||
import com.mogo.module.share.R;
|
||||
import com.mogo.module.share.manager.ISeekHelpListener;
|
||||
import com.mogo.module.share.manager.SeekHelpManager;
|
||||
@@ -74,7 +75,31 @@ public class LaucherShareDialog extends BaseFloatDialog implements View.OnClickL
|
||||
initView();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void setWrapContent() {
|
||||
Window window = getWindow();
|
||||
if(DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD){
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.width = 1024;
|
||||
lp.height = 600;
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
}else if(CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X){
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.width = 1920;
|
||||
lp.height = 1080;
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
}else{
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.width = 1024;
|
||||
lp.height = 600;
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void initView() {
|
||||
Logger.d(TAG, "test-------3");
|
||||
setContentView(R.layout.launcher_dialog_share_2);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.mogo.module.share.manager
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.GridLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.mogo.module.share.R
|
||||
import com.mogo.module.share.bean.FixableButton
|
||||
import com.mogo.utils.glide.GlideApp
|
||||
|
||||
/**
|
||||
* 用来管理生成对应的分享按钮
|
||||
*/
|
||||
class GridBtnManager(val context:Context,val container:GridLayout) {
|
||||
private val inflater = LayoutInflater.from(context)
|
||||
|
||||
fun resetContainer(){
|
||||
container.removeAllViews()
|
||||
}
|
||||
|
||||
fun generateShareButton(button: FixableButton): View {
|
||||
val view = inflater.inflate(R.layout.item_share_btn, container,false )
|
||||
val img = view.findViewById<ImageView>(R.id.ivShareIcon)
|
||||
val content = view.findViewById<TextView>(R.id.tvShareContent)
|
||||
GlideApp.with(context).load(button.iconRes).into(img)
|
||||
content.text = button.content
|
||||
view.setOnClickListener {
|
||||
btnClickListener?.invoke(button)
|
||||
}
|
||||
container.addView(view)
|
||||
return view
|
||||
}
|
||||
|
||||
private var btnClickListener:((fixableButton:FixableButton)->Unit)? =null
|
||||
fun setShareClickListener(listener: ((fixableButton: FixableButton) -> Unit)) {
|
||||
btnClickListener = listener
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user