Skip to content

Commit

Permalink
refactor(model): Refactor the data model and improve the message deta…
Browse files Browse the repository at this point in the history
…ils page

- Improve the message details page
- Move Chat, Announcement, ReleaseInfo and Asset classes to the model package
- Optimize the information loading and display logic in ChatInfoActivity
- Improve image loading in ImgViewActivity
- Update build configuration, upgrade Kotlin and Compose versions

refactor(model): 重构数据模型并完善消息详细信息页面

- 完善消息详细信息页面
-将 Chat、Announcement、ReleaseInfo 和 Asset 类移至 model 包
- 优化 ChatInfoActivity 中的信息加载和展示逻辑
- 改进 ImgViewActivity 中的图片加载
- 更新构建配置,升级 Kotlin 和 Compose版本

Signed-off-by: gohj99 <[email protected]>
  • Loading branch information
gohj99 committed Nov 24, 2024
1 parent e705ec6 commit ff7a1ea
Show file tree
Hide file tree
Showing 42 changed files with 727 additions and 272 deletions.
27 changes: 27 additions & 0 deletions .idea/jsonSchemas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.compose.compiler)
}

android {
namespace = "com.gohj99.telewatch"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.gohj99.telewatch"
minSdk = 26
//noinspection OldTargetApi
targetSdk = 34
versionCode = 20
versionName = "1.2.9-beta1"
versionName = "1.2.9-beta2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gohj99/telewatch/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ private fun getAppVersion(context: Context): String {
pInfo.versionName
} catch (e: Exception) {
"1.0.0"
}
}.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.lifecycle.lifecycleScope
import com.gohj99.telewatch.model.Announcement
import com.gohj99.telewatch.ui.SplashAnnouncementScreen
import com.gohj99.telewatch.ui.main.ErrorScreen
import com.gohj99.telewatch.ui.main.SplashLoadingScreen
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -34,10 +34,6 @@ import okhttp3.Request
import okhttp3.Response
import java.io.IOException

data class Announcement(
@SerializedName("id") val id: String,
@SerializedName("title") val title: String
)

class AnnouncementActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gohj99/telewatch/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.core.content.FileProvider
import androidx.lifecycle.lifecycleScope
import com.gohj99.telewatch.model.Chat
import com.gohj99.telewatch.ui.chat.SplashChatScreen
import com.gohj99.telewatch.ui.main.Chat
import com.gohj99.telewatch.ui.main.ErrorScreen
import com.gohj99.telewatch.ui.main.SplashLoadingScreen
import com.gohj99.telewatch.ui.theme.TelewatchTheme
Expand Down
91 changes: 89 additions & 2 deletions app/src/main/java/com/gohj99/telewatch/ChatInfoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import com.gohj99.telewatch.model.Chat
import com.gohj99.telewatch.ui.SplashChatInfoScreen
import com.gohj99.telewatch.ui.main.Chat
import com.gohj99.telewatch.ui.main.SplashLoadingScreen
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.gohj99.telewatch.utils.telegram.TgApi
import kotlinx.coroutines.runBlocking
Expand All @@ -27,6 +30,13 @@ class ChatInfoActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

// 加载页面
setContent {
TelewatchTheme {
SplashLoadingScreen(modifier = Modifier.fillMaxSize())
}
}

tgApi = TgApiManager.tgApi

// 接收传递的 Chat 对象
Expand All @@ -45,13 +55,90 @@ class ChatInfoActivity : ComponentActivity() {
chatObject = tgApi!!.getChat(safeChat.id) // 在 runBlocking 中赋值
}


//println("获取到的chatObject")
//println(chatObject)
// 这里可以使用 chatObject,因为它在 runBlocking 块外声明了
chatObject?.let { itChatObject ->
// 副标题
var subtitle = getString(R.string.Unknown)
// 详细信息
var info = ""
val chatType = chatObject.type
when(chatType) {
// 私人聊天
is TdApi.ChatTypePrivate -> {
subtitle = getString(R.string.Private_Chat)
val userInfo = runBlocking {
tgApi!!.getUser(chatType.userId)
}
if (userInfo != null) {
when(userInfo.status) {
is TdApi.UserStatusOnline ->
subtitle = getString(R.string.Online)
is TdApi.UserStatusEmpty ->
subtitle = getString(R.string.Unknown)
is TdApi.UserStatusRecently ->
subtitle = getString(R.string.Lately)
is TdApi.UserStatusLastWeek ->
subtitle = getString(R.string.Last_week)
is TdApi.UserStatusLastMonth ->
subtitle = getString(R.string.Last_month)
is TdApi.UserStatusOffline ->
subtitle = getString(R.string.Offline)
}
if (userInfo.phoneNumber != "") {
info += "\n${getString(R.string.phoneNumber)}: ${userInfo.phoneNumber}"
}
if (userInfo.usernames != null) {
info += "\n${getString(R.string.username)}: ${userInfo.usernames!!.activeUsernames[0]}"
}
}
}

// 普通群组
is TdApi.ChatTypeBasicGroup -> {
subtitle = getString(R.string.Group_Chat)
val groupInfo = runBlocking {
tgApi!!.getBasicGroup(chatType.basicGroupId)
}
if (groupInfo != null) {
subtitle = "${groupInfo.memberCount} ${getString(R.string.Member)}"
}
}

// 超级群组
is TdApi.ChatTypeSupergroup -> {
subtitle = getString(R.string.Supergroup_Chat)
if (chatType.isChannel) {
// 频道
subtitle = getString(R.string.Channel)
val supergroupInfo = runBlocking {
tgApi!!.getSupergroup(chatType.supergroupId)
}
if (supergroupInfo != null) {
subtitle =
"${supergroupInfo.memberCount} ${getString(R.string.Subscribers)}"
}
} else {
val supergroupInfo = runBlocking {
tgApi!!.getSupergroup(chatType.supergroupId)
}
if (supergroupInfo != null) {
subtitle =
"${supergroupInfo.memberCount} ${getString(R.string.Member)}"
}
}
}

}
setContent {
TelewatchTheme {
SplashChatInfoScreen(itChatObject)
SplashChatInfoScreen(
chatObject = itChatObject,
subtitle = subtitle,
info = info
)
}
}
}
Expand Down
15 changes: 2 additions & 13 deletions app/src/main/java/com/gohj99/telewatch/CheckUpdateActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.lifecycleScope
import com.gohj99.telewatch.model.ReleaseInfo
import com.gohj99.telewatch.ui.CustomButton
import com.gohj99.telewatch.ui.main.ErrorScreen
import com.gohj99.telewatch.ui.main.SplashLoadingScreen
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.gohj99.telewatch.ui.verticalRotaryScroll
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.Call
Expand All @@ -65,17 +65,6 @@ import java.io.IOException
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

data class ReleaseInfo(
@SerializedName("tag_name") val tagName: String,
@SerializedName("prerelease") val prerelease: Boolean,
@SerializedName("published_at") val publishedAt: String,
@SerializedName("assets") val assets: List<Asset>
)

data class Asset(
@SerializedName("name") val name: String,
@SerializedName("browser_download_url") val browserDownloadUrl: String
)

class CheckUpdateActivity : ComponentActivity() {
private var downloadId: Long = -1
Expand Down Expand Up @@ -128,7 +117,7 @@ class CheckUpdateActivity : ComponentActivity() {

val pInfo = packageManager.getPackageInfo(packageName, 0)
val localVersion = pInfo.versionName
val needsUpdate = compareVersions(version, localVersion)
val needsUpdate = compareVersions(version, localVersion.toString())

val publishedAt = releaseInfo.publishedAt
val zonedDateTime = ZonedDateTime.parse(publishedAt)
Expand Down
Loading

0 comments on commit ff7a1ea

Please sign in to comment.