updated extensions library

This commit is contained in:
Mariotaku Lee 2016-12-07 17:50:44 +08:00
parent d1f51601bf
commit 7f8c15d553
12 changed files with 210 additions and 104 deletions

View File

@ -30,6 +30,12 @@ allprojects {
}
subprojects {
buildscript {
ext.kotlin_version = '1.0.5-2'
ext.android_support_lib_version = '25.0.1'
ext.mariotaku_commons_library_version = '0.9.11'
ext.mariotaku_restfu_version = '0.9.34'
}
afterEvaluate { project ->
if (project.hasProperty('android')) {

View File

@ -39,13 +39,13 @@ dependencies {
apt 'com.bluelinelabs:logansquare-compiler:1.3.7'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
apt 'com.github.mariotaku.ObjectCursor:processor:0.9.12'
compile 'com.android.support:support-annotations:25.0.1'
compile "com.android.support:support-annotations:$android_support_lib_version"
compile 'com.bluelinelabs:logansquare:1.3.7'
compile 'com.github.mariotaku.RestFu:library:0.9.34'
compile 'com.github.mariotaku.RestFu:oauth:0.9.34'
compile "com.github.mariotaku.RestFu:library:$mariotaku_restfu_version"
compile "com.github.mariotaku.RestFu:oauth:$mariotaku_restfu_version"
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.12'
compile 'com.github.mariotaku.CommonsLibrary:objectcursor:0.9.10'
compile 'com.github.mariotaku.CommonsLibrary:logansquare:0.9.10'
compile "com.github.mariotaku.CommonsLibrary:objectcursor:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:logansquare:$mariotaku_commons_library_version"
compile fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@ -0,0 +1,17 @@
// IDataSyncService.aidl
package org.mariotaku.twidere;
// Declare any non-default types here with import statements
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
import org.mariotaku.twidere.model.SyncAuthInfo;
interface IDataSyncService {
SyncAuthInfo getAuthInfo();
Intent getAuthRequestIntent(in SyncAuthInfo info);
void onPerformSync(in SyncAuthInfo info, in Bundle extras, in SyncResult syncResult);
}

View File

@ -1,7 +1,7 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* Copyright (C) 2016 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,4 +19,4 @@
package org.mariotaku.twidere.model;
parcelable Account;
parcelable SyncAuthInfo;

View File

@ -0,0 +1,35 @@
package org.mariotaku.twidere.model;
import android.os.Parcel;
import android.os.Parcelable;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
/**
* Created by mariotaku on 2016/12/7.
*/
@ParcelablePlease
public class SyncAuthInfo implements Parcelable {
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
SyncAuthInfoParcelablePlease.writeToParcel(this, dest, flags);
}
public static final Creator<SyncAuthInfo> CREATOR = new Creator<SyncAuthInfo>() {
public SyncAuthInfo createFromParcel(Parcel source) {
SyncAuthInfo target = new SyncAuthInfo();
SyncAuthInfoParcelablePlease.readFromParcel(target, source);
return target;
}
public SyncAuthInfo[] newArray(int size) {
return new SyncAuthInfo[size];
}
};
}

View File

@ -19,6 +19,9 @@
package org.mariotaku.twidere;
import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
@ -26,20 +29,37 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
import com.bluelinelabs.logansquare.LoganSquare;
import org.mariotaku.twidere.annotation.AccountType;
import org.mariotaku.twidere.model.AccountDetails;
import org.mariotaku.twidere.model.ComposingStatus;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.model.ParcelableUserList;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.model.account.AccountExtras;
import org.mariotaku.twidere.model.account.StatusNetAccountExtras;
import org.mariotaku.twidere.model.account.TwitterAccountExtras;
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.OAuth2Credentials;
import org.mariotaku.twidere.model.account.cred.OAuthCredentials;
import org.mariotaku.twidere.provider.TwidereDataStore;
import org.mariotaku.twidere.provider.TwidereDataStore.DNS;
import org.mariotaku.twidere.provider.TwidereDataStore.Permissions;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.Inet4Address;
@ -227,6 +247,98 @@ public final class Twidere implements TwidereConstants {
}
}
@Nullable
@RequiresPermission(allOf = {Manifest.permission.GET_ACCOUNTS}, conditional = true)
public static Account findByAccountKey(@NonNull Context context, @NonNull UserKey userKey) {
final AccountManager am = AccountManager.get(context);
for (Account account : am.getAccountsByType(ACCOUNT_TYPE)) {
if (userKey.equals(getAccountKey(account, am))) {
return account;
}
}
return null;
}
@RequiresPermission(allOf = {"android.permission.AUTHENTICATE_ACCOUNTS"}, conditional = true)
@NonNull
public static AccountDetails getAccountDetails(Context context, Account account) throws SecurityException {
final AccountManager am = AccountManager.get(context);
final AccountDetails details = new AccountDetails();
details.account = account;
details.key = getAccountKey(account, am);
//noinspection WrongConstant
details.type = am.getUserData(account, ACCOUNT_USER_DATA_TYPE);
details.color = Color.parseColor(am.getUserData(account, ACCOUNT_USER_DATA_COLOR));
details.position = Integer.parseInt(am.getUserData(account, ACCOUNT_USER_DATA_POSITION));
//noinspection WrongConstant
details.credentials_type = am.getUserData(account, ACCOUNT_USER_DATA_CREDS_TYPE);
try {
details.user = LoganSquare.parse(am.getUserData(account, ACCOUNT_USER_DATA_USER), ParcelableUser.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
details.activated = Boolean.parseBoolean(am.getUserData(account, ACCOUNT_USER_DATA_ACTIVATED));
try {
details.credentials = parseCredentials(am.peekAuthToken(account, ACCOUNT_AUTH_TOKEN_TYPE),
details.credentials_type);
} catch (SecurityException e) {
// Ignore
}
details.extras = parseAccountExtras(am.getUserData(account, ACCOUNT_USER_DATA_EXTRAS), details.type);
details.user.color = details.color;
return details;
}
@NonNull
@RequiresPermission(allOf = {"android.permission.AUTHENTICATE_ACCOUNTS"}, conditional = true)
private static UserKey getAccountKey(Account account, AccountManager am) {
return UserKey.valueOf(am.getUserData(account, ACCOUNT_USER_DATA_KEY));
}
private static Credentials parseCredentials(String json, @Credentials.Type String type) {
try {
switch (type) {
case Credentials.Type.OAUTH:
case Credentials.Type.XAUTH: {
return LoganSquare.parse(json, OAuthCredentials.class);
}
case Credentials.Type.BASIC: {
return LoganSquare.parse(json, BasicCredentials.class);
}
case Credentials.Type.EMPTY: {
return LoganSquare.parse(json, EmptyCredentials.class);
}
case Credentials.Type.OAUTH2: {
return LoganSquare.parse(json, OAuth2Credentials.class);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
throw new UnsupportedOperationException(type);
}
private static AccountExtras parseAccountExtras(String json, @AccountType String type) {
if (json == null) return null;
try {
switch (type) {
case AccountType.TWITTER: {
return LoganSquare.parse(json, TwitterAccountExtras.class);
}
case AccountType.STATUSNET: {
return LoganSquare.parse(json, StatusNetAccountExtras.class);
}
}
} catch (IOException e) {
return null;
}
return null;
}
private static int indexOf(String[] input, String find) {
for (int i = 0, inputLength = input.length; i < inputLength; i++) {
if (find == null) {

View File

@ -107,6 +107,7 @@ dependencies {
googleCompile 'com.google.maps.android:android-maps-utils:0.4.4'
googleCompile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true }
googleCompile 'com.anjlab.android.iab.v3:library:1.0.36'
googleCompile 'com.dropbox.core:dropbox-core-sdk:2.1.2'
googleCompile ':YouTubeAndroidPlayerApi:1.2.2@jar'
// END Non-FOSS component
@ -121,18 +122,18 @@ dependencies {
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.0.1'
androidTestCompile "com.android.support:support-annotations:$android_support_lib_version"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:preference-v7:25.0.1'
compile 'com.android.support:preference-v14:25.0.1'
compile 'com.android.support:customtabs:25.0.1'
compile "com.android.support:support-v4:$android_support_lib_version"
compile "com.android.support:appcompat-v7:$android_support_lib_version"
compile "com.android.support:cardview-v7:$android_support_lib_version"
compile "com.android.support:recyclerview-v7:$android_support_lib_version"
compile "com.android.support:preference-v7:$android_support_lib_version"
compile "com.android.support:preference-v14:$android_support_lib_version"
compile "com.android.support:customtabs:$android_support_lib_version"
compile 'com.twitter:twitter-text:1.13.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
@ -157,8 +158,8 @@ dependencies {
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku:PickNCrop:0.9.5'
compile 'com.github.mariotaku.RestFu:library:0.9.34'
compile 'com.github.mariotaku.RestFu:okhttp3:0.9.34'
compile "com.github.mariotaku.RestFu:library:$mariotaku_restfu_version"
compile "com.github.mariotaku.RestFu:okhttp3:$mariotaku_restfu_version"
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.lnikkila:extendedtouchview:0.1.0'
compile 'com.google.dagger:dagger:2.6.1'
@ -169,10 +170,10 @@ dependencies {
compile 'com.github.mariotaku.ObjectCursor:core:0.9.12'
compile 'com.github.mariotaku:MultiValueSwitch:0.9.7'
compile 'com.github.mariotaku:AbstractTask:0.9.4'
compile 'com.github.mariotaku.CommonsLibrary:parcel:0.9.10'
compile 'com.github.mariotaku.CommonsLibrary:io:0.9.10'
compile 'com.github.mariotaku.CommonsLibrary:text:0.9.10'
compile 'com.github.mariotaku.CommonsLibrary:text-kotlin:0.9.10'
compile "com.github.mariotaku.CommonsLibrary:parcel:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:io:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:text:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:text-kotlin:$mariotaku_commons_library_version"
compile 'com.github.mariotaku:KPreferences:0.9.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'nl.komponents.kovenant:kovenant:3.3.0'

View File

@ -29,5 +29,18 @@
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
<data android:scheme="db-lflrwypk2e5pjm6"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -109,4 +109,6 @@ public interface Constants extends TwidereConstants {
String GOOGLE_APIS_SERVER_CLIENT_ID = "223623398518-1p34hsndj7couh2c9c2f8909amh9euhf.apps.googleusercontent.com";
@SuppressWarnings("SpellCheckingInspection")
String GOOGLE_PLAY_LICENCING_PUBKEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgiWSUKjOMgIAYKH0BLPIN4shhldgg1B0bYk8rXtWqIuiE15Ei+3YmoGBzYGrMzuaCwAZzRuWbg17xBBU6OnNYpQ5ncR133l9Cuor8z3nU2k4Jdxl2cv9P+fqdBFBi+VZ7BT+cROEoNnAD6sTOwfD2X+zykpFFbaOGyl5CQr1gdqWktf4BwihzCIrZ4PkT+2HKSFo/GEluFE60O7bAKqZmlRJ8RqlJimXtv9VtJQXqVIRDm5GkTRfcwkAg5rhmMRvsUxotYlnvtcMBidA9tT1zkSKF4X6gtrThvZndkZZgkSxCtTxJfkFIGmwrZoH66155+i2Qnk0XEB8NOt1e8N1AwIDAQAB";
@SuppressWarnings("SpellCheckingInspection")
String DROPBOX_APP_KEY = "lflrwypk2e5pjm6";
}

View File

@ -1,80 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.util.collection;
import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
import java.util.Set;
/**
* Created by mariotaku on 14/12/12.
*/
public class LongSparseMap<T> {
private final LongSparseArray<CompactHashSet<T>> internalArray;
public LongSparseMap() {
internalArray = new LongSparseArray<>();
}
public boolean put(long key, T value) {
final int idx = internalArray.indexOfKey(key);
final CompactHashSet<T> set;
if (idx < 0) {
set = new CompactHashSet<>();
internalArray.put(key, set);
} else {
set = internalArray.valueAt(idx);
}
return set.add(value);
}
@Nullable
public Set<T> get(long key) {
return internalArray.get(key);
}
public boolean clear(long key) {
final int idx = internalArray.indexOfKey(key);
if (idx < 0) return false;
internalArray.valueAt(idx).clear();
return true;
}
public boolean remove(long key, T value) {
final int idx = internalArray.indexOfKey(key);
return idx >= 0 && internalArray.valueAt(idx).remove(value);
}
public boolean has(long key, T value) {
final int idx = internalArray.indexOfKey(key);
return idx >= 0 && internalArray.valueAt(idx).contains(value);
}
public long[] keys() {
final long[] keys = new long[internalArray.size()];
for (int i = 0, j = internalArray.size(); i < j; i++) {
keys[i] = internalArray.keyAt(i);
}
return keys;
}
}

View File

@ -2,7 +2,6 @@ package org.mariotaku.twidere.extension
import android.accounts.Account
import android.accounts.AccountManager
import android.graphics.Color
import android.support.annotation.ColorInt
import com.bluelinelabs.logansquare.LoganSquare
import org.mariotaku.ktextension.toInt
@ -17,6 +16,7 @@ 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.util.ParseUtils
import org.mariotaku.twidere.util.toHexColor
@ -51,7 +51,7 @@ fun Account.setAccountUser(am: AccountManager, user: ParcelableUser) {
@ColorInt
fun Account.getColor(am: AccountManager): Int {
return Color.parseColor(am.getUserData(this, ACCOUNT_USER_DATA_COLOR))
return ParseUtils.parseColor(am.getUserData(this, ACCOUNT_USER_DATA_COLOR), 0)
}
fun Account.getPosition(am: AccountManager): Int {