diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/MutesUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/MutesUsersLoader.java deleted file mode 100644 index 84b6449a9..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/MutesUsersLoader.java +++ /dev/null @@ -1,51 +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.annotation.NonNull; -import android.support.annotation.Nullable; - -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.User; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class MutesUsersLoader extends CursorSupportUsersLoader { - - public MutesUsersLoader(final Context context, @Nullable final UserKey accountKey, - @Nullable final List data, boolean fromUser) { - super(context, accountKey, data, fromUser); - } - - @NonNull - @Override - protected final PageableResponseList getCursoredUsers(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull final Paging paging) - throws MicroBlogException { - return twitter.getMutesUsersList(paging); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/StatusFavoritersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/StatusFavoritersLoader.java deleted file mode 100644 index 6924523c6..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/StatusFavoritersLoader.java +++ /dev/null @@ -1,56 +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.annotation.NonNull; - -import org.mariotaku.microblog.library.MicroBlog; -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.IDs; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class StatusFavoritersLoader extends CursorSupportUsersLoader { - - private final String mStatusId; - - public StatusFavoritersLoader(final Context context, final UserKey accountKey, - final String statusId, final List data, - final boolean fromUser) { - super(context, accountKey, data, fromUser); - mStatusId = statusId; - } - - @NonNull - @Override - protected IDs getIDs(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull final Paging paging) throws MicroBlogException { - return twitter.getStatusActivitySummary(mStatusId).getFavoriters(); - } - - @Override - protected boolean useIDs(@NonNull ParcelableCredentials credentials) { - return true; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/StatusRetweetersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/StatusRetweetersLoader.java deleted file mode 100644 index 01ddbfb4e..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/StatusRetweetersLoader.java +++ /dev/null @@ -1,56 +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.annotation.NonNull; - -import org.mariotaku.microblog.library.MicroBlog; -import org.mariotaku.microblog.library.MicroBlogException; -import org.mariotaku.microblog.library.twitter.model.IDs; -import org.mariotaku.microblog.library.twitter.model.Paging; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class StatusRetweetersLoader extends CursorSupportUsersLoader { - - private final String mStatusId; - - public StatusRetweetersLoader(final Context context, final UserKey accountKey, - final String statusId, final List data, - final boolean fromUser) { - super(context, accountKey, data, fromUser); - mStatusId = statusId; - } - - @NonNull - @Override - protected IDs getIDs(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull final Paging paging) throws MicroBlogException { - return twitter.getRetweetersIDs(mStatusId, paging); - } - - @Override - protected boolean useIDs(@NonNull ParcelableCredentials credentials) { - return true; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserBlocksLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserBlocksLoader.java deleted file mode 100644 index 4ddd21b1e..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserBlocksLoader.java +++ /dev/null @@ -1,58 +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.annotation.NonNull; - -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.User; -import org.mariotaku.twidere.annotation.AccountType; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; -import org.mariotaku.twidere.model.util.ParcelableAccountUtils; - -import java.util.List; - -public class UserBlocksLoader extends CursorSupportUsersLoader { - - public UserBlocksLoader(final Context context, final UserKey accountKey, - final List data, boolean fromUser) { - super(context, accountKey, data, fromUser); - } - - @NonNull - @Override - protected final List getCursoredUsers(@NonNull final MicroBlog twitter, - @NonNull ParcelableCredentials credentials, - @NonNull final Paging paging) - throws MicroBlogException { - switch (ParcelableAccountUtils.getAccountType(credentials)) { - case AccountType.FANFOU: { - return twitter.getFanfouBlocking(paging); - } - } - return twitter.getBlocksList(paging); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembersLoader.java deleted file mode 100644 index ed5f50f88..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListMembersLoader.java +++ /dev/null @@ -1,65 +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.annotation.NonNull; - -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.User; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class UserListMembersLoader extends CursorSupportUsersLoader { - - private final String mListId; - private final UserKey mUserKey; - private final String mScreenName, mListName; - - public UserListMembersLoader(final Context context, final UserKey accountKey, final String listId, - final UserKey userKey, final String screenName, final String listName, - final List data, boolean fromUser) { - super(context, accountKey, data, fromUser); - mListId = listId; - mUserKey = userKey; - mScreenName = screenName; - mListName = listName; - } - - @NonNull - @Override - public PageableResponseList getCursoredUsers(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull final Paging paging) - throws MicroBlogException { - if (mListId != null) - return twitter.getUserListMembers(mListId, paging); - else if (mUserKey != null) - return twitter.getUserListMembers(mListName.replace(' ', '-'), mUserKey.getId(), paging); - else if (mScreenName != null) - return twitter.getUserListMembersByScreenName(mListName.replace(' ', '-'), mScreenName, paging); - throw new MicroBlogException("list_id or list_name and user_id (or screen_name) required"); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListSubscribersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserListSubscribersLoader.java deleted file mode 100644 index fd3e8ea3d..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserListSubscribersLoader.java +++ /dev/null @@ -1,65 +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.annotation.NonNull; - -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.User; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; - -import java.util.List; - -public class UserListSubscribersLoader extends CursorSupportUsersLoader { - - private final String mListId; - private final UserKey mUserKey; - private final String mScreenName, mListName; - - public UserListSubscribersLoader(final Context context, final UserKey accountKey, final String listId, - final UserKey userKey, final String screenName, final String listName, - final List data, boolean fromUser) { - super(context, accountKey, data, fromUser); - mListId = listId; - mUserKey = userKey; - mScreenName = screenName; - mListName = listName; - } - - @NonNull - @Override - public PageableResponseList getCursoredUsers(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull final Paging paging) - throws MicroBlogException { - if (mListId != null) - return twitter.getUserListSubscribers(mListId, paging); - else if (mUserKey != null) - return twitter.getUserListSubscribers(mListName.replace(' ', '-'), mUserKey.getId(), paging); - else if (mScreenName != null) - return twitter.getUserListSubscribersByScreenName(mListName.replace(' ', '-'), mScreenName, paging); - throw new MicroBlogException("list_id or list_name and user_id (or screen_name) required"); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/UserSearchLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/UserSearchLoader.java deleted file mode 100644 index 7f07e261c..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/UserSearchLoader.java +++ /dev/null @@ -1,70 +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.annotation.NonNull; - -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.User; -import org.mariotaku.twidere.annotation.AccountType; -import org.mariotaku.twidere.model.ParcelableCredentials; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.UserKey; -import org.mariotaku.twidere.model.util.ParcelableAccountUtils; - -import java.util.List; - -public class UserSearchLoader extends TwitterAPIUsersLoader { - - private final String mQuery; - private final int mPage; - - public UserSearchLoader(final Context context, final UserKey accountKey, final String query, - final int page, final List data, boolean fromUser) { - super(context, accountKey, data, fromUser); - mQuery = query; - mPage = page; - } - - public int getPage() { - return mPage; - } - - public String getQuery() { - return mQuery; - } - - @NonNull - @Override - public List getUsers(@NonNull final MicroBlog twitter, @NonNull ParcelableCredentials credentials) throws MicroBlogException { - final Paging paging = new Paging(); - paging.page(mPage); - switch (ParcelableAccountUtils.getAccountType(credentials)) { - case AccountType.FANFOU: { - return twitter.searchFanfouUsers(mQuery, paging); - } - } - return twitter.searchUsers(mQuery, paging); - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java index ccb045ec0..5478c6a96 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/AccountUtils.java @@ -40,6 +40,13 @@ public class AccountUtils { return details; } + @Nullable + public static AccountDetails getAccountDetails(@NonNull AccountManager am, @NonNull UserKey accountKey) { + final Account account = findByAccountKey(am, accountKey); + if (account == null) return null; + return getAccountDetails(am, account); + } + public static AccountDetails getAccountDetails(@NonNull AccountManager am, @NonNull Account account) { AccountDetails details = new AccountDetails(); details.key = AccountExtensionsKt.getAccountKey(account, am); diff --git a/twidere/src/main/kotlin/UserFollowersLoader.kt b/twidere/src/main/kotlin/UserFollowersLoader.kt deleted file mode 100644 index 63555a6e9..000000000 --- a/twidere/src/main/kotlin/UserFollowersLoader.kt +++ /dev/null @@ -1,98 +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.Paging -import org.mariotaku.microblog.library.twitter.model.ResponseList -import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.model.ParcelableAccount -import org.mariotaku.twidere.model.ParcelableCredentials -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.ParcelableAccountUtils - -class UserFollowersLoader( - context: Context, - accountKey: UserKey?, - private val userKey: UserKey?, - private val screenName: String?, - data: List?, - fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override fun getCursoredUsers(twitter: MicroBlog, credentials: ParcelableCredentials, paging: Paging): ResponseList { - when (ParcelableAccountUtils.getAccountType(credentials)) { - AccountType.STATUSNET -> { - run { - if (userKey != null) { - return twitter.getStatusesFollowersList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getStatusesFollowersListByScreenName(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getUsersFollowers(userKey.id, paging) - } else if (screenName != null) { - return twitter.getUsersFollowers(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getFollowersList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFollowersListByScreenName(screenName, paging) - } - } - } - AccountType.FANFOU -> { - run { - if (userKey != null) { - return twitter.getUsersFollowers(userKey.id, paging) - } else if (screenName != null) { - return twitter.getUsersFollowers(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getFollowersList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFollowersListByScreenName(screenName, paging) - } - } - } - else -> { - if (userKey != null) { - return twitter.getFollowersList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFollowersListByScreenName(screenName, paging) - } - } - } - throw MicroBlogException("user_id or screen_name required") - } - -} diff --git a/twidere/src/main/kotlin/UserFriendsLoader.kt b/twidere/src/main/kotlin/UserFriendsLoader.kt deleted file mode 100644 index f6f3c45fb..000000000 --- a/twidere/src/main/kotlin/UserFriendsLoader.kt +++ /dev/null @@ -1,98 +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.Paging -import org.mariotaku.microblog.library.twitter.model.ResponseList -import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.model.ParcelableAccount -import org.mariotaku.twidere.model.ParcelableCredentials -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.ParcelableAccountUtils - -class UserFriendsLoader( - context: Context, - accountKey: UserKey?, - private val userKey: UserKey?, - private val screenName: String?, - data: List?, - fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override fun getCursoredUsers(twitter: MicroBlog, - credentials: ParcelableCredentials, paging: Paging): ResponseList { - when (ParcelableAccountUtils.getAccountType(credentials)) { - AccountType.STATUSNET -> { - run { - if (userKey != null) { - return twitter.getStatusesFriendsList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getStatusesFriendsListByScreenName(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getUsersFriends(userKey.id, paging) - } else if (screenName != null) { - return twitter.getUsersFriends(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getFriendsList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFriendsListByScreenName(screenName, paging) - } - } - } - AccountType.FANFOU -> { - run { - if (userKey != null) { - return twitter.getUsersFriends(userKey.id, paging) - } else if (screenName != null) { - return twitter.getUsersFriends(screenName, paging) - } - } - run { - if (userKey != null) { - return twitter.getFriendsList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFriendsListByScreenName(screenName, paging) - } - } - } - else -> { - if (userKey != null) { - return twitter.getFriendsList(userKey.id, paging) - } else if (screenName != null) { - return twitter.getFriendsListByScreenName(screenName, paging) - } - } - } - throw MicroBlogException("user_id or screen_name required") - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt index dec3cdaa0..aa04b2ee3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt @@ -26,6 +26,7 @@ fun Account.getCredentials(am: AccountManager): Credentials { return creds } +@Credentials.Type fun Account.getCredentialsType(am: AccountManager): String { return am.getUserData(this, ACCOUNT_USER_DATA_CREDS_TYPE) ?: Credentials.Type.OAUTH } diff --git a/twidere/src/main/kotlin/CursorSupportUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt similarity index 81% rename from twidere/src/main/kotlin/CursorSupportUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt index 381a87fc9..a3c9bfab2 100644 --- a/twidere/src/main/kotlin/CursorSupportUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt @@ -28,7 +28,7 @@ import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.loader.iface.ICursorSupportLoader -import org.mariotaku.twidere.model.ParcelableCredentials +import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey @@ -72,20 +72,17 @@ abstract class CursorSupportUsersLoader( @Throws(MicroBlogException::class) - protected open fun getCursoredUsers(twitter: MicroBlog, - credentials: ParcelableCredentials, - paging: Paging): List { + protected open fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): List { throw UnsupportedOperationException() } @Throws(MicroBlogException::class) - protected open fun getIDs(twitter: MicroBlog, credentials: ParcelableCredentials, - paging: Paging): IDs { + protected open fun getIDs(twitter: MicroBlog, details: AccountDetails, paging: Paging): IDs { throw UnsupportedOperationException() } @Throws(MicroBlogException::class) - override fun getUsers(twitter: MicroBlog, credentials: ParcelableCredentials): List { + override fun getUsers(twitter: MicroBlog, details: AccountDetails): List { val paging = Paging() paging.count(count) if (cursor > 0) { @@ -94,12 +91,12 @@ abstract class CursorSupportUsersLoader( paging.setPage(page) } val users: List - if (useIDs(credentials)) { - val ids = getIDs(twitter, credentials, paging) + if (useIDs(details)) { + val ids = getIDs(twitter, details, paging) setCursors(ids) users = twitter.lookupUsers(ids.iDs) } else { - users = getCursoredUsers(twitter, credentials, paging) + users = getCursoredUsers(twitter, details, paging) if (users is CursorSupport) { setCursors(users) } @@ -108,7 +105,7 @@ abstract class CursorSupportUsersLoader( return users } - protected open fun useIDs(credentials: ParcelableCredentials): Boolean { + protected open fun useIDs(details: AccountDetails): Boolean { return false } } diff --git a/twidere/src/main/kotlin/GroupMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt similarity index 90% rename from twidere/src/main/kotlin/GroupMembersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt index ced71171f..67491f34c 100644 --- a/twidere/src/main/kotlin/GroupMembersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt @@ -20,13 +20,12 @@ 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.ResponseList import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.model.ParcelableCredentials +import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey @@ -40,7 +39,7 @@ class GroupMembersLoader( ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - public override fun getCursoredUsers(twitter: MicroBlog, credentials: ParcelableCredentials, paging: Paging): ResponseList { + public 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/java/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt similarity index 79% rename from twidere/src/main/java/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt index b859a2367..6cd37a5bf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt @@ -20,7 +20,6 @@ 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.IDs @@ -28,10 +27,9 @@ import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.ResponseList import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.model.ParcelableCredentials +import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.ParcelableAccountUtils class IncomingFriendshipsLoader( context: Context, @@ -41,17 +39,17 @@ class IncomingFriendshipsLoader( ) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getIDs(twitter: MicroBlog, credentials: ParcelableCredentials, paging: Paging): IDs { + override fun getIDs(twitter: MicroBlog, details: AccountDetails, paging: Paging): IDs { return twitter.getIncomingFriendships(paging) } @Throws(MicroBlogException::class) - override fun getCursoredUsers(twitter: MicroBlog, credentials: ParcelableCredentials, paging: Paging): ResponseList { + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { return twitter.getFriendshipsRequests(paging) } - override fun useIDs(credentials: ParcelableCredentials): Boolean { - when (ParcelableAccountUtils.getAccountType(credentials)) { + override fun useIDs(details: AccountDetails): Boolean { + when (details.type) { AccountType.FANFOU -> { return false } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt new file mode 100644 index 000000000..ef9574a8f --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt @@ -0,0 +1,44 @@ +/* + * 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.User +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class MutesUsersLoader( + context: Context, + accountKey: UserKey?, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { + return twitter.getMutesUsersList(paging) + } + +} diff --git a/twidere/src/main/kotlin/ParcelableUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt similarity index 100% rename from twidere/src/main/kotlin/ParcelableUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt new file mode 100644 index 000000000..29d413528 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt @@ -0,0 +1,48 @@ +/* + * 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.IDs +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class StatusFavoritersLoader( + context: Context, + accountKey: UserKey, + private val statusId: String, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getIDs(twitter: MicroBlog, details: AccountDetails, paging: Paging): IDs { + return twitter.getStatusActivitySummary(statusId).favoriters + } + + override fun useIDs(details: AccountDetails): Boolean { + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt new file mode 100644 index 000000000..4296b97ef --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt @@ -0,0 +1,47 @@ +/* + * 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.IDs +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class StatusRetweetersLoader( + context: Context, + accountKey: UserKey, + private val statusId: String, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getIDs(twitter: MicroBlog, details: AccountDetails, paging: Paging): IDs { + return twitter.getRetweetersIDs(statusId, paging) + } + + override fun useIDs(details: AccountDetails): Boolean { + return true + } +} diff --git a/twidere/src/main/kotlin/TwitterAPIUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TwitterAPIUsersLoader.kt similarity index 75% rename from twidere/src/main/kotlin/TwitterAPIUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/TwitterAPIUsersLoader.kt index 3edeaa685..ba3e6ae25 100644 --- a/twidere/src/main/kotlin/TwitterAPIUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TwitterAPIUsersLoader.kt @@ -19,19 +19,20 @@ package org.mariotaku.twidere.loader +import android.accounts.AccountManager import android.content.Context import android.util.Log import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.TwidereConstants +import org.mariotaku.twidere.extension.newMicroBlogInstance +import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ListResponse -import org.mariotaku.twidere.model.ParcelableCredentials import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils +import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.ParcelableUserUtils -import org.mariotaku.twidere.util.MicroBlogAPIFactory import java.util.* abstract class TwitterAPIUsersLoader( @@ -45,14 +46,14 @@ abstract class TwitterAPIUsersLoader( if (accountKey == null) { return ListResponse.getListInstance(MicroBlogException("No Account")) } - val credentials = ParcelableCredentialsUtils.getCredentials(context, - accountKey) ?: return ListResponse.getListInstance(MicroBlogException("No Account")) - val twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, - true) ?: return ListResponse.getListInstance(MicroBlogException("No Account")) + val am = AccountManager.get(context) + val details = AccountUtils.getAccountDetails(am, accountKey) ?: + return ListResponse.getListInstance(MicroBlogException("No Account")) + val twitter: MicroBlog = details.credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java) val data = data val users: List try { - users = getUsers(twitter, credentials) + users = getUsers(twitter, details) } catch (e: MicroBlogException) { Log.w(TwidereConstants.LOGTAG, e) return ListResponse.getListInstance(data) @@ -71,6 +72,5 @@ abstract class TwitterAPIUsersLoader( } @Throws(MicroBlogException::class) - protected abstract fun getUsers(twitter: MicroBlog, - credentials: ParcelableCredentials): List + protected abstract fun getUsers(twitter: MicroBlog, details: AccountDetails): List } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt new file mode 100644 index 000000000..4a9f0402e --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt @@ -0,0 +1,52 @@ +/* + * 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.User +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserBlocksLoader( + context: Context, + accountKey: UserKey, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getCursoredUsers(twitter: MicroBlog, + details: AccountDetails, + paging: Paging): List { + when (details.type) { + AccountType.FANFOU -> { + return twitter.getFanfouBlocking(paging) + } + } + return twitter.getBlocksList(paging) + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt new file mode 100644 index 000000000..7a19f908b --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt @@ -0,0 +1,64 @@ +/* + * 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.ResponseList +import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserFollowersLoader( + context: Context, + accountKey: UserKey?, + private val userKey: UserKey?, + private val screenName: String?, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { + when (details.type) { + AccountType.STATUSNET -> if (userKey != null) { + return twitter.getStatusesFollowersList(userKey.id, paging) + } else if (screenName != null) { + return twitter.getStatusesFollowersListByScreenName(screenName, paging) + } + AccountType.FANFOU -> if (userKey != null) { + return twitter.getUsersFollowers(userKey.id, paging) + } else if (screenName != null) { + return twitter.getUsersFollowers(screenName, paging) + } + else -> if (userKey != null) { + return twitter.getFollowersList(userKey.id, paging) + } else if (screenName != null) { + return twitter.getFollowersListByScreenName(screenName, paging) + } + } + throw MicroBlogException("user_id or screen_name required") + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt new file mode 100644 index 000000000..e2cef5921 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt @@ -0,0 +1,63 @@ +/* + * 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.ResponseList +import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserFriendsLoader( + context: Context, + accountKey: UserKey?, + private val userKey: UserKey?, + private val screenName: String?, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): ResponseList { + when (details.type) { + AccountType.STATUSNET -> if (userKey != null) { + return twitter.getStatusesFriendsList(userKey.id, paging) + } else if (screenName != null) { + return twitter.getStatusesFriendsListByScreenName(screenName, paging) + } + AccountType.FANFOU -> if (userKey != null) { + return twitter.getUsersFriends(userKey.id, paging) + } else if (screenName != null) { + return twitter.getUsersFriends(screenName, paging) + } + else -> if (userKey != null) { + return twitter.getFriendsList(userKey.id, paging) + } else if (screenName != null) { + return twitter.getFriendsListByScreenName(screenName, paging) + } + } + throw MicroBlogException("user_id or screen_name required") + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt new file mode 100644 index 000000000..0ae8b86c4 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt @@ -0,0 +1,55 @@ +/* + * 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.User +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserListMembersLoader( + context: Context, + accountKey: UserKey, + private val listId: String?, + private val userKey: UserKey?, + private val screenName: String?, + private val listName: String, + data: List, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { + if (listId != null) + return twitter.getUserListMembers(listId, paging) + else if (userKey != null) + return twitter.getUserListMembers(listName.replace(' ', '-'), userKey.id, paging) + else if (screenName != null) + return twitter.getUserListMembersByScreenName(listName.replace(' ', '-'), screenName, paging) + throw MicroBlogException("list_id or list_name and user_id (or screen_name) required") + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt new file mode 100644 index 000000000..5e1030f16 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt @@ -0,0 +1,55 @@ +/* + * 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.User +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserListSubscribersLoader( + context: Context, + accountKey: UserKey, + private val listId: String?, + private val userKey: UserKey?, + private val screenName: String?, + private val listName: String?, + data: List?, + fromUser: Boolean +) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + public override fun getCursoredUsers(twitter: MicroBlog, details: AccountDetails, paging: Paging): PageableResponseList { + if (listId != null) + return twitter.getUserListSubscribers(listId, paging) + else if (userKey != null) + return twitter.getUserListSubscribers(listName!!.replace(' ', '-'), userKey.id, paging) + else if (screenName != null) + return twitter.getUserListSubscribersByScreenName(listName!!.replace(' ', '-'), screenName, paging) + throw MicroBlogException("list_id or list_name and user_id (or screen_name) required") + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt new file mode 100644 index 000000000..c5eddadda --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt @@ -0,0 +1,53 @@ +/* + * 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.User +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +open class UserSearchLoader( + context: Context, + accountKey: UserKey, + val query: String, + val page: Int, + data: List?, + fromUser: Boolean +) : TwitterAPIUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + public override fun getUsers(twitter: MicroBlog, details: AccountDetails): List { + val paging = Paging() + paging.page(page) + when (details.type) { + AccountType.FANFOU -> { + return twitter.searchFanfouUsers(query, paging) + } + } + return twitter.searchUsers(query, paging) + } + +} diff --git a/twidere/src/main/kotlin/ICursorSupportLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/ICursorSupportLoader.kt similarity index 100% rename from twidere/src/main/kotlin/ICursorSupportLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/ICursorSupportLoader.kt diff --git a/twidere/src/main/kotlin/IExtendedLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/IExtendedLoader.kt similarity index 100% rename from twidere/src/main/kotlin/IExtendedLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/IExtendedLoader.kt diff --git a/twidere/src/main/kotlin/SafeSpannableString.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/text/SafeSpannableString.kt similarity index 100% rename from twidere/src/main/kotlin/SafeSpannableString.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/text/SafeSpannableString.kt diff --git a/twidere/src/main/kotlin/TwidereURLSpan.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/text/TwidereURLSpan.kt similarity index 100% rename from twidere/src/main/kotlin/TwidereURLSpan.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/text/TwidereURLSpan.kt diff --git a/twidere/src/main/kotlin/DependencyHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt similarity index 100% rename from twidere/src/main/kotlin/DependencyHolder.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt diff --git a/twidere/src/main/kotlin/GeneralComponent.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt similarity index 100% rename from twidere/src/main/kotlin/GeneralComponent.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt diff --git a/twidere/src/main/kotlin/StatusViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/StatusViewHolder.kt similarity index 100% rename from twidere/src/main/kotlin/StatusViewHolder.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/StatusViewHolder.kt diff --git a/twidere/src/main/kotlin/IStatusViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.kt similarity index 100% rename from twidere/src/main/kotlin/IStatusViewHolder.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/iface/IStatusViewHolder.kt