Skip to content

Commit

Permalink
Vibrate and show toast when SIM is manually changed
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Mar 1, 2020
1 parent 70275b2 commit 582a823
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SMS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {

sim.setVisible(state.subscription != null)
sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
simIndex.text = state.subscription?.simSlotIndex?.plus(1)?.toString()

send.isEnabled = state.canSend
send.imageAlpha = if (state.canSend) 255 else 128
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ package com.moez.QKSMS.feature.compose

import android.content.Context
import android.net.Uri
import android.os.Vibrator
import android.provider.ContactsContract
import android.telephony.SmsMessage
import androidx.core.content.getSystemService
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel
Expand Down Expand Up @@ -616,6 +618,13 @@ class ComposeViewModel @Inject constructor(
subIndex < subs.size - 1 -> subs[subIndex + 1]
else -> subs[0]
}

if (subscription != null) {
context.getSystemService<Vibrator>()?.vibrate(40)
context.makeToast(context.getString(R.string.compose_sim_changed_toast,
subscription.simSlotIndex + 1, subscription.displayName))
}

newState { copy(subscription = subscription) }
}
.autoDisposable(view.scope())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class MessagesAdapter @Inject constructor(
val subscription = subs.find { sub -> sub.subscriptionId == message.subId }

holder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
holder.simIndex.text = subscription?.let { sub -> sub.simSlotIndex + 1 }?.toString()
holder.simIndex.text = subscription?.simSlotIndex?.plus(1)?.toString()

holder.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|| message.subId != previous?.subId && subscription != null)
Expand Down
2 changes: 2 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<string name="compose_schedule_cd">Schedule message</string>
<string name="compose_contact_cd">Attach a contact</string>
<string name="compose_contact_error">Error reading contact</string>
<!-- Example: SIM 1 (Verizon) selected-->
<string name="compose_sim_changed_toast">SIM %1$d (%2$s) selected</string>
<string name="compose_sim_cd">%s selected, change SIM card</string>
<string name="compose_send_cd">Send message</string>

Expand Down

0 comments on commit 582a823

Please sign in to comment.