-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add composables OpenDialerApp CallsScreen, CallDetailScreen, Contacts…
…Screen
- Loading branch information
Showing
22 changed files
with
992 additions
and
85 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
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
96 changes: 96 additions & 0 deletions
96
app/src/main/java/dev/alenajam/opendialer/ui/OpenDialerApp.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,96 @@ | ||
package dev.alenajam.opendialer.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.AccessTimeFilled | ||
import androidx.compose.material.icons.filled.People | ||
import androidx.compose.material.icons.outlined.AccessTime | ||
import androidx.compose.material.icons.outlined.Dialpad | ||
import androidx.compose.material.icons.outlined.People | ||
import androidx.compose.material.icons.outlined.Search | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.FloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.NavigationBar | ||
import androidx.compose.material3.NavigationBarItem | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.SearchBar | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.viewinterop.AndroidViewBinding | ||
import dev.alenajam.opendialer.R | ||
import dev.alenajam.opendialer.databinding.AppFragmentCallsBinding | ||
import dev.alenajam.opendialer.databinding.AppFragmentContactsBinding | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun OpenDialerApp( | ||
openDialpad: () -> Unit | ||
) { | ||
var selectedNavigationItem by remember { mutableStateOf("CALLS") } | ||
Scaffold( | ||
topBar = { | ||
SearchBar( | ||
query = "", | ||
active = false, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp), | ||
placeholder = { Text(text = stringResource(id = R.string.searchContacts)) }, | ||
leadingIcon = { Icon(imageVector = Icons.Outlined.Search, contentDescription = null) }, | ||
onSearch = {}, | ||
onActiveChange = {}, | ||
onQueryChange = {}, | ||
) {} | ||
}, | ||
bottomBar = { | ||
NavigationBar { | ||
val isSelected = { item: String -> item == selectedNavigationItem } | ||
NavigationBarItem( | ||
selected = isSelected("CALLS"), | ||
icon = { | ||
Icon( | ||
imageVector = if (isSelected("CALLS")) Icons.Filled.AccessTimeFilled else Icons.Outlined.AccessTime, | ||
contentDescription = null | ||
) | ||
}, | ||
label = { Text("Recents") }, | ||
onClick = { selectedNavigationItem = "CALLS" }, | ||
) | ||
|
||
NavigationBarItem( | ||
selected = isSelected("CONTACTS"), | ||
icon = { | ||
Icon( | ||
imageVector = if (isSelected("CONTACTS")) Icons.Filled.People else Icons.Outlined.People, | ||
contentDescription = null | ||
) | ||
}, | ||
label = { Text("Contacts") }, | ||
onClick = { selectedNavigationItem = "CONTACTS" }, | ||
) | ||
} | ||
}, | ||
floatingActionButton = { | ||
FloatingActionButton(onClick = openDialpad) { | ||
Icon(imageVector = Icons.Outlined.Dialpad, contentDescription = null) | ||
} | ||
} | ||
) { innerPadding -> | ||
Surface(modifier = Modifier.padding(innerPadding)) { | ||
when (selectedNavigationItem) { | ||
"CALLS" -> AndroidViewBinding(AppFragmentCallsBinding::inflate) | ||
"CONTACTS" -> AndroidViewBinding(AppFragmentContactsBinding::inflate) | ||
} | ||
} | ||
} | ||
} |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/fragment_container_view_calls" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:name="dev.alenajam.opendialer.feature.calls.RecentsFragment" /> |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/fragment_container_view_contacts" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:name="dev.alenajam.opendialer.feature.contacts.ContactsFragment" /> |
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
60 changes: 60 additions & 0 deletions
60
core/common/src/main/java/dev/alenajam/opendialer/core/common/forwardingPainter.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,60 @@ | ||
package dev.alenajam.opendialer.core.common | ||
|
||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.DefaultAlpha | ||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
import androidx.compose.ui.graphics.painter.Painter | ||
|
||
/** | ||
* Create and return a new [Painter] that wraps [painter] with its [alpha], [colorFilter], or [onDraw] overwritten. | ||
*/ | ||
fun forwardingPainter( | ||
painter: Painter, | ||
alpha: Float = DefaultAlpha, | ||
colorFilter: ColorFilter? = null, | ||
onDraw: DrawScope.(ForwardingDrawInfo) -> Unit = DefaultOnDraw, | ||
): Painter = ForwardingPainter(painter, alpha, colorFilter, onDraw) | ||
|
||
data class ForwardingDrawInfo( | ||
val painter: Painter, | ||
val alpha: Float, | ||
val colorFilter: ColorFilter?, | ||
) | ||
|
||
private class ForwardingPainter( | ||
private val painter: Painter, | ||
private var alpha: Float, | ||
private var colorFilter: ColorFilter?, | ||
private val onDraw: DrawScope.(ForwardingDrawInfo) -> Unit, | ||
) : Painter() { | ||
|
||
private var info = newInfo() | ||
|
||
override val intrinsicSize get() = painter.intrinsicSize | ||
|
||
override fun applyAlpha(alpha: Float): Boolean { | ||
if (alpha != DefaultAlpha) { | ||
this.alpha = alpha | ||
this.info = newInfo() | ||
} | ||
return true | ||
} | ||
|
||
override fun applyColorFilter(colorFilter: ColorFilter?): Boolean { | ||
if (colorFilter != null) { | ||
this.colorFilter = colorFilter | ||
this.info = newInfo() | ||
} | ||
return true | ||
} | ||
|
||
override fun DrawScope.onDraw() = onDraw(info) | ||
|
||
private fun newInfo() = ForwardingDrawInfo(painter, alpha, colorFilter) | ||
} | ||
|
||
private val DefaultOnDraw: DrawScope.(ForwardingDrawInfo) -> Unit = { info -> | ||
with(info.painter) { | ||
draw(size, info.alpha, info.colorFilter) | ||
} | ||
} |
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
Oops, something went wrong.