From 1ca2b360d70e5e5717c451dbdb408cf23ee2f38b Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Fri, 6 Sep 2024 01:04:53 +0900 Subject: [PATCH] . --- app/build.gradle.kts | 1 + app/src/main/AndroidManifest.xml | 5 +- .../rasel/lunar/launcher/LauncherActivity.kt | 45 ++++----- .../rasel/lunar/launcher/feeds/Feeds.kt | 92 ++++++++++++------- .../rasel/lunar/launcher/home/LauncherHome.kt | 7 +- .../main/res/xml/network_security_config.xml | 6 ++ 6 files changed, 97 insertions(+), 59 deletions(-) create mode 100644 app/src/main/res/xml/network_security_config.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f0a37a2..18631b4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -89,4 +89,5 @@ dependencies { implementation ("io.realm.kotlin:library-base:2.1.0") implementation ("org.jsoup:jsoup:1.18.1") implementation ("org.apache.commons:commons-text:1.12.0") + implementation("com.squareup.okhttp:okhttp:2.7.5") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aca53c5..2599db1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,11 +52,14 @@ android:stateNotNeeded="true" android:enableOnBackInvokedCallback="true" android:largeHeap="true" + android:debuggable="false" + android:networkSecurityConfig="@xml/network_security_config" android:hardwareAccelerated="true" android:usesCleartextTraffic="true" android:screenOrientation="nosensor" android:windowSoftInputMode="adjustResize" - android:requestLegacyExternalStorage="true"> + android:requestLegacyExternalStorage="true" + > Unit)? = null var isF = false fun doWebParseStart(url : String, callBack : (()->Unit)?) { - isF = true + isF = false this.callBack = callBack binding.searcher01.post { binding.searcher01.visibility = View.VISIBLE } BLog.LOGE("binding.otherCheck before ThreadRun") binding.searcher01.webViewClient = object : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { - if (!isF && url?.contains("missav") == true) { + if (url?.contains("missav") == true && isF) { + BLog.LOGE("binding.otherCheck before reload") view?.loadUrl(url!!) isF = true + return false } return false } @@ -544,35 +545,35 @@ internal class LauncherActivity : AppCompatActivity() { BLog.LOGE("binding.otherCheck searcher01 in onPageFinished ${url}") //lastedFinishedPageUrl?.length ?: 0 > 10 && // if(url?.startsWith("https://") == true) { - if (url?.contains("youtube", false) == true) { - view?.evaluateJavascript( - "function getAll() {\n" + - " MyJavaScriptInterface.sendValueFromHtml(document.getElementsByTagName('html')[0].innerHTML)" + - " };getAll()" - ) { result -> - (result as? String)?.let { + if (url?.contains("youtube", false) == true) { + view?.evaluateJavascript( + "function getAll() {\n" + + " MyJavaScriptInterface.sendValueFromHtml(document.getElementsByTagName('html')[0].innerHTML)" + + " };getAll()" + ) { result -> + (result as? String)?.let { - } } - } else { - //if (url?.contains("guru", true) == true) - view?.evaluateJavascript( - "function getAll() {\n" + - " MyJavaScriptInterface.sendValueFromHtml(document.getElementsByTagName('html')[0].innerHTML)" + - " };getAll()" - ) { result -> - (result as? String)?.let { + } + } else { + //if (url?.contains("guru", true) == true) + view?.evaluateJavascript( + "function getAll() {\n" + + " MyJavaScriptInterface.sendValueFromHtml(document.getElementsByTagName('html')[0].innerHTML)" + + " };getAll()" + ) { result -> + (result as? String)?.let { - } } + } // if (!isF) { // binding.searcher01.post { // binding.searcher01.loadUrl("https://missav.com/dm11/ko") // isF = true // } // } - } -// callBack?.invoke() + } + if (isF) this@LauncherActivity.callBack?.invoke() // binding.searcher01.post { binding.searcher01.visibility = View.GONE } // } } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt index 1ead8fa..80b79fa 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt @@ -37,7 +37,13 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.google.android.material.button.MaterialButtonToggleGroup +import com.squareup.okhttp.ConnectionPool +import com.squareup.okhttp.OkHttpClient +import com.squareup.okhttp.Request +import com.squareup.okhttp.Response +import com.squareup.okhttp.ResponseBody import io.realm.kotlin.ext.query +import io.realm.kotlin.query.Sort import kotlinx.coroutines.* import org.jsoup.Jsoup import rasel.lunar.launcher.LauncherActivity.Companion.appWidgetHost @@ -57,18 +63,19 @@ import rasel.lunar.launcher.helpers.Constants.Companion.SEPARATOR import rasel.lunar.launcher.helpers.Constants.Companion.requestCreateWidget import rasel.lunar.launcher.helpers.Constants.Companion.requestPickWidget import rasel.lunar.launcher.home.LauncherHome.Companion.home -import rasel.lunar.launcher.home.LauncherHome.Companion.listItem import rasel.lunar.launcher.home.LauncherHome.Companion.listTags -import rasel.lunar.launcher.model.RssTagItem import rasel.lunar.launcher.model.RssData import rasel.lunar.launcher.model.RssDataInterface import rasel.lunar.launcher.model.RssDataType +import rasel.lunar.launcher.model.RssTagItem import rasel.lunar.launcher.utils.BLog import rasel.lunar.launcher.utils.RssList.jGuruMain import rasel.lunar.launcher.workers.WorkersDb import java.net.URLEncoder import java.nio.charset.Charset import java.util.* +import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit internal class Feeds : Fragment() { @@ -150,6 +157,8 @@ internal class Feeds : Fragment() { mapIntent.setPackage("com.opera.browser") lActivity?.startActivity(mapIntent) } + + val USAGT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15" /* start rss service if network is active and rss url is not empty */ private fun startService() { binding.feedsRss.rss.visibility = View.GONE @@ -168,7 +177,8 @@ internal class Feeds : Fragment() { if (input.text.toString().trim().contains(" ")) { val cmd = input.text.toString().trim().split(" ") when(cmd[0]) { - "miss"-> lActivity?.doWebParseStart("https://missav.com/ko/search/${input.text.toString().trim().split(" ")[1]}/") {} + //lActivity?.doWebParseStart("https://missav.com/dm16/en") {} + "miss"-> lActivity?.doWebParseStart("https://missav.com/en/search/${input.text.toString().trim().split(" ")[1]}/") {} "mgn"-> { // lActivity?.doWebParseStart("https://cili.site/search?q=${URLEncoder.encode(cmd[1], Charset.defaultCharset().name())}") {} GlobalScope.launch { @@ -212,34 +222,12 @@ internal class Feeds : Fragment() { binding.feedsRss.apply { rss.adapter = mRssAdapter loading.visibility = View.VISIBLE - if (listItem.size > 0) { - listItem.sortByDescending { it.pubDate() } - WorkersDb.getRealm() - .query("category == '$0'", RssDataType.GURU.name) - .find()?.apply { - mRssAdapter?.updateData(listItem) - } - - rss.visibility = View.VISIBLE - loading.visibility = View.GONE - refresh.visibility = View.GONE - } else { - refresh.visibility = View.VISIBLE - rss.visibility = View.GONE - refresh.setOnClickListener { - var call = { - if (listItem.size > 0) { - rss?.postDelayed({ - listItem.sortByDescending { it.pubDate() } - mRssAdapter?.updateData(listItem) - loading.visibility = View.GONE - refresh.visibility = View.GONE - rss.visibility = View.VISIBLE - }, 500L) - } - } - } - } + mRssAdapter?.updateData(WorkersDb.getRealm() + .query("category == $0", RssDataType.GURU.name) + .sort("pubDate", Sort.DESCENDING).find()) + rss.visibility = View.VISIBLE + loading.visibility = View.GONE + refresh.visibility = View.GONE } } @@ -247,10 +235,48 @@ internal class Feeds : Fragment() { lActivity?.doWebParseStart("https://projectjav.com") {} } "jmnew" -> { - lActivity?.doWebParseStart("https://missav.com/dm511/ko/new") {} + Executors.newSingleThreadScheduledExecutor().schedule({ + try { + val url = "https://missav.com/" + + + // OkHttp 클라이언트 객체 생성 + val client: OkHttpClient = OkHttpClient() + client.connectionPool = ConnectionPool(10, 300, TimeUnit.SECONDS) + client.setFollowSslRedirects(true) + + // GET 요청 객체 생성 + val builder: Request.Builder = Request.Builder().url(url).get() +// builder.addHeader("password", "BlahBlah") + val request: Request = builder.build() + + + // OkHttp 클라이언트로 GET 요청 객체 전송 + val response: Response = client.newCall(request).execute() + if (response.isSuccessful()) { + // 응답 받아서 처리 + val body: ResponseBody = response.body() + if (body != null) { + System.out.println("Response:" + body.string()) + } + } else System.err.println("Error Occurred") + + } catch (e: java.lang.Exception) { + e.printStackTrace() + } +// try { +// Jsoup.connect("https://missav.com/").userAgent(USAGT).timeout(300000).get().apply { +// BLog.LOGE("https://missav.com/dm507/en/release >>>> ${this}") +// } +// }catch (e : Exception) { +// e.printStackTrace() +// +// } + }, 2, TimeUnit.SECONDS) +// lActivity?.doWebParseStart("https://missav.com/dm507/en/release") {} } "jmiss" -> { - lActivity?.doWebParseStart("https://missav.com/dm11/ko") {} + lActivity?.doWebParseStart("https://missav.com/dm16/en") {} } "jreq" -> { lActivity?.doWebParseStart(jGuruMain) {} diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt index 2355191..d1afb6c 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -84,6 +84,7 @@ import rasel.lunar.launcher.qaccess.QuickAccess import rasel.lunar.launcher.settings.SettingsActivity import rasel.lunar.launcher.todos.MissedCallsAdapter import rasel.lunar.launcher.model.RssDataInterface +import rasel.lunar.launcher.model.RssDataType import rasel.lunar.launcher.todos.NotificationItemAdapter import rasel.lunar.launcher.todos.RssItemAdapter import rasel.lunar.launcher.todos.SmsLogsAdapter @@ -118,7 +119,6 @@ internal class LauncherHome : Fragment() { var callList = arrayListOf() var smsList = arrayListOf() var listTags = arrayListOf() - var listItem = arrayListOf() } private var nReceiver: NotificationReceiver? = null @@ -232,8 +232,9 @@ internal class LauncherHome : Fragment() { registerReceiver(requireContext(),nReceiver, filter,RECEIVER_EXPORTED) BLog.LOGE("onCreateView()") - mRssDataResult = WorkersDb.getRealm().query().query("pubDate > $0",beforeDay(Date(),3)).sort("pubDate ", Sort.DESCENDING).find() - mNotificationResult = WorkersDb.getRealm().query().find() + + mRssDataResult = WorkersDb.getRealm().query().query("pubDate > $0",beforeDay(Date(),3)).query("category != $0", RssDataType.GURU.name).sort("pubDate ", Sort.DESCENDING).find() + mNotificationResult = WorkersDb.getRealm().query().sort("postTime",Sort.DESCENDING).find() job = CoroutineScope(Dispatchers.Default).launch { mRssDataResult.asFlow().collect { changes: ResultsChange -> when (changes) { diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..f871846 --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file