From e98200217af5e7cce99e685ef1db381ad4a81dd9 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 23 Oct 2016 20:51:08 +0800 Subject: [PATCH] supports app shortcuts fixed npe --- build.gradle | 4 +- twidere.component.common/build.gradle | 2 +- twidere/build.gradle | 16 +++---- twidere/src/main/AndroidManifest.xml | 10 ++++ .../twidere/util/StatusCodeMessageUtils.java | 4 ++ .../org/mariotaku/twidere/util/Utils.java | 46 ++++--------------- .../fragment/ParcelableStatusesFragment.kt | 3 +- .../src/main/res/xml/compose_shortcuts.xml | 29 ++++++++++++ .../drawable/ic_app_shortcut_camera-mdpi.svg | 16 +++++++ .../drawable/ic_app_shortcut_compose-mdpi.svg | 13 ++++++ 10 files changed, 94 insertions(+), 49 deletions(-) create mode 100644 twidere/src/main/res/xml/compose_shortcuts.xml create mode 100644 twidere/src/main/svg/drawable/ic_app_shortcut_camera-mdpi.svg create mode 100644 twidere/src/main/svg/drawable/ic_app_shortcut_compose-mdpi.svg diff --git a/build.gradle b/build.gradle index 1563859e0..66745b2e0 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.google.gms:google-services:3.0.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath('fr.avianey.androidsvgdrawable:gradle-plugin:3.0.0') { @@ -34,7 +34,7 @@ subprojects { if (project.hasProperty('android')) { android { - compileSdkVersion 24 + compileSdkVersion 25 buildToolsVersion '24.0.1' lintOptions { diff --git a/twidere.component.common/build.gradle b/twidere.component.common/build.gradle index 9c954123d..a6252da81 100644 --- a/twidere.component.common/build.gradle +++ b/twidere.component.common/build.gradle @@ -39,7 +39,7 @@ dependencies { apt 'com.bluelinelabs:logansquare-compiler:1.3.7' apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2' apt 'com.github.mariotaku.ObjectCursor:processor:0.9.9' - compile 'com.android.support:support-annotations:24.2.1' + compile 'com.android.support:support-annotations:25.0.0' compile 'com.bluelinelabs:logansquare:1.3.7' compile 'com.github.mariotaku.RestFu:library:0.9.34' compile 'com.github.mariotaku.RestFu:oauth:0.9.34' diff --git a/twidere/build.gradle b/twidere/build.gradle index b54c09af4..2ed9bc493 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -34,7 +34,7 @@ android { defaultConfig { applicationId "org.mariotaku.twidere" minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 212 versionName '3.2.8' multiDexEnabled true @@ -120,17 +120,17 @@ dependencies { testCompile 'junit:junit:4.12' - androidTestCompile 'com.android.support:support-annotations:24.2.1' + androidTestCompile 'com.android.support:support-annotations:25.0.0' androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:rules:0.5' compile 'com.android.support:multidex:1.0.1' - compile 'com.android.support:support-v4:24.2.1' - compile 'com.android.support:appcompat-v7:24.2.1' - compile 'com.android.support:cardview-v7:24.2.1' - compile 'com.android.support:recyclerview-v7:24.2.1' - compile 'com.android.support:preference-v7:24.2.1' - compile 'com.android.support:preference-v14:24.2.1' + compile 'com.android.support:support-v4:25.0.0' + compile 'com.android.support:appcompat-v7:25.0.0' + compile 'com.android.support:cardview-v7:25.0.0' + compile 'com.android.support:recyclerview-v7:25.0.0' + compile 'com.android.support:preference-v7:25.0.0' + compile 'com.android.support:preference-v14:25.0.0' compile 'com.twitter:twitter-text:1.13.0' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0' diff --git a/twidere/src/main/AndroidManifest.xml b/twidere/src/main/AndroidManifest.xml index 1ea0131b7..7d51911f1 100644 --- a/twidere/src/main/AndroidManifest.xml +++ b/twidere/src/main/AndroidManifest.xml @@ -119,6 +119,10 @@ + + + + + + diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusCodeMessageUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusCodeMessageUtils.java index a944cb98b..39e23062e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusCodeMessageUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusCodeMessageUtils.java @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util; import android.content.Context; +import android.support.annotation.Nullable; import android.util.SparseIntArray; import org.mariotaku.microblog.library.twitter.model.ErrorInfo; @@ -66,6 +67,7 @@ public class StatusCodeMessageUtils { return TWITTER_ERROR_CODE_MESSAGES.get(code, -1) != -1; } + @Nullable public static String getHttpStatusMessage(final Context context, final int code) { if (context == null) return null; final int res_id = HTTP_STATUS_CODE_MESSAGES.get(code, -1); @@ -73,12 +75,14 @@ public class StatusCodeMessageUtils { return null; } + @Nullable public static String getMessage(final Context context, final int statusCode, final int errorCode) { if (containsHttpStatus(statusCode)) return getHttpStatusMessage(context, statusCode); if (containsTwitterError(errorCode)) return getTwitterErrorMessage(context, errorCode); return null; } + @Nullable public static String getTwitterErrorMessage(final Context context, final int code) { if (context == null) return null; final int resId = TWITTER_ERROR_CODE_MESSAGES.get(code, -1); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 99686fe83..3091d38f9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -47,7 +47,6 @@ import android.net.Uri; import android.nfc.NfcAdapter; import android.nfc.NfcAdapter.CreateNdefMessageCallback; import android.os.AsyncTask; -import android.os.BadParcelableException; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; @@ -59,7 +58,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.annotation.WorkerThread; -import android.support.v4.app.Fragment; import android.support.v4.net.ConnectivityManagerCompat; import android.support.v4.view.GravityCompat; import android.support.v4.view.accessibility.AccessibilityEventCompat; @@ -109,38 +107,6 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.CopyLinkActivity; import org.mariotaku.twidere.adapter.iface.IBaseAdapter; import org.mariotaku.twidere.annotation.CustomTabType; -import org.mariotaku.twidere.fragment.AccountsManagerFragment; -import org.mariotaku.twidere.fragment.DirectMessagesFragment; -import org.mariotaku.twidere.fragment.DraftsFragment; -import org.mariotaku.twidere.fragment.FiltersFragment; -import org.mariotaku.twidere.fragment.GroupFragment; -import org.mariotaku.twidere.fragment.IncomingFriendshipsFragment; -import org.mariotaku.twidere.fragment.InteractionsTimelineFragment; -import org.mariotaku.twidere.fragment.ItemsListFragment; -import org.mariotaku.twidere.fragment.ListsFragment; -import org.mariotaku.twidere.fragment.MessagesConversationFragment; -import org.mariotaku.twidere.fragment.MutesUsersListFragment; -import org.mariotaku.twidere.fragment.PublicTimelineFragment; -import org.mariotaku.twidere.fragment.SavedSearchesListFragment; -import org.mariotaku.twidere.fragment.SearchFragment; -import org.mariotaku.twidere.fragment.StatusFavoritersListFragment; -import org.mariotaku.twidere.fragment.StatusFragment; -import org.mariotaku.twidere.fragment.StatusRetweetersListFragment; -import org.mariotaku.twidere.fragment.UserBlocksListFragment; -import org.mariotaku.twidere.fragment.UserFavoritesFragment; -import org.mariotaku.twidere.fragment.UserFollowersFragment; -import org.mariotaku.twidere.fragment.UserFragment; -import org.mariotaku.twidere.fragment.UserFriendsFragment; -import org.mariotaku.twidere.fragment.UserGroupsFragment; -import org.mariotaku.twidere.fragment.UserListFragment; -import org.mariotaku.twidere.fragment.UserListMembersFragment; -import org.mariotaku.twidere.fragment.UserListMembershipsFragment; -import org.mariotaku.twidere.fragment.UserListSubscribersFragment; -import org.mariotaku.twidere.fragment.UserListTimelineFragment; -import org.mariotaku.twidere.fragment.UserMediaTimelineFragment; -import org.mariotaku.twidere.fragment.UserMentionsFragment; -import org.mariotaku.twidere.fragment.UserProfileEditorFragment; -import org.mariotaku.twidere.fragment.UserTimelineFragment; import org.mariotaku.twidere.graphic.PaddingDrawable; import org.mariotaku.twidere.model.AccountPreferences; import org.mariotaku.twidere.model.ParcelableAccount; @@ -647,12 +613,17 @@ public final class Utils implements Constants { if (t instanceof MicroBlogException) return getTwitterErrorMessage(context, action, (MicroBlogException) t); else if (t != null) return getErrorMessage(context, trimLineBreak(t.getMessage())); + TwidereBugReporter.logException(new IllegalStateException()); return context.getString(R.string.error_unknown_error); } - public static String getErrorMessage(final Context context, final Throwable t) { - if (t == null) return null; - if (context != null && t instanceof MicroBlogException) + @Nullable + public static String getErrorMessage(@NonNull final Context context, final Throwable t) { + if (t == null) { + TwidereBugReporter.logException(new IllegalStateException()); + return context.getString(R.string.error_unknown_error); + } + if (t instanceof MicroBlogException) return getTwitterErrorMessage(context, (MicroBlogException) t); return t.getMessage(); } @@ -900,6 +871,7 @@ public final class Utils implements Constants { return getErrorMessage(context, action, trimLineBreak(te.getMessage())); } + @Nullable public static String getTwitterErrorMessage(final Context context, final MicroBlogException te) { if (te == null) return null; if (StatusCodeMessageUtils.containsTwitterError(te.getErrorCode())) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt index 9f8da925b..d03b1b058 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt @@ -133,7 +133,8 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() { } else if (loader is MicroBlogAPIStatusesLoader) { val e = loader.exception if (e != null) { - showError(R.drawable.ic_info_error_generic, Utils.getErrorMessage(context, e)) + showError(R.drawable.ic_info_error_generic, Utils.getErrorMessage(context, e) ?: + context.getString(R.string.error_unknown_error)) } else { showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh)) } diff --git a/twidere/src/main/res/xml/compose_shortcuts.xml b/twidere/src/main/res/xml/compose_shortcuts.xml new file mode 100644 index 000000000..341f35323 --- /dev/null +++ b/twidere/src/main/res/xml/compose_shortcuts.xml @@ -0,0 +1,29 @@ + + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/svg/drawable/ic_app_shortcut_camera-mdpi.svg b/twidere/src/main/svg/drawable/ic_app_shortcut_camera-mdpi.svg new file mode 100644 index 000000000..cc2f41ccb --- /dev/null +++ b/twidere/src/main/svg/drawable/ic_app_shortcut_camera-mdpi.svg @@ -0,0 +1,16 @@ + + + + ic_app_shortcut_camera-mdpi + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/svg/drawable/ic_app_shortcut_compose-mdpi.svg b/twidere/src/main/svg/drawable/ic_app_shortcut_compose-mdpi.svg new file mode 100644 index 000000000..e558638b7 --- /dev/null +++ b/twidere/src/main/svg/drawable/ic_app_shortcut_compose-mdpi.svg @@ -0,0 +1,13 @@ + + + + ic_app_shortcut_compose-mdpi + Created with Sketch. + + + + + + + + \ No newline at end of file