function signIn(){
    //打开手机App
    home();
    sleep(2000);
   launchApp('抖音极速版');
   sleep(1500);
   var activityName = currentActivity();
   waitForActivity("com.ss.android.ugc.aweme.main.MainActivity");
   toastLog("name==="+activityName);
   while(true){
    activityName = currentActivity();
    if(activityName.includes("Launcher")){
        home();
        sleep(5000);
        launchApp('抖音极速版');
        continue;
    }
    if(activityName == "com.ss.android.ugc.aweme.main.MainActivity"){
        var isRoom = checkIsDirectBroadcastingRoom()
        if(isRoom){
            continue;
        }
        sleep(2000)
        checkIsGiveLike()
        sleep(1000)
        swipe(300,1200,300,300,500);
    }
   }
}

//校验是否是直播间
function checkIsDirectBroadcastingRoom(){
  var roomPreviewList = id("g+m").find();
  if(roomPreviewList.empty()){
    toastLog("===不是直播间")
    return false;
  }

  var room;

  for(var i =0 ; i < roomPreviewList.length ;i++){
      var eachRoom = roomPreviewList[i]
      if(eachRoom.bounds().centerY > 0 && eachRoom.bounds().centerY < device.height){
        room = eachRoom;
        break;
      }
  }
  if(room == null){
    toastLog("===不是直播间")
    return false;
  }
  toastLog("===当前是直播间==直接划走===")
  swipe(300,1200,300,300,500);
  return true;
}

function checkIsGiveLike(){
    toastLog("====checkIsGiveLike===")
    // var likeBtn  = id("ct=").findOne();
    var likeBtns  = id("ct=").find();
    var likeBtn;
    if(likeBtns.empty()){
        toastLog("=====没找到按钮");
    }else {
        for (var i = 0; i < likeBtns.length; i++) {
            var btn = likeBtns[i];
            if(btn.bounds().centerY() > 0 && btn.bounds().centerY() < device.height){
                likeBtn = btn;
                break;
            }
        }
    }
    if(likeBtn == null){
        toastLog("=====没找到按钮===2");
        return;
    }
    requestScreenCapture()
    var img = captureScreen();
    //获取在点(100, 100)的颜色值
    toastLog("=====bounds===="+likeBtn.bounds());
    var color = images.pixel(img, likeBtn.bounds().centerX(), likeBtn.bounds().centerY());
    var likeBtnRedColor = colors.red(color)
    var likeBtnBlueColor = colors.blue(color)
    var likeBtnGreenColor = colors.green(color)
    toastLog("====red====="+likeBtnRedColor);
    if(likeBtnRedColor > 200 && likeBtnBlueColor > 200 && likeBtnGreenColor > 200){
        toastLog("====还没点过赞了====");
        likeBtn.click();
    }
}
//检查无障碍服务是否启动,若没有则跳转到无障碍服务启动界面,并等待;当服务启动后脚本继续运行
auto.waitFor();
//调用签到方法
signIn();