Skip to content

Commit

Permalink
feat: improved dialer screen
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Apr 27, 2024
1 parent 66edda8 commit f21f6ea
Show file tree
Hide file tree
Showing 19 changed files with 462 additions and 253 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dependencies {

// Image parsing
implementation("androidx.exifinterface:exifinterface:1.3.7")
implementation("io.coil-kt:coil-compose:2.4.0")

// Phone number formatting
implementation("com.googlecode.libphonenumber:libphonenumber:8.2.0")
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@
android:name=".util.receivers.CopyTextReceiver"
android:exported="false" />

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

<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/bnyro/contacts/domain/model/CallerInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bnyro.contacts.domain.model

import android.net.Uri

data class CallerInfo(
val rawPhoneNumber: String = "",
val formattedPhoneNumber: String = "",
val callerName: String? = null,
val callerPhoto: Uri? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bnyro.contacts.presentation.screens.calllog.model.CallModel
import com.bnyro.contacts.presentation.screens.contacts.model.ContactsModel
import com.bnyro.contacts.presentation.screens.dialer.model.DialerModel
import com.bnyro.contacts.presentation.screens.settings.model.ThemeModel
import com.bnyro.contacts.presentation.screens.sms.model.SmsModel

Expand All @@ -34,7 +34,7 @@ fun HomeNavContainer(
onNavigate: (String) -> Unit,
smsModel: SmsModel,
contactsModel: ContactsModel,
dialerModel: DialerModel,
callModel: CallModel,
themeModel: ThemeModel
) {
val navController = rememberNavController()
Expand Down Expand Up @@ -108,7 +108,7 @@ fun HomeNavContainer(
onNavigate = onNavigate,
smsModel = smsModel,
contactsModel = contactsModel,
dialerModel = dialerModel,
callModel = callModel,
themeModel = themeModel
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.bnyro.contacts.presentation.screens.calllog.CallLogsScreen
import com.bnyro.contacts.presentation.screens.calllog.model.CallModel
import com.bnyro.contacts.presentation.screens.contacts.ContactsPage
import com.bnyro.contacts.presentation.screens.contacts.model.ContactsModel
import com.bnyro.contacts.presentation.screens.dialer.model.DialerModel
import com.bnyro.contacts.presentation.screens.settings.model.ThemeModel
import com.bnyro.contacts.presentation.screens.sms.SmsListScreen
import com.bnyro.contacts.presentation.screens.sms.model.SmsModel
Expand All @@ -24,7 +24,7 @@ fun HomeNavHost(
modifier: Modifier = Modifier,
smsModel: SmsModel,
contactsModel: ContactsModel,
dialerModel: DialerModel,
callModel: CallModel,
themeModel: ThemeModel
) {
val viewModelStoreOwner: ViewModelStoreOwner = LocalViewModelStoreOwner.current!!
Expand All @@ -40,7 +40,7 @@ fun HomeNavHost(
}
composable(HomeRoutes.Phone.route) {
CompositionLocalProvider(LocalViewModelStoreOwner provides viewModelStoreOwner) {
CallLogsScreen(contactsModel, dialerModel, themeModel)
CallLogsScreen(contactsModel, callModel, themeModel)
}
}
composable(HomeRoutes.Messages.route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.rememberNavController
import com.bnyro.contacts.presentation.screens.calllog.model.CallModel
import com.bnyro.contacts.presentation.screens.contacts.model.ContactsModel
import com.bnyro.contacts.presentation.screens.dialer.model.DialerModel
import com.bnyro.contacts.presentation.screens.settings.model.ThemeModel
import com.bnyro.contacts.presentation.screens.sms.model.SmsModel

Expand All @@ -17,7 +17,7 @@ fun NavContainer(
val navController = rememberNavController()
val smsModel: SmsModel = viewModel()
val contactsModel: ContactsModel = viewModel(factory = ContactsModel.Factory)
val dialerModel: DialerModel = viewModel()
val callModel: CallModel = viewModel()
val themeModel: ThemeModel = viewModel()
AppNavHost(
navController,
Expand All @@ -26,7 +26,7 @@ fun NavContainer(
.fillMaxSize(),
smsModel = smsModel,
contactsModel = contactsModel,
dialerModel = dialerModel,
callModel = callModel,
themeModel = themeModel
)
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/bnyro/contacts/navigation/NavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.bnyro.contacts.presentation.screens.about.AboutScreen
import com.bnyro.contacts.presentation.screens.calllog.model.CallModel
import com.bnyro.contacts.presentation.screens.contacts.model.ContactsModel
import com.bnyro.contacts.presentation.screens.dialer.model.DialerModel
import com.bnyro.contacts.presentation.screens.settings.SettingsScreen
import com.bnyro.contacts.presentation.screens.settings.model.ThemeModel
import com.bnyro.contacts.presentation.screens.sms.SmsThreadScreen
Expand All @@ -29,7 +29,7 @@ fun AppNavHost(
initialTab: HomeRoutes,
smsModel: SmsModel,
contactsModel: ContactsModel,
dialerModel: DialerModel,
callModel: CallModel,
themeModel: ThemeModel
) {
val viewModelStoreOwner: ViewModelStoreOwner = LocalViewModelStoreOwner.current!!
Expand All @@ -53,7 +53,7 @@ fun AppNavHost(
},
smsModel = smsModel,
contactsModel = contactsModel,
dialerModel = dialerModel,
callModel = callModel,
themeModel = themeModel
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bnyro.contacts.presentation.screens.calllog
import android.content.ComponentName
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.telecom.PhoneAccountHandle
import android.telecom.TelecomManager
import android.text.format.DateUtils
Expand Down Expand Up @@ -44,8 +43,8 @@ import com.bnyro.contacts.presentation.components.NothingHere
import com.bnyro.contacts.presentation.components.NumberInput
import com.bnyro.contacts.presentation.components.PhoneNumberDisplay
import com.bnyro.contacts.presentation.features.ConfirmationDialog
import com.bnyro.contacts.presentation.screens.calllog.model.CallModel
import com.bnyro.contacts.presentation.screens.contacts.model.ContactsModel
import com.bnyro.contacts.presentation.screens.dialer.model.DialerModel
import com.bnyro.contacts.presentation.screens.editor.components.ContactIconPlaceholder
import com.bnyro.contacts.presentation.screens.settings.model.ThemeModel
import com.bnyro.contacts.util.CallLogHelper
Expand All @@ -57,7 +56,7 @@ import com.bnyro.contacts.util.extension.removeLastChar
@Composable
fun CallLogsScreen(
contactsModel: ContactsModel,
dialerModel: DialerModel,
dialerModel: CallModel,
themeModel: ThemeModel
) {
val context = LocalContext.current
Expand All @@ -72,32 +71,26 @@ fun CallLogsScreen(
mutableStateOf(emptyList<CallLogEntry>())
}
val subscriptions = remember {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
SmsUtil.getSubscriptions(context)
} else {
null
}
SmsUtil.getSubscriptions(context)
}

var chosenSubInfo = remember {
subscriptions?.firstOrNull()
subscriptions.firstOrNull()
}

fun callNumber(number: String) {
if (!PermissionHelper.checkPermissions(context, DialerModel.phonePerms)) return
if (!PermissionHelper.checkPermissions(context, CallModel.phonePerms)) return

val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:$number")).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
chosenSubInfo?.let {
val phoneAccountHandle = PhoneAccountHandle(
ComponentName(
"com.android.phone",
"com.android.services.telephony.TelephonyConnectionService"
),
it.subscriptionId.toString()
)
putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle)
}
chosenSubInfo?.let {
val phoneAccountHandle = PhoneAccountHandle(
ComponentName(
"com.android.phone",
"com.android.services.telephony.TelephonyConnectionService"
),
it.subscriptionId.toString()
)
putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle)
}
}
context.startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.bnyro.contacts.presentation.screens.calllog.model

import android.Manifest
import android.content.Context
import android.content.Intent
import android.telecom.TelecomManager
import androidx.lifecycle.ViewModel

class CallModel : ViewModel() {
var initialPhoneNumber: String? = null

fun requestDefaultDialerApp(context: Context) {
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager?
val isAlreadyDefaultDialer =
context.packageName.equals(telecomManager!!.defaultDialerPackage)
if (!isAlreadyDefaultDialer) {
val intent: Intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
.putExtra(
TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
context.packageName
)
context.startActivity(intent)
}
}

companion object {
val phonePerms = arrayOf(
Manifest.permission.CALL_PHONE,
Manifest.permission.READ_PHONE_STATE
)
}
}
Loading

0 comments on commit f21f6ea

Please sign in to comment.