improved UserList icon quality

This commit is contained in:
Mariotaku Lee 2017-03-02 20:52:11 +08:00
parent 163cc2f88e
commit 95f8b7a8e0
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 84 additions and 70 deletions

View File

@ -1,66 +0,0 @@
package org.mariotaku.twidere.model.util;
import android.text.TextUtils;
import org.mariotaku.microblog.library.twitter.model.User;
import org.mariotaku.microblog.library.twitter.model.UserList;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.util.TwitterContentUtils;
/**
* Created by mariotaku on 16/3/5.
*/
public class ParcelableUserListUtils {
private ParcelableUserListUtils() {
}
public static ParcelableUserList from(UserList list, UserKey accountKey) {
return from(list, accountKey, 0, false);
}
public static ParcelableUserList from(UserList list, UserKey accountKey, long position, boolean isFollowing) {
ParcelableUserList obj = new ParcelableUserList();
final User user = list.getUser();
obj.position = position;
obj.account_key = accountKey;
obj.id = list.getId();
obj.is_public = UserList.Mode.PUBLIC.equals(list.getMode());
obj.is_following = isFollowing;
obj.name = list.getName();
obj.description = list.getDescription();
obj.user_key = UserKeyUtils.fromUser(user);
obj.user_name = user.getName();
obj.user_screen_name = user.getScreenName();
obj.user_profile_image_url = TwitterContentUtils.getProfileImageUrl(user);
obj.members_count = list.getMemberCount();
obj.subscribers_count = list.getSubscriberCount();
return obj;
}
public static ParcelableUserList[] fromUserLists(UserList[] userLists, UserKey accountKey) {
if (userLists == null) return null;
int size = userLists.length;
final ParcelableUserList[] result = new ParcelableUserList[size];
for (int i = 0; i < size; i++) {
result[i] = from(userLists[i], accountKey);
}
return result;
}
public static boolean check(ParcelableUserList userList, UserKey accountKey, String listId,
UserKey userKey, String screenName, String listName) {
if (!userList.account_key.equals(accountKey)) return false;
if (listId != null) {
return TextUtils.equals(listId, userList.id);
} else if (listName != null) {
if (!TextUtils.equals(listName, userList.name)) return false;
if (userKey != null) {
return userKey.equals(userList.user_key);
} else if (screenName != null) {
return TextUtils.equals(screenName, userList.user_screen_name);
}
}
return false;
}
}

View File

@ -29,6 +29,7 @@ import org.mariotaku.microblog.library.twitter.model.CursorSupport
import org.mariotaku.microblog.library.twitter.model.PageableResponseList
import org.mariotaku.microblog.library.twitter.model.Paging
import org.mariotaku.microblog.library.twitter.model.UserList
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.LOGTAG
import org.mariotaku.twidere.constant.loadItemLimitKey
import org.mariotaku.twidere.loader.iface.ICursorSupportLoader
@ -54,6 +55,8 @@ abstract class BaseUserListsLoader(
protected val data = NoDuplicatesArrayList<ParcelableUserList>()
private val profileImageSize = context.getString(R.string.profile_image_size)
override var nextCursor: Long = 0
override var prevCursor: Long = 0
@ -89,12 +92,14 @@ abstract class BaseUserListsLoader(
val dataSize = data.size
for (i in 0..listSize - 1) {
val list = listLoaded[i]
data.add(ParcelableUserListUtils.from(list, accountId, (dataSize + i).toLong(), isFollowing(list)))
data.add(ParcelableUserListUtils.from(list, accountId, (dataSize + i).toLong(),
isFollowing(list), profileImageSize))
}
} else {
for (i in 0..listSize - 1) {
val list = listLoaded[i]
data.add(ParcelableUserListUtils.from(listLoaded[i], accountId, i.toLong(), isFollowing(list)))
data.add(ParcelableUserListUtils.from(listLoaded[i], accountId, i.toLong(),
isFollowing(list), profileImageSize))
}
}
}

View File

@ -69,10 +69,10 @@ object ParcelableActivityUtils {
result.min_position = activity.minPosition
result.sources = ParcelableUserUtils.fromUsers(activity.sources, accountKey, profileImageSize)
result.target_users = ParcelableUserUtils.fromUsers(activity.targetUsers, accountKey, profileImageSize)
result.target_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetUserLists, accountKey)
result.target_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetUserLists, accountKey, profileImageSize)
result.target_statuses = ParcelableStatusUtils.fromStatuses(activity.targetStatuses, accountKey, profileImageSize)
result.target_object_statuses = ParcelableStatusUtils.fromStatuses(activity.targetObjectStatuses, accountKey, profileImageSize)
result.target_object_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetObjectUserLists, accountKey)
result.target_object_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetObjectUserLists, accountKey, profileImageSize)
result.target_object_users = ParcelableUserUtils.fromUsers(activity.targetObjectUsers, accountKey, profileImageSize)
result.has_following_source = activity.sources.fold(false) { folded, item ->
if (item.isFollowing) {

View File

@ -0,0 +1,75 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 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.model.util
import android.text.TextUtils
import org.mariotaku.microblog.library.twitter.model.UserList
import org.mariotaku.twidere.extension.model.api.getProfileImageOfSize
import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.model.UserKey
/**
* Created by mariotaku on 16/3/5.
*/
object ParcelableUserListUtils {
fun from(list: UserList, accountKey: UserKey, position: Long = 0,
isFollowing: Boolean = false, profileImageSize: String = "normal"): ParcelableUserList {
val obj = ParcelableUserList()
val user = list.user
obj.position = position
obj.account_key = accountKey
obj.id = list.id
obj.is_public = UserList.Mode.PUBLIC == list.mode
obj.is_following = isFollowing
obj.name = list.name
obj.description = list.description
obj.user_key = UserKeyUtils.fromUser(user)
obj.user_name = user.name
obj.user_screen_name = user.screenName
obj.user_profile_image_url = user.getProfileImageOfSize(profileImageSize)
obj.members_count = list.memberCount
obj.subscribers_count = list.subscriberCount
return obj
}
fun fromUserLists(userLists: Array<UserList>?, accountKey: UserKey,
profileImageSize: String = "normal"): Array<ParcelableUserList>? {
if (userLists == null) return emptyArray()
val size = userLists.size
return Array(size) { from(userLists[it], accountKey, profileImageSize = profileImageSize) }
}
fun check(userList: ParcelableUserList, accountKey: UserKey, listId: String?,
userKey: UserKey?, screenName: String?, listName: String?): Boolean {
if (userList.account_key != accountKey) return false
if (listId != null) {
return TextUtils.equals(listId, userList.id)
} else if (listName != null) {
if (!TextUtils.equals(listName, userList.name)) return false
if (userKey != null) {
return userKey == userList.user_key
} else if (screenName != null) {
return TextUtils.equals(screenName, userList.user_screen_name)
}
}
return false
}
}