Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -25,14 +25,11 @@ import com.rosetta.messenger.data.DecryptedAccount
|
||||
import com.rosetta.messenger.data.PreferencesManager
|
||||
import com.rosetta.messenger.ui.auth.AccountInfo
|
||||
import com.rosetta.messenger.ui.auth.AuthFlow
|
||||
import com.rosetta.messenger.ui.chats.Chat
|
||||
import com.rosetta.messenger.ui.chats.ChatsListScreen
|
||||
import com.rosetta.messenger.ui.onboarding.OnboardingScreen
|
||||
import com.rosetta.messenger.ui.splash.SplashScreen
|
||||
import com.rosetta.messenger.ui.theme.RosettaAndroidTheme
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private lateinit var preferencesManager: PreferencesManager
|
||||
@@ -176,6 +173,11 @@ class MainActivity : ComponentActivity() {
|
||||
MainScreen(
|
||||
account = currentAccount,
|
||||
isDarkTheme = isDarkTheme,
|
||||
onToggleTheme = {
|
||||
scope.launch {
|
||||
preferencesManager.setDarkTheme(!isDarkTheme)
|
||||
}
|
||||
},
|
||||
onLogout = {
|
||||
scope.launch {
|
||||
accountManager.logout()
|
||||
@@ -196,53 +198,46 @@ class MainActivity : ComponentActivity() {
|
||||
fun MainScreen(
|
||||
account: DecryptedAccount? = null,
|
||||
isDarkTheme: Boolean = true,
|
||||
onToggleTheme: () -> Unit = {},
|
||||
onLogout: () -> Unit = {}
|
||||
) {
|
||||
// Demo chats for now
|
||||
val demoChats = remember {
|
||||
listOf(
|
||||
Chat(
|
||||
id = "1",
|
||||
name = "Alice Johnson",
|
||||
lastMessage = "Hey! How are you doing?",
|
||||
lastMessageTime = Date(),
|
||||
unreadCount = 2,
|
||||
isOnline = true,
|
||||
publicKey = "alice_key_123"
|
||||
),
|
||||
Chat(
|
||||
id = "2",
|
||||
name = "Bob Smith",
|
||||
lastMessage = "See you tomorrow!",
|
||||
lastMessageTime = Date(System.currentTimeMillis() - 3600000),
|
||||
unreadCount = 0,
|
||||
isOnline = false,
|
||||
publicKey = "bob_key_456"
|
||||
),
|
||||
Chat(
|
||||
id = "3",
|
||||
name = "Team Rosetta",
|
||||
lastMessage = "Great work everyone! 🎉",
|
||||
lastMessageTime = Date(System.currentTimeMillis() - 86400000),
|
||||
unreadCount = 5,
|
||||
isOnline = true,
|
||||
publicKey = "team_key_789"
|
||||
)
|
||||
)
|
||||
}
|
||||
val accountName = account?.name ?: "Rosetta User"
|
||||
val accountPhone = account?.publicKey?.take(16)?.let {
|
||||
"+${it.take(1)} ${it.substring(1, 4)} ${it.substring(4, 7)}${it.substring(7)}"
|
||||
} ?: "+7 775 9932587"
|
||||
|
||||
ChatsListScreen(
|
||||
isDarkTheme = isDarkTheme,
|
||||
chats = demoChats,
|
||||
onChatClick = { chat ->
|
||||
// TODO: Navigate to chat detail
|
||||
accountName = accountName,
|
||||
accountPhone = accountPhone,
|
||||
onToggleTheme = onToggleTheme,
|
||||
onProfileClick = {
|
||||
// TODO: Navigate to profile
|
||||
},
|
||||
onNewGroupClick = {
|
||||
// TODO: Navigate to new group
|
||||
},
|
||||
onContactsClick = {
|
||||
// TODO: Navigate to contacts
|
||||
},
|
||||
onCallsClick = {
|
||||
// TODO: Navigate to calls
|
||||
},
|
||||
onSavedMessagesClick = {
|
||||
// TODO: Navigate to saved messages
|
||||
},
|
||||
onSettingsClick = {
|
||||
// TODO: Navigate to settings
|
||||
},
|
||||
onInviteFriendsClick = {
|
||||
// TODO: Share invite link
|
||||
},
|
||||
onSearchClick = {
|
||||
// TODO: Show search
|
||||
},
|
||||
onNewChat = {
|
||||
// TODO: Show new chat screen
|
||||
},
|
||||
onProfileClick = onLogout, // For now, logout on profile click
|
||||
onSavedMessagesClick = {
|
||||
// TODO: Navigate to saved messages
|
||||
}
|
||||
onLogout = onLogout
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user