improved launch speed #339

fixed twitter media handling
This commit is contained in:
Mariotaku Lee 2016-02-09 16:02:08 +08:00
parent 967d2e7277
commit 58cb88caed
29 changed files with 298 additions and 308 deletions

View File

@ -56,7 +56,7 @@ script: ./gradlew build --no-daemon --stacktrace
deploy:
provider: releases
prerelease: false
prerelease: true
api_key:
secure: WKtKwda3hegqO9QVujdonNoL2ESJUR80WHNq/13wDsbCABo/GNnuqHNYZmml3wAifEKKeCEYfNZRUuHQ8eHs54Lj5BlGRX5i+1LrGhhgnVFQgmrhIv4RJuVQ663kDEh+Jwo4vowJ2mxNDvLvOhfZwxjULPDiknqy6u5PyW3id5M=
file_glob: true

View File

@ -1,32 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 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.common;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@ -10,7 +10,7 @@ import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.util.HtmlLinkExtractor;
import org.mariotaku.twidere.util.media.preview.provider.InstagramProvider;
import org.mariotaku.twidere.util.media.preview.provider.Provider;
import org.mariotaku.twidere.util.media.preview.provider.TwitterPicProvider;
import org.mariotaku.twidere.util.media.preview.provider.TwitterMediaProvider;
import java.io.IOException;
import java.util.ArrayList;
@ -24,7 +24,7 @@ public class PreviewMediaExtractor {
private static final Provider[] sProviders = {
new InstagramProvider(),
new TwitterPicProvider()
new TwitterMediaProvider()
};
@Nullable
@ -81,4 +81,19 @@ public class PreviewMediaExtractor {
}
return link.substring(start + 3, end);
}
@Nullable
public static String getPath(@NonNull String link) {
int start = link.indexOf("://");
if (start < 0) return null;
start = link.indexOf('/', start + 3);
if (start < 0) {
return "";
}
int end = link.indexOf('?', start);
if (end < 0) {
end = link.length();
}
return link.substring(start, end);
}
}

View File

@ -12,26 +12,31 @@ import java.util.Locale;
/**
* Created by darkwhite on 1/16/16.
*/
public class TwitterPicProvider implements Provider {
public class TwitterMediaProvider implements Provider {
@Override
public boolean supports(@NonNull String link) {
final String authority = PreviewMediaExtractor.getAuthority(link);
if (authority == null) return false;
return authority.endsWith(".twimg.com") && !link.contains("/tweet_video");
return authority != null && authority.endsWith(".twimg.com");
}
@Nullable
@Override
public ParcelableMedia from(@NonNull String link) {
final String path = PreviewMediaExtractor.getPath(link);
if (path == null) return null;
final ParcelableMedia media = new ParcelableMedia();
media.type = ParcelableMedia.Type.TYPE_IMAGE;
media.url = link;
if (link.contains("profile")) {
media.preview_url = link;
media.media_url = link;
} else {
if (path.startsWith("/tweet_video/")) {
// Video is not supported yet
return null;
} else if (path.startsWith("/media/")) {
media.type = ParcelableMedia.Type.TYPE_IMAGE;
media.preview_url = String.format(Locale.ROOT, "%s:medium", link);
media.media_url = String.format(Locale.ROOT, "%s:orig", link);
} else {
media.type = ParcelableMedia.Type.TYPE_IMAGE;
media.preview_url = link;
media.media_url = link;
}
return media;
@ -42,4 +47,5 @@ public class TwitterPicProvider implements Provider {
public ParcelableMedia from(@NonNull String link, @NonNull RestHttpClient client, @Nullable Object extra) {
return from(link);
}
}

View File

@ -24,10 +24,11 @@ android {
minSdkVersion 14
targetSdkVersion 23
versionCode 138
versionName "3.0.2"
versionName "3.0.3-SNAPSHOT"
multiDexEnabled true
buildConfigField 'boolean', 'ENABLE_MEDIA_VIEWER', 'Boolean.parseBoolean("true")'
buildConfigField 'boolean', 'NEW_DOCUMENT_INTENT', 'Boolean.parseBoolean("false")'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -1,30 +0,0 @@
package org.mariotaku.twidere.test.okhttp3;
import org.junit.Test;
import java.net.InetSocketAddress;
import java.net.Proxy;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import static org.junit.Assert.assertTrue;
/**
* Created by mariotaku on 16/2/5.
*/
public class OkHttpClientTest {
@Test
public void testSocksFunctionality() throws Exception {
final Proxy proxy = new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved("127.0.0.1", 1080));
final OkHttpClient client = new OkHttpClient.Builder()
.proxy(proxy)
.build();
final Request request = new Request.Builder()
.url("https://www.google.com/")
.build();
assertTrue(client.newCall(request).execute().isSuccessful());
}
}

View File

@ -0,0 +1,28 @@
package org.mariotaku.twidere.util.media.preview;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
/**
* Created by mariotaku on 16/2/9.
*/
public class PreviewMediaExtractorTest {
@Test
public void testGetAuthority() throws Exception {
assertEquals("www.google.com", PreviewMediaExtractor.getAuthority("http://www.google.com/"));
assertEquals("twitter.com", PreviewMediaExtractor.getAuthority("https://twitter.com"));
assertNull(PreviewMediaExtractor.getAuthority("www.google.com/"));
}
@Test
public void testGetPath() throws Exception {
assertEquals("/", PreviewMediaExtractor.getPath("http://www.example.com/"));
assertEquals("", PreviewMediaExtractor.getPath("http://www.example.com"));
assertEquals("/test/path", PreviewMediaExtractor.getPath("https://example.com/test/path"));
assertEquals("/test/path", PreviewMediaExtractor.getPath("https://example.com/test/path?with=query"));
}
}

View File

@ -108,7 +108,6 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/Theme.Launcher"
android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -124,7 +123,6 @@
android:icon="@mipmap/ic_launcher_hondajojo"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/Theme.Launcher"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -396,7 +394,7 @@
android:name=".activity.TwitterLinkHandlerActivity"
android:excludeFromRecents="true"
android:taskAffinity=":twidere_twitter_link_handler"
android:theme="@style/Theme.Launcher">
android:theme="@style/Theme.Twidere.Dark.NoDisplay">
<intent-filter>
<data
android:host="twitter.com"
@ -435,7 +433,7 @@
android:enabled="false"
android:excludeFromRecents="true"
android:taskAffinity=":twidere_assist_launcher"
android:theme="@style/Theme.Launcher">
android:theme="@style/Theme.Twidere.Dark.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.ASSIST"/>

View File

@ -31,25 +31,20 @@ import org.mariotaku.twidere.util.ThemeUtils;
public class MainActivity extends Activity implements Constants {
@Override
public void finish() {
super.finish();
ThemeUtils.overrideActivityCloseAnimation(this);
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
if (BuildConfig.DEBUG) {
StrictModeUtils.detectAllVmPolicy();
StrictModeUtils.detectAllThreadPolicy();
}
ThemeUtils.overrideActivityOpenAnimation(this);
super.onCreate(savedInstanceState);
setVisible(true);
final Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
@Override
public void setTheme(int resid) {
super.setTheme(ThemeUtils.getNoActionBarThemeResource(this));
}
}

View File

@ -704,11 +704,11 @@ public class ComposeActivity extends ThemedFragmentActivity implements OnMenuIte
mSendView.setOnClickListener(this);
mSendView.setOnLongClickListener(this);
final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
Utils.addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION);
MenuUtils.addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION);
final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE);
final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu);
if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) {
Utils.addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION);
MenuUtils.addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION);
}
setMenu();
updateLocationState();

View File

@ -60,6 +60,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory;
import org.mariotaku.twidere.provider.TwidereDataStore.Suggestions;
import org.mariotaku.twidere.util.EditTextEnterHandler;
import org.mariotaku.twidere.util.EditTextEnterHandler.EnterListener;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.ParseUtils;
@ -171,12 +172,13 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
final SuggestionItem item = mUsersSearchAdapter.getSuggestionItem(position);
switch (mUsersSearchAdapter.getItemViewType(position)) {
case SuggestionsAdapter.VIEW_TYPE_USER_SUGGESTION_ITEM: {
Utils.openUserProfile(this, getAccountId(), item.extra_id, item.summary, null);
IntentUtils.openUserProfile(this, getAccountId(), item.extra_id, item.summary, null,
true);
finish();
break;
}
case SuggestionsAdapter.VIEW_TYPE_USER_SCREEN_NAME: {
Utils.openUserProfile(this, getAccountId(), -1, item.title, null);
IntentUtils.openUserProfile(this, getAccountId(), -1, item.title, null, true);
finish();
break;
}

View File

@ -20,10 +20,7 @@
package org.mariotaku.twidere.adapter;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.util.Pair;
import android.support.v4.widget.Space;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView.ViewHolder;
@ -38,16 +35,15 @@ import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.iface.IActivitiesAdapter;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.fragment.support.CursorActivitiesFragment;
import org.mariotaku.twidere.fragment.support.UserFragment;
import org.mariotaku.twidere.model.ParcelableActivity;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.util.ParcelableActivityUtils;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.MediaLoadingHandler;
import org.mariotaku.twidere.util.OnLinkClickHandler;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder;
import org.mariotaku.twidere.view.holder.GapViewHolder;
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
@ -440,16 +436,8 @@ public abstract class AbsActivitiesAdapter<Data> extends LoadMoreSupportAdapter<
final ParcelableActivity activity = adapter.getActivity(position);
final ParcelableStatus status = ParcelableActivity.getActivityStatus(activity);
assert status != null;
final View profileImageView = holder.getProfileImageView();
final View profileTypeView = holder.getProfileTypeView();
if (context instanceof FragmentActivity) {
final Bundle options = Utils.makeSceneTransitionOption((FragmentActivity) context,
new Pair<>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
new Pair<>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
Utils.openUserProfile(context, status.account_id, status.user_id, status.user_screen_name, options);
} else {
Utils.openUserProfile(context, status.account_id, status.user_id, status.user_screen_name, null);
}
IntentUtils.openUserProfile(context, status.account_id, status.user_id,
status.user_screen_name, null, true);
}
@Override

View File

@ -50,6 +50,7 @@ import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.util.ParcelableActivityUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
@ -366,7 +367,7 @@ public abstract class AbsActivitiesFragment<Data> extends AbsContentListRecycler
public void onActivityClick(ActivityTitleSummaryViewHolder holder, int position) {
final ParcelableActivity activity = getAdapter().getActivity(position);
if (activity == null) return;
Utils.openUsers(getActivity(), Arrays.asList(ParcelableActivityUtils.getAfterFilteredSources(activity)));
IntentUtils.openUsers(getActivity(), Arrays.asList(ParcelableActivityUtils.getAfterFilteredSources(activity)));
}
@Override

View File

@ -29,7 +29,6 @@ import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v4.util.Pair;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.PopupMenu.OnMenuItemClickListener;
@ -53,6 +52,7 @@ import org.mariotaku.twidere.loader.iface.IExtendedLoader;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.LinkCreator;
@ -407,12 +407,8 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListRecyclerVi
@Override
public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) {
final FragmentActivity activity = getActivity();
final View profileImageView = holder.getProfileImageView();
final View profileTypeView = holder.getProfileTypeView();
final Bundle options = Utils.makeSceneTransitionOption(activity,
new Pair<>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
new Pair<>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
Utils.openUserProfile(activity, status.account_id, status.user_id, status.user_screen_name, options);
IntentUtils.openUserProfile(activity, status.account_id, status.user_id,
status.user_screen_name, null, true);
}
@Override

View File

@ -26,21 +26,19 @@ import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v4.util.Pair;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import org.mariotaku.twidere.adapter.AbsUsersAdapter;
import org.mariotaku.twidere.adapter.AbsUsersAdapter.UserAdapterListener;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.UserViewHolder;
abstract class AbsUsersFragment<Data> extends AbsContentListRecyclerViewFragment<AbsUsersAdapter<Data>>
@ -114,12 +112,7 @@ abstract class AbsUsersFragment<Data> extends AbsContentListRecyclerViewFragment
public void onUserClick(UserViewHolder holder, int position) {
final ParcelableUser user = getAdapter().getUser(position);
final FragmentActivity activity = getActivity();
final View profileImageView = holder.getProfileImageView();
final View profileTypeView = holder.getProfileTypeView();
final Bundle options = Utils.makeSceneTransitionOption(activity,
new Pair<>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
new Pair<>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
Utils.openUserProfile(activity, user.account_id, user.id, user.screen_name, options);
IntentUtils.openUserProfile(activity, user.account_id, user.id, user.screen_name, null, true);
}

View File

@ -86,12 +86,12 @@ import org.mariotaku.twidere.activity.support.ComposeActivity;
import org.mariotaku.twidere.activity.support.HomeActivity;
import org.mariotaku.twidere.activity.support.QuickSearchBarActivity;
import org.mariotaku.twidere.adapter.ArrayAdapter;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.menu.support.AccountToggleProvider;
import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.util.CompareUtils;
import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.ListViewUtils;
@ -244,8 +244,8 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
final FragmentActivity activity = getActivity();
final Bundle activityOption = Utils.makeSceneTransitionOption(activity,
new Pair<View, String>(mAccountProfileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE));
Utils.openUserProfile(activity, account.account_id, account.account_id,
account.screen_name, activityOption);
IntentUtils.openUserProfile(activity, account.account_id, account.account_id,
account.screen_name, activityOption, true);
break;
}
}

View File

@ -51,6 +51,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.Inbox;
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.Outbox;
import org.mariotaku.twidere.provider.TwidereDataStore.Mentions;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.collection.CompactHashSet;
@ -147,8 +148,8 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final ParcelableAccount account = mAdapter.getAccount(position);
Utils.openUserProfile(getActivity(), account.account_id, account.account_id, account.screen_name,
null);
IntentUtils.openUserProfile(getActivity(), account.account_id, account.account_id, account.screen_name,
null, true);
}
@Override

View File

@ -59,6 +59,7 @@ import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.ErrorInfoStore;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
@ -195,7 +196,8 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment<M
@Override
public void onUserClick(int position, DirectMessageEntry entry) {
Utils.openUserProfile(getActivity(), entry.account_id, entry.conversation_id, entry.screen_name, null);
IntentUtils.openUserProfile(getActivity(), entry.account_id, entry.conversation_id,
entry.screen_name, null, true);
}
@Subscribe

View File

@ -48,7 +48,6 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v4.util.Pair;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.CardView;
import android.support.v7.widget.FixedLinearLayoutManager;
@ -118,6 +117,7 @@ import org.mariotaku.twidere.util.CompareUtils;
import org.mariotaku.twidere.util.ContentListScrollListener;
import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.HtmlSpanBuilder;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.LinkCreator;
@ -467,12 +467,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@Override
public void onUserProfileClick(IStatusViewHolder holder, ParcelableStatus status, int position) {
final FragmentActivity activity = getActivity();
final View profileImageView = holder.getProfileImageView();
final View profileTypeView = holder.getProfileTypeView();
final Bundle options = Utils.makeSceneTransitionOption(activity,
new Pair<>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
new Pair<>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
Utils.openUserProfile(activity, status.account_id, status.user_id, status.user_screen_name, options);
IntentUtils.openUserProfile(activity, status.account_id, status.user_id,
status.user_screen_name, null, true);
}
@Override
@ -798,7 +794,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
private void onUserClick(ParcelableUser user) {
Utils.openUserProfile(getContext(), user, null);
IntentUtils.openUserProfile(getContext(), user, null, true);
}
public static final class LoadSensitiveImageConfirmDialogFragment extends BaseSupportDialogFragment implements
@ -1167,17 +1163,14 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
case R.id.profile_container: {
final FragmentActivity activity = fragment.getActivity();
final Bundle activityOption = Utils.makeSceneTransitionOption(activity,
new Pair<View, String>(profileImageView, UserFragment.TRANSITION_NAME_PROFILE_IMAGE),
new Pair<View, String>(profileTypeView, UserFragment.TRANSITION_NAME_PROFILE_TYPE));
Utils.openUserProfile(activity, status.account_id, status.user_id, status.user_screen_name,
activityOption);
IntentUtils.openUserProfile(activity, status.account_id, status.user_id,
status.user_screen_name, null, true);
break;
}
case R.id.retweeted_by: {
if (status.retweet_id > 0) {
Utils.openUserProfile(adapter.getContext(), status.account_id, status.retweeted_by_user_id,
status.retweeted_by_user_screen_name, null);
IntentUtils.openUserProfile(adapter.getContext(), status.account_id, status.retweeted_by_user_id,
status.retweeted_by_user_screen_name, null, true);
}
break;
}
@ -1188,8 +1181,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
break;
}
case R.id.quoted_name_container: {
Utils.openUserProfile(adapter.getContext(), status.account_id, status.quoted_user_id,
status.quoted_user_screen_name, null);
IntentUtils.openUserProfile(adapter.getContext(), status.account_id, status.quoted_user_id,
status.quoted_user_screen_name, null, true);
break;
}
case R.id.quote_original_link: {

View File

@ -122,6 +122,7 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ContentValuesCreator;
import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.HtmlSpanBuilder;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.LinkCreator;
@ -679,7 +680,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (resultCode == Activity.RESULT_OK) {
if (data == null || !data.hasExtra(EXTRA_ID)) return;
final long accountId = data.getLongExtra(EXTRA_ID, -1);
Utils.openUserProfile(getActivity(), accountId, user.id, user.screen_name, null);
IntentUtils.openUserProfile(getActivity(), accountId, user.id, user.screen_name,
null, true);
}
break;
}
@ -917,7 +919,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
extras.putParcelable(EXTRA_USER, user);
intent.putExtras(extras);
menu.removeGroup(MENU_GROUP_USER_EXTENSION);
Utils.addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
MenuUtils.addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
final HeaderDrawerLayout drawer = mHeaderDrawerLayout;
if (drawer != null) {
final int offset = drawer.getPaddingTop() - drawer.getHeaderTop();
@ -1056,7 +1058,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
return true;
}
case R.id.user_mentions: {
Utils.openUserMentions(getActivity(), user.account_id, user.screen_name);
IntentUtils.openUserMentions(getActivity(), user.account_id, user.screen_name);
return true;
}
case R.id.saved_searches: {
@ -1296,7 +1298,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (user == null) return;
switch (type) {
case TwidereLinkify.LINK_TYPE_MENTION: {
Utils.openUserProfile(getActivity(), user.account_id, -1, link, null);
IntentUtils.openUserProfile(getActivity(), user.account_id, -1, link, null, true);
break;
}
case TwidereLinkify.LINK_TYPE_HASHTAG: {
@ -1421,7 +1423,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (mActionBarBackground != null) {
mActionBarBackground.setColor(actionBarColor);
}
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null, actionBarColor));
if (mUser != null) {
final String displayName = mUserColorNameManager.getDisplayName(mUser, mNameFirst, false);
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(displayName, null,
actionBarColor));
} else {
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null,
actionBarColor));
}
final int optimalAccentColor = ThemeUtils.getOptimalAccentColor(color,
mDescriptionView.getCurrentTextColor());
mDescriptionView.setLinkTextColor(optimalAccentColor);

View File

@ -72,18 +72,15 @@ import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.model.SingleResponse;
import org.mariotaku.twidere.text.validator.UserListNameValidator;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.LinkCreator;
import org.mariotaku.twidere.util.MenuUtils;
import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.TabPagerIndicator;
import static org.mariotaku.twidere.util.MenuUtils.setMenuItemAvailability;
import static org.mariotaku.twidere.util.Utils.addIntentToMenu;
import static org.mariotaku.twidere.util.Utils.openUserListDetails;
import static org.mariotaku.twidere.util.Utils.openUserProfile;
public class UserListFragment extends BaseSupportFragment implements OnClickListener,
LoaderCallbacks<SingleResponse<ParcelableUserList>>, SystemWindowsInsetsCallback,
SupportFragmentCallback {
@ -177,7 +174,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
if (resultCode == Activity.RESULT_OK) {
if (data == null || !data.hasExtra(EXTRA_ID)) return;
final long accountId = data.getLongExtra(EXTRA_ID, -1);
openUserListDetails(getActivity(), accountId, userList.id, userList.user_id,
Utils.openUserListDetails(getActivity(), accountId, userList.id, userList.user_id,
userList.user_screen_name, userList.name);
}
break;
@ -252,15 +249,15 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@Override
public void onPrepareOptionsMenu(Menu menu) {
final ParcelableUserList userList = mUserList;
setMenuItemAvailability(menu, R.id.info, userList != null);
MenuUtils.setMenuItemAvailability(menu, R.id.info, userList != null);
menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
if (userList != null) {
final boolean isMyList = userList.user_id == userList.account_id;
final boolean isFollowing = userList.is_following;
setMenuItemAvailability(menu, R.id.edit, isMyList);
setMenuItemAvailability(menu, R.id.follow, !isMyList);
setMenuItemAvailability(menu, R.id.add, isMyList);
setMenuItemAvailability(menu, R.id.delete, isMyList);
MenuUtils.setMenuItemAvailability(menu, R.id.edit, isMyList);
MenuUtils.setMenuItemAvailability(menu, R.id.follow, !isMyList);
MenuUtils.setMenuItemAvailability(menu, R.id.add, isMyList);
MenuUtils.setMenuItemAvailability(menu, R.id.delete, isMyList);
final MenuItem followItem = menu.findItem(R.id.follow);
if (isFollowing) {
followItem.setIcon(R.drawable.ic_action_cancel);
@ -272,12 +269,12 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader());
extensionsIntent.putExtra(EXTRA_USER_LIST, userList);
addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
MenuUtils.addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
} else {
setMenuItemAvailability(menu, R.id.edit, false);
setMenuItemAvailability(menu, R.id.follow, false);
setMenuItemAvailability(menu, R.id.add, false);
setMenuItemAvailability(menu, R.id.delete, false);
MenuUtils.setMenuItemAvailability(menu, R.id.edit, false);
MenuUtils.setMenuItemAvailability(menu, R.id.follow, false);
MenuUtils.setMenuItemAvailability(menu, R.id.add, false);
MenuUtils.setMenuItemAvailability(menu, R.id.delete, false);
}
}
@ -351,8 +348,8 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
}
case R.id.profile_image: {
if (mUserList == null) return;
openUserProfile(getActivity(), mUserList.account_id,
mUserList.user_id, mUserList.user_screen_name, null);
IntentUtils.openUserProfile(getActivity(), mUserList.account_id,
mUserList.user_id, mUserList.user_screen_name, null, true);
break;
}
}

View File

@ -28,8 +28,9 @@ import android.view.View;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.util.MenuUtils;
import static org.mariotaku.twidere.util.Utils.addIntentToMenu;
import static org.mariotaku.twidere.util.MenuUtils.addIntentToMenu;
import static org.mariotaku.twidere.util.Utils.createStatusShareIntent;
/**
@ -71,7 +72,7 @@ public class SupportStatusShareProvider extends ActionProvider implements Consta
if (status == null) return;
final Intent shareIntent = createStatusShareIntent(mContext, status);
subMenu.removeGroup(MENU_GROUP_STATUS_SHARE);
addIntentToMenu(mContext, subMenu, shareIntent, MENU_GROUP_STATUS_SHARE);
MenuUtils.addIntentToMenu(mContext, subMenu, shareIntent, MENU_GROUP_STATUS_SHARE);
}
public void setStatus(ParcelableStatus status) {

View File

@ -6,14 +6,12 @@ import android.content.SharedPreferences;
import android.text.TextUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.mariotaku.inetaddrjni.library.InetAddressUtils;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.util.net.TwidereProxySelector;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.concurrent.TimeUnit;
@ -51,10 +49,9 @@ public class HttpClientFactory implements Constants {
public static void updateHttpClientConfiguration(final Context context,
final SharedPreferences prefs,
Dns dns, final OkHttpClient.Builder builder) {
final long connectionTimeoutMillis = TimeUnit.SECONDS.toMillis(prefs.getInt(KEY_CONNECTION_TIMEOUT, 10));
final long connectionTimeout = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10);
final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);
builder.connectTimeout(connectionTimeoutMillis, TimeUnit.MILLISECONDS);
builder.connectTimeout(connectionTimeout, TimeUnit.SECONDS);
if (enableProxy) {
final String proxyType = prefs.getString(KEY_PROXY_TYPE, null);
final String proxyHost = prefs.getString(KEY_PROXY_HOST, null);
@ -63,11 +60,7 @@ public class HttpClientFactory implements Constants {
TwidereMathUtils.RANGE_INCLUSIVE_INCLUSIVE)) {
final Proxy.Type type = getProxyType(proxyType);
if (type != Proxy.Type.DIRECT) {
if (InetAddressUtils.getInetAddressType(proxyHost) != 0) {
builder.proxy(new Proxy(type, InetSocketAddress.createUnresolved(proxyHost, proxyPort)));
} else {
builder.proxySelector(new TwidereProxySelector(context, type, proxyHost, proxyPort));
}
builder.proxySelector(new TwidereProxySelector(context, type, proxyHost, proxyPort));
}
}
final String username = prefs.getString(KEY_PROXY_USERNAME, null);

View File

@ -1,11 +1,25 @@
package org.mariotaku.twidere.util;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.constant.IntentConstants;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableUser;
import java.util.ArrayList;
import java.util.List;
import static android.text.TextUtils.isEmpty;
/**
* Created by mariotaku on 16/1/2.
@ -22,4 +36,92 @@ public class IntentUtils {
return context.getString(R.string.status_share_subject_format_with_time,
status.user_name, status.user_screen_name, timeString);
}
public static void openUserProfile(final Context context, final ParcelableUser user,
final Bundle activityOptions, final boolean newDocument) {
if (context == null || user == null) return;
final Bundle extras = new Bundle();
extras.putParcelable(IntentConstants.EXTRA_USER, user);
final Uri.Builder builder = new Uri.Builder();
builder.scheme(TwidereConstants.SCHEME_TWIDERE);
builder.authority(TwidereConstants.AUTHORITY_USER);
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
if (user.id > 0) {
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_USER_ID, String.valueOf(user.id));
}
if (user.screen_name != null) {
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_SCREEN_NAME, user.screen_name);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
intent.setExtrasClassLoader(context.getClassLoader());
intent.putExtras(extras);
if (BuildConfig.NEW_DOCUMENT_INTENT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& newDocument) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}
if (context instanceof Activity) {
ActivityCompat.startActivity((Activity) context, intent, activityOptions);
} else {
context.startActivity(intent);
}
}
public static void openUserProfile(final Context context, final long accountId, final long userId,
final String screenName, final Bundle activityOptions,
final boolean newDocument) {
if (context == null || accountId <= 0 || userId <= 0 && isEmpty(screenName)) return;
final Uri uri = LinkCreator.getTwidereUserLink(accountId, userId, screenName);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (BuildConfig.NEW_DOCUMENT_INTENT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& newDocument) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}
if (context instanceof Activity) {
ActivityCompat.startActivity((Activity) context, intent, activityOptions);
} else {
context.startActivity(intent);
}
}
public static void openUsers(final Context context, final List<ParcelableUser> users) {
if (context == null || users == null) return;
final Bundle extras = new Bundle();
extras.putParcelableArrayList(IntentConstants.EXTRA_USERS, new ArrayList<>(users));
final Uri.Builder builder = new Uri.Builder();
builder.scheme(TwidereConstants.SCHEME_TWIDERE);
builder.authority(TwidereConstants.AUTHORITY_USERS);
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
intent.putExtras(extras);
context.startActivity(intent);
}
public static void openUserTimeline(final Context context, final long accountId,
final long userId, final String screenName) {
if (context == null) return;
final Uri.Builder builder = new Uri.Builder();
builder.scheme(TwidereConstants.SCHEME_TWIDERE);
builder.authority(TwidereConstants.AUTHORITY_USER_TIMELINE);
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
if (userId > 0) {
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_USER_ID, String.valueOf(userId));
}
if (screenName != null) {
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_SCREEN_NAME, screenName);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
context.startActivity(intent);
}
public static void openUserMentions(final Context context, final long accountId, final String screenName) {
if (context == null) return;
final Uri.Builder builder = new Uri.Builder();
builder.scheme(TwidereConstants.SCHEME_TWIDERE);
builder.authority(TwidereConstants.AUTHORITY_USER_MENTIONS);
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
if (screenName != null) {
builder.appendQueryParameter(TwidereConstants.QUERY_PARAM_SCREEN_NAME, screenName);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
context.startActivity(intent);
}
}

View File

@ -19,10 +19,20 @@
package org.mariotaku.twidere.util;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
import org.mariotaku.twidere.graphic.PaddingDrawable;
import java.util.List;
/**
* Created by mariotaku on 15/4/12.
*/
@ -63,4 +73,33 @@ public class MenuUtils {
if (item == null) return;
item.setTitle(icon);
}
public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent) {
addIntentToMenu(context, menu, queryIntent, Menu.NONE);
}
public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent,
final int groupId) {
if (context == null || menu == null || queryIntent == null) return;
final PackageManager pm = context.getPackageManager();
final Resources res = context.getResources();
final float density = res.getDisplayMetrics().density;
final int padding = Math.round(density * 4);
final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, 0);
for (final ResolveInfo info : activities) {
final Intent intent = new Intent(queryIntent);
final Drawable icon = info.loadIcon(pm);
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
item.setIntent(intent);
final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
if (iw > 0 && ih > 0) {
final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
iconWithPadding.setBounds(0, 0, iw, ih);
item.setIcon(iconWithPadding);
} else {
item.setIcon(icon);
}
}
}
}

View File

@ -36,11 +36,6 @@ import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor;
import edu.tsinghua.hotmobi.HotMobiLogger;
import edu.tsinghua.hotmobi.model.LinkEvent;
import static org.mariotaku.twidere.util.Utils.openStatus;
import static org.mariotaku.twidere.util.Utils.openTweetSearch;
import static org.mariotaku.twidere.util.Utils.openUserListDetails;
import static org.mariotaku.twidere.util.Utils.openUserProfile;
public class OnLinkClickHandler implements OnLinkClickListener, Constants {
@NonNull
@ -67,11 +62,11 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
switch (type) {
case TwidereLinkify.LINK_TYPE_MENTION: {
openUserProfile(context, accountId, -1, link, null);
IntentUtils.openUserProfile(context, accountId, -1, link, null, true);
break;
}
case TwidereLinkify.LINK_TYPE_HASHTAG: {
openTweetSearch(context, accountId, "#" + link);
Utils.openTweetSearch(context, accountId, "#" + link);
break;
}
case TwidereLinkify.LINK_TYPE_LINK: {
@ -87,19 +82,19 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
if (mentionList.length != 2) {
break;
}
openUserListDetails(context, accountId, -1, -1, mentionList[0], mentionList[1]);
Utils.openUserListDetails(context, accountId, -1, -1, mentionList[0], mentionList[1]);
break;
}
case TwidereLinkify.LINK_TYPE_CASHTAG: {
openTweetSearch(context, accountId, link);
Utils.openTweetSearch(context, accountId, link);
break;
}
case TwidereLinkify.LINK_TYPE_USER_ID: {
openUserProfile(context, accountId, NumberUtils.toLong(link, -1), null, null);
IntentUtils.openUserProfile(context, accountId, NumberUtils.toLong(link, -1), null, null, true);
break;
}
case TwidereLinkify.LINK_TYPE_STATUS: {
openStatus(context, accountId, NumberUtils.toLong(link, -1));
Utils.openStatus(context, accountId, NumberUtils.toLong(link, -1));
break;
}
}

View File

@ -51,6 +51,8 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.Dns;
import static android.text.TextUtils.isEmpty;
/**
@ -142,7 +144,7 @@ public class TwitterAPIFactory implements TwidereConstants {
factory.setConstantPool(sConstantPoll);
factory.setRestConverterFactory(new TwitterConverterFactory());
factory.setHttpRequestFactory(new TwidereHttpRequestFactory(userAgent));
factory.setExceptionFactory(new TwidereExceptionFactory());
factory.setExceptionFactory(new TwidereExceptionFactory(holder.getDns()));
return factory.build(cls);
}
@ -432,6 +434,13 @@ public class TwitterAPIFactory implements TwidereConstants {
}
public static class TwidereExceptionFactory implements ExceptionFactory<TwitterException> {
private final Dns dns;
TwidereExceptionFactory(Dns dns) {
this.dns = dns;
}
@Override
public TwitterException newException(Throwable cause, HttpRequest request, HttpResponse response) {
final TwitterException te;

View File

@ -293,35 +293,6 @@ public final class Utils implements Constants {
throw new AssertionError("You are trying to create an instance for this utility class!");
}
public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent) {
addIntentToMenu(context, menu, queryIntent, Menu.NONE);
}
public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent,
final int groupId) {
if (context == null || menu == null || queryIntent == null) return;
final PackageManager pm = context.getPackageManager();
final Resources res = context.getResources();
final float density = res.getDisplayMetrics().density;
final int padding = Math.round(density * 4);
final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, 0);
for (final ResolveInfo info : activities) {
final Intent intent = new Intent(queryIntent);
final Drawable icon = info.loadIcon(pm);
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
item.setIntent(intent);
final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
if (iw > 0 && ih > 0) {
final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
iconWithPadding.setBounds(0, 0, iw, ih);
item.setIcon(iconWithPadding);
} else {
item.setIcon(icon);
}
}
}
public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId,
final String action, final String parelableKey, final String parelableJSONKey,
final Parcelable parcelable) {
@ -2261,31 +2232,6 @@ public final class Utils implements Constants {
return false;
}
public static void openUserMentions(final Activity activity, final long account_id, final String screen_name) {
if (activity == null) return;
final Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_TWIDERE);
builder.authority(AUTHORITY_USER_MENTIONS);
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
if (screen_name != null) {
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
activity.startActivity(intent);
}
public static void openUserProfile(final Context context, final long accountId, final long userId,
final String screenName, final Bundle activityOptions) {
if (context == null || accountId <= 0 || userId <= 0 && isEmpty(screenName)) return;
final Uri uri = LinkCreator.getTwidereUserLink(accountId, userId, screenName);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (context instanceof Activity) {
ActivityCompat.startActivity((Activity) context, intent, activityOptions);
} else {
context.startActivity(intent);
}
}
public static int getInsetsTopWithoutActionBarHeight(Context context, int top) {
final int actionBarHeight;
if (context instanceof AppCompatActivity) {
@ -2308,60 +2254,6 @@ public final class Utils implements Constants {
return top - actionBarHeight;
}
public static void openUserProfile(final Context context, final ParcelableUser user,
final Bundle activityOptions) {
if (context == null || user == null) return;
final Bundle extras = new Bundle();
extras.putParcelable(EXTRA_USER, user);
final Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_TWIDERE);
builder.authority(AUTHORITY_USER);
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
if (user.id > 0) {
builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
}
if (user.screen_name != null) {
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, user.screen_name);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
intent.setExtrasClassLoader(context.getClassLoader());
intent.putExtras(extras);
if (context instanceof Activity) {
ActivityCompat.startActivity((Activity) context, intent, activityOptions);
} else {
context.startActivity(intent);
}
}
public static void openUsers(final Activity activity, final List<ParcelableUser> users) {
if (activity == null || users == null) return;
final Bundle extras = new Bundle();
extras.putParcelableArrayList(EXTRA_USERS, new ArrayList<>(users));
final Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_TWIDERE);
builder.authority(AUTHORITY_USERS);
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
intent.putExtras(extras);
activity.startActivity(intent);
}
public static void openUserTimeline(final Activity activity, final long account_id, final long user_id,
final String screen_name) {
if (activity == null) return;
final Uri.Builder builder = new Uri.Builder();
builder.scheme(SCHEME_TWIDERE);
builder.authority(AUTHORITY_USER_TIMELINE);
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
if (user_id > 0) {
builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user_id));
}
if (screen_name != null) {
builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, screen_name);
}
final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
activity.startActivity(intent);
}
public static void openUserMediaTimeline(final Activity activity, final long account_id, final long user_id,
final String screen_name) {
if (activity == null) return;
@ -2503,7 +2395,7 @@ public final class Utils implements Constants {
final Menu shareSubMenu = shareItem.getSubMenu();
final Intent shareIntent = createStatusShareIntent(context, status);
shareSubMenu.removeGroup(MENU_GROUP_STATUS_SHARE);
addIntentToMenu(context, shareSubMenu, shareIntent, MENU_GROUP_STATUS_SHARE);
MenuUtils.addIntentToMenu(context, shareSubMenu, shareIntent, MENU_GROUP_STATUS_SHARE);
} else {
final Intent shareIntent = createStatusShareIntent(context, status);
final Intent chooserIntent = Intent.createChooser(shareIntent, context.getString(R.string.share_status));

View File

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme" />
<style name="Theme.Launcher" parent="Theme.Twidere.Dark.NoDisplay">
<item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>
</style>
<style name="Theme"/>
<style name="Theme.Twidere.Dark.NoActionBar" parent="Theme.Compat.Base.NoActionBar">
@ -343,7 +339,7 @@
<!--<item name="android:windowNoDisplay">true</item>-->
</style>
<style name="Theme.Test" parent="Theme.Compat.Base" />
<style name="Theme.Test" parent="Theme.Compat.Base"/>
<style name="Theme.Nyan" parent="Theme.Compat.Base.NoActionBar">
<item name="android:windowBackground">@color/nyan_background</item>