List of usage examples for android.support.v4.app LoaderManager destroyLoader
public abstract void destroyLoader(int id);
From source file:org.mariotaku.twidere.fragment.UserFragment.java
public void getUserInfo(final UserKey accountKey, final UserKey userKey, final String screenName, final boolean omitIntentExtra) { final LoaderManager lm = getLoaderManager(); lm.destroyLoader(LOADER_ID_USER); lm.destroyLoader(LOADER_ID_FRIENDSHIP); final Bundle args = new Bundle(); args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey); args.putParcelable(EXTRA_USER_KEY, userKey); args.putString(EXTRA_SCREEN_NAME, screenName); args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra); if (!mGetUserInfoLoaderInitialized) { lm.initLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks); mGetUserInfoLoaderInitialized = true; } else {/*from w ww .ja v a 2 s .c o m*/ lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks); } if (accountKey == null || userKey == null && screenName == null) { mCardContent.setVisibility(View.GONE); mHeaderErrorContainer.setVisibility(View.GONE); } }
From source file:org.mariotaku.twidere.fragment.UserFragment.java
@UiThread public void displayUser(final ParcelableUser user, ParcelableAccount account) { final FragmentActivity activity = getActivity(); if (activity == null) return;/* w w w . ja v a2 s .c o m*/ mUser = user; mAccount = account; 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); lm.destroyLoader(LOADER_ID_FRIENDSHIP); mCardContent.setVisibility(View.VISIBLE); mHeaderErrorContainer.setVisibility(View.GONE); mProgressContainer.setVisibility(View.GONE); mUser = user; mProfileImageView.setBorderColor(user.color != 0 ? user.color : Color.WHITE); mProfileNameContainer.drawEnd(user.account_color); mNameView.setText(mBidiFormatter.unicodeWrap(TextUtils.isEmpty(user.nickname) ? user.name : getString(R.string.name_with_nickname, user.name, user.nickname))); final int typeIconRes = Utils.getUserTypeIconRes(user.is_verified, user.is_protected); if (typeIconRes != 0) { mProfileTypeView.setImageResource(typeIconRes); mProfileTypeView.setVisibility(View.VISIBLE); } else { mProfileTypeView.setImageDrawable(null); mProfileTypeView.setVisibility(View.GONE); } mScreenNameView.setText(String.format("@%s", user.screen_name)); final TwidereLinkify linkify = new TwidereLinkify(this); if (user.description_unescaped != null) { final SpannableStringBuilder text = SpannableStringBuilder.valueOf(user.description_unescaped); ParcelableStatusUtils.applySpans(text, user.description_spans); linkify.applyAllLinks(text, user.account_key, false, false); mDescriptionView.setText(text); } else { mDescriptionView.setText(user.description_plain); Linkify.addLinks(mDescriptionView, Linkify.WEB_URLS); } mDescriptionContainer.setVisibility(mDescriptionView.length() > 0 ? View.VISIBLE : View.GONE); mLocationContainer.setVisibility(TextUtils.isEmpty(user.location) ? View.GONE : View.VISIBLE); mLocationView.setText(user.location); mURLContainer.setVisibility( TextUtils.isEmpty(user.url) && TextUtils.isEmpty(user.url_expanded) ? View.GONE : View.VISIBLE); mURLView.setText(TextUtils.isEmpty(user.url_expanded) ? user.url : user.url_expanded); final String createdAt = Utils.formatToLongTimeString(activity, user.created_at); final float daysSinceCreation = (System.currentTimeMillis() - user.created_at) / 1000 / 60 / 60 / 24; final int dailyTweets = Math.round(user.statuses_count / Math.max(1, daysSinceCreation)); mCreatedAtView.setText(resources.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets, createdAt, dailyTweets)); mListedCount.setText(Utils.getLocalizedNumber(mLocale, user.listed_count)); final long groupsCount = user.extras != null ? user.extras.groups_count : -1; mGroupsCount.setText(Utils.getLocalizedNumber(mLocale, groupsCount)); mFollowersCount.setText(Utils.getLocalizedNumber(mLocale, user.followers_count)); mFriendsCount.setText(Utils.getLocalizedNumber(mLocale, user.friends_count)); mListedContainer.setVisibility(user.listed_count < 0 ? View.GONE : View.VISIBLE); mGroupsContainer.setVisibility(groupsCount < 0 ? View.GONE : View.VISIBLE); mMediaLoader.displayOriginalProfileImage(mProfileImageView, user); if (user.color != 0) { setUiColor(user.color); } else if (user.link_color != 0) { setUiColor(user.link_color); } 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; final String bannerUrl = ParcelableUserUtils.getProfileBannerUrl(user); if (ObjectUtils.notEqual(mProfileBannerView.getTag(), bannerUrl) || mProfileBannerView.getDrawable() == null) { mProfileBannerView.setTag(bannerUrl); mMediaLoader.displayProfileBanner(mProfileBannerView, bannerUrl, width); } final UserRelationship relationship = mRelationship; if (relationship == null) { getFriendship(); } activity.setTitle( UserColorNameManager.decideDisplayName(user.nickname, user.name, user.screen_name, mNameFirst)); Calendar cal = Calendar.getInstance(); final int currentMonth = cal.get(Calendar.MONTH), currentDay = cal.get(Calendar.DAY_OF_MONTH); cal.setTimeInMillis(user.created_at); if (cal.get(Calendar.MONTH) == currentMonth && cal.get(Calendar.DAY_OF_MONTH) == currentDay && !mHideBirthdayView) { mProfileBirthdayBannerView.setVisibility(View.VISIBLE); } else { mProfileBirthdayBannerView.setVisibility(View.GONE); } updateTitleAlpha(); invalidateOptionsMenu(); updateSubtitle(); }