From ab2d0af59480e2f035e32c6bfea8a3459885c45b Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 2 Dec 2024 10:48:45 +0900 Subject: [PATCH] .... --- .../lunatic/launcher/home/LauncherHome.kt | 2 +- .../lunatic/launcher/model/CommunityData.kt | 1 + .../lunatic/launcher/workers/WorkersDb.kt | 4 +- .../awesomewebview/AwesomeWebView.kt | 2 +- .../awesomewebview/AwesomeWebViewActivity.kt | 143 +++++++++++------- 5 files changed, 94 insertions(+), 58 deletions(-) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt index 4e6bb21..5d9946b 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt @@ -526,7 +526,7 @@ internal class LauncherHome : Fragment() { filter: Collection? = arrayListOf(RssDataType.GURU, RssDataType.MOST,RssDataType.REDDIT_NSFW), noLimit: Boolean = false ) { beforeQuery() - var rQ = WorkersDb.getRealm().query().query("read < $0", nomoreShowCount) + var rQ = WorkersDb.getRealm().query().query("read < $0", nomoreShowCount).distinct("originPage").distinct("title") if (!noLimit) rQ.query("pubDate > $0", beforeDay(Date(), 3)) ((filter?.size ?: 0) > 0).letTrue {filter!!.forEach {rQ = rQ.query("category != $0", it.name)}} updateQuery(rQ) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/model/CommunityData.kt b/app/src/main/kotlin/bums/lunatic/launcher/model/CommunityData.kt index 3a868ad..045f4f4 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/model/CommunityData.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/model/CommunityData.kt @@ -212,6 +212,7 @@ class RssData : RealmObject, RssDataInterface { @PrimaryKey var originPage : String? = null + var title : String? = null var description : String? = null var thumbnail : String? = null diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/WorkersDb.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/WorkersDb.kt index 2637819..0a0a089 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/WorkersDb.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/WorkersDb.kt @@ -195,7 +195,7 @@ object WorkersDb { } } - fun getVotedRss() = getRealm().query().query("vote == $0", true) + fun getVotedRss() = getRealm().query().query("vote == $0", true).distinct("originPage").distinct("title") fun getRssQuery(keyword: String?, category: Collection? = arrayListOf(), @@ -230,7 +230,7 @@ object WorkersDb { if (keyword?.length ?: 0 == 0 && category?.size ?: 0 == 0) { rQ = rQ.query("read < $0", 3).query("vote != $0", true) } - return rQ + return rQ.distinct("originPage").distinct("title") } } \ No newline at end of file diff --git a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt index 9f37bed..9613038 100644 --- a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt +++ b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt @@ -132,7 +132,7 @@ class AwesomeWebView { var webViewLoadWithOverviewMode: Boolean? = null var webViewSaveFormData: Boolean? = null var webViewTextZoom: Int? = null - var webViewUseWideViewPort: Boolean? = null + var webViewUseWideViewPort: Boolean = true var webViewSupportMultipleWindows: Boolean? = null var webViewLayoutAlgorithm: LayoutAlgorithm? = null var webViewStandardFontFamily: String? = null diff --git a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt index e9206bb..77b4d43 100644 --- a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt +++ b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt @@ -36,7 +36,6 @@ import android.webkit.CookieSyncManager import android.webkit.DownloadListener import android.webkit.GeolocationPermissions import android.webkit.PermissionRequest -import android.webkit.URLUtil import android.webkit.ValueCallback import android.webkit.WebChromeClient import android.webkit.WebResourceRequest @@ -46,10 +45,8 @@ import android.webkit.WebSettings.LayoutAlgorithm import android.webkit.WebView import android.webkit.WebView.HitTestResult import android.webkit.WebViewClient -import android.widget.FrameLayout import android.widget.ImageButton import android.widget.LinearLayout -import android.widget.ProgressBar import android.widget.RelativeLayout import android.widget.TextView import android.widget.Toast @@ -57,8 +54,6 @@ import androidx.annotation.DrawableRes import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.AppCompatImageButton -import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.ContextCompat import androidx.core.content.FileProvider @@ -92,7 +87,6 @@ import java.io.ByteArrayOutputStream import java.io.File import java.io.IOException import java.io.InputStream -import java.net.URL import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -1443,7 +1437,22 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener, webView!!.reload() hideMenu() } else if (viewId == R.id.menuPdf) { -// PDFPrint + LogUtil.e("onClick on menuPdf") + val fileName = host.plus(SimpleDateFormat("_yyyyMMddhhmmss").format(Date())).plus(".pdf") + val path = File(Environment.getExternalStorageDirectory(),"bums") + if (path.exists() == false) { + path.mkdirs() + } + val file = File(path, fileName) + PDFPrint.generatePDFFromWebView(file,webView,object :PDFPrint.OnPDFPrintListener { + override fun onSuccess(file: File?) { + LogUtil.e("file.absolutePath >>> ${file?.absolutePath ?: "fail"}") + } + + override fun onError(exception: java.lang.Exception?) { + exception?.printStackTrace() + } + }) hideMenu() } else if (viewId == R.id.menuFind) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) webView!!.showFindDialog( @@ -1865,7 +1874,7 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener, .contains("ads".toLowerCase(Locale.ROOT))) { LogUtil.e("shouldInterceptRequest request url contains ads >>> ${request.url.toString()}") } - var adblockKeyWords = arrayOf("adcr.naver.com","daumcdn.net/biz/ui/ad/adcm","imgad","ad.daum.net","cr.adsappier.com","ar-adview","adtrafficquality","criteo","adlib.nhnace.com","google.com/ads","googleads.","/pagead","/adpost/","ads/search") + var adblockKeyWords = arrayOf("adcr.naver.com","daumcdn.net/biz/ui/ad/adcm","imgad","ad.daum.net","cr.adsappier.com","ar-adview","adtrafficquality","criteo","adlib.nhnace.com","google.com/ads","googleads.","/pagead","/adpost/","ads/search","plugin.adplex") val adblock = adblockKeyWords.filter { url.toLowerCase(Locale.ROOT).contains(it.toLowerCase(Locale.ROOT)) }.size > 0 return if(adblock) { try { @@ -1877,14 +1886,18 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener, }else if(url.toLowerCase(Locale.ROOT).contains(".jpg") || url.toLowerCase(Locale.ROOT).contains(".jpeg")){ try { val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get() - WebResourceResponse("image/jpg", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.JPEG)) + WebResourceResponse("image/jpg", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.JPEG)).apply { + LogUtil.e("shouldInterceptRequest request url down from Glide >>> ${request.url.toString()}") + } } catch (e : Exception) { super.shouldInterceptRequest(view, url) } }else if(url.toLowerCase(Locale.ROOT).contains(".png")){ try { val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get() - WebResourceResponse("image/png", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.PNG)) + WebResourceResponse("image/png", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.PNG)).apply { + LogUtil.e("shouldInterceptRequest request url down from Glide >>> ${request.url.toString()}") + } } catch (e : Exception) { super.shouldInterceptRequest(view, url) } @@ -1892,7 +1905,9 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener, }else if(url.toLowerCase(Locale.ROOT).contains(".webp")){ try { val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get() - WebResourceResponse("image/webp", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.WEBP)) + WebResourceResponse("image/webp", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.WEBP)).apply { + LogUtil.e("shouldInterceptRequest request url down from Glide >>> ${request.url.toString()}") + } } catch (e : Exception) { super.shouldInterceptRequest(view, url) } @@ -1971,62 +1986,82 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener, var skipResource = host!= null && ((url.contains(host!!) ?: true) == false) && (host!!.contains("google") == false) if (skipResource) { LogUtil.e("shouldOverrideUrlLoading block url $url , host >>>> $host ") - return true - } - if (url.contains("coupang") == false && url.contains("aliex") == false) { - if (url.endsWith(".mp4")) { - val intent = Intent(Intent.ACTION_VIEW) - intent.setDataAndType(Uri.parse(url), "video/*") - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - view.context.startActivity(intent) - // If we return true, onPageStarted, onPageFinished won't be called. - return true - } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url - .startsWith("mms:") || url.startsWith("mmsto:") - ) { + val alertDialog = AlertDialog.Builder(view.context).create() + alertDialog.setCancelable(false) + alertDialog.setTitle("링크 열거임?!") + alertDialog.setMessage("$host 와 다른 사이트인데 브라우저로 열거임?") + alertDialog.setButton( + AlertDialog.BUTTON_NEUTRAL, "NO" + ) { dialog, which -> + Toast.makeText(applicationContext, "취소를 선택하심.", Toast.LENGTH_SHORT) + .show() + dialog.dismiss() + } + alertDialog.setButton( + AlertDialog.BUTTON_POSITIVE, "OK" + ) { dialog, which -> + Toast.makeText(applicationContext, "오~ 브라우저로 열릴꺼임.", Toast.LENGTH_SHORT) + .show() val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) view.context.startActivity(intent) - return true // If we return true, onPageStarted, onPageFinished won't be called. - } else if (url.startsWith("mailto:")) { - val mt = MailTo.parse(url) + dialog.dismiss() + } - val emailIntent = Intent(Intent.ACTION_SEND) + alertDialog.show() + return true + } + if (url.endsWith(".mp4")) { + val intent = Intent(Intent.ACTION_VIEW) + intent.setDataAndType(Uri.parse(url), "video/*") + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + view.context.startActivity(intent) + // If we return true, onPageStarted, onPageFinished won't be called. + return true + } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url + .startsWith("mms:") || url.startsWith("mmsto:") + ) { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + view.context.startActivity(intent) + return true // If we return true, onPageStarted, onPageFinished won't be called. + } else if (url.startsWith("mailto:")) { + val mt = MailTo.parse(url) - emailIntent.setType("text/html") - emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mt.to)) - emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.subject) - emailIntent.putExtra(Intent.EXTRA_CC, mt.cc) - emailIntent.putExtra(Intent.EXTRA_TEXT, mt.body) + val emailIntent = Intent(Intent.ACTION_SEND) - startActivity(emailIntent) + emailIntent.setType("text/html") + emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mt.to)) + emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.subject) + emailIntent.putExtra(Intent.EXTRA_CC, mt.cc) + emailIntent.putExtra(Intent.EXTRA_TEXT, mt.body) + startActivity(emailIntent) + + return true + } else if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) { + if (extraHeaders == null || extraHeadersMainPage!! && url != this@AwesomeWebViewActivity.url) { + return super.shouldOverrideUrlLoading(view, url) + } else { + view.loadUrl(url, extraHeaders!!) return true - } else if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) { - if (extraHeaders == null || extraHeadersMainPage!! && url != this@AwesomeWebViewActivity.url) { - return super.shouldOverrideUrlLoading(view, url) - } else { - view.loadUrl(url, extraHeaders!!) + } + } else { + if (webViewAppJumpEnabled!!) { + try { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + view.context.startActivity(intent) + return true // If we return true, onPageStarted, onPageFinished won't be called. + } catch (exception: Exception) { + exception.printStackTrace() return true } } else { - if (webViewAppJumpEnabled!!) { - try { - val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - view.context.startActivity(intent) - return true // If we return true, onPageStarted, onPageFinished won't be called. - } catch (exception: Exception) { - exception.printStackTrace() - return true - } - } else { - return super.shouldOverrideUrlLoading(view, url) - } + return super.shouldOverrideUrlLoading(view, url) } - } else { - return true } + } override fun onLoadResource(view: WebView, url: String) {