다시 토끼로...
This commit is contained in:
parent
ceb22bcbcb
commit
f107c7c84d
@ -46,6 +46,7 @@ import com.mime.dualscreenview.view.TouchArea
|
||||
import com.mime.dualscreenview.webcontents.BaseWebContentsViewer
|
||||
import com.mime.dualscreenview.webcontents.MainControllInterface
|
||||
import com.mime.dualscreenview.webcontents.contentsinfo.Agit
|
||||
import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki
|
||||
import com.mime.dualscreenview.webcontents.contentsinfo.GotoSomeWhere
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import io.realm.kotlin.ext.copyFromRealm
|
||||
@ -143,7 +144,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
|
||||
findViewById<View>(R.id.btn_home).setOnClickListener { v->
|
||||
paged_layer?.visibility = GONE
|
||||
mBaseWebContentsViewer.loadContents(Agit)
|
||||
mBaseWebContentsViewer.loadContents(Booktoki)
|
||||
}
|
||||
|
||||
loadLastInfo()
|
||||
@ -175,31 +176,48 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.pages}")
|
||||
// realm.createObjectFromJson
|
||||
Blog.LOGE("onBookInfos" , "onBookInfos 2 - 1 >> ${infosj?.getR()}")
|
||||
infos = infosj?.getR()
|
||||
if (infos != null) {
|
||||
infos = copyToRealm(infos!!, UpdatePolicy.ALL)
|
||||
for (item in infosj.pages) {
|
||||
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}")
|
||||
}
|
||||
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()
|
||||
if (infos != null) {
|
||||
infos = copyToRealm(infos!!, UpdatePolicy.ALL)
|
||||
for (item in infosj.pages) {
|
||||
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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (infos != null) {
|
||||
infos = this.copyFromRealm(infos!!)
|
||||
}
|
||||
} catch (e :Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
realm.close()
|
||||
infos?.let {
|
||||
Blog.LOGE("onBookInfos" , "onBookInfos it >> ${it}")
|
||||
runOnUiThread {
|
||||
showList(it)
|
||||
infos?.bookPageUrl?.let {
|
||||
HistoryManager.getBooInfo(it){
|
||||
it?.let {
|
||||
Blog.LOGE("onBookInfos" , "onBookInfos it >> ${it}")
|
||||
runOnUiThread {
|
||||
showList(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun reloadTo(lastInfo: LastInfo?) {
|
||||
@ -207,7 +225,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
if (lastInfo != null) {
|
||||
mBaseWebContentsViewer.loadLastInfo(lastInfo!!)
|
||||
} else {
|
||||
mBaseWebContentsViewer.loadContents(Agit)
|
||||
mBaseWebContentsViewer.loadContents(Booktoki)
|
||||
}
|
||||
},200L)
|
||||
}
|
||||
@ -245,8 +263,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
arrayAdapter.addAll(item.title)
|
||||
}
|
||||
|
||||
|
||||
|
||||
builderSingle.setNegativeButton("cancel",
|
||||
DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() })
|
||||
|
||||
@ -293,17 +309,23 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
|
||||
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(
|
||||
this@Intro,
|
||||
"현제는 ${currentTitle} - ${(infos.pages.size ?: 0) - currentChapter} -> 다른화를 골라",
|
||||
infos.getTitleArray(),
|
||||
items,
|
||||
currentChapter,
|
||||
{ position ->
|
||||
return@showDefaultList infos.pages?.get(position)?.chapterTitle ?: ""
|
||||
return@showDefaultList items?.get(position)?.chapterTitle ?: ""
|
||||
},
|
||||
{ position ->
|
||||
infos.pages?.get(position)?.let { moveTo(it) }
|
||||
items?.get(position)?.let { moveTo(it) }
|
||||
}, { state ->
|
||||
if (state < 0 ) {
|
||||
saveItem(infos)
|
||||
@ -325,7 +347,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
Blog.LOGE("ramdomTime >>> ${ramdomTimeSec}")
|
||||
webView?.postDelayed( {
|
||||
Blog.LOGE("saveClient >>> ${isLoading} ${url}")
|
||||
var findContents = Agit.getFindContentsJs()
|
||||
var findContents = Booktoki.getFindContentsJs()
|
||||
Blog.LOGE("saveClient find >>> ${findContents}")
|
||||
Random(System.currentTimeMillis()).nextLong().rem(999)
|
||||
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!!))
|
||||
paged_layer?.visibility = GONE
|
||||
} else {
|
||||
Blog.LOGE("HistoryManager.getNextPage(${Agit.getLastedDoamin()})")
|
||||
mBaseWebContentsViewer.webview.loadUrl(Agit.getLastedDoamin() + it?.pathUrl!!)
|
||||
Blog.LOGE("HistoryManager.getNextPage(${Booktoki.getLastedDoamin()})")
|
||||
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
|
||||
paged_layer?.visibility = GONE
|
||||
}
|
||||
it?.pathUrl?.let {
|
||||
@ -512,7 +534,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
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(Agit.getLastedDoamin() + it?.pathUrl!!)
|
||||
mBaseWebContentsViewer.webview.loadUrl(Booktoki.getLastedDoamin() + it?.pathUrl!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,12 +58,25 @@ 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) {
|
||||
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))
|
||||
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)
|
||||
}
|
||||
}
|
||||
}?.close()
|
||||
@ -94,7 +107,7 @@ object HistoryManager {
|
||||
if (bookPageInfo != null) {
|
||||
Blog.LOGE("getNextPage 2 ${bookPageInfo.chapterNum}" )
|
||||
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) {
|
||||
results.first()?.let {
|
||||
Blog.LOGE("getNextPage 2 ${it.pathUrl}" )
|
||||
@ -111,11 +124,11 @@ object HistoryManager {
|
||||
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("getNextPage ${bookPageInfo}" )
|
||||
Blog.LOGE("getPrevPage ${bookPageInfo}" )
|
||||
if (bookPageInfo != null) {
|
||||
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()
|
||||
Blog.LOGE("getPrevPage 2 ${bookPageInfo.chapterNum}" )
|
||||
Blog.LOGE("getPrevPage 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 {
|
||||
callback.invoke(it)
|
||||
|
||||
@ -5,6 +5,7 @@ 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.PrimaryKey
|
||||
|
||||
|
||||
@ -63,17 +64,30 @@ class BookPageInfos : RealmObject {
|
||||
var pages : RealmList<BookPageInfo> = realmListOf()
|
||||
fun getTitleArray() : ArrayList<String> {
|
||||
var arrayList = ArrayList<String>()
|
||||
|
||||
pages?.forEach {
|
||||
// Blog.LOGE("chapterTitle >> ${it.getTitleItem()} ")
|
||||
arrayList.add(it.getTitleItem())}
|
||||
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 {
|
||||
|
||||
var chapterID : Int = 0
|
||||
var contents : String? = ""
|
||||
|
||||
@ -82,6 +96,7 @@ class BookPageInfo : RealmObject {
|
||||
var bookTitle : String? = ""
|
||||
var chapterNum : Int = 0
|
||||
var lastPage : Int? = 0
|
||||
|
||||
@PrimaryKey
|
||||
var pathUrl : String? = ""
|
||||
|
||||
|
||||
@ -5,14 +5,17 @@ import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.mime.dualscreenview.data.model.BookPageInfo
|
||||
|
||||
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)
|
||||
builderSingle.setTitle(title)
|
||||
val arrayAdapter =
|
||||
ArrayAdapter<String>(context, R.layout.select_dialog_singlechoice)
|
||||
arrayAdapter.addAll(items)
|
||||
for (item in items) {
|
||||
arrayAdapter.add(item.getTitleItem())
|
||||
}
|
||||
builderSingle.setNeutralButton("전체 저장") { dialog, which ->
|
||||
saveCalback.invoke(-1)
|
||||
dialog.dismiss()
|
||||
|
||||
@ -173,10 +173,15 @@ open class BaseWebContentsViewer {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
super.onPageFinished(view, url)
|
||||
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 {
|
||||
Blog.LOGE("onPageFinished", url ?: "")
|
||||
}
|
||||
}
|
||||
currentContentsProvider?.doOnloaded(it , { result ->
|
||||
result?.let { mainControllInterface.onLoadedContents(it) }
|
||||
|
||||
@ -4,10 +4,10 @@ import com.mime.dualscreenview.webcontents.contentsinfo.Agit
|
||||
import com.mime.dualscreenview.webcontents.contentsinfo.Booktoki
|
||||
|
||||
object WebContentsManger {
|
||||
val allContentsList : ArrayList<BaseWebContents> = arrayListOf(Agit)
|
||||
val allContentsList : ArrayList<BaseWebContents> = arrayListOf(Booktoki)
|
||||
|
||||
fun getBaseWebContentsBy(name : String) : BaseWebContents {
|
||||
var correctContents : BaseWebContents = Agit
|
||||
var correctContents : BaseWebContents = Booktoki
|
||||
for (contents in allContentsList) {
|
||||
if(name.equals(contents.getWebcontentsName())) {
|
||||
correctContents = contents
|
||||
|
||||
@ -4,7 +4,7 @@ import com.mime.dualscreenview.webcontents.BaseWebContents
|
||||
|
||||
object Booktoki : BaseWebContents() {
|
||||
|
||||
override var lastNumber : Int = 283
|
||||
override var lastNumber : Int = 347
|
||||
|
||||
override fun getWebcontentsName(): String {
|
||||
return "Booktoki"
|
||||
@ -15,19 +15,46 @@ object Booktoki : BaseWebContents() {
|
||||
}
|
||||
|
||||
override fun getContentsList(): String {
|
||||
return "" +
|
||||
"function getList() {\n" +
|
||||
"\t\t\t var children = document.getElementsByName('wr_id')[0].children;\n" +
|
||||
" var maxCount = children.length\n" +
|
||||
" const contentsArray = []\n" +
|
||||
" for (i= 0; i < maxCount; i++) {\n" +
|
||||
" contentsArray.push({'title' : children[i].text ,\n" +
|
||||
" 'link' : children[i].value})\n" +
|
||||
" }\n" +
|
||||
" contentsArray.reverse() \n" +
|
||||
"return {'list' :contentsArray}\n" +
|
||||
return "function getList() {\n" +
|
||||
" const contentsArray = [];\n" +
|
||||
" var children = document.getElementsByClassName('list-body')[0].children;\n" +
|
||||
" var maxCount = children.length;\n" +
|
||||
" for (i= 0; i < maxCount; i++) {\n" +
|
||||
" var chapterNum = children[i].getElementsByClassName('wr-num')[0].textContent;\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" +
|
||||
"getList()\n"
|
||||
"getList()\n" +
|
||||
""
|
||||
}
|
||||
|
||||
override fun acccceptResourceKeyword(): String {
|
||||
|
||||
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user