wangrong
2024-12-10 9d5a2a788bedb68e99c080ed77e7e0e5051e90d4
app/src/main/java/com/shsening/autouploadvideos/action/ActionRedbook.kt
@@ -1,4 +1,4 @@
package com.shsening.autouploadvideos.action
package com.shsening.autouploadvideos
import android.app.Instrumentation
@@ -8,8 +8,6 @@
import android.os.Bundle
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import com.shsening.autouploadvideos.UploadSessionActivity
import com.shsening.autouploadvideos.WebviewUtils
import com.shsening.autouploadvideos.action.PlatformActionInterface
import com.shsening.autouploadvideos.utils.Utils
@@ -35,6 +33,14 @@
    private fun updatePostDescription(){
        WebviewUtils.addValueToInput(webView,"#publish-container > div > div.body > div.content > div.input.titleInput > div.d-input-wrapper.d-inline-block.c-input_inner > div > input",videoInfo.title)
        WebviewUtils.addValueToDiv(webView,"#quillEditor > div > p",videoInfo.description)
        WebviewUtils.simpleElementClick(webView,"#topicBtn")
        SystemClock.sleep(500)
        WebviewUtils.simpleElementClick(webView,"#quill-mention-item-0")
        WebviewUtils.simpleElementClick(webView,"#topicBtn")
        SystemClock.sleep(500)
        WebviewUtils.simpleElementClick(webView,"#quill-mention-item-1")
//        WebviewUtils.simpleElementClick(webView,"#el-id-3410-26 > label:nth-child(1)")
        WebviewUtils.simpleElementClick(webView,"html > body > div:nth-of-type(1) > div > div:nth-of-type(2) > div > div:nth-of-type(2) > main > div:nth-of-type(3) > div > div > div:nth-of-type(1) > div > div > div > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(10) > div > div:nth-of-type(5) > div:nth-of-type(2) > label:nth-of-type(2)")
        addValueToDatePickerInput(true,"html > body > div:nth-of-type(1) > div > div:nth-of-type(2) > div > div:nth-of-type(2) > main > div:nth-of-type(3) > div > div > div:nth-of-type(1) > div > div > div > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(10) > div > div:nth-of-type(5) > div:nth-of-type(2) > div > div:nth-of-type(1) > div",videoInfo.datetime)
        // 在主线程中设置延迟执行
@@ -69,12 +75,9 @@
            webView.evaluateJavascript(jsCode_CheckVideoUploadFinished) { result ->
                if (result == "true") {
                    // 等待视频检测和生成封面
//                    WebviewUtils.simpleElementClick(webView,"#web > div > div > div > div.upload-content > div.upload-wrapper > div > input")
                    println("33333333333333333333333333333333333333")
                    threadHandler.postDelayed({updatePostDescription()},3000)
                } else {
                    println("11111111111111111111111")
                    // 元素不存在,1秒后再次检查
                    webView.postDelayed({
                        checkVideoUploadFinished()
@@ -83,6 +86,7 @@
            }
        }, 1000) // 每秒检查一次
    }
    private fun checkVideoPublishFinished(){
        webView.postDelayed({
            webView.evaluateJavascript(jsCode_PublishVideo_Finished) { result ->
@@ -148,9 +152,11 @@
        val displayMetrics = activity.resources.displayMetrics
        val width = displayMetrics.widthPixels
        val height = displayMetrics.heightPixels
        val startX = width.toFloat() * 0.9f // 从右侧滑动
        val endX = width.toFloat() * 0.1f // 滑动到左侧
        val y = height / 3f // Y 坐标在屏幕中间
        Thread {
            Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
            SystemClock.sleep(500)
@@ -158,7 +164,6 @@
            SystemClock.sleep(500)
            Utils.instrumentationClick(instrumentation, width / 2f, height * 2 / 4f)
            // back to main thread
            threadHandler.post {
                checkVideoUploadFinished()
            }