[function]成绩录入上报
This commit is contained in:
parent
7a3e13eede
commit
d216996ec9
|
|
@ -6,13 +6,12 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.libs.fragment.BaseActivity
|
||||
import com.libs.utils.LogUtil
|
||||
import com.skipping.*
|
||||
import com.skipping.TIMING_NAME
|
||||
import com.skipping.net.DetailActivityBean
|
||||
import com.skipping.utils.NumberUtil
|
||||
import com.skipping.utils.ScreenUtil
|
||||
import com.skipping.utils.ThreadPoolUtil
|
||||
import com.skipping.view.bubblewindow.BubbleWindow
|
||||
import com.skipping.net.ScoreReqBean
|
||||
import com.skipping.utils.*
|
||||
import com.skipping.view.dialog.DialogBean
|
||||
import com.skipping.view.dialog.DialogTool
|
||||
import kotlinx.android.synthetic.main.activity_begin.*
|
||||
|
|
@ -30,10 +29,12 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
lateinit var adaper: BeginGridAdaper
|
||||
lateinit var detailBean: DetailActivityBean
|
||||
lateinit var future: ScheduledFuture<*>
|
||||
lateinit var bubbleWindow: BubbleWindow
|
||||
lateinit var dialog: AlertDialog
|
||||
var choseCla: List<DetailActivityBean.CandidatesBean>? = null
|
||||
var choseGradeBeanList = mutableListOf<DialogBean<List<DetailActivityBean.CandidatesBean>>>()
|
||||
lateinit var showBean: List<DetailActivityBean.CandidatesBean>
|
||||
var position = 0
|
||||
var scList = mutableListOf<ScoreReqBean.CandidatesBean>()
|
||||
var complete = mutableListOf<Int>()
|
||||
|
||||
companion object {
|
||||
val ID = "id"
|
||||
|
|
@ -68,25 +69,41 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
if (detailBean.activityType == TIMING) {
|
||||
//定时计数
|
||||
var num = detailBean.activityValue
|
||||
ConnectManager.getSingleton().startJumpLimitTime(num)
|
||||
|
||||
future = ThreadPoolUtil.getSingleton().scheduleWithFixedDelayMain({
|
||||
if (num <= 0) {
|
||||
ConnectManager.getSingleton().stopGetScore()
|
||||
// ConnectManager.getSingleton().stopJump()
|
||||
future.cancel(false)
|
||||
choseGradeBeanList.get(position).bean = showBean
|
||||
choseGradeBeanList.get(position).bean
|
||||
score()
|
||||
return@scheduleWithFixedDelayMain
|
||||
}
|
||||
ConnectManager.getSingleton().getCount()
|
||||
num--
|
||||
begin_type.text = TIMING_NAME + ": " + num + " 秒"
|
||||
}, 0, 1000)
|
||||
begin_type.text = "${TIMING_NAME}: ${num} 秒"
|
||||
flushScore()
|
||||
}, 1000, 1000)
|
||||
|
||||
}
|
||||
}
|
||||
begin_listRL.setOnClickListener {
|
||||
dialog = DialogTool().buildList(this, choseGradeBeanList) {
|
||||
adaper.list = it.bean
|
||||
dialog = DialogTool().buildList(this, choseGradeBeanList) { bean, p ->
|
||||
position = p
|
||||
showBean = bean.bean
|
||||
adaper.list = showBean
|
||||
adaper.notifyDataSetChanged()
|
||||
begin_list.text = it.content
|
||||
begin_list.text = bean.content
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
begin_type.setOnClickListener {
|
||||
ConnectManager.getSingleton().getCount()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +113,9 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
val num = NumberUtil.numberToChinese(index + 1)
|
||||
choseGradeBeanList.add(DialogBean("第 $num 组", mutableList))
|
||||
}
|
||||
|
||||
detailBean = bean
|
||||
showBean = bean.candidates[0]
|
||||
begin_name.text = bean.activityName
|
||||
if (detailBean.activityType == TIMING) {
|
||||
begin_type.text = TIMING_NAME + ": " + bean.activityValue + " 秒"
|
||||
|
|
@ -104,8 +123,56 @@ class BeginActivity : BaseActivity<BeginPresenter>() {
|
|||
begin_type.text = NUMBER_NAME + ": " + bean.activityValue + " 个"
|
||||
}
|
||||
beginList.layoutManager = GridLayoutManager(this, 4)
|
||||
adaper = BeginGridAdaper(this, bean.candidates[0])
|
||||
adaper = BeginGridAdaper(this, showBean)
|
||||
beginList.adapter = adaper
|
||||
}
|
||||
|
||||
fun flushScore() {
|
||||
var scoreMap = ConnectManager.getSingleton().scoreMap
|
||||
showBean.forEachIndexed { index, bean ->
|
||||
val list = scoreMap.get(index + 1)
|
||||
if (list != null) {
|
||||
bean.score = list?.get(list.size - 1)
|
||||
}
|
||||
}
|
||||
adaper.list = showBean
|
||||
adaper.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
||||
fun score() {
|
||||
var bean = ScoreReqBean.CandidatesBean()
|
||||
bean.complateTime = (System.currentTimeMillis() / 1000).toInt()
|
||||
var list = mutableListOf<ScoreReqBean.CandidatesBean.InfoBean>()
|
||||
choseGradeBeanList.get(position).bean.forEachIndexed() { position, it ->
|
||||
var info = ScoreReqBean.CandidatesBean.InfoBean()
|
||||
info.personID = it.personID
|
||||
info.score = it.score
|
||||
info.detail = cute()
|
||||
list.add(info)
|
||||
}
|
||||
bean.info = list
|
||||
scList.add(bean)
|
||||
complete.add(position)
|
||||
if (complete.size == choseGradeBeanList.size) {
|
||||
p.score(intent.getBundleExtra(DATA).getString(ID).toInt(), detailBean.step, scList)
|
||||
}
|
||||
}
|
||||
|
||||
fun cute(): List<Int> {
|
||||
var list = ConnectManager.getSingleton().scoreMap.get(position + 1)
|
||||
LogUtil.e("111", list)
|
||||
var newList = mutableListOf<Int>()
|
||||
for (i in 0..(list?.size!! / 2 - 1)) {
|
||||
newList.add(list[i])
|
||||
}
|
||||
LogUtil.e("222", newList)
|
||||
return newList
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
ConnectManager.getSingleton().stopJump()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,8 @@ class BeginGridAdaper(context: Context, list: List<DetailActivityBean.Candidates
|
|||
override fun onBindViewHolder(holder: BeginGridAdaper.Holder, position: Int) {
|
||||
holder.begin_item_name.text = list[position].name
|
||||
holder.begin_item_id.text = list[position].studentID
|
||||
holder.begin_item_num.text = (position + 1).toString()
|
||||
holder.begin_item_number.text = list[position].score.toString()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
|
@ -51,6 +53,8 @@ class BeginGridAdaper(context: Context, list: List<DetailActivityBean.Candidates
|
|||
class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var begin_item_name = itemView.findViewById<TextView>(R.id.begin_item_name)
|
||||
var begin_item_id = itemView.findViewById<TextView>(R.id.begin_item_id)
|
||||
var begin_item_num = itemView.findViewById<TextView>(R.id.begin_item_num)
|
||||
var begin_item_number = itemView.findViewById<TextView>(R.id.begin_item_number)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.os.Parcelable
|
|||
import com.libs.fragment.BasePresenter
|
||||
import com.libs.network.CallBack
|
||||
import com.libs.network.Concise
|
||||
import com.libs.utils.LogUtil
|
||||
import com.libs.utils.ToastUtil
|
||||
import com.skipping.ACCOUNT
|
||||
import com.skipping.BASE_URL
|
||||
|
|
@ -24,7 +25,7 @@ class BeginPresenter() : BasePresenter<BeginActivity>() {
|
|||
val concise: Concise<API> = object : Concise<API>(BASE_URL) {}.addHeader("Token", mmkv?.decodeString(TOKEN)).build() as Concise<API>
|
||||
|
||||
fun getActivityDetail(id: String) {
|
||||
concise.request(v, concise.api.detailActivity(id), object : CallBack<BaseBean<DetailActivityBean>>{
|
||||
concise.request(v, concise.api.detailActivity(id), object : CallBack<BaseBean<DetailActivityBean>> {
|
||||
override fun onSuccess(k: BaseBean<DetailActivityBean>?) {
|
||||
v.activityDetailResult(k?.data!!)
|
||||
}
|
||||
|
|
@ -33,4 +34,22 @@ class BeginPresenter() : BasePresenter<BeginActivity>() {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun score(id:Int,step:Int,list: List<ScoreReqBean.CandidatesBean>) {
|
||||
var bean = ScoreReqBean()
|
||||
bean.id = id
|
||||
bean.step = step
|
||||
bean.candidates = list
|
||||
LogUtil.e("提交数据",bean)
|
||||
|
||||
// concise.request(v, concise.api.score(bean), object : CallBack<BaseBean<*>> {
|
||||
// override fun onSuccess(k: BaseBean<*>?) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// override fun onFailed(e: Throwable?) {
|
||||
// }
|
||||
//
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import com.libs.fragment.BaseActivity
|
|||
import com.libs.utils.ActivityManager
|
||||
import com.libs.utils.LogUtil
|
||||
import com.libs.utils.ToastUtil
|
||||
import com.loop.loopminisdk.LoopMini
|
||||
import com.skipping.*
|
||||
import com.skipping.activity.begin.BeginActivity
|
||||
import com.skipping.activity.perform.PerformActivity
|
||||
|
|
@ -22,6 +23,7 @@ import com.skipping.net.GradleBean
|
|||
import com.skipping.utils.ConnectManager
|
||||
import com.skipping.utils.DateUtils
|
||||
import com.skipping.utils.ScreenUtil
|
||||
import com.skipping.utils.ThreadPoolUtil
|
||||
import com.skipping.view.dialog.DialogBean
|
||||
import com.skipping.view.dialog.DialogTool
|
||||
import kotlinx.android.synthetic.main.activity_detail.view.*
|
||||
|
|
@ -40,6 +42,7 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
lateinit var adaper: HomeGridAdaper
|
||||
var position = 0
|
||||
val layoutManager = GridLayoutManager(this, 3)
|
||||
lateinit var manager:ConnectManager
|
||||
|
||||
companion object {
|
||||
fun startHome(activity: Activity) {
|
||||
|
|
@ -58,7 +61,7 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
}
|
||||
|
||||
override fun initData() {
|
||||
ConnectManager.getSingleton()
|
||||
manager = ConnectManager.getSingleton()
|
||||
setting_btn.setOnClickListener {
|
||||
startActivity(Intent(this@HomeActivity, SettingActivity::class.java))
|
||||
}
|
||||
|
|
@ -69,10 +72,11 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
p.getClassList()
|
||||
|
||||
choseClass.setOnClickListener {
|
||||
dialog = DialogTool().buildList(this, choseGradeBeanList) {
|
||||
choseCla = it.bean
|
||||
chooseIV.text = it.bean.groupName + "班"
|
||||
activityNameEdit?.setText(it.bean.groupName + "班活动")
|
||||
dialog = DialogTool().buildList(this, choseGradeBeanList){
|
||||
bean, _ ->
|
||||
choseCla = bean.bean
|
||||
chooseIV.text = bean.bean.groupName + "班"
|
||||
activityNameEdit?.setText(bean.bean.groupName + "班活动")
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
|
@ -211,5 +215,10 @@ class HomeActivity : BaseActivity<HomePresenter>() {
|
|||
super.onRestart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
manager.resume()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.skipping.fragment.pair
|
|||
import com.libs.utils.LogUtil
|
||||
import com.loop.loopminisdk.LoopDevice
|
||||
import com.loop.loopminisdk.LoopHost
|
||||
import com.loop.loopminisdk.LoopMini
|
||||
|
||||
/**
|
||||
* @author Ming
|
||||
|
|
@ -13,7 +14,6 @@ class DeviceBean {
|
|||
var Code: String? = null
|
||||
get() {
|
||||
if (field?.get(0) == '0') {
|
||||
LogUtil.e("123123")
|
||||
return field?.replace("0", "")
|
||||
}
|
||||
return field
|
||||
|
|
@ -22,6 +22,7 @@ class DeviceBean {
|
|||
var loopDevice: LoopDevice? = null
|
||||
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return "DeviceBean(Code=$Code, loopDevice=$loopDevice)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
override fun initView(view: View?, savedInstanceState: Bundle?) {
|
||||
initPresnter()
|
||||
pairStatus.setOnClickListener {
|
||||
manager.getpower()
|
||||
LogUtil.e("列表", manager.deviceBeanList)
|
||||
}
|
||||
pair_btn.setOnClickListener {
|
||||
|
|
@ -47,6 +48,8 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
pair_power.visibility = View.GONE
|
||||
pair_ll.visibility = View.VISIBLE
|
||||
adaper.changeStatus(PairAdaper.STATUS.con)
|
||||
manager.openPairMode()
|
||||
manager.disconnectDevice()
|
||||
}
|
||||
|
||||
connect_btn.setOnClickListener {
|
||||
|
|
@ -61,9 +64,10 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
pair_power.visibility = View.VISIBLE
|
||||
pair_ll.visibility = View.GONE
|
||||
adaper.changeStatus(PairAdaper.STATUS.uncon)
|
||||
manager.connectDevice()
|
||||
}
|
||||
title_host.setOnClickListener {
|
||||
manager.openPairMode()
|
||||
manager.getpower()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,13 +78,21 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
adaper.notifyDataSetChanged()
|
||||
}
|
||||
showDeviceList()
|
||||
if (manager.host != null) {
|
||||
var bytes = manager.host.macList
|
||||
pair_address.text = "网关地址:" + LoopMini.bytesToHexString(bytes)
|
||||
pair_id.text = "网关id:" + manager.host.hostId.toString()
|
||||
pair_list.layoutManager = LinearLayoutManager(activity)
|
||||
pairStatus.text = "主机已连接"
|
||||
}
|
||||
|
||||
|
||||
manager.setLoopHostListener {
|
||||
var bytes = it.macList
|
||||
pair_address.text = "网关地址:" + LoopMini.bytesToHexString(bytes)
|
||||
pair_id.text = "网关id:" + it.hostId.toString()
|
||||
pair_list.layoutManager = LinearLayoutManager(activity)
|
||||
|
||||
pairStatus.text = "主机已连接"
|
||||
// for (i in 0..it.license) {
|
||||
// var device = LoopDevice().apply {
|
||||
// this.loopDeviceId = i
|
||||
|
|
@ -93,32 +105,8 @@ class PairFragment : BaseFragment<PairPresenter>() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
manager.resume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// manager.pause()
|
||||
}
|
||||
|
||||
fun deviceList(list: List<DeviceCode>) {
|
||||
// list.forEach {
|
||||
// var deviceBean = DeviceBean()
|
||||
// deviceBean.Code = it.code
|
||||
// deviceList.add(deviceBean)
|
||||
// }
|
||||
// manager.setList(deviceList)
|
||||
// pair_list.layoutManager = LinearLayoutManager(activity)
|
||||
// adaper = PairAdaper(activity, deviceList)
|
||||
// adaper.setOnConnectClickListener {
|
||||
// manager.pairDevice(activity, it.Code?.toInt()!!)
|
||||
// }
|
||||
// pair_list.adapter = adaperpair_item_tv5
|
||||
}
|
||||
|
||||
fun showDeviceList(){
|
||||
fun showDeviceList() {
|
||||
pair_list.layoutManager = LinearLayoutManager(activity)
|
||||
adaper = PairAdaper(activity, manager.deviceBeanList)
|
||||
adaper.setOnConnectClickListener {
|
||||
|
|
|
|||
|
|
@ -18,17 +18,5 @@ import com.tencent.mmkv.MMKV
|
|||
*
|
||||
*/
|
||||
class PairPresenter :BasePresenter<PairFragment>(){
|
||||
val mmkv = MMKV.defaultMMKV()
|
||||
val concise: Concise<API> = object : Concise<API>(BASE_URL) {}.addHeader("Token", mmkv?.decodeString(TOKEN)).build() as Concise<API>
|
||||
|
||||
fun getDeviceList(){
|
||||
concise.request(v, concise.api.getdeviceList(), object : CallBack<BaseBean<List<DeviceCode>>> {
|
||||
override fun onSuccess(k: BaseBean<List<DeviceCode>>?) {
|
||||
v.deviceList(k?.data!!)
|
||||
}
|
||||
|
||||
override fun onFailed(e: Throwable?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -133,7 +133,7 @@ public class DetailActivityBean implements Serializable {
|
|||
private String Name;
|
||||
private String StudentID;
|
||||
private Integer Score;
|
||||
private Object Detail;
|
||||
private List<Integer> Detail;
|
||||
|
||||
public String getPersonID() {
|
||||
return PersonID;
|
||||
|
|
@ -167,11 +167,11 @@ public class DetailActivityBean implements Serializable {
|
|||
Score = score;
|
||||
}
|
||||
|
||||
public Object getDetail() {
|
||||
public List<Integer> getDetail() {
|
||||
return Detail;
|
||||
}
|
||||
|
||||
public void setDetail(Object detail) {
|
||||
public void setDetail(List<Integer> detail) {
|
||||
Detail = detail;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.skipping.view.dialog.Status;
|
|||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -48,7 +49,6 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class ConnectManager {
|
||||
private LoopMini loopMax;
|
||||
private Set<LoopDevice> loopDeviceSet = new HashSet<>();
|
||||
private LoopDevice loopDevice;
|
||||
private LoopHost loopHost;
|
||||
private Handler mHandler;
|
||||
|
|
@ -60,6 +60,8 @@ public class ConnectManager {
|
|||
public List<DeviceBean> deviceBeanList = new ArrayList<>();
|
||||
private ScheduledFuture future;
|
||||
private DialogTool dialog;
|
||||
public HashMap<Integer, List<Integer>> scoreMap = new HashMap<>();
|
||||
private boolean getScore = false;
|
||||
|
||||
public static ConnectManager getSingleton() {
|
||||
if (connectManager == null) {
|
||||
|
|
@ -77,12 +79,16 @@ public class ConnectManager {
|
|||
this.deviceBeanList.addAll(deviceBeanList);
|
||||
}
|
||||
|
||||
public void stopGetScore() {
|
||||
getScore = false;
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case LoopMini.ACTION_USB_PERMISSION_GRANTED:
|
||||
connect();
|
||||
ToastUtil.longToast("确认设备权限");
|
||||
break;
|
||||
case LoopMini.ACTION_USB_PERMISSION_NOT_GRANTED:
|
||||
|
|
@ -101,15 +107,7 @@ public class ConnectManager {
|
|||
}
|
||||
};
|
||||
|
||||
public ConnectManager() {
|
||||
mHandler = new DeviceHandler();
|
||||
getdeviceList();
|
||||
}
|
||||
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
|
||||
loopMax = ((LoopMini.UsbBinder) arg1).getService();
|
||||
private void connect() {
|
||||
loopMax.setHandler(mHandler);
|
||||
ThreadPoolUtil.getSingleton().scheduleMain(new Runnable() {
|
||||
@Override
|
||||
|
|
@ -120,6 +118,27 @@ public class ConnectManager {
|
|||
}, 1000);
|
||||
}
|
||||
|
||||
public ConnectManager() {
|
||||
mHandler = new DeviceHandler();
|
||||
getdeviceList();
|
||||
}
|
||||
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
|
||||
LogUtil.e("连接成功");
|
||||
loopMax = ((LoopMini.UsbBinder) arg1).getService();
|
||||
connect();
|
||||
// loopMax.setHandler(mHandler);
|
||||
// ThreadPoolUtil.getSingleton().scheduleMain(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// loopMax.getHostInfo();
|
||||
// loopMax.openPairMode();
|
||||
// }
|
||||
// }, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
loopMax = null;
|
||||
|
|
@ -148,6 +167,13 @@ public class ConnectManager {
|
|||
loopMax.getPower();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电量
|
||||
*/
|
||||
public void getCount() {
|
||||
loopMax.getCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭配对模式
|
||||
*/
|
||||
|
|
@ -155,6 +181,27 @@ public class ConnectManager {
|
|||
loopMax.closePairMode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定时计数
|
||||
*
|
||||
* @param n
|
||||
*/
|
||||
public void startJumpLimitTime(int n) {
|
||||
getScore = true;
|
||||
scoreMap.clear();
|
||||
loopMax.startJumpLimitTime(n);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 停止计数
|
||||
*/
|
||||
public void stopJump() {
|
||||
getScore = false;
|
||||
loopMax.stopJump();
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配设备到指定id
|
||||
*
|
||||
|
|
@ -183,33 +230,43 @@ public class ConnectManager {
|
|||
* 连接设备
|
||||
*/
|
||||
public void connectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.connectDevice(loopDevice));
|
||||
connectDeviceInner(1);
|
||||
}
|
||||
|
||||
public void disconnectDevice() {
|
||||
connectDeviceInner(loopDevice -> loopMax.disconnectDevice(loopDevice));
|
||||
connectDeviceInner(0);
|
||||
}
|
||||
|
||||
|
||||
public void connectDeviceInner(HostActivity.ConnectInterface connectInterface) {
|
||||
if (loopDeviceSet.size() == 0) {
|
||||
public void connectDeviceInner(int status) {
|
||||
closePairMode();
|
||||
if (deviceBeanList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (scheduledFuture != null) {
|
||||
scheduledFuture.cancel(false);
|
||||
}
|
||||
List<LoopDevice> deviceList = loopDeviceSet.stream().collect(Collectors.toList());
|
||||
position = 0;
|
||||
scheduledFuture = ThreadPoolUtil.getSingleton().scheduleAtFixedRate(new Runnable() {
|
||||
scheduledFuture = ThreadPoolUtil.getSingleton().scheduleAtFixedRateMain(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (position > deviceList.size()) {
|
||||
scheduledFuture.cancel(false);
|
||||
if (loopMax != null && deviceBeanList.get(position).getLoopDevice() != null) {
|
||||
if (status == 1) {
|
||||
LogUtil.e("连接设备", deviceBeanList.get(position).getLoopDevice());
|
||||
loopMax.connectDevice(deviceBeanList.get(position).getLoopDevice());
|
||||
} else if (status == 0) {
|
||||
LogUtil.e("断开设备", deviceBeanList.get(position).getLoopDevice());
|
||||
loopMax.disconnectDevice(deviceBeanList.get(position).getLoopDevice());
|
||||
}
|
||||
}
|
||||
connectInterface.connect(deviceList.get(position));
|
||||
position++;
|
||||
if (position >= deviceBeanList.size()) {
|
||||
scheduledFuture.cancel(false);
|
||||
getpower();
|
||||
return;
|
||||
}
|
||||
}, 0, 10);
|
||||
}
|
||||
}, 0, 20);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -251,15 +308,30 @@ public class ConnectManager {
|
|||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case LoopMini.LOOP_PAIR_DEVICE_INFO:
|
||||
case LoopMini.LOOP_GET_DEVICE_INFO:
|
||||
loopDevice = (LoopDevice) msg.obj;
|
||||
addList(loopDevice);
|
||||
// addDevice(loopDevice);
|
||||
LogUtil.e("连接LoopDevice", loopDevice.toString());
|
||||
LogUtil.e("连接LoopDevice__LOOP_PAIR_DEVICE_INFO", loopDevice.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_GET_DEVICE_INFO:
|
||||
loopDevice = (LoopDevice) msg.obj;
|
||||
LogUtil.e("连接LoopDevice__LOOP_GET_DEVICE_INFO", loopDevice.toString());
|
||||
if (getScore) {
|
||||
if (scoreMap.get(loopDevice.loopDeviceId) == null) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.add(loopDevice.count);
|
||||
scoreMap.put(loopDevice.loopDeviceId, list);
|
||||
} else {
|
||||
scoreMap.get(loopDevice.loopDeviceId).add(loopDevice.count);
|
||||
}
|
||||
} else {
|
||||
addList(loopDevice);
|
||||
}
|
||||
break;
|
||||
case LoopMini.Loop_GET_HOST_INFO:
|
||||
loopHost = (LoopHost) msg.obj;
|
||||
if (onLoopHost != null) {
|
||||
onLoopHost.connected(loopHost);
|
||||
}
|
||||
LogUtil.e("LoopHost", loopHost.toString());
|
||||
break;
|
||||
case LoopMini.LOOP_MESSAGE:
|
||||
|
|
@ -278,14 +350,6 @@ public class ConnectManager {
|
|||
}
|
||||
}
|
||||
|
||||
private void addDevice(LoopDevice loopDevice) {
|
||||
loopDeviceSet.add(loopDevice);
|
||||
}
|
||||
|
||||
public Set<LoopDevice> getDevice() {
|
||||
return loopDeviceSet;
|
||||
}
|
||||
|
||||
public void setLoopHostListener(OnLoopHost onLoopHost) {
|
||||
this.onLoopHost = onLoopHost;
|
||||
}
|
||||
|
|
@ -309,13 +373,29 @@ public class ConnectManager {
|
|||
|
||||
|
||||
private void addList(LoopDevice loopDevice) {
|
||||
String macList = LoopMini.bytesToHexString(loopDevice.macList);
|
||||
for (DeviceBean deviceBean : deviceBeanList) {
|
||||
if (deviceBean.getLoopDevice() != null) {
|
||||
String s1 = LoopMini.bytesToHexString(deviceBean.getLoopDevice().getMacList());
|
||||
if (!s1.equals("[00, 00, 00, 00, 00, 00]") && s1.equals(macList) && !deviceBean.getCode().equals(String.valueOf(loopDevice.loopDeviceId))) {
|
||||
deviceBean.setLoopDevice(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DeviceBean deviceBean : deviceBeanList) {
|
||||
if (deviceBean.getCode().equals(String.valueOf(loopDevice.loopDeviceId))) {
|
||||
if (deviceBean.getLoopDevice() == null) {
|
||||
deviceBean.setLoopDevice(loopDevice);
|
||||
} else {
|
||||
deviceBean.getLoopDevice().setCount(loopDevice.getCount());
|
||||
// deviceBean.getLoopDevice().setMacList(loopDevice.macList);
|
||||
// deviceBean.getLoopDevice().setMacCS(loopDevice.getMacCS());
|
||||
deviceBean.getLoopDevice().setPower(loopDevice.getPower());
|
||||
deviceBean.getLoopDevice().setTime(loopDevice.getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
onflushList.flush();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.skipping.view.dialog
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -8,7 +7,6 @@ import android.view.ViewGroup
|
|||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.skipping.R
|
||||
import com.skipping.TIMING_NAME
|
||||
import com.skipping.net.ActivityBean
|
||||
import com.skipping.net.DetailActivityBean
|
||||
|
||||
|
|
@ -19,7 +17,7 @@ import com.skipping.net.DetailActivityBean
|
|||
*/
|
||||
class DialogAdaper<T>(context: Context, val list: List<DialogBean<T>>) : RecyclerView.Adapter<DialogAdaper.Holder>() {
|
||||
var context = context
|
||||
lateinit var onClick: (bean: DialogBean<T>) -> Unit
|
||||
lateinit var onClick: (bean: DialogBean<T>, position: Int) -> Unit
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DialogAdaper.Holder {
|
||||
return Holder(LayoutInflater.from(context).inflate(R.layout.dialog_item, parent, false))
|
||||
|
|
@ -28,7 +26,7 @@ class DialogAdaper<T>(context: Context, val list: List<DialogBean<T>>) : Recycle
|
|||
override fun onBindViewHolder(holder: DialogAdaper.Holder, position: Int) {
|
||||
holder.dialog_item_content.text = list[position].content
|
||||
holder.itemView.setOnClickListener {
|
||||
onClick.invoke(list[position])
|
||||
onClick.invoke(list[position], position)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +39,7 @@ class DialogAdaper<T>(context: Context, val list: List<DialogBean<T>>) : Recycle
|
|||
}
|
||||
|
||||
|
||||
fun setOnItemClickListener(onClick: (bean: DialogBean<T>) -> Unit) {
|
||||
fun setOnItemClickListener(onClick: (bean: DialogBean<T>, position: Int) -> Unit) {
|
||||
this.onClick = onClick
|
||||
}
|
||||
}
|
||||
|
|
@ -5,5 +5,9 @@ package com.skipping.view.dialog
|
|||
* 3/29/22
|
||||
*
|
||||
*/
|
||||
class DialogBean<T>(val content: String, val bean: T) {
|
||||
class DialogBean<T>(val content: String, var bean: T) {
|
||||
|
||||
override fun toString(): String {
|
||||
return "DialogBean(content='$content', bean=${bean.toString()})"
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package com.skipping.view.dialog
|
|||
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.animation.LinearInterpolator
|
||||
import android.widget.ImageView
|
||||
|
|
@ -11,9 +10,7 @@ import android.widget.TextView
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.skipping.R
|
||||
import com.skipping.fragment.pair.PairFragment
|
||||
import com.skipping.utils.ThreadPoolUtil
|
||||
import org.w3c.dom.Text
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
|
||||
/**
|
||||
|
|
@ -95,7 +92,7 @@ class DialogTool() {
|
|||
}
|
||||
|
||||
|
||||
fun <T> buildList(activity: Activity, list: List<DialogBean<T>>, onClick: (bean: DialogBean<T>) -> Unit): AlertDialog {
|
||||
fun <T> buildList(activity: Activity, list: List<DialogBean<T>>, onClick: (bean: DialogBean<T>, position: Int) -> Unit): AlertDialog {
|
||||
dialog = AlertDialog.Builder(activity, R.style.bubble_dialog_style).create()
|
||||
val view = View.inflate(activity, R.layout.dialog_view_list, null)
|
||||
val dialog_list_ll = view.findViewById<LinearLayout>(R.id.dialog_list_ll)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="36dp"/>
|
||||
<solid android:color="@color/color_50_D8D8D8" />
|
||||
</shape>
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:paddingRight="30dp"
|
||||
android:paddingBottom="30dp"
|
||||
android:text="第一组"
|
||||
android:text="第 一 组"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28dp" />
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -26,20 +26,32 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/begin_item_name"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="王一"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/begin_item_id"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:text="15号"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="24dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/begin_item_num"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@drawable/begin_item_tv"
|
||||
android:gravity="center"
|
||||
android:text="1"
|
||||
android:textColor="@color/color_3d3d3d"
|
||||
android:textSize="28dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
<color name="color_D9D9D9">#D9D9D9</color>
|
||||
<color name="color_F4EA2A">#F4EA2A</color>
|
||||
<color name="color_00FF55">#00FF55</color>
|
||||
<color name="color_D8D8D8">#D8D8D8</color>
|
||||
<color name="color_50_D8D8D8">#80D8D8D8</color>
|
||||
<color name="color_70_E6E6E6">#4DE6E6E6</color>
|
||||
<color name="color_45_2C2C2C">#8C2C2C2C</color>
|
||||
|
|
|
|||
Loading…
Reference in New Issue