Skip to content

Commit

Permalink
v3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
15dd committed Dec 31, 2024
1 parent 8c27efb commit e20fc33
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 91 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = "com.cyh128.hikari_novel"
minSdk = 24
targetSdk = 35
versionCode = 241217
versionName = "3.3.3"
versionCode = 241231
versionName = "3.4.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -85,8 +85,8 @@ dependencies {
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.viewpager2:viewpager2:1.1.0")

implementation("androidx.navigation:navigation-fragment-ktx:2.8.4")
implementation("androidx.navigation:navigation-ui-ktx:2.8.4")
implementation("androidx.navigation:navigation-fragment-ktx:2.8.5")
implementation("androidx.navigation:navigation-ui-ktx:2.8.5")

//数据库
implementation("androidx.room:room-ktx:2.6.1")
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Binary file modified app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 241217,
"versionName": "3.3.3",
"versionCode": 241231,
"versionName": "3.4.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sealed class Event {
data object SearchInitErrorCauseByInFiveSecondEvent: Event() //初始化内容页面失败,因为5秒限制
data object LogInSuccessEvent: Event() //登录成功
data object LogInFailureEvent: Event() //登录失败
data object AuthFailedEvent: Event() //验证失败事件(用户名或者密码错误)
data object SignInSuccessEvent: Event() //签到成功
data object SignInFailureEvent: Event() //签到失败
data object TempSignInUnableEvent: Event() //临时签到不可用事件
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/cyh128/hikari_novel/data/model/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ data class ChapterContentResponse(
)

data class LoginResponse(
val isUsernameCorrect: Boolean,
val isPasswordCorrect: Boolean
var isUsernameCorrect: Boolean,
var isPasswordCorrect: Boolean,
var isLoginSuccessful: Boolean
) {
fun isCorrect() = isUsernameCorrect && isPasswordCorrect

companion object {
fun empty() = LoginResponse(
isUsernameCorrect = false,
isPasswordCorrect = false,
isLoginSuccessful = false
)
}
}

data class CommentResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class Wenku8Repository @Inject constructor(
return Result.failure(NetworkException(HttpCodeParser.parser(body.code())))
} else {
val html = String(body.body()!!.bytes(), Charset.forName("GBK"))
val checkResult = Wenku8Parser.isUsernameOrPasswordCorrect(html)
return Result.success(checkResult)
val response = LoginResponse.empty()
Wenku8Parser.isUsernameOrPasswordCorrect(html, response)
Wenku8Parser.isLoginSuccessful(html, response)
return Result.success(response)
}
}.onFailure {
return Result.failure(NetworkException(it.message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Network @Inject constructor() {
.add("appver", "1.18")
.add("request", Base64Helper.encodeBase64(request))
.add("timetoken", "${System.currentTimeMillis()}")
.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.70 Safari/537.36")
.toAwait<String>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class NovelInfoActivity : BaseActivity<ActivityNovelInfoBinding>() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding.tbANovelInfo.setNavigationOnClickListener { finish() }

WindowCompat.setDecorFitsSystemWindows(window, false)

receiveEvent<Event>("event_novel_info_activity") { event ->
when (event) {
Event.LoadSuccessEvent -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.cyh128.hikari_novel.base.BaseActivity
import com.cyh128.hikari_novel.data.model.Event
import com.cyh128.hikari_novel.databinding.ActivityLoginBinding
import com.cyh128.hikari_novel.ui.view.main.MainActivity
import com.cyh128.hikari_novel.ui.view.main.more.more.setting.SettingActivity
import com.cyh128.hikari_novel.util.ResourceUtil
import com.cyh128.hikari_novel.util.openUrl
import com.cyh128.hikari_novel.util.startActivity
import com.drake.channel.receiveEvent
Expand Down Expand Up @@ -70,16 +72,25 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
}
}

Event.LogInFailureEvent -> {
Event.AuthFailedEvent -> {
isEnableLoginButton(true)
clearError()
}

Event.LogInFailureEvent -> {
MaterialAlertDialogBuilder(this@LoginActivity)
.setTitle(R.string.login_failure)
.setIcon(R.drawable.ic_error)
.setMessage(ResourceUtil.getString(R.string.login_failed_tip_2))
.setPositiveButton(R.string.ok, null)
.show()
isEnableLoginButton(true)
}

is Event.NetworkErrorEvent -> {
MaterialAlertDialogBuilder(this@LoginActivity)
.setTitle(R.string.network_error)
.setIcon(R.drawable.ic_error)
.setTitle(R.string.network_error)
.setMessage(event.msg)
.setPositiveButton(R.string.ok, null)
.show()
Expand Down Expand Up @@ -136,25 +147,8 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
.show()
}

binding.bALoginDomain.setOnClickListener {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.switch_node)
.setIcon(R.drawable.ic_network_node)
.setNegativeButton(R.string.cancel, null)
.setSingleChoiceItems(
arrayOf("www.wenku8.cc", "www.wenku8.net"),
run {
if (viewModel.getWenku8Node() == "www.wenku8.cc") return@run 0
else return@run 1
}
) { dialog: DialogInterface, which: Int ->
when (which) {
0 -> viewModel.setWenku8Node("www.wenku8.cc")
1 -> viewModel.setWenku8Node("www.wenku8.net")
}
dialog.dismiss()
}
.show()
binding.bALoginSetting.setOnClickListener {
startActivity<SettingActivity>()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.cyh128.hikari_novel.ui.view.splash

import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.cyh128.hikari_novel.R
import com.cyh128.hikari_novel.base.BaseFragment
import com.cyh128.hikari_novel.databinding.FragmentLoginErrorBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.cyh128.hikari_novel.ui.view.main.more.more.setting.SettingActivity
import com.cyh128.hikari_novel.util.startActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -23,25 +23,8 @@ class LoginErrorFragment : BaseFragment<FragmentLoginErrorBinding>() {
}
binding.tvFLoginError.text = requireArguments().getString("msg")

binding.bFLoginErrorDomain.setOnClickListener {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.switch_node)
.setIcon(R.drawable.ic_network_node)
.setNegativeButton(R.string.cancel, null)
.setSingleChoiceItems(
arrayOf("www.wenku8.cc", "www.wenku8.net"),
run {
if (viewModel.getWenku8Node() == "www.wenku8.cc") return@run 0
else return@run 1
}
) { dialog: DialogInterface, which: Int ->
when (which) {
0 -> viewModel.setWenku8Node("www.wenku8.cc")
1 -> viewModel.setWenku8Node("www.wenku8.net")
}
dialog.dismiss()
}
.show()
binding.bFLoginErrorSetting.setOnClickListener {
startActivity<SettingActivity>()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class LoginViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
wenku8Repository.login(username, password)
.onSuccess { success ->
if (success.isCorrect()) {
if (success.isCorrect() && success.isLoginSuccessful) { //当密码正确时并且网页提示登录成功时
sendEvent(Event.LogInSuccessEvent,"event_login_activity")
} else {
} else if (!success.isCorrect() && !success.isLoginSuccessful) { //当密码不正确时并且网页没有提示登录成功时
sendEvent(Event.LogInFailureEvent, "event_login_activity")
} else if (!success.isCorrect()) { //当密码错误时
_isUsernameCorrect.postValue(success.isUsernameCorrect)
_isPasswordCorrect.postValue(success.isPasswordCorrect)
sendEvent(Event.LogInFailureEvent,"event_login_activity")
}
sendEvent(Event.AuthFailedEvent,"event_login_activity")
} else sendEvent(Event.LogInFailureEvent,"event_login_activity")
}.onFailure { failure ->
sendEvent(Event.NetworkErrorEvent(failure.message),"event_login_activity")
}
Expand All @@ -47,12 +49,6 @@ class LoginViewModel @Inject constructor(
wenku8Repository.password = password
}

//获取网页wenku8节点
fun getWenku8Node() = wenku8Repository.getWenku8Node()

//设置网页wenku8节点
fun setWenku8Node(node: String) = wenku8Repository.setWenku8Node(node)

//刷新书架列表
suspend fun refreshBookshelfList() {
wenku8Repository.getBookshelf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.cyh128.hikari_novel.base.BaseActivity
import com.cyh128.hikari_novel.data.model.Event
import com.cyh128.hikari_novel.databinding.ActivitySplashBinding
import com.cyh128.hikari_novel.ui.view.main.MainActivity
import com.cyh128.hikari_novel.util.ResourceUtil
import com.cyh128.hikari_novel.util.startActivity
import com.drake.channel.receiveEvent
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -37,14 +38,18 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>() {
overridePendingTransition(0, 0)
}

Event.LogInFailureEvent -> {
Event.AuthFailedEvent -> {
startActivity<LoginActivity> {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
putExtra("isShowTip", true)
}
}

Event.LogInFailureEvent -> {
toErrorScreen(ResourceUtil.getString(R.string.login_failed_tip_2))
}

is Event.NetworkErrorEvent -> {
toErrorScreen(event.msg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ class SplashViewModel @Inject constructor(
fun login() {
viewModelScope.launch(Dispatchers.IO) {
wenku8Repository.login()
.onSuccess {
sendEvent(Event.LogInSuccessEvent,"event_splash_activity")
}.onFailure {
sendEvent(Event.LogInFailureEvent,"event_splash_activity")
.onSuccess { success ->
if (success.isCorrect() && success.isLoginSuccessful) sendEvent(
Event.LogInSuccessEvent,
"event_splash_activity"
) else if (!success.isCorrect() && !success.isLoginSuccessful) sendEvent(
Event.LogInFailureEvent,
"event_splash_activity"
) else if (!success.isCorrect()) sendEvent(
Event.AuthFailedEvent,
"event_splash_activity"
) else sendEvent(Event.LogInFailureEvent, "event_splash_activity")
}.onFailure { failure ->
sendEvent(Event.NetworkErrorEvent(failure.message),"event_splash_activity")
}
}
}
Expand All @@ -43,7 +52,7 @@ class SplashViewModel @Inject constructor(
.onSuccess { success ->
bookshelfRepository.updateBookshelfList(success)
}.onFailure { failure ->
sendEvent(Event.NetworkErrorEvent(failure.message),"event_splash_activity")
sendEvent(Event.NetworkErrorEvent(failure.message), "event_splash_activity")
}
}

Expand All @@ -59,9 +68,4 @@ class SplashViewModel @Inject constructor(
//设置首次启动状态
fun setIsFirstLaunch(isFirstLaunch: Boolean) = appRepository.setIsFirstLaunch(isFirstLaunch)

//获取网页wenku8节点
fun getWenku8Node() = wenku8Repository.getWenku8Node()

//设置网页wenku8节点
fun setWenku8Node(node: String) = wenku8Repository.setWenku8Node(node)
}
23 changes: 20 additions & 3 deletions app/src/main/java/com/cyh128/hikari_novel/util/Wenku8Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object Wenku8Parser {
}

//判断用户名和密码是否正确
fun isUsernameOrPasswordCorrect(html: String): LoginResponse {
fun isUsernameOrPasswordCorrect(html: String, response: LoginResponse) {
val isUsernameCorrect: Boolean?
val isPasswordCorrect: Boolean?

Expand All @@ -123,7 +123,11 @@ object Wenku8Parser {
} catch (_: Exception) {
}
} catch (_: Exception) {
return LoginResponse(isUsernameCorrect = true, isPasswordCorrect = true)
response.apply {
isUsernameCorrect = true
isPasswordCorrect = true
}
return
}

if (t!!.contains("用户不存在")) {
Expand All @@ -139,7 +143,20 @@ object Wenku8Parser {
isUsernameCorrect = true
isPasswordCorrect = true
}
return LoginResponse(isUsernameCorrect, isPasswordCorrect)
response.apply {
this.isUsernameCorrect = isUsernameCorrect
this.isPasswordCorrect = isPasswordCorrect
}
}

fun isLoginSuccessful(html: String, response: LoginResponse) {
val document = Jsoup.parse(html)
try {
val text = document.getElementsByClass("blocktitle")[0].text()
response.isLoginSuccessful = text == "登录成功" || text == "登錄成功"
} catch (e: Exception) {
response.isLoginSuccessful = false
}
}

fun getNovelInfo(html: String): NovelInfo {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@

<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.TextButton"
android:id="@+id/b_a_login_domain"
android:id="@+id/b_a_login_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/switch_node"
app:icon="@drawable/ic_network_node"/>
android:text="@string/setting"
app:icon="@drawable/ic_setting"/>

<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.TextButton"
Expand Down
Loading

0 comments on commit e20fc33

Please sign in to comment.