improved activity tab
This commit is contained in:
parent
dce59e4637
commit
841dfbda0d
|
@ -203,7 +203,7 @@ public class User extends TwitterResponseObject implements Comparable<User>, Par
|
|||
boolean followedBy;
|
||||
|
||||
@JsonField(name = "following")
|
||||
boolean following;
|
||||
boolean following = true;
|
||||
|
||||
@JsonField(name = "follow_request_sent")
|
||||
boolean followRequestSent;
|
||||
|
@ -294,12 +294,10 @@ public class User extends TwitterResponseObject implements Comparable<User>, Par
|
|||
return followersCount;
|
||||
}
|
||||
|
||||
|
||||
public boolean isFollowing() {
|
||||
return following;
|
||||
}
|
||||
|
||||
|
||||
public long getFriendsCount() {
|
||||
return friendsCount;
|
||||
}
|
||||
|
|
|
@ -215,6 +215,11 @@ public class ParcelableActivity implements Comparable<ParcelableActivity>, Parce
|
|||
@Nullable
|
||||
public String status_my_retweet_id;
|
||||
|
||||
@CursorField(Activities.HAS_FOLLOWING_SOURCE)
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "has_following_source")
|
||||
public boolean has_following_source = true;
|
||||
|
||||
public transient UserKey[] after_filtered_source_ids;
|
||||
public transient ParcelableUser[] after_filtered_sources;
|
||||
|
||||
|
|
|
@ -932,6 +932,7 @@ public interface TwidereDataStore {
|
|||
String TARGET_OBJECT_STATUSES = "target_object_statuses";
|
||||
String TARGET_OBJECT_USER_LISTS = "target_object_user_lists";
|
||||
String TARGET_OBJECT_USERS = "target_object_users";
|
||||
String HAS_FOLLOWING_SOURCE = "has_following_source";
|
||||
|
||||
String POSITION_KEY = "position_key";
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
|
|||
public interface Constants extends TwidereConstants {
|
||||
|
||||
String DATABASES_NAME = "twidere.sqlite";
|
||||
int DATABASES_VERSION = 151;
|
||||
int DATABASES_VERSION = 152;
|
||||
|
||||
int MENU_GROUP_STATUS_EXTENSION = 10;
|
||||
int MENU_GROUP_COMPOSE_EXTENSION = 11;
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity;
|
||||
import org.mariotaku.twidere.model.ParcelableActivity;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Processing ParcelableActivity
|
||||
* <p/>
|
||||
* Created by mariotaku on 16/1/2.
|
||||
*/
|
||||
public class ParcelableActivityUtils {
|
||||
|
||||
private ParcelableActivityUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activity Activity for processing
|
||||
* @param filteredUserIds Those ids will be removed from source_ids.
|
||||
* @param followingOnly Limit following users in sources
|
||||
* @return true if source ids changed, false otherwise
|
||||
*/
|
||||
public static boolean initAfterFilteredSourceIds(ParcelableActivity activity, UserKey[] filteredUserIds,
|
||||
boolean followingOnly) {
|
||||
if (activity.sources == null) return false;
|
||||
if (activity.after_filtered_source_ids != null) return false;
|
||||
if (followingOnly || !ArrayUtils.isEmpty(filteredUserIds)) {
|
||||
List<UserKey> list = new ArrayList<>();
|
||||
for (ParcelableUser user : activity.sources) {
|
||||
if (followingOnly && !user.is_following) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ArrayUtils.contains(filteredUserIds, user.key)) {
|
||||
list.add(user.key);
|
||||
}
|
||||
}
|
||||
activity.after_filtered_source_ids = list.toArray(new UserKey[list.size()]);
|
||||
return true;
|
||||
} else {
|
||||
activity.after_filtered_source_ids = activity.source_ids;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ParcelableUser[] getAfterFilteredSources(ParcelableActivity activity) {
|
||||
if (activity.after_filtered_sources != null) return activity.after_filtered_sources;
|
||||
if (activity.after_filtered_source_ids == null || activity.sources.length == activity.after_filtered_source_ids.length) {
|
||||
return activity.sources;
|
||||
}
|
||||
ParcelableUser[] result = new ParcelableUser[activity.after_filtered_source_ids.length];
|
||||
for (int i = 0; i < activity.after_filtered_source_ids.length; i++) {
|
||||
for (ParcelableUser user : activity.sources) {
|
||||
if (user.key.equals(activity.after_filtered_source_ids[i])) {
|
||||
result[i] = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
return activity.after_filtered_sources = result;
|
||||
}
|
||||
|
||||
public static ParcelableActivity fromActivity(final Activity activity,
|
||||
final UserKey accountKey,
|
||||
final boolean isGap) {
|
||||
ParcelableActivity result = new ParcelableActivity();
|
||||
result.account_key = accountKey;
|
||||
result.timestamp = activity.getCreatedAt().getTime();
|
||||
result.action = activity.getAction();
|
||||
result.max_sort_position = activity.getMaxSortPosition();
|
||||
result.min_sort_position = activity.getMinSortPosition();
|
||||
result.max_position = activity.getMaxPosition();
|
||||
result.min_position = activity.getMinPosition();
|
||||
result.sources = ParcelableUserUtils.fromUsers(activity.getSources(), accountKey);
|
||||
result.target_users = ParcelableUserUtils.fromUsers(activity.getTargetUsers(), accountKey);
|
||||
result.target_user_lists = ParcelableUserListUtils.fromUserLists(activity.getTargetUserLists(), accountKey);
|
||||
result.target_statuses = ParcelableStatusUtils.fromStatuses(activity.getTargetStatuses(), accountKey);
|
||||
result.target_object_statuses = ParcelableStatusUtils.fromStatuses(activity.getTargetObjectStatuses(), accountKey);
|
||||
result.target_object_user_lists = ParcelableUserListUtils.fromUserLists(activity.getTargetObjectUserLists(), accountKey);
|
||||
result.target_object_users = ParcelableUserUtils.fromUsers(activity.getTargetObjectUsers(), accountKey);
|
||||
if (result.sources != null) {
|
||||
result.source_ids = new UserKey[result.sources.length];
|
||||
for (int i = 0; i < result.sources.length; i++) {
|
||||
result.source_ids[i] = result.sources[i].key;
|
||||
}
|
||||
}
|
||||
result.is_gap = isGap;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1425,9 +1425,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
|||
if (timestamp == -1) {
|
||||
timestamp = activity.timestamp;
|
||||
}
|
||||
ParcelableActivityUtils.initAfterFilteredSourceIds(activity, filteredUserIds,
|
||||
ParcelableActivityUtils.INSTANCE.initAfterFilteredSourceIds(activity, filteredUserIds,
|
||||
pref.isNotificationFollowingOnly());
|
||||
final ParcelableUser[] sources = ParcelableActivityUtils.getAfterFilteredSources(activity);
|
||||
final ParcelableUser[] sources = ParcelableActivityUtils.INSTANCE.getAfterFilteredSources(activity);
|
||||
if (ArrayUtils.isEmpty(sources)) continue;
|
||||
final ActivityTitleSummaryMessage message = ActivityTitleSummaryMessage.get(context,
|
||||
mUserColorNameManager, activity, sources,
|
||||
|
|
|
@ -154,7 +154,7 @@ public abstract class GetActivitiesTask extends AbstractTask<RefreshTaskParam, O
|
|||
final long sortDiff = firstSortId - lastSortId;
|
||||
for (int i = 0, j = activities.size(); i < j; i++) {
|
||||
Activity item = activities.get(i);
|
||||
final ParcelableActivity activity = ParcelableActivityUtils.fromActivity(item,
|
||||
final ParcelableActivity activity = ParcelableActivityUtils.INSTANCE.fromActivity(item,
|
||||
credentials.account_key, false);
|
||||
activity.position_key = GetStatusesTask.getPositionKey(activity.timestamp,
|
||||
activity.timestamp, lastSortId, sortDiff, i, j);
|
||||
|
|
|
@ -266,21 +266,18 @@ class ParcelableActivitiesAdapter(
|
|||
if (ArrayUtils.isEmpty(activity.target_object_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB
|
||||
}
|
||||
if (followingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY
|
||||
return ITEM_VIEW_TYPE_STATUS
|
||||
}
|
||||
Activity.Action.REPLY -> {
|
||||
if (ArrayUtils.isEmpty(activity.target_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB
|
||||
}
|
||||
if (followingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY
|
||||
return ITEM_VIEW_TYPE_STATUS
|
||||
}
|
||||
Activity.Action.QUOTE -> {
|
||||
if (ArrayUtils.isEmpty(activity.target_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB
|
||||
}
|
||||
if (followingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY
|
||||
return ITEM_VIEW_TYPE_STATUS
|
||||
}
|
||||
Activity.Action.FOLLOW, Activity.Action.FAVORITE, Activity.Action.RETWEET,
|
||||
|
@ -290,9 +287,11 @@ class ParcelableActivitiesAdapter(
|
|||
Activity.Action.MEDIA_TAGGED, Activity.Action.RETWEETED_MEDIA_TAGGED,
|
||||
Activity.Action.FAVORITED_MEDIA_TAGGED, Activity.Action.JOINED_TWITTER -> {
|
||||
if (mentionsOnly) return ITEM_VIEW_TYPE_EMPTY
|
||||
ParcelableActivityUtils.initAfterFilteredSourceIds(activity, filteredUserIds, followingOnly)
|
||||
if (ArrayUtils.isEmpty(activity.after_filtered_source_ids)) {
|
||||
return ITEM_VIEW_TYPE_EMPTY
|
||||
if (filteredUserIds != null) {
|
||||
ParcelableActivityUtils.initAfterFilteredSourceIds(activity, filteredUserIds!!, followingOnly)
|
||||
if (ArrayUtils.isEmpty(activity.after_filtered_source_ids)) {
|
||||
return ITEM_VIEW_TYPE_EMPTY
|
||||
}
|
||||
}
|
||||
return ITEM_VIEW_TYPE_TITLE_SUMMARY
|
||||
}
|
||||
|
|
|
@ -96,11 +96,11 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
|||
accountKeys.size)
|
||||
val expression = processWhere(where, accountSelectionArgs)
|
||||
val selection = expression.sql
|
||||
val adapter = adapter
|
||||
adapter!!.showAccountsColor = accountKeys.size > 1
|
||||
val adapter = adapter!!
|
||||
adapter.showAccountsColor = accountKeys.size > 1
|
||||
val projection = Activities.COLUMNS
|
||||
return CursorActivitiesLoader(context, uri, projection, selection,
|
||||
expression.parameters, sortOrder, fromUser)
|
||||
return CursorActivitiesLoader(context, uri, projection, selection, expression.parameters,
|
||||
sortOrder, fromUser)
|
||||
}
|
||||
|
||||
override fun createMessageBusCallback(): Any {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.mariotaku.twidere.fragment
|
|||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import edu.tsinghua.hotmobi.model.TimelineType
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.TwidereConstants.NOTIFICATION_ID_INTERACTIONS_TIMELINE
|
||||
|
@ -65,10 +64,18 @@ class InteractionsTimelineFragment : CursorActivitiesFragment() {
|
|||
val arguments = arguments
|
||||
if (arguments != null) {
|
||||
val extras = arguments.getParcelable<InteractionsTabExtras>(EXTRA_EXTRAS)
|
||||
if (extras != null && extras.isMentionsOnly) {
|
||||
val expression = Expression.and(where, Expression.inArgs(Activities.ACTION, 3))
|
||||
return ParameterizedExpression(expression, ArrayUtils.addAll(whereArgs, Activity.Action.MENTION,
|
||||
Activity.Action.REPLY, Activity.Action.QUOTE))
|
||||
if (extras != null) {
|
||||
val expressions = mutableListOf(where)
|
||||
val combinedArgs = mutableListOf(*whereArgs)
|
||||
if (extras.isMentionsOnly) {
|
||||
expressions.add(Expression.inArgs(Activities.ACTION, 3))
|
||||
combinedArgs.addAll(arrayOf(Activity.Action.MENTION, Activity.Action.REPLY, Activity.Action.QUOTE))
|
||||
}
|
||||
if (extras.isMyFollowingOnly) {
|
||||
expressions.add(Expression.equals(Activities.HAS_FOLLOWING_SOURCE, 1))
|
||||
}
|
||||
return ParameterizedExpression(Expression.and(*expressions.toTypedArray()),
|
||||
combinedArgs.toTypedArray())
|
||||
}
|
||||
}
|
||||
return super.processWhere(where, whereArgs)
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Processing ParcelableActivity
|
||||
*
|
||||
*
|
||||
* Created by mariotaku on 16/1/2.
|
||||
*/
|
||||
object ParcelableActivityUtils {
|
||||
|
||||
/**
|
||||
* @param activity Activity for processing
|
||||
* *
|
||||
* @param filteredUserIds Those ids will be removed from source_ids.
|
||||
* *
|
||||
* @param followingOnly Limit following users in sources
|
||||
* *
|
||||
* @return true if source ids changed, false otherwise
|
||||
*/
|
||||
fun initAfterFilteredSourceIds(activity: ParcelableActivity, filteredUserIds: Array<UserKey>,
|
||||
followingOnly: Boolean): Boolean {
|
||||
if (activity.sources == null) return false
|
||||
if (activity.after_filtered_source_ids != null) return false
|
||||
if (followingOnly || !ArrayUtils.isEmpty(filteredUserIds)) {
|
||||
val list = ArrayList<UserKey>()
|
||||
for (user in activity.sources) {
|
||||
if (followingOnly && !user.is_following) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!ArrayUtils.contains(filteredUserIds, user.key)) {
|
||||
list.add(user.key)
|
||||
}
|
||||
}
|
||||
activity.after_filtered_source_ids = list.toTypedArray()
|
||||
return true
|
||||
} else {
|
||||
activity.after_filtered_source_ids = activity.source_ids
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
fun getAfterFilteredSources(activity: ParcelableActivity): Array<ParcelableUser> {
|
||||
if (activity.after_filtered_sources != null) return activity.after_filtered_sources
|
||||
if (activity.after_filtered_source_ids == null || activity.sources.size == activity.after_filtered_source_ids.size) {
|
||||
return activity.sources
|
||||
}
|
||||
val result = Array<ParcelableUser>(activity.after_filtered_source_ids.size) { idx ->
|
||||
return@Array activity.sources.find { it.key == activity.after_filtered_source_ids[idx] }!!
|
||||
}
|
||||
activity.after_filtered_sources = result
|
||||
return result
|
||||
}
|
||||
|
||||
fun fromActivity(activity: Activity,
|
||||
accountKey: UserKey,
|
||||
isGap: Boolean): ParcelableActivity {
|
||||
val result = ParcelableActivity()
|
||||
result.account_key = accountKey
|
||||
result.timestamp = activity.createdAt.time
|
||||
result.action = activity.action
|
||||
result.max_sort_position = activity.maxSortPosition
|
||||
result.min_sort_position = activity.minSortPosition
|
||||
result.max_position = activity.maxPosition
|
||||
result.min_position = activity.minPosition
|
||||
result.sources = ParcelableUserUtils.fromUsers(activity.sources, accountKey)
|
||||
result.target_users = ParcelableUserUtils.fromUsers(activity.targetUsers, accountKey)
|
||||
result.target_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetUserLists, accountKey)
|
||||
result.target_statuses = ParcelableStatusUtils.fromStatuses(activity.targetStatuses, accountKey)
|
||||
result.target_object_statuses = ParcelableStatusUtils.fromStatuses(activity.targetObjectStatuses, accountKey)
|
||||
result.target_object_user_lists = ParcelableUserListUtils.fromUserLists(activity.targetObjectUserLists, accountKey)
|
||||
result.target_object_users = ParcelableUserUtils.fromUsers(activity.targetObjectUsers, accountKey)
|
||||
result.has_following_source = activity.sources.fold(false) { folded, item ->
|
||||
if (item.isFollowing) {
|
||||
return@fold true
|
||||
}
|
||||
return@fold false
|
||||
}
|
||||
if (result.sources != null) {
|
||||
result.source_ids = arrayOfNulls<UserKey>(result.sources.size)
|
||||
for (i in result.sources.indices) {
|
||||
result.source_ids[i] = result.sources[i].key
|
||||
}
|
||||
}
|
||||
result.is_gap = isGap
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue