Skip to content

Commit 2db6ffb

Browse files
committed
use the new way of launching activity intents
1 parent 57be93b commit 2db6ffb

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class ThreadActivity : SimpleActivity() {
543543
var hadUnreadItems = false
544544
val cnt = messages.size
545545
for (i in 0 until cnt) {
546-
val message = messages[i]
546+
val message = messages.getOrNull(i) ?: continue
547547
// do not show the date/time above every message, only if the difference between the 2 messages is at least MIN_DATE_TIME_DIFF_SECS
548548
if (message.date - prevDateTime > MIN_DATE_TIME_DIFF_SECS) {
549549
val simCardID = subscriptionIdToSimId[message.subscriptionId] ?: "?"

app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.simplemobiletools.smsmessenger.adapters
22

3+
import android.content.ActivityNotFoundException
34
import android.content.Intent
45
import android.graphics.Typeface
56
import android.net.Uri
@@ -26,8 +27,10 @@ import com.simplemobiletools.smsmessenger.helpers.refreshMessages
2627
import com.simplemobiletools.smsmessenger.models.Conversation
2728
import kotlinx.android.synthetic.main.item_conversation.view.*
2829

29-
class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayList<Conversation>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
30-
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
30+
class ConversationsAdapter(
31+
activity: SimpleActivity, var conversations: ArrayList<Conversation>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
32+
itemClick: (Any) -> Unit
33+
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
3134
private var fontSize = activity.getTextSize()
3235

3336
init {
@@ -120,11 +123,13 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
120123
Intent(Intent.ACTION_DIAL).apply {
121124
data = Uri.fromParts("tel", conversation.phoneNumber, null)
122125

123-
if (resolveActivity(activity.packageManager) != null) {
126+
try {
124127
activity.startActivity(this)
125128
finishActMode()
126-
} else {
129+
} catch (e: ActivityNotFoundException) {
127130
activity.toast(R.string.no_app_found)
131+
} catch (e: Exception) {
132+
activity.showErrorToast(e)
128133
}
129134
}
130135
}
@@ -185,12 +190,7 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
185190
action = Intent.ACTION_INSERT_OR_EDIT
186191
type = "vnd.android.cursor.item/contact"
187192
putExtra(KEY_PHONE, conversation.phoneNumber)
188-
189-
if (resolveActivity(activity.packageManager) != null) {
190-
activity.startActivity(this)
191-
} else {
192-
activity.toast(R.string.no_app_found)
193-
}
193+
activity.launchActivityIntent(this)
194194
}
195195
}
196196

app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.simplemobiletools.smsmessenger.adapters
22

33
import android.annotation.SuppressLint
4+
import android.content.ActivityNotFoundException
45
import android.content.Intent
56
import android.graphics.drawable.Drawable
67
import android.net.Uri
@@ -315,15 +316,17 @@ class ThreadAdapter(
315316
setDataAndType(uri, mimetype)
316317
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
317318

318-
if (resolveActivity(activity.packageManager) != null) {
319+
try {
319320
activity.startActivity(this)
320-
} else {
321+
} catch (e: ActivityNotFoundException) {
321322
val newMimetype = filename.getMimeType()
322323
if (newMimetype.isNotEmpty() && mimetype != newMimetype) {
323324
launchViewIntent(uri, newMimetype, filename)
324325
} else {
325326
activity.toast(R.string.no_app_found)
326327
}
328+
} catch (e: Exception) {
329+
activity.showErrorToast(e)
327330
}
328331
}
329332
}

0 commit comments

Comments
 (0)