From 20c49e727cb58353a9cef9b170c4557ea09d1ad0 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 30 Jan 2017 21:41:34 +0800 Subject: [PATCH] refactored user lists fragment code cleanup --- .../library/twitter/api/ListResources.java | 4 +- .../twidere/loader/BaseUserListsLoader.java | 117 ------------------ .../loader/UserListMembershipsLoader.java | 60 --------- .../twidere/loader/UserListsLoader.java | 62 ---------- .../twidere/activity/BrowserSignInActivity.kt | 2 +- .../twidere/activity/ComposeActivity.kt | 4 +- .../twidere/activity/NyanActivity.kt | 8 +- .../activity/UserListSelectorActivity.kt | 5 - .../twidere/fragment/GroupFragment.kt | 2 +- .../twidere/fragment/GroupMembersFragment.kt | 2 +- .../fragment/IncomingFriendshipsFragment.kt | 2 +- .../twidere/fragment/ListsFragment.kt | 8 +- .../fragment/ParcelableGroupsFragment.kt | 10 +- .../fragment/ParcelableUserListsFragment.kt | 8 +- .../fragment/ParcelableUsersFragment.kt | 11 +- .../twidere/fragment/SearchUsersFragment.kt | 2 +- .../fragment/StatusFavoritersListFragment.kt | 2 +- .../fragment/StatusRetweetersListFragment.kt | 2 +- .../twidere/fragment/UserFollowersFragment.kt | 2 +- .../twidere/fragment/UserFriendsFragment.kt | 2 +- .../twidere/fragment/UserListFragment.kt | 2 +- .../fragment/UserListMembersFragment.kt | 2 +- .../fragment/UserListMembershipsFragment.kt | 2 +- .../fragment/UserListSubscribersFragment.kt | 2 +- .../fragment/UserListSubscriptionsFragment.kt | 40 ++++++ ...ment.kt => UserListsOwnershipsFragment.kt} | 8 +- .../twidere/fragment/VideoPageFragment.kt | 2 +- .../twidere/loader/BaseUserListsLoader.kt | 103 +++++++++++++++ .../twidere/loader/ConversationLoader.kt | 2 +- .../twidere/loader/GroupMembersLoader.kt | 2 +- .../twidere/loader/ParcelableUsersLoader.kt | 2 +- .../twidere/loader/SavedSearchesLoader.kt | 2 +- .../twidere/loader/TweetSearchLoader.kt | 2 +- .../twidere/loader/UserFavoritesLoader.kt | 2 +- .../twidere/loader/UserListMembersLoader.kt | 2 +- .../loader/UserListMembershipsLoader.kt | 51 ++++++++ .../loader/UserListOwnershipsLoader.kt | 51 ++++++++ .../loader/UserListSubscribersLoader.kt | 2 +- .../loader/UserListSubscriptionsLoader.kt | 51 ++++++++ .../twidere/loader/UserSearchLoader.kt | 2 +- .../task/AbsFriendshipOperationTask.kt | 2 +- .../twidere/task/CacheUsersStatusesTask.kt | 2 +- .../twidere/task/GetDirectMessagesTask.kt | 2 +- .../twidere/task/GetSavedSearchesTask.kt | 2 +- .../mariotaku/twidere/task/GetTrendsTask.kt | 2 +- .../twidere/task/twitter/GetActivitiesTask.kt | 6 +- .../twidere/task/twitter/GetStatusesTask.kt | 4 +- .../twitter/card/CardPollViewController.kt | 4 +- twidere/src/main/res/values/strings.xml | 3 + 49 files changed, 366 insertions(+), 308 deletions(-) delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/loader/BaseUserListsLoader.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembershipsLoader.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/loader/UserListsLoader.java create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt rename twidere/src/main/kotlin/org/mariotaku/twidere/fragment/{UserListsFragment.kt => UserListsOwnershipsFragment.kt} (92%) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/ListResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/ListResources.java index 7379c90f9..d54d076c9 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/ListResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/api/ListResources.java @@ -148,11 +148,11 @@ public interface ListResources { @GET("/lists/subscriptions.json") - PageableResponseList getUserListSubscriptionsByScreenName(@Query("screen_name") String listOwnerScreenName, long cursor) + PageableResponseList getUserListSubscriptionsByScreenName(@Query("screen_name") String listOwnerScreenName, @Query Paging paging) throws MicroBlogException; @GET("/lists/subscriptions.json") - PageableResponseList getUserListSubscriptions(@Query("user_id") String userId, long cursor) + PageableResponseList getUserListSubscriptions(@Query("user_id") String userId, @Query Paging paging) throws MicroBlogException; @GET("/lists/show.json") diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/BaseUserListsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/BaseUserListsLoader.java deleted file mode 100644 index ec2638d98..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/BaseUserListsLoader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.loader; - -import android.content.Context; -import android.support.v4.content.AsyncTaskLoader; -import android.util.Log; - -import org.mariotaku.microblog.library.MicroBlog; -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.CursorSupport; -import org.mariotaku.microblog.library.twitter.model.PageableResponseList; -import org.mariotaku.microblog.library.twitter.model.UserList; -import org.mariotaku.twidere.TwidereConstants; -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader; -import org.mariotaku.twidere.model.ParcelableUserList; -import org.mariotaku.twidere.model.UserKey; -import org.mariotaku.twidere.model.util.ParcelableUserListUtils; -import org.mariotaku.twidere.util.MicroBlogAPIFactory; -import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList; - -import java.util.Collections; -import java.util.List; - - -public abstract class BaseUserListsLoader extends AsyncTaskLoader> - implements TwidereConstants, ICursorSupportLoader { - - protected final NoDuplicatesArrayList mData = new NoDuplicatesArrayList<>(); - protected final UserKey mAccountId; - private final long mCursor; - - private long mNextCursor, mPrevCursor; - - public BaseUserListsLoader(final Context context, final UserKey accountKey, final long cursor, - final List data) { - super(context); - if (data != null) { - mData.addAll(data); - } - mCursor = cursor; - mAccountId = accountKey; - } - - @Override - public long getCursor() { - return mCursor; - } - - @Override - public long getNextCursor() { - return mNextCursor; - } - - @Override - public long getPrevCursor() { - return mPrevCursor; - } - - public abstract List getUserLists(final MicroBlog twitter) throws MicroBlogException; - - @Override - public List loadInBackground() { - final MicroBlog twitter = MicroBlogAPIFactory.getInstance(getContext(), mAccountId); - List listLoaded = null; - try { - listLoaded = getUserLists(twitter); - } catch (final MicroBlogException e) { - Log.w(LOGTAG, e); - } - if (listLoaded != null) { - final int listSize = listLoaded.size(); - if (listLoaded instanceof PageableResponseList) { - mNextCursor = ((CursorSupport) listLoaded).getNextCursor(); - mPrevCursor = ((CursorSupport) listLoaded).getPreviousCursor(); - final int dataSize = mData.size(); - for (int i = 0; i < listSize; i++) { - final UserList list = listLoaded.get(i); - mData.add(ParcelableUserListUtils.from(list, mAccountId, dataSize + i, isFollowing(list))); - } - } else { - for (int i = 0; i < listSize; i++) { - final UserList list = listLoaded.get(i); - mData.add(ParcelableUserListUtils.from(listLoaded.get(i), mAccountId, i, isFollowing(list))); - } - } - } - Collections.sort(mData); - return mData; - } - - @Override - public void onStartLoading() { - forceLoad(); - } - - protected boolean isFollowing(final UserList list) { - return list.isFollowing(); - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembershipsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembershipsLoader.java deleted file mode 100644 index 8c16d0219..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembershipsLoader.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.loader; - -import android.content.Context; - -import org.mariotaku.microblog.library.MicroBlog; -import org.mariotaku.microblog.library.MicroBlogException; -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.model.ParcelableUserList; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class UserListMembershipsLoader extends BaseUserListsLoader { - - private final UserKey mUserKey; - private final String mScreenName; - - public UserListMembershipsLoader(final Context context, final UserKey accountKey, - final UserKey userKey, final String screenName, - final long cursor, final List data) { - super(context, accountKey, cursor, data); - mUserKey = userKey; - mScreenName = screenName; - } - - @Override - public PageableResponseList getUserLists(final MicroBlog twitter) throws MicroBlogException { - if (twitter == null) return null; - final Paging paging = new Paging(); - paging.cursor(getCursor()); - if (mUserKey != null) { - return twitter.getUserListMemberships(mUserKey.getId(), paging); - } else if (mScreenName != null) { - return twitter.getUserListMembershipsByScreenName(mScreenName, paging); - } - return null; - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListsLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserListsLoader.java deleted file mode 100644 index 24c1d0e13..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListsLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.loader; - -import android.content.Context; - -import org.mariotaku.microblog.library.MicroBlog; -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.ResponseList; -import org.mariotaku.microblog.library.twitter.model.UserList; -import org.mariotaku.twidere.model.ParcelableUserList; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class UserListsLoader extends BaseUserListsLoader { - - private final UserKey mUserKey; - private final String mScreenName; - private final boolean mReverse; - - public UserListsLoader(final Context context, final UserKey accountKey, final UserKey userKey, - final String screenName, final boolean reverse, final List data) { - super(context, accountKey, 0, data); - mUserKey = userKey; - mScreenName = screenName; - mReverse = reverse; - } - - @Override - public ResponseList getUserLists(final MicroBlog twitter) throws MicroBlogException { - if (twitter == null) return null; - if (mUserKey != null) { - return twitter.getUserLists(mUserKey.getId(), mReverse); - } else if (mScreenName != null) { - return twitter.getUserListsByScreenName(mScreenName, mReverse); - } - return null; - } - - @Override - protected boolean isFollowing(final UserList list) { - return true; - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BrowserSignInActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BrowserSignInActivity.kt index e16185d69..f6bef7c98 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BrowserSignInActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BrowserSignInActivity.kt @@ -89,7 +89,7 @@ class BrowserSignInActivity : BaseActivity() { getRequestToken() } - public override fun onDestroy() { + override fun onDestroy() { if (task?.status == AsyncTask.Status.RUNNING) { task?.cancel(true) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt index 92857d2e7..dcdf7f1a1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -143,7 +143,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener // Listeners private var locationListener: LocationListener? = null - public override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { + override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { when (requestCode) { REQUEST_TAKE_PHOTO, REQUEST_PICK_MEDIA -> { if (resultCode == Activity.RESULT_OK && intent != null) { @@ -213,7 +213,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener return textChanged || hasMedia() || isEditingDraft } - public override fun onSaveInstanceState(outState: Bundle) { + override fun onSaveInstanceState(outState: Bundle) { outState.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountsAdapter.selectedAccountKeys) outState.putParcelableArrayList(EXTRA_MEDIA, ArrayList(mediaList)) outState.putBoolean(EXTRA_IS_POSSIBLY_SENSITIVE, possiblySensitive) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/NyanActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/NyanActivity.kt index 55e0aeb14..011a274cf 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/NyanActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/NyanActivity.kt @@ -37,7 +37,7 @@ import org.mariotaku.twidere.nyan.NyanWallpaperService class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChangeListener { - private var helper: NyanSurfaceHelper? = null + private lateinit var helper: NyanSurfaceHelper override fun onLongClick(v: View): Boolean { Toast.makeText(this, R.string.message_toast_nyan_sakamoto, Toast.LENGTH_SHORT).show() @@ -63,11 +63,11 @@ class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChan override fun onStart() { super.onStart() - helper?.start() + helper.start() } override fun onStop() { - helper?.stop() + helper.stop() super.onStop() } @@ -97,7 +97,7 @@ class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChan private fun updateSurface() { val def = resources.getInteger(R.integer.default_live_wallpaper_scale) - helper!!.setScale(preferences.getInt(KEY_LIVE_WALLPAPER_SCALE, def).toFloat()) + helper.setScale(preferences.getInt(KEY_LIVE_WALLPAPER_SCALE, def).toFloat()) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt index 20bc9d6f9..6140fe50f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt @@ -24,7 +24,6 @@ import android.content.Intent import android.os.AsyncTask import android.os.Bundle import android.support.v4.app.DialogFragment -import android.support.v4.app.LoaderManager import android.text.TextUtils import android.text.TextUtils.isEmpty import android.util.Log @@ -44,7 +43,6 @@ import org.mariotaku.twidere.adapter.UserAutoCompleteAdapter import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.fragment.CreateUserListDialogFragment import org.mariotaku.twidere.fragment.ProgressDialogFragment -import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.SingleResponse import org.mariotaku.twidere.model.UserKey @@ -126,9 +124,6 @@ class UserListSelectorActivity : BaseActivity(), OnClickListener, OnItemClickLis AsyncTaskUtils.executeTask(task) } - private val isSelectingUser: Boolean - get() = INTENT_ACTION_SELECT_USER == intent.action - private fun setUserListsData(data: List, isMyAccount: Boolean) { userListsAdapter.setData(data, true) userListsContainer.visibility = View.VISIBLE diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt index 2d56aa1f2..23badb6d2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt @@ -123,7 +123,7 @@ class GroupFragment : AbsToolbarTabPagesFragment(), LoaderCallbacks(EXTRA_ACCOUNT_KEY) val groupId = args.getString(EXTRA_GROUP_ID) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt index c301f8591..f9d9253c9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt @@ -35,7 +35,7 @@ import org.mariotaku.twidere.view.holder.UserViewHolder class IncomingFriendshipsFragment : CursorUsersListFragment(), IUsersAdapter.RequestClickListener { - public override fun onCreateUsersLoader(context: Context, args: Bundle, + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val loader = IncomingFriendshipsLoader(context, accountKey, adapter.getData(), fromUser) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ListsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ListsFragment.kt index c8afe785b..088b1cca5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ListsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ListsFragment.kt @@ -32,7 +32,11 @@ class ListsFragment : AbsToolbarTabPagesFragment() { } override fun addTabs(adapter: SupportTabsAdapter) { - adapter.addTab(cls = UserListsFragment::class.java, args = arguments, name = getString(R.string.follows)) - adapter.addTab(cls = UserListMembershipsFragment::class.java, args = arguments, name = getString(R.string.belongs_to)) + adapter.addTab(cls = UserListsOwnershipsFragment::class.java, args = arguments, + name = getString(R.string.title_user_list_ownerships)) + adapter.addTab(cls = UserListSubscriptionsFragment::class.java, args = arguments, + name = getString(R.string.title_user_list_subscriptions)) + adapter.addTab(cls = UserListMembershipsFragment::class.java, args = arguments, + name = getString(R.string.title_user_list_memberships)) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt index a8b1f09f2..158ac2852 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt @@ -44,7 +44,7 @@ import org.mariotaku.twidere.view.holder.GroupViewHolder abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment(), LoaderCallbacks?>, GroupAdapterListener, KeyboardShortcutCallback { - private var mNavigationHelper: RecyclerViewNavigationHelper? = null + private lateinit var navigationHelper: RecyclerViewNavigationHelper val nextCursor: Long = 0 val prevCursor: Long = 0 @@ -109,15 +109,15 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment(), LoaderCallbacks>, UserListClickListener, KeyboardShortcutCallback { - private var navigationHelper: RecyclerViewNavigationHelper? = null + private lateinit var navigationHelper: RecyclerViewNavigationHelper var nextCursor: Long = 0 private set var prevCursor: Long = 0 @@ -115,15 +115,15 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment< get() = adapter.getData() override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { - return navigationHelper!!.handleKeyboardShortcutSingle(handler, keyCode, event, metaState) + return navigationHelper.handleKeyboardShortcutSingle(handler, keyCode, event, metaState) } override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean { - return navigationHelper!!.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState) + return navigationHelper.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState) } override fun isKeyboardShortcutHandled(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { - return navigationHelper!!.isKeyboardShortcutHandled(handler, keyCode, event, metaState) + return navigationHelper.isKeyboardShortcutHandled(handler, keyCode, event, metaState) } override fun onActivityCreated(savedInstanceState: Bundle?) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt index fe73537b6..b915241a9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt @@ -40,7 +40,6 @@ import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserClickListener import org.mariotaku.twidere.annotation.Referral import org.mariotaku.twidere.constant.IntentConstants import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SIMPLE_LAYOUT -import org.mariotaku.twidere.constant.SharedPreferenceConstants import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.loader.iface.IExtendedLoader import org.mariotaku.twidere.model.ParcelableUser @@ -56,9 +55,9 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?>, UserClickListener, KeyboardShortcutCallback, IUsersAdapter.FriendshipClickListener { - private val usersBusCallback: Any + private lateinit var navigationHelper: RecyclerViewNavigationHelper - private var navigationHelper: RecyclerViewNavigationHelper? = null + private val usersBusCallback: Any init { usersBusCallback = createMessageBusCallback() @@ -118,17 +117,17 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SearchUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SearchUsersFragment.kt index 6109092f8..2ac21772d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SearchUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SearchUsersFragment.kt @@ -41,7 +41,7 @@ class SearchUsersFragment : ParcelableUsersFragment() { super.onActivityCreated(savedInstanceState) } - public override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): Loader?> { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): Loader?> { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val query = args.getString(EXTRA_QUERY) val page = args.getInt(EXTRA_PAGE, 1) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt index 482dabb23..c5a733299 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt @@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey class StatusFavoritersListFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val statusId = args.getString(EXTRA_STATUS_ID) val loader = StatusFavoritersLoader(context, accountKey, diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt index 492392652..af28e7bd8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt @@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey class StatusRetweetersListFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt index a4b7030fe..aed41558b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt @@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.message.FriendshipTaskEvent class UserFollowersFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt index 2fe0ec9c3..6064d9e83 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt @@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.message.FriendshipTaskEvent class UserFriendsFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt index cab47b2d9..b5cbc2e5c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt @@ -439,7 +439,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, LoaderCa } - public override fun onStartLoading() { + override fun onStartLoading() { forceLoad() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt index a8086f75b..184093815 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt @@ -44,7 +44,7 @@ import java.util.* class UserListMembersFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val accountId = args.getParcelable(EXTRA_ACCOUNT_KEY) val listId = args.getString(EXTRA_LIST_ID) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt index 478cac8db..7f413b520 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt @@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey class UserListMembershipsFragment : ParcelableUserListsFragment() { - public override fun onCreateUserListsLoader(context: Context, + override fun onCreateUserListsLoader(context: Context, args: Bundle, fromUser: Boolean): Loader> { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt index 1fe973021..32c6882b9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt @@ -28,7 +28,7 @@ import org.mariotaku.twidere.model.UserKey class UserListSubscribersFragment : CursorUsersListFragment() { - public override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { val listId = args.getString(EXTRA_LIST_ID) val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt new file mode 100644 index 000000000..79c158fe2 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt @@ -0,0 +1,40 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.fragment + +import android.content.Context +import android.os.Bundle +import android.support.v4.content.Loader +import org.mariotaku.twidere.constant.IntentConstants.* +import org.mariotaku.twidere.loader.UserListSubscriptionsLoader +import org.mariotaku.twidere.model.ParcelableUserList +import org.mariotaku.twidere.model.UserKey + +class UserListSubscriptionsFragment : ParcelableUserListsFragment() { + + override fun onCreateUserListsLoader(context: Context, args: Bundle, fromUser: Boolean): Loader> { + val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) + val userKey = args.getParcelable(EXTRA_USER_KEY) + val screenName = args.getString(EXTRA_SCREEN_NAME) + val cursor = args.getLong(EXTRA_NEXT_CURSOR, -1) + return UserListSubscriptionsLoader(activity, accountKey, userKey, screenName, cursor, data) + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt similarity index 92% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt index 9707dcfe6..e114b351a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt @@ -28,21 +28,21 @@ import android.view.MenuItem import com.squareup.otto.Subscribe import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListsLoader +import org.mariotaku.twidere.loader.UserListOwnershipsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.message.UserListDestroyedEvent import org.mariotaku.twidere.util.MenuUtils import org.mariotaku.twidere.util.Utils -class UserListsFragment : ParcelableUserListsFragment() { +class UserListsOwnershipsFragment : ParcelableUserListsFragment() { - public override fun onCreateUserListsLoader(context: Context, + override fun onCreateUserListsLoader(context: Context, args: Bundle, fromUser: Boolean): Loader> { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - return UserListsLoader(activity, accountKey, userKey, screenName, true, data) + return UserListOwnershipsLoader(activity, accountKey, userKey, screenName, data) } override fun onActivityCreated(savedInstanceState: Bundle?) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/VideoPageFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/VideoPageFragment.kt index 2972ad176..5cb734267 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/VideoPageFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/VideoPageFragment.kt @@ -233,7 +233,7 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), MediaPlayer.OnPrep } } - public override fun onCreateMediaView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + override fun onCreateMediaView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { return inflater.inflate(R.layout.layout_media_viewer_texture_video_view, container, false) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt new file mode 100644 index 000000000..e52bb67f4 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt @@ -0,0 +1,103 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.loader + +import android.content.Context +import android.support.v4.content.AsyncTaskLoader +import android.util.Log +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +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.TwidereConstants.LOGTAG +import org.mariotaku.twidere.loader.iface.ICursorSupportLoader +import org.mariotaku.twidere.model.ParcelableUserList +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.util.ParcelableUserListUtils +import org.mariotaku.twidere.util.MicroBlogAPIFactory +import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList +import java.util.* + + +abstract class BaseUserListsLoader( + context: Context, + protected val accountId: UserKey, + override val cursor: Long, + data: List? +) : AsyncTaskLoader>(context), ICursorSupportLoader { + + protected val data = NoDuplicatesArrayList() + + override var nextCursor: Long = 0 + override var prevCursor: Long = 0 + + init { + if (data != null) { + this.data.addAll(data) + } + } + + @Throws(MicroBlogException::class) + abstract fun getUserLists(twitter: MicroBlog, paging: Paging): List + + override fun loadInBackground(): List { + val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return data + var listLoaded: List? = null + try { + val paging = Paging() + if (cursor > 0) { + paging.cursor(cursor) + } + listLoaded = getUserLists(twitter, paging) + } catch (e: MicroBlogException) { + Log.w(LOGTAG, e) + } + + if (listLoaded != null) { + val listSize = listLoaded.size + if (listLoaded is PageableResponseList<*>) { + nextCursor = (listLoaded as CursorSupport).nextCursor + prevCursor = listLoaded.previousCursor + 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))) + } + } else { + for (i in 0..listSize - 1) { + val list = listLoaded[i] + data.add(ParcelableUserListUtils.from(listLoaded[i], accountId, i.toLong(), isFollowing(list))) + } + } + } + Collections.sort(data) + return data + } + + override fun onStartLoading() { + forceLoad() + } + + protected open fun isFollowing(list: UserList): Boolean { + return list.isFollowing + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt index 12e6d55f8..2a0545844 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt @@ -60,7 +60,7 @@ class ConversationLoader( } @Throws(MicroBlogException::class) - public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List { + override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List { canLoadAllReplies = false when (details.type) { AccountType.TWITTER -> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt index 67491f34c..a58d3a64f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt @@ -39,7 +39,7 @@ class GroupMembersLoader( ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { if (groupId != null) return twitter.getGroupMembers(groupId, paging) else if (groupName != null) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt index cd9dbe4d9..613e25e84 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt @@ -41,7 +41,7 @@ abstract class ParcelableUsersLoader( } } - public override fun onStartLoading() { + override fun onStartLoading() { forceLoad() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/SavedSearchesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/SavedSearchesLoader.kt index b5d6393d7..1f65e5b2e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/SavedSearchesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/SavedSearchesLoader.kt @@ -47,7 +47,7 @@ class SavedSearchesLoader( return null } - public override fun onStartLoading() { + override fun onStartLoading() { forceLoad() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt index 2e4ecb577..d7f2d2d38 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt @@ -52,7 +52,7 @@ open class TweetSearchLoader( tabPosition, fromUser, loadingMore) { @Throws(MicroBlogException::class) - public override fun getStatuses(microBlog: MicroBlog, + override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List { if (query == null) throw MicroBlogException("Empty query") diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt index 0f775c054..90c2dde94 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt @@ -50,7 +50,7 @@ class UserFavoritesLoader( tabPosition, fromUser, loadingMore) { @Throws(MicroBlogException::class) - public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { + override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { if (userKey != null) { return microBlog.getFavorites(userKey.id, paging) } else if (screenName != null) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt index d02f53698..2eafc0d90 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt @@ -42,7 +42,7 @@ class UserListMembersLoader( ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { if (listId != null) { return twitter.getUserListMembers(listId, paging) } else if (listName != null) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt new file mode 100644 index 000000000..2e7437c90 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt @@ -0,0 +1,51 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.loader + +import android.content.Context + +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +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.model.ParcelableUserList +import org.mariotaku.twidere.model.UserKey + +class UserListMembershipsLoader( + context: Context, + accountKey: UserKey, + private val userKey: UserKey?, + private val screenName: String?, + cursor: Long, + data: List? +) : BaseUserListsLoader(context, accountKey, cursor, data) { + + @Throws(MicroBlogException::class) + override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList { + if (userKey != null) { + return twitter.getUserListMemberships(userKey.id, paging) + } else if (screenName != null) { + return twitter.getUserListMembershipsByScreenName(screenName, paging) + } + throw MicroBlogException("Invalid user") + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt new file mode 100644 index 000000000..df595b988 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt @@ -0,0 +1,51 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.loader + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.microblog.library.twitter.model.UserList +import org.mariotaku.twidere.model.ParcelableUserList +import org.mariotaku.twidere.model.UserKey + +class UserListOwnershipsLoader( + context: Context, + accountKey: UserKey, + private val userKey: UserKey?, + private val screenName: String?, + data: List? +) : BaseUserListsLoader(context, accountKey, 0, data) { + + @Throws(MicroBlogException::class) + override fun getUserLists(twitter: MicroBlog, paging: Paging): List { + if (userKey != null) { + return twitter.getUserListOwnerships(userKey.id, paging) + } else if (screenName != null) { + return twitter.getUserListOwnershipsByScreenName(screenName, paging) + } + throw MicroBlogException("Invalid user") + } + + override fun isFollowing(list: UserList): Boolean { + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt index 5e1030f16..c61c7149e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt @@ -42,7 +42,7 @@ class UserListSubscribersLoader( ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { if (listId != null) return twitter.getUserListSubscribers(listId, paging) else if (userKey != null) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt new file mode 100644 index 000000000..98d550417 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt @@ -0,0 +1,51 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.loader + +import android.content.Context + +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +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.model.ParcelableUserList +import org.mariotaku.twidere.model.UserKey + +class UserListSubscriptionsLoader( + context: Context, + accountKey: UserKey, + private val userKey: UserKey?, + private val screenName: String?, + cursor: Long, + data: List? +) : BaseUserListsLoader(context, accountKey, cursor, data) { + + @Throws(MicroBlogException::class) + override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList { + if (userKey != null) { + return twitter.getUserListSubscriptions(userKey.id, paging) + } else if (screenName != null) { + return twitter.getUserListSubscriptionsByScreenName(screenName, paging) + } + throw MicroBlogException("Invalid user") + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt index d0a104274..9375ca650 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt @@ -39,7 +39,7 @@ open class UserSearchLoader( ) : MicroBlogAPIUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - public override fun getUsers(twitter: MicroBlog, details: AccountDetails): List { + override fun getUsers(twitter: MicroBlog, details: AccountDetails): List { val paging = Paging() paging.page(page) when (details.type) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AbsFriendshipOperationTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AbsFriendshipOperationTask.kt index ae7f35dee..4c3cc82d4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AbsFriendshipOperationTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AbsFriendshipOperationTask.kt @@ -70,7 +70,7 @@ abstract class AbsFriendshipOperationTask( bus.post(event) } - public override fun doLongOperation(args: Arguments): SingleResponse { + override fun doLongOperation(args: Arguments): SingleResponse { val details = AccountUtils.getAccountDetails(AccountManager.get(context), args.accountKey, true) ?: return SingleResponse.getInstance() val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java) try { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/CacheUsersStatusesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/CacheUsersStatusesTask.kt index d7702e17d..efd8f2469 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/CacheUsersStatusesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/CacheUsersStatusesTask.kt @@ -35,7 +35,7 @@ class CacheUsersStatusesTask( private val context: Context ) : AbstractTask, Unit, Unit>() { - public override fun doLongOperation(params: TwitterListResponse) { + override fun doLongOperation(params: TwitterListResponse) { val resolver = context.contentResolver val extractor = Extractor() val list = params.data ?: return diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt index 913d50163..59e3c8eec 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt @@ -47,7 +47,7 @@ abstract class GetDirectMessagesTask( protected abstract val isOutgoing: Boolean - public override fun doLongOperation(param: RefreshTaskParam): List { + override fun doLongOperation(param: RefreshTaskParam): List { val accountKeys = param.accountKeys val sinceIds = param.sinceIds val maxIds = param.maxIds diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetSavedSearchesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetSavedSearchesTask.kt index e50b6662d..be805aa72 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetSavedSearchesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetSavedSearchesTask.kt @@ -22,7 +22,7 @@ class GetSavedSearchesTask( private val context: Context ) : AbstractTask, SingleResponse, Any?>() { - public override fun doLongOperation(params: Array): SingleResponse { + override fun doLongOperation(params: Array): SingleResponse { val cr = context.contentResolver for (accountKey in params) { val twitter = MicroBlogAPIFactory.getInstance(context, accountKey) ?: continue diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetTrendsTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetTrendsTask.kt index 32b81789f..e830a63a7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetTrendsTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetTrendsTask.kt @@ -37,7 +37,7 @@ abstract class GetTrendsTask( @Throws(MicroBlogException::class) abstract fun getTrends(twitter: MicroBlog): List - public override fun doLongOperation(param: Any?) { + override fun doLongOperation(param: Any?) { val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return try { val trends = getTrends(twitter) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt index 705d0376e..af907c326 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt @@ -53,7 +53,7 @@ abstract class GetActivitiesTask( GeneralComponentHelper.build(context).inject(this) } - public override fun doLongOperation(param: RefreshTaskParam) { + override fun doLongOperation(param: RefreshTaskParam) { if (param.shouldAbort) return val accountIds = param.accountKeys val maxIds = param.maxIds @@ -189,7 +189,7 @@ abstract class GetActivitiesTask( @Throws(MicroBlogException::class) protected abstract fun getActivities(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList - public override fun afterExecute(handler: ((Boolean) -> Unit)?, result: Unit) { + override fun afterExecute(handler: ((Boolean) -> Unit)?, result: Unit) { context.contentResolver.notifyChange(contentUri, null) bus.post(GetActivitiesTaskEvent(contentUri, false, null)) handler?.invoke(true) @@ -198,7 +198,7 @@ abstract class GetActivitiesTask( protected abstract val contentUri: Uri @UiThread - public override fun beforeExecute() { + override fun beforeExecute() { bus.post(GetActivitiesTaskEvent(contentUri, true, null)) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt index 7553fe6f9..7d4b7a295 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt @@ -67,7 +67,7 @@ abstract class GetStatusesTask( protected abstract val timelineType: String - public override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List) { + override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List) { context.contentResolver.notifyChange(contentUri, null) bus.post(GetStatusesTaskEvent(contentUri, false, AsyncTwitterWrapper.getException(result))) handler?.invoke(true) @@ -79,7 +79,7 @@ abstract class GetStatusesTask( protected abstract val errorInfoKey: String - public override fun doLongOperation(param: RefreshTaskParam): List { + override fun doLongOperation(param: RefreshTaskParam): List { if (param.shouldAbort) return emptyList() val accountKeys = param.accountKeys val maxIds = param.maxIds diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/twitter/card/CardPollViewController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/twitter/card/CardPollViewController.kt index 654e9e67a..b4eb0f30b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/twitter/card/CardPollViewController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/controller/twitter/card/CardPollViewController.kt @@ -147,12 +147,12 @@ class CardPollViewController : ContainerView.ViewController() { cardData.putString("selected_choice", (i + 1).toString()) val task = object : AbstractTask() { - public override fun afterExecute(handler: CardPollViewController?, result: ParcelableCardEntity?) { + override fun afterExecute(handler: CardPollViewController?, result: ParcelableCardEntity?) { result ?: return handler?.displayAndReloadPoll(result, status) } - public override fun doLongOperation(cardDataMap: CardDataMap): ParcelableCardEntity? { + override fun doLongOperation(cardDataMap: CardDataMap): ParcelableCardEntity? { val details = AccountUtils.getAccountDetails(AccountManager.get(context), card.account_key, true) ?: return null val caps = details.newMicroBlogInstance(context, cls = TwitterCaps::class.java) diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 046ed384c..0addb6ac9 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -486,6 +486,9 @@ Following you Follows + Subscriptions + Belongs to + Created Font Font family