parent
b1d4fb39f2
commit
37b287d341
@ -0,0 +1,44 @@ |
||||
package io.legado.app.help |
||||
|
||||
import io.legado.app.help.http.newCallStrResponse |
||||
import io.legado.app.help.http.okHttpClient |
||||
import io.legado.app.help.http.postMultipart |
||||
import io.legado.app.model.analyzeRule.AnalyzeRule |
||||
import io.legado.app.model.analyzeRule.RuleData |
||||
|
||||
object DirectLinkUpload { |
||||
|
||||
private const val uploadUrlKey = "directLinkUploadUrl" |
||||
private const val downloadUrlRuleKey = "directLinkDownloadUrlRule" |
||||
|
||||
suspend fun upLoad(fileName: String, byteArray: ByteArray): String { |
||||
val res = okHttpClient.newCallStrResponse { |
||||
url("https://shuyuan.miaogongzi.site/index.html") |
||||
postMultipart(mapOf("file" to Triple(fileName, byteArray, null))) |
||||
} |
||||
val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url) |
||||
return analyzeRule.getString("tag.b@text") |
||||
} |
||||
|
||||
fun getUploadUrl(): String? { |
||||
return CacheManager.get(uploadUrlKey) |
||||
} |
||||
|
||||
fun putUploadUrl(url: String) { |
||||
CacheManager.put(uploadUrlKey, url) |
||||
} |
||||
|
||||
fun getDownloadUrlRule(): String? { |
||||
return CacheManager.get(uploadUrlKey) |
||||
} |
||||
|
||||
fun putDownloadUrlRule(rule: String) { |
||||
CacheManager.put(downloadUrlRuleKey, rule) |
||||
} |
||||
|
||||
fun delete() { |
||||
CacheManager.delete(uploadUrlKey) |
||||
CacheManager.delete(downloadUrlRuleKey) |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@ |
||||
package io.legado.app.ui.config |
||||
|
||||
import android.os.Bundle |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseDialogFragment |
||||
import io.legado.app.databinding.DialogDirectLinkUploadConfigBinding |
||||
import io.legado.app.help.DirectLinkUpload |
||||
import io.legado.app.utils.toastOnUi |
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding |
||||
import io.legado.app.utils.windowSize |
||||
import splitties.views.onClick |
||||
|
||||
class DirectLinkUploadConfig : BaseDialogFragment() { |
||||
|
||||
private val binding by viewBinding(DialogDirectLinkUploadConfigBinding::bind) |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
val dm = requireActivity().windowSize |
||||
dialog?.window?.setLayout( |
||||
(dm.widthPixels * 0.9).toInt(), |
||||
ViewGroup.LayoutParams.WRAP_CONTENT |
||||
) |
||||
} |
||||
|
||||
override fun onCreateView( |
||||
inflater: LayoutInflater, |
||||
container: ViewGroup?, |
||||
savedInstanceState: Bundle? |
||||
): View? { |
||||
return inflater.inflate(R.layout.dialog_direct_link_upload_config, container) |
||||
} |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||
binding.editUploadUrl.setText(DirectLinkUpload.getUploadUrl()) |
||||
binding.editDownloadUrlRule.setText(DirectLinkUpload.getDownloadUrlRule()) |
||||
binding.tvCancel.onClick { |
||||
dismiss() |
||||
} |
||||
binding.tvFooterLeft.onClick { |
||||
DirectLinkUpload.delete() |
||||
} |
||||
binding.tvOk.onClick { |
||||
val uploadUrl = binding.editUploadUrl.text?.toString() |
||||
val downloadUrlRule = binding.editDownloadUrlRule.text?.toString() |
||||
uploadUrl ?: let { |
||||
toastOnUi("上传Url不能为空") |
||||
return@onClick |
||||
} |
||||
downloadUrlRule ?: let { |
||||
toastOnUi("下载Url规则不能为空") |
||||
return@onClick |
||||
} |
||||
DirectLinkUpload.putUploadUrl(uploadUrl) |
||||
DirectLinkUpload.putDownloadUrlRule(downloadUrlRule) |
||||
dismiss() |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,101 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:orientation="vertical"> |
||||
|
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/tool_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:theme="?attr/actionBarStyle" |
||||
app:title="直链上传配置" |
||||
app:popupTheme="@style/AppTheme.PopupOverlay" |
||||
app:titleTextAppearance="@style/ToolbarTitle" /> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingTop="3dp"> |
||||
|
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_upload_url" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:hint="@string/upload_url" |
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" /> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingTop="3dp"> |
||||
|
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_download_url_rule" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:hint="@string/download_url_rule" |
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" /> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</androidx.core.widget.NestedScrollView> |
||||
|
||||
<com.google.android.flexbox.FlexboxLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="12dp" |
||||
android:paddingRight="12dp" |
||||
app:flexWrap="wrap" |
||||
app:justifyContent="space_between"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_footer_left" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/delete" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_cancel" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/cancel" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_ok" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/ok" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</com.google.android.flexbox.FlexboxLayout> |
||||
</LinearLayout> |
Loading…
Reference in new issue