-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for using contact groups in record rules
This is unfortunately a relatively big change because unlike single contacts, Android does not provide a standard intent for apps to select a contact group. We have to implement our own contact group picker UI. Following our current convention, the most specific rule wins as a side effect of how rules are sorted. If a call matches both a contact and a contact group, the contact rule has higher precedence. Fixes: #536 Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
- Loading branch information
1 parent
45f113c
commit 48cb283
Showing
34 changed files
with
746 additions
and
314 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
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/chiller3/bcr/PreferenceBaseActivity.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,65 @@ | ||
package com.chiller3.bcr | ||
|
||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.view.ViewGroup | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.core.view.updateLayoutParams | ||
import androidx.fragment.app.Fragment | ||
import com.chiller3.bcr.databinding.SettingsActivityBinding | ||
|
||
abstract class PreferenceBaseActivity : AppCompatActivity() { | ||
protected abstract val titleResId: Int | ||
|
||
protected abstract val showUpButton: Boolean | ||
|
||
protected abstract fun createFragment(): Fragment | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
enableEdgeToEdge() | ||
super.onCreate(savedInstanceState) | ||
|
||
val binding = SettingsActivityBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
if (savedInstanceState == null) { | ||
supportFragmentManager | ||
.beginTransaction() | ||
.replace(R.id.settings, createFragment()) | ||
.commit() | ||
} | ||
|
||
ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar) { v, windowInsets -> | ||
val insets = windowInsets.getInsets( | ||
WindowInsetsCompat.Type.systemBars() | ||
or WindowInsetsCompat.Type.displayCutout() | ||
) | ||
|
||
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
leftMargin = insets.left | ||
topMargin = insets.top | ||
rightMargin = insets.right | ||
} | ||
|
||
WindowInsetsCompat.CONSUMED | ||
} | ||
|
||
setSupportActionBar(binding.toolbar) | ||
supportActionBar!!.setDisplayHomeAsUpEnabled(showUpButton) | ||
|
||
setTitle(titleResId) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
android.R.id.home -> { | ||
onBackPressedDispatcher.onBackPressed() | ||
true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/chiller3/bcr/PreferenceBaseFragment.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,43 @@ | ||
package com.chiller3.bcr | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.core.view.updatePadding | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
abstract class PreferenceBaseFragment : PreferenceFragmentCompat() { | ||
override fun onCreateRecyclerView( | ||
inflater: LayoutInflater, | ||
parent: ViewGroup, | ||
savedInstanceState: Bundle? | ||
): RecyclerView { | ||
val view = super.onCreateRecyclerView(inflater, parent, savedInstanceState) | ||
|
||
view.clipToPadding = false | ||
|
||
ViewCompat.setOnApplyWindowInsetsListener(view) { v, windowInsets -> | ||
val insets = windowInsets.getInsets( | ||
WindowInsetsCompat.Type.systemBars() | ||
or WindowInsetsCompat.Type.displayCutout() | ||
) | ||
|
||
// This is a little bit ugly in landscape mode because the divider lines for categories | ||
// extend into the inset area. However, it's worth applying the left/right padding here | ||
// anyway because it allows the inset area to be used for scrolling instead of just | ||
// being a useless dead zone. | ||
v.updatePadding( | ||
bottom = insets.bottom, | ||
left = insets.left, | ||
right = insets.right, | ||
) | ||
|
||
WindowInsetsCompat.CONSUMED | ||
} | ||
|
||
return view | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/chiller3/bcr/rule/PickContactGroup.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,25 @@ | ||
package com.chiller3.bcr.rule | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.activity.result.contract.ActivityResultContract | ||
import androidx.core.content.IntentCompat | ||
import com.chiller3.bcr.ContactGroupInfo | ||
|
||
/** Launch our own picker for contact groups. There is no standard Android component for this. */ | ||
class PickContactGroup : ActivityResultContract<Void?, ContactGroupInfo?>() { | ||
override fun createIntent(context: Context, input: Void?): Intent { | ||
return Intent(context, PickContactGroupActivity::class.java) | ||
} | ||
|
||
override fun parseResult(resultCode: Int, intent: Intent?): ContactGroupInfo? { | ||
return intent.takeIf { resultCode == Activity.RESULT_OK }?.let { | ||
IntentCompat.getParcelableExtra( | ||
it, | ||
PickContactGroupActivity.RESULT_CONTACT_GROUP, | ||
ContactGroupInfo::class.java, | ||
) | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/chiller3/bcr/rule/PickContactGroupActivity.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,17 @@ | ||
package com.chiller3.bcr.rule | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.chiller3.bcr.PreferenceBaseActivity | ||
import com.chiller3.bcr.R | ||
|
||
class PickContactGroupActivity : PreferenceBaseActivity() { | ||
override val titleResId: Int = R.string.pick_contact_group_title | ||
|
||
override val showUpButton: Boolean = true | ||
|
||
override fun createFragment(): Fragment = PickContactGroupFragment() | ||
|
||
companion object { | ||
const val RESULT_CONTACT_GROUP = "contact_group" | ||
} | ||
} |
Oops, something went wrong.