You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
270 lines
10 KiB
270 lines
10 KiB
package com.example.dattingapp.homes
|
|
|
|
import android.os.Bundle
|
|
import android.util.Log
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.Add
|
|
import androidx.compose.material.icons.filled.ChatBubbleOutline
|
|
import androidx.compose.material.icons.filled.Explore
|
|
import androidx.compose.material.icons.filled.Person
|
|
import androidx.compose.material.icons.filled.SwapHoriz
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.NavigationBar
|
|
import androidx.compose.material3.NavigationBarItem
|
|
import androidx.compose.material3.Scaffold
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableIntStateOf
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.example.dattingapp.ChatScreen
|
|
import com.example.dattingapp.homes.networkandapi.HomeNetworkModule
|
|
import com.example.dattingapp.homes.networkandapi.MeetUiState
|
|
import com.example.dattingapp.homes.networkandapi.MeetUserProfile
|
|
import com.example.dattingapp.homes.networkandapi.MeetViewModel
|
|
import com.example.dattingapp.homes.networkandapi.MyProfileUiState
|
|
import com.example.dattingapp.homes.networkandapi.MyProfileViewModel
|
|
|
|
import com.example.dattingapp.ui.theme.DattingAPPTheme
|
|
import kotlin.coroutines.cancellation.CancellationException
|
|
|
|
|
|
class HomeActivity : ComponentActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
enableEdgeToEdge()
|
|
|
|
setContent {
|
|
|
|
DattingAPPTheme {
|
|
|
|
HomeScreen()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Composable
|
|
fun HomeScreen() {
|
|
|
|
val appContext = LocalContext.current.applicationContext
|
|
|
|
|
|
var selectedItem by remember { mutableIntStateOf(0) }
|
|
|
|
Scaffold(
|
|
bottomBar = {
|
|
NavigationBar {
|
|
// =========================================
|
|
// MEET
|
|
// =========================================
|
|
|
|
NavigationBarItem(
|
|
selected = selectedItem == 0,
|
|
onClick = { selectedItem = 0 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = Icons.Default.SwapHoriz,
|
|
contentDescription = "Meet"
|
|
)
|
|
},
|
|
label = {
|
|
Text("Meet")
|
|
}
|
|
)
|
|
// =========================================
|
|
// EXPLORE
|
|
// =========================================
|
|
NavigationBarItem(
|
|
selected = selectedItem == 1,
|
|
onClick = { selectedItem = 1 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = Icons.Default.Explore,
|
|
contentDescription = "Explore"
|
|
)
|
|
},
|
|
|
|
label = { Text("Explore") }
|
|
)
|
|
|
|
|
|
// =========================================
|
|
// POST
|
|
// =========================================
|
|
|
|
NavigationBarItem(
|
|
selected = selectedItem == 2,
|
|
onClick = { selectedItem = 2 },
|
|
icon = { Icon(
|
|
imageVector = Icons.Default.Add,
|
|
contentDescription = "Post"
|
|
)
|
|
},
|
|
label = {
|
|
Text("Post")
|
|
}
|
|
)
|
|
// =========================================
|
|
// CHAT
|
|
// =========================================
|
|
NavigationBarItem(
|
|
selected = selectedItem == 3,
|
|
onClick = { selectedItem = 3 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = Icons.Default.ChatBubbleOutline,
|
|
contentDescription = "Chat"
|
|
)
|
|
},
|
|
label = { Text("Chat") }
|
|
)
|
|
// =========================================
|
|
// PROFILE
|
|
// =========================================
|
|
NavigationBarItem(
|
|
selected = selectedItem == 4,
|
|
onClick = { selectedItem = 4 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = Icons.Default.Person,
|
|
contentDescription = "Profile"
|
|
)
|
|
},
|
|
label = { Text("Profile") }
|
|
)
|
|
}
|
|
}
|
|
|
|
) { innerPadding ->
|
|
// =========================================
|
|
// CONTENT AREA
|
|
// =========================================
|
|
|
|
val context = LocalContext.current
|
|
|
|
// or via hiltViewModel() / factory
|
|
|
|
Box(modifier = Modifier.padding(innerPadding)) {
|
|
when (selectedItem) {
|
|
// =========================================
|
|
// MEET
|
|
// =========================================
|
|
0 -> {
|
|
// 1. Obtain instance of ViewModel and LocalContext
|
|
|
|
val viewModel: MeetViewModel = viewModel()
|
|
|
|
// 2. Collect state from ViewModel
|
|
val uiState by viewModel.meetUiState.collectAsState()
|
|
|
|
// 3. Trigger network call once when screen loads
|
|
LaunchedEffect(Unit) {
|
|
viewModel.meetUserResponse(context)
|
|
}
|
|
|
|
// 4. Map UI state to Composable parameters
|
|
when (val state = uiState) {
|
|
is MeetUiState.Loading, MeetUiState.Idle -> {
|
|
MeetDiscoveryScreen(
|
|
profiles = emptyList(),
|
|
isLoading = true,
|
|
errorMessage = null
|
|
)
|
|
}
|
|
is MeetUiState.Success -> {
|
|
MeetDiscoveryScreen(
|
|
profiles = state.response,
|
|
isLoading = false,
|
|
errorMessage = null
|
|
)
|
|
}
|
|
is MeetUiState.Error -> {
|
|
MeetDiscoveryScreen(
|
|
profiles = emptyList(),
|
|
isLoading = false,
|
|
errorMessage = state.message
|
|
)
|
|
}
|
|
}
|
|
}
|
|
// =========================================
|
|
// EXPLORE
|
|
// =========================================
|
|
1 -> {
|
|
VibeCheckHomeScreen()
|
|
}
|
|
// =========================================
|
|
// CREATE POST
|
|
// =========================================
|
|
2 -> {
|
|
CreateVibePostScreen()
|
|
}
|
|
// =========================================
|
|
// CHAT
|
|
// =========================================
|
|
3 -> {
|
|
ChatScreen()
|
|
}
|
|
// =========================================
|
|
// PROFILE
|
|
// =========================================
|
|
4 -> {
|
|
// 1. Obtain instance of ViewModel and LocalContext
|
|
val viewModel: MyProfileViewModel = viewModel()
|
|
val context = LocalContext.current
|
|
|
|
// 2. Collect state from ViewModel
|
|
val uiState by viewModel.myProfileUiState.collectAsState()
|
|
|
|
// 3. Trigger network call once when screen loads
|
|
LaunchedEffect(Unit) {
|
|
viewModel.meetUserResponse(context)
|
|
}
|
|
|
|
// 4. Map UI state to Composable parameters
|
|
when (val state = uiState) {
|
|
is MyProfileUiState.Loading, MyProfileUiState.Idle -> {
|
|
MyProfileScreen(
|
|
profile = null,
|
|
isLoading = true,
|
|
errorMessage = null,
|
|
// onRetry = { viewModel.meetUserResponse(context) }
|
|
)
|
|
}
|
|
is MyProfileUiState.Success -> {
|
|
MyProfileScreen(
|
|
profile = state.myProfile, // or state.response depending on your data class naming
|
|
isLoading = false,
|
|
errorMessage = null,
|
|
)
|
|
}
|
|
is MyProfileUiState.Error -> {
|
|
MyProfileScreen(
|
|
profile = null,
|
|
isLoading = false,
|
|
errorMessage = state.message,
|
|
onRetry = { viewModel.meetUserResponse(context) }
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|