...
This commit is contained in:
parent
63ebcab28d
commit
271e0c66dc
@ -10,6 +10,8 @@ import android.hardware.display.DisplayManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
@ -26,12 +28,14 @@ import com.google.gson.Gson
|
||||
import com.lge.display.DisplayManagerHelper
|
||||
import com.mime.dualscreenview.R
|
||||
import com.mime.dualscreenview.common.Blog
|
||||
import com.mime.dualscreenview.data.HistoryManager
|
||||
import com.mime.dualscreenview.dialog.StyleSelectInterface
|
||||
import com.mime.dualscreenview.dialog.Stylez
|
||||
import com.mime.dualscreenview.data.model.BookPageInfo
|
||||
import com.mime.dualscreenview.data.model.BookPageInfos
|
||||
import com.mime.dualscreenview.data.model.HistoryItem
|
||||
import com.mime.dualscreenview.data.model.LastInfo
|
||||
import com.mime.dualscreenview.data.model.ReaderConfig
|
||||
import com.mime.dualscreenview.dialog.DefaultList
|
||||
import com.mime.dualscreenview.view.PagedTextLayout
|
||||
import com.mime.dualscreenview.view.PagedTextViewInterface
|
||||
@ -43,6 +47,7 @@ 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.android.synthetic.main.intro.paged_layer
|
||||
import java.lang.System.currentTimeMillis
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@ -63,7 +68,25 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
private lateinit var mBaseWebContentsViewer : BaseWebContentsViewer
|
||||
var lastInfo : LastInfo? = null
|
||||
|
||||
val handle = object : Handler() {
|
||||
override fun handleMessage(msg: Message) {
|
||||
// super.handleMessage(msg)
|
||||
if (msg.what == 0 ) {
|
||||
(msg.obj as? ReaderConfig)?.let {
|
||||
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)
|
||||
paged_layer?.forceUpdateUI()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
@ -122,8 +145,11 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
|
||||
|
||||
|
||||
findViewById<View>(R.id.btn_home).setOnClickListener { v->
|
||||
pagedTextLayout?.visibility = GONE
|
||||
paged_layer?.visibility = GONE
|
||||
mBaseWebContentsViewer.loadContents(Booktoki)
|
||||
}
|
||||
|
||||
@ -153,7 +179,18 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
var realm = HistoryManager.openRealm()
|
||||
realm.query<ReaderConfig>()?.find()?.let {
|
||||
if (it.size > 0) {
|
||||
realm.copyFromRealm(it.first())?.let {
|
||||
var msg = handle.obtainMessage()
|
||||
msg.what = 0
|
||||
msg.obj = it
|
||||
handle.sendMessageDelayed(msg, 200)
|
||||
}
|
||||
}
|
||||
}
|
||||
realm.close()
|
||||
reloadLastInfo()
|
||||
reloadTo(lastInfo)
|
||||
}
|
||||
@ -247,7 +284,7 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
var mStylez = Stylez(this@Intro)
|
||||
mStylez.styleSelectInterface = object : StyleSelectInterface {
|
||||
override fun onSelectStyle(bgColor: String, textColor: String) {
|
||||
pagedTextLayout?.setColorStyle(arrayOf(textColor,bgColor))
|
||||
paged_layer?.setColorStyle(arrayOf(textColor,bgColor))
|
||||
}
|
||||
}
|
||||
mStylez.show()
|
||||
@ -372,7 +409,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
var pagedTextLayout : PagedTextLayout? = null;
|
||||
|
||||
var onNextClickAction: GotoSomeWhere? = null
|
||||
override fun showNextBtn(find : Boolean , onClickAction: GotoSomeWhere) {
|
||||
@ -387,9 +423,9 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
|
||||
fun actionNextEvent() {
|
||||
if (pagedTextLayout != null && pagedTextLayout!!.visibility == View.VISIBLE && pagedTextLayout!!.size() > 0 && (pagedTextLayout!!.current() < pagedTextLayout!!.size() - 1) ) {
|
||||
pagedTextLayout!!.doNext()
|
||||
updateLastInfo(pagedTextLayout!!)
|
||||
if (paged_layer != null && paged_layer!!.visibility == View.VISIBLE && paged_layer!!.size() > 0 && (paged_layer!!.current() < paged_layer!!.size() - 1) ) {
|
||||
paged_layer!!.doNext()
|
||||
updateLastInfo(paged_layer!!)
|
||||
}else {
|
||||
onNextClickAction?.let { it() }
|
||||
}
|
||||
@ -409,9 +445,9 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
|
||||
|
||||
fun actionPrevEvent() {
|
||||
if (pagedTextLayout != null && pagedTextLayout!!.visibility == View.VISIBLE && pagedTextLayout!!.size() > 0 && pagedTextLayout!!.current() > 0 ) {
|
||||
pagedTextLayout!!.doPrev()
|
||||
updateLastInfo(pagedTextLayout!!)
|
||||
if (paged_layer != null && paged_layer!!.visibility == View.VISIBLE && paged_layer!!.size() > 0 && paged_layer!!.current() > 0 ) {
|
||||
paged_layer!!.doPrev()
|
||||
updateLastInfo(paged_layer!!)
|
||||
} else {
|
||||
onPrevClickAction?.let{ it() }
|
||||
}
|
||||
@ -451,19 +487,36 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
}
|
||||
|
||||
override fun onLoadedContents(contents: String) {
|
||||
pagedTextLayout = null;
|
||||
findViewById<PagedTextLayout>(R.id.paged_layer).apply {
|
||||
paged_layer.apply {
|
||||
if (contents != null) {
|
||||
pagedTextLayout = this
|
||||
visibility = VISIBLE
|
||||
mPagedTextViewInterface = this@Intro
|
||||
var realm = HistoryManager.openRealm()
|
||||
realm.query<ReaderConfig>()?.find()?.let {
|
||||
if (it.size > 0) {
|
||||
realm.copyFromRealm(it.first())?.let {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
realm.close()
|
||||
|
||||
|
||||
|
||||
|
||||
setText(contents.replace("\\n", System.getProperty("line.separator")))
|
||||
setTextSize(22f)
|
||||
if(lastInfo != null && lastInfo!!.pageUrl.equals(mBaseWebContentsViewer.webview.url)) {
|
||||
this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = VISIBLE
|
||||
pagedTextLayout?.postDelayed({
|
||||
paged_layer?.postDelayed({
|
||||
next(lastInfo!!.pageIndex)
|
||||
pagedTextLayout?.post {
|
||||
paged_layer?.post {
|
||||
this@Intro.findViewById<ProgressBar>(R.id.progress)?.visibility = GONE
|
||||
}
|
||||
},1000)
|
||||
@ -471,7 +524,6 @@ class Intro : Base() , MainControllInterface, PagedTextViewInterface {
|
||||
forceUpdateUI()
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG,"onLoadedContents >> " + contents)
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ package com.mime.dualscreenview.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import com.mime.dualscreenview.R
|
||||
import com.mime.dualscreenview.data.HistoryManager
|
||||
import com.mime.dualscreenview.data.model.ReaderConfig
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import io.realm.kotlin.ext.query
|
||||
import kotlinx.android.synthetic.main.settings.letter_space
|
||||
import kotlinx.android.synthetic.main.settings.line_space
|
||||
import kotlinx.android.synthetic.main.settings.page_padding
|
||||
@ -10,27 +14,77 @@ import kotlinx.android.synthetic.main.settings.text_size
|
||||
|
||||
class Settings : Base() {
|
||||
|
||||
var readerConfig : ReaderConfig? = null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.settings)
|
||||
text_size.displayFormat = "글자 크기 : %d"
|
||||
text_size.mValueChange = { preview.textSize = it.toFloat() }
|
||||
text_size.value = 14
|
||||
page_padding.displayFormat = "페이지 여백 : %d"
|
||||
page_padding.mValueChange = { preview.setPadding(it,it,it,it) }
|
||||
page_padding.value = 5
|
||||
letter_space.displayFormat = "자간 : %d"
|
||||
letter_space.mValueChange = { preview.letterSpacing = it.times(0.01).toFloat() }
|
||||
letter_space.value = 1
|
||||
line_space.displayFormat = "행간 : %d"
|
||||
line_space.mValueChange = { preview.setLineSpacing(1f, 1f.plus(it.times(0.01f))) }
|
||||
line_space.value = 1
|
||||
var realm = HistoryManager.openRealm()
|
||||
realm.writeBlocking {
|
||||
this.query<ReaderConfig>()?.find()?.let {
|
||||
if (it.size > 0) {
|
||||
readerConfig = copyFromRealm(it.first())
|
||||
} else {
|
||||
readerConfig = ReaderConfig()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
text_size.displayFormat = "글자 크기 : %d"
|
||||
text_size.value = readerConfig?.textSize ?: 14
|
||||
text_size.mValueChange = {
|
||||
preview.textSize = it.toFloat() ;
|
||||
if (readerConfig?.textSize != it) {
|
||||
readerConfig?.textSize = it
|
||||
configSave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
page_padding.displayFormat = "페이지 여백 : %d"
|
||||
page_padding.value = readerConfig?.padding ?: 5
|
||||
page_padding.mValueChange = {
|
||||
preview.setPadding(it,it,it,it) ;
|
||||
if (readerConfig?.padding != it) {
|
||||
readerConfig?.padding = it
|
||||
configSave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
letter_space.displayFormat = "자간 : %d"
|
||||
letter_space.value = readerConfig?.letterSpace ?: 1
|
||||
letter_space.mValueChange = {
|
||||
preview.letterSpacing = it.times(0.01).toFloat() ;
|
||||
if (readerConfig?.letterSpace != it) {
|
||||
readerConfig?.letterSpace = it
|
||||
configSave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
line_space.displayFormat = "행간 : %d"
|
||||
line_space.value = readerConfig?.lineSpace ?: 1
|
||||
line_space.mValueChange = {
|
||||
preview.setLineSpacing(1f, 1f.plus(it.times(0.01f))) ;
|
||||
if (readerConfig?.lineSpace != it) {
|
||||
readerConfig?.lineSpace = it
|
||||
configSave()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun configSave() {
|
||||
var realm = HistoryManager.openRealm()
|
||||
realm.writeBlocking {
|
||||
copyToRealm(readerConfig!!, UpdatePolicy.ALL)
|
||||
}
|
||||
realm.close()
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@ object HistoryManager {
|
||||
val schemaVersion : Long = 1
|
||||
|
||||
fun openRealm() : Realm = Realm.open(RealmConfiguration.Builder(clazz)
|
||||
.schemaVersion(1)
|
||||
.schemaVersion(2)
|
||||
.build())
|
||||
|
||||
fun save(lastInfo: LastInfo) {
|
||||
@ -38,4 +38,12 @@ object HistoryManager {
|
||||
|
||||
}?.close()
|
||||
}
|
||||
|
||||
fun save(config : ReaderConfig) {
|
||||
openRealm()?.apply{
|
||||
this.writeBlocking {
|
||||
copyToRealm(config,UpdatePolicy.ALL)
|
||||
}
|
||||
}?.close()
|
||||
}
|
||||
}
|
||||
@ -5,11 +5,12 @@ import io.realm.kotlin.types.annotations.PrimaryKey
|
||||
|
||||
class ReaderConfig() : RealmObject {
|
||||
@PrimaryKey
|
||||
var id : String? = ""
|
||||
var id : String? = "ReaderConfig"
|
||||
var textSize : Int? = 14
|
||||
var textColor : String? = "#FFFFFF"
|
||||
var bgColor : String? = "#000000"
|
||||
var lineSpace : Int? = 0
|
||||
var letterSpace : Int? = 0
|
||||
var lineSpace : Int? = 1
|
||||
var letterSpace : Int? = 1
|
||||
var font : String? = ""
|
||||
var padding : Int? = 5
|
||||
}
|
||||
@ -1,7 +1,10 @@
|
||||
package com.mime.dualscreenview.view
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
@ -167,11 +170,36 @@ class PagedTextLayout : ConstraintLayout , PagedTextGenerateInterface {
|
||||
}
|
||||
|
||||
fun forceUpdateUI() {
|
||||
mPagedTextViewInterface?.onTouch(TouchArea.Center)
|
||||
// mPagedTextViewInterface?.onTouch(TouchArea.Center)
|
||||
hiddenTextView?.doUpdate()
|
||||
hanler?.postDelayed(touchTimeover, 3000L)
|
||||
// hanler?.postDelayed(touchTimeover, 3000L)
|
||||
}
|
||||
|
||||
override fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
|
||||
hiddenTextView?.setPadding(left,top,right, bottom)
|
||||
mainTextView?.setPadding(left,top,right, bottom)
|
||||
sencondTextView?.setPadding(left,top,right, bottom)
|
||||
}
|
||||
|
||||
|
||||
fun setTypeface(tf: Typeface?) {
|
||||
hiddenTextView?.setTypeface(tf)
|
||||
mainTextView?.setTypeface(tf)
|
||||
sencondTextView?.setTypeface(tf)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
fun setLetterSpacing(letterSpacing: Float) {
|
||||
hiddenTextView?.letterSpacing = letterSpacing.times(0.01f)
|
||||
mainTextView?.letterSpacing = letterSpacing.times(0.01f)
|
||||
sencondTextView?.letterSpacing = letterSpacing.times(0.01f)
|
||||
}
|
||||
|
||||
|
||||
fun setLineSpacing(mult: Float) {
|
||||
hiddenTextView?.setLineSpacing(1f, 1f.plus(mult.times(0.01f)))
|
||||
mainTextView?.setLineSpacing(1f, 1f.plus(mult.times(0.01f)))
|
||||
sencondTextView?.setLineSpacing(1f, 1f.plus(mult.times(0.01f)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,26 +29,26 @@ class StepsEditor : ConstraintLayout {
|
||||
|
||||
var value : Int = 14
|
||||
set(newValue) {
|
||||
text_value.text = displayFormat.format(newValue)
|
||||
mValueChange?.invoke(newValue)
|
||||
field = newValue
|
||||
text_value.text = displayFormat.format(field)
|
||||
mValueChange?.invoke(field)
|
||||
}
|
||||
var displayFormat = "글자 크기 : %d"
|
||||
set(newValue) {
|
||||
field = newValue
|
||||
try {
|
||||
text_value.text = displayFormat.format(value)
|
||||
} catch (e : Exception) {
|
||||
|
||||
}
|
||||
field = newValue
|
||||
}
|
||||
|
||||
var mValueChange : ValueChange? = null
|
||||
set(newValue) {
|
||||
field = newValue
|
||||
if (newValue != null) {
|
||||
newValue(value)
|
||||
}
|
||||
field = newValue
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user