From bd54352f44f33caef57a8dbb541e5e84a372dcbb Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期六, 30 十一月 2024 15:48:02 +0800
Subject: [PATCH] app 升级功能
---
app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt | 75 ++++++++++++++-----------------------
app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt | 24 +++++++----
app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt | 4 +-
3 files changed, 45 insertions(+), 58 deletions(-)
diff --git a/app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt b/app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt
index c69cdb4..326399b 100644
--- a/app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt
+++ b/app/src/main/java/com/shsening/autouploadvideos/AppConfig.kt
@@ -8,7 +8,7 @@
)
class AppConfig {
companion object {
- const val APP_VERSION_NAME = "1.1.0"
+ const val APP_VERSION_NAME = "1.1.2"
const val MSG_MY_TAB_COPY_TO_CLIPBOARD = "鏂囨湰宸插鍒跺埌鍓垏鏉�"
const val MSG_MY_TAB_ADD_WECHAT = "璇︾粏鍐呭璇锋坊鍔犲井淇″挩璇�"
@@ -57,7 +57,7 @@
PlatformItem(5,"YouTube", false,"https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page"),
PlatformItem(6,"TikTok", false,"https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page")
)
- val SESSION_PROFILE_TYPE: Map<Int, String> = mapOf(0 to "缇庡コ璺宠垶", 1 to "缇庡コ绌挎惌",2 to "AI缇庢櫙", 3 to "鎼炵瑧鍔ㄧ墿")
+ val SESSION_PROFILE_TYPE: Map<Int, String> = mapOf(0 to "缇庡コ璺宠垶", 1 to "缇庡コ绌挎惌",2 to "AI缇庢櫙", 3 to "鎼炵瑧鍔ㄧ墿", 4 to "AI榛戜笣", 5 to "瀹犵墿", 6 to "鏃楄", 7 to "浜屾鍏�", 8 to "浜氭床鎬ф劅缇庡コ")
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt b/app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt
index 9e029b1..f50cd9a 100644
--- a/app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt
+++ b/app/src/main/java/com/shsening/autouploadvideos/action/ActionDouyin.kt
@@ -4,6 +4,7 @@
import android.app.Instrumentation
import android.os.SystemClock
import android.os.Handler
+import android.util.Log
import com.shsening.autouploadvideos.UploadSessionActivity
import com.shsening.autouploadvideos.utils.Utils
import com.shsening.autouploadvideos.WebviewUtils
@@ -12,6 +13,7 @@
private var webView = activity.sessionProfileWebView
+ private var TAG = "ActionDouyin"
var jsCode_CheckContentLoaded = """
@@ -27,39 +29,16 @@
private fun updatePostDescription(){
- WebviewUtils.addValueToInput(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div:nth-child(1) > div > div > input",
- videoInfo.title
- )
+ WebviewUtils.addValueToInput(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div:nth-child(1) > div > div > input",videoInfo.title)
- WebviewUtils.addValueToDiv(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div.outerdocbody.editor-kit-outer-container > div",
- videoInfo.description
- )
+ WebviewUtils.addValueToDiv(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div.editor-container-zRPSAi > div > div > div > div.outerdocbody.editor-kit-outer-container > div",videoInfo.description)
- WebviewUtils.simpleElementClick(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(1)"
- )
- WebviewUtils.simpleElementClick(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(2)"
- )
+ WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(1)")
+ WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-mention-wrapper-LWv5ed > div:nth-child(3) > div > div.activity-list-container-AZzfdV > div:nth-child(2)")
- WebviewUtils.simpleElementClick(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.content-upload-new > div > div.recommendContainer-HXvL9W > div.recommendDisplay-ifUYki > div > div:nth-child(1) > div"
- )
- WebviewUtils.simpleElementClick(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.download-content-Lci5tL > div > label:nth-child(2)"
- )
- WebviewUtils.simpleElementClick(
- webView,
- "#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > label:nth-child(2)"
- )
+ WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.content-upload-new > div > div.recommendContainer-HXvL9W > div.recommendDisplay-ifUYki > div > div:nth-child(1) > div")
+ WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.download-content-Lci5tL > div > label:nth-child(2)")
+ WebviewUtils.simpleElementClick(webView,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > label:nth-child(2)")
addValueToDatePickerInput(true,"#root > div > div > div.content-body-v8tuJQ > div.form-kSES6A > div.publish-settings-WtW_ZW > div.schedule-part-V615Zn > div.row-suTOx_ > div.date-picker-ioPchj > div > div",videoInfo.datetime)
@@ -85,7 +64,7 @@
}
private fun startToPublishVideo(){
- WebviewUtils.simpleElementClick(webView, jsPath_PublishVideo)
+ WebviewUtils.simpleElementClick(webView,jsPath_PublishVideo)
checkVideoPublishFinished()
}
@@ -111,11 +90,8 @@
webView.postDelayed({
webView.evaluateJavascript(jsCode_PublishVideo_Finished) { result ->
if (result == "true") {
-
// video published successfully!!!
activity.checkAndStartNextTask()
-
-
} else {
// 鍏冪礌涓嶅瓨鍦紝1绉掑悗鍐嶆妫�鏌�
webView.postDelayed({
@@ -133,7 +109,7 @@
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 {
@@ -144,17 +120,17 @@
// need time to popup date-picker
setTimeout(() => {
var dpPanel = document.querySelector('.semi-popover-content');
- var dpPanelSpan = dpPanel.querySelector('div > div > div > div:nth-child(1) > div.semi-datepicker-navigation > div > button > span > span');
+ var dpPanelSpan = document.querySelectorAll(".semi-datepicker")[1].querySelector(".semi-datepicker-navigation-month");
if (dpPanelSpan && dpPanelSpan.textContent != '${dpPanelText}'){
- dpPanel.querySelector('div > div > div > div > div:nth-child(1) > div.semi-datepicker-navigation > button:nth-child(3)').click();
+ document.querySelectorAll(".semi-datepicker")[1].querySelectorAll(".semi-button-content")[2].click();
}
- dpPanel.querySelector('div > div > div > div > div:nth-child(1) > div.semi-datepicker-month > div.semi-datepicker-weeks > div:nth-child(${dateRowColum[0]}) > div:nth-child(${dateRowColum[1]})').click()
+ document.querySelectorAll(".semi-datepicker-month")[0].querySelectorAll(".semi-datepicker-weeks")[0].querySelector("div:nth-child(${dateRowColum[0]}) > div:nth-child(${dateRowColum[1]})").click();
//switch to time selection
- dpPanel.querySelector('div > div > div > div > div.semi-datepicker-switch > div.semi-datepicker-switch-time').click();
+ document.querySelectorAll(".semi-datepicker-switch-time")[0].click()
setTimeout(() => {
- dpPanel.querySelector('div > div > div > div.semi-datepicker-tpk > div > div > div.semi-scrolllist-body > div.semi-scrolllist-item-wheel.undefined-list-hour > div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[3]+1)})').click();
- dpPanel.querySelector('div > div > div > div.semi-datepicker-tpk > div > div > div.semi-scrolllist-body > div.semi-scrolllist-item-wheel.undefined-list-minute > div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[4]+1)})').click();
+ document.querySelectorAll('.semi-scrolllist-body')[0].querySelectorAll('.semi-scrolllist-item-wheel')[0].querySelector('div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[3]+1)})').click();
+ document.querySelectorAll('.semi-scrolllist-body')[0].querySelectorAll('.semi-scrolllist-item-wheel')[1].querySelector('div.semi-scrolllist-list-outer > ul > li:nth-child(${(datetimes[4]+1)})').click();
}, 500);
}, 500);
} catch (error) {
@@ -178,12 +154,17 @@
val y = height / 3f // Y 鍧愭爣鍦ㄥ睆骞曚腑闂�
Thread {
- Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
- SystemClock.sleep(500)
- Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
- SystemClock.sleep(500)
- Utils.instrumentationClick(instrumentation, width / 2f, height * 2 / 4f)
- // back to main thread
+ try {
+ Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
+ SystemClock.sleep(500)
+ Utils.instrumentationSwipe(instrumentation, startX, y, endX, y)
+ SystemClock.sleep(500)
+ Utils.instrumentationClick(instrumentation, width / 2f, height * 2 / 3f)
+ // back to main thread
+
+ } catch (e: Exception) {
+ Log.e(TAG, "婊戝姩鎿嶄綔澶辫触锛氬簲鐢ㄥ彲鑳藉湪鍚庡彴", e)
+ }
threadHandler.post {
checkVideoUploadFinished()
}
diff --git a/app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt b/app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt
index ed18a16..33f6b72 100644
--- a/app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt
+++ b/app/src/main/java/com/shsening/autouploadvideos/utils/Utils.kt
@@ -278,7 +278,7 @@
suspend fun downloadCommonFileToExternalFilesDir(context: Context, url: String, filename: String, install: Boolean) {
val tmpFile = File(context.getExternalFilesDir(null), filename)
- try{
+ try {
if (tmpFile.exists()) {
return
}
@@ -292,17 +292,20 @@
override fun onFailure(call: Call, e: IOException) {
deferred.completeExceptionally(e) // 涓嬭浇澶辫触鏃舵爣璁颁负寮傚父
}
+
override fun onResponse(call: Call, response: Response) {
response.use {
if (!response.isSuccessful) {
deferred.completeExceptionally(IOException("Unexpected code $response")) // 濡傛灉鍝嶅簲涓嶆垚鍔燂紝鏍囪涓哄紓甯�
return
}
+
tmpFile.outputStream().use { outputStream ->
outputStream.write(response.body?.bytes())
}
+
if (install) {
- installApk(context,tmpFile)
+ installApk(context, tmpFile)
}
deferred.complete(Unit) // 涓嬭浇鎴愬姛鏃惰繑鍥炴枃浠�
@@ -311,19 +314,22 @@
})
}
- // 绛夊緟涓嬭浇瀹屾垚
-
- Toast.makeText(context, filename + " " + AppConfig.MSG_DOWNLOAD_FINISHED, Toast.LENGTH_SHORT).show()
+ // Switch to main thread for Toast
+ withContext(Dispatchers.Main) {
+ Toast.makeText(context, "$filename ${AppConfig.MSG_DOWNLOAD_FINISHED}", Toast.LENGTH_SHORT).show()
+ }
deferred.await()
- }catch(e:Exception){
+ } catch (e: Exception) {
e.printStackTrace()
- Toast.makeText(context, filename+" download fails, Please try again later!", Toast.LENGTH_SHORT)
- .show()
-
+ // Switch to main thread for Toast
+ withContext(Dispatchers.Main) {
+ Toast.makeText(context, "$filename download fails, Please try again later!", Toast.LENGTH_SHORT).show()
+ }
}
}
+
fun installApk(context: Context,apkFile: File) {
val intent = Intent(Intent.ACTION_VIEW)
val apkUri = FileProvider.getUriForFile(context, AppConfig.FILE_PROVIDER, apkFile)
--
Gitblit v1.9.1