prevented crashes #729

This commit is contained in:
Mariotaku Lee 2017-03-20 20:40:50 +08:00
parent f3ebbc3c9e
commit d229aa7a4f
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
9 changed files with 176 additions and 15 deletions

View File

@ -112,10 +112,10 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
@JsonField(name = "contributors") @JsonField(name = "contributors")
Contributor[] contributors; Contributor[] contributors;
@JsonField(name = "retweet_count") @JsonField(name = {"retweet_count", "repeat_num"})
long retweetCount = -1; long retweetCount = -1;
@JsonField(name = "favorite_count") @JsonField(name = {"favorite_count", "fave_num"})
long favoriteCount = -1; long favoriteCount = -1;
@JsonField(name = "reply_count") @JsonField(name = "reply_count")
@ -123,7 +123,7 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
@JsonField(name = "favorited") @JsonField(name = "favorited")
boolean favorited; boolean favorited;
@JsonField(name = "retweeted") @JsonField(name = {"retweeted", "repeated"})
boolean retweeted; boolean retweeted;
@JsonField(name = "lang") @JsonField(name = "lang")
String lang; String lang;

View File

@ -175,6 +175,7 @@ dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'jp.wasabeef:glide-transformations:2.0.1' compile 'jp.wasabeef:glide-transformations:2.0.1'
compile 'info.debatty:java-string-similarity:0.23'
compile "com.github.mariotaku.MediaViewerLibrary:base:${libVersions['MediaViewerLibrary']}" compile "com.github.mariotaku.MediaViewerLibrary:base:${libVersions['MediaViewerLibrary']}"
compile "com.github.mariotaku.MediaViewerLibrary:subsample-image-view:${libVersions['MediaViewerLibrary']}" compile "com.github.mariotaku.MediaViewerLibrary:subsample-image-view:${libVersions['MediaViewerLibrary']}"

View File

@ -392,7 +392,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".activity.CreateComposeShortcutActivity" android:name=".activity.shortcut.CreateComposeShortcutActivity"
android:label="@string/title_compose" android:label="@string/title_compose"
android:theme="@style/Theme.Twidere.NoDisplay"> android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter> <intent-filter>
@ -401,6 +401,16 @@
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".activity.shortcut.CreateQuickAccessShortcutActivity"
android:label="@string/title_quick_action"
android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity <activity
android:name=".activity.RequestPermissionsActivity" android:name=".activity.RequestPermissionsActivity"
android:label="@string/permissions_request" android:label="@string/permissions_request"

View File

@ -139,6 +139,10 @@ public class ParcelableMediaUtils {
media.type = ParcelableMedia.Type.IMAGE; media.type = ParcelableMedia.Type.IMAGE;
} else if (mimeType.startsWith("video/")) { } else if (mimeType.startsWith("video/")) {
media.type = ParcelableMedia.Type.VIDEO; media.type = ParcelableMedia.Type.VIDEO;
} else {
// https://github.com/TwidereProject/Twidere-Android/issues/729
// Skip unsupported attachment
continue;
} }
media.width = attachment.getWidth(); media.width = attachment.getWidth();
media.height = attachment.getHeight(); media.height = attachment.getHeight();

View File

@ -1,7 +1,7 @@
/* /*
* Twidere - Twitter client for Android * Twidere - Twitter client for Android
* *
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com> * Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,11 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.mariotaku.twidere.activity package org.mariotaku.twidere.activity.shortcut
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_COMPOSE import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_COMPOSE
@ -31,12 +32,14 @@ class CreateComposeShortcutActivity : Activity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setVisible(true) setVisible(true)
val intent = Intent() val intent = Intent()
val launch_intent = Intent(INTENT_ACTION_COMPOSE) val launchIntent = Intent(INTENT_ACTION_COMPOSE).apply {
`package` = BuildConfig.VERSION_NAME
}
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher) val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launch_intent) intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon) intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.action_compose)) intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.action_compose))
setResult(Activity.RESULT_OK, intent) setResult(RESULT_OK, intent)
finish() finish()
} }
} }

View File

@ -0,0 +1,131 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.shortcut
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AlertDialog
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.AccountSelectorActivity
import org.mariotaku.twidere.activity.BaseActivity
import org.mariotaku.twidere.activity.UserSelectorActivity
import org.mariotaku.twidere.constant.nameFirstKey
import org.mariotaku.twidere.extension.applyTheme
import org.mariotaku.twidere.fragment.BaseDialogFragment
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.IntentUtils
class CreateQuickAccessShortcutActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
val df = QuickAccessShortcutTypeDialogFragment()
df.show(supportFragmentManager, "quick_access_shortcut_type")
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_SELECT_ACCOUNT -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val actionType = data.getBundleExtra(EXTRA_EXTRAS)?.getString(EXTRA_TYPE)
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) ?: run {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
when (actionType) {
"user" -> {
val selectUserIntent = Intent(this, UserSelectorActivity::class.java)
selectUserIntent.putExtra(EXTRA_ACCOUNT_KEY, accountKey)
startActivityForResult(selectUserIntent, REQUEST_SELECT_USER)
}
else -> {
setResult(Activity.RESULT_CANCELED)
finish()
}
}
}
REQUEST_SELECT_USER -> {
if (resultCode != Activity.RESULT_OK || data == null) {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER) ?: run {
setResult(Activity.RESULT_CANCELED)
finish()
return
}
val launchIntent = IntentUtils.userProfile(user.account_key, user.key,
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
val icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent)
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)
putExtra(Intent.EXTRA_SHORTCUT_NAME, userColorNameManager.getDisplayName(user,
preferences[nameFirstKey]))
})
finish()
}
}
}
private fun onItemSelected(which: Int) {
val actionType = resources.getStringArray(R.array.values_quick_access_shortcut_types)[which]
val selectAccountIntent = Intent(this, AccountSelectorActivity::class.java)
selectAccountIntent.putExtra(EXTRA_EXTRAS, Bundle {
this[EXTRA_TYPE] = actionType
})
if (actionType == "list") {
selectAccountIntent.putExtra(EXTRA_ACCOUNT_HOST, USER_TYPE_TWITTER_COM)
}
startActivityForResult(selectAccountIntent, REQUEST_SELECT_ACCOUNT)
}
class QuickAccessShortcutTypeDialogFragment : BaseDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(context)
builder.setItems(R.array.entries_quick_access_shortcut_types) { dialog, which ->
(activity as CreateQuickAccessShortcutActivity).onItemSelected(which)
}
return builder.create().apply {
setOnShowListener { it ->
it as AlertDialog
it.applyTheme()
}
}
}
}
}

View File

@ -73,4 +73,10 @@
<item>Pure white/black</item> <item>Pure white/black</item>
<item>Transparent</item> <item>Transparent</item>
</string-array> </string-array>
<string-array name="entries_quick_access_shortcut_types">
<item>User</item>
<item>List</item>
<item>User timeline</item>
<item>Favorite</item>
</string-array>
</resources> </resources>

View File

@ -96,5 +96,10 @@
<item>normal</item> <item>normal</item>
<item>wide</item> <item>wide</item>
</string-array> </string-array>
<string-array name="values_quick_access_shortcut_types">
<item>user</item>
<item>list</item>
<item>user_timeline</item>
<item>favorite</item>
</string-array>
</resources> </resources>

View File

@ -1135,6 +1135,7 @@
<string name="title_nicknames">Nicknames</string> <string name="title_nicknames">Nicknames</string>
<string name="title_open_source_license">Open source license</string> <string name="title_open_source_license">Open source license</string>
<string name="title_premium_features_name">Twidere ∞</string> <string name="title_premium_features_name">Twidere ∞</string>
<string name="title_quick_action">Quick action</string>
<string name="title_search">Search</string> <string name="title_search">Search</string>
<string name="title_select_users">Select users</string> <string name="title_select_users">Select users</string>
<string name="title_set_nickname">Set nickname</string> <string name="title_set_nickname">Set nickname</string>