Skip to content

- Search Impl #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/app/
120 changes: 111 additions & 9 deletions app/src/main/java/com/iptv/stream/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.iptv.stream.ui.theme.StreamTVTheme
Expand All @@ -18,10 +17,23 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.iptv.stream.entity.Channel

Expand Down Expand Up @@ -81,29 +93,119 @@ fun ListChannels(channels: List<Channel>, loading: Boolean, channelCallback: (St

Log.d("stream_data", "ListChannels: starts: ")

val searchChannel = remember {
mutableStateOf("")
}


if (loading == true){

CircularProgressIndicator()

}else{

LazyColumn(modifier = Modifier.fillMaxSize()){
items(channels){ channel ->
Column {

ChannelView(channel){
Log.d("channelUrlCallback", "ListChannels received: ${it}")
SearchChannel(searchChannel){
searchChannel.value = it
}

channelCallback(it)
}
LazyColumn(modifier = Modifier.fillMaxSize()){

items(if (searchChannel.value == "") channels else channels.filter {channel ->
channel.channelName.contains(searchChannel.value, ignoreCase = true)
}){ channel ->

ChannelView(channel){
Log.d("channelUrlCallback", "ListChannels received: ${it}")

channelCallback(it)
}

}
}

}

}

Log.d("stream_data", "ListChannels: ends: ")


}

//@Preview
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SearchChannel(searchChannel: MutableState<String>, channelCallback: (String) -> Unit) {

val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = remember {
FocusRequester()
}

val hiddenTextField = remember {
mutableStateOf(true)
}

Row(modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End) {

if(hiddenTextField.value == false) {

OutlinedTextField(value = searchChannel.value, onValueChange = {
searchChannel.value = it
},
modifier = Modifier
.padding(5.dp)
.weight(8f),
trailingIcon = {

if (searchChannel.value.isNotBlank()){

Icon(imageVector = Icons.Default.Clear, contentDescription = "Clear icon",
modifier = Modifier.width(50.dp).height(50.dp).padding(10.dp).clickable {
searchChannel.value = ""
})

}


}, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions (
onDone = {
keyboardController?.hide()
channelCallback(searchChannel.value)
})
)
//TX ends

}

IconButton(onClick = {
hiddenTextField.value = !hiddenTextField.value

keyboardController?.show()
focusRequester.requestFocus()

if (!hiddenTextField.value && searchChannel.value != ""){
channelCallback(searchChannel.value)
searchChannel.value = ""
}

}) {
Icon(imageVector = Icons.Default.Search, contentDescription = "Search Icon",
modifier = Modifier
.width(50.dp)
.height(50.dp)
.weight(2f)
.focusRequester(focusRequester))
}

}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class StreamViewModel @Inject constructor(private val repository: StreamReposito
Log.d("stream_data", "StreamViewModel | viewModelScope.launch intent")

loading.value = true
delay(3000)
delay(4000)

if (intent.resolveActivity(packageManager) != null) {
startActivity(context, intent, null)
Expand Down