This commit is contained in:
2024-08-25 14:46:14 +09:00
parent 06e95de43d
commit 7fe2cd5674
6 changed files with 47 additions and 26 deletions
@@ -62,8 +62,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import java.lang.System.currentTimeMillis
import java.text.Normalizer
import java.text.SimpleDateFormat
import java.util.Date
import java.util.regex.Pattern
import kotlin.random.Random
@@ -430,6 +432,20 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
})
}
}
val String.cleanTextContent: String
get() {
// strips off all non-ASCII characters
var text = this
text = text.replace("[^\\x00-\\x7F]".toRegex(), "")
// erases all the ASCII control characters
text = text.replace("[\\p{Cntrl}&&[^\r\n\t]]".toRegex(), "")
// removes non-printable characters from Unicode
text = text.replace("\\p{C}".toRegex(), "")
return text.trim()
}
var isLoading = false
var saveClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
@@ -457,12 +473,10 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("saveClient contents >>> ${contents.length}")
Uri.parse(url)?.let {
it.path?.let {
HistoryManager.getBooPageInfoContentsSave(it, contents.replace(Char(0x20).toString()," "))
HistoryManager.getBooPageInfo(it) { info ->
runOnUiThread {
info?.let {
HistoryManager.openRealm.writeBlocking {
it.contents = contents
}
var origin = info.getTitleItem()
val biggerText = SpannableStringBuilder(origin)
biggerText.setSpan(RelativeSizeSpan(1.6f), 0, origin.length, 0)
@@ -473,6 +487,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
}
}
}
var ramdomTime = 8000L + Random(System.currentTimeMillis()).nextLong().rem(7999)
@@ -863,14 +878,12 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
it.path?.let {
HistoryManager.getBooPageInfo(it){
currentBooinfo = it
HistoryManager.openRealm.writeBlocking {
currentBooinfo?.contents = contents
}
currentChapter = it?.chapterNum ?: 0
currentPage = it?.chapterNum ?: 0
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
}
}
HistoryManager.getBooPageInfoContentsSave(it!!.path!!,contents)
}
}
}
@@ -21,7 +21,7 @@ object HistoryManager {
val openRealm : Realm = Realm.open(RealmConfiguration.Builder(clazz as Set<KClass<out TypedRealmObject>>)
.schemaVersion(schemaVersion)
.log(LogLevel.ALL)
.deleteRealmIfMigrationNeeded()
.build())
fun save(lastInfo: LastInfo) {
@@ -58,13 +58,15 @@ object HistoryManager {
openRealm.apply{
Blog.LOGE("get ${url}" )
Blog.LOGE("get ${this.query(BookPageInfo::class).count().find()}" )
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find().first()
if (bookPageInfo != null) {
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
if (bookPageInfo != null && bookPageInfo.count() > 0) {
Blog.LOGE("get ${bookPageInfo}" )
this.query(BookPageInfos::class,"bookPageUrl == $0",bookPageInfo.bookPageUrl).find().first().let {
this.query(BookPageInfos::class,"bookPageUrl == $0",bookPageInfo.first().bookPageUrl).find().first().let {
Blog.LOGE("get ${it} , ${it?.pages}" )
callback.invoke(this.copyFromRealm(it))
}
} else {
callback.invoke(null)
}
}
}
@@ -77,25 +79,22 @@ object HistoryManager {
if (result.size > 0) {
var bookPageInfo = result?.first()
if (bookPageInfo != null) {
callback.invoke(this.copyFromRealm(bookPageInfo))
callback.invoke(bookPageInfo)
}
}
}
}
suspend fun getBooPageInfoContentsSave(url : String, contents : String) {
val realm = openRealm
Blog.LOGE("get ${url}" )
Blog.LOGE("get ${realm.query(BookPageInfo::class).count().find()}" )
val result = realm.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
if (result.size > 0) {
val bookPageInfo = realm.copyFromRealm(result.first())
realm.write {
bookPageInfo.contents = contents
copyToRealm(bookPageInfo, UpdatePolicy.ALL)
fun getBooPageInfoContentsSave(url : String, contents : String) {
openRealm.writeBlocking {
Blog.LOGE("get ${url}")
Blog.LOGE("get ${query(BookPageInfo::class).count().find()}")
val result = query(BookPageInfo::class).query("pathUrl == $0", "${url}").find()
if (result.size > 0) {
result.first().contents = contents
copyToRealm(result.first(), UpdatePolicy.ALL)
}
}
}
@@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
object Booktoki : BaseWebContents() {
override var lastNumber : Int = 349
override var lastNumber : Int = 350
override fun getWebcontentsName(): String {
return "Booktoki"