-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gohj99 <[email protected]>
- Loading branch information
Showing
16 changed files
with
11,361 additions
and
9,912 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 54 additions & 27 deletions
81
app/src/main/java/com/gohj99/telewatch/SettingActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,74 @@ | ||
package com.gohj99.telewatch | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.widget.Toast | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.gohj99.telewatch.ui.SettingItem | ||
import com.gohj99.telewatch.ui.SplashSettingScreen | ||
import com.gohj99.telewatch.ui.theme.TelewatchTheme | ||
import java.io.File | ||
|
||
class SettingActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
enableEdgeToEdge() | ||
|
||
val settingsList = listOf( | ||
SettingItem.NestedSetting(getString(R.string.Clearing_cache), onClick = { | ||
cacheDir.deleteRecursively() | ||
Toast.makeText(this, getString(R.string.Successful), Toast.LENGTH_SHORT).show() | ||
}), | ||
SettingItem.NestedSetting(getString(R.string.Reset_libtd), onClick = { reset_libtd() }), | ||
SettingItem.NestedSetting(getString(R.string.Reset_self), onClick = { reset_self() }) | ||
) | ||
|
||
setContent { | ||
TelewatchTheme { | ||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | ||
Greeting3( | ||
name = "Android", | ||
modifier = Modifier.padding(innerPadding) | ||
) | ||
} | ||
SplashSettingScreen( | ||
settings = settingsList | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun Greeting3(name: String, modifier: Modifier = Modifier) { | ||
Text( | ||
text = "Hello $name!", | ||
modifier = modifier | ||
) | ||
} | ||
private fun reset_libtd(){ | ||
val dir = File(applicationContext.filesDir.absolutePath) | ||
dir.listFiles()?.find { it.name == "tdlib" && it.isDirectory }?.deleteRecursively() | ||
// 清除登录数据 | ||
getSharedPreferences("LoginPref", Context.MODE_PRIVATE).edit().clear().apply() | ||
// Toast提醒 | ||
Toast.makeText(this, getString(R.string.Successful), Toast.LENGTH_SHORT).show() | ||
// 重启软件 | ||
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) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview4() { | ||
TelewatchTheme { | ||
Greeting3("Android") | ||
private fun reset_self(){ | ||
// 清除缓存 | ||
cacheDir.deleteRecursively() | ||
// 清空软件文件 | ||
filesDir.deleteRecursively() | ||
// 清空 SharedPreferences | ||
getSharedPreferences("LoginPref", Context.MODE_PRIVATE).edit().clear().apply() | ||
// Toast提醒 | ||
Toast.makeText(this, getString(R.string.Successful), Toast.LENGTH_SHORT).show() | ||
// 重启软件 | ||
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.