Skip to content

Commit

Permalink
Merge pull request #331 from you-apps/dialer
Browse files Browse the repository at this point in the history
[WIP] feat: inbuilt dialer including call history
  • Loading branch information
Bnyro authored Apr 25, 2024
2 parents eded8ea + 64d6ed9 commit 670595d
Show file tree
Hide file tree
Showing 28 changed files with 1,516 additions and 52 deletions.
9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {

defaultConfig {
applicationId = "com.bnyro.contacts"
minSdk = 21
minSdk = 23
targetSdk = 33
versionCode = 28
versionName = "9.0"
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<!-- Sms notifications -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- Dialing support -->
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission
android:name="android.permission.MODIFY_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<!-- Opt out from network permissions declared by whatever dependency -->
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
Expand Down Expand Up @@ -141,6 +153,24 @@
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>

<!-- Receive phone calls -->
<intent-filter>
<action android:name="android.intent.action.DIAL" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="tel" />
</intent-filter>

</activity>

<activity
Expand Down Expand Up @@ -180,6 +210,10 @@

</activity>

<activity
android:name=".ui.activities.CallActivity"
android:exported="false" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down Expand Up @@ -212,6 +246,10 @@
android:name=".receivers.CopyTextReceiver"
android:exported="false" />

<receiver
android:name=".receivers.CallActionReceiver"
android:exported="false" />

<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver
android:name=".receivers.MmsReceiver"
Expand Down Expand Up @@ -240,6 +278,20 @@
<data android:scheme="mmsto" />
</intent-filter>
</service>

<service
android:name=".services.CallService"
android:exported="true"
android:foregroundServiceType="phoneCall"
android:permission="android.permission.BIND_INCALL_SERVICE">
<meta-data
android:name="android.telecom.IN_CALL_SERVICE_UI"
android:value="true" />

<intent-filter>
<action android:name="android.telecom.InCallService" />
</intent-filter>
</service>
</application>

</manifest>
6 changes: 6 additions & 0 deletions app/src/main/java/com/bnyro/contacts/ext/String.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bnyro.contacts.ext

fun String.removeLastChar(): String {
return if (isEmpty()) this
else substring(0, length - 1)
}
6 changes: 5 additions & 1 deletion app/src/main/java/com/bnyro/contacts/nav/NavContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.navigation.compose.rememberNavController
import com.bnyro.contacts.ui.activities.MainActivity

val bottomNavItems = listOf(
NavRoutes.Phone,
NavRoutes.Contacts,
NavRoutes.Messages
)
Expand Down Expand Up @@ -71,7 +72,10 @@ fun NavContainer(
val orientation = LocalConfiguration.current.orientation
Scaffold(
bottomBar = {
if (orientation == Configuration.ORIENTATION_PORTRAIT && (selectedRoute == NavRoutes.Contacts || selectedRoute == NavRoutes.Messages)) {
if (orientation == Configuration.ORIENTATION_PORTRAIT && bottomNavItems.contains(
selectedRoute
)
) {
NavigationBar(
tonalElevation = 5.dp
) {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/bnyro/contacts/nav/NavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.bnyro.contacts.ui.models.ContactsModel
import com.bnyro.contacts.ui.models.DialerModel
import com.bnyro.contacts.ui.models.SmsModel
import com.bnyro.contacts.ui.models.ThemeModel
import com.bnyro.contacts.ui.screens.AboutScreen
import com.bnyro.contacts.ui.screens.CallLogsScreen
import com.bnyro.contacts.ui.screens.ContactsPage
import com.bnyro.contacts.ui.screens.SettingsScreen
import com.bnyro.contacts.ui.screens.SmsListScreen
Expand All @@ -29,6 +31,7 @@ fun AppNavHost(
) {
val smsModel: SmsModel = viewModel(factory = SmsModel.Factory)
val contactsModel: ContactsModel = viewModel(factory = ContactsModel.Factory)
val dialerModel: DialerModel = viewModel()
val themeModel: ThemeModel = viewModel()

val viewModelStoreOwner: ViewModelStoreOwner = LocalViewModelStoreOwner.current!!
Expand All @@ -52,6 +55,11 @@ fun AppNavHost(
})
}
}
composable(NavRoutes.Phone.route) {
CompositionLocalProvider(LocalViewModelStoreOwner provides viewModelStoreOwner) {
CallLogsScreen(contactsModel, dialerModel, themeModel)
}
}
composable(NavRoutes.Messages.route) {
CompositionLocalProvider(LocalViewModelStoreOwner provides viewModelStoreOwner) {
SmsListScreen(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/bnyro/contacts/nav/NavRoutes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Message
import androidx.compose.material.icons.rounded.Person
import androidx.compose.material.icons.rounded.Phone
import androidx.compose.ui.graphics.vector.ImageVector
import com.bnyro.contacts.R

Expand All @@ -14,6 +15,7 @@ sealed class NavRoutes(
) {
object About : NavRoutes("about", null, null)
object Settings : NavRoutes("settings", null, null)
object Phone : NavRoutes("phone", R.string.dial, Icons.Rounded.Phone)
object Contacts : NavRoutes("contacts", R.string.contacts, Icons.Rounded.Person)
object Messages : NavRoutes("messages", R.string.messages, Icons.Rounded.Message)
object MessageThread : NavRoutes("message_thread", null, null)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/bnyro/contacts/obj/CallLogEntry.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bnyro.contacts.obj

data class CallLogEntry(
val phoneNumber: String,
val type: Int,
val time: Long,
val duration: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bnyro.contacts.receivers;

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.bnyro.contacts.util.CallManager

class CallActionReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
ACCEPT_CALL -> {
CallManager.acceptCall()
}

DECLINE_CALL -> CallManager.cancelCall()
}
}

companion object {
const val ACCEPT_CALL = "com.bnyro.contacts.accept_call"
const val DECLINE_CALL = "com.bnyro.contacts.decline_call"
}
}
Loading

0 comments on commit 670595d

Please sign in to comment.