This commit is contained in:
lunaticbum 2024-08-25 14:46:14 +09:00
parent 06e95de43d
commit 7fe2cd5674
6 changed files with 47 additions and 26 deletions

BIN
app/bs_debug.keystore Normal file

Binary file not shown.

View File

@ -18,6 +18,15 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
signingConfigs {
debug {
storeFile = file("./bs_debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
buildTypes { buildTypes {
release { release {
@ -56,7 +65,7 @@ dependencies {
// implementation files('libs/DualScreen.jar') // implementation files('libs/DualScreen.jar')
implementation 'io.realm.kotlin:library-base:1.16.0' implementation 'io.realm.kotlin:library-base:2.0.0'

View File

@ -62,8 +62,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.lang.System.currentTimeMillis import java.lang.System.currentTimeMillis
import java.text.Normalizer
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.regex.Pattern
import kotlin.random.Random 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 isLoading = false
var saveClient = object : WebViewClient() { var saveClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
@ -457,12 +473,10 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("saveClient contents >>> ${contents.length}") Blog.LOGE("saveClient contents >>> ${contents.length}")
Uri.parse(url)?.let { Uri.parse(url)?.let {
it.path?.let { it.path?.let {
HistoryManager.getBooPageInfoContentsSave(it, contents.replace(Char(0x20).toString()," "))
HistoryManager.getBooPageInfo(it) { info -> HistoryManager.getBooPageInfo(it) { info ->
runOnUiThread { runOnUiThread {
info?.let { info?.let {
HistoryManager.openRealm.writeBlocking {
it.contents = contents
}
var origin = info.getTitleItem() var origin = info.getTitleItem()
val biggerText = SpannableStringBuilder(origin) val biggerText = SpannableStringBuilder(origin)
biggerText.setSpan(RelativeSizeSpan(1.6f), 0, origin.length, 0) 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) var ramdomTime = 8000L + Random(System.currentTimeMillis()).nextLong().rem(7999)
@ -863,14 +878,12 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
it.path?.let { it.path?.let {
HistoryManager.getBooPageInfo(it){ HistoryManager.getBooPageInfo(it){
currentBooinfo = it currentBooinfo = it
HistoryManager.openRealm.writeBlocking {
currentBooinfo?.contents = contents
}
currentChapter = it?.chapterNum ?: 0 currentChapter = it?.chapterNum ?: 0
currentPage = it?.chapterNum ?: 0 currentPage = it?.chapterNum ?: 0
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!)) HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
} }
} }
HistoryManager.getBooPageInfoContentsSave(it!!.path!!,contents)
} }
} }
} }

View File

@ -21,7 +21,7 @@ object HistoryManager {
val openRealm : Realm = Realm.open(RealmConfiguration.Builder(clazz as Set<KClass<out TypedRealmObject>>) val openRealm : Realm = Realm.open(RealmConfiguration.Builder(clazz as Set<KClass<out TypedRealmObject>>)
.schemaVersion(schemaVersion) .schemaVersion(schemaVersion)
.log(LogLevel.ALL) .deleteRealmIfMigrationNeeded()
.build()) .build())
fun save(lastInfo: LastInfo) { fun save(lastInfo: LastInfo) {
@ -58,13 +58,15 @@ object HistoryManager {
openRealm.apply{ openRealm.apply{
Blog.LOGE("get ${url}" ) Blog.LOGE("get ${url}" )
Blog.LOGE("get ${this.query(BookPageInfo::class).count().find()}" ) Blog.LOGE("get ${this.query(BookPageInfo::class).count().find()}" )
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find().first() var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
if (bookPageInfo != null) { if (bookPageInfo != null && bookPageInfo.count() > 0) {
Blog.LOGE("get ${bookPageInfo}" ) 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}" ) Blog.LOGE("get ${it} , ${it?.pages}" )
callback.invoke(this.copyFromRealm(it)) callback.invoke(this.copyFromRealm(it))
} }
} else {
callback.invoke(null)
} }
} }
} }
@ -77,25 +79,22 @@ object HistoryManager {
if (result.size > 0) { if (result.size > 0) {
var bookPageInfo = result?.first() var bookPageInfo = result?.first()
if (bookPageInfo != null) { if (bookPageInfo != null) {
callback.invoke(this.copyFromRealm(bookPageInfo)) callback.invoke(bookPageInfo)
} }
} }
} }
} }
suspend fun getBooPageInfoContentsSave(url : String, contents : String) { fun getBooPageInfoContentsSave(url : String, contents : String) {
val realm = openRealm openRealm.writeBlocking {
Blog.LOGE("get ${url}" ) Blog.LOGE("get ${url}")
Blog.LOGE("get ${realm.query(BookPageInfo::class).count().find()}" ) Blog.LOGE("get ${query(BookPageInfo::class).count().find()}")
val result = realm.query(BookPageInfo::class).query("pathUrl == $0","${url}").find() val result = query(BookPageInfo::class).query("pathUrl == $0", "${url}").find()
if (result.size > 0) { if (result.size > 0) {
val bookPageInfo = realm.copyFromRealm(result.first()) result.first().contents = contents
realm.write { copyToRealm(result.first(), UpdatePolicy.ALL)
bookPageInfo.contents = contents
copyToRealm(bookPageInfo, UpdatePolicy.ALL)
} }
} }
} }

View File

@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
object Booktoki : BaseWebContents() { object Booktoki : BaseWebContents() {
override var lastNumber : Int = 349 override var lastNumber : Int = 350
override fun getWebcontentsName(): String { override fun getWebcontentsName(): String {
return "Booktoki" return "Booktoki"

View File

@ -2,8 +2,8 @@
plugins { plugins {
id 'com.android.application' version '8.5.2' apply false id 'com.android.application' version '8.5.2' apply false
id 'com.android.library' version '8.5.2' apply false id 'com.android.library' version '8.5.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
id 'io.realm.kotlin' version '1.16.0' apply false id 'io.realm.kotlin' version '2.0.0' apply false
} }