[optimization]返回监听
This commit is contained in:
parent
122d75ebf1
commit
714bac19f9
|
|
@ -8,6 +8,7 @@ import android.util.Log
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.libs.fragment.BaseActivity
|
||||
import com.libs.utils.LogUtil
|
||||
import com.libs.utils.ToastUtil
|
||||
import com.skipping.*
|
||||
import com.skipping.TIMING_NAME
|
||||
import com.skipping.net.DetailActivityBean
|
||||
|
|
@ -67,6 +68,11 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
finish()
|
||||
}
|
||||
begin_start.setOnClickListener {
|
||||
if (!ConnectManager.getSingleton().deviceStatus || !ConnectManager.getSingleton().deviceNum()) {
|
||||
ToastUtil.longToast("请先连接设备并开启连接模式")
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (detailBean.activityType == TIMING) {
|
||||
//定时计数
|
||||
var num = detailBean.activityValue
|
||||
|
|
@ -82,8 +88,12 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
ConnectManager.getSingleton().getCount()
|
||||
score()
|
||||
flushScore()
|
||||
begin_listRL.isClickable = true
|
||||
begin_start.isClickable = true
|
||||
return@scheduleWithFixedDelayMain
|
||||
}
|
||||
begin_listRL.isClickable = false
|
||||
begin_start.isClickable = false
|
||||
ConnectManager.getSingleton().getCount()
|
||||
num--
|
||||
begin_type.text = "${TIMING_NAME}: ${num} 秒"
|
||||
|
|
@ -202,7 +212,7 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
override fun onStop() {
|
||||
super.onStop()
|
||||
ConnectManager.getSingleton().stopJump()
|
||||
if (future != null) {
|
||||
if (::future.isInitialized && future != null) {
|
||||
future.cancel(true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.skipping.activity.home
|
|||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
|
|
@ -27,6 +28,7 @@ import com.skipping.view.dialog.DialogBean
|
|||
import com.skipping.view.dialog.DialogTool
|
||||
import kotlinx.android.synthetic.main.activity_detail.view.*
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
|
|
@ -157,7 +159,7 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
recyclerview.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
refreshLayout.setEnabled(recyclerView.getChildCount() == 0 || recyclerView.getChildAt(0).getTop() >= 0)
|
||||
refreshLayout.isEnabled = recyclerView.childCount == 0 || recyclerView.getChildAt(0).top >= 0
|
||||
}
|
||||
})
|
||||
recyclerview.setOnScrollChangeListener(object : View.OnScrollChangeListener {
|
||||
|
|
@ -187,7 +189,8 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
drawerlayout.open()
|
||||
}
|
||||
|
||||
fun showList(page: Int, list: List<ActivityBean>) {
|
||||
fun showList(page: Int, list: MutableList<ActivityBean>) {
|
||||
LogUtil.e("新数据", list[0])
|
||||
if (refreshLayout.isRefreshing) {
|
||||
refreshLayout.isRefreshing = false
|
||||
}
|
||||
|
|
@ -243,5 +246,20 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
manager.resume()
|
||||
}
|
||||
|
||||
|
||||
var clickBack = 0
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event?.repeatCount == 0) {
|
||||
ThreadPoolUtil.getSingleton().schedule({
|
||||
clickBack = 0
|
||||
}, 1000)
|
||||
if (clickBack > 0) {
|
||||
finish()
|
||||
} else {
|
||||
ToastUtil.longToast("再次点击退出")
|
||||
}
|
||||
clickBack++
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -19,18 +19,20 @@ import com.skipping.utils.DateUtils
|
|||
* 3/25/22
|
||||
*
|
||||
*/
|
||||
class HomeGridAdaper(context: Context, list: List<ActivityBean>) : RecyclerView.Adapter<HomeGridAdaper.Holder>() {
|
||||
class HomeGridAdaper(context: Context, list: MutableList<ActivityBean>) : RecyclerView.Adapter<HomeGridAdaper.Holder>() {
|
||||
var list = list
|
||||
var context = context
|
||||
|
||||
lateinit var onClickChange: (bean: ActivityBean) -> Unit
|
||||
lateinit var onClickStart: (bean: ActivityBean) -> Unit
|
||||
|
||||
fun addData(list: List<ActivityBean>) {
|
||||
this.list += list
|
||||
fun addData(list: MutableList<ActivityBean>) {
|
||||
this.list.addAll(list)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun setData(list: List<ActivityBean>) {
|
||||
fun setData(list: MutableList<ActivityBean>) {
|
||||
this.list.clear()
|
||||
this.list = list
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class HomePresenter() : BasePresenter<HomeActivity>() {
|
|||
override fun onSuccess(k: BaseBean<List<ActivityBean>>?) {
|
||||
loadBoolean = k?.data?.size == 15
|
||||
if (k != null) {
|
||||
v.showList(page, k.data)
|
||||
v.showList(page, k.data as MutableList<ActivityBean>)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.skipping.activity.setting
|
|||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.libs.fragment.BaseActivity
|
||||
import com.libs.utils.ActivityManager
|
||||
|
|
@ -99,4 +101,10 @@ class SettingActivity : BaseActivity<SettingPresenter>() {
|
|||
ScreenUtil.setCustomDensity(this)
|
||||
super.onRestart()
|
||||
}
|
||||
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
HomeActivity.startHome(this)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -36,41 +36,44 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
manager.getpower()
|
||||
LogUtil.e("列表", manager.deviceBeanList)
|
||||
}
|
||||
pair_btn.setOnClickListener {
|
||||
if (position == 0) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
position = 0
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_clicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_unclicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
pair_power.visibility = View.GONE
|
||||
pair_ll.visibility = View.VISIBLE
|
||||
adaper.changeStatus(PairAdaper.STATUS.con)
|
||||
manager.openPairMode()
|
||||
manager.disconnectDevice()
|
||||
}
|
||||
|
||||
connect_btn.setOnClickListener {
|
||||
if (position == 1) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
position = 1
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_unclicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_clicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
pair_power.visibility = View.VISIBLE
|
||||
pair_ll.visibility = View.GONE
|
||||
adaper.changeStatus(PairAdaper.STATUS.uncon)
|
||||
manager.connectDevice()
|
||||
}
|
||||
title_host.setOnClickListener {
|
||||
manager.getpower()
|
||||
}
|
||||
}
|
||||
|
||||
fun click0() {
|
||||
if (position == 0) {
|
||||
return
|
||||
}
|
||||
position = 0
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_clicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_unclicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
pair_power.visibility = View.GONE
|
||||
pair_ll.visibility = View.VISIBLE
|
||||
adaper.changeStatus(PairAdaper.STATUS.con)
|
||||
manager.openPairMode()
|
||||
manager.disconnectDevice()
|
||||
}
|
||||
|
||||
|
||||
fun click1() {
|
||||
if (position == 1) {
|
||||
return
|
||||
}
|
||||
position = 1
|
||||
pair_btn.setBackgroundResource(R.drawable.pair_btn_unclicked)
|
||||
pair_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.white))
|
||||
connect_btn.setBackgroundResource(R.drawable.connect_btn_clicked)
|
||||
connect_btn.setTextColor(ContextCompat.getColor(activity!!, R.color.black))
|
||||
pair_power.visibility = View.VISIBLE
|
||||
pair_ll.visibility = View.GONE
|
||||
adaper.changeStatus(PairAdaper.STATUS.uncon)
|
||||
manager.connectDevice()
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
manager = ConnectManager.getSingleton()
|
||||
manager.setOnflushListListener {
|
||||
|
|
@ -103,6 +106,22 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
// pair_list.adapter = adaper
|
||||
// adaper.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (manager.deviceStatus) {
|
||||
click1()
|
||||
} else {
|
||||
click0()
|
||||
}
|
||||
|
||||
|
||||
pair_btn.setOnClickListener {
|
||||
click0()
|
||||
}
|
||||
connect_btn.setOnClickListener {
|
||||
click1()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ import com.tencent.mmkv.MMKV;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
/**
|
||||
|
|
@ -53,6 +55,7 @@ public class ConnectManager {
|
|||
private DialogTool dialog;
|
||||
public HashMap<Integer, List<Integer>> scoreMap = new HashMap<>();
|
||||
private boolean getScore = false;
|
||||
public Boolean deviceStatus = false;
|
||||
|
||||
public static ConnectManager getSingleton() {
|
||||
if (connectManager == null) {
|
||||
|
|
@ -65,6 +68,20 @@ public class ConnectManager {
|
|||
return connectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
*
|
||||
* @return true有设备 false无设备
|
||||
*/
|
||||
public boolean deviceNum() {
|
||||
for (DeviceBean deviceBean : deviceBeanList) {
|
||||
if(deviceBean.getLoopDevice()!=null){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setList(List<DeviceBean> deviceBeanList) {
|
||||
deviceBeanList.clear();
|
||||
this.deviceBeanList.addAll(deviceBeanList);
|
||||
|
|
@ -150,6 +167,7 @@ public class ConnectManager {
|
|||
*/
|
||||
public void openPairMode() {
|
||||
loopMini.openPairMode();
|
||||
deviceStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,13 +203,12 @@ public class ConnectManager {
|
|||
loopMini.startJumpLimitTime(n);
|
||||
}
|
||||
|
||||
public void start(){
|
||||
public void start() {
|
||||
getScore = true;
|
||||
scoreMap.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 停止计数
|
||||
*/
|
||||
|
|
@ -206,9 +223,9 @@ public class ConnectManager {
|
|||
* @param id
|
||||
*/
|
||||
public void pairDevice(Activity activity, int id) {
|
||||
LogUtil.e("连接到", id);
|
||||
if (dialog != null) {
|
||||
dialog.setStatus(Status.CONNECTING);
|
||||
dialog.dialog.show();
|
||||
} else {
|
||||
dialog = new DialogTool();
|
||||
dialog.build(activity, Status.CONNECTING, String.valueOf(id));
|
||||
|
|
@ -229,10 +246,12 @@ public class ConnectManager {
|
|||
*/
|
||||
public void connectDevice() {
|
||||
connectDeviceInner(1);
|
||||
deviceStatus = true;
|
||||
}
|
||||
|
||||
public void disconnectDevice() {
|
||||
connectDeviceInner(0);
|
||||
deviceStatus = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue