Commit 17910593 by 宁斌

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

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