다시 토끼로...

This commit is contained in:
lunaticbum 2024-08-02 13:20:22 +09:00
parent ceb22bcbcb
commit f107c7c84d
8 changed files with 162 additions and 59 deletions

View File

@ -46,6 +46,7 @@ import com.mime.dualscreenview.view.TouchArea
import com.mime.dualscreenview.webcontents.BaseWebContentsViewer import com.mime.dualscreenview.webcontents.BaseWebContentsViewer
import com.mime.dualscreenview.webcontents.MainControllInterface import com.mime.dualscreenview.webcontents.MainControllInterface
import com.mime.dualscreenview.webcontents.contentsinfo.Agit import com.mime.dualscreenview.webcontents.contentsinfo.Agit
import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki
import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere
import io.realm.kotlin.UpdatePolicy import io.realm.kotlin.UpdatePolicy
import io.realm.kotlin.ext.copyFromRealm import io.realm.kotlin.ext.copyFromRealm
@ -143,7 +144,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
findViewById<View>(R.id.btn_home).setOnClickListener { v-> findViewById<View>(R.id.btn_home).setOnClickListener { v->
paged_layer?.visibility = GONE paged_layer?.visibility = GONE
mBaseWebContentsViewer.loadContents(Agit) mBaseWebContentsViewer.loadContents(Booktoki)
} }
loadLastInfo() loadLastInfo()
@ -175,6 +176,18 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.pages}") Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.pages}")
// realm.createObjectFromJson // realm.createObjectFromJson
Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.getR()}") Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.getR()}")
HistoryManager.getBooInfo(infosj.bookPageUrl!!){
if (it != null) {
infos = copyToRealm(it!!, UpdatePolicy.ALL)
for (item in infosj.pages) {
if (infos!!.hasItem(item.getRealm()) == false) {
infos!!.pages.add(item.getRealm())
}
}
Blog.LOGE("onBookInfos", "onBookInfos 3 >> ${realm.query<BookPageInfos>().find().size}")
Blog.LOGE("onBookInfos", "onBookInfos 4 >> ${realm.query<BookPageInfo>().find().size}")
} else {
infos = infosj?.getR() infos = infosj?.getR()
if (infos != null) { if (infos != null) {
infos = copyToRealm(infos!!, UpdatePolicy.ALL) infos = copyToRealm(infos!!, UpdatePolicy.ALL)
@ -184,22 +197,27 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("onBookInfos", "onBookInfos 3 >> ${realm.query<BookPageInfos>().find().size}") Blog.LOGE("onBookInfos", "onBookInfos 3 >> ${realm.query<BookPageInfos>().find().size}")
Blog.LOGE("onBookInfos", "onBookInfos 4 >> ${realm.query<BookPageInfo>().find().size}") Blog.LOGE("onBookInfos", "onBookInfos 4 >> ${realm.query<BookPageInfo>().find().size}")
} }
}
}
if (infos != null) {
infos = this.copyFromRealm(infos!!)
}
} catch (e :Exception) { } catch (e :Exception) {
e.printStackTrace() e.printStackTrace()
} }
} }
realm.close() realm.close()
infos?.let { infos?.bookPageUrl?.let {
HistoryManager.getBooInfo(it){
it?.let {
Blog.LOGE("onBookInfos" , "onBookInfos it >> ${it}") Blog.LOGE("onBookInfos" , "onBookInfos it >> ${it}")
runOnUiThread { runOnUiThread {
showList(it) showList(it)
} }
} }
}
}
} }
fun reloadTo(lastInfo: LastInfo?) { fun reloadTo(lastInfo: LastInfo?) {
@ -207,7 +225,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
if (lastInfo != null) { if (lastInfo != null) {
mBaseWebContentsViewer.loadLastInfo(lastInfo!!) mBaseWebContentsViewer.loadLastInfo(lastInfo!!)
} else { } else {
mBaseWebContentsViewer.loadContents(Agit) mBaseWebContentsViewer.loadContents(Booktoki)
} }
},200L) },200L)
} }
@ -245,8 +263,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
arrayAdapter.addAll(item.title) arrayAdapter.addAll(item.title)
} }
builderSingle.setNegativeButton("cancel", builderSingle.setNegativeButton("cancel",
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() }) DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() })
@ -293,17 +309,23 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
} }
fun showList(infos: BookPageInfos) { fun showList(infos: BookPageInfos) {
if (infos != null) {
if (infos != null && infos.pages.size ?: 0 > 0) {
var items : ArrayList<BookPageInfo> = arrayListOf()
for (item in infos.pages) {
items.add(item)
}
items.sortBy { it.chapterNum }
DefaultList.showDefaultList( DefaultList.showDefaultList(
this@Intro, this@Intro,
"현제는 ${currentTitle} - ${(infos.pages.size ?: 0) - currentChapter} -> 다른화를 골라", "현제는 ${currentTitle} - ${(infos.pages.size ?: 0) - currentChapter} -> 다른화를 골라",
infos.getTitleArray(), items,
currentChapter, currentChapter,
{ position -> { position ->
return@showDefaultList infos.pages?.get(position)?.chapterTitle ?: "" return@showDefaultList items?.get(position)?.chapterTitle ?: ""
}, },
{ position -> { position ->
infos.pages?.get(position)?.let { moveTo(it) } items?.get(position)?.let { moveTo(it) }
}, { state -> }, { state ->
if (state < 0 ) { if (state < 0 ) {
saveItem(infos) saveItem(infos)
@ -325,7 +347,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
Blog.LOGE("ramdomTime >>> ${ramdomTimeSec}") Blog.LOGE("ramdomTime >>> ${ramdomTimeSec}")
webView?.postDelayed( { webView?.postDelayed( {
Blog.LOGE("saveClient >>> ${isLoading} ${url}") Blog.LOGE("saveClient >>> ${isLoading} ${url}")
var findContents = Agit.getFindContentsJs() var findContents = Booktoki.getFindContentsJs()
Blog.LOGE("saveClient find >>> ${findContents}") Blog.LOGE("saveClient find >>> ${findContents}")
Random(System.currentTimeMillis()).nextLong().rem(999) Random(System.currentTimeMillis()).nextLong().rem(999)
webView?.evaluateJavascript(findContents){ result: String? -> webView?.evaluateJavascript(findContents){ result: String? ->
@ -463,8 +485,8 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!)) mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
paged_layer?.visibility = GONE paged_layer?.visibility = GONE
} else { } else {
Blog.LOGE("HistoryManager.getNextPage(${Agit.getLastedDoamin()})") Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
mBaseWebContentsViewer.webview.loadUrl(Agit.getLastedDoamin() + it?.pathUrl!!) mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
paged_layer?.visibility = GONE paged_layer?.visibility = GONE
} }
it?.pathUrl?.let { it?.pathUrl?.let {
@ -512,7 +534,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) { if (lastInfo?.pageUrl?.length ?: 0 > 0 && lastInfo?.pageUrl!!.startsWith("http")) {
mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!)) mBaseWebContentsViewer.webview.loadUrl(lastInfo!!.pageUrl!!.replace(Uri.parse(lastInfo!!.pageUrl)!!.path!!,it?.pathUrl!!))
} else { } else {
mBaseWebContentsViewer.webview.loadUrl(Agit.getLastedDoamin() + it?.pathUrl!!) mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
} }
} }
} }

View File

@ -58,13 +58,26 @@ 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 list = this.query(BookPageInfo::class).query("pathUrl == $0","${url}").find()
if (list.size > 0) {
var bookPageInfo = list.first()
if (bookPageInfo != null) { if (bookPageInfo != null) {
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.bookPageUrl)
Blog.LOGE("get ${it} , ${it?.pages}" ) .find().first().let {
Blog.LOGE("get ${it} , ${it?.pages}")
callback.invoke(this.copyFromRealm(it)) 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)
}
} }
}?.close() }?.close()
} }
@ -94,7 +107,7 @@ object HistoryManager {
if (bookPageInfo != null) { if (bookPageInfo != null) {
Blog.LOGE("getNextPage 2 ${bookPageInfo.chapterNum}" ) Blog.LOGE("getNextPage 2 ${bookPageInfo.chapterNum}" )
Blog.LOGE("getNextPage 2 ${bookPageInfo.bookPageUrl}" ) Blog.LOGE("getNextPage 2 ${bookPageInfo.bookPageUrl}" )
var results = this.query(BookPageInfo::class).query("chapterNum == $0",bookPageInfo.chapterNum - 1).query("bookPageUrl == $0","${bookPageInfo.bookPageUrl}").find() var results = this.query(BookPageInfo::class).query("chapterNum == $0",bookPageInfo.chapterNum + 1).query("bookPageUrl == $0","${bookPageInfo.bookPageUrl}").find()
if(results.size > 0) { if(results.size > 0) {
results.first()?.let { results.first()?.let {
Blog.LOGE("getNextPage 2 ${it.pathUrl}" ) Blog.LOGE("getNextPage 2 ${it.pathUrl}" )
@ -111,11 +124,11 @@ object HistoryManager {
Blog.LOGE("getPrevPage ${url}" ) Blog.LOGE("getPrevPage ${url}" )
Blog.LOGE("getPrevPage ${this.query(BookPageInfo::class).count().find()}" ) Blog.LOGE("getPrevPage ${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()?.first()
Blog.LOGE("getNextPage ${bookPageInfo}" ) Blog.LOGE("getPrevPage ${bookPageInfo}" )
if (bookPageInfo != null) { if (bookPageInfo != null) {
Blog.LOGE("getNextPage 2 ${bookPageInfo.chapterNum}" ) Blog.LOGE("getPrevPage 2 ${bookPageInfo.chapterNum}" )
Blog.LOGE("getNextPage 2 ${bookPageInfo.bookPageUrl}" ) Blog.LOGE("getPrevPage 2 ${bookPageInfo.bookPageUrl}" )
var results = this.query(BookPageInfo::class).query("chapterNum == $0 && bookPageUrl == $1",bookPageInfo.chapterNum + 1,"${bookPageInfo.bookPageUrl}").find() var results = this.query(BookPageInfo::class).query("chapterNum == $0 && bookPageUrl == $1",bookPageInfo.chapterNum - 1,"${bookPageInfo.bookPageUrl}").find()
if(results.size > 0) { if(results.size > 0) {
results.first()?.let { results.first()?.let {
callback.invoke(it) callback.invoke(it)

View File

@ -5,6 +5,7 @@ import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.RealmSet import io.realm.kotlin.types.RealmSet
import io.realm.kotlin.types.annotations.Index
import io.realm.kotlin.types.annotations.PrimaryKey import io.realm.kotlin.types.annotations.PrimaryKey
@ -63,17 +64,30 @@ class BookPageInfos : RealmObject {
var pages : RealmList<BookPageInfo> = realmListOf() var pages : RealmList<BookPageInfo> = realmListOf()
fun getTitleArray() : ArrayList<String> { fun getTitleArray() : ArrayList<String> {
var arrayList = ArrayList<String>() var arrayList = ArrayList<String>()
pages?.forEach { pages?.forEach {
// Blog.LOGE("chapterTitle >> ${it.getTitleItem()} ")
arrayList.add(it.getTitleItem())} arrayList.add(it.getTitleItem())}
return arrayList return arrayList
} }
fun sort() {
val comparator : Comparator<BookPageInfo> = compareBy { it.chapterID }
pages.sortWith(comparator)
}
fun hasItem(item: BookPageInfo) : Boolean {
var hasItem = false
for (c in pages) {
if (!hasItem) {
hasItem = c.pathUrl.equals(item.pathUrl)
}
}
return hasItem
}
} }
class BookPageInfo : RealmObject { class BookPageInfo : RealmObject {
var chapterID : Int = 0 var chapterID : Int = 0
var contents : String? = "" var contents : String? = ""
@ -82,6 +96,7 @@ class BookPageInfo : RealmObject {
var bookTitle : String? = "" var bookTitle : String? = ""
var chapterNum : Int = 0 var chapterNum : Int = 0
var lastPage : Int? = 0 var lastPage : Int? = 0
@PrimaryKey @PrimaryKey
var pathUrl : String? = "" var pathUrl : String? = ""

View File

@ -5,14 +5,17 @@ import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.mime.dualscreenview.data.model.BookPageInfo
object DefaultList { object DefaultList {
fun showDefaultList(context: Context,title : String, items : Collection<String>, firstPosition : Int, choosedTitle : (Int)->String, chooedPositive : (Int)->Unit, saveCalback : (Int)->Unit ) { fun showDefaultList(context: Context, title : String, items : Collection<BookPageInfo>, firstPosition : Int, choosedTitle : (Int)->String, chooedPositive : (Int)->Unit, saveCalback : (Int)->Unit ) {
val builderSingle: AlertDialog.Builder = AlertDialog.Builder(context) val builderSingle: AlertDialog.Builder = AlertDialog.Builder(context)
builderSingle.setTitle(title) builderSingle.setTitle(title)
val arrayAdapter = val arrayAdapter =
ArrayAdapter<String>(context, R.layout.select_dialog_singlechoice) ArrayAdapter<String>(context, R.layout.select_dialog_singlechoice)
arrayAdapter.addAll(items) for (item in items) {
arrayAdapter.add(item.getTitleItem())
}
builderSingle.setNeutralButton("전체 저장") { dialog, which -> builderSingle.setNeutralButton("전체 저장") { dialog, which ->
saveCalback.invoke(-1) saveCalback.invoke(-1)
dialog.dismiss() dialog.dismiss()

View File

@ -173,7 +173,12 @@ open class BaseWebContentsViewer {
override fun onPageFinished(view: WebView?, url: String?) { override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url) super.onPageFinished(view, url)
view?.let { view?.let {
if(url?.contains("/list/") ?: false){
if(url?.contains("/list/") ?: false && url?.contains("agit") ?: false){
findListItem {
Blog.LOGE("onPageFinished", url ?: "")
}
} else if (url?.contains("booktoki") ?: false){
findListItem { findListItem {
Blog.LOGE("onPageFinished", url ?: "") Blog.LOGE("onPageFinished", url ?: "")
} }

View File

@ -4,10 +4,10 @@ import com.mime.dualscreenview.webcontents.contentsinfo.Agit
import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki
object WebContentsManger { object WebContentsManger {
val allContentsList : ArrayList<BaseWebContents> = arrayListOf(Agit) val allContentsList : ArrayList<BaseWebContents> = arrayListOf(Booktoki)
fun getBaseWebContentsBy(name : String) : BaseWebContents { fun getBaseWebContentsBy(name : String) : BaseWebContents {
var correctContents : BaseWebContents = Agit var correctContents : BaseWebContents = Booktoki
for (contents in allContentsList) { for (contents in allContentsList) {
if(name.equals(contents.getWebcontentsName())) { if(name.equals(contents.getWebcontentsName())) {
correctContents = contents correctContents = contents

View File

@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
object Booktoki : BaseWebContents() { object Booktoki : BaseWebContents() {
override var lastNumber : Int = 283 override var lastNumber : Int = 347
override fun getWebcontentsName(): String { override fun getWebcontentsName(): String {
return "Booktoki" return "Booktoki"
@ -15,19 +15,46 @@ object Booktoki : BaseWebContents() {
} }
override fun getContentsList(): String { override fun getContentsList(): String {
return "" + return "function getList() {\n" +
"function getList() {\n" + " const contentsArray = [];\n" +
"\t\t\t var children = document.getElementsByName('wr_id')[0].children;\n" + " var children = document.getElementsByClassName('list-body')[0].children;\n" +
" var maxCount = children.length\n" + " var maxCount = children.length;\n" +
" const contentsArray = []\n" +
" for (i= 0; i < maxCount; i++) {\n" + " for (i= 0; i < maxCount; i++) {\n" +
" contentsArray.push({'title' : children[i].text ,\n" + " var chapterNum = children[i].getElementsByClassName('wr-num')[0].textContent;\n" +
" 'link' : children[i].value})\n" + " var pageUrl = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].href;\n" +
" if (pageUrl != null && pageUrl.length > 0 && pageUrl.startsWith(\"http\")) {\n" +
" pageUrl = new URL(pageUrl).pathname;\n" +
" }\n" +
" var chapterTitle = children[i].getElementsByClassName('wr-subject')[0].getElementsByTagName('a')[0].innerText;\n" +
" if(chapterTitle.split('\\n').length > 1) {\n" +
" chapterTitle = chapterTitle.split('\\n')[1];\n" +
" }\n" +
"\n" +
" var bookPageUrl = location.pathname;\n" +
" var bookTitle = document.getElementsByClassName('view-title')[0].getElementsByTagName('span')[0].innerText;\n" +
" var data = {\n" +
" 'chapterID': Number(chapterNum),\n" +
" 'chapterNum': Number(chapterNum),\n" +
" 'pathUrl': pageUrl,\n" +
" 'bookPageUrl': bookPageUrl,\n" +
" 'chapterTitle': chapterTitle,\n" +
" 'bookTitle': bookTitle,\n" +
" };\n" +
" contentsArray.push(\n" +
" data\n" +
" );\n" +
" }\n" +
" \n" +
" if(contentsArray.length > 0) {\n" +
" PAgit.onBookInfo(JSON.stringify({\n" +
" 'bookTitle': bookTitle,\n" +
" 'bookPageUrl': new URL(location.href).pathname,\n" +
" 'pages': contentsArray ,\n" +
" }));\n" +
" }\n" + " }\n" +
" contentsArray.reverse() \n" +
"return {'list' :contentsArray}\n" +
"}\n" + "}\n" +
"getList()\n" "getList()\n" +
""
} }
override fun acccceptResourceKeyword(): String { override fun acccceptResourceKeyword(): String {

View File

@ -0,0 +1,18 @@
function getList() {
var children = document.getElementsByClassName('list-body')[0].children
var maxCount = children.length
const contentsArray = []
for (i= 0; i < maxCount; i++) {
children[i].getElementsByClassName('wr-num')
contentsArray.push(
{
'title' : children[i].text ,
'link' : children[i].value
}
)
}
contentsArray.reverse()
return {'list' :contentsArray}
}
getList()