crash fixes

This commit is contained in:
Mariotaku Lee 2017-05-05 23:49:46 +08:00
parent f0b844c102
commit 9c92c88783
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 14 additions and 7 deletions

View File

@ -258,7 +258,9 @@ public class MicroBlogException extends Exception implements TwitterResponse, Ht
@Override
public String toString() {
return getMessage();
final String message = getMessage();
if (message == null) return getClass().getSimpleName();
return message;
}
public String getErrorMessage() {

View File

@ -350,8 +350,10 @@ class MediaViewerActivity : BaseActivity(), IMediaViewerActivity, MediaSwipeClos
ParcelableMedia.Type.EXTERNAL_PLAYER -> {
return Fragment.instantiate(this, ExternalBrowserPageFragment::class.java.name, args) as MediaViewerFragment
}
else -> {
return Fragment.instantiate(this, ExternalBrowserPageFragment::class.java.name, args) as MediaViewerFragment
}
}
throw UnsupportedOperationException(media.toString())
}
override fun getMediaCount(): Int {

View File

@ -53,5 +53,5 @@ private fun MicroBlogException.getMicroBlogErrorMessage(context: Context): Strin
} else {
errorMessage
}
return msg ?: message ?: toString()
return msg ?: message ?: javaClass.simpleName
}

View File

@ -20,6 +20,7 @@
package org.mariotaku.twidere.util
import android.graphics.Typeface
import android.net.Uri
import android.text.Editable
import android.text.Spannable
import android.text.SpannableStringBuilder

View File

@ -271,10 +271,12 @@ object Utils {
return File(context.cacheDir, cacheDirName)
}
fun getExternalCacheDir(context: Context?, cacheDirName: String,
sizeInBytes: Long): File? {
if (context == null) throw NullPointerException()
val externalCacheDir = context.externalCacheDir ?: return null
fun getExternalCacheDir(context: Context, cacheDirName: String, sizeInBytes: Long): File? {
val externalCacheDir = try {
context.externalCacheDir
} catch (e: SecurityException) {
null
} ?: return null
val cacheDir = File(externalCacheDir, cacheDirName)
if (sizeInBytes > 0 && externalCacheDir.freeSpace < sizeInBytes / 10) {
// Less then 10% space available