Skip to content

Commit

Permalink
1.替换繁简转换jar包
Browse files Browse the repository at this point in the history
2.优化包体积。
  • Loading branch information
390057892 committed Apr 25, 2021
1 parent 2dd625a commit 0d4eb3c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 45 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ dependencies {
implementation 'io.noties.markwon:core:4.6.0'
implementation 'io.noties.markwon:image-glide:4.6.0'
//转换繁体
implementation 'com.hankcs:hanlp:portable-1.7.8'

implementation files('libs/ZHConverter.jar')
//brvah
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6'

Expand Down
Binary file added app/libs/ZHConverter.jar
Binary file not shown.
9 changes: 1 addition & 8 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@
public static ** valueOf(java.lang.String);
}


-keep class com.burst.k17reader_sdk.** { *; }
-keep class com.chineseall.reader.utils.** { *; }

-keep class org.litepal.** { *;}
-keep class * extends org.litepal.crud.DataSupport { *;}
-keep class * extends org.litepal.crud.LitePalSupport { *;}
Expand All @@ -230,7 +226,4 @@
public static ** valueOf(java.lang.String);
}

-dontwarn com.youth.banner.**
-keep class com.youth.banner.**{*;}

-keep class com.android.vending.billing.**
-keep class com.spreada.utils.chinese.**
15 changes: 15 additions & 0 deletions app/src/main/java/com/novel/read/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication
import com.bumptech.glide.Glide
import com.jeremyliao.liveeventbus.LiveEventBus
import com.novel.read.constant.AppConst.channelIdDownload
import com.novel.read.constant.AppConst.channelIdReadAloud
Expand Down Expand Up @@ -120,4 +121,18 @@ class App : MultiDexApplication() {
}
}


override fun onLowMemory() {
super.onLowMemory()
Glide.get(this).clearMemory()
}

override fun onTrimMemory(level: Int) {
super.onTrimMemory(level)
if (level == TRIM_MEMORY_UI_HIDDEN) {
Glide.get(this).clearMemory()
}
Glide.get(this).trimMemory(level)
}

}
1 change: 0 additions & 1 deletion app/src/main/java/com/novel/read/constant/PreferKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object PreferKey {
const val ttsSpeechRate = "ttsSpeechRate"
const val prevKeys = "prevKeyCodes"
const val nextKeys = "nextKeyCodes"
const val showRss = "showRss"
const val bookshelfLayout = "bookshelfLayout"
const val bookshelfSort = "bookshelfSort"
const val recordLog = "recordLog"
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/novel/read/help/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ object AppConfig {
}
}

val autoRefreshBook: Boolean
get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh)

var threadCount: Int
get() = App.INSTANCE.getPrefInt(PreferKey.threadCount, 16)
set(value) {
Expand All @@ -83,7 +80,7 @@ object AppConfig {
val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false)

var chineseConverterType: Int
get() = App.INSTANCE.getPrefInt(PreferKey.chineseConverterType,2)
get() = App.INSTANCE.getPrefInt(PreferKey.chineseConverterType,1)
set(value) {
App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value)
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/novel/read/help/BookHelp.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.novel.read.help

import android.util.Log
import com.hankcs.hanlp.HanLP
import com.novel.read.App
import com.novel.read.constant.AppPattern
import com.novel.read.constant.EventBus
Expand All @@ -14,6 +13,7 @@ import com.novel.read.utils.ext.*
import com.novel.read.help.coroutine.Coroutine
import com.novel.read.network.repository.ImageRepository
import com.novel.read.utils.NetworkUtils
import com.spreada.utils.chinese.ZHConverter
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -367,12 +367,12 @@ object BookHelp {
try {
when (AppConfig.chineseConverterType) {
1 -> {
title1 = HanLP.convertToSimplifiedChinese(title1)
content1 = HanLP.convertToSimplifiedChinese(content1)
title1=ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(title1)
content1=ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(content1)
}
2 -> {
title1 = HanLP.convertToTraditionalChinese(title1)
content1 = HanLP.convertToTraditionalChinese(content1)
title1=ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(title1)
content1=ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(content1)
}
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.novel.read.network.repository

import com.hankcs.hanlp.HanLP
import com.novel.read.network.ServiceCreator
import com.novel.read.utils.ext.GSON
import com.spreada.utils.chinese.ZHConverter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.MediaType
Expand All @@ -14,7 +14,7 @@ class SearchRepository {

suspend fun searchBook(page: Int, pageSize: Int, key: String) = withContext(Dispatchers.IO) {
val map = HashMap<String, String>()
val key1 = HanLP.convertToSimplifiedChinese(key)
val key1 = ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(key)
map["pageNum"] = page.toString()
map["pageSize"] = pageSize.toString()
map["searchTerms"] = key1
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/novel/read/service/help/ReadBook.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.novel.read.service.help

import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP
import com.novel.read.App
import com.novel.read.constant.AppConst
import com.novel.read.constant.BookType
import com.novel.read.data.db.entity.Book
import com.novel.read.data.db.entity.BookChapter
Expand All @@ -16,6 +14,7 @@ import com.novel.read.help.IntentDataHelp
import com.novel.read.help.ReadBookConfig
import com.novel.read.service.BaseReadAloudService
import com.novel.read.help.coroutine.Coroutine
import com.spreada.utils.chinese.ZHConverter
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider
import kotlinx.coroutines.Dispatchers
Expand All @@ -25,7 +24,6 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast


object ReadBook {
var titleDate = MutableLiveData<String>()
var book: Book? = null
Expand Down Expand Up @@ -354,8 +352,8 @@ object ReadBook {
Coroutine.async {
if (chapter.chapterIndex in durChapterIndex - 1..durChapterIndex + 1) {
chapter.chapterName = when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese(chapter.chapterName)
2 -> HanLP.convertToTraditionalChinese(chapter.chapterName)
1 -> ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(chapter.chapterName)
2 -> ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(chapter.chapterName)
else -> chapter.chapterName
}
val contents = BookHelp.disposeContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import com.novel.read.network.repository.HomeRepository

class MailViewModel(application: Application) : BaseViewModel(application) {
private val homeRepository by lazy { HomeRepository() }

var homeResp = MutableLiveData<HomeResp>()
val refreshStatus = MutableLiveData<Int>()

fun getAll() {
refreshStatus.value = AppConst.loading
launch(block = {
homeResp.value = homeRepository.getHomeBook(AppConst.home)
refreshStatus.value = AppConst.complete
}, error = {
refreshStatus.value = AppConst.error
},showErrorToast = false)
}, showErrorToast = false)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class OtherConfigFragment : BasePreferenceFragment(), CoroutineScope by MainScop

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "")
PreferKey.language -> {
val lg = sharedPreferences?.all?.get("language")
if (lg == "zh") {
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/novel/read/ui/welcome/WelcomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package com.novel.read.ui.welcome
import android.Manifest
import android.content.Intent
import android.os.Bundle
import com.hankcs.hanlp.HanLP
import com.permissionx.guolindev.PermissionX
import com.novel.read.R
import com.novel.read.base.BaseActivity
import com.novel.read.databinding.ActivityWelcomeBinding
import com.novel.read.help.AppConfig
import com.novel.read.ui.MainActivity
import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ext.getPrefBoolean
import com.novel.read.help.coroutine.Coroutine
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

Expand All @@ -33,15 +30,6 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
}

private fun init() {
Coroutine.async {
//初始化简繁转换引擎
when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese("初始化")
2 -> HanLP.convertToTraditionalChinese("初始化")
else -> null
}
}

PermissionX.init(this)
.permissions(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Expand All @@ -52,7 +40,6 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
binding.rootView.postDelayed({ startMainActivity() }, 2500)
} else {
toast("权限被拒绝,将导致部分功能异常,请到设置中开启相关权限")
// finish()
}
}

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/novel/read/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.novel.read.utils

import android.annotation.SuppressLint
import android.text.TextUtils.isEmpty
import com.hankcs.hanlp.HanLP
import android.util.Log
import com.novel.read.App
import com.novel.read.constant.PreferKey
import com.novel.read.help.AppConfig
import com.novel.read.utils.ext.getPrefInt
import com.novel.read.utils.ext.getPrefLong
import com.spreada.utils.chinese.ZHConverter
import java.text.DecimalFormat
import java.text.ParseException
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -340,10 +341,10 @@ object StringUtils {
fun convertCC(input: String?): String {
return when (AppConfig.chineseConverterType) {
1 -> {
HanLP.convertToSimplifiedChinese(input)
ZHConverter.getInstance(ZHConverter.SIMPLIFIED).convert(input)
}
2 -> {
HanLP.convertToTraditionalChinese(input)
ZHConverter.getInstance(ZHConverter.TRADITIONAL).convert(input)
}
else -> {
input!!
Expand Down

0 comments on commit 0d4eb3c

Please sign in to comment.