Commit 0791daf6 authored by shiyl's avatar shiyl

通过XBrid调用原生页面

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