add a button for setting the app as the default Phone app at the Recents

This commit is contained in:
tibbi 2018-11-29 16:44:53 +01:00
parent 25c9c0d598
commit 02198f572e
1 changed files with 15 additions and 4 deletions

View File

@ -1,12 +1,16 @@
package com.simplemobiletools.contacts.pro.fragments package com.simplemobiletools.contacts.pro.fragments
import android.annotation.TargetApi
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.telecom.TelecomManager
import android.util.AttributeSet import android.util.AttributeSet
import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.hasPermission import com.simplemobiletools.commons.extensions.hasPermission
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
import com.simplemobiletools.contacts.pro.activities.EditContactActivity import com.simplemobiletools.contacts.pro.activities.EditContactActivity
import com.simplemobiletools.contacts.pro.adapters.RecentCallsAdapter import com.simplemobiletools.contacts.pro.adapters.RecentCallsAdapter
import com.simplemobiletools.contacts.pro.extensions.contactClicked import com.simplemobiletools.contacts.pro.extensions.contactClicked
@ -21,7 +25,10 @@ import kotlinx.android.synthetic.main.fragment_layout.view.*
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() {} override fun fabClicked() {}
@TargetApi(Build.VERSION_CODES.M)
override fun placeholderClicked() { override fun placeholderClicked() {
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
if (!isMarshmallowPlus() || (isMarshmallowPlus() && telecomManager.defaultDialerPackage == context.packageName)) {
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) { activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
if (it) { if (it) {
activity!!.handlePermission(PERMISSION_READ_CALL_LOG) { activity!!.handlePermission(PERMISSION_READ_CALL_LOG) {
@ -29,6 +36,10 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} }
} }
} }
} else {
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, context.packageName)
context.startActivity(intent)
}
} }
fun updateRecentCalls(recentCalls: ArrayList<RecentCall>) { fun updateRecentCalls(recentCalls: ArrayList<RecentCall>) {