|
@@ -14,6 +14,7 @@ import androidx.compose.material3.ListItem
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Scaffold
|
|
|
import androidx.compose.material3.SearchBar
|
|
|
+import androidx.compose.material3.SearchBarDefaults
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextButton
|
|
|
import androidx.compose.material3.TopAppBar
|
|
@@ -43,7 +44,8 @@ import org.json.JSONArray
|
|
|
fun Friend(navController: NavHostController) {
|
|
|
val viewModel: BuddyViewModel = hiltViewModel()
|
|
|
var text by rememberSaveable { mutableStateOf("") }
|
|
|
- var active by rememberSaveable { mutableStateOf(false) }
|
|
|
+ var expanded by rememberSaveable { mutableStateOf(false) }
|
|
|
+ var isSearchActive by remember { mutableStateOf(false) }
|
|
|
val list = remember { mutableStateListOf<Buddy>() }
|
|
|
val listSuggestions = remember { mutableStateListOf<Buddy>() }
|
|
|
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
|
@@ -68,70 +70,77 @@ fun Friend(navController: NavHostController) {
|
|
|
.imePadding()
|
|
|
) {
|
|
|
SearchBar(
|
|
|
- modifier = Modifier.align(Alignment.CenterHorizontally),
|
|
|
- query = text,
|
|
|
- onQueryChange = { text = it },
|
|
|
- onSearch = {
|
|
|
- active = false
|
|
|
- if (text.isNotEmpty()) {
|
|
|
- viewModel.searchFriend(text) { r, d ->
|
|
|
- list.clear()
|
|
|
- if (r && d.isNotEmpty()) {
|
|
|
- val data = JSONArray(d)
|
|
|
- for (i in 0 until data.length()) {
|
|
|
- val t = data.getJSONObject(i)
|
|
|
- val pin = t.optString("A00", "")
|
|
|
- if (pin.isNotEmpty()) {
|
|
|
- list.add(
|
|
|
- Buddy(
|
|
|
- f_pin = t.optString("A00", ""),
|
|
|
- first_name = t.optString("A02", ""),
|
|
|
- last_name = t.optString("A03", ""),
|
|
|
- image_id = t.optString("A74", ""),
|
|
|
- official_account = t.optString("oacc", "0")
|
|
|
- )
|
|
|
- )
|
|
|
+ inputField = {
|
|
|
+ SearchBarDefaults.InputField(
|
|
|
+ query = text,
|
|
|
+ onQueryChange = { text = it },
|
|
|
+ onSearch = {
|
|
|
+ expanded = false
|
|
|
+ if (text.isNotEmpty()) {
|
|
|
+ viewModel.searchFriend(text) { r, d ->
|
|
|
+ list.clear()
|
|
|
+ if (r && d.isNotEmpty()) {
|
|
|
+ val data = JSONArray(d)
|
|
|
+ for (i in 0 until data.length()) {
|
|
|
+ val t = data.getJSONObject(i)
|
|
|
+ val pin = t.optString("A00", "")
|
|
|
+ if (pin.isNotEmpty()) {
|
|
|
+ list.add(
|
|
|
+ Buddy(
|
|
|
+ f_pin = t.optString("A00", ""),
|
|
|
+ first_name = t.optString("A02", ""),
|
|
|
+ last_name = t.optString("A03", ""),
|
|
|
+ image_id = t.optString("A74", ""),
|
|
|
+ official_account = t.optString("oacc", "0")
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- active = active,
|
|
|
- onActiveChange = {
|
|
|
- active = it
|
|
|
- if (it) {
|
|
|
- viewModel.suggestFriend("0") { r, d ->
|
|
|
- list.clear()
|
|
|
- if (r && d.isNotEmpty()) {
|
|
|
- val data = JSONArray(d)
|
|
|
- for (i in 0 until data.length()) {
|
|
|
- val t = data.getJSONObject(i)
|
|
|
- val pin = t.optString("A00", "")
|
|
|
- if (pin.isNotEmpty()) {
|
|
|
- listSuggestions.add(
|
|
|
- Buddy(
|
|
|
- f_pin = t.optString("A00", ""),
|
|
|
- first_name = t.optString("A02", ""),
|
|
|
- last_name = t.optString("A03", ""),
|
|
|
- image_id = t.optString("A74", ""),
|
|
|
- official_account = t.optString("oacc", "0")
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
+ },
|
|
|
+ expanded = expanded,
|
|
|
+ onExpandedChange = {
|
|
|
+// expanded = it
|
|
|
+ },
|
|
|
+ placeholder = { Text("Search name..") },
|
|
|
+ leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) },
|
|
|
+ trailingIcon = {
|
|
|
+ if (expanded) {
|
|
|
+ IconButton(onClick = { text = "" }) {
|
|
|
+ Icon(Icons.Default.Close, contentDescription = null)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ })
|
|
|
},
|
|
|
- placeholder = { Text("Search name..") },
|
|
|
- leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) },
|
|
|
- trailingIcon = {
|
|
|
- if (active) {
|
|
|
- IconButton(onClick = { text = "" }) {
|
|
|
- Icon(Icons.Default.Close, contentDescription = null)
|
|
|
- }
|
|
|
- }
|
|
|
+ modifier = Modifier.align(Alignment.CenterHorizontally),
|
|
|
+ expanded = expanded,
|
|
|
+ onExpandedChange = {
|
|
|
+ expanded = it
|
|
|
+// if (it) {
|
|
|
+// viewModel.suggestFriend("0") { r, d ->
|
|
|
+// list.clear()
|
|
|
+// if (r && d.isNotEmpty()) {
|
|
|
+// val data = JSONArray(d)
|
|
|
+// for (i in 0 until data.length()) {
|
|
|
+// val t = data.getJSONObject(i)
|
|
|
+// val pin = t.optString("A00", "")
|
|
|
+// if (pin.isNotEmpty()) {
|
|
|
+// listSuggestions.add(
|
|
|
+// Buddy(
|
|
|
+// f_pin = t.optString("A00", ""),
|
|
|
+// first_name = t.optString("A02", ""),
|
|
|
+// last_name = t.optString("A03", ""),
|
|
|
+// image_id = t.optString("A74", ""),
|
|
|
+// official_account = t.optString("oacc", "0")
|
|
|
+// )
|
|
|
+// )
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
},
|
|
|
) {
|
|
|
SearchResultList(viewModel = viewModel, list = listSuggestions)
|