Skip to content

Commit

Permalink
feat/ui: Added global search and announcement viewing reminder functions
Browse files Browse the repository at this point in the history
- Added GoToAnnouncementActivity to remind users to view announcements
- Implemented global search function to allow users to search public chats
- Optimized chat list display logic and added processing for those who did not join the chat- Adjusted the settings interface and updated the configuration related to announcement viewing reminders
- Fixed some UI style issues, such as button color and text style

feat/ui: 新增全局搜索和公告查看提醒功能

- 新增 GoToAnnouncementActivity,用于提示用户查看公告
- 实现全局搜索功能,允许用户搜索公共聊天
- 优化聊天列表显示逻辑,增加未加入聊天的处理- 调整设置界面,更新公告查看提醒相关配置
- 修复了一些 UI 样式问题,如按钮颜色和文本样式

Signed-off-by: gohj99 <[email protected]>
  • Loading branch information
gohj99 committed Nov 10, 2024
1 parent d26b741 commit 8d4ef2e
Show file tree
Hide file tree
Showing 26 changed files with 775 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetSelector.xml

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

9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
android:theme="@style/Theme.Telewatch"
tools:ignore="WearStandaloneAppFlag"
tools:targetApi="31">
<activity
android:name=".GoToAnnouncementActivity"
android:exported="true"
android:label="@string/announcement_title"
android:theme="@style/Theme.Telewatch" />
<activity
android:name=".AnnouncementActivity"
android:exported="false"
android:label="@string/announcement_title"
android:theme="@style/Theme.Telewatch" />
<activity
android:name=".GoToCheckUpdateActivity"
android:exported="false"
android:exported="true"
android:label="@string/Beta_title"
android:theme="@style/Theme.Telewatch" />
<activity
Expand Down Expand Up @@ -83,7 +88,7 @@
android:theme="@style/Theme.Telewatch" />
<activity
android:name=".AboutActivity"
android:exported="false"
android:exported="true"
android:label="@string/about_activity_setting"
android:theme="@style/Theme.Telewatch" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
Expand Down Expand Up @@ -107,36 +106,72 @@ fun SplashAllowDataCollectionScreen(set: (Boolean) -> Unit) {
Spacer(modifier = Modifier.height(16.dp))

// 不同意和同意按钮
Row(
horizontalArrangement = Arrangement.Center,
Box(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 64.dp, start = 16.dp, end = 16.dp)
.padding(bottom = 4.dp, start = 16.dp, end = 16.dp)
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(
onClick = { set(false) },
modifier = Modifier.weight(1f),
onClick = { set(true) },
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF3E4D58), // 按钮背景颜色
containerColor = Color(0xFF3A7FBE), // 按钮背景颜色
contentColor = Color.White // 按钮文字颜色
)
) {
Text(text = stringResource(id = R.string.disagree))
Text(text = stringResource(id = R.string.agree))
}

Spacer(modifier = Modifier.width(8.dp))

}
Box(
modifier = Modifier
.padding(bottom = 16.dp, start = 16.dp, end = 16.dp)
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(
onClick = { set(true) },
modifier = Modifier.weight(1f),
onClick = { set(false) },
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF3A7FBE), // 按钮背景颜色
containerColor = Color(0xFF3E4D58), // 按钮背景颜色
contentColor = Color.White // 按钮文字颜色
)
) {
Text(text = stringResource(id = R.string.agree))
Text(text = stringResource(id = R.string.disagree))
}
}

Spacer(modifier = Modifier.height(42.dp))
// Row(
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .fillMaxWidth()
// .padding(bottom = 64.dp, start = 16.dp, end = 16.dp)
// ) {
// Button(
// onClick = { set(false) },
// modifier = Modifier.weight(1f),
// colors = ButtonDefaults.buttonColors(
// containerColor = Color(0xFF3E4D58), // 按钮背景颜色
// contentColor = Color.White // 按钮文字颜色
// )
// ) {
// Text(text = stringResource(id = R.string.disagree))
// }
//
// Spacer(modifier = Modifier.width(8.dp))
//
// Button(
// onClick = { set(true) },
// modifier = Modifier.weight(1f),
// colors = ButtonDefaults.buttonColors(
// containerColor = Color(0xFF3A7FBE), // 按钮背景颜色
// contentColor = Color.White // 按钮文字颜色
// )
// ) {
// Text(text = stringResource(id = R.string.agree))
// }
// }
}
}

Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/gohj99/telewatch/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ChatActivity : ComponentActivity() {
}
}

private suspend fun init(lastRun: Boolean = false) {
private suspend fun init(parameter: String? = null) {
tgApi = TgApiManager.tgApi

// 接收传递的 Chat 对象
Expand Down Expand Up @@ -362,19 +362,24 @@ class ChatActivity : ComponentActivity() {
// 处理没有可用浏览器的情况
Toast.makeText(this, getString(R.string.No_app_to_handle_this_url), Toast.LENGTH_SHORT).show()
}
},
reInit = {
lifecycleScope.launch {
init()
}
}
)
}
}
}
}
if (chatObject == null) {
if (lastRun) {
if (parameter == "lastRun") {
throw IllegalStateException("Unable to create private chat")
} else {
tgApi!!.CreatePrivateChat(chat!!.id)
tgApi!!.createPrivateChat(chat!!.id)
lifecycleScope.launch(Dispatchers.IO) {
init(true)
init("lastRun")
}
}
}
Expand Down
162 changes: 162 additions & 0 deletions app/src/main/java/com/gohj99/telewatch/GoToAnnouncementActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright (c) 2024 gohj99. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
* Vestibulum commodo. Ut rhoncus gravida arcu.
*/

package com.gohj99.telewatch

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.gohj99.telewatch.ui.verticalRotaryScroll

class GoToAnnouncementActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

val settingsSharedPref = getSharedPreferences("app_settings", Context.MODE_PRIVATE)
if (settingsSharedPref.getBoolean("Skip_GoToAnnouncementActivity", false)) {
startActivity(
Intent(
this@GoToAnnouncementActivity,
AnnouncementActivity::class.java
)
)
finish()
} else {
setContent {
TelewatchTheme {
SplashAnnouncementActivityScreen { isSkip ->
with(settingsSharedPref.edit()) {
putBoolean("Skip_GoToAnnouncementActivity", isSkip)
commit()
startActivity(
Intent(
this@GoToAnnouncementActivity,
AnnouncementActivity::class.java
)
)
finish()
}
}
}
}
}
}
}

@Composable
fun SplashAnnouncementActivityScreen(set: (Boolean) -> Unit) {
val scrollState = rememberScrollState()
LaunchedEffect(Unit) {
scrollState.scrollTo(80)
}

Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.verticalRotaryScroll(scrollState),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
// 标题
Text(
text = stringResource(id = R.string.GoToAnnouncementActivity_title),
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.White,
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 86.dp)
)

// 主要说明部分
Text(
text = stringResource(id = R.string.GoToAnnouncementActivity_description),
fontSize = 16.sp,
color = Color.White,
textAlign = TextAlign.Center,
modifier = Modifier.padding(16.dp)
)

Spacer(modifier = Modifier.height(16.dp))

// 不提醒继续和继续按钮
Box(
modifier = Modifier
.padding(bottom = 4.dp, start = 16.dp, end = 16.dp)
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(
onClick = { set(true) },
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF3A7FBE), // 按钮背景颜色
contentColor = Color.White // 按钮文字颜色
)
) {
Text(text = stringResource(id = R.string.don_remind_me_again))
}
}
Box(
modifier = Modifier
.padding(bottom = 16.dp, start = 16.dp, end = 16.dp)
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(
onClick = { set(false) },
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF3E4D58), // 按钮背景颜色
contentColor = Color.White // 按钮文字颜色
)
) {
Text(text = stringResource(id = R.string.agree))
}
}

Spacer(modifier = Modifier.height(42.dp))
}
}

@Preview(showBackground = true)
@Composable
fun SplashGoToAnnouncementActivityPreview() {
TelewatchTheme {
SplashAnnouncementActivityScreen { /*TODO*/ }
}
}
Loading

0 comments on commit 8d4ef2e

Please sign in to comment.