Skip to content

Commit b16d619

Browse files
Extract logic to check for available phone contact options
1 parent 8bff5bb commit b16d619

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.woocommerce.android.util
2+
3+
import android.content.Context
4+
import androidx.annotation.StringRes
5+
import com.woocommerce.android.R
6+
7+
private const val WHATSAPP_PACKAGE_NAME = "com.whatsapp"
8+
private const val TELEGRAM_PACKAGE_NAME = "org.telegram.messenger"
9+
10+
fun Context.getAvailablePhoneContactOptions(): List<PhoneContactOption> {
11+
return buildList {
12+
add(PhoneContactOption.CALL)
13+
add(PhoneContactOption.SMS)
14+
if (ActivityUtils.isAppInstalled(this@getAvailablePhoneContactOptions, WHATSAPP_PACKAGE_NAME)) {
15+
add(PhoneContactOption.WHATSAPP)
16+
}
17+
if (ActivityUtils.isAppInstalled(this@getAvailablePhoneContactOptions, TELEGRAM_PACKAGE_NAME)) {
18+
add(PhoneContactOption.TELEGRAM)
19+
}
20+
}
21+
}
22+
23+
enum class PhoneContactOption {
24+
CALL, SMS, WHATSAPP, TELEGRAM
25+
}
26+
27+
val PhoneContactOption.stringRes: Int
28+
@StringRes get() = when (this) {
29+
PhoneContactOption.CALL -> R.string.orderdetail_call_customer
30+
PhoneContactOption.SMS -> R.string.orderdetail_message_customer
31+
PhoneContactOption.WHATSAPP -> R.string.orderdetail_message_customer_using_whatsapp
32+
PhoneContactOption.TELEGRAM -> R.string.orderdetail_message_customer_using_telegram
33+
}

0 commit comments

Comments
 (0)