fixed crashes
This commit is contained in:
parent
8283c03bdb
commit
bab999a151
|
@ -1,5 +1,6 @@
|
|||
package org.mariotaku.ktextension
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.support.v4.content.ContextCompat
|
||||
|
@ -15,3 +16,13 @@ fun Context.checkAllSelfPermissionsGranted(vararg permissions: String): Boolean
|
|||
fun Context.checkAnySelfPermissionsGranted(vararg permissions: String): Boolean {
|
||||
return permissions.any { ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED }
|
||||
}
|
||||
|
||||
fun Context.unregisterReceiverSafe(receiver: BroadcastReceiver?): Boolean {
|
||||
if (receiver == null) return false
|
||||
try {
|
||||
unregisterReceiver(receiver)
|
||||
return true
|
||||
} catch (e: IllegalArgumentException) {
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ import org.mariotaku.chameleon.Chameleon
|
|||
import org.mariotaku.chameleon.ChameleonActivity
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.unregisterReceiverSafe
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME
|
||||
|
@ -272,7 +273,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
|
|||
|
||||
override fun onPause() {
|
||||
|
||||
unregisterReceiver(nightTimeChangedReceiver)
|
||||
unregisterReceiverSafe(nightTimeChangedReceiver)
|
||||
|
||||
val adapter = NfcAdapter.getDefaultAdapter(this)
|
||||
if (adapter != null && adapter.isEnabled) {
|
||||
|
|
|
@ -76,15 +76,15 @@ private fun MicroBlog.showUserAlternative(id: String?, screenName: String?): Use
|
|||
}
|
||||
val paging = Paging().count(1)
|
||||
val users = searchUsers(searchScreenName, paging)
|
||||
val match = users.first { it.id == id || searchScreenName.equals(it.screenName, ignoreCase = true) }
|
||||
val match = users.firstOrNull { it.id == id || searchScreenName.equals(it.screenName, ignoreCase = true) }
|
||||
if (match != null) return match
|
||||
if (id != null) {
|
||||
val timeline = getUserTimeline(id, paging, null)
|
||||
val status = timeline.first { it.user?.id == id }
|
||||
val status = timeline.firstOrNull { it.user?.id == id }
|
||||
if (status != null) return status.user
|
||||
} else {
|
||||
val timeline = getUserTimelineByScreenName(searchScreenName, paging, null)
|
||||
val status = timeline.first { searchScreenName.equals(it.user?.screenName, ignoreCase = true) }
|
||||
val status = timeline.firstOrNull { searchScreenName.equals(it.user?.screenName, ignoreCase = true) }
|
||||
if (status != null) return status.user
|
||||
}
|
||||
throw MicroBlogException("Can't find user")
|
||||
|
|
|
@ -422,7 +422,7 @@ class GetMessagesTask(
|
|||
conversation.conversation_avatar = v.avatarImageHttps
|
||||
conversation.request_cursor = response.cursor
|
||||
conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.TWITTER_OFFICIAL
|
||||
val myLastReadEventId = v.participants.first { it.userId == accountKey.id }?.lastReadEventId
|
||||
val myLastReadEventId = v.participants.firstOrNull { it.userId == accountKey.id }?.lastReadEventId
|
||||
// Find recent message timestamp
|
||||
val myLastReadTimestamp = messagesMap.findLastReadTimestamp(k, myLastReadEventId)
|
||||
|
||||
|
|
Loading…
Reference in New Issue