Commit 6587819a by Wyh

3-28 長連接接單

parent b3a5330a
apply from: rootProject.file('cc-settings.gradle')
//apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
// compileSdkVersion 28
defaultConfig {
if (project.ext.runAsApp) {
applicationId "com.gingersoft.gsa.other_order_mode"
}
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode rootProject.ext.android["versionCode"]
versionName rootProject.ext.android["versionName"]
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
// alternatively, just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha01"
//协程
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
//gson和scalars轉換器
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.gingersoft.gsa.other_order_mode
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.gingersoft.gsa.other_order_mode", appContext.packageName)
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gingersoft.gsa.other_order_mode">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".OtherOrderActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.GetInfoUpdateService" />
</application>
</manifest>
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.os.IBinder
import android.os.Looper
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager.widget.ViewPager
import com.gingersoft.gsa.other_order_mode.service.GetInfoUpdateService
import com.gingersoft.gsa.other_order_mode.ui.main.PageViewModel
import com.gingersoft.gsa.other_order_mode.ui.main.SectionsPagerAdapter
import com.gingersoft.gsa.other_order_mode.util.InjectorUtil
import kotlinx.android.synthetic.main.activity_other_order.*
class OtherOrderActivity : AppCompatActivity() {
private lateinit var pageViewModel: PageViewModel
private val instance by lazy { this }
private val ints = arrayOf(
R.string.tab_text_1,
R.string.tab_text_2,
R.string.tab_text_3,
R.string.tab_text_4,
R.string.tab_text_5
)
private val colors = arrayOf(
"#FF5722",
"#009688",
"#1E9FFF",
"#FFB800",
"#393D49"
)
private var titls: ArrayList<TextView> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_other_order)
var intent = Intent(this, GetInfoUpdateService::class.java)
// startService(intent)
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
pageViewModel = ViewModelProvider(this, InjectorUtil.getWeatherModelFactory())[PageViewModel::class.java]
initAppTop()
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager, ints)
val viewPager: ViewPager = findViewById(R.id.view_pager)
viewPager.adapter = sectionsPagerAdapter
viewPager.offscreenPageLimit = 4
tabs.setupWithViewPager(viewPager)
for (i in 0 until ints.size) {
//获取每一个tab对象
val tabAt = tabs.getTabAt(i)
if (tabAt != null) {
//将每一个条目设置我们自定义的视图
tabAt.setCustomView(R.layout.layout_table_count_item)
//通过tab对象找到自定义视图的ID
val mTvTitle = tabAt.customView!!.findViewById<TextView>(R.id.tv_table_item_title)
val mNumber = tabAt.customView!!.findViewById<TextView>(R.id.tv_table_item_num)
titls.add(mNumber)
mTvTitle.setText(ints[i])
val drawable = GradientDrawable()
drawable.setColor(Color.parseColor(colors[i]))
drawable.cornerRadius = 5f
mNumber.background = drawable
mNumber.text = "0"
when (i) {
0 -> pageViewModel.allOrderNum.observe(instance, Observer {
mNumber.text = it
Log.e("aaa", "接收到訂單數變化$it")
})
1 -> pageViewModel.toBeConfirmedNum.observe(instance, Observer {
mNumber.text = it
Log.e("aaa", "接收到待確認訂單數變化$it")
})
2 -> pageViewModel.makingNum.observe(instance, Observer {
mNumber.text = it
Log.e("aaa", "接收到製作中訂單數變化$it")
})
3 -> pageViewModel.inDeliveryNum.observe(instance, Observer {
mNumber.text = it
Log.e("aaa", "接收到送貨中訂單數變化$it")
})
4 -> pageViewModel.waitingForMealNum.observe(instance, Observer {
mNumber.text = it
Log.e("aaa", "接收到待取餐訂單數變化$it")
})
}
}
}
}
private var serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
var bind: GetInfoUpdateService.MyBind = service as GetInfoUpdateService.MyBind
bind.setOnPostCallBack(object : GetInfoUpdateService.PostCallBack {
override fun callBack(type: Int) {
Log.e("aaa", "類型:$type")
//-1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知"
if (type == 3 || type == 4 || type == 5
|| type == 6 || type == 7) {
Looper.prepare()
pageViewModel.refreshState.value = pageViewModel.refreshState.value?.plus(1)
Looper.loop()
}
}
})
}
override fun onServiceDisconnected(name: ComponentName) {
}
}
private fun initAppTop() {
qm_other_order_bar.setTitle(R.string.app_name)
qm_other_order_bar.addLeftImageButton(R.drawable.icon_return, R.id.iv_left_back).setOnClickListener { finish() }
qm_other_order_bar.setBackgroundColor(resources.getColor(R.color.theme_color))
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data
import com.gingersoft.gsa.other_order_mode.data.network.CoolWeatherNetwork
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.FormBody
class WeatherRepository private constructor(private val network: CoolWeatherNetwork) {
suspend fun requestOrderList(status: String, type: String) = withContext(Dispatchers.IO) {
val requestBody = FormBody.Builder()
.add("restaurantId", "26")
.add("page", "1")
.add("status", status)
.add("orderNo", "")
.add("phone", "")
.add("type", type)
.build()
val heWeather = network.fetchOrderList(requestBody)
heWeather
}
companion object {
private lateinit var instance: WeatherRepository
fun getInstance(network: CoolWeatherNetwork): WeatherRepository {
if (!::instance.isInitialized) {
synchronized(WeatherRepository::class.java) {
if (!::instance.isInitialized) {
instance = WeatherRepository(network)
}
}
}
return instance
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data.model.bean
class MessageBean {
private var data: String? = null
get() = field
set(value) {
field = value
}
private var password: String? = null
get() = field
set(value) {
field = value
}
private var token: String? = null
get() = field
set(value) {
field = value
}
private var type: Int? = null
get() = field
set(value) {
field = value
}
private var username: String? = null
get() = field
set(value) {
field = value
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data.model.bean
class OrderList {
/**
* success : true
* sysTime : 1585282096866
* data : {"data":[{"STATUS":0,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港荔枝角青山道479號麗昌工廠大廈2樓201L室Innovation Design Consultant Ltd.1111","PAY_AMOUNT":89,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200411316057124","Id":48883,"CREATE_TIME":"Mar 27, 2020 12:07:49 PM","takeFoodCode":"0","order_type":2,"RECEIVER":"有 女士"},{"STATUS":3,"MEMBER_NAME":"你好哦","ADDRESS_DETAIL":"香港長沙灣青山道479號麗昌工業大廈303","PAY_AMOUNT":128,"PHONE":"13554770615","orderPayType":1,"ORDER_NO":"26202501369354194","Id":48880,"CREATE_TIME":"Mar 27, 2020 11:43:53 AM","takeFoodCode":"0055","order_type":2,"RECEIVER":"劉先生 先生"},{"STATUS":2,"MEMBER_NAME":"你好哦","ADDRESS_DETAIL":"美國紐約州紐約123123","PAY_AMOUNT":128,"PHONE":"13554770615","orderPayType":1,"ORDER_NO":"26200341332451819","Id":48879,"CREATE_TIME":"Mar 27, 2020 11:39:08 AM","takeFoodCode":"0","order_type":2,"RECEIVER":"asdfasdf 先生"},{"STATUS":3,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港禮頓山禮頓道8號8號 59864香港銅鑼灣皇冠假日酒店一","PAY_AMOUNT":384,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200681397655588","Id":48875,"CREATE_TIME":"Mar 27, 2020 11:33:19 AM","takeFoodCode":"0052","order_type":2,"RECEIVER":"說 先生"},{"STATUS":2,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港半山堅尼地道28號香港特別行政區前任行政長官辦公室111","PAY_AMOUNT":228,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200031363851774","Id":48874,"CREATE_TIME":"Mar 27, 2020 11:33:01 AM","takeFoodCode":"0051","order_type":2,"RECEIVER":"特別 女士"},{"STATUS":3,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港鵝頸駱克道463-464號銅鑼灣廣場二期123","PAY_AMOUNT":128,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26201261317059894","Id":48873,"CREATE_TIME":"Mar 27, 2020 11:31:37 AM","takeFoodCode":"0050","order_type":2,"RECEIVER":"杜 先生"},{"STATUS":2,"MEMBER_NAME":"許立燦","ADDRESS_DETAIL":"香港島大坑電腦大廈","PAY_AMOUNT":78,"PHONE":"18938995556","orderPayType":2,"ORDER_NO":"26202381350555250","Id":48866,"CREATE_TIME":"Mar 27, 2020 10:53:45 AM","takeFoodCode":"0046","order_type":2,"RECEIVER":"許 先生"},{"STATUS":2,"MEMBER_NAME":"許立燦","ADDRESS_DETAIL":"香港島中環餐飲服務公司","PAY_AMOUNT":88,"PHONE":"18938995556","orderPayType":2,"ORDER_NO":"26201801340350065","Id":48854,"CREATE_TIME":"Mar 27, 2020 10:44:41 AM","takeFoodCode":"0045","order_type":2,"RECEIVER":"12345 先生"},{"MaxOrder":200,"selflNum":35,"totalAmount":78,"maxOrderSelf":100,"num":111,"dayOrderNum":1,"Open_Status":"1"}],"count":0,"page":{"pageIndex":1,"pageSize":10,"pageCount":0,"totalCount":8}}
*/
private var success: Boolean = false
private var sysTime: Long = 0
private var data: DataBeanX? = null
class DataBeanX {
/**
* data : [{"STATUS":0,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港荔枝角青山道479號麗昌工廠大廈2樓201L室Innovation Design Consultant Ltd.1111","PAY_AMOUNT":89,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200411316057124","Id":48883,"CREATE_TIME":"Mar 27, 2020 12:07:49 PM","takeFoodCode":"0","order_type":2,"RECEIVER":"有 女士"},{"STATUS":3,"MEMBER_NAME":"你好哦","ADDRESS_DETAIL":"香港長沙灣青山道479號麗昌工業大廈303","PAY_AMOUNT":128,"PHONE":"13554770615","orderPayType":1,"ORDER_NO":"26202501369354194","Id":48880,"CREATE_TIME":"Mar 27, 2020 11:43:53 AM","takeFoodCode":"0055","order_type":2,"RECEIVER":"劉先生 先生"},{"STATUS":2,"MEMBER_NAME":"你好哦","ADDRESS_DETAIL":"美國紐約州紐約123123","PAY_AMOUNT":128,"PHONE":"13554770615","orderPayType":1,"ORDER_NO":"26200341332451819","Id":48879,"CREATE_TIME":"Mar 27, 2020 11:39:08 AM","takeFoodCode":"0","order_type":2,"RECEIVER":"asdfasdf 先生"},{"STATUS":3,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港禮頓山禮頓道8號8號 59864香港銅鑼灣皇冠假日酒店一","PAY_AMOUNT":384,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200681397655588","Id":48875,"CREATE_TIME":"Mar 27, 2020 11:33:19 AM","takeFoodCode":"0052","order_type":2,"RECEIVER":"說 先生"},{"STATUS":2,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港半山堅尼地道28號香港特別行政區前任行政長官辦公室111","PAY_AMOUNT":228,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26200031363851774","Id":48874,"CREATE_TIME":"Mar 27, 2020 11:33:01 AM","takeFoodCode":"0051","order_type":2,"RECEIVER":"特別 女士"},{"STATUS":3,"MEMBER_NAME":"觉得很多很多","ADDRESS_DETAIL":"香港鵝頸駱克道463-464號銅鑼灣廣場二期123","PAY_AMOUNT":128,"PHONE":"15899876018","orderPayType":1,"ORDER_NO":"26201261317059894","Id":48873,"CREATE_TIME":"Mar 27, 2020 11:31:37 AM","takeFoodCode":"0050","order_type":2,"RECEIVER":"杜 先生"},{"STATUS":2,"MEMBER_NAME":"許立燦","ADDRESS_DETAIL":"香港島大坑電腦大廈","PAY_AMOUNT":78,"PHONE":"18938995556","orderPayType":2,"ORDER_NO":"26202381350555250","Id":48866,"CREATE_TIME":"Mar 27, 2020 10:53:45 AM","takeFoodCode":"0046","order_type":2,"RECEIVER":"許 先生"},{"STATUS":2,"MEMBER_NAME":"許立燦","ADDRESS_DETAIL":"香港島中環餐飲服務公司","PAY_AMOUNT":88,"PHONE":"18938995556","orderPayType":2,"ORDER_NO":"26201801340350065","Id":48854,"CREATE_TIME":"Mar 27, 2020 10:44:41 AM","takeFoodCode":"0045","order_type":2,"RECEIVER":"12345 先生"},{"MaxOrder":200,"selflNum":35,"totalAmount":78,"maxOrderSelf":100,"num":111,"dayOrderNum":1,"Open_Status":"1"}]
* count : 0
* page : {"pageIndex":1,"pageSize":10,"pageCount":0,"totalCount":8}
*/
var count: Int = 0
var page: PageBean? = null
var data: List<DataBean>? = null
class PageBean {
/**
* pageIndex : 1
* pageSize : 10
* pageCount : 0
* totalCount : 8
*/
var pageIndex: Int = 0
var pageSize: Int = 0
var pageCount: Int = 0
var totalCount: Int = 0
}
class DataBean {
/**
* STATUS : 0
* MEMBER_NAME : 觉得很多很多
* ADDRESS_DETAIL : 香港荔枝角青山道479號麗昌工廠大廈2樓201L室Innovation Design Consultant Ltd.1111
* PAY_AMOUNT : 89.0
* PHONE : 15899876018
* orderPayType : 1
* ORDER_NO : 26200411316057124
* Id : 48883
* CREATE_TIME : Mar 27, 2020 12:07:49 PM
* takeFoodCode : 0
* order_type : 2
* RECEIVER : 有 女士
* MaxOrder : 200
* selflNum : 35
* totalAmount : 78.0
* maxOrderSelf : 100
* num : 111
* dayOrderNum : 1
* Open_Status : 1
*/
var status: Int = 0
var membeR_NAME: String? = null
var addresS_DETAIL: String? = null
var paY_AMOUNT: Double = 0.toDouble()
var phone: String? = null
var orderPayType: Int = 0
var ordeR_NO: String? = null
var id: Int = 0
var creatE_TIME: String? = null
var takeFoodCode: String? = null
var order_type: Int = 0
var receiver: String? = null
var maxOrder: Int = 0
var selflNum: Int = 0
var totalAmount: Double = 0.toDouble()
var maxOrderSelf: Int = 0
var num: Int = 0
var dayOrderNum: Int = 0
var open_Status: String? = null
}
}
fun isSuccess(): Boolean {
return success
}
fun setSuccess(success: Boolean) {
this.success = success
}
fun getSysTime(): Long {
return sysTime
}
fun setSysTime(sysTime: Long) {
this.sysTime = sysTime
}
fun getData(): DataBeanX? {
return data
}
fun setData(data: DataBeanX) {
this.data = data
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data.network
import com.gingersoft.gsa.other_order_mode.data.network.api.WeatherService
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
class CoolWeatherNetwork {
private val orderService = ServiceCreator.create(WeatherService::class.java)
suspend fun fetchOrderList(requestBody: RequestBody) = orderService.getOrderList(requestBody).await()
private suspend fun <T> Call<T>.await(): T {
return suspendCoroutine { continuation ->
enqueue(object : Callback<T> {
override fun onFailure(call: Call<T>, t: Throwable) {
continuation.resumeWithException(t)
}
override fun onResponse(call: Call<T>, response: Response<T>) {
val body = response.body()
if (body != null) continuation.resume(body)
else continuation.resumeWithException(RuntimeException("response body is null"))
}
})
}
}
companion object {
private var network: CoolWeatherNetwork? = null
fun getInstance(): CoolWeatherNetwork {
if (network == null) {
synchronized(CoolWeatherNetwork::class.java) {
if (network == null) {
network = CoolWeatherNetwork()
}
}
}
return network!!
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data.network
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
object ServiceCreator {
private const val BASE_URL = "https://hktest.ricepon.com:64377/ricepon-wechat/api/"
private val httpClient = OkHttpClient.Builder()
private val builder = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(httpClient.build())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
private val retrofit = builder.build()
fun <T> create(serviceClass: Class<T>): T = retrofit.create(serviceClass)
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.data.network.api
import com.gingersoft.gsa.other_order_mode.data.model.bean.OrderList
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST
interface WeatherService {
@POST("wechat/findOrderList")
fun getOrderList(@Body requestBody: RequestBody): Call<OrderList>
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.model
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gingersoft.gsa.other_order_mode.data.WeatherRepository
import com.gingersoft.gsa.other_order_mode.ui.main.PageViewModel
class WeatherModelFactory(private val repository: WeatherRepository) : ViewModelProvider.NewInstanceFactory() {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return PageViewModel(repository) as T
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.service
import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.Handler
import android.os.IBinder
import android.util.Log
import okhttp3.*
import okio.ByteString
import org.json.JSONObject
import java.util.concurrent.TimeUnit
class GetInfoUpdateService : Service() {
/**
* 心跳检测时间
*/
private val HEART_BEAT_RATE = (15 * 1000).toLong()//每隔15秒进行一次对长连接的心跳检测
private val WEBSOCKET_HOST_AND_PORT = "https://hktest.ricepon.com:64377/ricepon-websocket/js/webSocketServer"//可替换为自己的主机名和端口号
private var mWebSocket: WebSocket? = null
private val sendMsg = "{\"type\":1,\"token\":\"weixin_26_7xjmv0geea1111111111\"}"
var postCallBack: PostCallBack? = null
override fun onBind(intent: Intent?): IBinder? {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
return MyBind()
}
interface PostCallBack {
fun callBack(type: Int)
}
inner class MyBind : Binder() {
fun getService(): GetInfoUpdateService {
return this@GetInfoUpdateService
}
fun setOnPostCallBack(postCallBack: PostCallBack?){
this@GetInfoUpdateService.postCallBack = postCallBack
}
}
override fun onCreate() {
super.onCreate()
InitSocketThread().start()
isDestroy = false
}
internal inner class InitSocketThread : Thread() {
override fun run() {
super.run()
initSocket()
}
}
// 初始化socket
private fun initSocket() {
val client = OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).build()
val request = Request.Builder()
.url(WEBSOCKET_HOST_AND_PORT)
.build()
client.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket?, response: Response?) {//开启长连接成功的回调
super.onOpen(webSocket, response)
mWebSocket = webSocket
webSocket!!.send(sendMsg)
Log.e("aaa", "onOpen$sendMsg")
}
override fun onMessage(webSocket: WebSocket?, text: String?) {//接收消息的回调
super.onMessage(webSocket, text)
val json = JSONObject(text)
if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type"))
}
//收到服务器端传过来的消息text
Log.e("aaa", "onMessage:" + text!!)
}
override fun onMessage(webSocket: WebSocket?, bytes: ByteString?) {
super.onMessage(webSocket, bytes)
val json = JSONObject(bytes.toString())
if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type"))
}
Log.e("aaa", "onMessage222:" + bytes!!)
}
override fun onClosing(webSocket: WebSocket?, code: Int, reason: String?) {
super.onClosing(webSocket, code, reason)
//連接斷開,
Log.e("aaa", "onClosing")
InitSocketThread().start()//创建一个新的连接
}
override fun onClosed(webSocket: WebSocket?, code: Int, reason: String?) {
super.onClosed(webSocket, code, reason)
Log.e("aaa", "onClosed")
}
override fun onFailure(webSocket: WebSocket?, t: Throwable?, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response)
Log.e("aaa", "onFailure" + t!!.message)
}
})
client.dispatcher().executorService().shutdown()
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE)//开启心跳检测
}
private var sendTime = 0L
// 发送心跳包
private val mHandler = Handler()
private val heartBeatRunnable = object : Runnable {
override fun run() {
if (!isDestroy) {
if (System.currentTimeMillis() - sendTime >= HEART_BEAT_RATE) {
val isSuccess = mWebSocket?.send("0")//发送一个空消息给服务器,通过发送消息的成功失败来判断长连接的连接状态
Log.e("aaa", "連接狀態:$isSuccess")
if (!isSuccess!!) {//长连接已断开
mHandler.removeCallbacks(this)
mWebSocket?.cancel()//取消掉以前的长连接
InitSocketThread().start()//创建一个新的连接
} else {//长连接处于连接状态
}
sendTime = System.currentTimeMillis()
}
mHandler.postDelayed(this, HEART_BEAT_RATE)//每隔一定的时间,对长连接进行一次心跳检测
}
}
}
private var isDestroy = false
override fun onDestroy() {
super.onDestroy()
Log.e("aaa", "onDestroy")
isDestroy = true
if (mWebSocket != null) {
mWebSocket!!.send("-1")
mWebSocket!!.close(1000, null)
mHandler.removeCallbacks(heartBeatRunnable)
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.ui.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Adapter
import com.gingersoft.gsa.other_order_mode.R
import com.gingersoft.gsa.other_order_mode.data.model.bean.OrderList
class OtherOrdersAdapter : Adapter<OtherOrdersAdapter.ViewHolder>() {
var databeans: List<OrderList.DataBeanX.DataBean>? = null
fun setData(databeans: List<OrderList.DataBeanX.DataBean>) {
this.databeans = databeans
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_other_order_item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
}
override fun getItemCount(): Int {
return if (databeans == null) {
0
} else {
databeans!!.size
}
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.ui.main
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.gingersoft.gsa.other_order_mode.data.WeatherRepository
import com.gingersoft.gsa.other_order_mode.data.model.bean.OrderList
import kotlinx.coroutines.launch
class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
companion object {
var allOrderStatus: String = "0,1,2,3"
var allOrderType: String = "0"
var toBeConfirmedStatus: String = "0,1"
var toBeConfirmedType: String = "0"
var makingStatus: String = "2"
var makingType: String = "0"
var inDeliveryStatus: String = "3"
var inDeliveryType: String = "2"
var waitingForMealStatus: String = "3"
var waitingForMealType: String = "7"
}
var allOrderList = MutableLiveData<List<OrderList.DataBeanX.DataBean>>()
var toBeConfirmedOrderList = MutableLiveData<List<OrderList.DataBeanX.DataBean>>()
var makingOrderList = MutableLiveData<List<OrderList.DataBeanX.DataBean>>()
var inDeliveryOrderList = MutableLiveData<List<OrderList.DataBeanX.DataBean>>()
var waitingForMealOrderList = MutableLiveData<List<OrderList.DataBeanX.DataBean>>()
//總訂單數量
var allOrderNum = MutableLiveData<String>()
//待確認訂單數量
var toBeConfirmedNum = MutableLiveData<String>()
//製作中的訂單數量
var makingNum = MutableLiveData<String>()
//送貨中的訂單數量
var inDeliveryNum = MutableLiveData<String>()
//待取餐的訂單數量
var waitingForMealNum = MutableLiveData<String>()
//營業狀態,1為營業中,2為休息中
lateinit var businessStatus: String
//外賣訂單數 100/200
lateinit var takeawayOrders: String
//自取訂單數 50/200
lateinit var pickUpOrders: String
//今日訂單總數
lateinit var todayOrderNum: String
//今日營業額
lateinit var todayTurnover: String
//刷新狀態,有數據更新就會更改這個變量,將這個變量修改為allOrderStatus...上面五種狀態,fragment中監聽這個變量,再調用接口獲取最新數據
var refreshState = MutableLiveData<Int>()
var refreshType: String = "0"
var orderList = MutableLiveData<OrderList>()
fun getOrderList(status: String, type: String, position: Int) {
Log.e("aaa", status + "請求" + type)
launch({
repository.requestOrderList(status, type).apply {
Log.e("aaa", "數據:")
if (getData() != null && getData()?.data != null) {
val myData: ArrayList<OrderList.DataBeanX.DataBean> = getData()?.data as ArrayList<OrderList.DataBeanX.DataBean>
if (myData.isNotEmpty()) {
//取得最後一個對象,裡面有營業狀態和外賣訂單數,自取訂單數
val dataBean: OrderList.DataBeanX.DataBean = myData[myData.size - 1]
if (dataBean.open_Status != null) {
businessStatus = dataBean.open_Status!!
}
takeawayOrders = "本月外賣訂單數:" + dataBean.num + "/" + dataBean.maxOrder
pickUpOrders = "本月自取訂單數:" + dataBean.selflNum + "/" + dataBean.maxOrderSelf
todayOrderNum = dataBean.dayOrderNum.toString()
todayTurnover = dataBean.totalAmount.toString()
myData.removeAt(myData.size - 1)
Log.e("aaa", "數據:" + myData.size)
if (status == allOrderStatus) {
allOrderList.value = myData
Log.e("aaa", "全部訂單數變化" + allOrderNum.value)
allOrderNum.value = (myData.size).toString()
} else if (status == toBeConfirmedStatus) {
Log.e("aaa", "待確認訂單數變化" + (myData.size).toString())
toBeConfirmedOrderList.value = myData
toBeConfirmedNum.value = (myData.size).toString()
} else if (status == makingStatus) {
makingOrderList.value = myData
Log.e("aaa", "製作中訂單數變化" + (myData.size).toString())
makingNum.value = (myData.size).toString()
} else if (status == inDeliveryStatus || status == waitingForMealStatus) {
if (type == "2") {
//送貨中
inDeliveryOrderList.value = myData
Log.e("aaa", "送貨中訂單數變化" + (myData.size).toString())
inDeliveryNum.value = (myData.size).toString()
} else {
//待取餐
waitingForMealOrderList.value = myData
Log.e("aaa", "待取餐訂單數變化" + (myData.size).toString())
waitingForMealNum.value = (myData.size).toString()
}
}
} else {
Log.e("aaa", "數據為空")
}
}
}
}, {
//出錯
})
}
private fun launch(block: suspend () -> Unit, error: suspend (Throwable) -> Unit) = viewModelScope.launch {
try {
block()
} catch (e: Throwable) {
error(e)
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.ui.main
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.gingersoft.gsa.other_order_mode.R
import com.gingersoft.gsa.other_order_mode.ui.adapter.OtherOrdersAdapter
import com.gingersoft.gsa.other_order_mode.util.InjectorUtil
import kotlinx.android.synthetic.main.fragment_other_order.*
/**
* A placeholder fragment containing a simple view.
*/
class PlaceholderFragment : Fragment() {
private lateinit var pageViewModel: PageViewModel
private lateinit var textView: TextView
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
pageViewModel = ViewModelProvider(activity?.viewModelStore!!, InjectorUtil.getWeatherModelFactory())[PageViewModel::class.java].apply {
getOrderList(this)
refreshState.observe(viewLifecycleOwner, Observer {
//觸發刷新,判斷是否更新
// if (it == arguments?.getString(STATUS) && pageViewModel.refreshType == arguments?.getString(TYPE)) {
//如果狀態和當前fragment狀態一致,並且type一致,刷新數據
getOrderList(this)
// }
})
}
rv_other_order.layoutManager = LinearLayoutManager(activity)
var adapter = OtherOrdersAdapter()
rv_other_order.adapter = adapter
if (arguments?.getString(STATUS) == PageViewModel.allOrderStatus) {
pageViewModel.allOrderList.observe(viewLifecycleOwner, Observer {
it.let { it1 -> adapter.setData(it1) }
})
} else if (arguments?.getString(STATUS) == PageViewModel.toBeConfirmedStatus) {
pageViewModel.toBeConfirmedOrderList.observe(viewLifecycleOwner, Observer {
it.let { it1 -> adapter.setData(it1) }
})
} else if (arguments?.getString(STATUS) == PageViewModel.makingStatus) {
pageViewModel.makingOrderList.observe(viewLifecycleOwner, Observer {
it.let { it1 -> adapter.setData(it1) }
})
} else if (arguments?.getString(STATUS) == PageViewModel.inDeliveryStatus || arguments?.getString(STATUS) == PageViewModel.waitingForMealStatus) {
if (arguments?.getString(TYPE) == "2") {
//送貨中
pageViewModel.inDeliveryOrderList.observe(viewLifecycleOwner, Observer {
it.let { it1 -> adapter.setData(it1) }
})
} else {
//待取餐
pageViewModel.waitingForMealOrderList.observe(viewLifecycleOwner, Observer {
it.let { it1 -> adapter.setData(it1) }
})
}
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val root = inflater.inflate(R.layout.fragment_other_order, container, false)
return root
}
private fun getOrderList(pageViewModel: PageViewModel) {
pageViewModel.getOrderList(arguments?.getString(STATUS)
?: "", arguments?.getString(TYPE)
?: "", arguments?.getInt(INDEX) ?: 0)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
}
companion object {
private const val STATUS = "status"
private const val TYPE = "type"
private const val INDEX = "index"
@JvmStatic
fun newInstance(status: String, type: String, position: Int): PlaceholderFragment {
return PlaceholderFragment().apply {
arguments = Bundle().apply {
putString(STATUS, status)
putString(TYPE, type)
putInt(INDEX, position)
}
}
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.ui.main
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager, var titles: Array<Int>)
: FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
//BEHAVIOR_SET_USER_VISIBLE_HINT 时,Fragment切换时,会触发setUserVisibleHint。與舊版一致,是廢棄地
//BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT 会用到生命周期状态标识Lifecycle.State。
//Fragment初始化的时候,默认会执行到onResume(),而AndroidX只会执行到onStart(),所以我们迁移到AndroidX之后
// ,不需要全都依靠setUserVisibleHint()来判断当前页面是否显示,我们可以根据onResume()来判断。
override fun getItem(position: Int): Fragment {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
var status = "0"
var type = "0"
when (position) {
0 -> {
status = PageViewModel.allOrderStatus
type = PageViewModel.allOrderType
}
1 -> {
status = PageViewModel.toBeConfirmedStatus
type = PageViewModel.toBeConfirmedType
}
2 -> {
status = PageViewModel.makingStatus
type = PageViewModel.makingType
}
3 -> {
status = PageViewModel.inDeliveryStatus
type = PageViewModel.inDeliveryType
}
4 -> {
status = PageViewModel.waitingForMealStatus
type = PageViewModel.waitingForMealType
}
}
return PlaceholderFragment.newInstance(status, type, position)
}
override fun getPageTitle(position: Int): CharSequence? {
return context.resources.getString(titles[position])
}
override fun getCount(): Int {
// Show 5 total pages.
return 5
}
}
\ No newline at end of file
package com.gingersoft.gsa.other_order_mode.util
import com.gingersoft.gsa.other_order_mode.data.WeatherRepository
import com.gingersoft.gsa.other_order_mode.data.network.CoolWeatherNetwork
import com.gingersoft.gsa.other_order_mode.model.WeatherModelFactory
object InjectorUtil {
fun getWeatherModelFactory() = WeatherModelFactory(getWeatherRepository())
private fun getWeatherRepository() = WeatherRepository.getInstance(CoolWeatherNetwork.getInstance())
}
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent"
tools:context=".OtherOrderActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/qm_other_order_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/head_height"
android:fitsSystemWindows="true"
app:qmui_topbar_text_btn_color_state_list="@color/theme_white_color"
app:qmui_topbar_title_color="@color/theme_white_color" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_f0"
app:tabPaddingEnd="-1dp"
app:tabPaddingStart="-1dp" />
<!--item無法填滿左右時,加入下面這兩個-->
<!-- app:tabPaddingStart="-1dp"-->
<!-- app:tabPaddingEnd="-1dp"-->
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:visibility="gone"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_other_order"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.lihang.ShadowLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hl_cornerRadius="@dimen/dp_8"
app:hl_shadowLimit="@dimen/dp_5">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/dp_10"
android:paddingTop="@dimen/dp_5"
android:paddingRight="@dimen/dp_10"
android:paddingBottom="@dimen/dp_10">
<TextView
android:id="@+id/tv_payment_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="貨到付款"
android:textColor="@color/white"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_ordering_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:text="外"
android:textColor="@color/white"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toRightOf="@id/tv_payment_method"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_order_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="123456"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_ordering_method" />
<TextView
android:id="@+id/tv_order_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:text="2020-03-28 14:59:11"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintBottom_toBottomOf="@id/tv_order_user_name"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_order_user_name" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier_order_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:barrierDirection="right"
app:constraint_referenced_ids="tv_address_text,tv_cellphone_num_text,tv_order_num_text" />
<TextView
android:id="@+id/tv_cellphone_num_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="手機號:"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_order_user_name" />
<TextView
android:id="@+id/tv_cellphone_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:text="18938995556"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toRightOf="@id/barrier_order_info"
app:layout_constraintTop_toTopOf="@id/tv_cellphone_num_text" />
<TextView
android:id="@+id/tv_order_num_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_2"
android:layout_marginTop="@dimen/dp_5"
android:text="訂單號:"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="@id/tv_cellphone_num_text"
app:layout_constraintTop_toBottomOf="@id/tv_cellphone_num_text" />
<TextView
android:id="@+id/tv_order_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18938995556"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="@id/tv_cellphone_num"
app:layout_constraintTop_toTopOf="@id/tv_order_num_text" />
<TextView
android:id="@+id/tv_order_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="製作中"
app:layout_constraintBottom_toBottomOf="@id/tv_order_num_text"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_cellphone_num_text" />
<TextView
android:id="@+id/tv_address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_2"
android:layout_marginTop="@dimen/dp_5"
android:text="地址:"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_order_num_text" />
<TextView
android:id="@+id/tv_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="香港島中環餐飲服務公司"
android:textColor="@color/color_ccc"
android:textSize="@dimen/sp_12"
app:layout_constraintLeft_toLeftOf="@id/tv_cellphone_num"
app:layout_constraintTop_toTopOf="@id/tv_address_text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$88.0"
android:textColor="@color/red_600"
android:textSize="@dimen/sp_14"
app:layout_constraintBottom_toBottomOf="@id/tv_address"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_address" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.lihang.ShadowLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_table_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全部"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_14" />
<TextView
android:id="@+id/tv_table_item_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:padding="@dimen/dp_5"
android:text="11"
android:textColor="@color/white"
android:textSize="@dimen/dp_12" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>
<resources>
<string name="app_name">訂單管理</string>
<string name="tab_text_1">全部</string>
<string name="tab_text_2">待確認</string>
<string name="tab_text_3">製作中</string>
<string name="tab_text_4">送貨中</string>
<string name="tab_text_5">待取餐</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
package com.gingersoft.gsa.other_order_mode
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
...@@ -76,7 +76,17 @@ public class IpPrintActivity extends Activity implements PrintSocketHolder.OnSta ...@@ -76,7 +76,17 @@ public class IpPrintActivity extends Activity implements PrintSocketHolder.OnSta
initDialog(); initDialog();
initIntent(); initIntent();
callId = getIntent().getStringExtra(EXTRA_KEY_CALL_ID); callId = getIntent().getStringExtra(EXTRA_KEY_CALL_ID);
printOrder(this); if (type == 3) {
//廚房單,可能會有多個IP打印
//獲得ip打印列表,
//再將食品數據根據打印位置分組。
//打印一組之後,關閉連接,切換第二台打印機ip,如此循環
//打印完成之後,返回所有打印結果。
} else {
printOrder(this);
}
} }
......
...@@ -107,7 +107,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -107,7 +107,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
} }
int paperWidth = 500; int paperWidth = 500;
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
callId = CCUtil.getNavigateCallId(this); callId = CCUtil.getNavigateCallId(this);
...@@ -171,9 +170,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -171,9 +170,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
public void initLayout(ViewHepler hepler, Dialog dialog) { public void initLayout(ViewHepler hepler, Dialog dialog) {
dialogCount++; dialogCount++;
hepler.setViewClick(R.id.local_print, v -> { hepler.setViewClick(R.id.local_print, v -> {
// for (int i = 0; i < bitmaps.size(); i++) { locationPrint(bitmaps);
locationPrint(bitmaps);
// }
//修改默認打印方式為本地 //修改默認打印方式為本地
SPUtils.put(mContext, Constans.DEFAULT_PRINT_METHOD, Constans.LOCAL_PRINT); SPUtils.put(mContext, Constans.DEFAULT_PRINT_METHOD, Constans.LOCAL_PRINT);
dialog.dismiss(); dialog.dismiss();
......
package com.gingersoft.gsa.cloud.aspectj; package com.gingersoft.gsa.cloud.aspectj;
import android.app.Dialog;
import android.view.View;
import com.gingersoft.gsa.cloud.base.R;
import com.gingersoft.gsa.cloud.base.utils.constans.Constans;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.base.widget.DialogUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/** /**
* Created by Wyh on 2020/3/2. * Created by Wyh on 2020/3/2.
*/ */
@Aspect @Aspect
public class SwitchPrintAspect { public class SwitchPrintAspect {
/**
* 定义切点,标记切点为所有被@SwitchPrintMethod注解的方法
*/
@Pointcut("execution(@com.gingersoft.gsa.cloud.aspectj.SwitchPrintMethod * *(..))")
public void methodAnnotated() {
}
/**
* 定义一个切面方法,包裹切点方法
*/
@Around("methodAnnotated()")
public void aroundJoinPoint(ProceedingJoinPoint joinPoint) {
// 取出方法的参数
View view = null;
for (Object arg : joinPoint.getArgs()) {
if (arg instanceof View) {
view = (View) arg;
break;
}
}
if (view == null || view.getContext() == null) {
return;
}
// 顯示切換打印方式的彈窗
new DialogUtils(view.getContext(), R.layout.print_select_print_method) {
@Override
public void initLayout(ViewHepler hepler, Dialog dialog) {
hepler.setViewClick(R.id.local_print, v -> {
SPUtils.put(dialog.getContext(), Constans.DEFAULT_PRINT_METHOD, Constans.LOCAL_PRINT);
dialog.dismiss();
});
hepler.setViewClick(R.id.internet_print, v -> {
SPUtils.put(dialog.getContext(), Constans.DEFAULT_PRINT_METHOD, Constans.IP_PRINT);
dialog.dismiss();
});
}
}.createDialogView().show();
}
} }
...@@ -20,6 +20,7 @@ import com.gingersoft.gsa.cloud.base.BuildConfig; ...@@ -20,6 +20,7 @@ import com.gingersoft.gsa.cloud.base.BuildConfig;
import com.gingersoft.gsa.cloud.base.R; import com.gingersoft.gsa.cloud.base.R;
import com.gingersoft.gsa.cloud.base.common.bean.CurrentAndroidSetting; import com.gingersoft.gsa.cloud.base.common.bean.CurrentAndroidSetting;
import com.gingersoft.gsa.cloud.base.utils.AidlUtil; import com.gingersoft.gsa.cloud.base.utils.AidlUtil;
import com.gingersoft.gsa.cloud.base.utils.constans.Constans;
import com.gingersoft.gsa.cloud.base.utils.constans.HttpsConstans; import com.gingersoft.gsa.cloud.base.utils.constans.HttpsConstans;
import com.gingersoft.gsa.cloud.base.utils.constans.UserConstans; import com.gingersoft.gsa.cloud.base.utils.constans.UserConstans;
import com.gingersoft.gsa.cloud.base.utils.crash.AppCrashHandler; import com.gingersoft.gsa.cloud.base.utils.crash.AppCrashHandler;
...@@ -147,6 +148,9 @@ public class GsaCloudApplication extends BaseApplication { ...@@ -147,6 +148,9 @@ public class GsaCloudApplication extends BaseApplication {
} catch (NoInitPrinterException | RemoteException e) { } catch (NoInitPrinterException | RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else {
//如果當前機型不是上面兩種,那麼設置默認打印為ip打印
SPUtils.put(this, Constans.DEFAULT_PRINT_METHOD, Constans.IP_PRINT);
} }
//需要單獨配置域名URL的,在接口上添加@Headers({"Domain-Name: settlement_report_server"}),不添加則是使用默認域名 //需要單獨配置域名URL的,在接口上添加@Headers({"Domain-Name: settlement_report_server"}),不添加則是使用默認域名
setGlobalDomain(); setGlobalDomain();
......
...@@ -447,4 +447,6 @@ ...@@ -447,4 +447,6 @@
<color name="color_8f">#8f8f8f</color> <color name="color_8f">#8f8f8f</color>
<color name="color_3c">#3c3c3c</color> <color name="color_3c">#3c3c3c</color>
<color name="color_f0">#F0F0F0</color>
</resources> </resources>
include ':other_order_mode'
include 'cc-register', include 'cc-register',
'cc', 'cc',
'public-base', 'public-base',
......
...@@ -50,7 +50,6 @@ import com.gingersoft.gsa.cloud.table.R2; ...@@ -50,7 +50,6 @@ import com.gingersoft.gsa.cloud.table.R2;
import com.gingersoft.gsa.cloud.table.app.GoldConstants; import com.gingersoft.gsa.cloud.table.app.GoldConstants;
import com.gingersoft.gsa.cloud.table.di.component.DaggerMealStandComponent; import com.gingersoft.gsa.cloud.table.di.component.DaggerMealStandComponent;
import com.gingersoft.gsa.cloud.table.mvp.contract.MealStandContract; import com.gingersoft.gsa.cloud.table.mvp.contract.MealStandContract;
import com.gingersoft.gsa.cloud.table.mvp.model.bean.OrderDetailItem;
import com.gingersoft.gsa.cloud.table.mvp.model.constant.MealConstant; import com.gingersoft.gsa.cloud.table.mvp.model.constant.MealConstant;
import com.gingersoft.gsa.cloud.table.mvp.presenter.MealStandPresenter; import com.gingersoft.gsa.cloud.table.mvp.presenter.MealStandPresenter;
import com.gingersoft.gsa.cloud.table.mvp.ui.adapter.BaseFragmentAdapter; import com.gingersoft.gsa.cloud.table.mvp.ui.adapter.BaseFragmentAdapter;
...@@ -993,6 +992,12 @@ public class MealStandActivity extends BaseActivity<MealStandPresenter> implemen ...@@ -993,6 +992,12 @@ public class MealStandActivity extends BaseActivity<MealStandPresenter> implemen
}.createDialogView().show(); }.createDialogView().show();
return false; return false;
}); });
// btn_send_order.setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// return false;
// }
// });
} }
public FoodGroupAdapter getFoodGroupGridViewAdapter() { public FoodGroupAdapter getFoodGroupGridViewAdapter() {
......
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