fixed user ui color

fixed crashes in settings
This commit is contained in:
Mariotaku Lee 2016-03-25 11:20:58 +08:00
parent 5ecc60aa0f
commit a3c0750a29
9 changed files with 52 additions and 62 deletions

View File

@ -23,6 +23,7 @@ allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
mavenLocal()
}
}

View File

@ -148,7 +148,7 @@ dependencies {
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.13'
compile 'com.github.mariotaku.SQLiteQB:library:0.9.6'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.6'
compile 'com.github.mariotaku:MultiValueSwitch:0.9.1'
compile 'com.github.mariotaku:MultiValueSwitch:0.9.2'
compile 'com.github.mariotaku:AbstractTask:0.9'
}

View File

@ -509,6 +509,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
return new StatusesBusCallback();
}
@NonNull
protected abstract UserKey[] getAccountKeys();
protected List<ParcelableStatus> getAdapterData() {

View File

@ -181,6 +181,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
}
@NonNull
@Override
protected UserKey[] getAccountKeys() {
final Bundle args = getArguments();

View File

@ -118,9 +118,12 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment {
return (!TextUtils.equals(mLastId, mLastId = list.get(list.size() - 1).id));
}
@NonNull
@Override
protected UserKey[] getAccountKeys() {
return Utils.getAccountKeys(getContext(), getArguments());
final UserKey[] accountKeys = Utils.getAccountKeys(getContext(), getArguments());
if (accountKeys == null) return new UserKey[0];
return accountKeys;
}
@Override

View File

@ -30,7 +30,6 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@ -49,7 +48,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.app.SharedElementCallback;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v4.content.res.ResourcesCompat;
@ -82,6 +80,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.afollestad.appthemeengine.ATEActivity;
import com.afollestad.appthemeengine.Config;
import com.afollestad.appthemeengine.util.ATEUtil;
import com.squareup.otto.Subscribe;
@ -96,7 +95,6 @@ import org.mariotaku.twidere.activity.BaseActivity;
import org.mariotaku.twidere.activity.ColorPickerDialogActivity;
import org.mariotaku.twidere.activity.LinkHandlerActivity;
import org.mariotaku.twidere.activity.UserListSelectorActivity;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.adapter.SupportTabsAdapter;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
@ -165,7 +163,6 @@ import org.mariotaku.twidere.view.TintedStatusFrameLayout;
import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import edu.tsinghua.hotmobi.HotMobiLogger;
@ -176,8 +173,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
SystemWindowsInsetsCallback, RefreshScrollTopInterface, OnPageChangeListener, KeyboardShortcutCallback,
UserColorChangedListener, UserNicknameChangedListener, IToolBarSupportFragment {
public static final String TRANSITION_NAME_PROFILE_IMAGE = "profile_image";
public static final String TRANSITION_NAME_PROFILE_TYPE = "profile_type";
private static final ArgbEvaluator sArgbEvaluator = new ArgbEvaluator();
private static final int LOADER_ID_USER = 1;
private static final int LOADER_ID_FRIENDSHIP = 2;
@ -207,9 +202,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private HeaderDrawerLayout mHeaderDrawerLayout;
private ViewPager mViewPager;
private TabPagerIndicator mPagerIndicator;
private View mPagerOverlay;
private View mWindowOverlay;
private View mErrorOverlay;
private View mProfileBannerContainer;
private ExtendedRelativeLayout mProfileContentContainer;
private Button mFollowButton;
@ -298,7 +291,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
@Override
public void onLoadFinished(final Loader<SingleResponse<ParcelableUser>> loader,
final SingleResponse<ParcelableUser> data) {
if (getActivity() == null) return;
final FragmentActivity activity = getActivity();
if (activity == null) return;
if (data.hasData()) {
final ParcelableUser user = data.getData();
mCardContent.setVisibility(View.VISIBLE);
@ -313,19 +307,23 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, true);
getLoaderManager().restartLoader(LOADER_ID_USER, args, this);
}
setHasOptionsMenu(true);
} else if (mUser != null && mUser.is_cache) {
mCardContent.setVisibility(View.VISIBLE);
mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
displayUser(mUser);
setHasOptionsMenu(true);
} else {
if (data.hasException()) {
mHeaderErrorTextView.setText(Utils.getErrorMessage(getActivity(), data.getException()));
mHeaderErrorTextView.setText(Utils.getErrorMessage(activity, data.getException()));
mHeaderErrorTextView.setVisibility(View.VISIBLE);
}
mCardContent.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
displayUser(null);
setHasOptionsMenu(false);
}
}
@ -508,9 +506,18 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
@UiThread
public void displayUser(final ParcelableUser user) {
mUser = user;
final FragmentActivity activity = getActivity();
if (user == null || user.key == null || activity == null) return;
if (activity == null) return;
mUser = user;
if (user == null || user.key == null) {
mProfileImageView.setVisibility(View.GONE);
mProfileTypeView.setVisibility(View.GONE);
if (activity instanceof ATEActivity) {
setUiColor(Config.primaryColor(activity, ((ATEActivity) activity).getATEKey()));
}
return;
}
mProfileImageView.setVisibility(View.VISIBLE);
final Resources resources = getResources();
final LoaderManager lm = getLoaderManager();
lm.destroyLoader(LOADER_ID_USER);
@ -565,7 +572,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
setUiColor(user.color);
} else if (user.link_color != 0) {
setUiColor(user.link_color);
} else if (activity instanceof IThemedActivity) {
} else if (activity instanceof ATEActivity) {
setUiColor(Config.primaryColor(activity, ((ATEActivity) activity).getATEKey()));
}
final int defWidth = resources.getDisplayMetrics().widthPixels;
final int width = mBannerWidth > 0 ? mBannerWidth : defWidth;
@ -717,7 +725,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final FragmentActivity activity = getActivity();
setHasOptionsMenu(true);
mUserColorNameManager.registerColorChangedListener(this);
mUserColorNameManager.registerNicknameChangedListener(this);
mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
@ -750,42 +757,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
});
activity.setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
if (idx != -1) {
final View view = sharedElements.get(idx);
int[] location = new int[2];
final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
view.getLocationOnScreen(location);
bounds.offsetTo(location[0], location[1]);
mProfileImageView.setTransitionSource(bounds);
}
super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots);
}
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
if (idx != -1) {
final View view = sharedElements.get(idx);
int[] location = new int[2];
final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
view.getLocationOnScreen(location);
bounds.offsetTo(location[0], location[1]);
mProfileImageView.setTransitionDestination(bounds);
}
super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
}
});
ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE);
ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE);
// ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD);
mTintedStatusFrameLayout.setWindowInsetsListener(new TintedStatusFrameLayout.WindowInsetsListener() {
@Override
@ -1177,8 +1148,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mProfileBannerSpace = (ProfileBannerSpace) headerView.findViewById(R.id.profile_banner_space);
mViewPager = (ViewPager) contentView.findViewById(R.id.view_pager);
mPagerIndicator = (TabPagerIndicator) contentView.findViewById(R.id.toolbar_tabs);
mPagerOverlay = contentView.findViewById(R.id.pager_window_overlay);
mErrorOverlay = contentView.findViewById(R.id.error_window_overlay);
mFollowButton = (Button) headerView.findViewById(R.id.follow);
mFollowProgress = (ProgressBar) headerView.findViewById(R.id.follow_progress);
mWindowOverlay = view.findViewById(R.id.window_overlay);
@ -1497,11 +1466,17 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (mActionBarBackground != null) {
mActionBarBackground.setColor(mPrimaryColor);
}
int taskColor;
if (Config.coloredActionBar(activity, activity.getATEKey())) {
taskColor = color;
} else {
taskColor = Config.toolbarColor(activity, activity.getATEKey(), mToolbar);
}
if (mUser != null) {
final String name = mUserColorNameManager.getDisplayName(mUser, mNameFirst);
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(name, null, color));
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(name, null, taskColor));
} else {
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null, color));
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null, taskColor));
}
final int optimalAccentColor = ThemeUtils.getOptimalAccentColor(color,
mDescriptionView.getCurrentTextColor());

View File

@ -200,7 +200,7 @@ public final class TwidereLinkify implements Constants {
/**
* Applies a regex to the text of a TextView turning the matches into links.
*/
private void addLinks(final Spannable string, final UserKey accountKey, final long extraId, final int type,
private void addLinks(final Spannable string, @Nullable final UserKey accountKey, final long extraId, final int type,
final boolean sensitive, final OnLinkClickListener listener, final int highlightOption) {
switch (type) {
case LINK_TYPE_MENTION: {
@ -221,7 +221,7 @@ public final class TwidereLinkify implements Constants {
}
string.removeSpan(span);
String url = span.getURL();
if (USER_TYPE_FANFOU_COM.equals(accountKey.getHost())) {
if (accountKey != null && USER_TYPE_FANFOU_COM.equals(accountKey.getHost())) {
// Fix search path
if (url.startsWith("/")) {
url = "http://fanfou.com" + url;
@ -258,7 +258,9 @@ public final class TwidereLinkify implements Constants {
break;
}
case LINK_TYPE_STATUS: {
if (!USER_TYPE_TWITTER_COM.equals(accountKey.getHost())) break;
if (accountKey == null || !USER_TYPE_TWITTER_COM.equals(accountKey.getHost())) {
break;
}
final int length = string.length();
final URLSpan[] spans = string.getSpans(0, length, URLSpan.class);
for (final URLSpan span : spans) {

View File

@ -821,7 +821,7 @@ public final class Utils implements Constants {
}
final UserKey accountKey = UserKeyUtils.findById(context, accountId);
args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey);
if (accountKey == null) return new UserKey[0];
if (accountKey == null) return new UserKey[]{new UserKey(accountId, null)};
return new UserKey[]{accountKey};
}
return null;

View File

@ -42,6 +42,7 @@
android:id="@+id/profile_name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/profile_banner_space"
android:layout_toEndOf="@id/profile_image"
android:layout_toRightOf="@id/profile_image"
@ -68,7 +69,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
android:visibility="gone"
tools:text="@string/follow"
tools:visibility="visible"/>
<ProgressBar
android:id="@+id/follow_progress"
@ -408,7 +411,10 @@
android:layout_alignBottom="@+id/profile_name_container"
android:layout_marginLeft="@dimen/element_spacing_normal"
android:layout_marginStart="@dimen/element_spacing_normal"
android:contentDescription="@string/profile_image"/>
android:contentDescription="@string/profile_image"
android:visibility="gone"
tools:src="@mipmap/ic_launcher"
tools:visibility="visible"/>
<org.mariotaku.twidere.view.BoundsImageView
android:id="@+id/profile_type"
@ -422,6 +428,7 @@
android:layout_marginEnd="@dimen/element_spacing_minus_msmall"
android:layout_marginRight="@dimen/element_spacing_minus_msmall"
android:scaleType="fitCenter"
android:visibility="gone"
tools:visibility="gone"/>
</RelativeLayout>