Skip to content

Commit

Permalink
folder,webview
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Jan 1, 2020
1 parent d5c0347 commit 18ddfe5
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class ProgressActivityFragment : Fragment() {
val title1 = data[position].progress.getString("title")
val url = data[position].progress.getString("url")
val fileName = data[position].progress.getString("file")
val needCreateFold = data[position].progress.getBoolean("needcreatefold",false)
val userName = data[position].progress.getString("username")
holder.apply {
itemView.setOnClickListener {
val bundle = Bundle()
Expand All @@ -149,11 +151,14 @@ class ProgressActivityFragment : Fragment() {
WorkManager.getInstance(mContext).cancelWorkById(workinfo.id)
}
else -> {

val inputData = workDataOf(
"file" to fileName,
"url" to url,
"title" to title1,
"id" to id
"id" to id,
"username" to userName,
"needcreatefold" to needCreateFold
)
val oneTimeWorkRequest =
OneTimeWorkRequestBuilder<ImgDownLoadWorker>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class SpotlightActivity : RinkActivity() {
val builder = OkHttpClient.Builder()
val okHttpClient = builder.build()
val request = Request.Builder()

.url(url)
.addHeader("Accept-Language", local.language)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ package com.perol.asdpl.pixivez.activity
import android.content.Intent
import android.os.Bundle
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.objects.ThemeUtil
import kotlinx.android.synthetic.main.activity_web_view.*
import java.io.ByteArrayInputStream


class WebViewActivity : RinkActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -42,6 +45,25 @@ class WebViewActivity : RinkActivity() {
webview.settings.blockNetworkImage = false
webview.settings.javaScriptEnabled = true
webview.webViewClient = object : WebViewClient() {
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest
): WebResourceResponse? {
if (request.url.host!!.equals("d.pixiv.org") || request.url.host!!.equals("connect.facebook.net") || request.url.host!!.equals(
"platform.twitter.com"
) || request.url.host!!.equals("www.google-analytics.com")
) {
val webResourceResponse =
WebResourceResponse(
"application/javascript",
"UTF-8",
ByteArrayInputStream("".toByteArray())
);
return webResourceResponse;
}
return super.shouldInterceptRequest(view, request)
}

override fun shouldOverrideUrlLoading(
view: WebView,
request: WebResourceRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SettingFragment : PreferenceFragmentCompat() {
return filesDir?.list(filter)
}

fun onClick(position: Int) {
private fun onClick(position: Int) {
Toast.makeText(PxEZApp.instance, "正在尝试更换,等待启动器刷新", Toast.LENGTH_SHORT).show()
when (position) {
0 -> {
Expand Down Expand Up @@ -290,6 +290,9 @@ class SettingFragment : PreferenceFragmentCompat() {
REQUEST_CODE_PERMISSIONS
)
}
}
"saveformat" -> {

}
"version" -> {
try {
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/perol/asdpl/pixivez/services/PxEZApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package com.perol.asdpl.pixivez.services
import android.app.Activity
import android.app.Application
import android.os.Build
import android.os.Bundle
import android.os.Environment
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -63,7 +62,7 @@ class PxEZApp : Application() {

WorkManager.getInstance(this).pruneWork()

registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
/* registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
Logger.t(TAG).v("${activity.simpleName}: onActivityCreated")
Expand Down Expand Up @@ -95,7 +94,7 @@ class PxEZApp : Application() {
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
//
}
})
})*/
}

private val Activity.simpleName get() = javaClass.simpleName
Expand Down
34 changes: 21 additions & 13 deletions app/src/main/java/com/perol/asdpl/pixivez/services/Works.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ import java.util.*

class Works {
companion object {
private fun String.toLegal(): String {
return this.replace("/", "").replace("\\", "").replace(":", "")
}

fun imageDownloadWithFile(illust: Illust, file: File, part: Int?) {
var url = ""
var title = illust.title
title = title.replace("/", "")
title = title.replace("\\", "")
title = title.replace(":", "")
val title = illust.title.toLegal()
val userName = illust.user.name.toLegal()
val user = illust.user.id
val name = illust.id
val format = PreferenceManager.getDefaultSharedPreferences(PxEZApp.instance).getString(
val pre = PreferenceManager.getDefaultSharedPreferences(PxEZApp.instance);
val format = pre.getString(
"saveformat",
"0"
)?.toInt()
?: 0
val needCreateFold = pre.getBoolean("needcreatefold", false)
var type = ".png"
var filename = "${name}_p$part$type"
if (part != null && illust.meta_pages.isNotEmpty()) {
Expand Down Expand Up @@ -102,8 +106,10 @@ class Works {
}
}
}

val targetFile = File(PxEZApp.storepath, filename)
val path = if (needCreateFold) {
"${PxEZApp.storepath}/$userName"
} else PxEZApp.storepath
val targetFile = File(path, filename)
try {
file.copyTo(targetFile, overwrite = true)
Toasty.success(
Expand Down Expand Up @@ -137,17 +143,17 @@ class Works {

fun imageDownloadOne(illust: Illust, part: Int?) {
var url = ""
var title = illust.title
title = title.replace("/", "")
title = title.replace("\\", "")
title = title.replace(":", "")
val title = illust.title.toLegal()
val userName = illust.user.name.toLegal()
val user = illust.user.id
val name = illust.id
val format = PreferenceManager.getDefaultSharedPreferences(PxEZApp.instance).getString(
val pre = PreferenceManager.getDefaultSharedPreferences(PxEZApp.instance);
val format = pre.getString(
"saveformat",
"0"
)?.toInt()
?: 0
val needCreateFold = pre.getBoolean("needcreatefold", false)
var type = ".png"
var filename = "${name}_p$part$type"
if (part != null && illust.meta_pages.isNotEmpty()) {
Expand Down Expand Up @@ -194,7 +200,9 @@ class Works {
"file" to filename,
"url" to url,
"title" to illust.title,
"id" to illust.id
"id" to illust.id,
"username" to userName,
"needcreatefold" to needCreateFold
)
val oneTimeWorkRequest = OneTimeWorkRequestBuilder<ImgDownLoadWorker>()
.setInputData(inputData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,29 @@ class ImgDownLoadWorker(var appContext: Context, workerParams: WorkerParameters)
val fileName = inputData.getString("file")!!
val title = inputData.getString("title")!!
val id = inputData.getLong("id", 0L)
val appDir = File(PxEZApp.storepath)
val userName =inputData.getString("username")
val needCreateFold= inputData.getBoolean("needcreatefold",false)
val path = if (needCreateFold) {
"${PxEZApp.storepath}/$userName"
} else PxEZApp.storepath
val appDir = File(path)

val lastUpdate = workDataOf(
"max" to 100,
"now" to 1,
"url" to url,
"file" to fileName,
"title" to title,
"id" to id
"id" to id,
"username" to userName,
"needcreatefold" to needCreateFold
)
setProgress(lastUpdate)
if (!appDir.exists()) {
appDir.mkdirs()
}
val file = File(appDir, fileName)

val file = File(path, fileName)
if (file.exists()) {
val outputData = workDataOf("exist" to true)
return Result.success(outputData)
Expand Down Expand Up @@ -98,7 +107,9 @@ class ImgDownLoadWorker(var appContext: Context, workerParams: WorkerParameters)
"url" to url,
"file" to fileName,
"title" to title,
"id" to id
"id" to id,
"username" to userName,
"needcreatefold" to needCreateFold
)
setProgress(lastUpdate1)
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_about_x.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"

android:layout_height="wrap_content">

<com.google.android.material.appbar.MaterialToolbar
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/dialog_saveformat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
<string name="new1">New</string>
<string name="saveselectpic1">Save?</string>
<string name="confirm">confirm</string>
<string name="cancel">cancel</string>
<string name="mutichoicesave">Multiple selection</string>
<string name="choice">Choice</string>
<string name="errorgif">动图文件似乎出现了损坏,请清除缓存后重试</string>
Expand Down Expand Up @@ -252,4 +251,6 @@
<string name="start_date">Start Date</string>
<string name="end_date">End Date</string>
<string name="choice_date">Choice Date</string>
<string name="create_painter_folder">Create a separate folder for each painter</string>
<string name="create_separate_folder">create separate folder</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
<string name="new1">動態</string>
<string name="saveselectpic1">儲存選定圖像?</string>
<string name="confirm">確定</string>
<string name="cancel">取消</string>
<string name="mutichoicesave">多選儲存</string>
<string name="choice">選擇</string>
<string name="logoutallaccount">Log out of all accounts</string>
Expand Down Expand Up @@ -267,4 +266,6 @@
<string name="start_date">Start Date</string>
<string name="end_date">End Date</string>
<string name="choice_date">Choice Date</string>
<string name="create_painter_folder">为每个画师单独创建文件夹</string>
<string name="create_separate_folder">create separate folder</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
<string name="new1">动态</string>
<string name="saveselectpic1">保存选定图片?</string>
<string name="confirm">确定</string>
<string name="cancel">取消</string>
<string name="mutichoicesave">多选保存</string>
<string name="choice">选择</string>
<string name="title_activity_work">WorkActivity</string>
Expand Down Expand Up @@ -291,4 +290,6 @@
<string name="action_apply">应用</string>
<string name="action_select">选择</string>
<string name="action_change">更换</string>
<string name="create_painter_folder">为每个画师单独创建文件夹</string>
<string name="create_separate_folder">创建单独文件夹</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/pref_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<Preference
app:key="storepath1"
app:title="@string/savepath" />
<SwitchPreference
app:key="needcreatefold"
app:defaultValue="false"
app:title="@string/create_separate_folder"
app:summary="@string/create_painter_folder"/>
<ListPreference
android:entries="@array/format"
android:entryValues="@array/format_value"
Expand Down

0 comments on commit 18ddfe5

Please sign in to comment.