mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
abandoning old account code
This commit is contained in:
parent
ccb9ab47ee
commit
6c98b02c57
@ -0,0 +1,23 @@
|
||||
package org.mariotaku.twidere.annotation;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/4.
|
||||
*/
|
||||
@IntDef({AuthTypeInt.OAUTH, AuthTypeInt.XAUTH, AuthTypeInt.BASIC, AuthTypeInt.TWIP_O_MODE,
|
||||
AuthTypeInt.OAUTH2})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface AuthTypeInt {
|
||||
|
||||
int OAUTH = 0;
|
||||
int XAUTH = 1;
|
||||
int BASIC = 2;
|
||||
int TWIP_O_MODE = 3;
|
||||
int OAUTH2 = 4;
|
||||
}
|
@ -20,8 +20,8 @@
|
||||
package org.mariotaku.twidere.constant;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.annotation.Preference;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
|
||||
import static org.mariotaku.twidere.annotation.PreferenceType.BOOLEAN;
|
||||
import static org.mariotaku.twidere.annotation.PreferenceType.INT;
|
||||
@ -237,7 +237,7 @@ public interface SharedPreferenceConstants {
|
||||
String KEY_SAME_OAUTH_SIGNING_URL = "same_oauth_signing_url";
|
||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
|
||||
String KEY_NO_VERSION_SUFFIX = "no_version_suffix";
|
||||
@Preference(type = INT, hasDefault = true, defaultInt = ParcelableCredentials.AuthTypeInt.OAUTH)
|
||||
@Preference(type = INT, hasDefault = true, defaultInt = AuthTypeInt.OAUTH)
|
||||
String KEY_AUTH_TYPE = "auth_type";
|
||||
@Preference(type = STRING, hasDefault = true, defaultString = TwidereConstants.TWITTER_CONSUMER_KEY)
|
||||
String KEY_CONSUMER_KEY = "consumer_key";
|
||||
|
@ -1,17 +1,25 @@
|
||||
package org.mariotaku.twidere.model;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.model.account.AccountExtras;
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/3.
|
||||
*/
|
||||
|
||||
public class AccountDetails {
|
||||
@ParcelablePlease
|
||||
public class AccountDetails implements Parcelable {
|
||||
|
||||
public boolean dummy;
|
||||
public Account account;
|
||||
public UserKey key;
|
||||
public Credentials credentials;
|
||||
@ -24,4 +32,51 @@ public class AccountDetails {
|
||||
public String type;
|
||||
@Credentials.Type
|
||||
public String credentials_type;
|
||||
public AccountExtras extras;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
AccountDetailsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AccountDetails{" +
|
||||
"account=" + account +
|
||||
", dummy=" + dummy +
|
||||
", key=" + key +
|
||||
", credentials=" + credentials +
|
||||
", user=" + user +
|
||||
", color=" + color +
|
||||
", position=" + position +
|
||||
", activated=" + activated +
|
||||
", type='" + type + '\'' +
|
||||
", credentials_type='" + credentials_type + '\'' +
|
||||
", extras=" + extras +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static final Creator<AccountDetails> CREATOR = new Creator<AccountDetails>() {
|
||||
public AccountDetails createFromParcel(Parcel source) {
|
||||
AccountDetails target = new AccountDetails();
|
||||
AccountDetailsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public AccountDetails[] newArray(int size) {
|
||||
return new AccountDetails[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public static AccountDetails dummy() {
|
||||
AccountDetails dummy = new AccountDetails();
|
||||
dummy.dummy = true;
|
||||
return dummy;
|
||||
}
|
||||
}
|
||||
|
@ -19,90 +19,65 @@
|
||||
|
||||
package org.mariotaku.twidere.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
||||
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorField;
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorObject;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/5/26.
|
||||
*/
|
||||
@JsonObject
|
||||
@CursorObject
|
||||
@ParcelablePlease
|
||||
@Deprecated
|
||||
public class ParcelableCredentials extends ParcelableAccount implements Parcelable {
|
||||
public class ParcelableCredentials extends ParcelableAccount {
|
||||
|
||||
public static final Creator<ParcelableCredentials> CREATOR = new Creator<ParcelableCredentials>() {
|
||||
@Override
|
||||
public ParcelableCredentials createFromParcel(Parcel source) {
|
||||
ParcelableCredentials target = new ParcelableCredentials();
|
||||
ParcelableCredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelableCredentials[] newArray(int size) {
|
||||
return new ParcelableCredentials[size];
|
||||
}
|
||||
};
|
||||
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "auth_type")
|
||||
@CursorField(Accounts.AUTH_TYPE)
|
||||
@AuthTypeInt
|
||||
public int auth_type;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "consumer_key")
|
||||
@CursorField(Accounts.CONSUMER_KEY)
|
||||
public String consumer_key;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "consumer_secret")
|
||||
@CursorField(Accounts.CONSUMER_SECRET)
|
||||
public String consumer_secret;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "basic_auth_username")
|
||||
@CursorField(Accounts.BASIC_AUTH_USERNAME)
|
||||
public String basic_auth_username;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "basic_auth_password")
|
||||
@CursorField(Accounts.BASIC_AUTH_PASSWORD)
|
||||
public String basic_auth_password;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "oauth_token")
|
||||
@CursorField(Accounts.OAUTH_TOKEN)
|
||||
public String oauth_token;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "oauth_token_secret")
|
||||
@CursorField(Accounts.OAUTH_TOKEN_SECRET)
|
||||
public String oauth_token_secret;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "api_url_format")
|
||||
@CursorField(Accounts.API_URL_FORMAT)
|
||||
@Nullable
|
||||
public String api_url_format;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "same_oauth_signing_url")
|
||||
@CursorField(Accounts.SAME_OAUTH_SIGNING_URL)
|
||||
public boolean same_oauth_signing_url;
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "no_version_suffix")
|
||||
@CursorField(Accounts.NO_VERSION_SUFFIX)
|
||||
public boolean no_version_suffix;
|
||||
|
||||
@ParcelableThisPlease
|
||||
|
||||
@JsonField(name = "account_extras")
|
||||
@CursorField(Accounts.ACCOUNT_EXTRAS)
|
||||
public String account_extras;
|
||||
@ -132,21 +107,4 @@ public class ParcelableCredentials extends ParcelableAccount implements Parcelab
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
ParcelableCredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
@IntDef({AuthTypeInt.OAUTH, AuthTypeInt.XAUTH, AuthTypeInt.BASIC, AuthTypeInt.TWIP_O_MODE,
|
||||
AuthTypeInt.OAUTH2})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface AuthTypeInt {
|
||||
|
||||
int OAUTH = 0;
|
||||
int XAUTH = 1;
|
||||
int BASIC = 2;
|
||||
int TWIP_O_MODE = 3;
|
||||
int OAUTH2 = 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ParcelableStatusUpdate implements Parcelable {
|
||||
@JsonField(name = "accounts")
|
||||
@NonNull
|
||||
@ParcelableThisPlease
|
||||
public ParcelableAccount[] accounts;
|
||||
public AccountDetails[] accounts;
|
||||
@JsonField(name = "media")
|
||||
@ParcelableThisPlease
|
||||
public ParcelableMediaUpdate[] media;
|
||||
|
@ -122,9 +122,8 @@ public class UserKey implements Comparable<UserKey>, Parcelable {
|
||||
return this.id.equals(accountId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UserKey valueOf(@Nullable String str) {
|
||||
if (str == null) return null;
|
||||
@NonNull
|
||||
public static UserKey valueOf(@NonNull String str) {
|
||||
boolean escaping = false, idFinished = false;
|
||||
StringBuilder idBuilder = new StringBuilder(str.length()),
|
||||
hostBuilder = new StringBuilder(str.length());
|
||||
|
@ -1,16 +1,43 @@
|
||||
package org.mariotaku.twidere.model.account.cred;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/2.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class BasicCredentials extends Credentials {
|
||||
public class BasicCredentials extends Credentials implements Parcelable {
|
||||
@JsonField(name = "username")
|
||||
public String username;
|
||||
@JsonField(name = "password")
|
||||
public String password;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
BasicCredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<BasicCredentials> CREATOR = new Creator<BasicCredentials>() {
|
||||
public BasicCredentials createFromParcel(Parcel source) {
|
||||
BasicCredentials target = new BasicCredentials();
|
||||
BasicCredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public BasicCredentials[] newArray(int size) {
|
||||
return new BasicCredentials[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package org.mariotaku.twidere.model.account.cred;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.StringDef;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -12,8 +15,9 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* Created by mariotaku on 2016/12/2.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class Credentials {
|
||||
public class Credentials implements Parcelable {
|
||||
@JsonField(name = "api_url_format")
|
||||
public String api_url_format;
|
||||
@JsonField(name = "no_version_suffix")
|
||||
@ -30,4 +34,25 @@ public class Credentials {
|
||||
String OAUTH2 = "oauth2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
CredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<Credentials> CREATOR = new Creator<Credentials>() {
|
||||
public Credentials createFromParcel(Parcel source) {
|
||||
Credentials target = new Credentials();
|
||||
CredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public Credentials[] newArray(int size) {
|
||||
return new Credentials[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,37 @@
|
||||
package org.mariotaku.twidere.model.account.cred;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/2.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class EmptyCredentials extends Credentials {
|
||||
public class EmptyCredentials extends Credentials implements Parcelable {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
EmptyCredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<EmptyCredentials> CREATOR = new Creator<EmptyCredentials>() {
|
||||
public EmptyCredentials createFromParcel(Parcel source) {
|
||||
EmptyCredentials target = new EmptyCredentials();
|
||||
EmptyCredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public EmptyCredentials[] newArray(int size) {
|
||||
return new EmptyCredentials[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,37 @@
|
||||
package org.mariotaku.twidere.model.account.cred;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/2.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class OAuth2Credentials extends Credentials {
|
||||
public class OAuth2Credentials extends Credentials implements Parcelable {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
OAuth2CredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<OAuth2Credentials> CREATOR = new Creator<OAuth2Credentials>() {
|
||||
public OAuth2Credentials createFromParcel(Parcel source) {
|
||||
OAuth2Credentials target = new OAuth2Credentials();
|
||||
OAuth2CredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public OAuth2Credentials[] newArray(int size) {
|
||||
return new OAuth2Credentials[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
package org.mariotaku.twidere.model.account.cred;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorField;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/2.
|
||||
*/
|
||||
|
||||
@ParcelablePlease
|
||||
@JsonObject
|
||||
public class OAuthCredentials extends Credentials {
|
||||
public class OAuthCredentials extends Credentials implements Parcelable {
|
||||
@JsonField(name = "consumer_key")
|
||||
public String consumer_key;
|
||||
@JsonField(name = "consumer_secret")
|
||||
@ -24,4 +26,26 @@ public class OAuthCredentials extends Credentials {
|
||||
|
||||
@JsonField(name = "same_oauth_signing_url")
|
||||
public boolean same_oauth_signing_url;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
OAuthCredentialsParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<OAuthCredentials> CREATOR = new Creator<OAuthCredentials>() {
|
||||
public OAuthCredentials createFromParcel(Parcel source) {
|
||||
OAuthCredentials target = new OAuthCredentials();
|
||||
OAuthCredentialsParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
|
||||
public OAuthCredentials[] newArray(int size) {
|
||||
return new OAuthCredentials[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.loader;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
@ -27,12 +28,12 @@ import android.support.v4.content.AsyncTaskLoader;
|
||||
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.ErrorInfo;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.constant.IntentConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.SingleResponse;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
|
||||
import org.mariotaku.twidere.util.DataStoreUtils;
|
||||
@ -41,13 +42,13 @@ import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT;
|
||||
import static org.mariotaku.twidere.util.Utils.findStatus;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/5.
|
||||
*/
|
||||
public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<ParcelableStatus>>
|
||||
implements Constants {
|
||||
public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<ParcelableStatus>> {
|
||||
|
||||
private final boolean mOmitIntentExtra;
|
||||
private final Bundle mExtras;
|
||||
@ -83,13 +84,13 @@ public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<Parce
|
||||
}
|
||||
}
|
||||
try {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(getContext(), mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(getContext()), mAccountKey);
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final ParcelableStatus status = findStatus(getContext(), mAccountKey, mStatusId);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, credentials, mUserColorNameManager);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, details, mUserColorNameManager);
|
||||
final SingleResponse<ParcelableStatus> response = SingleResponse.Companion.getInstance(status);
|
||||
final Bundle extras = response.getExtras();
|
||||
extras.putParcelable(EXTRA_ACCOUNT, credentials);
|
||||
extras.putParcelable(EXTRA_ACCOUNT, details);
|
||||
return response;
|
||||
} catch (final MicroBlogException e) {
|
||||
if (e.getErrorCode() == ErrorInfo.STATUS_NOT_FOUND) {
|
||||
|
@ -29,14 +29,14 @@ import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
public class AccountToggleProvider extends ActionProvider implements TwidereConstants {
|
||||
|
||||
public static final int MENU_GROUP = 201;
|
||||
|
||||
private ParcelableAccount[] mAccounts;
|
||||
private AccountDetails[] mAccounts;
|
||||
|
||||
private boolean mExclusive;
|
||||
|
||||
@ -44,11 +44,11 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ParcelableAccount[] getAccounts() {
|
||||
public AccountDetails[] getAccounts() {
|
||||
return mAccounts;
|
||||
}
|
||||
|
||||
public void setAccounts(ParcelableAccount[] accounts) {
|
||||
public void setAccounts(AccountDetails[] accounts) {
|
||||
mAccounts = accounts;
|
||||
}
|
||||
|
||||
@ -57,9 +57,9 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons
|
||||
if (mAccounts == null) return new UserKey[0];
|
||||
UserKey[] temp = new UserKey[mAccounts.length];
|
||||
int len = 0;
|
||||
for (ParcelableAccount account : mAccounts) {
|
||||
if (account.is_activated) {
|
||||
temp[len++] = account.account_key;
|
||||
for (AccountDetails account : mAccounts) {
|
||||
if (account.activated) {
|
||||
temp[len++] = account.key;
|
||||
}
|
||||
}
|
||||
final UserKey[] result = new UserKey[len];
|
||||
@ -95,8 +95,8 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons
|
||||
subMenu.removeGroup(MENU_GROUP);
|
||||
if (mAccounts == null) return;
|
||||
for (int i = 0, j = mAccounts.length; i < j; i++) {
|
||||
final ParcelableAccount account = mAccounts[i];
|
||||
final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name);
|
||||
final AccountDetails account = mAccounts[i];
|
||||
final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.user.name);
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_ACCOUNT, account);
|
||||
item.setIntent(intent);
|
||||
@ -104,7 +104,7 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons
|
||||
subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
|
||||
for (int i = 0, j = subMenu.size(); i < j; i++) {
|
||||
final MenuItem item = subMenu.getItem(i);
|
||||
if (mAccounts[i].is_activated) {
|
||||
if (mAccounts[i].activated) {
|
||||
item.setChecked(true);
|
||||
}
|
||||
}
|
||||
@ -112,9 +112,9 @@ public class AccountToggleProvider extends ActionProvider implements TwidereCons
|
||||
|
||||
public void setAccountActivated(UserKey accountId, boolean isChecked) {
|
||||
if (mAccounts == null) return;
|
||||
for (final ParcelableAccount account : mAccounts) {
|
||||
if (account.account_key == accountId) {
|
||||
account.is_activated = isChecked;
|
||||
for (final AccountDetails account : mAccounts) {
|
||||
if (account.key == accountId) {
|
||||
account.activated = isChecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.model;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.RingtoneManager;
|
||||
@ -29,7 +30,7 @@ import android.text.TextUtils;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
|
||||
public class AccountPreferences implements Constants {
|
||||
|
||||
@ -49,7 +50,7 @@ public class AccountPreferences implements Constants {
|
||||
}
|
||||
|
||||
public int getDefaultNotificationLightColor() {
|
||||
final ParcelableAccount a = ParcelableAccountUtils.getAccount(mContext, mAccountKey);
|
||||
final AccountDetails a = AccountUtils.getAccountDetails(AccountManager.get(mContext), mAccountKey);
|
||||
if (a != null) {
|
||||
return a.color;
|
||||
} else {
|
||||
|
@ -10,6 +10,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.util.JsonSerializer;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
@ -34,7 +35,7 @@ public final class CustomAPIConfig {
|
||||
String localizedName;
|
||||
@JsonField(name = "api_url_format")
|
||||
String apiUrlFormat;
|
||||
@ParcelableCredentials.AuthTypeInt
|
||||
@AuthTypeInt
|
||||
@JsonField(name = "auth_type", typeConverter = AuthTypeConverter.class)
|
||||
int authType;
|
||||
@JsonField(name = "same_oauth_url")
|
||||
@ -116,46 +117,46 @@ public final class CustomAPIConfig {
|
||||
|
||||
public static List<CustomAPIConfig> listBuiltin(@NonNull Context context) {
|
||||
return Collections.singletonList(new CustomAPIConfig(context.getString(R.string.provider_default),
|
||||
DEFAULT_TWITTER_API_URL_FORMAT, ParcelableCredentials.AuthTypeInt.OAUTH, true, false,
|
||||
DEFAULT_TWITTER_API_URL_FORMAT, AuthTypeInt.OAUTH, true, false,
|
||||
TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET));
|
||||
}
|
||||
|
||||
static class AuthTypeConverter extends StringBasedTypeConverter<Integer> {
|
||||
@Override
|
||||
@ParcelableCredentials.AuthTypeInt
|
||||
@AuthTypeInt
|
||||
public Integer getFromString(String string) {
|
||||
if (string == null) return ParcelableCredentials.AuthTypeInt.OAUTH;
|
||||
if (string == null) return AuthTypeInt.OAUTH;
|
||||
switch (string) {
|
||||
case "oauth": {
|
||||
return ParcelableCredentials.AuthTypeInt.OAUTH;
|
||||
return AuthTypeInt.OAUTH;
|
||||
}
|
||||
case "xauth": {
|
||||
return ParcelableCredentials.AuthTypeInt.XAUTH;
|
||||
return AuthTypeInt.XAUTH;
|
||||
}
|
||||
case "basic": {
|
||||
return ParcelableCredentials.AuthTypeInt.BASIC;
|
||||
return AuthTypeInt.BASIC;
|
||||
}
|
||||
case "twip_o_mode": {
|
||||
return ParcelableCredentials.AuthTypeInt.TWIP_O_MODE;
|
||||
return AuthTypeInt.TWIP_O_MODE;
|
||||
}
|
||||
}
|
||||
return ParcelableCredentials.AuthTypeInt.OAUTH;
|
||||
return AuthTypeInt.OAUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(@ParcelableCredentials.AuthTypeInt Integer object) {
|
||||
public String convertToString(@AuthTypeInt Integer object) {
|
||||
if (object == null) return "oauth";
|
||||
switch (object) {
|
||||
case ParcelableCredentials.AuthTypeInt.OAUTH: {
|
||||
case AuthTypeInt.OAUTH: {
|
||||
return "oauth";
|
||||
}
|
||||
case ParcelableCredentials.AuthTypeInt.XAUTH: {
|
||||
case AuthTypeInt.XAUTH: {
|
||||
return "xauth";
|
||||
}
|
||||
case ParcelableCredentials.AuthTypeInt.BASIC: {
|
||||
case AuthTypeInt.BASIC: {
|
||||
return "basic";
|
||||
}
|
||||
case ParcelableCredentials.AuthTypeInt.TWIP_O_MODE: {
|
||||
case AuthTypeInt.TWIP_O_MODE: {
|
||||
return "twip_o_mode";
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ import android.accounts.AccountManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.extension.AccountExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
@ -40,6 +43,23 @@ public class AccountUtils {
|
||||
return details;
|
||||
}
|
||||
|
||||
public static AccountDetails[] getAllAccountDetails(@NonNull AccountManager am, @NonNull UserKey[] accountKeys) {
|
||||
AccountDetails[] details = new AccountDetails[accountKeys.length];
|
||||
for (int i = 0; i < accountKeys.length; i++) {
|
||||
details[i] = getAccountDetails(am, accountKeys[i]);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
public static AccountDetails[] getAllAccountDetails(@NonNull AccountManager am) {
|
||||
Account[] accounts = getAccounts(am);
|
||||
AccountDetails[] details = new AccountDetails[accounts.length];
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
details[i] = getAccountDetails(am, accounts[i]);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AccountDetails getAccountDetails(@NonNull AccountManager am, @NonNull UserKey accountKey) {
|
||||
final Account account = findByAccountKey(am, accountKey);
|
||||
@ -60,4 +80,36 @@ public class AccountUtils {
|
||||
details.credentials_type = AccountExtensionsKt.getCredentialsType(account, am);
|
||||
return details;
|
||||
}
|
||||
|
||||
public static Account findByScreenName(AccountManager am, String screenName) {
|
||||
for (Account account : getAccounts(am)) {
|
||||
if (StringUtils.equalsIgnoreCase(UserKey.valueOf(account.name).getId(), screenName)) {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@AccountType
|
||||
public static String getAccountType(@NonNull AccountDetails account) {
|
||||
return account.type;
|
||||
}
|
||||
|
||||
public static int getAccountTypeIcon(@Nullable String accountType) {
|
||||
if (accountType == null) return R.drawable.ic_account_logo_twitter;
|
||||
switch (accountType) {
|
||||
case AccountType.TWITTER: {
|
||||
return R.drawable.ic_account_logo_twitter;
|
||||
}
|
||||
case AccountType.FANFOU: {
|
||||
return R.drawable.ic_account_logo_fanfou;
|
||||
}
|
||||
case AccountType.STATUSNET: {
|
||||
return R.drawable.ic_account_logo_statusnet;
|
||||
}
|
||||
|
||||
}
|
||||
return R.drawable.ic_account_logo_twitter;
|
||||
}
|
||||
}
|
||||
|
@ -6,18 +6,12 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.extension.AccountExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableAccountExtensionsKt;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials;
|
||||
import org.mariotaku.twidere.model.account.cred.OAuthCredentials;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/20.
|
||||
@ -27,95 +21,4 @@ public class ParcelableAccountUtils {
|
||||
private ParcelableAccountUtils() {
|
||||
}
|
||||
|
||||
public static UserKey[] getAccountKeys(@NonNull ParcelableAccount[] accounts) {
|
||||
UserKey[] ids = new UserKey[accounts.length];
|
||||
for (int i = 0, j = accounts.length; i < j; i++) {
|
||||
ids[i] = accounts[i].account_key;
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ParcelableAccount getAccount(@NonNull final Context context,
|
||||
@NonNull final UserKey accountKey) {
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
final Account account = AccountUtils.findByAccountKey(am, accountKey);
|
||||
if (account == null) return null;
|
||||
return ParcelableAccountExtensionsKt.toParcelableAccount(account, am);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ParcelableAccount[] getAccounts(final Context context, final boolean activatedOnly,
|
||||
final boolean officialKeyOnly) {
|
||||
ArrayList<Account> accounts = new ArrayList<>();
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
for (Account account : AccountUtils.getAccounts(am)) {
|
||||
boolean activated = AccountExtensionsKt.isAccountActivated(account, am);
|
||||
if (!activated && activatedOnly) continue;
|
||||
boolean isOfficialKey = isOfficialKey(context, account, am);
|
||||
if (!isOfficialKey && officialKeyOnly) continue;
|
||||
accounts.add(account);
|
||||
}
|
||||
return getAccounts(am, accounts.toArray(new Account[accounts.size()]));
|
||||
}
|
||||
|
||||
static boolean isOfficialKey(Context context, Account account, AccountManager am) {
|
||||
final String credentialsType = AccountExtensionsKt.getCredentialsType(account, am);
|
||||
if (!Credentials.Type.OAUTH.equals(credentialsType) && !Credentials.Type.XAUTH.equals(credentialsType)) {
|
||||
return false;
|
||||
}
|
||||
final OAuthCredentials credentials = (OAuthCredentials) AccountExtensionsKt.getCredentials(account, am);
|
||||
return TwitterContentUtils.isOfficialKey(context, credentials.consumer_key, credentials.consumer_secret);
|
||||
}
|
||||
|
||||
public static ParcelableAccount[] getAccounts(@NonNull final Context context) {
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
return getAccounts(am, AccountUtils.getAccounts(am));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ParcelableAccount[] getAccounts(@NonNull final Context context, @NonNull final UserKey... accountIds) {
|
||||
ArrayList<Account> accounts = new ArrayList<>();
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
for (Account account : AccountUtils.getAccounts(am)) {
|
||||
if (ArrayUtils.contains(accountIds, AccountExtensionsKt.getAccountKey(account, am))) {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
return getAccounts(am, accounts.toArray(new Account[accounts.size()]));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ParcelableAccount[] getAccounts(@NonNull final AccountManager am, @Nullable final Account[] accounts) {
|
||||
if (accounts == null) return new ParcelableAccount[0];
|
||||
final ParcelableAccount[] parcelableAccounts = new ParcelableAccount[accounts.length];
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
parcelableAccounts[i] = ParcelableAccountExtensionsKt.toParcelableAccount(accounts[i], am);
|
||||
}
|
||||
return parcelableAccounts;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@AccountType
|
||||
public static String getAccountType(@NonNull ParcelableAccount account) {
|
||||
if (account.account_type == null) return AccountType.TWITTER;
|
||||
return account.account_type;
|
||||
}
|
||||
|
||||
public static int getAccountTypeIcon(@Nullable String accountType) {
|
||||
if (accountType == null) return R.drawable.ic_account_logo_twitter;
|
||||
switch (accountType) {
|
||||
case AccountType.TWITTER: {
|
||||
return R.drawable.ic_account_logo_twitter;
|
||||
}
|
||||
case AccountType.FANFOU: {
|
||||
return R.drawable.ic_account_logo_fanfou;
|
||||
}
|
||||
case AccountType.STATUSNET: {
|
||||
return R.drawable.ic_account_logo_statusnet;
|
||||
}
|
||||
|
||||
}
|
||||
return R.drawable.ic_account_logo_twitter;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,8 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials.AuthTypeInt;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentialsExtensionsKt;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials;
|
||||
@ -61,7 +60,7 @@ public class ParcelableCredentialsUtils {
|
||||
|
||||
public static ParcelableCredentials[] getCredentialses(@NonNull final Context context) {
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
final Account[] accounts = am.getAccountsByType(TwidereConstants.ACCOUNT_TYPE);
|
||||
final Account[] accounts = AccountUtils.getAccounts(am);
|
||||
final ParcelableCredentials[] credentialses = new ParcelableCredentials[accounts.length];
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
credentialses[i] = ParcelableCredentialsExtensionsKt.toParcelableCredentials(accounts[i], am);
|
||||
|
@ -1,9 +1,10 @@
|
||||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.Draft;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableStatusUpdate;
|
||||
import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra;
|
||||
|
||||
@ -17,9 +18,9 @@ public class ParcelableStatusUpdateUtils {
|
||||
public static ParcelableStatusUpdate fromDraftItem(final Context context, final Draft draft) {
|
||||
ParcelableStatusUpdate statusUpdate = new ParcelableStatusUpdate();
|
||||
if (draft.account_keys != null) {
|
||||
statusUpdate.accounts = ParcelableAccountUtils.getAccounts(context, draft.account_keys);
|
||||
statusUpdate.accounts = AccountUtils.getAllAccountDetails(AccountManager.get(context), draft.account_keys);
|
||||
} else {
|
||||
statusUpdate.accounts = new ParcelableAccount[0];
|
||||
statusUpdate.accounts = new AccountDetails[0];
|
||||
}
|
||||
statusUpdate.text = draft.text;
|
||||
statusUpdate.location = draft.location;
|
||||
|
@ -9,7 +9,7 @@ import android.text.TextUtils;
|
||||
import org.mariotaku.microblog.library.twitter.model.UrlEntity;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.SpanItem;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
@ -129,7 +129,7 @@ public class ParcelableUserUtils implements TwidereConstants {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void updateExtraInformation(ParcelableUser user, ParcelableAccount account, UserColorNameManager manager) {
|
||||
public static void updateExtraInformation(ParcelableUser user, AccountDetails account, UserColorNameManager manager) {
|
||||
user.account_color = account.color;
|
||||
user.color = manager.getUserColor(user.key);
|
||||
user.nickname = manager.getUserNickname(user.key);
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.preference;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
@ -43,8 +44,8 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.BitmapUtils;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
@ -73,9 +74,9 @@ public abstract class AccountsListPreference extends PreferenceCategory implemen
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setAccountsData(final ParcelableAccount[] accounts) {
|
||||
public void setAccountsData(final AccountDetails[] accounts) {
|
||||
removeAll();
|
||||
for (final ParcelableAccount account : accounts) {
|
||||
for (final AccountDetails account : accounts) {
|
||||
final AccountItemPreference preference = new AccountItemPreference(getContext(), account,
|
||||
mSwitchKey, mSwitchDefault);
|
||||
setupPreference(preference, account);
|
||||
@ -90,30 +91,30 @@ public abstract class AccountsListPreference extends PreferenceCategory implemen
|
||||
protected void onAttachedToHierarchy(@NonNull final PreferenceManager preferenceManager) {
|
||||
super.onAttachedToHierarchy(preferenceManager);
|
||||
if (getPreferenceCount() > 0) return;
|
||||
setAccountsData(ParcelableAccountUtils.getAccounts(getContext()));
|
||||
setAccountsData(AccountUtils.getAllAccountDetails(AccountManager.get(getContext())));
|
||||
}
|
||||
|
||||
protected abstract void setupPreference(AccountItemPreference preference, ParcelableAccount account);
|
||||
protected abstract void setupPreference(AccountItemPreference preference, AccountDetails account);
|
||||
|
||||
public static final class AccountItemPreference extends Preference implements ImageLoadingListener,
|
||||
OnSharedPreferenceChangeListener {
|
||||
|
||||
private final ParcelableAccount mAccount;
|
||||
private final AccountDetails mAccount;
|
||||
private final SharedPreferences mSwitchPreference;
|
||||
|
||||
@Inject
|
||||
MediaLoaderWrapper mImageLoader;
|
||||
|
||||
public AccountItemPreference(final Context context, final ParcelableAccount account, final String switchKey,
|
||||
public AccountItemPreference(final Context context, final AccountDetails account, final String switchKey,
|
||||
final boolean switchDefault) {
|
||||
super(context);
|
||||
GeneralComponentHelper.build(context).inject(this);
|
||||
final String switchPreferenceName = ACCOUNT_PREFERENCES_NAME_PREFIX + account.account_key;
|
||||
final String switchPreferenceName = ACCOUNT_PREFERENCES_NAME_PREFIX + account.key;
|
||||
mAccount = account;
|
||||
mSwitchPreference = context.getSharedPreferences(switchPreferenceName, Context.MODE_PRIVATE);
|
||||
mSwitchPreference.registerOnSharedPreferenceChangeListener(this);
|
||||
setTitle(mAccount.name);
|
||||
setSummary(String.format("@%s", mAccount.screen_name));
|
||||
setTitle(mAccount.user.name);
|
||||
setSummary(String.format("@%s", mAccount.user.screen_name));
|
||||
mImageLoader.loadProfileImage(mAccount, this);
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ import android.widget.Toast;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.APIEditorActivity;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.fragment.ThemedPreferenceDialogFragmentCompat;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.preference.iface.IDialogPreference;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
@ -117,12 +117,12 @@ public class DefaultAPIPreference extends DialogPreference implements Constants,
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
final int authType = APIEditorActivity.Companion.getCheckedAuthType(checkedId);
|
||||
final boolean isOAuth = authType == ParcelableCredentials.AuthTypeInt.OAUTH || authType == ParcelableCredentials.AuthTypeInt.XAUTH;
|
||||
final boolean isOAuth = authType == AuthTypeInt.OAUTH || authType == AuthTypeInt.XAUTH;
|
||||
mEditSameOAuthSigningUrl.setVisibility(isOAuth ? View.VISIBLE : View.GONE);
|
||||
mEditConsumerKey.setVisibility(isOAuth ? View.VISIBLE : View.GONE);
|
||||
mEditConsumerSecret.setVisibility(isOAuth ? View.VISIBLE : View.GONE);
|
||||
if (!mEditNoVersionSuffixChanged) {
|
||||
mEditNoVersionSuffix.setChecked(authType == ParcelableCredentials.AuthTypeInt.TWIP_O_MODE);
|
||||
mEditNoVersionSuffix.setChecked(authType == AuthTypeInt.TWIP_O_MODE);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -144,7 +144,7 @@ public class DefaultAPIPreference extends DialogPreference implements Constants,
|
||||
} else {
|
||||
final SharedPreferences preferences = preference.getSharedPreferences();
|
||||
final String apiUrlFormat = preferences.getString(KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT);
|
||||
final int authType = preferences.getInt(KEY_AUTH_TYPE, ParcelableCredentials.AuthTypeInt.OAUTH);
|
||||
final int authType = preferences.getInt(KEY_AUTH_TYPE, AuthTypeInt.OAUTH);
|
||||
final boolean sameOAuthSigningUrl = preferences.getBoolean(KEY_SAME_OAUTH_SIGNING_URL, true);
|
||||
final boolean noVersionSuffix = preferences.getBoolean(KEY_NO_VERSION_SUFFIX, false);
|
||||
final String consumerKey = trim(preferences.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY));
|
||||
@ -201,10 +201,10 @@ public class DefaultAPIPreference extends DialogPreference implements Constants,
|
||||
mEditConsumerKey.setText(consumerKey);
|
||||
mEditConsumerSecret.setText(consumerSecret);
|
||||
|
||||
mButtonOAuth.setChecked(authType == ParcelableCredentials.AuthTypeInt.OAUTH);
|
||||
mButtonxAuth.setChecked(authType == ParcelableCredentials.AuthTypeInt.XAUTH);
|
||||
mButtonBasic.setChecked(authType == ParcelableCredentials.AuthTypeInt.BASIC);
|
||||
mButtonTwipOMode.setChecked(authType == ParcelableCredentials.AuthTypeInt.TWIP_O_MODE);
|
||||
mButtonOAuth.setChecked(authType == AuthTypeInt.OAUTH);
|
||||
mButtonxAuth.setChecked(authType == AuthTypeInt.XAUTH);
|
||||
mButtonBasic.setChecked(authType == AuthTypeInt.BASIC);
|
||||
mButtonTwipOMode.setChecked(authType == AuthTypeInt.TWIP_O_MODE);
|
||||
if (mEditAuthType.getCheckedRadioButtonId() == -1) {
|
||||
mButtonOAuth.setChecked(true);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mariotaku.twidere.task;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -10,12 +11,12 @@ import org.mariotaku.abstask.library.AbstractTask;
|
||||
import org.mariotaku.microblog.library.MicroBlog;
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
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.SingleResponse;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.message.FriendshipTaskEvent;
|
||||
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.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory;
|
||||
@ -80,15 +81,14 @@ public abstract class AbsFriendshipOperationTask extends AbstractTask<AbsFriends
|
||||
|
||||
@Override
|
||||
public final SingleResponse<ParcelableUser> doLongOperation(final Arguments args) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
args.accountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, false, false);
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(context), args.accountKey);
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, details, false, false, MicroBlog.class);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final User user = perform(twitter, credentials, args);
|
||||
final User user = perform(twitter, details, args);
|
||||
final ParcelableUser parcelableUser = ParcelableUserUtils.fromUser(user, args.accountKey);
|
||||
succeededWorker(twitter, credentials, args, parcelableUser);
|
||||
succeededWorker(twitter, details, args, parcelableUser);
|
||||
return SingleResponse.Companion.getInstance(parcelableUser);
|
||||
} catch (final MicroBlogException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
@ -97,11 +97,11 @@ public abstract class AbsFriendshipOperationTask extends AbstractTask<AbsFriends
|
||||
|
||||
@NonNull
|
||||
protected abstract User perform(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException;
|
||||
|
||||
protected abstract void succeededWorker(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args,
|
||||
@NonNull ParcelableUser user);
|
||||
|
||||
|
@ -10,10 +10,10 @@ import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
/**
|
||||
@ -27,8 +27,8 @@ public class AcceptFriendshipTask extends AbsFriendshipOperationTask implements
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.acceptFanfouFriendship(args.userKey.getId());
|
||||
}
|
||||
@ -37,7 +37,7 @@ public class AcceptFriendshipTask extends AbsFriendshipOperationTask implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
Utils.setLastSeen(context, user.key, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,10 @@ import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
/**
|
||||
@ -28,8 +28,8 @@ public class CreateFriendshipTask extends AbsFriendshipOperationTask implements
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.createFanfouFriendship(args.userKey.getId());
|
||||
}
|
||||
@ -38,7 +38,7 @@ public class CreateFriendshipTask extends AbsFriendshipOperationTask implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
user.is_following = true;
|
||||
Utils.setLastSeen(context, user.key, System.currentTimeMillis());
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
||||
@ -34,9 +34,9 @@ public class CreateUserBlockTask extends AbsFriendshipOperationTask implements C
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials,
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.createFanfouBlock(args.userKey.getId());
|
||||
}
|
||||
@ -46,7 +46,7 @@ public class CreateUserBlockTask extends AbsFriendshipOperationTask implements C
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
Utils.setLastSeen(context, args.userKey, -1);
|
||||
|
@ -12,7 +12,7 @@ import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
@ -33,14 +33,14 @@ public class CreateUserMuteTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials,
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException {
|
||||
return twitter.createMute(args.userKey.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
Utils.setLastSeen(context, args.userKey, -1);
|
||||
|
@ -9,10 +9,10 @@ import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST;
|
||||
@ -28,8 +28,8 @@ public class DenyFriendshipTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.denyFanfouFriendship(args.userKey.getId());
|
||||
}
|
||||
@ -38,7 +38,7 @@ public class DenyFriendshipTask extends AbsFriendshipOperationTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
Utils.setLastSeen(context, user.key, -1);
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,11 @@ import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST;
|
||||
@ -31,8 +31,8 @@ public class DestroyFriendshipTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args) throws MicroBlogException {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.destroyFanfouFriendship(args.userKey.getId());
|
||||
}
|
||||
@ -41,16 +41,16 @@ public class DestroyFriendshipTask extends AbsFriendshipOperationTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter, @NonNull AccountDetails details, @NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
user.is_following = false;
|
||||
Utils.setLastSeen(context, user.key, -1);
|
||||
final Expression where = Expression.and(Expression.equalsArgs(TwidereDataStore.Statuses.ACCOUNT_KEY),
|
||||
Expression.or(Expression.equalsArgs(TwidereDataStore.Statuses.USER_KEY),
|
||||
Expression.equalsArgs(TwidereDataStore.Statuses.RETWEETED_BY_USER_KEY)));
|
||||
final Expression where = Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_KEY),
|
||||
Expression.or(Expression.equalsArgs(Statuses.USER_KEY),
|
||||
Expression.equalsArgs(Statuses.RETWEETED_BY_USER_KEY)));
|
||||
final String[] whereArgs = {args.userKey.toString(), args.userKey.toString(),
|
||||
args.userKey.toString()};
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
resolver.delete(TwidereDataStore.Statuses.CONTENT_URI, where.getSQL(), whereArgs);
|
||||
resolver.delete(Statuses.CONTENT_URI, where.getSQL(), whereArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,10 +11,10 @@ import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.R;
|
||||
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.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
@ -30,9 +30,9 @@ public class DestroyUserBlockTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials,
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException {
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
return twitter.destroyFanfouBlock(args.userKey.getId());
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class DestroyUserBlockTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
// I bet you don't want to see this user in your auto complete list.
|
||||
|
@ -10,7 +10,7 @@ import org.mariotaku.microblog.library.MicroBlog;
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.message.FriendshipTaskEvent;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
||||
@ -28,14 +28,14 @@ public class DestroyUserMuteTask extends AbsFriendshipOperationTask {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials,
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException {
|
||||
return twitter.destroyMute(args.userKey.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void succeededWorker(@NonNull MicroBlog twitter,
|
||||
@NonNull ParcelableCredentials credentials,
|
||||
@NonNull AccountDetails details,
|
||||
@NonNull Arguments args, @NonNull ParcelableUser user) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
// I bet you don't want to see this user in your auto complete list.
|
||||
|
@ -1,84 +0,0 @@
|
||||
package org.mariotaku.twidere.task;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mariotaku.microblog.library.MicroBlog;
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity;
|
||||
import org.mariotaku.microblog.library.twitter.model.CursorTimestampResponse;
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging;
|
||||
import org.mariotaku.microblog.library.twitter.model.ResponseList;
|
||||
import org.mariotaku.microblog.library.twitter.model.Status;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.annotation.ReadPositionTag;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesTask;
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
public class GetActivitiesAboutMeTask extends GetActivitiesTask {
|
||||
|
||||
public GetActivitiesAboutMeTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String getErrorInfoKey() {
|
||||
return ErrorInfoStore.KEY_INTERACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveReadPosition(@NonNull UserKey accountKey, ParcelableCredentials credentials, @NonNull MicroBlog twitter) {
|
||||
if (AccountType.TWITTER.equals(ParcelableAccountUtils.getAccountType(credentials))) {
|
||||
if (Utils.isOfficialCredentials(getContext(), credentials)) {
|
||||
try {
|
||||
CursorTimestampResponse response = twitter.getActivitiesAboutMeUnread(true);
|
||||
final String tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.ACTIVITIES_ABOUT_ME,
|
||||
accountKey);
|
||||
getReadStateManager().setPosition(tag, response.getCursor(), false);
|
||||
} catch (MicroBlogException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseList<Activity> getActivities(@NonNull final MicroBlog twitter,
|
||||
@NonNull final ParcelableCredentials credentials,
|
||||
@NonNull final Paging paging) throws MicroBlogException {
|
||||
if (Utils.isOfficialCredentials(getContext(), credentials)) {
|
||||
return twitter.getActivitiesAboutMe(paging);
|
||||
}
|
||||
final ResponseList<Activity> activities = new ResponseList<>();
|
||||
final ResponseList<Status> statuses;
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
case AccountType.FANFOU: {
|
||||
statuses = twitter.getMentions(paging);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
statuses = twitter.getMentionsTimeline(paging);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Status status : statuses) {
|
||||
activities.add(Activity.fromMention(credentials.account_key.getId(), status));
|
||||
}
|
||||
return activities;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Uri getContentUri() {
|
||||
return Activities.AboutMe.CONTENT_URI;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.mariotaku.twidere.task
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.ResponseList
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesTask
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
class GetActivitiesAboutMeTask(context: Context) : GetActivitiesTask(context) {
|
||||
|
||||
override val errorInfoKey: String
|
||||
get() = ErrorInfoStore.KEY_INTERACTIONS
|
||||
|
||||
override fun saveReadPosition(accountKey: UserKey, details: AccountDetails, twitter: MicroBlog) {
|
||||
if (AccountType.TWITTER == AccountUtils.getAccountType(details)) {
|
||||
if (details.isOfficial(context)) {
|
||||
try {
|
||||
val response = twitter.getActivitiesAboutMeUnread(true)
|
||||
val tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.ACTIVITIES_ABOUT_ME,
|
||||
accountKey)
|
||||
readStateManager.setPosition(tag, response.cursor, false)
|
||||
} catch (e: MicroBlogException) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getActivities(twitter: MicroBlog,
|
||||
details: AccountDetails,
|
||||
paging: Paging): ResponseList<Activity> {
|
||||
if (details.isOfficial(context)) {
|
||||
return twitter.getActivitiesAboutMe(paging)
|
||||
}
|
||||
val activities = ResponseList<Activity>()
|
||||
val statuses: ResponseList<Status>
|
||||
when (AccountUtils.getAccountType(details)) {
|
||||
AccountType.FANFOU -> {
|
||||
statuses = twitter.getMentions(paging)
|
||||
}
|
||||
else -> {
|
||||
statuses = twitter.getMentionsTimeline(paging)
|
||||
}
|
||||
}
|
||||
for (status in statuses) {
|
||||
activities.add(Activity.fromMention(details.key.id, status))
|
||||
}
|
||||
return activities
|
||||
}
|
||||
|
||||
override val contentUri: Uri
|
||||
get() = Activities.AboutMe.CONTENT_URI
|
||||
}
|
@ -6,7 +6,7 @@ import android.support.annotation.NonNull;
|
||||
import org.mariotaku.microblog.library.MicroBlog;
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/11.
|
||||
@ -16,10 +16,9 @@ public class ReportSpamAndBlockTask extends CreateUserBlockTask {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull ParcelableCredentials credentials,
|
||||
protected User perform(@NonNull MicroBlog twitter, @NonNull AccountDetails details,
|
||||
@NonNull Arguments args) throws MicroBlogException {
|
||||
return twitter.reportSpam(args.userKey.getId());
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -57,9 +58,10 @@ import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.extension.CredentialsExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ListResponse;
|
||||
import org.mariotaku.twidere.model.ParcelableActivity;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
@ -83,8 +85,7 @@ import org.mariotaku.twidere.model.message.UserListMembersChangedEvent;
|
||||
import org.mariotaku.twidere.model.message.UserListSubscriptionEvent;
|
||||
import org.mariotaku.twidere.model.message.UserListUpdatedEvent;
|
||||
import org.mariotaku.twidere.model.message.UsersBlockedEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserListUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils;
|
||||
@ -223,7 +224,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
}
|
||||
|
||||
public int createFavoriteAsync(final UserKey accountKey, final String statusId) {
|
||||
final CreateFavoriteTask task = new CreateFavoriteTask(accountKey, statusId);
|
||||
final CreateFavoriteTask task = new CreateFavoriteTask(context, accountKey, statusId);
|
||||
return asyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
@ -519,9 +520,9 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
TaskStarter.execute(new AbstractTask<Object, SingleResponse<Relationship>, Bus>() {
|
||||
@Override
|
||||
public SingleResponse<Relationship> doLongOperation(Object param) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountKey, true);
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, accountKey, true);
|
||||
try {
|
||||
final Relationship relationship = twitter.updateFriendship(userKey.getId(), update);
|
||||
final Relationship relationship = microBlog.updateFriendship(userKey.getId(), update);
|
||||
if (!relationship.isSourceWantRetweetsFromTarget()) {
|
||||
// TODO remove cached retweets
|
||||
final Expression where = Expression.and(
|
||||
@ -562,10 +563,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
public Object doLongOperation(Object o) {
|
||||
for (UserKey accountId : accountKeys) {
|
||||
MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountId, false);
|
||||
MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, accountId, false);
|
||||
if (!Utils.isOfficialCredentials(context, accountId)) continue;
|
||||
try {
|
||||
twitter.setActivitiesAboutMeUnread(cursor);
|
||||
microBlog.setActivitiesAboutMeUnread(cursor);
|
||||
} catch (MicroBlogException e) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.w(LOGTAG, e);
|
||||
@ -614,8 +615,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUser> doLongOperation(final Object params) {
|
||||
try {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, true);
|
||||
TwitterWrapper.updateProfileImage(mContext, twitter, mImageUri, mDeleteImage);
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, true);
|
||||
TwitterWrapper.updateProfileImage(mContext, microBlog, mImageUri, mDeleteImage);
|
||||
// Wait for 5 seconds, see
|
||||
// https://dev.twitter.com/rest/reference/post/account/update_profile_image
|
||||
try {
|
||||
@ -623,7 +624,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
} catch (InterruptedException e) {
|
||||
Log.w(LOGTAG, e);
|
||||
}
|
||||
final User user = twitter.verifyCredentials();
|
||||
final User user = microBlog.verifyCredentials();
|
||||
return SingleResponse.Companion.getInstance(ParcelableUserUtils.fromUser(user, mAccountKey));
|
||||
} catch (MicroBlogException | IOException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
@ -661,14 +662,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserKey[] userIds = new UserKey[mUsers.length];
|
||||
for (int i = 0, j = mUsers.length; i < j; i++) {
|
||||
userIds[i] = mUsers[i].key;
|
||||
}
|
||||
final UserList result = twitter.addUserListMembers(mListId, UserKey.getIds(userIds));
|
||||
final UserList result = microBlog.addUserListMembers(mListId, UserKey.getIds(userIds));
|
||||
final ParcelableUserList list = ParcelableUserListUtils.from(result, mAccountKey);
|
||||
return SingleResponse.Companion.getInstance(list);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -738,7 +739,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
private final UserKey mAccountKey;
|
||||
private final String mStatusId;
|
||||
|
||||
public CreateFavoriteTask(final UserKey accountKey, final String statusId) {
|
||||
public CreateFavoriteTask(Context context, final UserKey accountKey, final String statusId) {
|
||||
super(context);
|
||||
this.mAccountKey = accountKey;
|
||||
this.mStatusId = statusId;
|
||||
@ -746,26 +747,28 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final ContentResolver resolver = getContext().getContentResolver();
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(getContext()), mAccountKey);
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = CredentialsExtensionsKt.newMicroBlogInstance(details.credentials,
|
||||
getContext(), true, null, MicroBlog.class);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final ParcelableStatus result;
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
switch (details.type) {
|
||||
case AccountType.FANFOU: {
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.createFanfouFavorite(mStatusId),
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.createFanfouFavorite(mStatusId),
|
||||
mAccountKey, false);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.createFavorite(mStatusId),
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.createFavorite(mStatusId),
|
||||
mAccountKey, false);
|
||||
}
|
||||
}
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, details,
|
||||
mUserColorNameManager);
|
||||
Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
|
||||
Utils.setLastSeen(getContext(), result.mentions, System.currentTimeMillis());
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(Statuses.IS_FAVORITE, true);
|
||||
values.put(Statuses.REPLY_COUNT, result.reply_count);
|
||||
@ -837,7 +840,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
// END HotMobi
|
||||
} else {
|
||||
taskEvent.setSucceeded(false);
|
||||
Utils.showErrorMessage(context, R.string.action_favoriting, result.getException(), true);
|
||||
Utils.showErrorMessage(getContext(), R.string.action_favoriting, result.getException(), true);
|
||||
}
|
||||
bus.post(taskEvent);
|
||||
bus.post(new StatusListChangedEvent());
|
||||
@ -877,11 +880,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected ListResponse<String> doInBackground(final Object... params) {
|
||||
final List<String> blockedUsers = new ArrayList<>();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter != null) {
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog != null) {
|
||||
for (final String userId : mUserIds) {
|
||||
try {
|
||||
final User user = twitter.createBlock(userId);
|
||||
final User user = microBlog.createBlock(userId);
|
||||
blockedUsers.add(user.getId());
|
||||
} catch (final MicroBlogException e) {
|
||||
deleteCaches(blockedUsers);
|
||||
@ -920,10 +923,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<SavedSearch> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return null;
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return null;
|
||||
try {
|
||||
return SingleResponse.Companion.getInstance(twitter.createSavedSearch(mQuery));
|
||||
return SingleResponse.Companion.getInstance(microBlog.createSavedSearch(mQuery));
|
||||
} catch (final MicroBlogException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
}
|
||||
@ -962,10 +965,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserList userList = twitter.createUserListSubscription(mListId);
|
||||
final UserList userList = microBlog.createUserListSubscription(mListId);
|
||||
final ParcelableUserList list = ParcelableUserListUtils.from(userList, mAccountKey);
|
||||
return SingleResponse.Companion.getInstance(list);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1006,15 +1009,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(getContext(), mAccountKey,
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(getContext(), mAccountKey,
|
||||
false);
|
||||
if (twitter == null || mListName == null) return SingleResponse.Companion.getInstance();
|
||||
if (microBlog == null || mListName == null)
|
||||
return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserListUpdate userListUpdate = new UserListUpdate();
|
||||
userListUpdate.setName(mListName);
|
||||
userListUpdate.setMode(mIsPublic ? UserList.Mode.PUBLIC : UserList.Mode.PRIVATE);
|
||||
userListUpdate.setDescription(mDescription);
|
||||
final UserList list = twitter.createUserList(userListUpdate);
|
||||
final UserList list = microBlog.createUserList(userListUpdate);
|
||||
return SingleResponse.Companion.getInstance(ParcelableUserListUtils.from(list, mAccountKey));
|
||||
} catch (final MicroBlogException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
@ -1052,14 +1056,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserKey[] userIds = new UserKey[users.length];
|
||||
for (int i = 0, j = users.length; i < j; i++) {
|
||||
userIds[i] = users[i].key;
|
||||
}
|
||||
final UserList userList = twitter.deleteUserListMembers(mUserListId, UserKey.getIds(userIds));
|
||||
final UserList userList = microBlog.deleteUserListMembers(mUserListId, UserKey.getIds(userIds));
|
||||
final ParcelableUserList list = ParcelableUserListUtils.from(userList, mAccountKey);
|
||||
return SingleResponse.Companion.getInstance(list);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1124,10 +1128,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<DirectMessage> doInBackground(final Object... args) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final DirectMessage message = twitter.destroyDirectMessage(mMessageId);
|
||||
final DirectMessage message = microBlog.destroyDirectMessage(mMessageId);
|
||||
deleteMessages();
|
||||
return SingleResponse.Companion.getInstance(message);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1186,10 +1190,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<Void> doInBackground(final Object... args) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
twitter.destroyDirectMessagesConversation(mAccountKey.getId(), mUserId);
|
||||
microBlog.destroyDirectMessagesConversation(mAccountKey.getId(), mUserId);
|
||||
deleteMessages(mAccountKey, mUserId);
|
||||
return SingleResponse.Companion.getInstance();
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1230,20 +1234,21 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(context), mAccountKey);
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = CredentialsExtensionsKt.newMicroBlogInstance(details.credentials,
|
||||
getContext(), true, null, MicroBlog.class);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final ParcelableStatus result;
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.destroyFanfouFavorite(mStatusId),
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.destroyFanfouFavorite(mStatusId),
|
||||
mAccountKey, false);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.destroyFavorite(mStatusId),
|
||||
result = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.destroyFavorite(mStatusId),
|
||||
mAccountKey, false);
|
||||
}
|
||||
}
|
||||
@ -1334,10 +1339,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<SavedSearch> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
return SingleResponse.Companion.getInstance(twitter.destroySavedSearch(mSearchId));
|
||||
return SingleResponse.Companion.getInstance(microBlog.destroySavedSearch(mSearchId));
|
||||
} catch (final MicroBlogException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
}
|
||||
@ -1370,18 +1375,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(getContext()),
|
||||
mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true,
|
||||
true);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = CredentialsExtensionsKt.newMicroBlogInstance(details.credentials,
|
||||
getContext(), true, null, MicroBlog.class);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
ParcelableStatus status = null;
|
||||
MicroBlogException exception = null;
|
||||
try {
|
||||
status = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.destroyStatus(mStatusId),
|
||||
status = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.destroyStatus(mStatusId),
|
||||
mAccountKey, false);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, credentials,
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, details,
|
||||
mUserColorNameManager);
|
||||
} catch (final MicroBlogException e) {
|
||||
exception = e;
|
||||
@ -1436,10 +1441,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, mAccountKey, false);
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserList userList = twitter.destroyUserListSubscription(mListId);
|
||||
final UserList userList = microBlog.destroyUserListSubscription(mListId);
|
||||
final ParcelableUserList list = ParcelableUserListUtils.from(userList, mAccountKey);
|
||||
return SingleResponse.Companion.getInstance(list);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1476,11 +1481,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(getContext(), mAccountKey,
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(getContext(), mAccountKey,
|
||||
false);
|
||||
if (twitter == null) return SingleResponse.Companion.getInstance();
|
||||
if (microBlog == null) return SingleResponse.Companion.getInstance();
|
||||
try {
|
||||
final UserList userList = twitter.destroyUserList(mListId);
|
||||
final UserList userList = microBlog.destroyUserList(mListId);
|
||||
final ParcelableUserList list = ParcelableUserListUtils.from(userList, mAccountKey);
|
||||
return SingleResponse.Companion.getInstance(list);
|
||||
} catch (final MicroBlogException e) {
|
||||
@ -1592,17 +1597,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
@Override
|
||||
protected SingleResponse<ParcelableStatus> doInBackground(final Object... params) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(getContext()),
|
||||
mAccountKey);
|
||||
if (credentials == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true);
|
||||
if (twitter == null) {
|
||||
if (details == null) return SingleResponse.Companion.getInstance();
|
||||
final MicroBlog microBlog = CredentialsExtensionsKt.newMicroBlogInstance(details.credentials,
|
||||
getContext(), true, null, MicroBlog.class);
|
||||
if (microBlog == null) {
|
||||
return SingleResponse.Companion.getInstance();
|
||||
}
|
||||
try {
|
||||
final ParcelableStatus result = ParcelableStatusUtils.INSTANCE.fromStatus(twitter.retweetStatus(mStatusId),
|
||||
final ParcelableStatus result = ParcelableStatusUtils.INSTANCE.fromStatus(microBlog.retweetStatus(mStatusId),
|
||||
mAccountKey, false);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, credentials,
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(result, details,
|
||||
mUserColorNameManager);
|
||||
Utils.setLastSeen(context, result.mentions, System.currentTimeMillis());
|
||||
final ContentValues values = new ContentValues();
|
||||
@ -1694,10 +1700,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected SingleResponse<ParcelableUserList> doInBackground(final Object... params) {
|
||||
|
||||
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
if (twitter != null) {
|
||||
final MicroBlog microBlog = MicroBlogAPIFactory.getInstance(mContext, mAccountKey, false);
|
||||
if (microBlog != null) {
|
||||
try {
|
||||
final UserList list = twitter.updateUserList(listId, update);
|
||||
final UserList list = microBlog.updateUserList(listId, update);
|
||||
return SingleResponse.Companion.getInstance(ParcelableUserListUtils.from(list, mAccountKey));
|
||||
} catch (final MicroBlogException e) {
|
||||
return SingleResponse.Companion.getInstance(e);
|
||||
|
@ -29,10 +29,10 @@ import org.mariotaku.microblog.library.twitter.model.Trend;
|
||||
import org.mariotaku.microblog.library.twitter.model.Trends;
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.Draft;
|
||||
import org.mariotaku.twidere.model.ParcelableActivity;
|
||||
import org.mariotaku.twidere.model.ParcelableActivityValuesCreator;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessage;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessageValuesCreator;
|
||||
import org.mariotaku.twidere.model.ParcelableMediaUpdate;
|
||||
@ -155,15 +155,15 @@ public final class ContentValuesCreator implements TwidereConstants {
|
||||
|
||||
@NonNull
|
||||
public static ContentValues createActivity(final ParcelableActivity activity,
|
||||
final ParcelableCredentials credentials,
|
||||
final AccountDetails details,
|
||||
final UserColorNameManager manager) throws IOException {
|
||||
final ContentValues values = new ContentValues();
|
||||
final ParcelableStatus status = ParcelableActivityExtensionsKt.getActivityStatus(activity);
|
||||
|
||||
activity.account_color = credentials.color;
|
||||
activity.account_color = details.color;
|
||||
|
||||
if (status != null) {
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, credentials, manager);
|
||||
ParcelableStatusUtils.INSTANCE.updateExtraInformation(status, details, manager);
|
||||
|
||||
activity.status_id = status.id;
|
||||
activity.status_retweet_id = status.retweet_id;
|
||||
|
@ -32,7 +32,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageSize;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
@ -146,18 +146,8 @@ public class MediaLoaderWrapper {
|
||||
}
|
||||
|
||||
|
||||
public void displayProfileBanner(final ImageView view, final ParcelableAccount account, final int width) {
|
||||
displayProfileBanner(view, getBestBannerUrl(getBannerUrl(account), width));
|
||||
}
|
||||
|
||||
private String getBannerUrl(ParcelableAccount account) {
|
||||
String bannerUrl = account.profile_banner_url;
|
||||
if (bannerUrl == null && AccountType.FANFOU.equals(account.account_type)) {
|
||||
if (account.account_user != null) {
|
||||
bannerUrl = ParcelableUserUtils.getProfileBannerUrl(account.account_user);
|
||||
}
|
||||
}
|
||||
return bannerUrl;
|
||||
public void displayProfileBanner(final ImageView view, final AccountDetails account, final int width) {
|
||||
displayProfileBanner(view, getBestBannerUrl(ParcelableUserUtils.getProfileBannerUrl(account.user), width));
|
||||
}
|
||||
|
||||
public void displayOriginalProfileImage(final ImageView view, final ParcelableUser user) {
|
||||
@ -220,14 +210,13 @@ public class MediaLoaderWrapper {
|
||||
}
|
||||
|
||||
public void displayDashboardProfileImage(@NonNull final ImageView view,
|
||||
@NonNull final ParcelableAccount account,
|
||||
@NonNull final AccountDetails account,
|
||||
@Nullable final Drawable drawableOnLoading) {
|
||||
if (account.account_user != null && account.account_user.extras != null
|
||||
&& !TextUtils.isEmpty(account.account_user.extras.profile_image_url_profile_size)) {
|
||||
displayDashboardProfileImage(view, account.account_user.extras.profile_image_url_profile_size,
|
||||
if (account.user.extras != null && !TextUtils.isEmpty(account.user.extras.profile_image_url_profile_size)) {
|
||||
displayDashboardProfileImage(view, account.user.extras.profile_image_url_profile_size,
|
||||
drawableOnLoading);
|
||||
} else {
|
||||
displayDashboardProfileImage(view, account.profile_image_url, drawableOnLoading);
|
||||
displayDashboardProfileImage(view, account.user.profile_image_url, drawableOnLoading);
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,12 +241,11 @@ public class MediaLoaderWrapper {
|
||||
mImageLoader.displayImage(url, view, mProfileImageDisplayOptions, listener);
|
||||
}
|
||||
|
||||
public void loadProfileImage(final ParcelableAccount account, final ImageLoadingListener listener) {
|
||||
if (account.account_user != null && account.account_user.extras != null
|
||||
&& !TextUtils.isEmpty(account.account_user.extras.profile_image_url_profile_size)) {
|
||||
loadProfileImage(account.account_user.extras.profile_image_url_profile_size, listener);
|
||||
public void loadProfileImage(final AccountDetails account, final ImageLoadingListener listener) {
|
||||
if (account.user.extras != null && !TextUtils.isEmpty(account.user.extras.profile_image_url_profile_size)) {
|
||||
loadProfileImage(account.user.extras.profile_image_url_profile_size, listener);
|
||||
} else {
|
||||
loadProfileImage(account.profile_image_url, listener);
|
||||
loadProfileImage(account.user.profile_image_url, listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -45,17 +46,18 @@ import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.restfu.oauth.OAuthAuthorization;
|
||||
import org.mariotaku.restfu.oauth.OAuthEndpoint;
|
||||
import org.mariotaku.restfu.oauth.OAuthToken;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.extension.AccountExtensionsKt;
|
||||
import org.mariotaku.twidere.extension.CredentialsExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -111,7 +113,11 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
public static MicroBlog getInstance(@NonNull final Context context,
|
||||
@NonNull final UserKey accountKey,
|
||||
final boolean includeEntities) {
|
||||
return getInstance(context, accountKey, includeEntities, true);
|
||||
AccountManager am = AccountManager.get(context);
|
||||
Account account = AccountUtils.findByAccountKey(am, accountKey);
|
||||
if (account == null) return null;
|
||||
return CredentialsExtensionsKt.newMicroBlogInstance(AccountExtensionsKt.getCredentials(account,
|
||||
am), context, true, null, MicroBlog.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -123,13 +129,6 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
return getInstance(context, accountKey, includeEntities, includeRetweets, MicroBlog.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MicroBlog getInstance(@NonNull final Context context,
|
||||
@NonNull final ParcelableCredentials credentials,
|
||||
final boolean includeEntities, final boolean includeRetweets) {
|
||||
return getInstance(context, credentials, includeEntities, includeRetweets, MicroBlog.class);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@WorkerThread
|
||||
@ -138,18 +137,18 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
final boolean includeEntities,
|
||||
final boolean includeRetweets,
|
||||
@NonNull Class<T> cls) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, accountKey);
|
||||
if (credentials == null) return null;
|
||||
return getInstance(context, credentials, includeEntities, includeRetweets, cls);
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey);
|
||||
if (details == null) return null;
|
||||
return getInstance(context, details, includeEntities, includeRetweets, cls);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T getInstance(@NonNull final Context context,
|
||||
@NonNull final ParcelableCredentials credentials,
|
||||
@NonNull final AccountDetails details,
|
||||
final boolean includeEntities, final boolean includeRetweets,
|
||||
@NonNull Class<T> cls) {
|
||||
final HashMap<String, String> extraParams = new HashMap<>();
|
||||
switch (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
switch (AccountUtils.getAccountType(details)) {
|
||||
case AccountType.FANFOU: {
|
||||
extraParams.put("format", "html");
|
||||
break;
|
||||
@ -160,7 +159,8 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return getInstance(context, credentials, extraParams, cls);
|
||||
return CredentialsExtensionsKt.newMicroBlogInstance(details.credentials, context,
|
||||
AccountType.TWITTER.equals(details.type), extraParams, cls);
|
||||
}
|
||||
|
||||
|
||||
@ -205,13 +205,6 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
return getInstance(context, endpoint, auth, null, cls, true);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static <T> T getInstance(final Context context, final Endpoint endpoint,
|
||||
final ParcelableCredentials credentials,
|
||||
final Class<T> cls) {
|
||||
return getInstance(context, endpoint, credentials, null, cls);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static <T> T getInstance(final Context context, final Endpoint endpoint,
|
||||
final ParcelableCredentials credentials,
|
||||
@ -220,10 +213,6 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
isTwitterCredentials(credentials));
|
||||
}
|
||||
|
||||
public static boolean isTwitterCredentials(Context context, UserKey accountId) {
|
||||
return isTwitterCredentials(ParcelableAccountUtils.getAccount(context, accountId));
|
||||
}
|
||||
|
||||
public static boolean isTwitterCredentials(ParcelableAccount account) {
|
||||
if (account.account_type == null) {
|
||||
final String accountHost = account.account_key.getHost();
|
||||
@ -237,12 +226,6 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
return AccountType.STATUSNET.equals(account.account_type);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
static <T> T getInstance(final Context context, final ParcelableCredentials credentials,
|
||||
final Class<T> cls) {
|
||||
return getInstance(context, credentials, null, cls);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
static <T> T getInstance(final Context context, final ParcelableCredentials credentials,
|
||||
final Map<String, String> extraRequestParams, final Class<T> cls) {
|
||||
@ -287,7 +270,7 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
}
|
||||
final String endpointUrl;
|
||||
endpointUrl = getApiUrl(apiUrlFormat, domain, versionSuffix);
|
||||
if (credentials.auth_type == ParcelableCredentials.AuthTypeInt.XAUTH || credentials.auth_type == ParcelableCredentials.AuthTypeInt.OAUTH) {
|
||||
if (credentials.auth_type == AuthTypeInt.XAUTH || credentials.auth_type == AuthTypeInt.OAUTH) {
|
||||
final String signEndpointUrl;
|
||||
if (!sameOAuthSigningUrl) {
|
||||
signEndpointUrl = getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, domain, versionSuffix);
|
||||
@ -304,8 +287,8 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
public static Authorization getAuthorization(@Nullable ParcelableCredentials credentials) {
|
||||
if (credentials == null) return null;
|
||||
switch (credentials.auth_type) {
|
||||
case ParcelableCredentials.AuthTypeInt.OAUTH:
|
||||
case ParcelableCredentials.AuthTypeInt.XAUTH: {
|
||||
case AuthTypeInt.OAUTH:
|
||||
case AuthTypeInt.XAUTH: {
|
||||
final String consumerKey = TextUtils.isEmpty(credentials.consumer_key) ?
|
||||
TWITTER_CONSUMER_KEY_LEGACY : credentials.consumer_key;
|
||||
final String consumerSecret = TextUtils.isEmpty(credentials.consumer_secret) ?
|
||||
@ -316,7 +299,7 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
||||
return new OAuthAuthorization(consumerKey, consumerSecret, accessToken);
|
||||
return new OAuthAuthorization(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, accessToken);
|
||||
}
|
||||
case ParcelableCredentials.AuthTypeInt.BASIC: {
|
||||
case AuthTypeInt.BASIC: {
|
||||
final String screenName = credentials.screen_name;
|
||||
final String username = credentials.basic_auth_username;
|
||||
final String loginName = username != null ? username : screenName;
|
||||
|
@ -26,7 +26,7 @@ import android.text.TextUtils;
|
||||
import com.twitter.Validator;
|
||||
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.account.StatusNetAccountExtras;
|
||||
|
||||
public class TwidereValidator {
|
||||
@ -37,10 +37,10 @@ public class TwidereValidator {
|
||||
mValidator = new Validator();
|
||||
}
|
||||
|
||||
public static int getTextLimit(@NonNull ParcelableCredentials[] credentials) {
|
||||
public static int getTextLimit(@NonNull AccountDetails[] credentials) {
|
||||
int limit = -1;
|
||||
for (ParcelableCredentials credential : credentials) {
|
||||
int currentLimit = getTextLimit(credential);
|
||||
for (AccountDetails details : credentials) {
|
||||
int currentLimit = getTextLimit(details);
|
||||
if (currentLimit != 0) {
|
||||
if (limit <= 0) {
|
||||
limit = currentLimit;
|
||||
@ -56,14 +56,13 @@ public class TwidereValidator {
|
||||
* @param credentials Account for getting limit
|
||||
* @return Text limit, <= 0 if no limit
|
||||
*/
|
||||
public static int getTextLimit(@NonNull ParcelableCredentials credentials) {
|
||||
if (credentials.account_type == null) {
|
||||
public static int getTextLimit(@NonNull AccountDetails credentials) {
|
||||
if (credentials.type == null) {
|
||||
return Validator.MAX_TWEET_LENGTH;
|
||||
}
|
||||
switch (credentials.account_type) {
|
||||
switch (credentials.type) {
|
||||
case AccountType.STATUSNET: {
|
||||
StatusNetAccountExtras extra = JsonSerializer.parse(credentials.account_extras,
|
||||
StatusNetAccountExtras.class);
|
||||
StatusNetAccountExtras extra = (StatusNetAccountExtras) credentials.extras;
|
||||
if (extra != null) {
|
||||
return extra.getTextLimit();
|
||||
}
|
||||
|
@ -87,7 +87,6 @@ import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.json.JSONException;
|
||||
import org.mariotaku.microblog.library.MicroBlog;
|
||||
@ -103,12 +102,11 @@ import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.adapter.iface.IBaseAdapter;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.annotation.CustomTabType;
|
||||
import org.mariotaku.twidere.extension.model.AccountDetailsExtensionsKt;
|
||||
import org.mariotaku.twidere.graphic.PaddingDrawable;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.AccountPreferences;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessage;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
@ -118,10 +116,7 @@ import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUserMention;
|
||||
import org.mariotaku.twidere.model.PebbleMessage;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.account.TwitterAccountExtras;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
@ -333,7 +328,7 @@ public final class Utils implements Constants {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static int[] getAccountColors(@Nullable final ParcelableAccount[] accounts) {
|
||||
public static int[] getAccountColors(@Nullable final AccountDetails[] accounts) {
|
||||
if (accounts == null) return null;
|
||||
final int[] colors = new int[accounts.length];
|
||||
for (int i = 0, j = accounts.length; i < j; i++) {
|
||||
@ -514,23 +509,15 @@ public final class Utils implements Constants {
|
||||
}
|
||||
|
||||
public static boolean isOfficialCredentials(@NonNull final Context context, final UserKey accountKey) {
|
||||
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(context, accountKey);
|
||||
if (credentials == null) return false;
|
||||
return isOfficialCredentials(context, credentials);
|
||||
final AccountDetails details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey);
|
||||
if (details == null) return false;
|
||||
return AccountDetailsExtensionsKt.isOfficial(details, context);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isOfficialCredentials(@NonNull final Context context,
|
||||
@NonNull final ParcelableCredentials account) {
|
||||
if (AccountType.TWITTER.equals(account.account_type)) {
|
||||
final TwitterAccountExtras extra = JsonSerializer.parse(account.account_extras,
|
||||
TwitterAccountExtras.class);
|
||||
if (extra != null) {
|
||||
return extra.isOfficialCredentials();
|
||||
}
|
||||
}
|
||||
final boolean isOAuth = ParcelableCredentialsUtils.isOAuth(account.auth_type);
|
||||
final String consumerKey = account.consumer_key, consumerSecret = account.consumer_secret;
|
||||
return isOAuth && TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret);
|
||||
@NonNull final AccountDetails account) {
|
||||
return AccountDetailsExtensionsKt.isOfficial(account, context);
|
||||
}
|
||||
|
||||
public static boolean setLastSeen(Context context, ParcelableUserMention[] entities, long time) {
|
||||
@ -926,19 +913,14 @@ public final class Utils implements Constants {
|
||||
return plugged || level / scale > 0.15f;
|
||||
}
|
||||
|
||||
public static boolean isMyAccount(@NonNull final Context context, @Nullable final UserKey accountKey) {
|
||||
if (accountKey == null) return false;
|
||||
public static boolean isMyAccount(@NonNull final Context context, @NonNull final UserKey accountKey) {
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
return AccountUtils.findByAccountKey(am, accountKey) != null;
|
||||
}
|
||||
|
||||
public static boolean isMyAccount(final Context context, final String screenName) {
|
||||
for (ParcelableAccount account : ParcelableAccountUtils.getAccounts(context)) {
|
||||
if (StringUtils.equalsIgnoreCase(account.screen_name, screenName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public static boolean isMyAccount(@NonNull final Context context, @NonNull final String screenName) {
|
||||
final AccountManager am = AccountManager.get(context);
|
||||
return AccountUtils.findByScreenName(am, screenName) != null;
|
||||
}
|
||||
|
||||
public static boolean isMyRetweet(final ParcelableStatus status) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mariotaku.twidere.util.media;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@ -25,11 +26,12 @@ import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.restfu.oauth.OAuthAuthorization;
|
||||
import org.mariotaku.restfu.oauth.OAuthEndpoint;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.extension.CredentialsExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.CacheMetadata;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableMedia;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
import org.mariotaku.twidere.util.JsonSerializer;
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
@ -116,17 +118,19 @@ public class TwidereMediaDownloader implements MediaDownloader, Constants {
|
||||
@Nullable Object extra) throws IOException {
|
||||
final Uri uri = Uri.parse(url);
|
||||
Authorization auth = null;
|
||||
ParcelableCredentials account = null;
|
||||
AccountDetails account = null;
|
||||
boolean useThumbor = true;
|
||||
if (extra instanceof MediaExtra) {
|
||||
useThumbor = ((MediaExtra) extra).isUseThumbor();
|
||||
UserKey accountKey = ((MediaExtra) extra).getAccountKey();
|
||||
if (accountKey != null) {
|
||||
account = ParcelableCredentialsUtils.getCredentials(mContext, accountKey);
|
||||
auth = MicroBlogAPIFactory.getAuthorization(account);
|
||||
account = AccountUtils.getAccountDetails(AccountManager.get(mContext), accountKey);
|
||||
if (account != null) {
|
||||
auth = CredentialsExtensionsKt.getAuthorization(account.credentials);
|
||||
}
|
||||
}
|
||||
}
|
||||
final Uri modifiedUri = getReplacedUri(uri, account != null ? account.api_url_format : null);
|
||||
final Uri modifiedUri = getReplacedUri(uri, account != null ? account.credentials.api_url_format : null);
|
||||
final MultiValueMap<String> additionalHeaders = new MultiValueMap<>();
|
||||
additionalHeaders.add("User-Agent", mUserAgent);
|
||||
final String method = GET.METHOD;
|
||||
@ -189,10 +193,10 @@ public class TwidereMediaDownloader implements MediaDownloader, Constants {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean isAuthRequired(final Uri uri, @Nullable final ParcelableCredentials credentials) {
|
||||
if (credentials == null) return false;
|
||||
private boolean isAuthRequired(final Uri uri, @Nullable final AccountDetails details) {
|
||||
if (details == null) return false;
|
||||
final String host = uri.getHost();
|
||||
if (credentials.api_url_format != null && credentials.api_url_format.contains(host)) {
|
||||
if (details.credentials.api_url_format != null && details.credentials.api_url_format.contains(host)) {
|
||||
return true;
|
||||
}
|
||||
return "ton.twitter.com".equalsIgnoreCase(host);
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.mariotaku.twidere.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.*
|
||||
@ -77,8 +78,7 @@ import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableLocationUtils
|
||||
import org.mariotaku.twidere.preference.ServicePickerPreference
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts
|
||||
@ -429,11 +429,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
displayNewDraftNotification(text, draftUri)
|
||||
}
|
||||
|
||||
fun setSelectedAccounts(vararg accounts: ParcelableAccount) {
|
||||
fun setSelectedAccounts(vararg accounts: AccountDetails) {
|
||||
if (accounts.size == 1) {
|
||||
accountsCount.setText(null)
|
||||
val account = accounts[0]
|
||||
mediaLoader.displayProfileImage(accountProfileImage, account)
|
||||
mediaLoader.displayProfileImage(accountProfileImage, account.user)
|
||||
accountProfileImage.setBorderColor(account.color)
|
||||
} else {
|
||||
accountsCount.setText(accounts.size.toString())
|
||||
@ -456,7 +456,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
mNameFirst = preferences.getBoolean(KEY_NAME_FIRST)
|
||||
setContentView(R.layout.activity_compose)
|
||||
setFinishOnTouchOutside(false)
|
||||
val accounts = ParcelableCredentialsUtils.getCredentialses(this, false, false)
|
||||
val accounts = AccountUtils.getAllAccountDetails(AccountManager.get(this))
|
||||
if (accounts.isEmpty()) {
|
||||
val intent = Intent(INTENT_ACTION_TWITTER_LOGIN)
|
||||
intent.setClass(this, SignInActivity::class.java)
|
||||
@ -464,7 +464,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val defaultAccountIds = accounts.map { it.account_key }.toTypedArray()
|
||||
val defaultAccountIds = accounts.map { it.key }.toTypedArray()
|
||||
menuBar.setOnMenuItemClickListener(this)
|
||||
setupEditText()
|
||||
accountSelectorContainer.setOnClickListener(this)
|
||||
@ -524,7 +524,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
accountSelector.itemAnimator = DefaultItemAnimator()
|
||||
accountsAdapter = AccountIconsAdapter(this)
|
||||
accountSelector.adapter = accountsAdapter
|
||||
accountsAdapter!!.setAccounts(accounts.toTypedArray())
|
||||
accountsAdapter!!.setAccounts(accounts)
|
||||
|
||||
|
||||
val adapter = MediaPreviewAdapter(this, PreviewGridOnStartDragListener(this))
|
||||
@ -971,7 +971,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
|
||||
private fun handleReplyIntent(status: ParcelableStatus?): Boolean {
|
||||
if (status == null) return false
|
||||
val account = ParcelableAccountUtils.getAccount(this, status.account_key) ?: return false
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(this), status.account_key) ?: return false
|
||||
var selectionStart = 0
|
||||
val mentions = TreeSet(String.CASE_INSENSITIVE_ORDER)
|
||||
editText.append("@" + status.user_screen_name + " ")
|
||||
@ -1006,7 +1006,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
}
|
||||
|
||||
for (mention in mentions) {
|
||||
if (mention.equals(status.user_screen_name, ignoreCase = true) || mention.equals(account.screen_name, ignoreCase = true)) {
|
||||
if (mention.equals(status.user_screen_name, ignoreCase = true) || mention.equals(account.user.screen_name, ignoreCase = true)) {
|
||||
continue
|
||||
}
|
||||
editText.append("@$mention ")
|
||||
@ -1075,7 +1075,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
if (ArrayUtils.isEmpty(accounts)) {
|
||||
editText.accountKey = Utils.getDefaultAccountKey(this)
|
||||
} else {
|
||||
editText.accountKey = accounts[0].account_key
|
||||
editText.accountKey = accounts[0].key
|
||||
}
|
||||
statusTextCount.maxLength = TwidereValidator.getTextLimit(accounts)
|
||||
setMenu()
|
||||
@ -1121,12 +1121,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
get() {
|
||||
val accounts = accountsAdapter!!.selectedAccounts
|
||||
if (ArrayUtils.isEmpty(accounts)) return false
|
||||
for (account in accounts) {
|
||||
if (TwitterContentUtils.getOfficialKeyType(this, account.consumer_key, account.consumer_secret) != ConsumerKeyType.TWEETDECK) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun setProgressVisible(visible: Boolean) {
|
||||
@ -1280,7 +1275,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
} else {
|
||||
action = getDraftAction(intent.action)
|
||||
}
|
||||
update.accounts = ParcelableAccountUtils.getAccounts(this, *accountKeys)
|
||||
update.accounts = AccountUtils.getAllAccountDetails(AccountManager.get(this), accountKeys)
|
||||
update.text = text
|
||||
if (attachLocation) {
|
||||
update.location = recentLocation
|
||||
@ -1362,16 +1357,16 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
itemView.setOnClickListener(this)
|
||||
}
|
||||
|
||||
fun showAccount(adapter: AccountIconsAdapter, account: ParcelableAccount, isSelected: Boolean) {
|
||||
fun showAccount(adapter: AccountIconsAdapter, account: AccountDetails, isSelected: Boolean) {
|
||||
itemView.alpha = if (isSelected) 1f else 0.33f
|
||||
(itemView as CheckableLinearLayout).isChecked = isSelected
|
||||
val loader = adapter.imageLoader
|
||||
if (ObjectUtils.notEqual(account, iconView.tag) || iconView.drawable == null) {
|
||||
iconView.tag = account
|
||||
loader.displayProfileImage(iconView, account)
|
||||
loader.displayProfileImage(iconView, account.user)
|
||||
}
|
||||
iconView.setBorderColor(account.color)
|
||||
nameView.text = if (adapter.isNameFirst) account.name else "@" + account.screen_name
|
||||
nameView.text = if (adapter.isNameFirst) account.user.name else "@" + account.user.screen_name
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
@ -1387,7 +1382,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
private val selection: MutableMap<UserKey, Boolean>
|
||||
val isNameFirst: Boolean
|
||||
|
||||
private var accounts: Array<ParcelableCredentials>? = null
|
||||
private var accounts: Array<AccountDetails>? = null
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
@ -1406,8 +1401,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
val selectedAccountKeys: Array<UserKey>
|
||||
get() {
|
||||
val accounts = accounts ?: return emptyArray()
|
||||
return accounts.filter { selection[it.account_key] ?: false }
|
||||
.map { it.account_key!! }
|
||||
return accounts.filter { selection[it.key] ?: false }
|
||||
.map { it.key }
|
||||
.toTypedArray()
|
||||
}
|
||||
|
||||
@ -1419,10 +1414,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
val selectedAccounts: Array<ParcelableCredentials>
|
||||
val selectedAccounts: Array<AccountDetails>
|
||||
get() {
|
||||
val accounts = accounts ?: return emptyArray()
|
||||
return accounts.filter { selection[it.account_key] ?: false }.toTypedArray()
|
||||
return accounts.filter { selection[it.key] ?: false }.toTypedArray()
|
||||
}
|
||||
|
||||
val isSelectionEmpty: Boolean
|
||||
@ -1435,7 +1430,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
|
||||
override fun onBindViewHolder(holder: AccountIconViewHolder, position: Int) {
|
||||
val account = accounts!![position]
|
||||
val isSelected = selection[account.account_key] ?: false
|
||||
val isSelected = selection[account.key] ?: false
|
||||
holder.showAccount(this, account, isSelected)
|
||||
}
|
||||
|
||||
@ -1443,7 +1438,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
return if (accounts != null) accounts!!.size else 0
|
||||
}
|
||||
|
||||
fun setAccounts(accounts: Array<ParcelableCredentials>) {
|
||||
fun setAccounts(accounts: Array<AccountDetails>) {
|
||||
this.accounts = accounts
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@ -1451,7 +1446,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
internal fun toggleSelection(position: Int) {
|
||||
if (accounts == null || position < 0) return
|
||||
val account = accounts!![position]
|
||||
selection.put(account.account_key, java.lang.Boolean.TRUE != selection[account.account_key])
|
||||
selection.put(account.key, true != selection[account.key])
|
||||
activity.notifyAccountSelectionChanged()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.activity
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.graphics.PorterDuff.Mode
|
||||
@ -49,7 +50,7 @@ import org.mariotaku.twidere.constant.KeyboardShortcutConstants.CONTEXT_TAG_NAVI
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NEW_DOCUMENT_API
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Suggestions
|
||||
import org.mariotaku.twidere.util.*
|
||||
@ -166,7 +167,8 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_quick_search_bar)
|
||||
val accounts = ParcelableCredentialsUtils.getCredentialses(this, false, false)
|
||||
val am = AccountManager.get(this)
|
||||
val accounts = AccountUtils.getAllAccountDetails(am, AccountUtils.getAccounts(am)).toList()
|
||||
val accountsSpinnerAdapter = AccountsSpinnerAdapter(this, R.layout.spinner_item_account_icon)
|
||||
accountsSpinnerAdapter.setDropDownViewResource(R.layout.list_item_simple_user)
|
||||
accountsSpinnerAdapter.addAll(accounts)
|
||||
|
@ -68,9 +68,9 @@ import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.iface.APIEditorActivity
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials.AuthTypeInt
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.SingleResponse
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
@ -80,7 +80,10 @@ import org.mariotaku.twidere.model.account.cred.BasicCredentials
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials
|
||||
import org.mariotaku.twidere.model.account.cred.EmptyCredentials
|
||||
import org.mariotaku.twidere.model.account.cred.OAuthCredentials
|
||||
import org.mariotaku.twidere.model.util.*
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.*
|
||||
@ -558,7 +561,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
|
||||
val userId = apiUser.id!!
|
||||
val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser))
|
||||
val user = ParcelableUserUtils.fromUser(apiUser, accountKey)
|
||||
val account = ParcelableAccountUtils.getAccount(context, accountKey)
|
||||
val account = AccountUtils.getAccount(AccountManager.get(context), accountKey)
|
||||
if (account != null) {
|
||||
color = account.color
|
||||
}
|
||||
@ -854,7 +857,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
|
||||
val accountType = SignInActivity.detectAccountType(twitter, apiUser)
|
||||
val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser))
|
||||
val user = ParcelableUserUtils.fromUser(apiUser, accountKey)
|
||||
val account = ParcelableAccountUtils.getAccount(activity, accountKey)
|
||||
val account = AccountUtils.getAccount(AccountManager.get(activity), accountKey)
|
||||
if (account != null) {
|
||||
color = account.color
|
||||
}
|
||||
@ -882,7 +885,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
|
||||
val accountType = SignInActivity.detectAccountType(twitter, apiUser)
|
||||
val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser))
|
||||
val user = ParcelableUserUtils.fromUser(apiUser, accountKey)
|
||||
val account = ParcelableAccountUtils.getAccount(activity, accountKey)
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(activity), accountKey)
|
||||
if (account != null) {
|
||||
color = account.color
|
||||
}
|
||||
@ -908,7 +911,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
|
||||
val accountType = SignInActivity.detectAccountType(twitter, apiUser)
|
||||
val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser))
|
||||
val user = ParcelableUserUtils.fromUser(apiUser, accountKey)
|
||||
val account = ParcelableAccountUtils.getAccount(activity, accountKey)
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(activity), accountKey)
|
||||
if (account != null) {
|
||||
color = account.color
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.BaseActivity
|
||||
import org.mariotaku.twidere.adapter.ArrayAdapter
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.model.CustomAPIConfig
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
@ -66,12 +67,12 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
||||
|
||||
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
||||
val authType = getCheckedAuthType(checkedId)
|
||||
val isOAuth = authType == ParcelableCredentials.AuthTypeInt.OAUTH || authType == ParcelableCredentials.AuthTypeInt.XAUTH
|
||||
val isOAuth = authType == AuthTypeInt.OAUTH || authType == AuthTypeInt.XAUTH
|
||||
editSameOAuthSigningUrl.visibility = if (isOAuth) View.VISIBLE else View.GONE
|
||||
editConsumerKey.visibility = if (isOAuth) View.VISIBLE else View.GONE
|
||||
editConsumerSecret.visibility = if (isOAuth) View.VISIBLE else View.GONE
|
||||
if (!editNoVersionSuffixChanged) {
|
||||
editNoVersionSuffix.isChecked = authType == ParcelableCredentials.AuthTypeInt.TWIP_O_MODE
|
||||
editNoVersionSuffix.isChecked = authType == AuthTypeInt.TWIP_O_MODE
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +154,7 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
||||
|
||||
val pref = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
val prefApiUrlFormat = Utils.getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT)
|
||||
val prefAuthType = pref.getInt(KEY_AUTH_TYPE, ParcelableCredentials.AuthTypeInt.OAUTH)
|
||||
val prefAuthType = pref.getInt(KEY_AUTH_TYPE, AuthTypeInt.OAUTH)
|
||||
val prefSameOAuthSigningUrl = pref.getBoolean(KEY_SAME_OAUTH_SIGNING_URL, false)
|
||||
val prefNoVersionSuffix = pref.getBoolean(KEY_NO_VERSION_SUFFIX, false)
|
||||
val prefConsumerKey = Utils.getNonEmptyString(pref, KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY)
|
||||
@ -187,10 +188,10 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
||||
editConsumerKey.setText(consumerKey)
|
||||
editConsumerSecret.setText(consumerSecret)
|
||||
|
||||
oauth.isChecked = authType == ParcelableCredentials.AuthTypeInt.OAUTH
|
||||
xauth.isChecked = authType == ParcelableCredentials.AuthTypeInt.XAUTH
|
||||
basic.isChecked = authType == ParcelableCredentials.AuthTypeInt.BASIC
|
||||
twipO.isChecked = authType == ParcelableCredentials.AuthTypeInt.TWIP_O_MODE
|
||||
oauth.isChecked = authType == AuthTypeInt.OAUTH
|
||||
xauth.isChecked = authType == AuthTypeInt.XAUTH
|
||||
basic.isChecked = authType == AuthTypeInt.BASIC
|
||||
twipO.isChecked = authType == AuthTypeInt.TWIP_O_MODE
|
||||
if (editAuthType.checkedRadioButtonId == -1) {
|
||||
oauth.isChecked = true
|
||||
}
|
||||
@ -199,13 +200,13 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
||||
|
||||
private fun getAuthTypeId(authType: Int): Int {
|
||||
when (authType) {
|
||||
ParcelableCredentials.AuthTypeInt.XAUTH -> {
|
||||
AuthTypeInt.XAUTH -> {
|
||||
return R.id.xauth
|
||||
}
|
||||
ParcelableCredentials.AuthTypeInt.BASIC -> {
|
||||
AuthTypeInt.BASIC -> {
|
||||
return R.id.basic
|
||||
}
|
||||
ParcelableCredentials.AuthTypeInt.TWIP_O_MODE -> {
|
||||
AuthTypeInt.TWIP_O_MODE -> {
|
||||
return R.id.twipO
|
||||
}
|
||||
else -> {
|
||||
@ -310,16 +311,16 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
||||
fun getCheckedAuthType(checkedId: Int): Int {
|
||||
when (checkedId) {
|
||||
R.id.xauth -> {
|
||||
return ParcelableCredentials.AuthTypeInt.XAUTH
|
||||
return AuthTypeInt.XAUTH
|
||||
}
|
||||
R.id.basic -> {
|
||||
return ParcelableCredentials.AuthTypeInt.BASIC
|
||||
return AuthTypeInt.BASIC
|
||||
}
|
||||
R.id.twipO -> {
|
||||
return ParcelableCredentials.AuthTypeInt.TWIP_O_MODE
|
||||
return AuthTypeInt.TWIP_O_MODE
|
||||
}
|
||||
else -> {
|
||||
return ParcelableCredentials.AuthTypeInt.OAUTH
|
||||
return AuthTypeInt.OAUTH
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IBaseAdapter
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
@ -69,7 +70,7 @@ class AccountDetailsAdapter(context: Context) : ArrayAdapter<AccountDetails>(con
|
||||
mediaLoader.cancelDisplayTask(holder.profileImage)
|
||||
}
|
||||
val accountType = details.type
|
||||
holder.accountType.setImageResource(ParcelableAccountUtils.getAccountTypeIcon(accountType))
|
||||
holder.accountType.setImageResource(AccountUtils.getAccountTypeIcon(accountType))
|
||||
holder.toggle.isChecked = details.activated
|
||||
holder.toggle.setOnCheckedChangeListener(checkedChangeListener)
|
||||
holder.toggle.tag = details.user.key
|
||||
|
@ -24,18 +24,19 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
class AccountsSpinnerAdapter @JvmOverloads constructor(context: Context, itemViewResource: Int = R.layout.list_item_simple_user) : ArrayAdapter<ParcelableCredentials>(context, itemViewResource) {
|
||||
class AccountsSpinnerAdapter(
|
||||
context: Context,
|
||||
itemViewResource: Int = R.layout.list_item_simple_user
|
||||
) : ArrayAdapter<AccountDetails>(context, itemViewResource) {
|
||||
|
||||
@Inject
|
||||
lateinit var mediaLoader: MediaLoaderWrapper
|
||||
@ -48,7 +49,7 @@ class AccountsSpinnerAdapter @JvmOverloads constructor(context: Context, itemVie
|
||||
Context.MODE_PRIVATE).getBoolean(SharedPreferenceConstants.KEY_DISPLAY_PROFILE_IMAGE, true)
|
||||
}
|
||||
|
||||
constructor(context: Context, accounts: Collection<ParcelableCredentials>) : this(context) {
|
||||
constructor(context: Context, accounts: Collection<AccountDetails>) : this(context) {
|
||||
addAll(accounts)
|
||||
}
|
||||
|
||||
@ -68,23 +69,23 @@ class AccountsSpinnerAdapter @JvmOverloads constructor(context: Context, itemVie
|
||||
return view
|
||||
}
|
||||
|
||||
private fun bindView(view: View, item: ParcelableCredentials) {
|
||||
private fun bindView(view: View, item: AccountDetails) {
|
||||
val text1 = view.findViewById(android.R.id.text1) as TextView?
|
||||
val text2 = view.findViewById(android.R.id.text2) as TextView?
|
||||
val icon = view.findViewById(android.R.id.icon) as ImageView?
|
||||
if (!item.is_dummy) {
|
||||
if (!item.dummy) {
|
||||
if (text1 != null) {
|
||||
text1.visibility = View.VISIBLE
|
||||
text1.text = item.name
|
||||
text1.text = item.user.name
|
||||
}
|
||||
if (text2 != null) {
|
||||
text2.visibility = View.VISIBLE
|
||||
text2.text = String.format("@%s", item.screen_name)
|
||||
text2.text = String.format("@%s", item.user.screen_name)
|
||||
}
|
||||
if (icon != null) {
|
||||
icon.visibility = View.VISIBLE
|
||||
if (displayProfileImage) {
|
||||
mediaLoader.displayProfileImage(icon, item)
|
||||
mediaLoader.displayProfileImage(icon, item.user)
|
||||
} else {
|
||||
mediaLoader.cancelDisplayTask(icon)
|
||||
// icon.setImageResource(R.drawable.ic_profile_image_default);
|
||||
@ -115,12 +116,7 @@ class AccountsSpinnerAdapter @JvmOverloads constructor(context: Context, itemVie
|
||||
}
|
||||
|
||||
fun findPositionByKey(key: UserKey): Int {
|
||||
for (i in 0 until count) {
|
||||
if (key == getItem(i).account_key) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
return (0 until count).indexOfFirst { key == getItem(it).key }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.os.Build
|
||||
import android.text.TextUtils
|
||||
import org.mariotaku.kpreferences.*
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt
|
||||
import org.mariotaku.twidere.extension.getNonEmptyString
|
||||
import org.mariotaku.twidere.model.CustomAPIConfig
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
@ -39,7 +40,7 @@ object defaultAPIConfigKey : KPreferenceKey<CustomAPIConfig> {
|
||||
|
||||
override fun read(preferences: SharedPreferences): CustomAPIConfig {
|
||||
val apiUrlFormat = preferences.getNonEmptyString(KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT)
|
||||
val authType = preferences.getInt(KEY_AUTH_TYPE, ParcelableCredentials.AuthTypeInt.OAUTH)
|
||||
val authType = preferences.getInt(KEY_AUTH_TYPE, AuthTypeInt.OAUTH)
|
||||
val sameOAuthSigningUrl = preferences.getBoolean(KEY_SAME_OAUTH_SIGNING_URL, false)
|
||||
val noVersionSuffix = preferences.getBoolean(KEY_NO_VERSION_SUFFIX, false)
|
||||
val consumerKey = preferences.getNonEmptyString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY).trim()
|
||||
|
@ -0,0 +1,20 @@
|
||||
package org.mariotaku.twidere.extension.model
|
||||
|
||||
import android.content.Context
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.account.TwitterAccountExtras
|
||||
import org.mariotaku.twidere.model.account.cred.OAuthCredentials
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils
|
||||
|
||||
fun AccountDetails.isOfficial(context: Context): Boolean {
|
||||
val extra = this.extras
|
||||
if (extra is TwitterAccountExtras) {
|
||||
return extra.isOfficialCredentials
|
||||
}
|
||||
val credentials = this.credentials
|
||||
if (credentials is OAuthCredentials) {
|
||||
return TwitterContentUtils.isOfficialKey(context,
|
||||
credentials.consumer_key, credentials.consumer_secret);
|
||||
}
|
||||
return false
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.animation.Animator
|
||||
import android.animation.Animator.AnimatorListener
|
||||
import android.animation.AnimatorSet
|
||||
@ -63,9 +64,10 @@ import org.mariotaku.twidere.annotation.Referral
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
||||
import org.mariotaku.twidere.fragment.AccountsDashboardFragment.AccountsInfo
|
||||
import org.mariotaku.twidere.menu.AccountToggleProvider
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.SupportTabSpec
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts
|
||||
@ -181,13 +183,13 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
R.id.profileContainer -> {
|
||||
val account = mAccountsAdapter!!.selectedAccount ?: return
|
||||
val activity = activity
|
||||
if (account.account_user != null) {
|
||||
IntentUtils.openUserProfile(activity, account.account_user!!, null,
|
||||
if (account.user != null) {
|
||||
IntentUtils.openUserProfile(activity, account.user!!, null,
|
||||
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
|
||||
Referral.SELF_PROFILE)
|
||||
} else {
|
||||
IntentUtils.openUserProfile(activity, account.account_key,
|
||||
account.account_key, account.screen_name, null,
|
||||
IntentUtils.openUserProfile(activity, account.key, account.key,
|
||||
account.user.screen_name, null,
|
||||
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
|
||||
Referral.SELF_PROFILE)
|
||||
}
|
||||
@ -207,7 +209,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
val menu = accountDashboardMenu.menu
|
||||
mAccountActionProvider = MenuItemCompat.getActionProvider(menu.findItem(R.id.select_account)) as AccountToggleProvider
|
||||
val accounts = data.accounts
|
||||
if (accounts.size > 0) {
|
||||
if (accounts.isNotEmpty()) {
|
||||
noAccountContainer.visibility = View.GONE
|
||||
profileContainer.visibility = View.VISIBLE
|
||||
} else {
|
||||
@ -216,8 +218,8 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
}
|
||||
var defaultId: UserKey? = null
|
||||
for (account in accounts) {
|
||||
if (account.is_activated) {
|
||||
defaultId = account.account_key
|
||||
if (account.activated) {
|
||||
defaultId = account.key
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -228,9 +230,9 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
if (accountKey == null) {
|
||||
accountKey = defaultId
|
||||
}
|
||||
var selectedAccount: ParcelableAccount? = null
|
||||
var selectedAccount: AccountDetails? = null
|
||||
for (account in accounts) {
|
||||
if (account.account_key.maybeEquals(accountKey)) {
|
||||
if (account.key.maybeEquals(accountKey)) {
|
||||
selectedAccount = account
|
||||
break
|
||||
}
|
||||
@ -294,7 +296,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
val account = mAccountsAdapter!!.selectedAccount ?: return@OnMenuItemClickListener true
|
||||
val composeIntent = Intent(INTENT_ACTION_COMPOSE)
|
||||
composeIntent.setClass(activity, ComposeActivity::class.java)
|
||||
composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key)
|
||||
composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.key)
|
||||
startActivity(composeIntent)
|
||||
return@OnMenuItemClickListener true
|
||||
}
|
||||
@ -304,11 +306,11 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
val accounts = mAccountActionProvider!!.accounts
|
||||
val account = accounts[item.order]
|
||||
val values = ContentValues()
|
||||
val newActivated = !account.is_activated
|
||||
mAccountActionProvider!!.setAccountActivated(account.account_key, newActivated)
|
||||
val newActivated = !account.activated
|
||||
mAccountActionProvider!!.setAccountActivated(account.key, newActivated)
|
||||
values.put(Accounts.IS_ACTIVATED, newActivated)
|
||||
val where = Expression.equalsArgs(Accounts.ACCOUNT_KEY).sql
|
||||
val whereArgs = arrayOf(account.account_key.toString())
|
||||
val whereArgs = arrayOf(account.key.toString())
|
||||
mResolver!!.update(Accounts.CONTENT_URI, values, where, whereArgs)
|
||||
true
|
||||
})
|
||||
@ -363,12 +365,12 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
when (tab.type) {
|
||||
CustomTabType.DIRECT_MESSAGES -> {
|
||||
if (!hasDmTab) {
|
||||
hasDmTab = hasAccountInTab(tab, account.account_key, account.is_activated)
|
||||
hasDmTab = hasAccountInTab(tab, account.key, account.activated)
|
||||
}
|
||||
}
|
||||
CustomTabType.NOTIFICATIONS_TIMELINE -> {
|
||||
if (!hasInteractionsTab) {
|
||||
hasInteractionsTab = hasAccountInTab(tab, account.account_key, account.is_activated)
|
||||
hasInteractionsTab = hasAccountInTab(tab, account.key, account.activated)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -387,7 +389,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
var hasLists = false
|
||||
var hasGroups = false
|
||||
var hasPublicTimeline = false
|
||||
when (ParcelableAccountUtils.getAccountType(account)) {
|
||||
when (AccountUtils.getAccountType(account)) {
|
||||
AccountType.TWITTER -> {
|
||||
hasLists = true
|
||||
}
|
||||
@ -422,7 +424,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
rectF.set(location[0].toFloat(), location[1].toFloat(), (location[0] + view.width).toFloat(), (location[1] + view.height).toFloat())
|
||||
}
|
||||
|
||||
private fun onAccountSelected(holder: AccountProfileImageViewHolder, account: ParcelableAccount) {
|
||||
private fun onAccountSelected(holder: AccountProfileImageViewHolder, account: AccountDetails) {
|
||||
if (mSwitchAccountAnimationPlaying) return
|
||||
val snapshotView = floatingProfileImageSnapshot
|
||||
val profileImageView = accountProfileImageView
|
||||
@ -495,7 +497,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
|
||||
private fun finishAnimation() {
|
||||
val editor = preferences.edit()
|
||||
editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString())
|
||||
editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.key.toString())
|
||||
editor.apply()
|
||||
mAccountsAdapter!!.selectedAccount = account
|
||||
updateAccountActions()
|
||||
@ -515,7 +517,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
|
||||
}
|
||||
|
||||
protected fun displayAccountBanner(account: ParcelableAccount) {
|
||||
protected fun displayAccountBanner(account: AccountDetails) {
|
||||
val bannerWidth = accountProfileBanner.width
|
||||
val res = resources
|
||||
val defWidth = res.displayMetrics.widthPixels
|
||||
@ -531,8 +533,8 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
|
||||
private fun displayCurrentAccount(profileImageSnapshot: Drawable?) {
|
||||
val account = mAccountsAdapter!!.selectedAccount ?: return
|
||||
accountProfileNameView.text = account.name
|
||||
accountProfileScreenNameView.text = String.format("@%s", account.screen_name)
|
||||
accountProfileNameView.text = account.user.name
|
||||
accountProfileScreenNameView.text = String.format("@%s", account.user.screen_name)
|
||||
mediaLoader.displayDashboardProfileImage(accountProfileImageView, account,
|
||||
profileImageSnapshot)
|
||||
accountProfileImageView.setBorderColors(account.color)
|
||||
@ -547,39 +549,39 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
when (item.itemId) {
|
||||
R.id.search -> {
|
||||
val intent = Intent(activity, QuickSearchBarActivity::class.java)
|
||||
intent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key)
|
||||
intent.putExtra(EXTRA_ACCOUNT_KEY, account.key)
|
||||
startActivity(intent)
|
||||
closeAccountsDrawer()
|
||||
}
|
||||
R.id.compose -> {
|
||||
val composeIntent = Intent(INTENT_ACTION_COMPOSE)
|
||||
composeIntent.setClass(activity, ComposeActivity::class.java)
|
||||
composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.account_key)
|
||||
composeIntent.putExtra(EXTRA_ACCOUNT_KEY, account.key)
|
||||
startActivity(composeIntent)
|
||||
}
|
||||
R.id.favorites -> {
|
||||
IntentUtils.openUserFavorites(activity, account.account_key,
|
||||
account.account_key, account.screen_name)
|
||||
IntentUtils.openUserFavorites(activity, account.key,
|
||||
account.key, account.user.screen_name)
|
||||
}
|
||||
R.id.lists -> {
|
||||
IntentUtils.openUserLists(activity, account.account_key,
|
||||
account.account_key, account.screen_name)
|
||||
IntentUtils.openUserLists(activity, account.key,
|
||||
account.key, account.user.screen_name)
|
||||
}
|
||||
R.id.groups -> {
|
||||
IntentUtils.openUserGroups(activity, account.account_key,
|
||||
account.account_key, account.screen_name)
|
||||
IntentUtils.openUserGroups(activity, account.key,
|
||||
account.key, account.user.screen_name)
|
||||
}
|
||||
R.id.public_timeline -> {
|
||||
IntentUtils.openPublicTimeline(activity, account.account_key)
|
||||
IntentUtils.openPublicTimeline(activity, account.key)
|
||||
}
|
||||
R.id.messages -> {
|
||||
IntentUtils.openDirectMessages(activity, account.account_key)
|
||||
IntentUtils.openDirectMessages(activity, account.key)
|
||||
}
|
||||
R.id.interactions -> {
|
||||
IntentUtils.openInteractions(activity, account.account_key)
|
||||
IntentUtils.openInteractions(activity, account.key)
|
||||
}
|
||||
R.id.edit -> {
|
||||
IntentUtils.openProfileEditor(activity, account.account_key)
|
||||
IntentUtils.openProfileEditor(activity, account.key)
|
||||
}
|
||||
R.id.accounts -> {
|
||||
IntentUtils.openAccountsManager(activity)
|
||||
@ -631,13 +633,13 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
private val fragment: AccountsDashboardFragment
|
||||
) : Adapter<AccountProfileImageViewHolder>() {
|
||||
private val mediaLoader: MediaLoaderWrapper
|
||||
var accounts: Array<ParcelableAccount>? = null
|
||||
var accounts: Array<AccountDetails>? = null
|
||||
set(value) {
|
||||
if (value != null) {
|
||||
val previousAccounts = accounts
|
||||
if (previousAccounts != null) {
|
||||
val tmpList = arrayListOf(*value)
|
||||
val tmpResult = ArrayList<ParcelableAccount>()
|
||||
val tmpResult = ArrayList<AccountDetails>()
|
||||
previousAccounts.forEach { previousAccount ->
|
||||
val prefIndexOfTmp = tmpList.indexOfFirst { previousAccount == it }
|
||||
if (prefIndexOfTmp >= 0) {
|
||||
@ -660,16 +662,16 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
setHasStableIds(true)
|
||||
}
|
||||
|
||||
fun getAdapterAccount(adapterPosition: Int): ParcelableAccount? {
|
||||
if (accounts == null || accounts!!.size < 1) {
|
||||
fun getAdapterAccount(adapterPosition: Int): AccountDetails? {
|
||||
if (accounts == null || accounts!!.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return accounts!![adapterPosition + 1]
|
||||
}
|
||||
|
||||
var selectedAccount: ParcelableAccount?
|
||||
var selectedAccount: AccountDetails?
|
||||
get() {
|
||||
if (accounts == null || accounts!!.size == 0) {
|
||||
if (accounts == null || accounts!!.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
return accounts!![0]
|
||||
@ -683,7 +685,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
val selectedAccountKey: UserKey?
|
||||
get() {
|
||||
val selectedAccount = selectedAccount ?: return null
|
||||
return selectedAccount.account_key
|
||||
return selectedAccount.key
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccountProfileImageViewHolder {
|
||||
@ -702,7 +704,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
if (accounts == null || accounts!!.size == 0) return 0
|
||||
if (accounts == null || accounts!!.isEmpty()) return 0
|
||||
return accounts!!.size - 1
|
||||
}
|
||||
|
||||
@ -710,7 +712,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
fragment.onAccountSelected(holder, getAdapterAccount(holder.adapterPosition)!!)
|
||||
}
|
||||
|
||||
private fun swap(from: ParcelableAccount, to: ParcelableAccount) {
|
||||
private fun swap(from: AccountDetails, to: AccountDetails) {
|
||||
val accounts = accounts ?: return
|
||||
val fromIdx = accounts.indexOfFirst { it == from }
|
||||
val toIdx = accounts.indexOfFirst { it == to }
|
||||
@ -723,7 +725,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
}
|
||||
|
||||
data class AccountsInfo(
|
||||
val accounts: Array<ParcelableAccount>,
|
||||
val accounts: Array<AccountDetails>,
|
||||
val draftsCount: Int
|
||||
)
|
||||
|
||||
@ -737,7 +739,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
}
|
||||
|
||||
override fun loadInBackground(): AccountsInfo {
|
||||
val accounts = ParcelableAccountUtils.getAccounts(context)
|
||||
val accounts = AccountUtils.getAllAccountDetails(AccountManager.get(context))
|
||||
val draftsCount = DataStoreUtils.queryCount(context, Drafts.CONTENT_URI_UNSENT, null, null)
|
||||
return AccountsInfo(accounts, draftsCount)
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ContentValues
|
||||
@ -55,14 +56,12 @@ import org.mariotaku.twidere.activity.SettingsActivity
|
||||
import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter
|
||||
import org.mariotaku.twidere.adapter.ArrayAdapter
|
||||
import org.mariotaku.twidere.annotation.CustomTabType
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.Tab
|
||||
import org.mariotaku.twidere.model.TabCursorIndices
|
||||
import org.mariotaku.twidere.model.TabValuesCreator
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.tab.DrawableHolder
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration
|
||||
import org.mariotaku.twidere.model.tab.iface.AccountCallback
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Tabs
|
||||
import org.mariotaku.twidere.util.CustomTabUtils
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
@ -324,10 +323,15 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
||||
val accountIdRequired = conf.accountFlags and TabConfiguration.FLAG_ACCOUNT_REQUIRED != 0
|
||||
accountsAdapter.clear()
|
||||
if (!accountIdRequired) {
|
||||
accountsAdapter.add(ParcelableAccount.dummyCredentials())
|
||||
accountsAdapter.add(AccountDetails.dummy())
|
||||
}
|
||||
val officialKeyOnly = arguments.getBoolean(EXTRA_OFFICIAL_KEY_ONLY, false)
|
||||
accountsAdapter.addAll(ParcelableCredentialsUtils.getCredentialses(context, false, officialKeyOnly))
|
||||
accountsAdapter.addAll(AccountUtils.getAllAccountDetails(AccountManager.get(context)).filter {
|
||||
if (officialKeyOnly && !it.isOfficial(context)) {
|
||||
return@filter false
|
||||
}
|
||||
return@filter true
|
||||
})
|
||||
accountsAdapter.setDummyItemText(R.string.activated_accounts)
|
||||
|
||||
tab.arguments?.accountKeys?.firstOrNull()?.let { key ->
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
@ -69,7 +70,7 @@ import org.mariotaku.twidere.constant.SharedPreferenceConstants
|
||||
import org.mariotaku.twidere.loader.UserSearchLoader
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.message.TaskStateChangedEvent
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages
|
||||
@ -127,7 +128,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
private var navigateBackPressed: Boolean = false
|
||||
private var loaderInitialized: Boolean = false
|
||||
private var imageUri: String? = null
|
||||
private var account: ParcelableCredentials? = null
|
||||
private var account: AccountDetails? = null
|
||||
private var recipient: ParcelableUser? = null
|
||||
private var textChanged: Boolean = false
|
||||
private var queryTextChanged: Boolean = false
|
||||
@ -169,7 +170,8 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||
ActionBar.DISPLAY_SHOW_TITLE or ActionBar.DISPLAY_SHOW_CUSTOM)
|
||||
actionBar.setCustomView(R.layout.layout_actionbar_message_user_picker)
|
||||
val accounts = ParcelableCredentialsUtils.getCredentialses(activity, false, false)
|
||||
val am = AccountManager.get(context)
|
||||
val accounts = AccountUtils.getAllAccountDetails(am, AccountUtils.getAccounts(am)).asList()
|
||||
val accountsSpinnerAdapter = AccountsSpinnerAdapter(
|
||||
actionBar.themedContext, R.layout.spinner_item_account_icon)
|
||||
accountsSpinnerAdapter.setDropDownViewResource(R.layout.list_item_simple_user)
|
||||
@ -203,7 +205,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
usersSearchList.adapter = usersSearchAdapter
|
||||
usersSearchList.emptyView = usersSearchEmpty
|
||||
usersSearchList.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
||||
val account = actionBarCustomView.accountSpinner.selectedItem as ParcelableCredentials
|
||||
val account = actionBarCustomView.accountSpinner.selectedItem as AccountDetails
|
||||
showConversation(account, usersSearchAdapter!!.getItem(position))
|
||||
updateRecipientInfo()
|
||||
}
|
||||
@ -215,18 +217,18 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
addImage.setOnClickListener(this)
|
||||
sendMessage.isEnabled = false
|
||||
if (savedInstanceState != null) {
|
||||
val account = savedInstanceState.getParcelable<ParcelableCredentials>(EXTRA_ACCOUNT)
|
||||
val recipient = savedInstanceState.getParcelable<ParcelableUser>(EXTRA_USER)
|
||||
val account: AccountDetails = savedInstanceState.getParcelable(EXTRA_ACCOUNT)
|
||||
val recipient: ParcelableUser = savedInstanceState.getParcelable(EXTRA_USER)
|
||||
showConversation(account, recipient)
|
||||
editText.setText(savedInstanceState.getString(EXTRA_TEXT))
|
||||
imageUri = savedInstanceState.getString(EXTRA_IMAGE_URI)
|
||||
} else {
|
||||
val args = arguments
|
||||
val account: ParcelableCredentials?
|
||||
val account: AccountDetails?
|
||||
val recipient: ParcelableUser?
|
||||
if (args != null) {
|
||||
if (args.containsKey(EXTRA_ACCOUNT)) {
|
||||
account = args.getParcelable<ParcelableCredentials>(EXTRA_ACCOUNT)
|
||||
account = args.getParcelable(EXTRA_ACCOUNT)
|
||||
recipient = args.getParcelable<ParcelableUser>(EXTRA_USER)
|
||||
} else if (args.containsKey(EXTRA_ACCOUNT_KEY) && args.containsKey(EXTRA_RECIPIENT_ID)) {
|
||||
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
@ -242,7 +244,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
if (accountPos >= 0) {
|
||||
account = accountsSpinnerAdapter.getItem(accountPos)
|
||||
} else {
|
||||
account = ParcelableCredentialsUtils.getCredentials(activity, accountKey)
|
||||
account = AccountUtils.getAccountDetails(AccountManager.get(activity), accountKey)
|
||||
}
|
||||
if (userId != null) {
|
||||
recipient = Utils.getUserForConversation(activity, accountKey, userId)
|
||||
@ -255,7 +257,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
}
|
||||
showConversation(account, recipient)
|
||||
if (account != null && recipient != null) {
|
||||
val key = getDraftsTextKey(account.account_key, recipient.key)
|
||||
val key = getDraftsTextKey(account.key, recipient.key)
|
||||
editText.setText(messageDrafts!!.getString(key, null))
|
||||
}
|
||||
}
|
||||
@ -304,7 +306,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
val account = account
|
||||
val recipient = recipient
|
||||
if (account != null && recipient != null) {
|
||||
val key = getDraftsTextKey(account.account_key, recipient.key)
|
||||
val key = getDraftsTextKey(account.key, recipient.key)
|
||||
val editor = messageDrafts!!.edit()
|
||||
val text = ParseUtils.parseString(editText.text)
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
@ -375,7 +377,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) {
|
||||
val account = actionBarCustomView.accountSpinner.selectedItem as ParcelableCredentials?
|
||||
val account = actionBarCustomView.accountSpinner.selectedItem as AccountDetails?
|
||||
if (account != null) {
|
||||
this.account = account
|
||||
updateRecipientInfo()
|
||||
@ -462,13 +464,13 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
}
|
||||
|
||||
|
||||
fun showConversation(account: ParcelableCredentials?, recipient: ParcelableUser?) {
|
||||
fun showConversation(account: AccountDetails?, recipient: ParcelableUser?) {
|
||||
this.account = account
|
||||
this.recipient = recipient
|
||||
if (account == null || recipient == null) return
|
||||
val lm = loaderManager
|
||||
val args = Bundle()
|
||||
args.putParcelable(EXTRA_ACCOUNT_KEY, account.account_key)
|
||||
args.putParcelable(EXTRA_ACCOUNT_KEY, account.key)
|
||||
args.putString(EXTRA_RECIPIENT_ID, recipient.key.id)
|
||||
if (loaderInitialized) {
|
||||
lm.restartLoader(0, args, this)
|
||||
@ -548,7 +550,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
if (TextUtils.isEmpty(message)) {
|
||||
editText.error = getString(R.string.error_message_no_content)
|
||||
} else {
|
||||
twitterWrapper.sendDirectMessageAsync(account.account_key, recipient.key.id,
|
||||
twitterWrapper.sendDirectMessageAsync(account.key, recipient.key.id,
|
||||
message, imageUri)
|
||||
editText.text = null
|
||||
imageUri = null
|
||||
@ -799,7 +801,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
}
|
||||
}
|
||||
|
||||
class SetReadStateTask(private val context: Context, private val account: ParcelableCredentials, private val recipient: ParcelableUser) : AsyncTask<Any, Any, Cursor>() {
|
||||
class SetReadStateTask(private val context: Context, private val account: AccountDetails, private val recipient: ParcelableUser) : AsyncTask<Any, Any, Cursor>() {
|
||||
|
||||
@Inject
|
||||
lateinit var readStateManager: ReadStateManager
|
||||
@ -814,7 +816,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
val selection = Expression.and(
|
||||
Expression.equalsArgs(ConversationEntries.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(ConversationEntries.CONVERSATION_ID)).sql
|
||||
val selectionArgs = arrayOf(account.account_key.toString(), recipient.key.toString())
|
||||
val selectionArgs = arrayOf(account.key.toString(), recipient.key.toString())
|
||||
val orderBy = OrderBy(ConversationEntries.MESSAGE_ID, false).sql
|
||||
return resolver.query(ConversationEntries.CONTENT_URI, projection, selection,
|
||||
selectionArgs, orderBy)
|
||||
@ -823,7 +825,7 @@ class MessagesConversationFragment : BaseSupportFragment(), LoaderCallbacks<Curs
|
||||
override fun onPostExecute(cursor: Cursor) {
|
||||
if (cursor.moveToFirst()) {
|
||||
val messageIdIdx = cursor.getColumnIndex(ConversationEntries.MESSAGE_ID)
|
||||
val key = "${account.account_key}-${recipient.key}"
|
||||
val key = "${account.key}-${recipient.key}"
|
||||
readStateManager.setPosition(CustomTabType.DIRECT_MESSAGES, key, cursor.getLong(messageIdIdx), false)
|
||||
}
|
||||
cursor.close()
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
@ -40,9 +41,12 @@ import org.mariotaku.twidere.adapter.DummyItemAdapter
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_QUICK_SEND
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.Draft
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableStatusUpdate
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.service.BackgroundOperationService
|
||||
import org.mariotaku.twidere.util.BugReporter
|
||||
import org.mariotaku.twidere.util.EditTextEnterHandler
|
||||
@ -60,8 +64,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
val context = builder.context
|
||||
val status = status!!
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(getContext(),
|
||||
status.account_key)!!
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context), status.account_key)!!
|
||||
|
||||
builder.setView(R.layout.dialog_status_quote_retweet)
|
||||
builder.setTitle(R.string.retweet_quote_confirm_title)
|
||||
@ -93,12 +96,12 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
val holder = StatusViewHolder(adapter, itemContent)
|
||||
holder.displayStatus(status, false, true)
|
||||
|
||||
textCountView.maxLength = TwidereValidator.getTextLimit(credentials)
|
||||
textCountView.maxLength = TwidereValidator.getTextLimit(details)
|
||||
|
||||
itemMenu.visibility = View.GONE
|
||||
actionButtons.visibility = View.GONE
|
||||
itemContent.isFocusable = false
|
||||
val useQuote = useQuote(!status.user_is_protected, credentials)
|
||||
val useQuote = useQuote(!status.user_is_protected, details)
|
||||
|
||||
commentContainer.visibility = if (useQuote) View.VISIBLE else View.GONE
|
||||
editComment.accountKey = (status.account_key)
|
||||
@ -110,7 +113,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
}
|
||||
|
||||
override fun onHitEnter(): Boolean {
|
||||
if (retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM)) {
|
||||
if (retweetOrQuote(details, status, SHOW_PROTECTED_CONFIRM)) {
|
||||
dismiss()
|
||||
return true
|
||||
}
|
||||
@ -123,7 +126,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
updateTextCount(getDialog(), s, status, credentials)
|
||||
updateTextCount(getDialog(), s, status, details)
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
@ -150,12 +153,12 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {
|
||||
var dismissDialog = false
|
||||
if (editComment.length() > 0) {
|
||||
dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM)
|
||||
dismissDialog = retweetOrQuote(details, status, SHOW_PROTECTED_CONFIRM)
|
||||
} else if (isMyRetweet(status)) {
|
||||
twitterWrapper.cancelRetweetAsync(status.account_key, status.id, status.my_retweet_id)
|
||||
dismissDialog = true
|
||||
} else if (useQuote(!status.user_is_protected, credentials)) {
|
||||
dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM)
|
||||
} else if (useQuote(!status.user_is_protected, details)) {
|
||||
dismissDialog = retweetOrQuote(details, status, SHOW_PROTECTED_CONFIRM)
|
||||
} else {
|
||||
BugReporter.logException(IllegalStateException(status.toString()))
|
||||
}
|
||||
@ -164,15 +167,15 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
updateTextCount(alertDialog, editComment.text, status, credentials)
|
||||
updateTextCount(alertDialog, editComment.text, status, details)
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
|
||||
private fun updateTextCount(dialog: DialogInterface, s: CharSequence, status: ParcelableStatus, credentials: ParcelableCredentials) {
|
||||
private fun updateTextCount(dialog: DialogInterface, s: CharSequence, status: ParcelableStatus, credentials: AccountDetails) {
|
||||
if (dialog !is AlertDialog) return
|
||||
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE) ?: return
|
||||
if (s.length > 0) {
|
||||
if (s.isNotEmpty()) {
|
||||
positiveButton.setText(R.string.comment)
|
||||
positiveButton.isEnabled = true
|
||||
} else if (isMyRetweet(status)) {
|
||||
@ -197,7 +200,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
private fun retweetOrQuote(account: ParcelableAccount, status: ParcelableStatus,
|
||||
private fun retweetOrQuote(account: AccountDetails, status: ParcelableStatus,
|
||||
showProtectedConfirmation: Boolean): Boolean {
|
||||
val twitter = twitterWrapper
|
||||
val dialog = dialog ?: return false
|
||||
@ -212,7 +215,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
val update = ParcelableStatusUpdate()
|
||||
update.accounts = arrayOf(account)
|
||||
val editingComment = editComment.text.toString()
|
||||
when (ParcelableAccountUtils.getAccountType(account)) {
|
||||
when (AccountUtils.getAccountType(account)) {
|
||||
AccountType.FANFOU -> {
|
||||
if (!status.is_quote || !quoteOriginalStatus) {
|
||||
if (status.user_is_protected && showProtectedConfirmation) {
|
||||
@ -254,8 +257,8 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun useQuote(preCondition: Boolean, account: ParcelableAccount): Boolean {
|
||||
return preCondition || AccountType.FANFOU == account.account_type
|
||||
private fun useQuote(preCondition: Boolean, account: AccountDetails): Boolean {
|
||||
return preCondition || AccountType.FANFOU == account.type
|
||||
}
|
||||
|
||||
|
||||
@ -266,8 +269,8 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
val args = arguments
|
||||
val account = args.getParcelable<ParcelableAccount>(EXTRA_ACCOUNT)
|
||||
val status = args.getParcelable<ParcelableStatus>(EXTRA_STATUS)
|
||||
val account: AccountDetails = args.getParcelable(EXTRA_ACCOUNT)
|
||||
val status: ParcelableStatus = args.getParcelable(EXTRA_STATUS)
|
||||
if (fragment.retweetOrQuote(account, status, false)) {
|
||||
fragment.dismiss()
|
||||
}
|
||||
@ -288,7 +291,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
||||
companion object {
|
||||
|
||||
fun show(pf: RetweetQuoteDialogFragment,
|
||||
account: ParcelableAccount,
|
||||
account: AccountDetails,
|
||||
status: ParcelableStatus): QuoteProtectedStatusWarnFragment {
|
||||
val f = QuoteProtectedStatusWarnFragment()
|
||||
val args = Bundle()
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ContentValues
|
||||
@ -219,7 +220,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
|
||||
override fun onLoadFinished(loader: Loader<StatusActivity?>, data: StatusActivity?) {
|
||||
adapter!!.updateItemDecoration()
|
||||
adapter!!.setStatusActivity(data)
|
||||
adapter!!.statusActivity = data
|
||||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<StatusActivity?>) {
|
||||
@ -418,8 +419,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
if (status != null) {
|
||||
val readPosition = saveReadPosition()
|
||||
val dataExtra = data.extras
|
||||
val credentials = dataExtra.getParcelable<ParcelableCredentials>(EXTRA_ACCOUNT)
|
||||
if (adapter!!.setStatus(status, credentials)) {
|
||||
val details: AccountDetails = dataExtra.getParcelable(EXTRA_ACCOUNT)
|
||||
if (adapter!!.setStatus(status, details)) {
|
||||
val args = arguments
|
||||
if (args.containsKey(EXTRA_STATUS)) {
|
||||
args.putParcelable(EXTRA_STATUS, status)
|
||||
@ -436,7 +437,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
|
||||
val event = TweetEvent.create(activity, status, TimelineType.OTHER)
|
||||
event.action = TweetEvent.Action.OPEN
|
||||
event.isHasTranslateFeature = Utils.isOfficialCredentials(context, credentials)
|
||||
event.isHasTranslateFeature = Utils.isOfficialCredentials(context, details)
|
||||
mStatusEvent = event
|
||||
} else if (readPosition != null) {
|
||||
restoreReadPosition(readPosition)
|
||||
@ -758,7 +759,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun displayStatus(account: ParcelableCredentials?,
|
||||
fun displayStatus(account: AccountDetails?,
|
||||
status: ParcelableStatus?,
|
||||
statusActivity: StatusActivity?,
|
||||
translation: TranslationResult?) {
|
||||
@ -1451,9 +1452,9 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
private var mDetailMediaExpanded: Boolean = false
|
||||
|
||||
var status: ParcelableStatus? = null
|
||||
private set
|
||||
internal set
|
||||
var translationResult: TranslationResult? = null
|
||||
set(translation) {
|
||||
internal set(translation) {
|
||||
if (status == null || translation == null || !TextUtils.equals(InternalTwitterContentUtils.getOriginalId(status!!), translation.id)) {
|
||||
field = null
|
||||
} else {
|
||||
@ -1461,9 +1462,17 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
private var mStatusActivity: StatusActivity? = null
|
||||
var statusAccount: ParcelableCredentials? = null
|
||||
private set
|
||||
var statusActivity: StatusActivity? = null
|
||||
internal set(value) {
|
||||
val status = status ?: return
|
||||
if (value != null && value.isStatus(status)) {
|
||||
return
|
||||
}
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
var statusAccount: AccountDetails? = null
|
||||
internal set
|
||||
|
||||
private var data: List<ParcelableStatus>? = null
|
||||
private var replyError: CharSequence? = null
|
||||
@ -1687,7 +1696,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
VIEW_TYPE_DETAIL_STATUS -> {
|
||||
val status = getStatus(position)
|
||||
val detailHolder = holder as DetailStatusViewHolder
|
||||
detailHolder.displayStatus(statusAccount, status, mStatusActivity,
|
||||
detailHolder.displayStatus(statusAccount, status, statusActivity,
|
||||
translationResult)
|
||||
}
|
||||
VIEW_TYPE_LIST_STATUS -> {
|
||||
@ -1814,10 +1823,10 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
updateItemDecoration()
|
||||
}
|
||||
|
||||
fun setStatus(status: ParcelableStatus, credentials: ParcelableCredentials): Boolean {
|
||||
fun setStatus(status: ParcelableStatus, account: AccountDetails): Boolean {
|
||||
val old = this.status
|
||||
this.status = status
|
||||
statusAccount = credentials
|
||||
statusAccount = account
|
||||
notifyDataSetChanged()
|
||||
updateItemDecoration()
|
||||
return !CompareUtils.objectEquals(old, status)
|
||||
@ -1836,14 +1845,6 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
return RecyclerView.NO_POSITION
|
||||
}
|
||||
|
||||
fun setStatusActivity(activity: StatusActivity?) {
|
||||
val status = status ?: return
|
||||
if (activity != null && activity.isStatus(status)) {
|
||||
return
|
||||
}
|
||||
mStatusActivity = activity
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun getData(): List<ParcelableStatus>? {
|
||||
return data
|
||||
@ -2058,9 +2059,8 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
|
||||
override fun loadInBackground(): StatusActivity? {
|
||||
val context = context
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
mAccountKey)
|
||||
if (credentials == null || AccountType.TWITTER != ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context), mAccountKey)
|
||||
if (details == null || AccountType.TWITTER != AccountUtils.getAccountType(details)) {
|
||||
return null
|
||||
}
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, mAccountKey, false) ?: return null
|
||||
|
@ -145,7 +145,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||
// Data fields
|
||||
var user: ParcelableUser? = null
|
||||
private set
|
||||
private var account: ParcelableAccount? = null
|
||||
private var account: AccountDetails? = null
|
||||
private var relationship: ParcelableRelationship? = null
|
||||
private var locale: Locale? = null
|
||||
private var mGetUserInfoLoaderInitialized: Boolean = false
|
||||
@ -225,7 +225,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||
cardContent.visibility = View.VISIBLE
|
||||
errorContainer.visibility = View.GONE
|
||||
progressContainer.visibility = View.GONE
|
||||
val account = data.extras.getParcelable<ParcelableAccount>(EXTRA_ACCOUNT)
|
||||
val account: AccountDetails = data.extras.getParcelable(EXTRA_ACCOUNT)
|
||||
displayUser(user, account)
|
||||
if (user.is_cache) {
|
||||
val args = Bundle()
|
||||
@ -422,7 +422,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun displayUser(user: ParcelableUser?, account: ParcelableAccount?) {
|
||||
fun displayUser(user: ParcelableUser?, account: AccountDetails?) {
|
||||
val activity = activity ?: return
|
||||
this.user = user
|
||||
this.account = account
|
||||
@ -779,7 +779,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||
|
||||
if (account != null) {
|
||||
isTwitter = TextUtils.equals(AccountType.TWITTER,
|
||||
ParcelableAccountUtils.getAccountType(account))
|
||||
AccountUtils.getAccountType(account))
|
||||
} else {
|
||||
isTwitter = false
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -40,6 +41,7 @@ import com.twitter.Validator
|
||||
import kotlinx.android.synthetic.main.fragment_user_profile_editor.*
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.ProfileUpdate
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
@ -47,12 +49,13 @@ import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.ColorPickerDialogActivity
|
||||
import org.mariotaku.twidere.activity.ThemedImagePickerActivity
|
||||
import org.mariotaku.twidere.extension.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.loader.ParcelableUserLoader
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.SingleResponse
|
||||
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.task.UpdateAccountInfoTask
|
||||
import org.mariotaku.twidere.task.UpdateProfileBackgroundImageTask
|
||||
@ -345,9 +348,8 @@ class UserProfileEditorFragment : BaseSupportFragment(), OnSizeChangedListener,
|
||||
) : AbstractTask<Context, SingleResponse<ParcelableUser>, UserProfileEditorFragment>() {
|
||||
|
||||
override fun doLongOperation(context: Context): SingleResponse<ParcelableUser> {
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context, accountKey) ?: return SingleResponse.Companion.getInstance<ParcelableUser>()
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, credentials,
|
||||
true, true) ?: return SingleResponse.Companion.getInstance<ParcelableUser>()
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey) ?: return SingleResponse.getInstance()
|
||||
val microBlog = details.credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java)
|
||||
try {
|
||||
var user: User? = null
|
||||
if (isProfileChanged) {
|
||||
@ -358,7 +360,7 @@ class UserProfileEditorFragment : BaseSupportFragment(), OnSizeChangedListener,
|
||||
profileUpdate.url(url)
|
||||
profileUpdate.linkColor(linkColor)
|
||||
profileUpdate.backgroundColor(backgroundColor)
|
||||
user = twitter.updateProfile(profileUpdate)
|
||||
user = microBlog.updateProfile(profileUpdate)
|
||||
}
|
||||
if (user == null) {
|
||||
// User profile unchanged
|
||||
@ -366,7 +368,7 @@ class UserProfileEditorFragment : BaseSupportFragment(), OnSizeChangedListener,
|
||||
}
|
||||
val response = SingleResponse.Companion.getInstance(
|
||||
ParcelableUserUtils.fromUser(user, accountKey))
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, credentials)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, details)
|
||||
return response
|
||||
} catch (e: MicroBlogException) {
|
||||
return SingleResponse.Companion.getInstance<ParcelableUser>(e)
|
||||
|
@ -30,15 +30,12 @@ import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.SearchQuery
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
import org.mariotaku.twidere.util.Nullables
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
class ConversationLoader(
|
||||
@ -63,18 +60,16 @@ class ConversationLoader(
|
||||
}
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
public override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
paging: Paging): List<Status> {
|
||||
public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): List<Status> {
|
||||
canLoadAllReplies = false
|
||||
when (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
when (details.type) {
|
||||
AccountType.TWITTER -> {
|
||||
val isOfficial = Utils.isOfficialCredentials(context, credentials)
|
||||
val isOfficial = details.isOfficial(context)
|
||||
canLoadAllReplies = isOfficial
|
||||
if (isOfficial) {
|
||||
return microBlog.showConversation(status.id, paging)
|
||||
} else {
|
||||
return showConversationCompat(microBlog, credentials, status, true)
|
||||
return showConversationCompat(microBlog, details, status, true)
|
||||
}
|
||||
}
|
||||
AccountType.STATUSNET -> {
|
||||
@ -91,14 +86,14 @@ class ConversationLoader(
|
||||
}
|
||||
// Set to true because there's no conversation support on this platform
|
||||
canLoadAllReplies = true
|
||||
return showConversationCompat(microBlog, credentials, status, false)
|
||||
return showConversationCompat(microBlog, details, status, false)
|
||||
}
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
private fun showConversationCompat(twitter: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
status: ParcelableStatus,
|
||||
loadReplies: Boolean): List<Status> {
|
||||
details: AccountDetails,
|
||||
status: ParcelableStatus,
|
||||
loadReplies: Boolean): List<Status> {
|
||||
val statuses = ArrayList<Status>()
|
||||
val noSinceMaxId = maxId == null && sinceId == null
|
||||
// Load conversations
|
||||
@ -116,7 +111,7 @@ class ConversationLoader(
|
||||
// Load replies
|
||||
if (sinceId != null && sinceSortId > status.sort_id || noSinceMaxId) {
|
||||
val query = SearchQuery()
|
||||
if (MicroBlogAPIFactory.isTwitterCredentials(credentials)) {
|
||||
if (details.type == AccountType.TWITTER) {
|
||||
query.query("to:${status.user_screen_name}")
|
||||
} else {
|
||||
query.query("@${status.user_screen_name}")
|
||||
@ -147,3 +142,4 @@ class ConversationLoader(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,13 +22,12 @@ package org.mariotaku.twidere.loader
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
|
||||
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.Status
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
@ -50,7 +49,7 @@ class GroupTimelineLoader(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): ResponseList<Status> {
|
||||
when {
|
||||
groupId != null -> {
|
||||
|
@ -28,12 +28,13 @@ import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.*
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
import org.mariotaku.twidere.util.TwitterWrapper
|
||||
|
||||
|
||||
class MediaTimelineLoader(
|
||||
@ -55,12 +56,12 @@ class MediaTimelineLoader(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): ResponseList<Status> {
|
||||
val context = context
|
||||
when (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
when (details.type) {
|
||||
AccountType.TWITTER -> {
|
||||
if (Utils.isOfficialCredentials(context, credentials)) {
|
||||
if (details.isOfficial(context)) {
|
||||
if (userKey != null) {
|
||||
return microBlog.getMediaTimeline(userKey.id, paging)
|
||||
}
|
||||
@ -74,18 +75,13 @@ class MediaTimelineLoader(
|
||||
} else if (userKey != null) {
|
||||
if (user == null) {
|
||||
user = TwitterWrapper.tryShowUser(microBlog, userKey.id, null,
|
||||
credentials.account_type)
|
||||
details.type)
|
||||
}
|
||||
screenName = user!!.screenName
|
||||
} else {
|
||||
throw MicroBlogException("Invalid parameters")
|
||||
}
|
||||
val query: SearchQuery
|
||||
if (MicroBlogAPIFactory.isTwitterCredentials(credentials)) {
|
||||
query = SearchQuery("from:$screenName filter:media exclude:retweets")
|
||||
} else {
|
||||
query = SearchQuery("@$screenName pic.twitter.com -RT")
|
||||
}
|
||||
val query = SearchQuery("from:$screenName filter:media exclude:retweets")
|
||||
query.paging(paging)
|
||||
val result = ResponseList<Status>()
|
||||
for (status in microBlog.search(query)) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
@ -32,13 +33,17 @@ import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
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.ParcelableStatus
|
||||
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.ParcelableStatusUtils
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.JsonSerializer
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import java.io.IOException
|
||||
import java.io.PipedInputStream
|
||||
@ -86,8 +91,8 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
override fun loadInBackground(): ListResponse<ParcelableStatus> {
|
||||
val context = context
|
||||
val accountKey = accountKey ?: return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
accountKey) ?: return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey) ?:
|
||||
return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
|
||||
|
||||
var data: MutableList<ParcelableStatus>? = data
|
||||
if (data == null) {
|
||||
@ -106,15 +111,15 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
}
|
||||
}
|
||||
if (!fromUser) return ListResponse.getListInstance(data)
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, credentials, true,
|
||||
true) ?: return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
|
||||
val microBlog = details.credentials.newMicroBlogInstance(context = context,
|
||||
cls = MicroBlog::class.java)
|
||||
val statuses: List<Status>
|
||||
val noItemsBefore = data.isEmpty()
|
||||
val loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT)
|
||||
try {
|
||||
val paging = Paging()
|
||||
processPaging(credentials, loadItemLimit, paging)
|
||||
statuses = getStatuses(twitter, credentials, paging)
|
||||
processPaging(details, loadItemLimit, paging)
|
||||
statuses = getStatuses(microBlog, details, paging)
|
||||
} catch (e: MicroBlogException) {
|
||||
// mHandler.post(new ShowErrorRunnable(e));
|
||||
exception = e
|
||||
@ -146,7 +151,7 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
for (i in 0 until statuses.size) {
|
||||
val status = statuses[i]
|
||||
val item = ParcelableStatusUtils.fromStatus(status, accountKey, insertGap && isGapEnabled && minIdx == i)
|
||||
ParcelableStatusUtils.updateExtraInformation(item, credentials, userColorNameManager)
|
||||
ParcelableStatusUtils.updateExtraInformation(item, details, userColorNameManager)
|
||||
data.add(item)
|
||||
}
|
||||
|
||||
@ -177,7 +182,7 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
protected abstract fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): List<Status>
|
||||
|
||||
@WorkerThread
|
||||
@ -189,7 +194,7 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
super.onStartLoading()
|
||||
}
|
||||
|
||||
protected open fun processPaging(credentials: ParcelableCredentials, loadItemLimit: Int, paging: Paging) {
|
||||
protected open fun processPaging(details: AccountDetails, loadItemLimit: Int, paging: Paging) {
|
||||
paging.setCount(loadItemLimit)
|
||||
if (maxId != null) {
|
||||
paging.setMaxId(maxId)
|
||||
|
@ -19,27 +19,30 @@
|
||||
|
||||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.sqliteqb.library.Columns
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.annotation.Referral
|
||||
import org.mariotaku.twidere.extension.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.*
|
||||
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.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
|
||||
import org.mariotaku.twidere.task.UpdateAccountInfoTask
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator.createCachedUser
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
import org.mariotaku.twidere.util.TwitterWrapper
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
@ -66,29 +69,27 @@ class ParcelableUserLoader(
|
||||
val context = context
|
||||
val resolver = context.contentResolver
|
||||
val accountKey = accountKey
|
||||
var credentials: ParcelableCredentials? = null
|
||||
for (cred in ParcelableCredentialsUtils.getCredentialses(context)) {
|
||||
if (cred.account_key == accountKey) {
|
||||
credentials = cred
|
||||
break
|
||||
} else if (cred.account_user != null && cred.account_user!!.account_key == accountKey) {
|
||||
credentials = cred
|
||||
break
|
||||
val am = AccountManager.get(context)
|
||||
val details = AccountUtils.getAllAccountDetails(am, AccountUtils.getAccounts(am)).firstOrNull {
|
||||
if (it.key == accountKey) {
|
||||
return@firstOrNull true
|
||||
} else if (it.user.account_key == accountKey) {
|
||||
return@firstOrNull true
|
||||
}
|
||||
}
|
||||
if (credentials == null) return SingleResponse()
|
||||
return@firstOrNull false
|
||||
} ?: return SingleResponse()
|
||||
if (!omitIntentExtra && extras != null) {
|
||||
val user = extras.getParcelable<ParcelableUser>(EXTRA_USER)
|
||||
if (user != null) {
|
||||
val values = ParcelableUserValuesCreator.create(user)
|
||||
resolver.insert(CachedUsers.CONTENT_URI, values)
|
||||
ParcelableUserUtils.updateExtraInformation(user, credentials, userColorNameManager)
|
||||
ParcelableUserUtils.updateExtraInformation(user, details, userColorNameManager)
|
||||
val response = SingleResponse(user)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, credentials)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, details)
|
||||
return response
|
||||
}
|
||||
}
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, credentials, true, true) ?: return SingleResponse()
|
||||
val twitter = details.credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java)
|
||||
if (loadFromCache) {
|
||||
val where: Expression
|
||||
val whereArgs: Array<String>
|
||||
@ -119,9 +120,9 @@ class ParcelableUserLoader(
|
||||
val user = indices.newObject(cur)
|
||||
if (TextUtils.equals(UserKeyUtils.getUserHost(user), user.key.host)) {
|
||||
user.account_key = accountKey
|
||||
user.account_color = credentials.color
|
||||
user.account_color = details.color
|
||||
val response = SingleResponse(user)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, credentials)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, details)
|
||||
return response
|
||||
}
|
||||
cur.moveToNext()
|
||||
@ -140,22 +141,21 @@ class ParcelableUserLoader(
|
||||
if (extras != null) {
|
||||
profileUrl = extras.getString(EXTRA_PROFILE_URL)
|
||||
}
|
||||
if (MicroBlogAPIFactory.isStatusNetCredentials(credentials) && userKey != null &&
|
||||
profileUrl != null && !TextUtils.equals(credentials.account_key.host,
|
||||
userKey.host)) {
|
||||
if (details.type == AccountType.STATUSNET && userKey != null && profileUrl != null
|
||||
&& details.key.host != userKey.host) {
|
||||
twitterUser = twitter.showExternalProfile(profileUrl)
|
||||
} else {
|
||||
val id = userKey?.id
|
||||
twitterUser = TwitterWrapper.tryShowUser(twitter, id, screenName,
|
||||
credentials.account_type)
|
||||
details.type)
|
||||
}
|
||||
}
|
||||
val cachedUserValues = createCachedUser(twitterUser)
|
||||
resolver.insert(CachedUsers.CONTENT_URI, cachedUserValues)
|
||||
val user = ParcelableUserUtils.fromUser(twitterUser, accountKey)
|
||||
ParcelableUserUtils.updateExtraInformation(user, credentials, userColorNameManager)
|
||||
ParcelableUserUtils.updateExtraInformation(user, details, userColorNameManager)
|
||||
val response = SingleResponse.Companion.getInstance(user)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, credentials)
|
||||
response.extras.putParcelable(EXTRA_ACCOUNT, details)
|
||||
return response
|
||||
} catch (e: MicroBlogException) {
|
||||
Log.w(LOGTAG, e)
|
||||
|
@ -22,13 +22,12 @@ package org.mariotaku.twidere.loader
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
|
||||
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.Status
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
@ -47,9 +46,7 @@ class PublicTimelineLoader(
|
||||
tabPosition, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
paging: Paging): ResponseList<Status> {
|
||||
override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Status> {
|
||||
return microBlog.getPublicTimeline(paging)
|
||||
}
|
||||
|
||||
|
@ -22,20 +22,16 @@ package org.mariotaku.twidere.loader
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
|
||||
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.SearchQuery
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
|
||||
open class TweetSearchLoader(
|
||||
context: Context,
|
||||
@ -55,11 +51,11 @@ open class TweetSearchLoader(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
public override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): List<Status> {
|
||||
if (query == null) throw MicroBlogException("Empty query")
|
||||
val processedQuery = processQuery(credentials, query)
|
||||
when (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
val processedQuery = processQuery(details, query)
|
||||
when (details.type) {
|
||||
AccountType.TWITTER -> {
|
||||
val query = SearchQuery(processedQuery)
|
||||
query.paging(paging)
|
||||
@ -75,8 +71,8 @@ open class TweetSearchLoader(
|
||||
throw MicroBlogException("Not implemented")
|
||||
}
|
||||
|
||||
protected open fun processQuery(credentials: ParcelableCredentials, query: String): String {
|
||||
if (MicroBlogAPIFactory.isTwitterCredentials(credentials)) {
|
||||
protected open fun processQuery(details: AccountDetails, query: String): String {
|
||||
if (details.type == AccountType.TWITTER) {
|
||||
return String.format("%s exclude:retweets", query)
|
||||
}
|
||||
return query
|
||||
@ -87,15 +83,15 @@ open class TweetSearchLoader(
|
||||
return InternalTwitterContentUtils.isFiltered(database, status, true)
|
||||
}
|
||||
|
||||
override fun processPaging(credentials: ParcelableCredentials, loadItemLimit: Int, paging: Paging) {
|
||||
if (MicroBlogAPIFactory.isStatusNetCredentials(credentials)) {
|
||||
override fun processPaging(details: AccountDetails, loadItemLimit: Int, paging: Paging) {
|
||||
if (details.type == AccountType.STATUSNET) {
|
||||
paging.setRpp(loadItemLimit)
|
||||
val page = page
|
||||
if (page > 0) {
|
||||
paging.setPage(page)
|
||||
}
|
||||
} else {
|
||||
super.processPaging(credentials, loadItemLimit, paging)
|
||||
super.processPaging(details, loadItemLimit, paging)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,18 +22,15 @@ package org.mariotaku.twidere.loader
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
|
||||
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.Status
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
|
||||
class UserFavoritesLoader(
|
||||
@ -53,7 +50,7 @@ class UserFavoritesLoader(
|
||||
tabPosition, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
public override fun getStatuses(microBlog: MicroBlog, credentials: ParcelableCredentials, paging: Paging): ResponseList<Status> {
|
||||
public override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Status> {
|
||||
if (userKey != null) {
|
||||
return microBlog.getFavorites(userKey.id, paging)
|
||||
} else if (screenName != null) {
|
||||
@ -67,8 +64,8 @@ class UserFavoritesLoader(
|
||||
return InternalTwitterContentUtils.isFiltered(database, status, false)
|
||||
}
|
||||
|
||||
override fun processPaging(credentials: ParcelableCredentials, loadItemLimit: Int, paging: Paging) {
|
||||
when (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
override fun processPaging(details: AccountDetails, loadItemLimit: Int, paging: Paging) {
|
||||
when (details.type) {
|
||||
AccountType.FANFOU -> {
|
||||
paging.setCount(loadItemLimit)
|
||||
if (page > 0) {
|
||||
@ -76,7 +73,7 @@ class UserFavoritesLoader(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
super.processPaging(credentials, loadItemLimit, paging)
|
||||
super.processPaging(details, loadItemLimit, paging)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class UserListMembersLoader(
|
||||
private val userKey: UserKey?,
|
||||
private val screenName: String?,
|
||||
private val listName: String,
|
||||
data: List<ParcelableUser>,
|
||||
data: List<ParcelableUser>?,
|
||||
fromUser: Boolean
|
||||
) : CursorSupportUsersLoader(context, accountKey, data, fromUser) {
|
||||
|
||||
|
@ -22,13 +22,12 @@ package org.mariotaku.twidere.loader
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
|
||||
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.Status
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
@ -51,7 +50,7 @@ class UserListTimelineLoader(
|
||||
tabPosition, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(microBlog: MicroBlog, credentials: ParcelableCredentials, paging: Paging): ResponseList<Status> {
|
||||
override fun getStatuses(microBlog: MicroBlog, details: AccountDetails, paging: Paging): ResponseList<Status> {
|
||||
when {
|
||||
listId != null -> {
|
||||
return microBlog.getUserListStatuses(listId, paging)
|
||||
|
@ -20,10 +20,10 @@
|
||||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||
|
||||
class UserMentionsLoader(
|
||||
context: Context,
|
||||
@ -41,10 +41,9 @@ class UserMentionsLoader(
|
||||
) : TweetSearchLoader(context, accountId, screenName, sinceId, maxId, page, data, savedStatusesArgs,
|
||||
tabPosition, fromUser, makeGap, loadingMore) {
|
||||
|
||||
override fun processQuery(credentials: ParcelableCredentials, query: String): String {
|
||||
val accountKey = accountKey ?: return query
|
||||
override fun processQuery(details: AccountDetails, query: String): String {
|
||||
val screenName = if (query.startsWith("@")) query.substring(1) else query
|
||||
if (MicroBlogAPIFactory.isTwitterCredentials(context, accountKey)) {
|
||||
if (details.type == AccountType.TWITTER) {
|
||||
return "to:$screenName exclude:retweets"
|
||||
}
|
||||
return "@$screenName -RT"
|
||||
|
@ -28,7 +28,7 @@ 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.Status
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils
|
||||
@ -61,12 +61,12 @@ class UserTimelineLoader(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(microBlog: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): ResponseList<Status> {
|
||||
if (pinnedStatusIds != null) {
|
||||
try {
|
||||
pinnedStatuses = microBlog.lookupStatuses(pinnedStatusIds).mapIndexed { idx, status ->
|
||||
val created = ParcelableStatusUtils.fromStatus(status, credentials.account_key, false)
|
||||
val created = ParcelableStatusUtils.fromStatus(status, details.key, false)
|
||||
created.sort_id = idx.toLong()
|
||||
return@mapIndexed created
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mariotaku.twidere.menu
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.ActionProvider
|
||||
@ -8,13 +9,14 @@ import android.view.SubMenu
|
||||
import android.view.View
|
||||
import org.mariotaku.twidere.TwidereConstants
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
|
||||
class AccountActionProvider(
|
||||
context: Context,
|
||||
var accounts: Array<ParcelableAccount>? = ParcelableAccountUtils.getAccounts(context, false, false)
|
||||
var accounts: Array<AccountDetails>? = AccountUtils.getAllAccountDetails(AccountManager.get(context))
|
||||
) : ActionProvider(context), TwidereConstants {
|
||||
|
||||
var selectedAccountIds: Array<UserKey>? = null
|
||||
@ -32,7 +34,7 @@ class AccountActionProvider(
|
||||
subMenu.removeGroup(MENU_GROUP)
|
||||
if (accounts == null) return
|
||||
accounts?.forEachIndexed { idx, account ->
|
||||
val item = subMenu.add(MENU_GROUP, Menu.NONE, idx, account.name)
|
||||
val item = subMenu.add(MENU_GROUP, Menu.NONE, idx, account.user.name)
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_ACCOUNT, account)
|
||||
item.intent = intent
|
||||
|
@ -3,6 +3,7 @@ package org.mariotaku.twidere.model
|
||||
import android.accounts.Account
|
||||
import android.accounts.AccountManager
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt
|
||||
import org.mariotaku.twidere.extension.getAccountExtras
|
||||
import org.mariotaku.twidere.extension.getCredentials
|
||||
import org.mariotaku.twidere.extension.getCredentialsType
|
||||
@ -23,12 +24,12 @@ fun Account.toParcelableCredentials(am: AccountManager): ParcelableCredentials {
|
||||
internal fun Account.writeParcelableCredentials(am: AccountManager, credentials: ParcelableCredentials) {
|
||||
writeParcelableAccount(am, credentials)
|
||||
credentials.auth_type = when (getCredentialsType(am)) {
|
||||
Credentials.Type.OAUTH -> ParcelableCredentials.AuthTypeInt.OAUTH
|
||||
Credentials.Type.XAUTH -> ParcelableCredentials.AuthTypeInt.XAUTH
|
||||
Credentials.Type.BASIC -> ParcelableCredentials.AuthTypeInt.BASIC
|
||||
Credentials.Type.EMPTY -> ParcelableCredentials.AuthTypeInt.TWIP_O_MODE
|
||||
Credentials.Type.OAUTH2 -> ParcelableCredentials.AuthTypeInt.OAUTH2
|
||||
else -> ParcelableCredentials.AuthTypeInt.OAUTH
|
||||
Credentials.Type.OAUTH -> AuthTypeInt.OAUTH
|
||||
Credentials.Type.XAUTH -> AuthTypeInt.XAUTH
|
||||
Credentials.Type.BASIC -> AuthTypeInt.BASIC
|
||||
Credentials.Type.EMPTY -> AuthTypeInt.TWIP_O_MODE
|
||||
Credentials.Type.OAUTH2 -> AuthTypeInt.OAUTH2
|
||||
else -> AuthTypeInt.OAUTH
|
||||
}
|
||||
val extras = getAccountExtras(am)
|
||||
if (extras != null) {
|
||||
|
@ -254,8 +254,8 @@ object ParcelableStatusUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateExtraInformation(status: ParcelableStatus, credentials: ParcelableCredentials, manager: UserColorNameManager) {
|
||||
status.account_color = credentials.color
|
||||
fun updateExtraInformation(status: ParcelableStatus, details: AccountDetails, manager: UserColorNameManager) {
|
||||
status.account_color = details.color
|
||||
status.user_color = manager.getUserColor(status.user_key)
|
||||
status.user_nickname = manager.getUserNickname(status.user_key)
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.service
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.IntentService
|
||||
import android.app.Notification
|
||||
import android.app.Service
|
||||
@ -40,31 +41,30 @@ import android.util.Pair
|
||||
import android.widget.Toast
|
||||
import com.twitter.Extractor
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger
|
||||
import edu.tsinghua.hotmobi.model.MediaEvent
|
||||
import edu.tsinghua.hotmobi.model.MediaUploadEvent
|
||||
import edu.tsinghua.hotmobi.model.TimelineType
|
||||
import edu.tsinghua.hotmobi.model.TweetEvent
|
||||
import org.mariotaku.abstask.library.ManualTaskStarter
|
||||
import org.mariotaku.ktextension.configure
|
||||
import org.mariotaku.ktextension.toLong
|
||||
import org.mariotaku.ktextension.toTypedArray
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.TwitterUpload
|
||||
import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse
|
||||
import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse.ProcessingInfo
|
||||
import org.mariotaku.restfu.http.ContentType
|
||||
import org.mariotaku.restfu.http.mime.Body
|
||||
import org.mariotaku.restfu.http.mime.FileBody
|
||||
import org.mariotaku.restfu.http.mime.SimpleBody
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtra
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableDirectMessageUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUpdateUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages
|
||||
@ -350,15 +350,13 @@ class BackgroundOperationService : IntentService("background_operation"), Consta
|
||||
recipientId: String,
|
||||
text: String,
|
||||
imageUri: String?): SingleResponse<ParcelableDirectMessage> {
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(this,
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(this),
|
||||
accountKey) ?: return SingleResponse.getInstance<ParcelableDirectMessage>()
|
||||
val twitter = MicroBlogAPIFactory.getInstance(this, credentials, true, true)
|
||||
val twitterUpload = MicroBlogAPIFactory.getInstance(this, credentials,
|
||||
true, true, TwitterUpload::class.java)
|
||||
if (twitter == null || twitterUpload == null) return SingleResponse.getInstance<ParcelableDirectMessage>()
|
||||
val twitter = details.credentials.newMicroBlogInstance(context = this, cls = MicroBlog::class.java)
|
||||
val twitterUpload = details.credentials.newMicroBlogInstance(context = this, cls = TwitterUpload::class.java)
|
||||
try {
|
||||
val directMessage: ParcelableDirectMessage
|
||||
when (ParcelableAccountUtils.getAccountType(credentials)) {
|
||||
when (AccountUtils.getAccountType(details)) {
|
||||
AccountType.FANFOU -> {
|
||||
if (imageUri != null) {
|
||||
throw MicroBlogException("Can't send image DM on Fanfou")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mariotaku.twidere.task.twitter
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.ContentResolver
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
@ -19,12 +20,13 @@ import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_LOAD_ITEM_LIMIT
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.extension.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.GetActivitiesTaskEvent
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils
|
||||
@ -64,10 +66,8 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
val accountKey = accountIds[i]
|
||||
val noItemsBefore = DataStoreUtils.getActivitiesCount(context, contentUri,
|
||||
accountKey) <= 0
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
accountKey) ?: continue
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, credentials, true,
|
||||
true) ?: continue
|
||||
val credentials = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey) ?: continue
|
||||
val microBlog = credentials.credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java)
|
||||
val paging = Paging()
|
||||
paging.count(loadItemLimit)
|
||||
var maxId: String? = null
|
||||
@ -94,11 +94,11 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
}
|
||||
// We should delete old activities has intersection with new items
|
||||
try {
|
||||
val activities = getActivities(twitter, credentials, paging)
|
||||
val activities = getActivities(microBlog, credentials, paging)
|
||||
storeActivities(cr, loadItemLimit, credentials, noItemsBefore, activities, sinceId,
|
||||
maxId, false)
|
||||
if (saveReadPosition) {
|
||||
saveReadPosition(accountKey, credentials, twitter)
|
||||
saveReadPosition(accountKey, credentials, microBlog)
|
||||
}
|
||||
errorInfoStore.remove(errorInfoKey, accountKey)
|
||||
} catch (e: MicroBlogException) {
|
||||
@ -120,7 +120,7 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
|
||||
protected abstract val errorInfoKey: String
|
||||
|
||||
private fun storeActivities(cr: ContentResolver, loadItemLimit: Int, credentials: ParcelableCredentials,
|
||||
private fun storeActivities(cr: ContentResolver, loadItemLimit: Int, details: AccountDetails,
|
||||
noItemsBefore: Boolean, activities: ResponseList<Activity>,
|
||||
sinceId: String?, maxId: String?, notify: Boolean) {
|
||||
val deleteBound = LongArray(2, { return@LongArray -1 })
|
||||
@ -134,8 +134,7 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
val sortDiff = firstSortId - lastSortId
|
||||
for (i in activities.indices) {
|
||||
val item = activities[i]
|
||||
val activity = ParcelableActivityUtils.fromActivity(item,
|
||||
credentials.account_key, false)
|
||||
val activity = ParcelableActivityUtils.fromActivity(item, details.key, false)
|
||||
activity.position_key = GetStatusesTask.getPositionKey(activity.timestamp,
|
||||
activity.timestamp, lastSortId, sortDiff, i, activities.size)
|
||||
if (deleteBound[0] < 0) {
|
||||
@ -155,14 +154,14 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
|
||||
activity.inserted_date = System.currentTimeMillis()
|
||||
val values = ContentValuesCreator.createActivity(activity,
|
||||
credentials, userColorNameManager)
|
||||
details, userColorNameManager)
|
||||
valuesList.add(values)
|
||||
}
|
||||
}
|
||||
var olderCount = -1
|
||||
if (minPositionKey > 0) {
|
||||
olderCount = DataStoreUtils.getActivitiesCount(context, contentUri, minPositionKey,
|
||||
Activities.POSITION_KEY, false, credentials.account_key)
|
||||
Activities.POSITION_KEY, false, details.key)
|
||||
}
|
||||
val writeUri = UriUtils.appendQueryParameters(contentUri, QUERY_PARAM_NOTIFY, notify)
|
||||
if (deleteBound[0] > 0 && deleteBound[1] > 0) {
|
||||
@ -170,10 +169,10 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
Expression.equalsArgs(Activities.ACCOUNT_KEY),
|
||||
Expression.greaterEqualsArgs(Activities.MIN_SORT_POSITION),
|
||||
Expression.lesserEqualsArgs(Activities.MAX_SORT_POSITION))
|
||||
val whereArgs = arrayOf(credentials.account_key.toString(), deleteBound[0].toString(), deleteBound[1].toString())
|
||||
val whereArgs = arrayOf(details.key.toString(), deleteBound[0].toString(), deleteBound[1].toString())
|
||||
val rowsDeleted = cr.delete(writeUri, where.sql, whereArgs)
|
||||
// Why loadItemLimit / 2? because it will not acting strange in most cases
|
||||
val insertGap = !noItemsBefore && olderCount > 0 && rowsDeleted <= 0 && activities.size > loadItemLimit / 2
|
||||
val insertGap = !noItemsBefore && olderCount > 0 && rowsDeleted <= 0 && activities.size > loadItemLimit / 2
|
||||
if (insertGap && !valuesList.isEmpty()) {
|
||||
valuesList[valuesList.size - 1].put(Activities.IS_GAP, true)
|
||||
}
|
||||
@ -186,17 +185,17 @@ abstract class GetActivitiesTask(protected val context: Context) : AbstractTask<
|
||||
val noGapWhere = Expression.and(Expression.equalsArgs(Activities.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Activities.MIN_REQUEST_POSITION),
|
||||
Expression.equalsArgs(Activities.MAX_REQUEST_POSITION)).sql
|
||||
val noGapWhereArgs = arrayOf(credentials.account_key.toString(), maxId, maxId)
|
||||
val noGapWhereArgs = arrayOf(details.key.toString(), maxId, maxId)
|
||||
cr.update(writeUri, noGapValues, noGapWhere, noGapWhereArgs)
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun saveReadPosition(accountId: UserKey,
|
||||
credentials: ParcelableCredentials, twitter: MicroBlog)
|
||||
protected abstract fun saveReadPosition(accountKey: UserKey,
|
||||
details: AccountDetails, twitter: MicroBlog)
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
protected abstract fun getActivities(twitter: MicroBlog,
|
||||
credentials: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
paging: Paging): ResponseList<Activity>
|
||||
|
||||
public override fun afterExecute(handler: Any?, result: Any?) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mariotaku.twidere.task.twitter
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
@ -24,12 +25,13 @@ import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY
|
||||
import org.mariotaku.twidere.constant.loadItemLimitKey
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.extension.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatusValuesCreator
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.message.GetStatusesTaskEvent
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
@ -88,10 +90,10 @@ abstract class GetStatusesTask(protected val context: Context) : AbstractTask<Re
|
||||
val loadItemLimit = preferences[loadItemLimitKey]
|
||||
for (i in 0 until accountKeys.size) {
|
||||
val accountKey = accountKeys[i]
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context),
|
||||
accountKey) ?: continue
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, credentials,
|
||||
true, true) ?: continue
|
||||
val microBlog = details.credentials.newMicroBlogInstance(context = context,
|
||||
cls = MicroBlog::class.java)
|
||||
try {
|
||||
val paging = Paging()
|
||||
paging.count(loadItemLimit)
|
||||
@ -127,8 +129,8 @@ abstract class GetStatusesTask(protected val context: Context) : AbstractTask<Re
|
||||
} else {
|
||||
sinceId = null
|
||||
}
|
||||
val statuses = getStatuses(twitter, paging)
|
||||
storeStatus(accountKey, credentials, statuses, sinceId, maxId, sinceSortId,
|
||||
val statuses = getStatuses(microBlog, paging)
|
||||
storeStatus(accountKey, details, statuses, sinceId, maxId, sinceSortId,
|
||||
maxSortId, loadItemLimit, false)
|
||||
// TODO cache related data and preload
|
||||
val cacheTask = CacheUsersStatusesTask(context)
|
||||
@ -149,7 +151,7 @@ abstract class GetStatusesTask(protected val context: Context) : AbstractTask<Re
|
||||
return result
|
||||
}
|
||||
|
||||
private fun storeStatus(accountKey: UserKey, credentials: ParcelableCredentials,
|
||||
private fun storeStatus(accountKey: UserKey, details: AccountDetails,
|
||||
statuses: List<Status>,
|
||||
sinceId: String?, maxId: String?,
|
||||
sinceSortId: Long, maxSortId: Long,
|
||||
@ -173,7 +175,7 @@ abstract class GetStatusesTask(protected val context: Context) : AbstractTask<Re
|
||||
val item = statuses[i]
|
||||
val status = ParcelableStatusUtils.fromStatus(item, accountKey,
|
||||
false)
|
||||
ParcelableStatusUtils.updateExtraInformation(status, credentials, manager)
|
||||
ParcelableStatusUtils.updateExtraInformation(status, details, manager)
|
||||
status.position_key = getPositionKey(status.timestamp, status.sort_id, lastSortId,
|
||||
sortDiff, i, statuses.size)
|
||||
status.inserted_date = System.currentTimeMillis()
|
||||
|
@ -33,6 +33,7 @@ import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableLocationUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils
|
||||
@ -120,7 +121,7 @@ class UpdateStatusTask(
|
||||
val exception = result.exceptions[i]
|
||||
if (exception != null && !isDuplicate(exception)) {
|
||||
hasError = true
|
||||
failedAccounts.add(update.accounts[i].account_key)
|
||||
failedAccounts.add(update.accounts[i].key)
|
||||
}
|
||||
}
|
||||
val cr = context.contentResolver
|
||||
@ -161,7 +162,7 @@ class UpdateStatusTask(
|
||||
for (i in 0..pending.length - 1) {
|
||||
val account = update.accounts[i]
|
||||
// Skip upload if shared media found
|
||||
val accountKey = account.account_key
|
||||
val accountKey = account.key
|
||||
var uploadResult: MediaUploadResult? = sharedMedia[accountKey]
|
||||
if (uploadResult == null) {
|
||||
uploadResult = uploader.upload(update, accountKey, media)
|
||||
@ -191,7 +192,7 @@ class UpdateStatusTask(
|
||||
for (i in 0..pending.length - 1) {
|
||||
val account = update.accounts[i]
|
||||
// Skip upload if this shared media found
|
||||
val accountKey = account.account_key
|
||||
val accountKey = account.key
|
||||
var shortenResult: StatusShortenResult? = sharedShortened[accountKey]
|
||||
if (shortenResult == null) {
|
||||
shortenResult = shortener.shorten(update, accountKey, pending.overrideTexts[i])
|
||||
@ -223,10 +224,10 @@ class UpdateStatusTask(
|
||||
|
||||
for (i in 0 until pendingUpdate.length) {
|
||||
val account = statusUpdate.accounts[i]
|
||||
val microBlog = MicroBlogAPIFactory.getInstance(context, account.account_key, true)
|
||||
val microBlog = MicroBlogAPIFactory.getInstance(context, account.key, true)
|
||||
var bodyAndSize: Pair<Body, Point>? = null
|
||||
try {
|
||||
when (ParcelableAccountUtils.getAccountType(account)) {
|
||||
when (AccountUtils.getAccountType(account)) {
|
||||
AccountType.FANFOU -> {
|
||||
// Call uploadPhoto if media present
|
||||
if (!ArrayUtils.isEmpty(statusUpdate.media)) {
|
||||
@ -247,14 +248,14 @@ class UpdateStatusTask(
|
||||
val requestResult = microBlog.uploadPhoto(photoUpdate)
|
||||
|
||||
result.statuses[i] = ParcelableStatusUtils.fromStatus(requestResult,
|
||||
account.account_key, false)
|
||||
account.key, false)
|
||||
}
|
||||
} else {
|
||||
val requestResult = twitterUpdateStatus(microBlog,
|
||||
statusUpdate, pendingUpdate, pendingUpdate.overrideTexts[i], i)
|
||||
|
||||
result.statuses[i] = ParcelableStatusUtils.fromStatus(requestResult,
|
||||
account.account_key, false)
|
||||
account.key, false)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@ -262,7 +263,7 @@ class UpdateStatusTask(
|
||||
pendingUpdate, pendingUpdate.overrideTexts[i], i)
|
||||
|
||||
result.statuses[i] = ParcelableStatusUtils.fromStatus(requestResult,
|
||||
account.account_key, false)
|
||||
account.key, false)
|
||||
}
|
||||
}
|
||||
} catch (e: MicroBlogException) {
|
||||
@ -282,18 +283,18 @@ class UpdateStatusTask(
|
||||
// Return empty array if no media attached
|
||||
if (ArrayUtils.isEmpty(update.media)) return
|
||||
val ownersList = update.accounts.filter {
|
||||
AccountType.TWITTER == ParcelableAccountUtils.getAccountType(it)
|
||||
}.map(ParcelableAccount::account_key)
|
||||
AccountType.TWITTER == AccountUtils.getAccountType(it)
|
||||
}.map(AccountDetails::key)
|
||||
val ownerIds = ownersList.map {
|
||||
it.id
|
||||
}.toTypedArray()
|
||||
for (i in 0..pendingUpdate.length - 1) {
|
||||
val account = update.accounts[i]
|
||||
val mediaIds: Array<String>?
|
||||
when (ParcelableAccountUtils.getAccountType(account)) {
|
||||
when (AccountUtils.getAccountType(account)) {
|
||||
AccountType.TWITTER -> {
|
||||
val upload = MicroBlogAPIFactory.getInstance(context,
|
||||
account.account_key, true, true, TwitterUpload::class.java)!!
|
||||
account.key, true, true, TwitterUpload::class.java)!!
|
||||
if (pendingUpdate.sharedMediaIds != null) {
|
||||
mediaIds = pendingUpdate.sharedMediaIds
|
||||
} else {
|
||||
@ -308,7 +309,7 @@ class UpdateStatusTask(
|
||||
AccountType.STATUSNET -> {
|
||||
// TODO use their native API
|
||||
val upload = MicroBlogAPIFactory.getInstance(context,
|
||||
account.account_key, true, true, TwitterUpload::class.java)!!
|
||||
account.key, true, true, TwitterUpload::class.java)!!
|
||||
mediaIds = uploadAllMediaShared(upload, update, ownerIds, false)
|
||||
}
|
||||
else -> {
|
||||
@ -511,7 +512,7 @@ class UpdateStatusTask(
|
||||
|
||||
private fun saveDraft(@Draft.Action draftAction: String?, statusUpdate: ParcelableStatusUpdate): Long {
|
||||
val draft = Draft()
|
||||
draft.account_keys = ParcelableAccountUtils.getAccountKeys(statusUpdate.accounts)
|
||||
draft.account_keys = statusUpdate.accounts.map { it.key }.toTypedArray()
|
||||
if (draftAction != null) {
|
||||
draft.action_type = draftAction
|
||||
} else {
|
||||
|
@ -9,7 +9,7 @@ import com.bluelinelabs.logansquare.LoganSquare
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.extension.model.account_name
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials.AuthTypeInt
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt
|
||||
import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices
|
||||
import org.mariotaku.twidere.model.account.cred.BasicCredentials
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.util
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
@ -51,9 +52,9 @@ import org.mariotaku.twidere.graphic.ActionIconDrawable
|
||||
import org.mariotaku.twidere.graphic.PaddingDrawable
|
||||
import org.mariotaku.twidere.menu.FavoriteItemProvider
|
||||
import org.mariotaku.twidere.menu.SupportStatusShareProvider
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.util.menu.TwidereMenuInfo
|
||||
|
||||
/**
|
||||
@ -113,7 +114,7 @@ object MenuUtils {
|
||||
menu: Menu,
|
||||
status: ParcelableStatus,
|
||||
twitter: AsyncTwitterWrapper) {
|
||||
val account = ParcelableCredentialsUtils.getCredentials(context,
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context),
|
||||
status.account_key) ?: return
|
||||
setupForStatus(context, preferences, menu, status, account, twitter)
|
||||
}
|
||||
@ -123,7 +124,7 @@ object MenuUtils {
|
||||
preferences: SharedPreferencesWrapper,
|
||||
menu: Menu,
|
||||
status: ParcelableStatus,
|
||||
account: ParcelableCredentials,
|
||||
details: AccountDetails,
|
||||
twitter: AsyncTwitterWrapper) {
|
||||
if (menu is ContextMenu) {
|
||||
menu.setHeaderTitle(context.getString(R.string.status_menu_title_format,
|
||||
@ -187,8 +188,7 @@ object MenuUtils {
|
||||
}
|
||||
val translate = menu.findItem(R.id.translate)
|
||||
if (translate != null) {
|
||||
val isOfficialKey = Utils.isOfficialCredentials(context, account)
|
||||
val prefs = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
val isOfficialKey = Utils.isOfficialCredentials(context, details)
|
||||
setItemAvailability(menu, R.id.translate, isOfficialKey)
|
||||
}
|
||||
menu.removeGroup(Constants.MENU_GROUP_STATUS_EXTENSION)
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.util
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
@ -31,12 +32,13 @@ import com.twitter.Extractor
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.BaseActivity
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.extension.getAccountUser
|
||||
import org.mariotaku.twidere.menu.AccountActionProvider
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
@ -89,16 +91,17 @@ class MultiSelectEventHandler(
|
||||
when (item.itemId) {
|
||||
R.id.reply -> {
|
||||
val extractor = Extractor()
|
||||
val am = AccountManager.get(activity)
|
||||
val intent = Intent(INTENT_ACTION_REPLY_MULTIPLE)
|
||||
val bundle = Bundle()
|
||||
val accountScreenNames = ParcelableAccountUtils.getAccounts(activity).map { it.screen_name }.toTypedArray()
|
||||
val accountScreenNames = AccountUtils.getAccounts(am).map { it.getAccountUser(am).name }.toTypedArray()
|
||||
val allMentions = TreeSet(String.CASE_INSENSITIVE_ORDER)
|
||||
for (item in selectedItems) {
|
||||
if (item is ParcelableStatus) {
|
||||
allMentions.add(item.user_screen_name)
|
||||
allMentions.addAll(extractor.extractMentionedScreennames(item.text_plain))
|
||||
} else if (item is ParcelableUser) {
|
||||
allMentions.add(item.screen_name)
|
||||
for (selected in selectedItems) {
|
||||
if (selected is ParcelableStatus) {
|
||||
allMentions.add(selected.user_screen_name)
|
||||
allMentions.addAll(extractor.extractMentionedScreennames(selected.text_plain))
|
||||
} else if (selected is ParcelableUser) {
|
||||
allMentions.add(selected.screen_name)
|
||||
}
|
||||
}
|
||||
allMentions.removeAll(Arrays.asList(*accountScreenNames))
|
||||
@ -152,9 +155,9 @@ class MultiSelectEventHandler(
|
||||
if (item.groupId == AccountActionProvider.MENU_GROUP) {
|
||||
val intent = item.intent
|
||||
if (intent == null || !intent.hasExtra(EXTRA_ACCOUNT)) return false
|
||||
val account = intent.getParcelableExtra<ParcelableAccount>(EXTRA_ACCOUNT)
|
||||
multiSelectManager.accountKey = account.account_key
|
||||
accountActionProvider?.selectedAccountIds = arrayOf(account.account_key)
|
||||
val account: AccountDetails = intent.getParcelableExtra(EXTRA_ACCOUNT)
|
||||
multiSelectManager.accountKey = account.key
|
||||
accountActionProvider?.selectedAccountIds = arrayOf(account.key)
|
||||
mode.invalidate()
|
||||
}
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user