Skip to content

Commit

Permalink
Merge pull request #7 from gohj99/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
gohj99 authored Oct 6, 2024
2 parents fdb0bab + 2cec84d commit 08750fe
Show file tree
Hide file tree
Showing 28 changed files with 1,160 additions and 409 deletions.
14 changes: 9 additions & 5 deletions README.ja-JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ adb install Telewatch.apk

## 関数

- テキスト、写真、ビデオの表示またはダウンロード
- 写真やビデオを保存する
- 複数アカウント対応
- インターフェースのフォント調整
- 未読/既読インジケーター
- 接続状態インジケーター
- テキスト、画像、ビデオの閲覧またはダウンロード
- 画像やビデオの保存
- テキスト送信
- メッセージ処理の編集
- 削除メッセージの処理
- リューズの回転をサポート
- メッセージ編集処理
- メッセージ削除処理
- クラウンローテーションのサポート

## 最小構成と推奨構成

Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ adb install Telewatch.apk

## Functions

- View or download text, pictures, and videos
- Save pictures or videos
- Send text
- Edit message processing
- Delete message processing
- Support crown rotation
- Multi-account support
- Interface font adjustment
- Unread/read indicator
- Connection status indicator
- Viewing or downloading text, images, and videos
- Saving images or videos
- Text messaging
- Message editing
- Message deletion
- Support for rotating the digital crown

## Minimum and recommended requirements

Expand Down
4 changes: 4 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ adb install Telewatch.apk

## 功能

- 多账号支持
- 界面字体调节
- 未读/已读指示器
- 连接状态指示器
- 文字、图片、视频查看或下载
- 保存图片或视频
- 文字发送
Expand Down
4 changes: 4 additions & 0 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ adb install Telewatch.apk

## 功能

- 多帳號支持
- 介面字體調節
- 未讀/已讀指示器
- 連線狀態指示器
- 文字、圖片、影片檢視或下載
- 儲存圖片或視頻
- 文字發送
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
minSdk = 26
//noinspection OldTargetApi
targetSdk = 34
versionCode = 10
versionName = "1.1.5"
versionCode = 12
versionName = "1.2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
android:theme="@style/Theme.Telewatch"
tools:ignore="WearStandaloneAppFlag"
tools:targetApi="31">
<activity
android:name=".ConfirmLogoutActivity"
android:exported="false"
android:label="@string/Confirm_Logout"
android:theme="@style/Theme.Telewatch" />
<activity
android:name=".CheckUpdateActivity"
android:exported="false"
Expand Down
313 changes: 176 additions & 137 deletions app/src/main/java/com/gohj99/telewatch/ChatActivity.kt

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions app/src/main/java/com/gohj99/telewatch/CheckUpdateActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -88,24 +87,6 @@ class CheckUpdateActivity : ComponentActivity() {
private const val REQUEST_CODE_UNKNOWN_APP = 1234
}

@Deprecated("This method has been deprecated in favor of using the Activity Result API\n which brings increased type safety via an {@link ActivityResultContract} and the prebuilt\n contracts for common intents available in\n {@link androidx.activity.result.contract.ActivityResultContracts}, provides hooks for\n testing, and allow receiving results in separate, testable classes independent from your\n activity. Use\n {@link #registerForActivityResult(ActivityResultContract, ActivityResultCallback)}\n with the appropriate {@link ActivityResultContract} and handling the result in the\n {@link ActivityResultCallback#onActivityResult(Object) callback}.")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_UNKNOWN_APP) {
if (resultCode == RESULT_OK) {
// 用户已授予安装未知来源应用的权限,再次尝试安装 APK
installApk(fileName)
} else {
// 用户拒绝授予权限,处理拒绝情况
Toast.makeText(
this,
getString(R.string.unknown_apps_install_permission_denied),
Toast.LENGTH_SHORT
).show()
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down
206 changes: 206 additions & 0 deletions app/src/main/java/com/gohj99/telewatch/ConfirmLogoutActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* 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.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
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
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.telegram.TgApi
import com.gohj99.telewatch.ui.theme.TelewatchTheme
import com.google.gson.Gson
import com.google.gson.JsonObject
import java.io.File

class ConfirmLogoutActivity : ComponentActivity() {
private var tgApi: TgApi? = null
private var deletaAll = false

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

tgApi = TgApiManager.tgApi

val externalDir: File = getExternalFilesDir(null)
?: throw IllegalStateException("Failed to get external directory.")

val gson = Gson()
val sharedPref = getSharedPreferences("LoginPref", MODE_PRIVATE)
var userList = sharedPref.getString("userList", "")
if (userList == "") throw Exception("No user data found")
val jsonObject: JsonObject = gson.fromJson(userList, JsonObject::class.java)
var account = ""
if (jsonObject.entrySet().size <= 1) {
deletaAll = true
} else {
account = jsonObject.keySet().firstOrNull().toString()
jsonObject.remove(account)
userList = jsonObject.toString()
}

setContent {
TelewatchTheme {
SplashConfirmLogoutActivityScreen { isSwitch ->
if (isSwitch) {
tgApi?.logOut()
if (deletaAll) {
// 清除缓存
cacheDir.deleteRecursively()
// 清空软件文件
filesDir.deleteRecursively()
val dir = externalDir.listFiles()
dir?.forEach { file ->
if (!file.deleteRecursively()) {
// 如果某个文件或文件夹无法删除,可以记录日志或采取其他处理方式
println("Failed to delete: ${file.absolutePath}")
}
}
cacheDir.deleteRecursively()
// 清空 SharedPreferences
getSharedPreferences("LoginPref", MODE_PRIVATE).edit().clear()
.apply()
// 重启软件
Handler(Looper.getMainLooper()).postDelayed({
val intent = packageManager.getLaunchIntentForPackage(packageName)
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
android.os.Process.killProcess(android.os.Process.myPid())
}, 1000)
} else {
val dir = File(externalDir.absolutePath + "/" + account)
dir.listFiles()?.find { it.name == "tdlib" && it.isDirectory }
?.deleteRecursively()
cacheDir.deleteRecursively()
with(sharedPref.edit()) {
putString("userList", userList)
commit()
// 重启软件
Handler(Looper.getMainLooper()).postDelayed({
val intent =
packageManager.getLaunchIntentForPackage(packageName)
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
android.os.Process.killProcess(android.os.Process.myPid())
}, 1000)
}
}
} else {
finish()
}
}
}
}
}
}

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

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

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

Spacer(modifier = Modifier.height(16.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))
}
}
}
}

@Preview(showBackground = true)
@Composable
fun SplashConfirmLogoutActivityScreenPreview() {
TelewatchTheme {
SplashConfirmLogoutActivityScreen { /*TODO*/ }
}
}
22 changes: 17 additions & 5 deletions app/src/main/java/com/gohj99/telewatch/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ class LoginActivity : ComponentActivity() {
// 获取私有外部存储的根目录
val externalDir: File = getExternalFilesDir(null)
?: throw IllegalStateException("Failed to get external directory.")
// 删除可能存在的文件夹
val dir =
File(externalDir.absolutePath + "/" + it.id.toString())
dir.listFiles()?.find { it.name == "tdlib" && it.isDirectory }
?.deleteRecursively()
cacheDir.deleteRecursively()
// 定义源文件夹路径 (tdlib)
val sourceDir = File(externalDir, "tdlib")
if (!sourceDir.exists()) {
Expand All @@ -215,6 +221,7 @@ class LoginActivity : ComponentActivity() {
} else {
throw IOException("Failed to move folder to: ${targetDir.absolutePath}")
}

// 存储账号数据
val gson = Gson()
var userList: String
Expand All @@ -223,11 +230,16 @@ class LoginActivity : ComponentActivity() {
userList = sharedPref.getString("userList", "").toString()
val jsonObject: JsonObject =
gson.fromJson(userList, JsonObject::class.java)
jsonObject.firstAdd(
it.id.toString(),
"${it.firstName} ${it.lastName}"
)
userList = jsonObject.toString()
// 如果登录重复账号
if (jsonObject.has(it.id.toString())) {
jsonObject.remove(it.id.toString())
} else {
jsonObject.firstAdd(
it.id.toString(),
"${it.firstName} ${it.lastName}"
)
userList = jsonObject.toString()
}
} else {
// 首次登录
val jsonObject = JsonObject()
Expand Down
Loading

0 comments on commit 08750fe

Please sign in to comment.