refactored user lists fragment

code cleanup
This commit is contained in:
Mariotaku Lee 2017-01-30 21:41:34 +08:00
parent 52ebf05b84
commit 20c49e727c
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
49 changed files with 366 additions and 308 deletions

View File

@ -148,11 +148,11 @@ public interface ListResources {
@GET("/lists/subscriptions.json") @GET("/lists/subscriptions.json")
PageableResponseList<UserList> getUserListSubscriptionsByScreenName(@Query("screen_name") String listOwnerScreenName, long cursor) PageableResponseList<UserList> getUserListSubscriptionsByScreenName(@Query("screen_name") String listOwnerScreenName, @Query Paging paging)
throws MicroBlogException; throws MicroBlogException;
@GET("/lists/subscriptions.json") @GET("/lists/subscriptions.json")
PageableResponseList<UserList> getUserListSubscriptions(@Query("user_id") String userId, long cursor) PageableResponseList<UserList> getUserListSubscriptions(@Query("user_id") String userId, @Query Paging paging)
throws MicroBlogException; throws MicroBlogException;
@GET("/lists/show.json") @GET("/lists/show.json")

View File

@ -1,117 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<List<ParcelableUserList>>
implements TwidereConstants, ICursorSupportLoader {
protected final NoDuplicatesArrayList<ParcelableUserList> 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<ParcelableUserList> 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<UserList> getUserLists(final MicroBlog twitter) throws MicroBlogException;
@Override
public List<ParcelableUserList> loadInBackground() {
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(getContext(), mAccountId);
List<UserList> 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();
}
}

View File

@ -1,60 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList> data) {
super(context, accountKey, cursor, data);
mUserKey = userKey;
mScreenName = screenName;
}
@Override
public PageableResponseList<UserList> 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;
}
}

View File

@ -1,62 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList> data) {
super(context, accountKey, 0, data);
mUserKey = userKey;
mScreenName = screenName;
mReverse = reverse;
}
@Override
public ResponseList<UserList> 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;
}
}

View File

@ -89,7 +89,7 @@ class BrowserSignInActivity : BaseActivity() {
getRequestToken() getRequestToken()
} }
public override fun onDestroy() { override fun onDestroy() {
if (task?.status == AsyncTask.Status.RUNNING) { if (task?.status == AsyncTask.Status.RUNNING) {
task?.cancel(true) task?.cancel(true)
} }

View File

@ -143,7 +143,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
// Listeners // Listeners
private var locationListener: LocationListener? = null 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) { when (requestCode) {
REQUEST_TAKE_PHOTO, REQUEST_PICK_MEDIA -> { REQUEST_TAKE_PHOTO, REQUEST_PICK_MEDIA -> {
if (resultCode == Activity.RESULT_OK && intent != null) { if (resultCode == Activity.RESULT_OK && intent != null) {
@ -213,7 +213,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
return textChanged || hasMedia() || isEditingDraft return textChanged || hasMedia() || isEditingDraft
} }
public override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
outState.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountsAdapter.selectedAccountKeys) outState.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountsAdapter.selectedAccountKeys)
outState.putParcelableArrayList(EXTRA_MEDIA, ArrayList<Parcelable>(mediaList)) outState.putParcelableArrayList(EXTRA_MEDIA, ArrayList<Parcelable>(mediaList))
outState.putBoolean(EXTRA_IS_POSSIBLY_SENSITIVE, possiblySensitive) outState.putBoolean(EXTRA_IS_POSSIBLY_SENSITIVE, possiblySensitive)

View File

@ -37,7 +37,7 @@ import org.mariotaku.twidere.nyan.NyanWallpaperService
class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChangeListener { class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChangeListener {
private var helper: NyanSurfaceHelper? = null private lateinit var helper: NyanSurfaceHelper
override fun onLongClick(v: View): Boolean { override fun onLongClick(v: View): Boolean {
Toast.makeText(this, R.string.message_toast_nyan_sakamoto, Toast.LENGTH_SHORT).show() 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() { override fun onStart() {
super.onStart() super.onStart()
helper?.start() helper.start()
} }
override fun onStop() { override fun onStop() {
helper?.stop() helper.stop()
super.onStop() super.onStop()
} }
@ -97,7 +97,7 @@ class NyanActivity : BaseActivity(), OnLongClickListener, OnSharedPreferenceChan
private fun updateSurface() { private fun updateSurface() {
val def = resources.getInteger(R.integer.default_live_wallpaper_scale) 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())
} }
} }

View File

@ -24,7 +24,6 @@ import android.content.Intent
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.DialogFragment import android.support.v4.app.DialogFragment
import android.support.v4.app.LoaderManager
import android.text.TextUtils import android.text.TextUtils
import android.text.TextUtils.isEmpty import android.text.TextUtils.isEmpty
import android.util.Log import android.util.Log
@ -44,7 +43,6 @@ import org.mariotaku.twidere.adapter.UserAutoCompleteAdapter
import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.IntentConstants.*
import org.mariotaku.twidere.fragment.CreateUserListDialogFragment import org.mariotaku.twidere.fragment.CreateUserListDialogFragment
import org.mariotaku.twidere.fragment.ProgressDialogFragment import org.mariotaku.twidere.fragment.ProgressDialogFragment
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.model.SingleResponse import org.mariotaku.twidere.model.SingleResponse
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
@ -126,9 +124,6 @@ class UserListSelectorActivity : BaseActivity(), OnClickListener, OnItemClickLis
AsyncTaskUtils.executeTask(task) AsyncTaskUtils.executeTask(task)
} }
private val isSelectingUser: Boolean
get() = INTENT_ACTION_SELECT_USER == intent.action
private fun setUserListsData(data: List<ParcelableUserList>, isMyAccount: Boolean) { private fun setUserListsData(data: List<ParcelableUserList>, isMyAccount: Boolean) {
userListsAdapter.setData(data, true) userListsAdapter.setData(data, true)
userListsContainer.visibility = View.VISIBLE userListsContainer.visibility = View.VISIBLE

View File

@ -123,7 +123,7 @@ class GroupFragment : AbsToolbarTabPagesFragment(), LoaderCallbacks<SingleRespon
} }
public override fun onStartLoading() { override fun onStartLoading() {
forceLoad() forceLoad()
} }

View File

@ -28,7 +28,7 @@ import org.mariotaku.twidere.model.UserKey
class GroupMembersFragment : CursorUsersListFragment() { class GroupMembersFragment : CursorUsersListFragment() {
public override fun onCreateUsersLoader(context: Context, override fun onCreateUsersLoader(context: Context,
args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { args: Bundle, fromUser: Boolean): CursorSupportUsersLoader {
val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val groupId = args.getString(EXTRA_GROUP_ID) val groupId = args.getString(EXTRA_GROUP_ID)

View File

@ -35,7 +35,7 @@ import org.mariotaku.twidere.view.holder.UserViewHolder
class IncomingFriendshipsFragment : CursorUsersListFragment(), IUsersAdapter.RequestClickListener { class IncomingFriendshipsFragment : CursorUsersListFragment(), IUsersAdapter.RequestClickListener {
public override fun onCreateUsersLoader(context: Context, args: Bundle, override fun onCreateUsersLoader(context: Context, args: Bundle,
fromUser: Boolean): CursorSupportUsersLoader { fromUser: Boolean): CursorSupportUsersLoader {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val loader = IncomingFriendshipsLoader(context, accountKey, adapter.getData(), fromUser) val loader = IncomingFriendshipsLoader(context, accountKey, adapter.getData(), fromUser)

View File

@ -32,7 +32,11 @@ class ListsFragment : AbsToolbarTabPagesFragment() {
} }
override fun addTabs(adapter: SupportTabsAdapter) { override fun addTabs(adapter: SupportTabsAdapter) {
adapter.addTab(cls = UserListsFragment::class.java, args = arguments, name = getString(R.string.follows)) adapter.addTab(cls = UserListsOwnershipsFragment::class.java, args = arguments,
adapter.addTab(cls = UserListMembershipsFragment::class.java, args = arguments, name = getString(R.string.belongs_to)) 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))
} }
} }

View File

@ -44,7 +44,7 @@ import org.mariotaku.twidere.view.holder.GroupViewHolder
abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<ParcelableGroupsAdapter>(), abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<ParcelableGroupsAdapter>(),
LoaderCallbacks<List<ParcelableGroup>?>, GroupAdapterListener, KeyboardShortcutCallback { LoaderCallbacks<List<ParcelableGroup>?>, GroupAdapterListener, KeyboardShortcutCallback {
private var mNavigationHelper: RecyclerViewNavigationHelper? = null private lateinit var navigationHelper: RecyclerViewNavigationHelper
val nextCursor: Long = 0 val nextCursor: Long = 0
val prevCursor: Long = 0 val prevCursor: Long = 0
@ -109,15 +109,15 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
get() = adapter.getData() get() = adapter.getData()
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
return mNavigationHelper!!.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 { override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
return mNavigationHelper!!.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 { override fun isKeyboardShortcutHandled(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
return mNavigationHelper!!.isKeyboardShortcutHandled(handler, keyCode, event, metaState) return navigationHelper.isKeyboardShortcutHandled(handler, keyCode, event, metaState)
} }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -125,7 +125,7 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment<Par
val layoutManager = layoutManager val layoutManager = layoutManager
adapter.groupAdapterListener = this adapter.groupAdapterListener = this
mNavigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter, navigationHelper = RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter,
this) this)
val loaderArgs = Bundle(arguments) val loaderArgs = Bundle(arguments)
loaderArgs.putBoolean(EXTRA_FROM_USER, true) loaderArgs.putBoolean(EXTRA_FROM_USER, true)

View File

@ -44,7 +44,7 @@ import org.mariotaku.twidere.view.holder.UserListViewHolder
abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<ParcelableUserListsAdapter>(), LoaderCallbacks<List<ParcelableUserList>>, UserListClickListener, KeyboardShortcutCallback { abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<ParcelableUserListsAdapter>(), LoaderCallbacks<List<ParcelableUserList>>, UserListClickListener, KeyboardShortcutCallback {
private var navigationHelper: RecyclerViewNavigationHelper? = null private lateinit var navigationHelper: RecyclerViewNavigationHelper
var nextCursor: Long = 0 var nextCursor: Long = 0
private set private set
var prevCursor: Long = 0 var prevCursor: Long = 0
@ -115,15 +115,15 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment<
get() = adapter.getData() get() = adapter.getData()
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { 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 { 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 { 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?) { override fun onActivityCreated(savedInstanceState: Bundle?) {

View File

@ -40,7 +40,6 @@ import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserClickListener
import org.mariotaku.twidere.annotation.Referral import org.mariotaku.twidere.annotation.Referral
import org.mariotaku.twidere.constant.IntentConstants import org.mariotaku.twidere.constant.IntentConstants
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SIMPLE_LAYOUT 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.constant.newDocumentApiKey
import org.mariotaku.twidere.loader.iface.IExtendedLoader import org.mariotaku.twidere.loader.iface.IExtendedLoader
import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUser
@ -56,9 +55,9 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
LoaderCallbacks<List<ParcelableUser>?>, UserClickListener, KeyboardShortcutCallback, LoaderCallbacks<List<ParcelableUser>?>, UserClickListener, KeyboardShortcutCallback,
IUsersAdapter.FriendshipClickListener { IUsersAdapter.FriendshipClickListener {
private val usersBusCallback: Any private lateinit var navigationHelper: RecyclerViewNavigationHelper
private var navigationHelper: RecyclerViewNavigationHelper? = null private val usersBusCallback: Any
init { init {
usersBusCallback = createMessageBusCallback() usersBusCallback = createMessageBusCallback()
@ -118,17 +117,17 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int,
event: KeyEvent, metaState: Int): Boolean { 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, override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int,
repeatCount: Int, event: KeyEvent, metaState: Int): Boolean { 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, override fun isKeyboardShortcutHandled(handler: KeyboardShortcutsHandler, keyCode: Int,
event: KeyEvent, metaState: Int): Boolean { event: KeyEvent, metaState: Int): Boolean {
return navigationHelper!!.isKeyboardShortcutHandled(handler, keyCode, event, metaState) return navigationHelper.isKeyboardShortcutHandled(handler, keyCode, event, metaState)
} }
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableUser>?> { override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableUser>?> {

View File

@ -41,7 +41,7 @@ class SearchUsersFragment : ParcelableUsersFragment() {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
} }
public override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): Loader<List<ParcelableUser>?> { override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): Loader<List<ParcelableUser>?> {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val query = args.getString(EXTRA_QUERY) val query = args.getString(EXTRA_QUERY)
val page = args.getInt(EXTRA_PAGE, 1) val page = args.getInt(EXTRA_PAGE, 1)

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey
class StatusFavoritersListFragment : CursorUsersListFragment() { 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<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val statusId = args.getString(EXTRA_STATUS_ID) val statusId = args.getString(EXTRA_STATUS_ID)
val loader = StatusFavoritersLoader(context, accountKey, val loader = StatusFavoritersLoader(context, accountKey,

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey
class StatusRetweetersListFragment : CursorUsersListFragment() { class StatusRetweetersListFragment : CursorUsersListFragment() {
public override fun onCreateUsersLoader(context: Context, override fun onCreateUsersLoader(context: Context,
args: Bundle, args: Bundle,
fromUser: Boolean): CursorSupportUsersLoader { fromUser: Boolean): CursorSupportUsersLoader {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.message.FriendshipTaskEvent
class UserFollowersFragment : CursorUsersListFragment() { class UserFollowersFragment : CursorUsersListFragment() {
public override fun onCreateUsersLoader(context: Context, override fun onCreateUsersLoader(context: Context,
args: Bundle, args: Bundle,
fromUser: Boolean): CursorSupportUsersLoader { fromUser: Boolean): CursorSupportUsersLoader {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.message.FriendshipTaskEvent
class UserFriendsFragment : CursorUsersListFragment() { class UserFriendsFragment : CursorUsersListFragment() {
public override fun onCreateUsersLoader(context: Context, override fun onCreateUsersLoader(context: Context,
args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { args: Bundle, fromUser: Boolean): CursorSupportUsersLoader {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)

View File

@ -439,7 +439,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, LoaderCa
} }
public override fun onStartLoading() { override fun onStartLoading() {
forceLoad() forceLoad()
} }

View File

@ -44,7 +44,7 @@ import java.util.*
class UserListMembersFragment : CursorUsersListFragment() { class UserListMembersFragment : CursorUsersListFragment() {
public override fun onCreateUsersLoader(context: Context, override fun onCreateUsersLoader(context: Context,
args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { args: Bundle, fromUser: Boolean): CursorSupportUsersLoader {
val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountId = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val listId = args.getString(EXTRA_LIST_ID) val listId = args.getString(EXTRA_LIST_ID)

View File

@ -29,7 +29,7 @@ import org.mariotaku.twidere.model.UserKey
class UserListMembershipsFragment : ParcelableUserListsFragment() { class UserListMembershipsFragment : ParcelableUserListsFragment() {
public override fun onCreateUserListsLoader(context: Context, override fun onCreateUserListsLoader(context: Context,
args: Bundle, fromUser: Boolean): Loader<List<ParcelableUserList>> { args: Bundle, fromUser: Boolean): Loader<List<ParcelableUserList>> {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)

View File

@ -28,7 +28,7 @@ import org.mariotaku.twidere.model.UserKey
class UserListSubscribersFragment : CursorUsersListFragment() { 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 listId = args.getString(EXTRA_LIST_ID)
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)

View File

@ -0,0 +1,40 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<List<ParcelableUserList>> {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(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)
}
}

View File

@ -28,21 +28,21 @@ import android.view.MenuItem
import com.squareup.otto.Subscribe import com.squareup.otto.Subscribe
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.IntentConstants.* 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.ParcelableUserList
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.message.UserListDestroyedEvent import org.mariotaku.twidere.model.message.UserListDestroyedEvent
import org.mariotaku.twidere.util.MenuUtils import org.mariotaku.twidere.util.MenuUtils
import org.mariotaku.twidere.util.Utils 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<List<ParcelableUserList>> { args: Bundle, fromUser: Boolean): Loader<List<ParcelableUserList>> {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
val screenName = args.getString(EXTRA_SCREEN_NAME) 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?) { override fun onActivityCreated(savedInstanceState: Bundle?) {

View File

@ -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) return inflater.inflate(R.layout.layout_media_viewer_texture_video_view, container, false)
} }

View File

@ -0,0 +1,103 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList>?
) : AsyncTaskLoader<List<ParcelableUserList>>(context), ICursorSupportLoader {
protected val data = NoDuplicatesArrayList<ParcelableUserList>()
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<UserList>
override fun loadInBackground(): List<ParcelableUserList> {
val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return data
var listLoaded: List<UserList>? = 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
}
}

View File

@ -60,7 +60,7 @@ class ConversationLoader(
} }
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List<Status> { override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List<Status> {
canLoadAllReplies = false canLoadAllReplies = false
when (details.type) { when (details.type) {
AccountType.TWITTER -> { AccountType.TWITTER -> {

View File

@ -39,7 +39,7 @@ class GroupMembersLoader(
) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<User> { override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<User> {
if (groupId != null) if (groupId != null)
return twitter.getGroupMembers(groupId, paging) return twitter.getGroupMembers(groupId, paging)
else if (groupName != null) else if (groupName != null)

View File

@ -41,7 +41,7 @@ abstract class ParcelableUsersLoader(
} }
} }
public override fun onStartLoading() { override fun onStartLoading() {
forceLoad() forceLoad()
} }

View File

@ -47,7 +47,7 @@ class SavedSearchesLoader(
return null return null
} }
public override fun onStartLoading() { override fun onStartLoading() {
forceLoad() forceLoad()
} }

View File

@ -52,7 +52,7 @@ open class TweetSearchLoader(
tabPosition, fromUser, loadingMore) { tabPosition, fromUser, loadingMore) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getStatuses(microBlog: MicroBlog, override fun getStatuses(microBlog: MicroBlog,
details: AccountDetails, details: AccountDetails,
paging: Paging): List<Status> { paging: Paging): List<Status> {
if (query == null) throw MicroBlogException("Empty query") if (query == null) throw MicroBlogException("Empty query")

View File

@ -50,7 +50,7 @@ class UserFavoritesLoader(
tabPosition, fromUser, loadingMore) { tabPosition, fromUser, loadingMore) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Status> { override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Status> {
if (userKey != null) { if (userKey != null) {
return microBlog.getFavorites(userKey.id, paging) return microBlog.getFavorites(userKey.id, paging)
} else if (screenName != null) { } else if (screenName != null) {

View File

@ -42,7 +42,7 @@ class UserListMembersLoader(
) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList<User> { override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList<User> {
if (listId != null) { if (listId != null) {
return twitter.getUserListMembers(listId, paging) return twitter.getUserListMembers(listId, paging)
} else if (listName != null) { } else if (listName != null) {

View File

@ -0,0 +1,51 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList>?
) : BaseUserListsLoader(context, accountKey, cursor, data) {
@Throws(MicroBlogException::class)
override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList<UserList> {
if (userKey != null) {
return twitter.getUserListMemberships(userKey.id, paging)
} else if (screenName != null) {
return twitter.getUserListMembershipsByScreenName(screenName, paging)
}
throw MicroBlogException("Invalid user")
}
}

View File

@ -0,0 +1,51 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList>?
) : BaseUserListsLoader(context, accountKey, 0, data) {
@Throws(MicroBlogException::class)
override fun getUserLists(twitter: MicroBlog, paging: Paging): List<UserList> {
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
}
}

View File

@ -42,7 +42,7 @@ class UserListSubscribersLoader(
) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList<User> { override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList<User> {
if (listId != null) if (listId != null)
return twitter.getUserListSubscribers(listId, paging) return twitter.getUserListSubscribers(listId, paging)
else if (userKey != null) else if (userKey != null)

View File

@ -0,0 +1,51 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.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<ParcelableUserList>?
) : BaseUserListsLoader(context, accountKey, cursor, data) {
@Throws(MicroBlogException::class)
override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList<UserList> {
if (userKey != null) {
return twitter.getUserListSubscriptions(userKey.id, paging)
} else if (screenName != null) {
return twitter.getUserListSubscriptionsByScreenName(screenName, paging)
}
throw MicroBlogException("Invalid user")
}
}

View File

@ -39,7 +39,7 @@ open class UserSearchLoader(
) : MicroBlogAPIUsersLoader(context, accountKey, data, fromUser) { ) : MicroBlogAPIUsersLoader(context, accountKey, data, fromUser) {
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
public override fun getUsers(twitter: MicroBlog, details: AccountDetails): List<User> { override fun getUsers(twitter: MicroBlog, details: AccountDetails): List<User> {
val paging = Paging() val paging = Paging()
paging.page(page) paging.page(page)
when (details.type) { when (details.type) {

View File

@ -70,7 +70,7 @@ abstract class AbsFriendshipOperationTask(
bus.post(event) bus.post(event)
} }
public override fun doLongOperation(args: Arguments): SingleResponse<ParcelableUser> { override fun doLongOperation(args: Arguments): SingleResponse<ParcelableUser> {
val details = AccountUtils.getAccountDetails(AccountManager.get(context), args.accountKey, true) ?: return SingleResponse.getInstance() val details = AccountUtils.getAccountDetails(AccountManager.get(context), args.accountKey, true) ?: return SingleResponse.getInstance()
val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java) val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java)
try { try {

View File

@ -35,7 +35,7 @@ class CacheUsersStatusesTask(
private val context: Context private val context: Context
) : AbstractTask<TwitterListResponse<Status>, Unit, Unit>() { ) : AbstractTask<TwitterListResponse<Status>, Unit, Unit>() {
public override fun doLongOperation(params: TwitterListResponse<Status>) { override fun doLongOperation(params: TwitterListResponse<Status>) {
val resolver = context.contentResolver val resolver = context.contentResolver
val extractor = Extractor() val extractor = Extractor()
val list = params.data ?: return val list = params.data ?: return

View File

@ -47,7 +47,7 @@ abstract class GetDirectMessagesTask(
protected abstract val isOutgoing: Boolean protected abstract val isOutgoing: Boolean
public override fun doLongOperation(param: RefreshTaskParam): List<TwitterWrapper.MessageListResponse> { override fun doLongOperation(param: RefreshTaskParam): List<TwitterWrapper.MessageListResponse> {
val accountKeys = param.accountKeys val accountKeys = param.accountKeys
val sinceIds = param.sinceIds val sinceIds = param.sinceIds
val maxIds = param.maxIds val maxIds = param.maxIds

View File

@ -22,7 +22,7 @@ class GetSavedSearchesTask(
private val context: Context private val context: Context
) : AbstractTask<Array<UserKey>, SingleResponse<Unit>, Any?>() { ) : AbstractTask<Array<UserKey>, SingleResponse<Unit>, Any?>() {
public override fun doLongOperation(params: Array<UserKey>): SingleResponse<Unit> { override fun doLongOperation(params: Array<UserKey>): SingleResponse<Unit> {
val cr = context.contentResolver val cr = context.contentResolver
for (accountKey in params) { for (accountKey in params) {
val twitter = MicroBlogAPIFactory.getInstance(context, accountKey) ?: continue val twitter = MicroBlogAPIFactory.getInstance(context, accountKey) ?: continue

View File

@ -37,7 +37,7 @@ abstract class GetTrendsTask(
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
abstract fun getTrends(twitter: MicroBlog): List<Trends> abstract fun getTrends(twitter: MicroBlog): List<Trends>
public override fun doLongOperation(param: Any?) { override fun doLongOperation(param: Any?) {
val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return
try { try {
val trends = getTrends(twitter) val trends = getTrends(twitter)

View File

@ -53,7 +53,7 @@ abstract class GetActivitiesTask(
GeneralComponentHelper.build(context).inject(this) GeneralComponentHelper.build(context).inject(this)
} }
public override fun doLongOperation(param: RefreshTaskParam) { override fun doLongOperation(param: RefreshTaskParam) {
if (param.shouldAbort) return if (param.shouldAbort) return
val accountIds = param.accountKeys val accountIds = param.accountKeys
val maxIds = param.maxIds val maxIds = param.maxIds
@ -189,7 +189,7 @@ abstract class GetActivitiesTask(
@Throws(MicroBlogException::class) @Throws(MicroBlogException::class)
protected abstract fun getActivities(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Activity> protected abstract fun getActivities(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Activity>
public override fun afterExecute(handler: ((Boolean) -> Unit)?, result: Unit) { override fun afterExecute(handler: ((Boolean) -> Unit)?, result: Unit) {
context.contentResolver.notifyChange(contentUri, null) context.contentResolver.notifyChange(contentUri, null)
bus.post(GetActivitiesTaskEvent(contentUri, false, null)) bus.post(GetActivitiesTaskEvent(contentUri, false, null))
handler?.invoke(true) handler?.invoke(true)
@ -198,7 +198,7 @@ abstract class GetActivitiesTask(
protected abstract val contentUri: Uri protected abstract val contentUri: Uri
@UiThread @UiThread
public override fun beforeExecute() { override fun beforeExecute() {
bus.post(GetActivitiesTaskEvent(contentUri, true, null)) bus.post(GetActivitiesTaskEvent(contentUri, true, null))
} }
} }

View File

@ -67,7 +67,7 @@ abstract class GetStatusesTask(
protected abstract val timelineType: String protected abstract val timelineType: String
public override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List<TwitterWrapper.StatusListResponse>) { override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List<TwitterWrapper.StatusListResponse>) {
context.contentResolver.notifyChange(contentUri, null) context.contentResolver.notifyChange(contentUri, null)
bus.post(GetStatusesTaskEvent(contentUri, false, AsyncTwitterWrapper.getException(result))) bus.post(GetStatusesTaskEvent(contentUri, false, AsyncTwitterWrapper.getException(result)))
handler?.invoke(true) handler?.invoke(true)
@ -79,7 +79,7 @@ abstract class GetStatusesTask(
protected abstract val errorInfoKey: String protected abstract val errorInfoKey: String
public override fun doLongOperation(param: RefreshTaskParam): List<TwitterWrapper.StatusListResponse> { override fun doLongOperation(param: RefreshTaskParam): List<TwitterWrapper.StatusListResponse> {
if (param.shouldAbort) return emptyList() if (param.shouldAbort) return emptyList()
val accountKeys = param.accountKeys val accountKeys = param.accountKeys
val maxIds = param.maxIds val maxIds = param.maxIds

View File

@ -147,12 +147,12 @@ class CardPollViewController : ContainerView.ViewController() {
cardData.putString("selected_choice", (i + 1).toString()) cardData.putString("selected_choice", (i + 1).toString())
val task = object : AbstractTask<CardDataMap, ParcelableCardEntity, CardPollViewController>() { val task = object : AbstractTask<CardDataMap, ParcelableCardEntity, CardPollViewController>() {
public override fun afterExecute(handler: CardPollViewController?, result: ParcelableCardEntity?) { override fun afterExecute(handler: CardPollViewController?, result: ParcelableCardEntity?) {
result ?: return result ?: return
handler?.displayAndReloadPoll(result, status) handler?.displayAndReloadPoll(result, status)
} }
public override fun doLongOperation(cardDataMap: CardDataMap): ParcelableCardEntity? { override fun doLongOperation(cardDataMap: CardDataMap): ParcelableCardEntity? {
val details = AccountUtils.getAccountDetails(AccountManager.get(context), val details = AccountUtils.getAccountDetails(AccountManager.get(context),
card.account_key, true) ?: return null card.account_key, true) ?: return null
val caps = details.newMicroBlogInstance(context, cls = TwitterCaps::class.java) val caps = details.newMicroBlogInstance(context, cls = TwitterCaps::class.java)

View File

@ -486,6 +486,9 @@
<string name="following_you">Following you</string> <string name="following_you">Following you</string>
<string name="follows">Follows</string> <string name="follows">Follows</string>
<string name="title_user_list_subscriptions">Subscriptions</string>
<string name="title_user_list_memberships">Belongs to</string>
<string name="title_user_list_ownerships">Created</string>
<string name="font">Font</string> <string name="font">Font</string>
<string name="font_family">Font family</string> <string name="font_family">Font family</string>