| File was renamed from app/src/main/java/com/shsening/autouploadvideos/ActionShipinhao.kt |
| | |
| | | package com.shsening.autouploadvideos |
| | | package com.shsening.autouploadvideos.action |
| | | |
| | | |
| | | import android.app.Instrumentation |
| | | import android.content.Context |
| | | import android.os.SystemClock |
| | | import android.os.Handler |
| | | import com.shsening.autouploadvideos.UploadFragment |
| | | import com.shsening.autouploadvideos.UploadSessionActivity |
| | | import com.shsening.autouploadvideos.utils.Utils |
| | | import com.shsening.autouploadvideos.WebviewUtils |
| | | |
| | | class ActionShipinhao (private var fragment:UploadFragment, private var context:Context, private var threadHandler: Handler, private var videoInfo:Utils.VideoUploadTaskInfo){ |
| | | class ActionShipinhao (private var activity: UploadSessionActivity, private var threadHandler: Handler, private var videoInfo: Utils.VideoUploadTaskInfo) :PlatformActionInterface{ |
| | | |
| | | |
| | | private var webView = fragment.webView |
| | | private var webView = activity.sessionProfileWebView |
| | | |
| | | |
| | | var jsCode_CheckContentLoaded = """ |
| | |
| | | * Title,description(including # and @ ) publish datetime etc |
| | | */ |
| | | private fun updatePostDescription(){ |
| | | WebviewUtils.addValueToDiv(webView,"#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.form > div:nth-child(2) > div.form-item-body > div > div.input-editor",videoInfo.description) |
| | | WebviewUtils.addValueToDiv( |
| | | webView, |
| | | "#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.form > div:nth-child(2) > div.form-item-body > div > div.input-editor", |
| | | videoInfo.description |
| | | ) |
| | | |
| | | |
| | | // publish later radiobox |
| | | WebviewUtils.simpleElementClick(webView,"#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.form > div.post-time-wrap > div:nth-child(1) > div.form-item-body > div > label:nth-child(2)") |
| | | WebviewUtils.simpleElementClick( |
| | | webView, |
| | | "#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.form > div.post-time-wrap > div:nth-child(1) > div.form-item-body > div > label:nth-child(2)" |
| | | ) |
| | | |
| | | addValueToDatePickerInput(true,"#container-wrap > div.container-center > div > div > div.main-body-wrap.post-create > div.main-body > div > div.post-edit-wrap.material-edit-wrap > div.form > div.post-time-wrap > div:nth-child(2) > div.form-item-body > dl > dd",videoInfo.datetime) |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | fun checkIfContentLoaded() { |
| | | override fun checkIfContentLoaded() { |
| | | webView.postDelayed({ |
| | | webView.evaluateJavascript(jsCode_CheckContentLoaded) { result -> |
| | | if (result == "true") { |
| | |
| | | } |
| | | |
| | | private fun startToPublishVideo(){ |
| | | WebviewUtils.simpleElementClick(webView,jsPath_PublishVideo) |
| | | WebviewUtils.simpleElementClick(webView, jsPath_PublishVideo) |
| | | checkVideoPublishFinished() |
| | | } |
| | | private fun checkVideoUploadFinished(){ |
| | |
| | | webView.evaluateJavascript(jsCode_PublishVideo_Finished) { result -> |
| | | if (result == "true") { |
| | | // video published successfully!!! |
| | | fragment.startUploadSingleTask() |
| | | activity.checkAndStartNextTask() |
| | | } else { |
| | | // 元素不存在,1秒后再次检查 |
| | | webView.postDelayed({ |
| | |
| | | |
| | | var dpPanelText = datetimes[0].toString()+"年 "+datetimes[1].toString()+"月"; |
| | | |
| | | var dateRowColum = Utils.getDatePosition(datetimes[0],datetimes[1],datetimes[2])?:return; |
| | | var dateRowColum = Utils.getDatePosition(datetimes[0], datetimes[1], datetimes[2]) ?:return; |
| | | |
| | | val jsCode = """ |
| | | try { |
| | |
| | | |
| | | private fun simulateSwipeAndUploadVideo() { |
| | | val instrumentation = Instrumentation() |
| | | val displayMetrics = context.resources.displayMetrics |
| | | val displayMetrics = activity.resources.displayMetrics |
| | | val width = displayMetrics.widthPixels |
| | | val height = displayMetrics.heightPixels |
| | | |
| | |
| | | Thread { |
| | | Utils.instrumentationSwipe(instrumentation, startX, y, endX, y) |
| | | SystemClock.sleep(500) |
| | | Utils.instrumentationClick(instrumentation, width *4/5f, height / 2f) |
| | | Utils.instrumentationClick(instrumentation, width * 4 / 5f, height / 2f) |
| | | // back to main thread |
| | | threadHandler.post { |
| | | checkVideoUploadFinished() |