Commit 17910593 by 宁斌

1、處理打印dialog消失前有黑屏問題

parent 7e27ec13
...@@ -40,7 +40,7 @@ import com.gingersoft.gsa.cloud.common.constans.DeliveryPickConstans; ...@@ -40,7 +40,7 @@ import com.gingersoft.gsa.cloud.common.constans.DeliveryPickConstans;
import com.gingersoft.gsa.cloud.common.constans.ExpandConstant; import com.gingersoft.gsa.cloud.common.constans.ExpandConstant;
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager; import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager;
import com.gingersoft.gsa.cloud.common.core.restaurant.utils.RestaurantExpandInfoUtils; import com.gingersoft.gsa.cloud.common.core.restaurant.utils.RestaurantExpandInfoUtils;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService; import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil; import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils; import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog; import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
...@@ -220,7 +220,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre ...@@ -220,7 +220,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
private void initService() { private void initService() {
//開啟websocket //開啟websocket
Intent intent = new Intent(getApplicationContext(), DataNotificationService.class); Intent intent = new Intent(getApplicationContext(), GetInfoUpdateService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent); startForegroundService(intent);
} else { } else {
...@@ -235,13 +235,13 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre ...@@ -235,13 +235,13 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
registerReceiver(clearHeartBroadcastReceiver, intentFilter); registerReceiver(clearHeartBroadcastReceiver, intentFilter);
} }
private DataNotificationService.MyBind bind = null; private GetInfoUpdateService.MyBind bind = null;
private ServiceConnection serviceConnection = new ServiceConnection() { private ServiceConnection serviceConnection = new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
bind = (DataNotificationService.MyBind) service; bind = (GetInfoUpdateService.MyBind) service;
if (bind != null) { if (bind != null) {
bind.setOnPostCallBack(type -> { bind.setOnPostCallBack(type -> {
// -1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知" // -1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知"
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService" /> <service android:name="com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService" />
<meta-data <meta-data
android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration" android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration"
......
...@@ -7,7 +7,7 @@ import com.billy.cc.core.component.CCResult; ...@@ -7,7 +7,7 @@ import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent; import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.component.ComponentName; import com.gingersoft.gsa.cloud.component.ComponentName;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService; import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService;
import com.gingersoft.gsa.delivery_pick_mode.data.network.ServiceCreator; import com.gingersoft.gsa.delivery_pick_mode.data.network.ServiceCreator;
import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.PrjQueryActivity; import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.PrjQueryActivity;
import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.SendOrderActivity; import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.SendOrderActivity;
...@@ -52,7 +52,7 @@ public class DeliveryPickComponent implements IComponent { ...@@ -52,7 +52,7 @@ public class DeliveryPickComponent implements IComponent {
CC.sendCCResult(cc.getCallId(), CCResult.success()); CC.sendCCResult(cc.getCallId(), CCResult.success());
break; break;
case "closeHeart": case "closeHeart":
Intent intent = new Intent(cc.getContext(), DataNotificationService.class); Intent intent = new Intent(cc.getContext(), GetInfoUpdateService.class);
cc.getContext().stopService(intent); cc.getContext().stopService(intent);
break; break;
case "historyActivity": case "historyActivity":
......
...@@ -22,7 +22,7 @@ import com.gingersoft.gsa.cloud.common.core.delivery.OrderDetails.Companion.veri ...@@ -22,7 +22,7 @@ import com.gingersoft.gsa.cloud.common.core.delivery.OrderDetails.Companion.veri
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.core.user.UserContext import com.gingersoft.gsa.cloud.common.core.user.UserContext
import com.gingersoft.gsa.cloud.common.logan.LoganManager import com.gingersoft.gsa.cloud.common.logan.LoganManager
import com.gingersoft.gsa.cloud.common.service.DataNotificationService import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil import com.gingersoft.gsa.cloud.common.utils.other.TextUtil
...@@ -434,8 +434,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -434,8 +434,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}, { }, {
listener.invoke(getMsgBean(0, "", false)) listener.invoke(getMsgBean(0, "", false))
it.printStackTrace() it.printStackTrace()
DataNotificationService.loginfo.append("錯誤信息111:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause) GetInfoUpdateService.loginfo.append("錯誤信息111:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
DataNotificationService.loginfo.append("\n") GetInfoUpdateService.loginfo.append("\n")
}) })
} }
...@@ -575,12 +575,12 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -575,12 +575,12 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
//添加PRJ //添加PRJ
//單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯 //單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯
repository.addPrj(dataBean.Order_ID.toString(), restaurantId.toString(), ids.toString()) repository.addPrj(dataBean.Order_ID.toString(), restaurantId.toString(), ids.toString())
DataNotificationService.loginfo.append("添加PRJ:orderId:" + dataBean.Order_ID.toString() + "restaurantId:" + restaurantId + "orderDetailsIds:" + ids.toString()) GetInfoUpdateService.loginfo.append("添加PRJ:orderId:" + dataBean.Order_ID.toString() + "restaurantId:" + restaurantId + "orderDetailsIds:" + ids.toString())
DataNotificationService.loginfo.append("\n") GetInfoUpdateService.loginfo.append("\n")
}, { }, {
it.printStackTrace() it.printStackTrace()
DataNotificationService.loginfo.append("錯誤信息222:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause) GetInfoUpdateService.loginfo.append("錯誤信息222:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
DataNotificationService.loginfo.append("\n") GetInfoUpdateService.loginfo.append("\n")
}) })
} }
if (isPrintBill) { if (isPrintBill) {
......
...@@ -31,7 +31,7 @@ import com.gingersoft.gsa.cloud.common.constans.ExpandConstant ...@@ -31,7 +31,7 @@ import com.gingersoft.gsa.cloud.common.constans.ExpandConstant
import com.gingersoft.gsa.cloud.common.constans.FoodSummaryConstans.TAKEAWAY_TYPE import com.gingersoft.gsa.cloud.common.constans.FoodSummaryConstans.TAKEAWAY_TYPE
import com.gingersoft.gsa.cloud.common.constans.FunctionManagerConstants import com.gingersoft.gsa.cloud.common.constans.FunctionManagerConstants
import com.gingersoft.gsa.cloud.common.function.FunctionManager import com.gingersoft.gsa.cloud.common.function.FunctionManager
import com.gingersoft.gsa.cloud.common.service.DataNotificationService import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService
import com.gingersoft.gsa.cloud.common.service.PostCallBack import com.gingersoft.gsa.cloud.common.service.PostCallBack
import com.gingersoft.gsa.cloud.order.order.BaseOrder import com.gingersoft.gsa.cloud.order.order.BaseOrder
import com.gingersoft.gsa.cloud.ui.utils.AppDialog import com.gingersoft.gsa.cloud.ui.utils.AppDialog
...@@ -395,7 +395,7 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen ...@@ -395,7 +395,7 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen
private fun initWebsocket() { private fun initWebsocket() {
//開啟websocket //開啟websocket
val service = Intent(applicationContext, DataNotificationService::class.java) val service = Intent(applicationContext, GetInfoUpdateService::class.java)
val notification: NotificationManagerCompat = NotificationManagerCompat.from(this) val notification: NotificationManagerCompat = NotificationManagerCompat.from(this)
if (!notification.areNotificationsEnabled()) { if (!notification.areNotificationsEnabled()) {
//未開啟通知權限 //未開啟通知權限
...@@ -446,12 +446,12 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen ...@@ -446,12 +446,12 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen
unbindService(serviceConnection) unbindService(serviceConnection)
} }
var bind: DataNotificationService.MyBind? = null var bind: GetInfoUpdateService.MyBind? = null
var lastRefreshTime: Long = 0 var lastRefreshTime: Long = 0
private var serviceConnection = object : ServiceConnection { private var serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) { override fun onServiceConnected(name: ComponentName, service: IBinder) {
bind = service as DataNotificationService.MyBind bind = service as GetInfoUpdateService.MyBind
bind?.let { it -> bind?.let { it ->
it.setOnPostCallBack(object : PostCallBack { it.setOnPostCallBack(object : PostCallBack {
override fun callBack(type: Int) { override fun callBack(type: Int) {
......
...@@ -2,10 +2,8 @@ package com.gingersoft.gsa.delivery_pick_mode.ui.activity; ...@@ -2,10 +2,8 @@ package com.gingersoft.gsa.delivery_pick_mode.ui.activity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.delivery_pick_mode.R; import com.gingersoft.gsa.delivery_pick_mode.R;
public class LogActivity extends AppCompatActivity { public class LogActivity extends AppCompatActivity {
...@@ -16,13 +14,13 @@ public class LogActivity extends AppCompatActivity { ...@@ -16,13 +14,13 @@ public class LogActivity extends AppCompatActivity {
setContentView(R.layout.activity_log); setContentView(R.layout.activity_log);
loadInfo(); loadInfo();
findViewById(R.id.btn_clear_log).setOnClickListener(v -> { findViewById(R.id.btn_clear_log).setOnClickListener(v -> {
DataNotificationService.loginfo.setLength(0); GetInfoUpdateService.loginfo.setLength(0);
loadInfo(); loadInfo();
}); });
findViewById(R.id.btn_back).setOnClickListener(v ->finish()); findViewById(R.id.btn_back).setOnClickListener(v ->finish());
} }
private void loadInfo() { private void loadInfo() {
((TextView) findViewById(R.id.tv_log)).setText(DataNotificationService.loginfo.toString()); ((TextView) findViewById(R.id.tv_log)).setText(GetInfoUpdateService.loginfo.toString());
} }
} }
...@@ -38,7 +38,7 @@ import com.gingersoft.gsa.cloud.common.function.FunctionManager; ...@@ -38,7 +38,7 @@ import com.gingersoft.gsa.cloud.common.function.FunctionManager;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpBean; import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpBean;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpStrategy; import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpStrategy;
import com.gingersoft.gsa.cloud.common.logan.LoganManager; import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService; import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService;
import com.gingersoft.gsa.cloud.common.utils.AppDevices; import com.gingersoft.gsa.cloud.common.utils.AppDevices;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils; import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.StytemUtils; import com.gingersoft.gsa.cloud.common.utils.StytemUtils;
...@@ -218,24 +218,24 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl ...@@ -218,24 +218,24 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
} }
private void initService() { private void initService() {
boolean deliveryOrderServiceRunning = StytemUtils.isServiceRunning("com.gingersoft.gsa.cloud.common.service.DataNotificationService", this); // boolean deliveryOrderServiceRunning = StytemUtils.isServiceRunning("com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService", this);
if (!deliveryOrderServiceRunning) { // if (!deliveryOrderServiceRunning) {
Intent service = new Intent(GsaCloudApplication.getAppContext(), DataNotificationService.class); // Intent service = new Intent(GsaCloudApplication.getAppContext(), GetInfoUpdateService.class);
service.putExtra(DataNotificationService.CONNECTION_TYPE, DataNotificationService.mCurrConnectionType); // service.putExtra(GetInfoUpdateService.CONNECTION_TYPE, GetInfoUpdateService.mCurrConnectionType);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(service); // startForegroundService(service);
} else { // } else {
startService(service); // startService(service);
} // }
}
// boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
// if (!prjServiceRunning) {
// //開啟Prj打印服務
// CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
// .setActionName("openPrintService")
// .build()
// .call();
// } // }
boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
if (!prjServiceRunning) {
//開啟Prj打印服務
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("openPrintService")
.build()
.call();
}
} }
......
...@@ -166,12 +166,12 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -166,12 +166,12 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override @Override
public void connectionError(Exception e) { public void connectionError(Exception e) {
printerResult = false;
printerLoadingDialog.setStep(2, PrinterLoadingDialog.status_error, e.getMessage()); printerLoadingDialog.setStep(2, PrinterLoadingDialog.status_error, e.getMessage());
} }
@Override @Override
public void disconnect(Exception e) { public void disconnect(Exception e) {
} }
@Override @Override
...@@ -192,6 +192,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -192,6 +192,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override @Override
public void onPrintError(Exception e, int errorCode) { public void onPrintError(Exception e, int errorCode) {
printerResult = false;
printerLoadingDialog.setStep(3, PrinterLoadingDialog.status_error, e.getMessage()); printerLoadingDialog.setStep(3, PrinterLoadingDialog.status_error, e.getMessage());
} }
}); });
...@@ -515,8 +516,8 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -515,8 +516,8 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override @Override
public void printSuccess() { public void printSuccess() {
LoganManager.w_printer(TAG, "printFailure 打印成功"); LoganManager.w_printer(TAG, "printFailure 打印成功");
CC.sendCCResult(callId, CCResult.success());
killMyself(); killMyself();
CC.sendCCResult(callId, CCResult.success());
} }
@Override @Override
......
...@@ -33,10 +33,7 @@ ...@@ -33,10 +33,7 @@
android:name="design_height_in_dp" android:name="design_height_in_dp"
android:value="640"/> android:value="640"/>
<service <service
android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService" android:name="com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService"
android:enabled="true" />
<service
android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService2"
android:enabled="true" /> android:enabled="true" />
</application> </application>
</manifest> </manifest>
...@@ -15,23 +15,18 @@ import android.os.Build ...@@ -15,23 +15,18 @@ import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import android.util.Log import android.util.Log
import android.view.View
import android.widget.RemoteViews import android.widget.RemoteViews
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.billy.cc.core.component.CC
import com.billy.cc.core.component.CCResult
import com.gingersoft.gsa.cloud.common.R import com.gingersoft.gsa.cloud.common.R
import com.gingersoft.gsa.cloud.common.constans.AppConstans import com.gingersoft.gsa.cloud.common.constans.AppConstans
import com.gingersoft.gsa.cloud.common.constans.HttpsConstans import com.gingersoft.gsa.cloud.common.constans.HttpsConstans
import com.gingersoft.gsa.cloud.common.constans.PrintConstans
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.core.user.UserContext import com.gingersoft.gsa.cloud.common.core.user.UserContext
import com.gingersoft.gsa.cloud.common.logan.LoganManager import com.gingersoft.gsa.cloud.common.logan.LoganManager
import com.gingersoft.gsa.cloud.common.utils.SoundPoolUtils import com.gingersoft.gsa.cloud.common.utils.SoundPoolUtils
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils
import com.gingersoft.gsa.cloud.component.ComponentName
import com.google.gson.Gson import com.google.gson.Gson
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
...@@ -44,7 +39,7 @@ import org.json.JSONObject ...@@ -44,7 +39,7 @@ import org.json.JSONObject
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class DataNotificationService : Service() { class GetInfoUpdateService : Service() {
private val TAG = "heart" private val TAG = "heart"
...@@ -66,45 +61,13 @@ class DataNotificationService : Service() { ...@@ -66,45 +61,13 @@ class DataNotificationService : Service() {
private val CHANNEL_ID = "cloud_gsa" private val CHANNEL_ID = "cloud_gsa"
private var isCreate = false
/**
* prj數據
*/
private var PRJ_DATA = 10
/**
* prj數據
*/
private var TABLE_DATA = 11
companion object { companion object {
@kotlin.jvm.JvmField @kotlin.jvm.JvmField
var loginfo = StringBuffer() var loginfo = StringBuffer()
}
val restaurantId by lazy {
@kotlin.jvm.JvmField RestaurantInfoManager.newInstance().getRestaurantId()
var CONNECTION_TYPE = "connection_type"
/**
* 开启外送接单长连
*/
@kotlin.jvm.JvmField
var OPEN_DELIVET_ORDER_CONNECTION = 2
/**
* 开启外送其他数据接收长连(prj,餐台数据)
*/
@kotlin.jvm.JvmField
var OPEN_OTHER_CONNECTION = 1
/**
* 当前连接类型
*/
@kotlin.jvm.JvmField
var mCurrConnectionType = OPEN_OTHER_CONNECTION
} }
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
...@@ -125,23 +88,12 @@ class DataNotificationService : Service() { ...@@ -125,23 +88,12 @@ class DataNotificationService : Service() {
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// 在API11之后构建Notification的方式
//获取当前长连类型 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mCurrConnectionType = intent!!.getIntExtra(CONNECTION_TYPE, OPEN_DELIVET_ORDER_CONNECTION) createNotificationChannel()
} else {
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) { startNotification()
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
} else {
startNotification()
}
} }
if (isCreate) {
send(mCurrConnectionType)
}
isCreate = true
putTimeLog("啟動服務onStartCommand") putTimeLog("啟動服務onStartCommand")
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
} }
...@@ -198,14 +150,6 @@ class DataNotificationService : Service() { ...@@ -198,14 +150,6 @@ class DataNotificationService : Service() {
startForeground(123, builder.build()) startForeground(123, builder.build())
} }
fun cleanNotification() {
// val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// notificationManager.cancelAll()
// notificationManager.cancel(123)
// //停止前台服務
// stopForeground(true)
}
inner class MyBind : Binder() { inner class MyBind : Binder() {
lateinit var block: (isShow: Boolean) -> Unit lateinit var block: (isShow: Boolean) -> Unit
var jumpActivity: Class<*>? = null var jumpActivity: Class<*>? = null
...@@ -219,7 +163,7 @@ class DataNotificationService : Service() { ...@@ -219,7 +163,7 @@ class DataNotificationService : Service() {
} }
fun setOnPostCallBack(postCallBack: PostCallBack?) { fun setOnPostCallBack(postCallBack: PostCallBack?) {
this@DataNotificationService.postCallBack = postCallBack this@GetInfoUpdateService.postCallBack = postCallBack
} }
fun execute(block: (isShow: Boolean) -> Unit) { fun execute(block: (isShow: Boolean) -> Unit) {
...@@ -258,9 +202,10 @@ class DataNotificationService : Service() { ...@@ -258,9 +202,10 @@ class DataNotificationService : Service() {
it.newWebSocket(request, object : WebSocketListener() { it.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {//开启长连接成功的回调 override fun onOpen(webSocket: WebSocket, response: Response) {//开启长连接成功的回调
super.onOpen(webSocket, response) super.onOpen(webSocket, response)
if (!this@DataNotificationService.isDestroy) { if (!this@GetInfoUpdateService.isDestroy) {
mWebSocket = webSocket mWebSocket = webSocket
send(mCurrConnectionType) val token = "weixin_" + restaurantId + "_" + getRandomString(24)
webSocket.send(Gson().toJson(MsgBean(1, token)))
putTimeLog("連接成功") putTimeLog("連接成功")
cancelTimerDisposable() cancelTimerDisposable()
myBind?.block?.invoke(false) myBind?.block?.invoke(false)
...@@ -287,20 +232,11 @@ class DataNotificationService : Service() { ...@@ -287,20 +232,11 @@ class DataNotificationService : Service() {
// \n5:歷史訂單通知, // \n5:歷史訂單通知,
// \n6:修改訂單狀態通知, // \n6:修改訂單狀態通知,
// \n7:支付成功通知" // \n7:支付成功通知"
// 10:prj数据
// 11:餐台数据
if (type == 3 || type == 4 || type == 5 || type == 7) { if (type == 3 || type == 4 || type == 5 || type == 7) {
//播放提示音 //播放提示音
initSoundPool(R.raw.newordervocal) initSoundPool(R.raw.newordervocal)
} else if (type == 8) { } else if (type == 8) {
initSoundPool(R.raw.raw_logistics_cancel) initSoundPool(R.raw.raw_logistics_cancel)
} else if (type == PRJ_DATA) {
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("getPrjData")
.build()
.call()
} else if (type == TABLE_DATA) {
} }
//收到服务器端传过来的消息text //收到服务器端传过来的消息text
Log.e(TAG, "onMessage:$text") Log.e(TAG, "onMessage:$text")
...@@ -334,8 +270,7 @@ class DataNotificationService : Service() { ...@@ -334,8 +270,7 @@ class DataNotificationService : Service() {
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调 override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response) super.onFailure(webSocket, t, response)
Log.e(TAG, "onFailure " + t.message) Log.e(TAG, "onFailure " + t.message)
if (!this@GetInfoUpdateService.isDestroy) {
if (!this@DataNotificationService.isDestroy) {
//連接斷開,定時五秒,如果未重連,播放提示音 //連接斷開,定時五秒,如果未重連,播放提示音
delayFun({ delayFun({
initSoundPool(R.raw.raw_disconnect) initSoundPool(R.raw.raw_disconnect)
...@@ -348,7 +283,6 @@ class DataNotificationService : Service() { ...@@ -348,7 +283,6 @@ class DataNotificationService : Service() {
webSocket.cancel() webSocket.cancel()
it.dispatcher().cancelAll() it.dispatcher().cancelAll()
} }
} }
}) })
it.dispatcher().executorService().shutdown() it.dispatcher().executorService().shutdown()
...@@ -356,21 +290,6 @@ class DataNotificationService : Service() { ...@@ -356,21 +290,6 @@ class DataNotificationService : Service() {
}, HEART_BEAT_RATE) }, HEART_BEAT_RATE)
} }
fun send(currConnectionType: Int) {
val token = "weixin_" + RestaurantInfoManager.newInstance().restaurantId + "_" + UserContext.newInstance().memberId + "_" + getRandomString(24)
if (mWebSocket != null) {
mWebSocket?.send(Gson().toJson(MsgBean(1, getConnectiontype(), token)))
}
}
private fun getConnectiontype(): String {
var connectiontype = "$OPEN_OTHER_CONNECTION"
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
connectiontype = "$OPEN_OTHER_CONNECTION , $OPEN_DELIVET_ORDER_CONNECTION"
}
return connectiontype
}
private var lastSoundTime: Long = 0L private var lastSoundTime: Long = 0L
fun initSoundPool(resId: Int) { fun initSoundPool(resId: Int) {
val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲 val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲
...@@ -427,7 +346,7 @@ class DataNotificationService : Service() { ...@@ -427,7 +346,7 @@ class DataNotificationService : Service() {
private fun clearHeart() { private fun clearHeart() {
val requestBody = FormBody.Builder() val requestBody = FormBody.Builder()
.add("restaurantId", RestaurantInfoManager.newInstance().restaurantId .toString()) .add("restaurantId", restaurantId.toString())
.build() .build()
OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody) OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody)
.subscribeOn(Schedulers.io()).subscribe() .subscribeOn(Schedulers.io()).subscribe()
...@@ -436,10 +355,7 @@ class DataNotificationService : Service() { ...@@ -436,10 +355,7 @@ class DataNotificationService : Service() {
inner class ClearHeartBroadcastReceiver : BroadcastReceiver() { inner class ClearHeartBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
//關閉service,會調用service的onDestroy //關閉service,會調用service的onDestroy
// stopSelf() stopSelf()
cleanNotification()
mCurrConnectionType = OPEN_OTHER_CONNECTION;
send(mCurrConnectionType)
} }
} }
...@@ -512,6 +428,6 @@ class DataNotificationService : Service() { ...@@ -512,6 +428,6 @@ class DataNotificationService : Service() {
}) })
} }
class MsgBean(var type: Int, var data: String, var token: String) class MsgBean(var type: Int, var token: String)
} }
\ No newline at end of file
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