Commit 0791daf6 authored by shiyl's avatar shiyl

通过XBrid调用原生页面

parent dfa96cc3
...@@ -5,7 +5,6 @@ import android.app.Application ...@@ -5,7 +5,6 @@ import android.app.Application
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.util.Log
import com.orhanobut.hawk.Hawk import com.orhanobut.hawk.Hawk
import com.scwang.smart.refresh.footer.ClassicsFooter import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader import com.scwang.smart.refresh.header.ClassicsHeader
...@@ -171,16 +170,18 @@ open class YdBaseApplication : Application() { ...@@ -171,16 +170,18 @@ open class YdBaseApplication : Application() {
response: Response // 业务方需要借助 response 来回应服务调用结果 response: Response // 业务方需要借助 response 来回应服务调用结果
) { ) {
val data = request.params as JSONObject val data = request.params as JSONObject
Log.e("zhb-yd", "服务名:" + request.name) // JS调用Native传递的数据
Log.e("zhb-yd", "JS传递参数:$data") Timber.tag("xbrid").e("服务名:%s", request.name)
Timber.tag("xbrid").e("JS传递参数:%s", data)
val action = data.optString("action") val action = data.optString("action")
val params = data.optJSONObject("params") val params = data.optJSONObject("params")
val options = data.optJSONObject("options") val options = data.optJSONObject("options")
// Native调用JS传递的数据
ZapTicket(request.name).withAction(action).withServiceParams(params).withServiceOptions(options).withIdentifier(identifier) ZapTicket(request.name).withAction(action).withServiceParams(params).withServiceOptions(options).withIdentifier(identifier)
.onResult { result -> .onResult { result ->
response.result(result.code, result.result!!, "") response.result(result.code, result.result ?: "", "")
}.onLost { result -> }.onLost { result ->
response.result(result.code, "", result.mesg) response.result(result.code, "", result.mesg)
}.ship() }.ship()
......
...@@ -5,12 +5,16 @@ import com.yidian.common.XRouterPathConstants ...@@ -5,12 +5,16 @@ import com.yidian.common.XRouterPathConstants
import com.yidian.common.YdBaseApplication import com.yidian.common.YdBaseApplication
import com.yidian.news.util.ProcessUtil import com.yidian.news.util.ProcessUtil
import com.yidian.shenghuoquan.commodity.service.SelectCategoryService import com.yidian.shenghuoquan.commodity.service.SelectCategoryService
import com.yidian.shenghuoquan.commodity.ui.coupon.ChooseCategoryActivity
import com.yidian.shenghuoquan.commodity.ui.coupon.CommodityManagementActivity
import com.yidian.shenghuoquan.commodity.ui.coupon.PublishCouponsActivity
import com.yidian.xpage.XPageManager import com.yidian.xpage.XPageManager
import com.yidian.xpage.node.XPageHandler import com.yidian.xpage.node.XPageHandler
import com.yidian.xpage.node.XPageNode import com.yidian.xpage.node.XPageNode
import com.yidian.xpage.node.XPageNodePageType import com.yidian.xpage.node.XPageNodePageType
import com.yidian.yac.core.core.YacModuleSpec import com.yidian.yac.core.core.YacModuleSpec
import com.yidian.yac.core.zap.Zap import com.yidian.yac.core.zap.Zap
import timber.log.Timber
@YacModuleSpec @YacModuleSpec
class CommodityApplication : YdBaseApplication() { class CommodityApplication : YdBaseApplication() {
...@@ -18,6 +22,7 @@ class CommodityApplication : YdBaseApplication() { ...@@ -18,6 +22,7 @@ class CommodityApplication : YdBaseApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (ProcessUtil.isMainProcess(this)) { if (ProcessUtil.isMainProcess(this)) {
Timber.tag("注册").e("开始注册")
registerXPage() registerXPage()
initService() initService()
} }
...@@ -37,6 +42,7 @@ class CommodityApplication : YdBaseApplication() { ...@@ -37,6 +42,7 @@ class CommodityApplication : YdBaseApplication() {
} }
}) })
XPageManager.registeredNode(node) XPageManager.registeredNode(node)
Timber.e("注册XPage ${it.key}")
} }
} }
......
...@@ -5,13 +5,13 @@ package com.yidian.shenghuoquan.commodity.dto ...@@ -5,13 +5,13 @@ package com.yidian.shenghuoquan.commodity.dto
* 类目列表 * 类目列表
*/ */
data class CategoryListDto( data class CategoryListDto(
val category_id: Int,// 分类id val category_id: Long,// 分类id
val name: String,// 分类名称 val name: String,// 分类名称
val sub_list: List<SubCategory>// 二级分类 val sub_list: List<SubCategory>// 二级分类
) )
data class SubCategory( data class SubCategory(
val category_id: Int, val category_id: Long,
val name: String, val name: String,
var isSelect: Boolean = false var isSelect: Boolean = false
) )
...@@ -20,8 +20,8 @@ data class SubCategory( ...@@ -20,8 +20,8 @@ data class SubCategory(
* 当前选中的类目信息 * 当前选中的类目信息
*/ */
data class SelectCategoryDto( data class SelectCategoryDto(
val firstCategoryId: Int, val firstCategoryId: Long,
val firstCategoryName: String, val firstCategoryName: String,
val secondCategoryId: Int, val secondCategoryId: Long,
val secondCategoryName: String val secondCategoryName: String
) )
...@@ -35,13 +35,22 @@ class SelectCategoryService : ZapService() { ...@@ -35,13 +35,22 @@ class SelectCategoryService : ZapService() {
*/ */
private fun gotoSelectCategory(params: JSONObject) { private fun gotoSelectCategory(params: JSONObject) {
val lastSelectCategory = params.optJSONObject("selectedCategory") val lastSelectCategory = params.optJSONObject("selectedCategory")
if (lastSelectCategory == null) { lastSelectCategory?.let {
val firstCategoryId = it.optLong("firstCategoryId")
val firstCategoryName = it.optString("firstCategoryName")
val secondCategoryId = it.optLong("secondCategoryId")
val secondCategoryName = it.optString("secondCategoryName")
if (firstCategoryId == 0L || firstCategoryName.isNullOrBlank() || secondCategoryId == 0L || secondCategoryName.isNullOrBlank()) {
XPageManager.push(XRouterPathConstants.CHOOSE_CATEGORY_ACTIVITY, null) XPageManager.push(XRouterPathConstants.CHOOSE_CATEGORY_ACTIVITY, null)
} else { return
val map = HashMap<String, Any?>()
map[ChooseCategoryActivity.lastSelectCategoryKey] = lastSelectCategory
XPageManager.push(XRouterPathConstants.CHOOSE_CATEGORY_ACTIVITY, map)
} }
val map = HashMap<String, Any>()
map[ChooseCategoryActivity.firstCategoryId] = firstCategoryId
map[ChooseCategoryActivity.firstCategoryName] = firstCategoryName
map[ChooseCategoryActivity.secondCategoryId] = secondCategoryId
map[ChooseCategoryActivity.secondCategoryName] = secondCategoryName
XPageManager.push(XRouterPathConstants.CHOOSE_CATEGORY_ACTIVITY, map)
} ?: XPageManager.push(XRouterPathConstants.CHOOSE_CATEGORY_ACTIVITY, null)
} }
@Subscribe(sticky = false, threadMode = ThreadMode.MAIN) @Subscribe(sticky = false, threadMode = ThreadMode.MAIN)
......
...@@ -50,8 +50,11 @@ class ChooseCategoryActivity : BaseMvvmActivity<CommodityActivityChooseCategoryB ...@@ -50,8 +50,11 @@ class ChooseCategoryActivity : BaseMvvmActivity<CommodityActivityChooseCategoryB
val paramsMap = intent?.getSerializableExtra(XRouterPathConstants.ParamsKey) val paramsMap = intent?.getSerializableExtra(XRouterPathConstants.ParamsKey)
paramsMap?.let { paramsMap?.let {
it as HashMap<*, *> it as HashMap<*, *>
val selectCategoryDto = it[lastSelectCategoryKey] as SelectCategoryDto val firstId = it[firstCategoryId] as Long
vm.setLastSelected(selectCategoryDto) val firstName = it[firstCategoryName] as String
val secondId = it[secondCategoryId] as Long
val secondName = it[secondCategoryName] as String
vm.setLastSelected(SelectCategoryDto(firstId, firstName, secondId, secondName))
} }
} }
...@@ -131,7 +134,10 @@ class ChooseCategoryActivity : BaseMvvmActivity<CommodityActivityChooseCategoryB ...@@ -131,7 +134,10 @@ class ChooseCategoryActivity : BaseMvvmActivity<CommodityActivityChooseCategoryB
} }
companion object { companion object {
const val lastSelectCategoryKey = "lastSelectCategory" const val firstCategoryId = "firstCategoryId"
const val firstCategoryName = "firstCategoryName"
const val secondCategoryId = "secondCategoryId"
const val secondCategoryName = "secondCategoryName"
} }
} }
...@@ -22,11 +22,11 @@ class ChooseCategoryViewModel : BaseViewModel() { ...@@ -22,11 +22,11 @@ class ChooseCategoryViewModel : BaseViewModel() {
// 选择的一级类目名称 // 选择的一级类目名称
var selectFirstCategoryName = MutableLiveData<String>() var selectFirstCategoryName = MutableLiveData<String>()
var selectFirstCategoryId = MutableLiveData<Int>() var selectFirstCategoryId = MutableLiveData<Long>()
// 选择的二级类目名称 // 选择的二级类目名称
var selectSecondCategoryName = MutableLiveData<String>() var selectSecondCategoryName = MutableLiveData<String>()
var selectSecondCategoryId = MutableLiveData<Int>() var selectSecondCategoryId = MutableLiveData<Long>()
var selectedCategory = MutableLiveData<SelectCategoryDto?>(null) var selectedCategory = MutableLiveData<SelectCategoryDto?>(null)
/** /**
......
...@@ -53,9 +53,7 @@ class PublishCouponsActivity : BaseMvvmActivity<CommodityActivityPublishCouponsB ...@@ -53,9 +53,7 @@ class PublishCouponsActivity : BaseMvvmActivity<CommodityActivityPublishCouponsB
"xbrid_coupon_publish?life_account_id=$lifeAccountId" "xbrid_coupon_publish?life_account_id=$lifeAccountId"
} }
// webView.loadUrl(webUrl) // webView.loadUrl(webUrl)
// webView.loadUrl("http://10.60.102.66:8080") webView.loadUrl("http://10.60.102.66:8080")
webView.loadUrl("http://10.60.100.85:8080")
// webView.loadUrl("https://www.baidu.com")
webView.webChromeClient = object : WebChromeClient() { webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) { override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress) super.onProgressChanged(view, newProgress)
......
...@@ -3,30 +3,30 @@ ...@@ -3,30 +3,30 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.yidian.shenghuoquan.commodity"> package="com.yidian.shenghuoquan.commodity">
<application <!-- <application-->
android:name=".app.CommodityApplication" <!-- android:name=".app.CommodityApplication"-->
android:allowBackup="true" <!-- android:allowBackup="true"-->
android:icon="@mipmap/ic_launcher" <!-- android:icon="@mipmap/ic_launcher"-->
android:label="商品组件" <!-- android:label="商品组件"-->
android:networkSecurityConfig="@xml/network_security_config" <!-- android:networkSecurityConfig="@xml/network_security_config"-->
android:roundIcon="@mipmap/ic_launcher_round" <!-- android:roundIcon="@mipmap/ic_launcher_round"-->
android:theme="@style/AppTheme" <!-- android:theme="@style/AppTheme"-->
tools:replace="android:allowBackup,android:label" <!-- tools:replace="android:allowBackup,android:label"-->
tools:targetApi="n"> <!-- tools:targetApi="n">-->
<activity <!-- <activity-->
android:name=".ui.coupon.ChooseCategoryActivity" <!-- android:name=".ui.coupon.ChooseCategoryActivity"-->
android:theme="@style/FlashTheme"> <!-- android:theme="@style/FlashTheme">-->
<intent-filter> <!-- <intent-filter>-->
<action android:name="android.intent.action.VIEW" /> <!-- <action android:name="android.intent.action.VIEW" />-->
<action android:name="android.intent.action.MAIN" /> <!-- <action android:name="android.intent.action.MAIN" />-->
<category android:name="android.intent.category.LAUNCHER" /> <!-- <category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter> <!-- </intent-filter>-->
</activity> <!-- </activity>-->
<activity <!-- <activity-->
android:name=".ui.coupon.CategorySearchActivity" <!-- android:name=".ui.coupon.CategorySearchActivity"-->
android:windowSoftInputMode="adjustPan" /> <!-- android:windowSoftInputMode="adjustPan" />-->
</application> <!-- </application>-->
</manifest> </manifest>
\ No newline at end of file
...@@ -35,12 +35,16 @@ class SelectStoreService : ZapService() { ...@@ -35,12 +35,16 @@ class SelectStoreService : ZapService() {
* 选择门店 * 选择门店
*/ */
private fun gotoSelectStore(params: JSONObject) { private fun gotoSelectStore(params: JSONObject) {
val lastSelectStore = params.optJSONArray("selectedStore") val lastSelectStoreArray = params.optJSONArray("selectedStore")
if (lastSelectStore == null) { if (lastSelectStoreArray == null || lastSelectStoreArray.length() <= 0) {
XPageManager.push(XRouterPathConstants.CHOOSE_STORE_ACTIVITY, null) XPageManager.push(XRouterPathConstants.CHOOSE_STORE_ACTIVITY, null)
} else { } else {
val list = mutableListOf<String>()
for (i in 0 until lastSelectStoreArray.length()) {
list.add(lastSelectStoreArray.getString(i))
}
val map = HashMap<String, Any?>() val map = HashMap<String, Any?>()
map[ChooseStoreActivity.lastSelectStoreKey] = lastSelectStore map[ChooseStoreActivity.lastSelectStoreKey] = list
XPageManager.push(XRouterPathConstants.CHOOSE_STORE_ACTIVITY, map) XPageManager.push(XRouterPathConstants.CHOOSE_STORE_ACTIVITY, map)
} }
} }
......
...@@ -34,7 +34,8 @@ class FlashActivity : BaseActivity<ActivityFlashBinding>(), IGetLifeAccountListC ...@@ -34,7 +34,8 @@ class FlashActivity : BaseActivity<ActivityFlashBinding>(), IGetLifeAccountListC
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
getPermissions() XPageManager.push(XRouterPathConstants.PUBLISH_COUPONS_ACTIVITY, null)
// getPermissions()
} }
private fun launcher() { private fun launcher() {
......
...@@ -88,7 +88,7 @@ class ChooseStoreActivity : BaseActivity<ActivityChooseStoreBinding>() { ...@@ -88,7 +88,7 @@ class ChooseStoreActivity : BaseActivity<ActivityChooseStoreBinding>() {
XPageManager.pop(null) XPageManager.pop(null)
} }
viewBind.include.tvMenu.text = "新增门店" viewBind.include.tvMenu.text = "新增门店"
viewBind.include.tvMenu.setTextColor(ContextCompat.getColor(this, R.color.color_661852F1)) viewBind.include.tvMenu.setTextColor(ContextCompat.getColor(this, R.color.color_1852F1))
viewBind.include.tvMenu.clickAntiShake { viewBind.include.tvMenu.clickAntiShake {
val intent = Intent(this, EditStoreActivity::class.java) val intent = Intent(this, EditStoreActivity::class.java)
intent.putExtra("from", EditStoreActivity.fromAddStore) intent.putExtra("from", EditStoreActivity.fromAddStore)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<include <include
......
...@@ -14,7 +14,6 @@ android { ...@@ -14,7 +14,6 @@ android {
versionCode rootProject.ext.android.versionCode versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName versionName rootProject.ext.android.versionName
buildConfigField("boolean", "IS_ENCRYPT_DEBUG_KEY", rootProject.ext.android.isEncryptDebugKey) buildConfigField("boolean", "IS_ENCRYPT_DEBUG_KEY", rootProject.ext.android.isEncryptDebugKey)
buildConfigField("boolean", "IS_APP_UPGRADE_ONLINE", rootProject.ext.android.isAppUpgradeOnline)
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [qqappid: "101923771"] manifestPlaceholders = [qqappid: "101923771"]
......
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