-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
336 additions
and
32 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
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
81 changes: 81 additions & 0 deletions
81
app/src/main/kotlin/com/goodwy/dialer/dialogs/SelectSimButtonDialog.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,81 @@ | ||
package com.goodwy.dialer.dialogs | ||
|
||
import android.telecom.PhoneAccountHandle | ||
import androidx.appcompat.app.AlertDialog | ||
import com.goodwy.commons.activities.BaseSimpleActivity | ||
import com.goodwy.commons.extensions.* | ||
import com.goodwy.dialer.R | ||
import com.goodwy.dialer.databinding.DialogSelectSimButtonBinding | ||
import com.goodwy.dialer.extensions.config | ||
import com.goodwy.dialer.extensions.getAvailableSIMCardLabels | ||
|
||
class SelectSimButtonDialog( | ||
val activity: BaseSimpleActivity, | ||
val phoneNumber: String, | ||
onDismiss: () -> Unit = {}, | ||
val callback: (handle: PhoneAccountHandle?, label: String?) -> Unit | ||
) { | ||
private var dialog: AlertDialog? = null | ||
private val binding by activity.viewBinding(DialogSelectSimButtonBinding::inflate) | ||
|
||
init { | ||
|
||
val textColor = activity.baseConfig.simIconsColors[1].getContrastColor() | ||
|
||
activity.getAvailableSIMCardLabels().forEachIndexed { index, SIMAccount -> | ||
val indexText = index + 1 | ||
if (indexText == 1) { | ||
binding.sim1Button.apply { | ||
val drawable = resources.getColoredDrawableWithColor(activity, R.drawable.button_gray_bg, activity.baseConfig.simIconsColors[1]) | ||
background = drawable | ||
setPadding(2, 2, 2, 2) | ||
setTextColor(textColor) | ||
setOnClickListener { selectedSIM(SIMAccount.handle, SIMAccount.label) } | ||
} | ||
} else if (indexText == 2) { | ||
binding.sim2Button.apply { | ||
val drawable = resources.getColoredDrawableWithColor(activity, R.drawable.button_gray_bg, activity.baseConfig.simIconsColors[2]) | ||
background = drawable | ||
setPadding(2,2,2,2) | ||
setTextColor(textColor) | ||
setOnClickListener { selectedSIM(SIMAccount.handle, SIMAccount.label) } | ||
} | ||
} | ||
} | ||
|
||
activity.getAlertDialogBuilder() | ||
.apply { | ||
val title = activity.getString(R.string.select_sim) | ||
activity.setupDialogStuff(binding.root, this, titleText = title) { alertDialog -> | ||
dialog = alertDialog | ||
} | ||
} | ||
|
||
dialog?.setOnDismissListener { | ||
onDismiss() | ||
} | ||
|
||
binding.cancelButton.apply { | ||
val drawable = resources.getColoredDrawableWithColor(activity, R.drawable.button_gray_bg, 0xFFEB5545.toInt()) | ||
background = drawable | ||
setPadding(2,2,2,2) | ||
setTextColor(textColor) | ||
setOnClickListener { | ||
dialog?.dismiss() | ||
} | ||
} | ||
|
||
binding.selectSimRememberHolder.setOnClickListener { | ||
binding.selectSimRemember.toggle() | ||
} | ||
} | ||
|
||
private fun selectedSIM(handle: PhoneAccountHandle, label: String) { | ||
if (binding.selectSimRemember.isChecked) { | ||
activity.config.saveCustomSIM(phoneNumber, handle) | ||
} | ||
|
||
callback(handle, label) | ||
dialog?.dismiss() | ||
} | ||
} |
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
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.