From d229aa7a4f0dda8850eec418c31f54cf4cbdd4fa Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 20 Mar 2017 20:40:50 +0800 Subject: [PATCH] prevented crashes #729 --- .../library/twitter/model/Status.java | 6 +- twidere/build.gradle | 1 + twidere/src/main/AndroidManifest.xml | 12 +- .../model/util/ParcelableMediaUtils.java | 4 + .../CreateComposeShortcutActivity.kt | 23 +-- .../CreateQuickAccessShortcutActivity.kt | 131 ++++++++++++++++++ twidere/src/main/res/values/arrays.xml | 6 + .../main/res/values/arrays_no_translate.xml | 7 +- twidere/src/main/res/values/strings.xml | 1 + 9 files changed, 176 insertions(+), 15 deletions(-) rename twidere/src/main/kotlin/org/mariotaku/twidere/activity/{ => shortcut}/CreateComposeShortcutActivity.kt (74%) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/activity/shortcut/CreateQuickAccessShortcutActivity.kt diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Status.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Status.java index fb4f7cc05..83a9c9cdc 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Status.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Status.java @@ -112,10 +112,10 @@ public class Status extends TwitterResponseObject implements Comparable, @JsonField(name = "contributors") Contributor[] contributors; - @JsonField(name = "retweet_count") + @JsonField(name = {"retweet_count", "repeat_num"}) long retweetCount = -1; - @JsonField(name = "favorite_count") + @JsonField(name = {"favorite_count", "fave_num"}) long favoriteCount = -1; @JsonField(name = "reply_count") @@ -123,7 +123,7 @@ public class Status extends TwitterResponseObject implements Comparable, @JsonField(name = "favorited") boolean favorited; - @JsonField(name = "retweeted") + @JsonField(name = {"retweeted", "repeated"}) boolean retweeted; @JsonField(name = "lang") String lang; diff --git a/twidere/build.gradle b/twidere/build.gradle index 49befb6e2..ee2efbc51 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -175,6 +175,7 @@ dependencies { compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' 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:subsample-image-view:${libVersions['MediaViewerLibrary']}" diff --git a/twidere/src/main/AndroidManifest.xml b/twidere/src/main/AndroidManifest.xml index 4f8548ce4..36c759fe9 100644 --- a/twidere/src/main/AndroidManifest.xml +++ b/twidere/src/main/AndroidManifest.xml @@ -392,7 +392,7 @@ @@ -401,6 +401,16 @@ + + + + + + + - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * 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 . */ -package org.mariotaku.twidere.activity +package org.mariotaku.twidere.activity.shortcut import android.app.Activity import android.content.Intent import android.os.Bundle +import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_COMPOSE @@ -31,12 +32,14 @@ class CreateComposeShortcutActivity : Activity() { super.onCreate(savedInstanceState) setVisible(true) 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) - 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_NAME, getString(R.string.action_compose)) - setResult(Activity.RESULT_OK, intent) + setResult(RESULT_OK, intent) finish() } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/shortcut/CreateQuickAccessShortcutActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/shortcut/CreateQuickAccessShortcutActivity.kt new file mode 100644 index 000000000..a2757ec2d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/shortcut/CreateQuickAccessShortcutActivity.kt @@ -0,0 +1,131 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +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(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(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() + } + } + } + } +} diff --git a/twidere/src/main/res/values/arrays.xml b/twidere/src/main/res/values/arrays.xml index b007f862a..64c9ff252 100644 --- a/twidere/src/main/res/values/arrays.xml +++ b/twidere/src/main/res/values/arrays.xml @@ -73,4 +73,10 @@ Pure white/black Transparent + + User + List + User timeline + Favorite + diff --git a/twidere/src/main/res/values/arrays_no_translate.xml b/twidere/src/main/res/values/arrays_no_translate.xml index bbf214653..10eaf20f1 100644 --- a/twidere/src/main/res/values/arrays_no_translate.xml +++ b/twidere/src/main/res/values/arrays_no_translate.xml @@ -96,5 +96,10 @@ normal wide - + + user + list + user_timeline + favorite + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index b5d442025..59999b22f 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -1135,6 +1135,7 @@ Nicknames Open source license Twidere ∞ + Quick action Search Select users Set nickname