Skip to content

Commit

Permalink
Merge pull request #143 from dmzz-yyhyy/new_ui
Browse files Browse the repository at this point in the history
完成详情页面新UI
  • Loading branch information
dmzz-yyhyy authored Jan 13, 2025
2 parents 0c25111 + c2e7fac commit 30c7ace
Show file tree
Hide file tree
Showing 21 changed files with 758 additions and 421 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/dataSources.local.xml
.DS_Store
/build
/captures
Expand Down
4 changes: 3 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/build
/release
/debug
7 changes: 3 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*100+debug版本号(开发需要时迭代, 两位数)
versionCode = 1_00_00_018
versionCode = 1_00_00_021
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -33,9 +33,8 @@ android {
InetAddress.getLocalHost().hostName
} catch (_: Exception) {}
resValue("string", "info_build_date", dateFormat.format(Date()))
resValue("string", "info_build_host",
System.getProperty("user.name") + "@" + hostname + "\n"
+ " " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"))
resValue("string", "info_build_host", System.getProperty("user.name") + "@" + hostname )
resValue("string", "info_build_os", System.getProperty("os.name") + "/" + System.getProperty("os.arch"))
setProperty("archivesBaseName", "LightNovelReader-${versionName}")
}

Expand Down
11 changes: 9 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
-dontwarn javax.lang.model.util.SimpleElementVisitor8
-dontwarn javax.lang.model.util.SimpleTypeVisitor8
-dontwarn javax.lang.model.util.Types
-dontwarn sun.misc.**
-dontwarn org.xmlpull.v1.**
-dontwarn org.kxml2.io.**
-dontwarn android.content.res.**
-dontwarn org.slf4j.impl.StaticLoggerBinder

-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
Expand All @@ -62,7 +68,6 @@
-keep,allowobfuscation,allowshrinking class indi.dmzz_yyhyy.lightnovelreader.data.web.zaicomic.json.**{ *;}
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { <fields>; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
Expand Down Expand Up @@ -104,4 +109,6 @@
}
-keepclassmembers,allowobfuscation,allowoptimization class <1> {
<init>();
}
}
-keep class org.xmlpull.** { *; }
-keepclassmembers class org.xmlpull.** { *; }
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 10000005,
"versionCode": 10000021,
"versionName": "1.0.0",
"outputFile": "LightNovelReader-1.0.0-release.apk"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package indi.dmzz_yyhyy.lightnovelreader.data.work

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.hilt.work.HiltWorker
import androidx.work.Worker
import androidx.work.WorkerParameters
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import indi.dmzz_yyhyy.lightnovelreader.R
import indi.dmzz_yyhyy.lightnovelreader.data.book.ChapterContent
import indi.dmzz_yyhyy.lightnovelreader.data.web.WebBookDataSource
import indi.dmzz_yyhyy.lightnovelreader.utils.ImageDownloader
Expand All @@ -23,21 +29,85 @@ class ExportBookToEPUBWork @AssistedInject constructor(
@Assisted workerParams: WorkerParameters,
private val webBookDataSource: WebBookDataSource
) : Worker(appContext, workerParams) {

private val notificationManager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private var notification: Notification? = null
val coroutineScope = CoroutineScope(Dispatchers.IO)

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"BookEpubExport",
"EPUB 导出进度",
NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(channel)
}
}

private fun showProgressNotification() {
notification = NotificationCompat.Builder(applicationContext, "BookEpubExport")
.setContentTitle("导出 ${inputData.getString("title")}")
.setContentText("处理中...")
.setSmallIcon(R.drawable.file_export_24px)
.setProgress(100, 0, true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.build()

notificationManager.notify(1, notification)
}

private fun updateFailureNotification() {
notification = NotificationCompat.Builder(applicationContext, "BookEpubExport")
.setContentTitle("导出 ${inputData.getString("title")}")
.setContentText("导出失败")
.setSmallIcon(R.drawable.file_export_24px)
.setProgress(0, 0, false)
.setAutoCancel(true)
.build()

notificationManager.notify(1, notification)
}

private fun updateCompletionNotification() {
notification = NotificationCompat.Builder(applicationContext, "BookEpubExport")
.setContentTitle("导出 ${inputData.getString("title")}")
.setContentText("已完成")
.setSmallIcon(R.drawable.file_export_24px)
.setProgress(0, 0, false)
.setAutoCancel(true)
.build()

notificationManager.notify(1, notification)
}

override fun doWork(): Result {
createNotificationChannel()
showProgressNotification()

val bookId = inputData.getInt("bookId", -1)
val fileUri = inputData.getString("uri")?.let(Uri::parse) ?: return Result.failure()
val tempDir = applicationContext.cacheDir.resolve("epub").resolve(bookId.toString())
val cover = tempDir.resolve("cover.jpg")
if (bookId < 0) return Result.failure()
if (bookId < 0) {
updateFailureNotification()
return Result.failure()
}

val tasks = mutableListOf<ImageDownloader.Task>()
val epub = EpubBuilder().apply {
val bookInformation = webBookDataSource.getBookInformation(bookId) ?: return Result.failure()
val bookVolumes = webBookDataSource.getBookVolumes(bookId) ?: return Result.failure()
val bookInformation = webBookDataSource.getBookInformation(bookId) ?: return Result.failure().also {
updateFailureNotification()
}
val bookVolumes = webBookDataSource.getBookVolumes(bookId) ?: return Result.failure().also {
updateFailureNotification()
}
val bookContentMap = mutableMapOf<Int, ChapterContent>()
bookVolumes.volumes.forEach { volume ->
volume.chapters.forEach {
bookContentMap[it.id] = webBookDataSource.getChapterContent(it.id, bookId) ?: return Result.failure()
bookContentMap[it.id] = webBookDataSource.getChapterContent(it.id, bookId) ?: return Result.failure().also {
updateFailureNotification()
}
}
}
title = bookInformation.title
Expand All @@ -46,10 +116,8 @@ class ExportBookToEPUBWork @AssistedInject constructor(
description = bookInformation.description
publisher = bookInformation.publishingHouse
tasks.add(ImageDownloader.Task(cover, bookInformation.coverUrl))
if (!tempDir.exists())
tempDir.mkdirs()
else
tempDir.listFiles()?.forEach(File::delete)
if (!tempDir.exists()) tempDir.mkdirs()
else tempDir.listFiles()?.forEach(File::delete)
cover(cover)
bookVolumes.volumes.forEach { volume ->
chapter {
Expand All @@ -63,8 +131,7 @@ class ExportBookToEPUBWork @AssistedInject constructor(
val image = tempDir.resolve(singleText.hashCode().toString() + ".jpg")
tasks.add(ImageDownloader.Task(image, singleText))
image(image)
}
else {
} else {
singleText.split("\n").forEach {
text(it)
br()
Expand All @@ -77,6 +144,7 @@ class ExportBookToEPUBWork @AssistedInject constructor(
}
}
}

val imageDownloader = ImageDownloader(
tasks = tasks,
coroutineScope = coroutineScope,
Expand All @@ -86,6 +154,7 @@ class ExportBookToEPUBWork @AssistedInject constructor(
applicationContext.contentResolver.openOutputStream(fileUri).use {
it?.write(file.readBytes())
}
updateCompletionNotification()
tempDir.delete()
}
)
Expand All @@ -98,4 +167,4 @@ class ExportBookToEPUBWork @AssistedInject constructor(
super.onStopped()
coroutineScope.cancel()
}
}
}
Loading

0 comments on commit 30c7ace

Please sign in to comment.