Skip to content

Commit

Permalink
汐洛链滴社区客户端 #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed May 24, 2024
1 parent aa4f680 commit a4897c4
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 220 deletions.
156 changes: 74 additions & 82 deletions app/src/main/java/org/b3log/siyuan/ManageSpaceActivity.kt
Original file line number Diff line number Diff line change
@@ -1,82 +1,74 @@
package org.b3log.siyuan

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import kotlinx.coroutines.DelicateCoroutinesApi
import org.b3log.siyuan.compose.components.CommonTopAppBar
import org.b3log.siyuan.producer.MyUI

// TODO: 仿哔哩哔哩界面
// TODO: 实际清理逻辑
class ManageSpaceActivity : ComponentActivity() {
// 将"清除数据"项变为"管理空间",自定义数据清除 https://github.com/Hi-Windom/Sillot-android/issues/49
val TAG = "ManageSpaceActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// 设置沉浸式通知栏
window.setDecorFitsSystemWindows(false)
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
insets
}
setContent {
CascadeMaterialTheme {
UI(intent)
}
}

//设置竖屏锁定
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class)
@Composable
private fun UI(intent: Intent?) {
val TAG = "MainPro-MyUI"
val uri = intent?.data
val Lcc = LocalContext.current
val inspectionMode = LocalInspectionMode.current // 获取当前是否处于预览模式// 获取窗口尺寸
val coroutineScope = rememberCoroutineScope()
val fileName = uri?.let { Us.getFileName(Lcc, it) }
val fileSize = uri?.let { Us.getFileSize(Lcc, it) }
val mimeType = intent?.data?.let { Us.getMimeType(Lcc, it) } ?: ""
val fileType = fileName?.let { Us.getFileMIMEType(mimeType, it) } ?: run { Us.getFileMIMEType(mimeType) }
val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE // 是否横屏(宽高比)

var isMenuVisible by rememberSaveable { mutableStateOf(false) }

Scaffold(
topBar = {
CommonTopAppBar("汐洛存储清理助手", uri) {
// 将Context对象安全地转换为Activity
if (Lcc is Activity) {
Lcc.finish() // 结束活动
}
}
}, modifier = Modifier.background(Color.Gray)
) {

}
}
package org.b3log.siyuan

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import kotlinx.coroutines.DelicateCoroutinesApi
import org.b3log.siyuan.compose.components.CommonTopAppBar
import org.b3log.siyuan.producer.MyUI

// TODO: 仿哔哩哔哩界面
// TODO: 实际清理逻辑
class ManageSpaceActivity : ComponentActivity() {
// 将"清除数据"项变为"管理空间",自定义数据清除 https://github.com/Hi-Windom/Sillot-android/issues/49
val TAG = "ManageSpaceActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// 设置沉浸式通知栏
window.setDecorFitsSystemWindows(false)
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
insets
}
setContent {
CascadeMaterialTheme {
UI(intent)
}
}

//设置竖屏锁定
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class)
@Composable
private fun UI(intent: Intent?) {
val TAG = "MainPro-MyUI"
val uri = intent?.data
val Lcc = LocalContext.current
var isMenuVisible = rememberSaveable { mutableStateOf(false) }

Scaffold(
topBar = {
CommonTopAppBar("汐洛存储清理助手", uri, isMenuVisible) {
// 将Context对象安全地转换为Activity
if (Lcc is Activity) {
Lcc.finish() // 结束活动
}
}
}, modifier = Modifier.background(Color.Gray)
) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ data class MenuItem31(val title: String, val action: () -> Unit)
fun CommonTopAppBar(
title: String, // 应用栏标题
uri: Uri?,
isMenuVisible: MutableState<Boolean>,
additionalMenuItem: @Composable (() -> Unit)? = null,
onBackPressed: () -> Unit, // 返回按钮的点击事件
) {
val TAG = "CommonTopAppBar"
var isMenuVisible by rememberSaveable { mutableStateOf(false) }
// var isMenuVisible by rememberSaveable { mutableStateOf(false) }
val Lcc = LocalContext.current
TopAppBar(
title = {
Expand All @@ -87,12 +88,12 @@ fun CommonTopAppBar(
},
modifier = Modifier.background(Color.Blue),
actions = {
IconButton(onClick = { isMenuVisible = true }) {
IconButton(onClick = { isMenuVisible.value = true }) {
Icon(Icons.Rounded.MoreVert, contentDescription = "More options")
}
TopRightMenu(
expanded = isMenuVisible,
onDismiss = { isMenuVisible = false },
expanded = isMenuVisible.value,
onDismiss = { isMenuVisible.value = false },
TAG = TAG,
uri = uri,
additionalMenuItem = additionalMenuItem // 将额外的菜单项传递给 TopRightMenu
Expand All @@ -119,13 +120,15 @@ fun TopRightMenu(
expanded = expanded,
onDismissRequest = onDismiss
) {
if(uri != null){
if (uri != null) {
DropdownMenuItem(
text = { Text("复制") },
leadingIcon = { Icon(Icons.TwoTone.ContentCopy, contentDescription = null) },
onClick = {
onDismiss()
// 获取系统的剪贴板管理器
val clipboardManager = Lcc.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboardManager =
Lcc.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
// 创建一个剪贴板数据对象,将文件的 Uri 放入其中
val clipData = ClipData.newUri(Lcc.contentResolver, "label", uri)
// 设置剪贴板数据对象的 MIME 类型
Expand All @@ -139,6 +142,7 @@ fun TopRightMenu(
text = { Text("分享") },
leadingIcon = { Icon(Icons.TwoTone.Share, contentDescription = null) },
onClick = {
onDismiss()
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, uri) // 将文件 Uri 添加到 Intent 的 EXTRA_STREAM 中
Expand Down Expand Up @@ -170,6 +174,7 @@ fun TopRightMenu(
onClick = {
onDismiss()
Us.deleteFileByUri(Lcc, uri).let {
onDismiss()
if (it) {
// Us.notifyGallery(Lcc, uri)
Toast.Show(Lcc, "暂不支持该操作")
Expand All @@ -196,33 +201,46 @@ fun TopRightMenu(

DropdownMenuItem(
text = { Text("帮助") },
leadingIcon = { Icon(
painterResource(R.drawable.icon), contentDescription = null, modifier = modifier.size(
S.C.small_iconSize.current)) },
leadingIcon = {
Icon(
painterResource(R.drawable.icon),
contentDescription = null,
modifier = modifier.size(
S.C.small_iconSize.current
)
)
},
children = {
DropdownMenuItem(
text = { Text("报告此页") },
leadingIcon = { Icon(Icons.TwoTone.Email, contentDescription = null) },
onClick = { Us.sendEmail(Lcc.packageManager, S.emailAdress, "汐洛安卓反馈 - 报告此页", "TAG: ${TAG}\n${Utils.getDeviceInfoString()}") },
onClick = {
onDismiss();Us.sendEmail(
Lcc.packageManager,
S.emailAdress,
"汐洛安卓反馈 - 报告此页",
"TAG: ${TAG}\n${Utils.getDeviceInfoString()}"
)
},
)
DropdownMenuItem(
text = { Text("反馈此页") },
leadingIcon = { Icon(Icons.TwoTone.BugReport, contentDescription = null) },
onClick = { Us.openUrl("${S.gitRepoUrl}/issues/new")},
onClick = { onDismiss();Us.openUrl("${S.gitRepoUrl}/issues/new") },
)
},
)
}
}



data class MenuItem58(
val title: String,
val icon: ImageVector?,
val contentDescription: String?,
val action: () -> Unit
)

// 不好弄这个抽象
@Composable
fun CommonTopRightMenu(
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/org/b3log/siyuan/ld246/DC.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package org.b3log.siyuan.ld246

data class 回帖消息Response(
data class ld246_Response(
val msg: String,
val random: String,
val code: Int,
val data: 回帖消息Response_Data,
val data: ld246_Response_Data,
// 其他可能存在的字段可以省略
)

data class 回帖消息Response_Data(
val commentedNotifications: List<回帖消息Response_Notification>,
data class ld246_Response_Data(
val notifications: List<ld246_Response_Data_Notification>, // 理想的字段,其实不存在
val commentedNotifications: List<ld246_Response_Data_Notification>, // 回帖
val comment2edNotifications: List<ld246_Response_Data_Notification>, // 评论
val replyNotifications: List<ld246_Response_Data_Notification>, // 回复
val atNotifications: List<ld246_Response_Data_Notification>, // 提及
val followingNotifications: List<ld246_Response_Data_Notification>, // 关注
val pagination: Pagination,
val unreadNotificationCount: UnreadNotificationCount,
// 其他可能存在的字段可以省略
)

data class 回帖消息Response_Notification(
data class ld246_Response_Data_Notification(
val dataId: String,
val authorName: String,
val authorAvatarURL: String,
Expand Down
Loading

0 comments on commit a4897c4

Please sign in to comment.