-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBE-3749] Implement 'Threads' tab in compose sample app.
- Loading branch information
PetarVelikov
committed
Oct 14, 2024
1 parent
8d30835
commit fdb1ac1
Showing
6 changed files
with
221 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ample/src/main/java/io/getstream/chat/android/compose/sample/ui/component/AppBottomBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.chat.android.compose.sample.ui.component | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import io.getstream.chat.android.compose.sample.R | ||
import io.getstream.chat.android.compose.ui.theme.ChatTheme | ||
|
||
/** | ||
* Defines the possible options of the app bottom bar. | ||
*/ | ||
enum class AppBottomBarOption { | ||
CHATS, | ||
THREADS, | ||
} | ||
|
||
/** | ||
* Renders the default app bottom bar for switching between chats/threads. | ||
* | ||
* @param selectedOption The currently selected [AppBottomBarOption]. | ||
* @param onOptionSelected Action when invoked when the user clicks on an [AppBottomBarOption]. | ||
*/ | ||
@Composable | ||
fun AppBottomBar( | ||
selectedOption: AppBottomBarOption, | ||
onOptionSelected: (AppBottomBarOption) -> Unit, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.background(ChatTheme.colors.barsBackground), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.SpaceEvenly, | ||
) { | ||
AppBottomBarOptionTile( | ||
icon = R.drawable.ic_chats, | ||
text = R.string.app_bottom_bar_chats, | ||
isSelected = selectedOption == AppBottomBarOption.CHATS, | ||
onClick = { onOptionSelected(AppBottomBarOption.CHATS) }, | ||
) | ||
AppBottomBarOptionTile( | ||
icon = R.drawable.ic_threads, | ||
text = R.string.app_bottom_bar_threads, | ||
isSelected = selectedOption == AppBottomBarOption.THREADS, | ||
onClick = { onOptionSelected(AppBottomBarOption.THREADS) }, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AppBottomBarOptionTile( | ||
@DrawableRes icon: Int, | ||
@StringRes text: Int, | ||
isSelected: Boolean, | ||
onClick: () -> Unit, | ||
) { | ||
val contentColor = if (isSelected) ChatTheme.colors.textHighEmphasis else ChatTheme.colors.textLowEmphasis | ||
Column( | ||
modifier = Modifier | ||
.clickable { onClick() } | ||
.padding(8.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Icon( | ||
painter = painterResource(icon), | ||
contentDescription = null, | ||
tint = contentColor, | ||
) | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
Text( | ||
text = stringResource(text), | ||
fontSize = 12.sp, | ||
color = contentColor, | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
stream-chat-android-compose-sample/src/main/res/drawable/ic_chats.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
Licensed under the Stream License; | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M20,2H4C2.9,2 2,2.9 2,4V22L6,18H20C21.1,18 22,17.1 22,16V4C22,2.9 21.1,2 20,2ZM20,16H6L4,18V4H20V16Z" | ||
android:fillColor="#080707"/> | ||
</vector> |
25 changes: 25 additions & 0 deletions
25
stream-chat-android-compose-sample/src/main/res/drawable/ic_threads.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
Licensed under the Stream License; | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M4,4H20V16H5.17L4,17.17V4ZM4,2C2.9,2 2.01,2.9 2.01,4L2,22L6,18H20C21.1,18 22,17.1 22,16V4C22,2.9 21.1,2 20,2H4ZM6,12H14V14H6V12ZM6,9H18V11H6V9ZM6,6H18V8H6V6Z" | ||
android:fillColor="#080707"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters