Commit b5628706 by Wyh

6.23 外賣接單心跳加入通知欄,點擊可停用接單服務

parent 0fc0adee
......@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.RemoteException;
import android.util.Log;
import androidx.annotation.NonNull;
......@@ -280,8 +281,8 @@ public class GsaCloudApplication extends BaseApplication {
/**
* 给外部的三方库 {@link Activity} 自定义适配参数, 因为三方库的 {@link Activity} 并不能通过实现
* {@link CustomAdapt} 接口的方式来提供自定义适配参数 (因为远程依赖改不了源码)
* 所以使用 {@link ExternalAdaptManager} 来替代实现接口的方式, 来提供自定义适配参数
* {@link me.jessyan.autosize.internal.CustomAdapt} 接口的方式来提供自定义适配参数 (因为远程依赖改不了源码)
* 所以使用 {@link me.jessyan.autosize.external.ExternalAdaptManager} 来替代实现接口的方式, 来提供自定义适配参数
*/
private void customAdaptForExternal() {
/**
......@@ -408,5 +409,4 @@ public class GsaCloudApplication extends BaseApplication {
setRestaurantName(mAppContext, "");
setBrandRestaurantInfos(mAppContext, "");
}
}
......@@ -13,4 +13,6 @@ public class AppConstans {
public static final String PRESSSOUND_PROGRESS = "presssound_progress";//按键音量
public static final String CARSH_STR = "$";
public static final String CLEAR_ORDER_RECEIVING_HEART ="CLEAR_ORDER_RECEIVING_HEART";
}
......@@ -70,7 +70,7 @@ class OrderDetails {
var TOTAL_AMOUNT: String? = null
//後台不會返回
var order_type: Int = 0
var orderPayType: Int = 0
var orderPayType: Int = 0//1為貨到付款,其他是在線支付
var isDelete: Int = 1 //默認為1,為0是第三方物流,其他則是本店配送
var payType: Int = 0//1:積分支付;2:支付寶;3:财付通;4:微信支付;5:貨到付款;6:其他支付
......
......@@ -4,6 +4,7 @@
<style name="AppTheme" parent="PublicTheme">
<item name="QMUITopBarStyle">@style/QDTopBar</item>
<item name="QMUITabSegmentStyle">@style/QMUITabSegmentStyle</item>
<item name="android:windowActivityTransitions">true</item>
<!-- <item name="android:windowActivityTransitions">false</item>-->
<!-- <item name="android:windowDisablePreview">true</item>-->
</style>
</resources>
\ No newline at end of file
......@@ -487,6 +487,7 @@
<color name="restaurant_color_busy_close">#F56C6C</color>
<color name="restaurant_color_busy_open">#E6A23C</color>
<color name="close_btn_color">#E74E40</color>
<!-- 確認訂單按鈕背景色-->
<color name="other_order_details_sure_btn_color">#1196DB</color>
<!-- 取消訂單按鈕背景色-->
......
......@@ -30,7 +30,8 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowAnimationStyle">@style/ui_activityAnimation
</item><!-- 设置activity切换动画 -->
<item name="android:windowIsTranslucent">true</item><!-- 防止Acitivity跳转黑屏 将背景设置成透明-->
<item name="android:windowIsTranslucent">false</item><!-- 防止Acitivity跳转黑屏 将背景设置成透明-->
<item name="android:windowDisablePreview">true</item>
</style>
<!--首頁主題 標題欄文字顏色和其他的不一樣-->
......
......@@ -116,20 +116,7 @@ public class NewMainPresenter extends BasePresenter<NewMainContract.Model, NewMa
RequestBody requestBody = new FormBody.Builder()
.add("restaurantId", GsaCloudApplication.getRestaurantId(mApplication) + "")
.build();
CC.obtainBuilder("Component.OtherOrder")
.setActionName("closeHeart")
.build()
.call();
mModel.clearHeartbeat(requestBody)
.subscribeOn(Schedulers.io())
.subscribe(new ErrorHandleSubscriber<Object>(mErrorHandler) {
@Override
public void onNext(@NonNull Object info) {
}
});
clearHeartbeat();
mModel.loginOut(requestBody)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(null))
......@@ -149,6 +136,27 @@ public class NewMainPresenter extends BasePresenter<NewMainContract.Model, NewMa
});
}
public void clearHeartbeat(){
RequestBody requestBody = new FormBody.Builder()
.add("restaurantId", GsaCloudApplication.getRestaurantId(mApplication) + "")
.build();
//關閉心跳
CC.obtainBuilder("Component.OtherOrder")
.setActionName("closeHeart")
.build()
.call();
mModel.clearHeartbeat(requestBody)
.subscribeOn(Schedulers.io())
.subscribe(new ErrorHandleSubscriber<Object>(mErrorHandler) {
@Override
public void onNext(@NonNull Object info) {
}
});
}
public void updateAPK(int type, String downApkURL) {
if(type == 4 || type == 5){
if(type == 4){
......
package com.gingersoft.gsa.cloud.main.mvp.ui.activity;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
......@@ -17,6 +20,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
......@@ -27,6 +31,7 @@ import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.base.utils.RestaurantInfoUtils;
import com.gingersoft.gsa.cloud.base.utils.encryption.Aes;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.constans.AppConstans;
import com.gingersoft.gsa.cloud.database.bean.Function;
import com.gingersoft.gsa.cloud.main.BuildConfig;
import com.gingersoft.gsa.cloud.main.R;
......@@ -55,6 +60,8 @@ import java.util.List;
import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import static com.jess.arms.utils.Preconditions.checkNotNull;
......@@ -129,10 +136,9 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.activity_new_main; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
// mPresenter.requestExternalStoragePermission();
// mPresenter.requestExternalStoragePermission();
//初始化側邊欄菜單項
initSideMenu();
......@@ -444,6 +450,7 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
finish();
}
@OnClick({R2.id.layout_login_out, R2.id.iv_personal_center, R2.id.tv_restaurant_name})
@Override
public void onClick(View v) {
......@@ -492,4 +499,5 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
}
return super.onKeyDown(keyCode, event);
}
}
......@@ -10,7 +10,9 @@
android:label="@string/app_name"
android:launchMode="singleTop" />
<service
android:name=".service.GetInfoUpdateService" />
android:name=".service.GetInfoUpdateService"
android:enabled="true"
/>
<activity android:name=".ui.activity.HistoryOrderActivity" />
<meta-data
android:name="com.gingersoft.gsa.cloud.globalconfig.GlobalConfiguration"
......
......@@ -12,7 +12,8 @@
android:networkSecurityConfig="@xml/network_android"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.activity.OrderDetailsActivity"></activity>
<activity android:name=".ui.activity.OrderDetailsActivity" />
<activity
android:name=".ui.activity.OtherOrderActivity"
android:label="@string/app_name">
......
package com.gingersoft.gsa.other_order_mode.data.network
import android.util.Log
import com.gingersoft.gsa.other_order_mode.data.network.api.WeatherService
import okhttp3.RequestBody
import retrofit2.Call
......
......@@ -148,11 +148,11 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
if (isLoadMore) {
if (mOrderList[position].value != null) {
mOrderList[position].value!!.addAll(myData)
mOrderList[position].postValue(mOrderList[position].value)
}
} else {
mOrderList[position].value = myData
}
// mOrderList[position].postValue(mOrderList[position].value)
} else {
mOrderList[position].value = null
}
......@@ -161,7 +161,6 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}
//餐廳營業狀態,控制按鈕
var restaurantState = MutableLiveData<Int>()
......@@ -294,7 +293,6 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
listener.invoke(ProductionComplete, code == "1")
}
}
}
}, {
listener.invoke(0, false)
......
package com.gingersoft.gsa.other_order_mode.service
import android.annotation.SuppressLint
import android.app.*
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.BitmapFactory
import android.media.AudioAttributes
import android.media.AudioManager
......@@ -11,9 +14,14 @@ import android.os.Binder
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.view.LayoutInflater
import android.widget.RemoteViews
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.constans.AppConstans
import com.gingersoft.gsa.cloud.constans.HttpsConstans
import com.gingersoft.gsa.other_order_mode.R
import com.gingersoft.gsa.other_order_mode.data.network.ServiceCreator
import com.gingersoft.gsa.other_order_mode.ui.activity.OtherOrderActivity
......@@ -39,6 +47,7 @@ class GetInfoUpdateService : Service() {
var postCallBack: PostCallBack? = null
override fun onBind(intent: Intent?): IBinder? {
return MyBind()
}
......@@ -52,6 +61,8 @@ class GetInfoUpdateService : Service() {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
} else {
startNotification()
}
return super.onStartCommand(intent, flags, startId)
}
......@@ -69,7 +80,19 @@ class GetInfoUpdateService : Service() {
//构建通知渠道
val channel = NotificationChannel(CHANNEL_ID, channelName, importance)
channel.description = "New Order Notification"
//向系统注册通知渠道,注册后不能改变重要性以及其他通知行为
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
startNotification()
}
@SuppressLint("InflateParams")
private fun startNotification() {
val broadcastReceiver = Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
val broadcastIntent = PendingIntent.getBroadcast(this, 10, broadcastReceiver, 0)
// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
val remoteViews = RemoteViews(packageName, R.layout.layout_order_receiving)
remoteViews.setOnClickPendingIntent(R.id.btn_stop_service, broadcastIntent)
val intent = Intent(this, OtherOrderActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
......@@ -79,11 +102,10 @@ class GetInfoUpdateService : Service() {
.setContentTitle("Ricepon Pos")//设置通知标题
.setContentText("外賣接單服務")//设置通知内容Takeaway order service
.setContentIntent(pendingIntent)
.setContent(remoteViews)
.setAutoCancel(false) //用户触摸时,自动关闭
.setOngoing(true)//设置处于运行状态
//向系统注册通知渠道,注册后不能改变重要性以及其他通知行为
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
//将服务置于启动状态 NOTIFICATION_ID指的是创建的通知的ID
startForeground(123, builder.build())
}
......@@ -98,9 +120,14 @@ class GetInfoUpdateService : Service() {
}
}
private lateinit var mReceiver: ClearHeartBroadcastReceiver
override fun onCreate() {
super.onCreate()
val mFilter = IntentFilter(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
mReceiver = ClearHeartBroadcastReceiver()
registerReceiver(mReceiver, mFilter)
InitSocketThread().start()
isDestroy = false
}
......@@ -114,6 +141,7 @@ class GetInfoUpdateService : Service() {
// 初始化socket
private fun initSocket() {
Log.e("eee", "啊啊啊啊" + application.isRestricted)
RxTimerUtil.cancel()
RxTimerUtil.timer({
client = OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).build()
......@@ -260,7 +288,7 @@ class GetInfoUpdateService : Service() {
// private var sendTime = 0L
// 发送心跳包
// private val mHandler = Handler()
// private val mHandler = Handler()
// private val heartBeatRunnable = object : Runnable {
// override fun run() {
// if (!isDestroy) {
......@@ -280,13 +308,14 @@ class GetInfoUpdateService : Service() {
// }
// }
// }
private var isDestroy = false
override fun onDestroy() {
super.onDestroy()
Log.e(TAG, "onDestroy")
isDestroy = true
unregisterReceiver(mReceiver)
//斷開鏈接
client?.let {
mWebSocket?.cancel()
it.dispatcher().cancelAll()
......@@ -294,11 +323,23 @@ class GetInfoUpdateService : Service() {
if (mWebSocket != null) {
mWebSocket!!.send("-1")
mWebSocket!!.close(1000, null)
// mHandler.removeCallbacks(heartBeatRunnable)
}
RxTimerUtil.cancel()
//停止服務
stopForeground(true)
}
inner class ClearHeartBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
//清除心跳並關閉service
val requestBody = FormBody.Builder()
.add("restaurantId", GsaCloudApplication.getRestaurantId(this@GetInfoUpdateService).toString() + "")
.build()
OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody)//清除心跳
stopSelf()
}
}
class MsgBean(var type: Int, var token: String)
}
\ No newline at end of file
......@@ -71,17 +71,13 @@ class OrderDetailsActivity : BaseActivity() {
}
private fun PageViewModel.getOrderDetails(orderId: String, binding: ActivityOrderDetailsBinding) {
orderDetails.observe(this@OrderDetailsActivity, Observer {
skeletonScreen.hide()//隱藏骨架屏
Log.e("eee", "收到")
if (it?.data != null && it.data!!.isNotEmpty()) {
val orderDetails = it.data!![0]
orderDetails.order_type = orderType
orderDetails.orderPayType = orderPayType
binding.data = orderDetails
binding.totalAmount = orderDetails.TOTAL_AMOUNT!!.toDouble()
binding.isSelf = orderDetails.order_type == 7
......@@ -129,7 +125,6 @@ class OrderDetailsActivity : BaseActivity() {
orderStatusText = "派送中"
tv_order_state.setTextColor(resources.getColor(R.color.order_state2_color))
}
}
else -> {//待確認訂單
btnList.add(BtnBuilder().getSureBtn())
......@@ -160,7 +155,6 @@ class OrderDetailsActivity : BaseActivity() {
val orderBtnAdapter = OrderDetailsAdapter(btnList)
rv_order_details_btn.adapter = orderBtnAdapter
//--------------------------------------------------------------不同按鈕點擊事件----------------------------------------------------------------------------------------
orderBtnAdapter.setOnItemClickListener { adapter, view, position ->
when (btnList[position].type) {
......@@ -174,9 +168,20 @@ class OrderDetailsActivity : BaseActivity() {
//取消訂單
cancelOrder(orderDetails)
BtnBuilder.closingBtn -> {
val intent = Intent(this@OrderDetailsActivity, PayActivity::class.java)
intent.putExtra("orderDetails", orderDetails)
startActivityForResult(intent, 1001)
//如果是在線支付的訂單,就直接修改訂單狀態
if (orderPayType != 1) {
gsUpdateOrderStatus(orderDetails.ID.toString(), orderDetails.order_type) { status, isSuccess ->
if(isSuccess) {
finish()
} else {
ToastUtils.show(this@OrderDetailsActivity, "結賬失敗")
}
}
} else {
val intent = Intent(this@OrderDetailsActivity, PayActivity::class.java)
intent.putExtra("orderDetails", orderDetails)
startActivityForResult(intent, 1001)
}
}
else -> {
showLoading()
......
......@@ -2,10 +2,7 @@ package com.gingersoft.gsa.other_order_mode.ui.activity
import android.animation.ValueAnimator
import android.app.Dialog
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.*
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.media.AudioAttributes
......@@ -27,6 +24,7 @@ import androidx.viewpager.widget.ViewPager
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
import com.gingersoft.gsa.cloud.base.widget.DialogUtils
import com.gingersoft.gsa.cloud.constans.AppConstans
import com.gingersoft.gsa.other_order_mode.R
import com.gingersoft.gsa.other_order_mode.databinding.ActivityOtherOrderBinding
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel
......@@ -70,8 +68,14 @@ class OtherOrderActivity : BaseActivity() {
private var btnHeight: Float = 0F
private var selectPosition = 0
lateinit var mReceiver :ClearHeartBroadcastReceiver
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val mFilter = IntentFilter(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
mReceiver = ClearHeartBroadcastReceiver()
registerReceiver(mReceiver, mFilter)
val binding: ActivityOtherOrderBinding = DataBindingUtil.setContentView(this, R.layout.activity_other_order)
initWebsocket()
......@@ -94,7 +98,6 @@ class OtherOrderActivity : BaseActivity() {
selectPosition = position
}
})
searchMethod(view_pager)
initTabs()
//餐廳營業信息
......@@ -283,6 +286,7 @@ class OtherOrderActivity : BaseActivity() {
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(mReceiver)
unbindService(serviceConnection)
}
......@@ -456,4 +460,10 @@ class OtherOrderActivity : BaseActivity() {
// }
qm_other_order_bar.setBackgroundColor(resources.getColor(R.color.theme_color))
}
inner class ClearHeartBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
finish()
}
}
}
\ No newline at end of file
......@@ -57,13 +57,13 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
super.onCreate();
//讀取本地ip打印機
Log.e("eee", "開啟打印服務");
// if (printerDeviceBeans == null) {
// PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(this);
// printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
// printerDeviceDaoUtils.closeConnection();
// }
// //開始請求
// startGetPrjInfo();
if (printerDeviceBeans == null) {
PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(this);
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
printerDeviceDaoUtils.closeConnection();
}
//開始請求
startGetPrjInfo();
}
@Nullable
......
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