This commit is contained in:
lunaticbum 2024-08-22 20:38:56 +09:00
parent 0232c9dad0
commit 06e95de43d
13 changed files with 469 additions and 313 deletions

View File

@ -7,12 +7,12 @@ plugins {
android {
namespace 'com.mime.dualscreenview'
compileSdk 33
compileSdk 34
defaultConfig {
applicationId "com.mime.dualscreenview"
minSdk 24
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"
@ -43,24 +43,23 @@ android {
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.collection:collection-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.collection:collection-ktx:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.google.code.gson:gson:2.10.1'
// implementation files('libs/DualScreen.jar')
implementation 'io.realm.kotlin:library-base:1.6.0'
implementation 'io.realm.kotlin:library-base:1.16.0'
testImplementation 'junit:junit:4.13.2'
// testImplementation 'junit:junit:4.13.2'
}

View File

@ -126,6 +126,6 @@ open class Base : AppCompatActivity() {
return false
}
fun openRealm() : Realm = HistoryManager.openRealm()
fun openRealm() : Realm = HistoryManager.openRealm
}

View File

@ -58,6 +58,9 @@ import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere
import io.realm.kotlin.UpdatePolicy
import io.realm.kotlin.ext.copyFromRealm
import io.realm.kotlin.ext.query
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import java.lang.System.currentTimeMillis
import java.text.SimpleDateFormat
import java.util.Date
@ -106,8 +109,8 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
mBaseWebContentsViewer = BaseWebContentsViewer(it,this)
}
paged_layer =findViewById<PagedTextLayout>(R.id.paged_layer)
textview_title =findViewById<TextView>(R.id.textview_title)
paged_layer = findViewById<PagedTextLayout>(R.id.paged_layer)
textview_title = findViewById<TextView>(R.id.textview_title)
findViewById<ImageButton>(R.id.btn_list).setOnClickListener { v ->
mBaseWebContentsViewer?.webview?.url?.let {
@ -170,7 +173,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
realm.query<HistoryItem>()?.find()?.let {
showHistory(realm.copyFromRealm(it))
}
realm.close()
}
@ -185,8 +187,61 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
fun loadLastInfo(){
val realm = openRealm()
try { lastInfo = realm?.query<LastInfo>()?.find()?.last()?.copyFromRealm() } catch (e : Exception) { }
realm.close()
try { lastInfo = realm?.query<LastInfo>()?.find()?.last()?.copyFromRealm()
try {
if (lastInfo != null) {
HistoryManager.getBooPageInfo(Uri.parse(lastInfo!!.pageUrl!!).path!!) {
it?.let {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
if(it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
}
HistoryManager.openRealm.query<ReaderConfig>()?.find()?.let {
if (it.size > 0) {
realm.copyFromRealm(it.first()).let {
runOnUiThread {
paged_layer.setTextSize(it.textSize?.toFloat()?: 14f)
paged_layer.setLineSpacing(it.lineSpace?.toFloat() ?: 1f)
paged_layer.setLetterSpacing(it.letterSpace?.toFloat() ?: 1f)
paged_layer.setPadding(
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1)
var typeface = typesfacez.get(getIndex(typesfacez as PairArray<Any>,it.font ?: ""))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
paged_layer.setTypeface(resources.getFont(typeface.second))
}
val color = colorz.get(it.style ?: 0)
paged_layer.setColorStyle(color.second)
}
}
}
}
}
}
}
}catch (e1 : Exception){
}} catch (e : Exception) { }
}
fun reloadLastInfo() {
val configuration: Configuration = getResources().getConfiguration()
@ -240,7 +295,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
realm.close()
infos?.bookPageUrl?.let {
HistoryManager.getBooInfo(it){
it?.let {
@ -274,7 +328,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
fun proceedLastPage() {
var realm = HistoryManager.openRealm()
var realm = HistoryManager.openRealm
realm.query<ReaderConfig>()?.find()?.let {
if (it.size > 0) {
realm.copyFromRealm(it.first())?.let {
@ -285,7 +339,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
}
realm.close()
reloadLastInfo()
reloadTo(lastInfo)
}
@ -333,7 +386,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
this.delete(it)
}
}
realm.close()
dialog.dismiss()
})
builderInner.setNegativeButton("취소",
@ -388,40 +440,33 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
override fun onPageFinished(webView: WebView?, url: String?) {
super.onPageFinished(webView, url)
isLoading = false
var ramdomTimeSec = 1500L + Random(System.currentTimeMillis()).nextLong().rem(2999)
var ramdomTimeSec = 1000L + Random(System.currentTimeMillis()).nextLong().rem(3999)
Blog.LOGE("ramdomTime >>> ${ramdomTimeSec}")
webView?.postDelayed( {
Blog.LOGE("saveClient >>> ${isLoading} ${url}")
var findContents = Booktoki.getFindContentsJs()
Blog.LOGE("saveClient find >>> ${findContents}")
Random(System.currentTimeMillis()).nextLong().rem(999)
webView?.evaluateJavascript(findContents){ result: String? ->
Blog.LOGE("saveClient result >>> ${result}")
result?.let { string: String ->
Blog.LOGE("saveClient contents >>> ${string.length}")
if (string.length > 10) {
Blog.LOGE("saveClient it.length >>> ${string.length}")
var contents = string.replace("\\\"", "\"")
contents =
(contents.replace("\\n", System.getProperty("line.separator")))
var contents = string.replace("\\\"","\"")
contents = (contents.replace("\\n", System.getProperty("line.separator")))
contents = (contents.replace("\\n", System.getProperty("line.separator")))
Blog.LOGE("saveClient contents >>> ${contents.length}")
Uri.parse(url)?.let {
it.path?.let {
HistoryManager.getBooPageInfo(it) {
HistoryManager.openRealm().apply {
this.writeBlocking {
it?.contents = contents
if (it != null) {
copyToRealm(it, UpdatePolicy.ALL)
}
}
}.close()
HistoryManager.getBooPageInfo(it) { info ->
runOnUiThread {
it?.let {
var origin = it.getTitleItem()
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)
Toast.makeText(baseContext,biggerText, Toast.LENGTH_LONG).apply {
Toast.makeText(baseContext,biggerText, Toast.LENGTH_SHORT).apply {
setGravity(Gravity.CENTER, 0, 0)
}.show()
}
@ -430,7 +475,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
}
var ramdomTime = 10000L + Random(System.currentTimeMillis()).nextLong().rem(9999)
var ramdomTime = 8000L + Random(System.currentTimeMillis()).nextLong().rem(7999)
Blog.LOGE("ramdomTime >>> ${ramdomTime}")
contentsSaver?.postDelayed( { saveItem(null) }, ramdomTime)
}
@ -441,9 +486,10 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
var saveTarget : ArrayList<BookPageInfo> = arrayListOf()
private fun saveItem(infos: BookPageInfos?) {
Blog.LOGE("saveItem >>> infos?.pages ${infos?.pages?.size ?: 0}")
var savedCount = Random(System.currentTimeMillis()).nextLong().rem(19) + 6L
var savedCount = Math.abs(Random(System.currentTimeMillis()).nextLong().rem(19) + 6L)
Blog.LOGE("saveItem >>> targetCount = ${savedCount}")
infos?.pages?.reversed()?.forEach {
if (it.contents?.length ?: 0 > 10) {
if ((it.contents?.length ?: 0) > 10) {
} else {
if (saveTarget.size < savedCount.toInt()) {
saveTarget.add(it)
@ -454,7 +500,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("saveItem >>> saveTarget ${saveTarget.count()}")
if (isLoading == false) {
try {
saveTarget?.removeFirst()?.let {
saveTarget.removeFirst().let {
Blog.LOGE("saveItem >>> ${it.pathUrl}")
runOnUiThread {
mBaseWebContentsViewer.webview.url?.let { currentUrl ->
@ -521,52 +567,109 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
if (paged_layer != null && paged_layer!!.visibility == View.VISIBLE && paged_layer!!.size() > 0 && (paged_layer!!.current() < paged_layer!!.size() - 1) ) {
paged_layer!!.doNext(fast)
updateLastInfo(paged_layer!!)
}else {
Uri.parse(mBaseWebContentsViewer.webview.url)?.let {
it.path?.let {
HistoryManager.getNextPage(it) {
Blog.LOGE("HistoryManager.getNextPage(${it})")
if (it?.contents?.length ?: 0 > 10) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
if(it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
}
} else {
if(it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
paged_layer?.visibility = GONE
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
paged_layer?.visibility = GONE
}
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
} else {
val pathUrl = currentBooinfo?.pathUrl
if (pathUrl != null && pathUrl.length > 6) {
HistoryManager.getNextPage(pathUrl) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
Blog.LOGE("HistoryManager.getNextPage(${it})")
if ((it?.contents?.length ?: 0) > 10) {
paged_layer.visibility = VISIBLE
if((it?.pathUrl?.length ?: 0) > 0) {
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
}
applyReaderConfig()
} else {
if(it?.pathUrl?.length ?: 0 > 0) {
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
paged_layer.visibility = GONE
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
paged_layer.visibility = GONE
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
}
}
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
}
} else {
Uri.parse(mBaseWebContentsViewer.webview.url)?.let {
it.path?.let {
HistoryManager.getNextPage(it) {
Blog.LOGE("HistoryManager.getNextPage(${it})")
if (it?.contents?.length ?: 0 > 10) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
if (it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(
historyItem = HistoryItem().putHistory(
it,
mBaseWebContentsViewer.webview.url!!
)
)
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith(
"http"
)
) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(
lastInfo!!.pageUrl!!.replace(
Uri.parse(lastInfo!!.pageUrl)!!.path!!,
it?.pathUrl!!
)
)
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
}
} else {
if (it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(historyItem = HistoryItem().putHistory(it, mBaseWebContentsViewer.webview.url!!))
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(
lastInfo!!.pageUrl!!.replace(
Uri.parse(lastInfo!!.pageUrl)!!.path!!,
it?.pathUrl!!
)
)
paged_layer?.visibility = GONE
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
paged_layer?.visibility = GONE
}
}
}
it?.pathUrl?.let { HistoryManager.getBooInfo(it) { saveItem(it) } }
}
}
}
}
@ -585,29 +688,112 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
fun applyReaderConfig() {
var realm = HistoryManager.openRealm
realm.query<ReaderConfig>()?.find()?.let {
if (it.size > 0) {
realm.copyFromRealm(it.first())?.let {
runOnUiThread {
paged_layer.setTextSize(it.textSize?.toFloat()?: 14f)
paged_layer.setLineSpacing(it.lineSpace?.toFloat() ?: 1f)
paged_layer.setLetterSpacing(it.letterSpace?.toFloat() ?: 1f)
paged_layer.setPadding(
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1)
var typeface = typesfacez.get(getIndex(typesfacez as PairArray<Any>,it.font ?: ""))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
paged_layer?.setTypeface(resources.getFont(typeface.second))
}
val color = colorz.get(it.style ?: 0)
paged_layer?.setColorStyle(color.second)
}
}
}
}
}
fun actionPrevEvent(fast : Boolean = false) {
if (paged_layer != null && paged_layer!!.visibility == View.VISIBLE && paged_layer!!.size() > 0 && paged_layer!!.current() > 0 ) {
paged_layer!!.doPrev(fast)
updateLastInfo(paged_layer!!)
} else {
Uri.parse(mBaseWebContentsViewer.webview.url)?.let {
it.path?.let {
HistoryManager.getPrevPage(it) {
if (it?.contents?.length ?: 0 > 10) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
}
if (currentBooinfo != null) {
HistoryManager.getPrevPage(currentBooinfo!!.pathUrl!!) {
Blog.LOGE("HistoryManager.getNextPage(${it})")
if (it?.contents?.length ?: 0 > 10) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
if(it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
}
applyReaderConfig()
} else {
if(it?.pathUrl?.length ?: 0 > 0) {
Blog.LOGE("HistoryManager.getNextPage(${it?.pathUrl})")
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
Blog.LOGE("HistoryManager.getNextPage(${lastInfo?.pageUrl})")
paged_layer.visibility = GONE
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else {
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
paged_layer.visibility = GONE
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
}
}
if(it?.pathUrl?.length ?: 0 > 0) {
it?.pathUrl?.let {
HistoryManager.getBooInfo(it) {
saveItem(it)
}
}
}
}
} else {
Uri.parse(mBaseWebContentsViewer.webview.url)?.let {
it.path?.let {
HistoryManager.getPrevPage(it) {
if (it?.contents?.length ?: 0 > 10) {
currentBooinfo = it
paged_layer.text = it!!.contents!!
paged_layer.visibility = VISIBLE
}
if (it?.pathUrl?.length ?: 0 > 0) {
HistoryManager.save(
historyItem = HistoryItem().putHistory(
it,
mBaseWebContentsViewer.webview.url!!
)
)
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith(
"http"
)
) {
mBaseWebContentsViewer.webview.loadUrl(
lastInfo!!.pageUrl!!.replace(
Uri.parse(lastInfo!!.pageUrl)!!.path!!,
it?.pathUrl!!
)
)
} else {
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
}
}
}
}
}
}
@ -616,6 +802,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
override fun onBackPressed() {
// super.onBackPressed()
var layer = findViewById<PagedTextLayout>(R.id.paged_layer)
@ -642,6 +829,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} else {
finishAffinity()
didBackPress = false
// super.onBackPressed()
}
}
@ -653,39 +841,11 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
@RequiresApi(Build.VERSION_CODES.O)
override fun onLoadedContents(aContents: String) {
paged_layer.apply {
if (aContents != null) {
if (aContents != null && aContents.length > 10) {
var contents = aContents.replace("\\\"","\"")
contents = (contents.replace("\\n", System.getProperty("line.separator")))
contents = (contents.replace("\\n", System.getProperty("line.separator")))
mPagedTextViewInterface = this@Intro
var realm = HistoryManager.openRealm()
realm.query<ReaderConfig>()?.find()?.let {
if (it.size > 0) {
realm.copyFromRealm(it.first())?.let {
runOnUiThread {
paged_layer?.setTextSize(it.textSize?.toFloat()?: 14f)
paged_layer?.setLineSpacing(it.lineSpace?.toFloat() ?: 1f)
paged_layer?.setLetterSpacing(it.letterSpace?.toFloat() ?: 1f)
paged_layer?.setPadding(
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1,
it.padding ?: 1)
var typeface = typesfacez.get(getIndex(typesfacez as PairArray<Any>,it.font ?: ""))
paged_layer?.setTypeface(resources.getFont(typeface.second))
val color = colorz.get(it.style ?: 0)
paged_layer?.setColorStyle(color.second)
}
}
}
}
realm.close()
// text = (contents.replace("\\n", System.getProperty("line.separator")))
if(lastInfo != null && mBaseWebContentsViewer.webview.url?.endsWith(lastInfo!!.pageUrl) ?: false) {
this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = VISIBLE
paged_layer?.postDelayed({
@ -693,28 +853,21 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
},1000)
}
runOnUiThread {
text = (contents.replace("\\n", System.getProperty("line.separator")))
text = contents
visibility = VISIBLE
}
applyReaderConfig()
forceUpdateUI()
mBaseWebContentsViewer.webview.url?.let {
Uri.parse(it)?.let {
it.path?.let {
HistoryManager.getBooPageInfo(it){
currentBooinfo = it
HistoryManager.openRealm().apply {
this.writeBlocking {
it?.chapterTitle?.let {
onFindTitle(it)
}
currentChapter = it?.chapterNum ?: 0
currentPage = it?.chapterNum ?: 0
it?.contents = contents
if (it != null) {
copyToRealm(it, UpdatePolicy.ALL)
}
}
}.close()
HistoryManager.openRealm.writeBlocking {
currentBooinfo?.contents = contents
}
currentChapter = it?.chapterNum ?: 0
currentPage = it?.chapterNum ?: 0
HistoryManager.save(historyItem = HistoryItem().putHistory(it,mBaseWebContentsViewer.webview.url!!))
}
}
@ -804,7 +957,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
}
Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}")
realm.close()
}
fun updateLastInfo(pagedTextLayout: PagedTextLayout) {
@ -826,7 +979,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
}
Blog.LOGD(log ="Successfully opened realm: ${realm.configuration.name}")
realm.close()
}
override fun onKeyClick(keyCode: Int): Boolean {
when(keyCode) {

View File

@ -24,7 +24,7 @@ class Settings : Base() {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.settings)
// setContentView(R.layout.settings)
var realm = HistoryManager.openRealm()
var realm = HistoryManager.openRealm
realm.writeBlocking {
this.query<ReaderConfig>()?.find()?.let {
if (it.size > 0) {
@ -35,7 +35,6 @@ class Settings : Base() {
}
}
realm.close()
}
@RequiresApi(Build.VERSION_CODES.O)
@ -116,10 +115,9 @@ class Settings : Base() {
fun configSave() {
var realm = HistoryManager.openRealm()
var realm = HistoryManager.openRealm
realm.writeBlocking {
copyToRealm(readerConfig!!, UpdatePolicy.ALL)
}
realm.close()
}
}

View File

@ -18,72 +18,59 @@ object HistoryManager {
val clazz : Set<KClass<out BaseRealmObject>> = setOf(LastInfo::class, HistoryItem::class, ReaderConfig::class, BookPageInfos::class, BookPageInfo::class)
val schemaVersion : Long = 5
fun 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)
.log(LogLevel.ALL)
// .deleteRealmIfMigrationNeeded()
.build())
fun save(lastInfo: LastInfo) {
openRealm()?.apply{
openRealm.apply{
this.writeBlocking {
copyToRealm(lastInfo, UpdatePolicy.ALL)
}
}?.close()
}
}
fun save(historyItem: HistoryItem) {
openRealm()?.apply{
openRealm.apply{
this.writeBlocking {
copyToRealm(historyItem, UpdatePolicy.ALL)
}
}?.close()
}
}
fun requestLastInfo(callback : (LastInfo)->Unit) {
openRealm()?.apply{
openRealm.apply{
}?.close()
}
}
fun save(config : ReaderConfig) {
openRealm()?.apply{
openRealm.apply{
this.writeBlocking {
copyToRealm(config,UpdatePolicy.ALL)
}
}?.close()
}
}
fun getBooInfo(url : String ,callback : (BookPageInfos?)->Unit) {
openRealm()?.apply{
openRealm.apply{
Blog.LOGE("get ${url}" )
Blog.LOGE("get ${this.query(BookPageInfo::class).count().find()}" )
var list = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
if (list.size > 0) {
var bookPageInfo = list.first()
if (bookPageInfo != null) {
Blog.LOGE("get ${bookPageInfo}")
this.query(BookPageInfos::class, "bookPageUrl == $0", bookPageInfo.bookPageUrl)
.find().first().let {
Blog.LOGE("get ${it} , ${it?.pages}")
callback.invoke(this.copyFromRealm(it))
}
} else {
callback.invoke(null)
}
} else {
var list = this.query(BookPageInfos::class).query("bookPageUrl == $0","${url}").find()
if (list.size > 0) {
callback.invoke(this.copyFromRealm(list.first()))
} else {
callback.invoke(null)
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find().first()
if (bookPageInfo != null) {
Blog.LOGE("get ${bookPageInfo}" )
this.query(BookPageInfos::class,"bookPageUrl == $0",bookPageInfo.bookPageUrl).find().first().let {
Blog.LOGE("get ${it} , ${it?.pages}" )
callback.invoke(this.copyFromRealm(it))
}
}
}?.close()
}
}
fun getBooPageInfo(url : String ,callback : (BookPageInfo?)->Unit) {
openRealm()?.apply{
openRealm.apply{
Blog.LOGE("get ${url}" )
Blog.LOGE("get ${this.query(BookPageInfo::class).count().find()}" )
var result = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
@ -93,13 +80,29 @@ object HistoryManager {
callback.invoke(this.copyFromRealm(bookPageInfo))
}
}
}?.close()
}
}
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 getNextPage(url : String ,callback : (BookPageInfo?)->Unit) {
openRealm()?.apply{
openRealm.apply{
Blog.LOGE("getNextPage ${url}" )
Blog.LOGE("getNextPage ${this.query(BookPageInfo::class).count().find()}" )
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()?.first()
@ -109,25 +112,25 @@ object HistoryManager {
Blog.LOGE("getNextPage 2 ${bookPageInfo.bookPageUrl}" )
var results = this.query(BookPageInfo::class).query("chapterNum == $0",bookPageInfo.chapterNum + 1).query("bookPageUrl == $0","${bookPageInfo.bookPageUrl}").find()
if(results.size > 0) {
results.first()?.let {
results.first().let {
Blog.LOGE("getNextPage 2 ${it.pathUrl}" )
callback.invoke(it)
}
}
}
}?.close()
}
}
fun getPrevPage(url : String ,callback : (BookPageInfo?)->Unit) {
openRealm()?.apply{
openRealm.apply{
Blog.LOGE("getPrevPage ${url}" )
Blog.LOGE("getPrevPage ${this.query(BookPageInfo::class).count().find()}" )
var bookPageInfo = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()?.first()
Blog.LOGE("getPrevPage ${bookPageInfo}" )
Blog.LOGE("getNextPage ${bookPageInfo}" )
if (bookPageInfo != null) {
Blog.LOGE("getPrevPage 2 ${bookPageInfo.chapterNum}" )
Blog.LOGE("getPrevPage 2 ${bookPageInfo.bookPageUrl}" )
Blog.LOGE("getNextPage 2 ${bookPageInfo.chapterNum}" )
Blog.LOGE("getNextPage 2 ${bookPageInfo.bookPageUrl}" )
var results = this.query(BookPageInfo::class).query("chapterNum == $0 && bookPageUrl == $1",bookPageInfo.chapterNum - 1,"${bookPageInfo.bookPageUrl}").find()
if(results.size > 0) {
results.first()?.let {
@ -135,7 +138,7 @@ object HistoryManager {
}
}
}
}?.close()
}
}
}

View File

@ -1,22 +1,22 @@
package com.mime.dualscreenview.data.model
import com.mime.dualscreenview.common.Blog
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.RealmSet
import io.realm.kotlin.types.annotations.Index
import io.realm.kotlin.types.annotations.Ignore
import io.realm.kotlin.types.annotations.PrimaryKey
class BookPageInfosJ : RealmObject {
class BookPageInfosJ {
var bookTitle : String = ""
var bookPageUrl : String = ""
var pages : ArrayList<BookPageInfoJ> = arrayListOf<BookPageInfoJ>()
fun getTitleArray() : ArrayList<String> {
var arrayList = ArrayList<String>()
pages?.forEach { arrayList.add(it.bookTitle ?: "") }
pages.forEach { arrayList.add(it.bookTitle ?: "") }
return arrayList
}
@ -24,14 +24,11 @@ class BookPageInfosJ : RealmObject {
var r = BookPageInfos()
r.bookTitle = this.bookTitle
r.bookPageUrl = this.bookPageUrl
// for (item in this.pages) {
//// Blog.LOGE("item >>> ${item}")
// r.pages.add(item.getRealm())
// }
return r
}
}
class BookPageInfoJ : RealmObject {
class BookPageInfoJ {
var chapterID : Int = 0
var contents : String? = ""
var bookPageUrl : String? = ""
@ -58,13 +55,16 @@ class BookPageInfoJ : RealmObject {
class BookPageInfos : RealmObject {
var bookTitle : String = ""
@PrimaryKey
var bookPageUrl : String? = ""
var pages : RealmList<BookPageInfo> = realmListOf()
fun getTitleArray() : ArrayList<String> {
var arrayList = ArrayList<String>()
pages?.forEach {
pages.forEach {
arrayList.add(it.getTitleItem())}
return arrayList
}
@ -102,7 +102,7 @@ class BookPageInfo : RealmObject {
fun getTitleItem() : String {
var result = StringBuilder()
result.append(if (contents?.length ?: 0 > 10) {
result.append(if ((contents?.length ?: 0) > 10) {
"S:[0] "
} else {
"[X] "
@ -110,7 +110,7 @@ class BookPageInfo : RealmObject {
result.append(chapterTitle?: "")
result.append(if (lastPage ?: 0 >0) {
result.append(if ((lastPage ?: 0) > 0) {
" [0] "
} else {
" [X] "

View File

@ -7,7 +7,7 @@ import java.text.SimpleDateFormat
import java.util.Date
class LastInfo() : RealmObject {
class LastInfo : RealmObject {
@PrimaryKey
var _id : String = "UniqLastId"
var pageUrl : String = ""
@ -26,7 +26,7 @@ class LastInfo() : RealmObject {
displayOrientation = this@LastInfo.displayOrientation
}
}
class HistoryItem() : RealmObject {
class HistoryItem : RealmObject {
@PrimaryKey
var title : String = ""
var pageUrl : String = ""

View File

@ -3,7 +3,7 @@ package com.mime.dualscreenview.data.model
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
class ReaderConfig() : RealmObject {
class ReaderConfig : RealmObject {
@PrimaryKey
var id : String? = "ReaderConfig"
var textSize : Int? = 14

View File

@ -713,103 +713,103 @@ class SimpleFingerGestures : OnTouchListener {
}
}
abstract class OnSwipeTouchListener(val context: Context?) : View.OnTouchListener {
companion object {
private const val SWIPE_DISTANCE_THRESHOLD = 100
private const val SWIPE_VELOCITY_THRESHOLD = 100
}
private val gestureDetector: GestureDetector
abstract fun onSwipeLeft()
abstract fun onSwipeRight()
abstract fun onSwipeDown()
abstract fun onSwipeUp()
abstract fun onSingleTap(area : TouchArea)
abstract fun onDoubleTap(area : TouchArea)
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (event == null) {
return false
}
return gestureDetector.onTouchEvent(event!!)
}
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
return true
}
override fun onDoubleTapEvent(e: MotionEvent): Boolean {
val width: Int = context?.resources?.displayMetrics?.widthPixels ?: 0
val height: Int = context?.resources?.displayMetrics?.heightPixels ?: 0
var touchArea : TouchArea = TouchArea.Center
if(width > 0 && height > 0) {
val centerAreaSize = width * 0.4
var sideAreaSize = (width - centerAreaSize) * 0.5
if(e.x < sideAreaSize) {
touchArea = TouchArea.DoubleLeft
} else if(e.x > sideAreaSize && e.x < width - sideAreaSize) {
} else {
touchArea = TouchArea.DoubleRight
}
}
onDoubleTap(touchArea)
return super.onDoubleTapEvent(e)
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
val width: Int = context?.resources?.displayMetrics?.widthPixels ?: 0
val height: Int = context?.resources?.displayMetrics?.heightPixels ?: 0
var touchArea : TouchArea = TouchArea.Center
if(width > 0 && height > 0) {
val centerAreaSize = width * 0.4
var sideAreaSize = (width - centerAreaSize) * 0.5
if(e.x < sideAreaSize) {
touchArea = TouchArea.Left
} else if(e.x > sideAreaSize && e.x < width - sideAreaSize) {
} else {
touchArea = TouchArea.Right
}
}
onSingleTap(touchArea)
return super.onSingleTapConfirmed(e)
}
// override fun onSingleTapUp(e: MotionEvent): Boolean {
//abstract class OnSwipeTouchListener(val context: Context?) : View.OnTouchListener {
// companion object {
// private const val SWIPE_DISTANCE_THRESHOLD = 100
// private const val SWIPE_VELOCITY_THRESHOLD = 100
// }
// private val gestureDetector: GestureDetector
// abstract fun onSwipeLeft()
// abstract fun onSwipeRight()
// abstract fun onSwipeDown()
// abstract fun onSwipeUp()
// abstract fun onSingleTap(area : TouchArea)
// abstract fun onDoubleTap(area : TouchArea)
//
// return super.onSingleTapUp(e)
// override fun onTouch(v: View?, event: MotionEvent?): Boolean {
// if (event == null) {
// return false
// }
override fun onFling(
e1: MotionEvent,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
Blog.LOGE("e1.pointerCount >> ${e1.pointerCount}")
Blog.LOGE("e2.pointerCount >> ${e2.pointerCount}")
val distanceX = e2.x - (e1?.x ?: 0f)
val distanceY = e2.y - (e1?.y ?: 0f)
if (Math.abs(distanceX) > Math.abs(distanceY)
&& Math.abs(distanceX) > SWIPE_DISTANCE_THRESHOLD
&& Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (distanceX > 0) onSwipeRight() else onSwipeLeft()
return true
} else if (Math.abs(distanceY) > Math.abs(distanceX)
&& Math.abs(distanceY) > SWIPE_DISTANCE_THRESHOLD
&& Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (distanceY > 0) onSwipeDown() else onSwipeUp()
return true
} else {
}
return false
}
}
init {
gestureDetector = GestureDetector(context, GestureListener())
}
}
// return gestureDetector.onTouchEvent(event!!)
// }
//
//
// private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
//
// override fun onDown(e: MotionEvent): Boolean {
// return true
// }
//
// override fun onDoubleTapEvent(e: MotionEvent): Boolean {
// val width: Int = context?.resources?.displayMetrics?.widthPixels ?: 0
// val height: Int = context?.resources?.displayMetrics?.heightPixels ?: 0
// var touchArea : TouchArea = TouchArea.Center
// if(width > 0 && height > 0) {
// val centerAreaSize = width * 0.4
// var sideAreaSize = (width - centerAreaSize) * 0.5
// if(e.x < sideAreaSize) {
// touchArea = TouchArea.DoubleLeft
// } else if(e.x > sideAreaSize && e.x < width - sideAreaSize) {
//
// } else {
// touchArea = TouchArea.DoubleRight
// }
// }
// onDoubleTap(touchArea)
// return super.onDoubleTapEvent(e)
// }
//
// override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
// val width: Int = context?.resources?.displayMetrics?.widthPixels ?: 0
// val height: Int = context?.resources?.displayMetrics?.heightPixels ?: 0
// var touchArea : TouchArea = TouchArea.Center
// if(width > 0 && height > 0) {
// val centerAreaSize = width * 0.4
// var sideAreaSize = (width - centerAreaSize) * 0.5
// if(e.x < sideAreaSize) {
// touchArea = TouchArea.Left
// } else if(e.x > sideAreaSize && e.x < width - sideAreaSize) {
//
// } else {
// touchArea = TouchArea.Right
// }
// }
// onSingleTap(touchArea)
// return super.onSingleTapConfirmed(e)
// }
//
//// override fun onSingleTapUp(e: MotionEvent): Boolean {
////
//// return super.onSingleTapUp(e)
//// }
//
// override fun onFling(
// e1: MotionEvent?,
// e2: MotionEvent,
// velocityX: Float,
// velocityY: Float
// ): Boolean {
//Blog.LOGE("e1.pointerCount >> ${e1?.pointerCount}")
// Blog.LOGE("e2.pointerCount >> ${e2.pointerCount}")
// val distanceX = e2.x - (e1?.x ?: 0f)
// val distanceY = e2.y - (e1?.y ?: 0f)
// if (Math.abs(distanceX) > Math.abs(distanceY)
// && Math.abs(distanceX) > SWIPE_DISTANCE_THRESHOLD
// && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
// if (distanceX > 0) onSwipeRight() else onSwipeLeft()
// return true
// } else if (Math.abs(distanceY) > Math.abs(distanceX)
// && Math.abs(distanceY) > SWIPE_DISTANCE_THRESHOLD
// && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
// if (distanceY > 0) onSwipeDown() else onSwipeUp()
// return true
// } else {
//
// }
// return false
// }
// }
// init {
// gestureDetector = GestureDetector(context, GestureListener())
// }
//}

View File

@ -76,6 +76,7 @@ open class BaseWebContentsViewer {
fun loadLastInfo(lastInfo: LastInfo) {
lastInfo?.let { last ->
Blog.LOGE("last.pageUrl >>> ${last.pageUrl}")
currentContentsProvider = WebContentsManger.getBaseWebContentsBy(last.contentsName)
// HistoryManager.getBooPageInfo(last.pageUrl,{ page ->
// if(page != null){
@ -85,7 +86,7 @@ open class BaseWebContentsViewer {
// webview.loadUrl(last.pageUrl)
// }
// } else {
if (last.pageUrl.startsWith("http")) {
if (last.pageUrl.startsWith("https://")) {
webview.loadUrl(last.pageUrl)
} else {
try {

View File

@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
object Booktoki : BaseWebContents() {
override var lastNumber : Int = 348
override var lastNumber : Int = 349
override fun getWebcontentsName(): String {
return "Booktoki"
@ -84,12 +84,12 @@ object Booktoki : BaseWebContents() {
"fail load"
}
}
// "if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
// "if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
// "if(document.getElementById(\"main-banner-view\") != null) document.getElementById(\"main-banner-view\").remove();" +
// "if(document.getElementsByClassName(\"board-tail-banner\") != null && document.getElementsByClassName(\"board-tail-banner\").length > 0)document.getElementsByClassName(\"board-tail-banner\")[0].remove();" +
// "if(document.getElementById(\"id_mbv\") != null)document.getElementById(\"id_mbv\").remove();"
override fun onLoadedJs(): String {
return "if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
"if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
"if(document.getElementById(\"main-banner-view\") != null) document.getElementById(\"main-banner-view\").remove();" +
"if(document.getElementsByClassName(\"board-tail-banner\") != null && document.getElementsByClassName(\"board-tail-banner\").length > 0)document.getElementsByClassName(\"board-tail-banner\")[0].remove();" +
"if(document.getElementById(\"id_mbv\") != null)document.getElementById(\"id_mbv\").remove();"
return ""
}
}

View File

@ -1,9 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'io.realm.kotlin' version '1.6.0' apply false
id 'com.android.application' 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 'io.realm.kotlin' version '1.16.0' apply false
}

View File

@ -21,4 +21,6 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.useNewApkCreator=false
#android.useNewApkCreator=false
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false