1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-18 03:28:55 +01:00

updated library version

This commit is contained in:
Mariotaku Lee 2016-12-01 15:55:38 +08:00
parent 3df628c1fc
commit e2f600ad0e
39 changed files with 269 additions and 166 deletions

View File

@ -23,7 +23,7 @@ apply plugin: 'com.neenbedankt.android-apt'
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "3.0"
}
@ -38,13 +38,13 @@ android {
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.11'
apt 'com.github.mariotaku.ObjectCursor:processor:0.9.12'
compile 'com.android.support:support-annotations:25.0.1'
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.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.11'
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 fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -310,6 +310,7 @@ public class DMResponse implements Parcelable {
}
@StringDef({Type.ONE_TO_ONE, Type.GROUP_DM})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
String ONE_TO_ONE = "one_to_one", GROUP_DM = "group_dm";
}

View File

@ -25,6 +25,9 @@ import android.support.annotation.StringDef;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by mariotaku on 15/5/7.
*/
@ -163,6 +166,7 @@ public class MediaUploadResponse extends TwitterResponseObject implements Twitte
@StringDef({State.PENDING, State.IN_PROGRESS, State.FAILED, State.SUCCEEDED})
@Retention(RetentionPolicy.SOURCE)
public @interface State {
String PENDING = "pending";
String IN_PROGRESS = "in_progress";

View File

@ -24,6 +24,9 @@ import android.support.annotation.StringDef;
import org.mariotaku.microblog.library.twitter.util.InternalArrayUtil;
import org.mariotaku.restfu.http.SimpleValueMap;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by mariotaku on 15/10/21.
*/
@ -58,6 +61,7 @@ public class UniversalSearchQuery extends SimpleValueMap {
}
@StringDef({Filter.IMAGES, Filter.VIDEOS, Filter.PERISCOPE, Filter.NEWS})
@Retention(RetentionPolicy.SOURCE)
public @interface Filter {
String IMAGES = "images";
String VIDEOS = "videos";
@ -68,6 +72,7 @@ public class UniversalSearchQuery extends SimpleValueMap {
@StringDef({Module.TWEET, Module.USER_GALLERY, Module.NEWS, Module.MEDIA_GALLERY,
Module.SUGGESTION, Module.EVENT, Module.TWEET_GALLERY, Module.FOLLOWS_TWEET_GALLERY,
Module.NEARBY_TWEET_GALLERY, Module.SUMMARY, Module.EVENT_SUMMARY})
@Retention(RetentionPolicy.SOURCE)
public @interface Module {
String TWEET = "tweet";
String USER_GALLERY = "user_gallery";
@ -83,6 +88,7 @@ public class UniversalSearchQuery extends SimpleValueMap {
}
@StringDef({ResultType.RECENT, ResultType.FOLLOWS})
@Retention(RetentionPolicy.SOURCE)
public @interface ResultType {
String RECENT = "recent";
String FOLLOWS = "follows";

View File

@ -29,6 +29,8 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
@ -315,6 +317,7 @@ public class UniversalSearchResult {
}
@StringDef({ResultType.NORMAL, ResultType.TOP})
@Retention(RetentionPolicy.SOURCE)
public @interface ResultType {
String NORMAL = "normal";
String TOP = "top";

View File

@ -139,13 +139,13 @@ public class Tab implements Parcelable {
this.internalExtras = InternalExtras.from(extras);
}
@OnPreJsonSerialize
void beforeJsonSerialize() {
internalArguments = InternalArguments.from(arguments);
internalExtras = InternalExtras.from(extras);
}
@OnJsonParseComplete
void onJsonParseComplete() {
if (internalArguments != null) {
@ -169,6 +169,17 @@ public class Tab implements Parcelable {
'}';
}
@CustomTabType
public static String getTypeAlias(String key) {
if (key == null) return null;
switch (key) {
case "mentions_timeline":
case "activities_about_me":
return CustomTabType.NOTIFICATIONS_TIMELINE;
}
return key;
}
@ParcelablePlease(allFields = false)
@JsonObject
static class InternalArguments implements Parcelable {

View File

@ -5,14 +5,15 @@ import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.annotation.CustomTabType;
import org.mariotaku.twidere.model.UserKey;
import java.io.IOException;
import java.util.Arrays;
/**
@ -43,14 +44,18 @@ public class TabArguments implements TwidereConstants {
@CallSuper
public void copyToBundle(@NonNull Bundle bundle) {
final UserKey[] accountKeys = this.accountKeys;
if (!ArrayUtils.isEmpty(accountKeys)) {
assert accountKeys != null;
if (accountKeys != null && accountKeys.length > 0) {
for (UserKey key : accountKeys) {
if (key == null) return;
}
bundle.putParcelableArray(EXTRA_ACCOUNT_KEYS, accountKeys);
} else if (accountId != null) {
final long id = NumberUtils.toLong(accountId, Long.MIN_VALUE);
long id = Long.MIN_VALUE;
try {
id = Long.parseLong(accountId);
} catch (NumberFormatException e) {
// Ignore
}
if (id != Long.MIN_VALUE && id <= 0) {
// account_id = -1, means no account selected
bundle.putParcelableArray(EXTRA_ACCOUNT_KEYS, null);
@ -67,4 +72,26 @@ public class TabArguments implements TwidereConstants {
", accountKeys=" + Arrays.toString(accountKeys) +
'}';
}
@Nullable
public static TabArguments parse(@NonNull @CustomTabType String type, String json) throws IOException {
switch (type) {
case CustomTabType.HOME_TIMELINE:
case CustomTabType.NOTIFICATIONS_TIMELINE:
case CustomTabType.DIRECT_MESSAGES: {
return LoganSquare.parse(json, TabArguments.class);
}
case CustomTabType.USER_TIMELINE:
case CustomTabType.FAVORITES: {
return LoganSquare.parse(json, UserArguments.class);
}
case CustomTabType.LIST_TIMELINE: {
return LoganSquare.parse(json, UserListArguments.class);
}
case CustomTabType.SEARCH_STATUSES: {
return LoganSquare.parse(json, TextQueryArguments.class);
}
}
return null;
}
}

View File

@ -0,0 +1,38 @@
package org.mariotaku.twidere.model.tab.extra;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.commons.logansquare.LoganSquareMapperFinder;
import org.mariotaku.twidere.annotation.CustomTabType;
import java.io.IOException;
/**
* Created by mariotaku on 16/3/6.
*/
@JsonObject
public abstract class TabExtras implements Parcelable {
@CallSuper
public void copyToBundle(Bundle bundle) {
}
@Nullable
public static TabExtras parse(@NonNull @CustomTabType String type, String json) throws IOException {
switch (type) {
case CustomTabType.NOTIFICATIONS_TIMELINE: {
return LoganSquareMapperFinder.mapperFor(InteractionsTabExtras.class).parse(json);
}
case CustomTabType.HOME_TIMELINE: {
return LoganSquareMapperFinder.mapperFor(HomeTabExtras.class).parse(json);
}
}
return null;
}
}

View File

@ -4,12 +4,14 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import com.bluelinelabs.logansquare.LoganSquare;
import org.mariotaku.library.objectcursor.converter.CursorFieldConverter;
import org.mariotaku.twidere.model.Tab;
import org.mariotaku.twidere.model.tab.argument.TabArguments;
import org.mariotaku.twidere.provider.TwidereDataStore.Tabs;
import org.mariotaku.twidere.util.CustomTabUtils;
import org.mariotaku.twidere.util.JsonSerializer;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
/**
@ -18,15 +20,19 @@ import java.lang.reflect.ParameterizedType;
public class TabArgumentsFieldConverter implements CursorFieldConverter<TabArguments> {
@Override
public TabArguments parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) {
final String tabType = CustomTabUtils.getTabTypeAlias(cursor.getString(cursor.getColumnIndex(Tabs.TYPE)));
public TabArguments parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) throws IOException {
final String tabType = Tab.getTypeAlias(cursor.getString(cursor.getColumnIndex(Tabs.TYPE)));
if (TextUtils.isEmpty(tabType)) return null;
return CustomTabUtils.parseTabArguments(tabType, cursor.getString(columnIndex));
return TabArguments.parse(tabType, cursor.getString(columnIndex));
}
@Override
public void writeField(ContentValues values, TabArguments object, String columnName, ParameterizedType fieldType) {
if (object == null) return;
values.put(columnName, JsonSerializer.serialize(object));
try {
values.put(columnName, LoganSquare.serialize(object));
} catch (IOException e) {
// Ignore
}
}
}

View File

@ -4,12 +4,14 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import com.bluelinelabs.logansquare.LoganSquare;
import org.mariotaku.library.objectcursor.converter.CursorFieldConverter;
import org.mariotaku.twidere.model.Tab;
import org.mariotaku.twidere.model.tab.extra.TabExtras;
import org.mariotaku.twidere.provider.TwidereDataStore.Tabs;
import org.mariotaku.twidere.util.CustomTabUtils;
import org.mariotaku.twidere.util.JsonSerializer;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
/**
@ -17,15 +19,15 @@ import java.lang.reflect.ParameterizedType;
*/
public class TabExtrasFieldConverter implements CursorFieldConverter<TabExtras> {
@Override
public TabExtras parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) {
final String tabType = CustomTabUtils.getTabTypeAlias(cursor.getString(cursor.getColumnIndex(Tabs.TYPE)));
public TabExtras parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) throws IOException {
final String tabType = Tab.getTypeAlias(cursor.getString(cursor.getColumnIndex(Tabs.TYPE)));
if (TextUtils.isEmpty(tabType)) return null;
return CustomTabUtils.parseTabExtras(tabType, cursor.getString(columnIndex));
return TabExtras.parse(tabType, cursor.getString(columnIndex));
}
@Override
public void writeField(ContentValues values, TabExtras object, String columnName, ParameterizedType fieldType) {
public void writeField(ContentValues values, TabExtras object, String columnName, ParameterizedType fieldType) throws IOException {
if (object == null) return;
values.put(columnName, JsonSerializer.serialize(object));
values.put(columnName, LoganSquare.serialize(object));
}
}

View File

@ -22,7 +22,7 @@ apply plugin: 'com.android.library'
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

View File

@ -23,7 +23,7 @@ android {
defaultConfig {
applicationId "org.mariotaku.twidere.donate.nyanwp"
minSdkVersion 20
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

View File

@ -23,7 +23,7 @@ android {
defaultConfig {
applicationId "org.mariotaku.twidere.donate.nyanwp"
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
versionCode 3
versionName "1.2"
}

View File

@ -22,7 +22,7 @@ apply plugin: 'com.android.library'
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

View File

@ -33,18 +33,19 @@ import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.model.ComposingStatus;
import org.mariotaku.twidere.model.ParcelableCredentials;
import org.mariotaku.twidere.model.ParcelableCredentialsCursorIndices;
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.provider.TwidereDataStore;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
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;
@ -245,6 +246,8 @@ public final class Twidere implements TwidereConstants {
if (cur.moveToFirst()) {
return ParcelableCredentialsCursorIndices.fromCursor(cur);
}
} catch (IOException e) {
return null;
} finally {
cur.close();
}

View File

@ -23,7 +23,7 @@ android {
defaultConfig {
applicationId "org.mariotaku.twidere"
minSdkVersion 20
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true

View File

@ -91,7 +91,7 @@ dependencies {
kapt 'com.bluelinelabs:logansquare-compiler:1.3.7'
kapt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
kapt 'com.google.dagger:dagger-compiler:2.6.1'
kapt 'com.github.mariotaku.ObjectCursor:processor:0.9.11'
kapt 'com.github.mariotaku.ObjectCursor:processor:0.9.12'
compile('com.github.mariotaku:app-theme-engine:1efc6237e1@aar') {
transitive = true
@ -102,8 +102,8 @@ dependencies {
compile project(':twidere.component.nyan')
// START Non-FOSS component
googleCompile 'com.google.android.gms:play-services-maps:9.8.0'
googleCompile 'com.google.android.gms:play-services-auth:9.8.0'
googleCompile 'com.google.android.gms:play-services-maps:10.0.0'
googleCompile 'com.google.android.gms:play-services-auth:10.0.0'
googleCompile 'com.google.maps.android:android-maps-utils:0.4.4'
googleCompile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true }
googleCompile ':YouTubeAndroidPlayerApi:1.2.2@jar'
@ -163,7 +163,7 @@ dependencies {
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.17'
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.17'
compile 'com.github.mariotaku.SQLiteQB:library:0.9.8'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.11'
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'

View File

@ -167,9 +167,9 @@ public abstract class UserStreamCallback implements RawCallback {
public abstract void onConnected();
public abstract void onStatus(Status status);
public abstract void onStatus(Status status) throws IOException;
public abstract void onDirectMessage(DirectMessage directMessage);
public abstract void onDirectMessage(DirectMessage directMessage) throws IOException;
public abstract void onBlock(User source, User blockedUser);

View File

@ -1,18 +0,0 @@
package org.mariotaku.twidere.model.tab.extra;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.CallSuper;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by mariotaku on 16/3/6.
*/
@JsonObject
public abstract class TabExtras implements Parcelable {
@CallSuper
public void copyToBundle(Bundle bundle) {
}
}

View File

@ -16,6 +16,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.TwidereArrayUtils;
import java.io.IOException;
import java.util.List;
/**
@ -45,6 +46,8 @@ public class ParcelableAccountUtils {
if (c.moveToFirst()) {
return i.newObject(c);
}
} catch (IOException e) {
return null;
} finally {
c.close();
}
@ -93,6 +96,8 @@ public class ParcelableAccountUtils {
cursor.moveToNext();
}
return names;
} catch (IOException e) {
return new ParcelableAccount[0];
} finally {
cursor.close();
}

View File

@ -11,6 +11,8 @@ import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.util.DataStoreUtils;
import java.io.IOException;
/**
* Created by mariotaku on 16/3/4.
*/
@ -38,6 +40,8 @@ public class ParcelableCredentialsUtils {
if (c.moveToFirst()) {
return i.newObject(c);
}
} catch (IOException e) {
return null;
} finally {
c.close();
}
@ -56,7 +60,9 @@ public class ParcelableCredentialsUtils {
cursor.moveToNext();
}
return credentialses;
} finally {
} catch (IOException e) {
return new ParcelableCredentials[0];
}finally {
cursor.close();
}
}

View File

@ -548,6 +548,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
try {
if (!c.moveToFirst()) return -1;
item = i.newObject(c);
} catch (IOException e) {
return -1;
} finally {
c.close();
}
@ -1462,6 +1464,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
builder.setDeleteIntent(getMarkReadDeleteIntent(context,
NotificationType.INTERACTIONS, accountKey, timestamp, false));
}
} catch (IOException e) {
return;
} finally {
c.close();
}

View File

@ -243,7 +243,7 @@ public class StreamingService extends Service implements Constants {
}
@Override
public void onDirectMessage(final DirectMessage directMessage) {
public void onDirectMessage(final DirectMessage directMessage) throws IOException {
if (directMessage == null || directMessage.getId() == null) return;
final String where = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY),
Expression.equalsArgs(DirectMessages.MESSAGE_ID)).getSQL();
@ -340,7 +340,7 @@ public class StreamingService extends Service implements Constants {
}
@Override
public void onStatus(final Status status) {
public void onStatus(final Status status) throws IOException {
final ContentValues values = ContentValuesCreator.createStatus(status, account.account_key);
if (!statusStreamStarted) {
statusStreamStarted = true;

View File

@ -31,6 +31,7 @@ import org.mariotaku.twidere.util.UriUtils;
import org.mariotaku.twidere.util.content.ContentResolverUtils;
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -123,7 +124,11 @@ public abstract class GetDirectMessagesTask extends AbstractTask<RefreshTaskPara
for (int i = 0, j = messages.size(); i < j; i++) {
final DirectMessage message = messages.get(i);
valuesArray[i] = ContentValuesCreator.createDirectMessage(message, accountKey, isOutgoing);
try {
valuesArray[i] = ContentValuesCreator.createDirectMessage(message, accountKey, isOutgoing);
} catch (IOException e) {
return false;
}
}
// Delete all rows conflicting before new data inserted.

View File

@ -26,6 +26,8 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.provider.TwidereDataStore.Tabs;
import org.mariotaku.twidere.util.JsonSerializer;
import java.io.IOException;
import kotlin.Pair;
/**
@ -108,6 +110,8 @@ public class UpdateAccountInfoTask extends AbstractTask<Pair<ParcelableAccount,
final String[] whereArgs = {String.valueOf(values.keyAt(i))};
resolver.update(Tabs.CONTENT_URI, values.valueAt(i), where, whereArgs);
}
} catch (IOException e) {
// Ignore
} finally {
tabsCursor.close();
}

View File

@ -52,6 +52,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.provider.TwidereDataStore.SavedSearches;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -60,7 +61,7 @@ public final class ContentValuesCreator implements TwidereConstants {
private ContentValuesCreator() {
}
public static ContentValues createCachedUser(final User user) {
public static ContentValues createCachedUser(final User user) throws IOException {
if (user == null) return null;
final ContentValues values = new ContentValues();
ParcelableUserValuesCreator.writeTo(ParcelableUserUtils.fromUser(user, null), values);
@ -69,12 +70,12 @@ public final class ContentValuesCreator implements TwidereConstants {
public static ContentValues createDirectMessage(final DirectMessage message,
final UserKey accountKey,
final boolean isOutgoing) {
final boolean isOutgoing) throws IOException {
return ParcelableDirectMessageValuesCreator.create(ParcelableDirectMessageUtils.fromDirectMessage(message,
accountKey, isOutgoing));
}
public static ContentValues createDirectMessage(final ParcelableDirectMessage message) {
public static ContentValues createDirectMessage(final ParcelableDirectMessage message) throws IOException {
if (message == null) return null;
final ContentValues values = new ContentValues();
ParcelableDirectMessageValuesCreator.writeTo(message, values);
@ -147,7 +148,7 @@ public final class ContentValuesCreator implements TwidereConstants {
}
@NonNull
public static ContentValues createStatus(final Status orig, final UserKey accountKey) {
public static ContentValues createStatus(final Status orig, final UserKey accountKey) throws IOException {
return ParcelableStatusValuesCreator.create(ParcelableStatusUtils.INSTANCE.fromStatus(orig,
accountKey, false));
}
@ -155,7 +156,7 @@ public final class ContentValuesCreator implements TwidereConstants {
@NonNull
public static ContentValues createActivity(final ParcelableActivity activity,
final ParcelableCredentials credentials,
final UserColorNameManager manager) {
final UserColorNameManager manager) throws IOException {
final ContentValues values = new ContentValues();
final ParcelableStatus status = ParcelableActivityExtensionsKt.getActivityStatus(activity);

View File

@ -44,14 +44,10 @@ import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.model.tab.DrawableHolder;
import org.mariotaku.twidere.model.tab.TabConfiguration;
import org.mariotaku.twidere.model.tab.argument.TabArguments;
import org.mariotaku.twidere.model.tab.argument.TextQueryArguments;
import org.mariotaku.twidere.model.tab.argument.UserArguments;
import org.mariotaku.twidere.model.tab.argument.UserListArguments;
import org.mariotaku.twidere.model.tab.extra.HomeTabExtras;
import org.mariotaku.twidere.model.tab.extra.InteractionsTabExtras;
import org.mariotaku.twidere.model.tab.extra.TabExtras;
import org.mariotaku.twidere.provider.TwidereDataStore.Tabs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -77,14 +73,20 @@ public class CustomTabUtils implements Constants {
final ContentResolver resolver = context.getContentResolver();
final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER);
if (cur == null) return Collections.emptyList();
final ArrayList<Tab> tabs = new ArrayList<>();
cur.moveToFirst();
TabCursorIndices indices = new TabCursorIndices(cur);
while (!cur.isAfterLast()) {
tabs.add(indices.newObject(cur));
cur.moveToNext();
try {
final ArrayList<Tab> tabs = new ArrayList<>();
cur.moveToFirst();
TabCursorIndices indices = new TabCursorIndices(cur);
while (!cur.isAfterLast()) {
tabs.add(indices.newObject(cur));
cur.moveToNext();
}
return tabs;
} catch (IOException e) {
return Collections.emptyList();
} finally {
cur.close();
}
return tabs;
}
public static List<SupportTabSpec> getHomeTabs(@NonNull final Context context) {
@ -120,47 +122,20 @@ public class CustomTabUtils implements Constants {
@Nullable
public static TabArguments newTabArguments(@NonNull @CustomTabType String type) {
return parseTabArguments(type, "{}");
try {
return TabArguments.parse(type, "{}");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Nullable
public static TabExtras newTabExtras(@NonNull @CustomTabType String type) {
return parseTabExtras(type, "{}");
}
@Nullable
public static TabArguments parseTabArguments(@NonNull @CustomTabType String type, String json) {
switch (type) {
case CustomTabType.HOME_TIMELINE:
case CustomTabType.NOTIFICATIONS_TIMELINE:
case CustomTabType.DIRECT_MESSAGES: {
return JsonSerializer.parse(json, TabArguments.class);
}
case CustomTabType.USER_TIMELINE:
case CustomTabType.FAVORITES: {
return JsonSerializer.parse(json, UserArguments.class);
}
case CustomTabType.LIST_TIMELINE: {
return JsonSerializer.parse(json, UserListArguments.class);
}
case CustomTabType.SEARCH_STATUSES: {
return JsonSerializer.parse(json, TextQueryArguments.class);
}
try {
return TabExtras.parse(type, "{}");
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
@Nullable
public static TabExtras parseTabExtras(@NonNull @CustomTabType String type, String json) {
switch (type) {
case CustomTabType.NOTIFICATIONS_TIMELINE: {
return JsonSerializer.parse(json, InteractionsTabExtras.class);
}
case CustomTabType.HOME_TIMELINE: {
return JsonSerializer.parse(json, HomeTabExtras.class);
}
}
return null;
}
@Nullable
@ -180,18 +155,7 @@ public class CustomTabUtils implements Constants {
public static TabConfiguration getTabConfiguration(final String tabType) {
if (tabType == null) return null;
return TabConfiguration.ofType(getTabTypeAlias(tabType));
}
@CustomTabType
public static String getTabTypeAlias(String key) {
if (key == null) return null;
switch (key) {
case "mentions_timeline":
case "activities_about_me":
return CustomTabType.NOTIFICATIONS_TIMELINE;
}
return key;
return TabConfiguration.ofType(Tab.getTypeAlias(tabType));
}
public static Drawable getTabIconDrawable(final Context context, final DrawableHolder icon) {
@ -221,7 +185,7 @@ public class CustomTabUtils implements Constants {
}
public static boolean isTabTypeValid(final String tabType) {
return tabType != null && TabConfiguration.ofType(getTabTypeAlias(tabType)) != null;
return tabType != null && TabConfiguration.ofType(Tab.getTypeAlias(tabType)) != null;
}
public static boolean hasAccountId(final Context context, @NonNull final Bundle args,

View File

@ -152,7 +152,7 @@ public class DataImportExportUtils implements Constants {
}
private static <T> List<T> queryAll(ContentResolver cr, Uri uri, String[] projection,
Class<? extends ObjectCursor.CursorIndices<T>> cls) {
Class<? extends ObjectCursor.CursorIndices<T>> cls) throws IOException {
Cursor c = cr.query(uri, projection, null, null, null);
if (c == null) return null;
try {
@ -241,7 +241,7 @@ public class DataImportExportUtils implements Constants {
if (hasFlag(flags, FLAG_FILTERS)) {
importItem(context, zipFile, ENTRY_FILTERS, FiltersData.class, new ContentResolverProcessStrategy<FiltersData>() {
@Override
public boolean importItem(ContentResolver cr, FiltersData filtersData) {
public boolean importItem(ContentResolver cr, FiltersData filtersData) throws IOException {
if (filtersData == null) return false;
insertBase(cr, Filters.Keywords.CONTENT_URI, filtersData.getKeywords());
insertBase(cr, Filters.Sources.CONTENT_URI, filtersData.getSources());
@ -250,7 +250,7 @@ public class DataImportExportUtils implements Constants {
return true;
}
void insertBase(ContentResolver cr, Uri uri, List<FiltersData.BaseItem> items) {
void insertBase(ContentResolver cr, Uri uri, List<FiltersData.BaseItem> items) throws IOException {
if (items == null) return;
List<ContentValues> values = new ArrayList<>(items.size());
for (FiltersData.BaseItem item : items) {
@ -259,7 +259,7 @@ public class DataImportExportUtils implements Constants {
ContentResolverUtils.bulkInsert(cr, uri, values);
}
void insertUser(ContentResolver cr, Uri uri, List<FiltersData.UserItem> items) {
void insertUser(ContentResolver cr, Uri uri, List<FiltersData.UserItem> items) throws IOException {
if (items == null) return;
List<ContentValues> values = new ArrayList<>(items.size());
for (FiltersData.UserItem item : items) {
@ -272,7 +272,7 @@ public class DataImportExportUtils implements Constants {
if (hasFlag(flags, FLAG_TABS)) {
importItemsList(context, zipFile, ENTRY_TABS, Tab.class, new ContentResolverProcessStrategy<List<Tab>>() {
@Override
public boolean importItem(ContentResolver cr, List<Tab> items) {
public boolean importItem(ContentResolver cr, List<Tab> items) throws IOException {
if (items == null) return false;
List<ContentValues> values = new ArrayList<>(items.size());
for (Tab item : items) {
@ -380,7 +380,7 @@ public class DataImportExportUtils implements Constants {
}
private interface ContentResolverProcessStrategy<T> {
boolean importItem(ContentResolver cr, T item);
boolean importItem(ContentResolver cr, T item) throws IOException;
}
private interface SharedPreferencesProcessStrategy {

View File

@ -1064,6 +1064,8 @@ public class DataStoreUtils implements Constants {
values.put(activity._id, ParcelableActivityValuesCreator.create(activity));
c.moveToNext();
}
} catch (IOException e) {
return;
} finally {
c.close();
}
@ -1110,7 +1112,7 @@ public class DataStoreUtils implements Constants {
}
public static int queryCount(@NonNull final Context context, @NonNull final Uri uri,
@Nullable final String selection, @Nullable final String[] selectionArgs) {
@Nullable final String selection, @Nullable final String[] selectionArgs) {
final ContentResolver resolver = context.getContentResolver();
final String[] projection = new String[]{SQLFunctions.COUNT()};
final Cursor cur = resolver.query(uri, projection, selection, selectionArgs, null);
@ -1137,20 +1139,25 @@ public class DataStoreUtils implements Constants {
final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, selection, null, Accounts.SORT_POSITION);
if (cur == null) return accounts;
final ParcelableCredentialsCursorIndices indices = new ParcelableCredentialsCursorIndices(cur);
cur.moveToFirst();
while (!cur.isAfterLast()) {
if (!officialKeyOnly) {
accounts.add(indices.newObject(cur));
} else {
final String consumerKey = cur.getString(indices.consumer_key);
final String consumerSecret = cur.getString(indices.consumer_secret);
if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) {
try {
cur.moveToFirst();
while (!cur.isAfterLast()) {
if (!officialKeyOnly) {
accounts.add(indices.newObject(cur));
} else {
final String consumerKey = cur.getString(indices.consumer_key);
final String consumerSecret = cur.getString(indices.consumer_secret);
if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) {
accounts.add(indices.newObject(cur));
}
}
cur.moveToNext();
}
cur.moveToNext();
} catch (IOException e) {
return Collections.emptyList();
} finally {
cur.close();
}
cur.close();
return accounts;
}
@ -1225,19 +1232,24 @@ public class DataStoreUtils implements Constants {
if (cur == null) return accounts;
ParcelableCredentialsCursorIndices indices = new ParcelableCredentialsCursorIndices(cur);
cur.moveToFirst();
while (!cur.isAfterLast()) {
if (officialKeyOnly) {
final String consumerKey = cur.getString(indices.consumer_key);
final String consumerSecret = cur.getString(indices.consumer_secret);
if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) {
try {
while (!cur.isAfterLast()) {
if (officialKeyOnly) {
final String consumerKey = cur.getString(indices.consumer_key);
final String consumerSecret = cur.getString(indices.consumer_secret);
if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) {
accounts.add(indices.newObject(cur));
}
} else {
accounts.add(indices.newObject(cur));
}
} else {
accounts.add(indices.newObject(cur));
cur.moveToNext();
}
cur.moveToNext();
} catch (IOException e) {
return Collections.emptyList();
} finally {
cur.close();
}
cur.close();
return accounts;
}

View File

@ -111,6 +111,7 @@ import org.mariotaku.twidere.model.ParcelableCredentials;
import org.mariotaku.twidere.model.ParcelableDirectMessage;
import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableStatusValuesCreator;
import org.mariotaku.twidere.model.ParcelableStatusCursorIndices;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.model.ParcelableUserMention;
@ -422,10 +423,15 @@ public final class Utils implements Constants {
if (cur == null) {
continue;
}
if (cur.getCount() > 0 && cur.moveToFirst()) {
message = ParcelableDirectMessageCursorIndices.fromCursor(cur);
try {
if (cur.getCount() > 0 && cur.moveToFirst()) {
message = ParcelableDirectMessageCursorIndices.fromCursor(cur);
}
} catch (IOException e) {
// Ignore
} finally {
cur.close();
}
cur.close();
}
return message;
}
@ -440,14 +446,19 @@ public final class Utils implements Constants {
if (cached != null) return cached;
final MicroBlog twitter = MicroBlogAPIFactory.getInstance(context, accountKey, true);
if (twitter == null) throw new MicroBlogException("Account does not exist");
final Status status = twitter.showStatus(statusId);
final Status result = twitter.showStatus(statusId);
final String where = Expression.and(Expression.equalsArgs(Statuses.ACCOUNT_KEY),
Expression.equalsArgs(Statuses.STATUS_ID)).getSQL();
final String[] whereArgs = {accountKey.toString(), statusId};
final ContentResolver resolver = context.getContentResolver();
final ParcelableStatus status = ParcelableStatusUtils.INSTANCE.fromStatus(result, accountKey, false);
resolver.delete(CachedStatuses.CONTENT_URI, where, whereArgs);
resolver.insert(CachedStatuses.CONTENT_URI, ContentValuesCreator.createStatus(status, accountKey));
return ParcelableStatusUtils.INSTANCE.fromStatus(status, accountKey, false);
try {
resolver.insert(CachedStatuses.CONTENT_URI, ParcelableStatusValuesCreator.create(status));
} catch (IOException e) {
// Ignore
}
return status;
}
@Nullable
@ -465,11 +476,15 @@ public final class Utils implements Constants {
if (cur == null) {
continue;
}
if (cur.getCount() > 0) {
cur.moveToFirst();
status = ParcelableStatusCursorIndices.fromCursor(cur);
try {
if (cur.getCount() > 0 && cur.moveToFirst()) {
status = ParcelableStatusCursorIndices.fromCursor(cur);
}
} catch (IOException e) {
// Ignore
} finally {
cur.close();
}
cur.close();
}
return status;
}

View File

@ -71,6 +71,7 @@ import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback
import org.mariotaku.twidere.graphic.EmptyDrawable
import org.mariotaku.twidere.model.ParcelableAccount
import org.mariotaku.twidere.model.SupportTabSpec
import org.mariotaku.twidere.model.Tab
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.message.TaskStateChangedEvent
import org.mariotaku.twidere.model.message.UnreadCountUpdatedEvent
@ -681,7 +682,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
val accountKey = UserKey.valueOf(uri!!.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY))
for (i in 0 until pagerAdapter!!.count) {
val tab = pagerAdapter!!.getTab(i)
if (tabType == CustomTabUtils.getTabTypeAlias(tab.type)) {
if (tabType == Tab.getTypeAlias(tab.type)) {
val args = tab.args
if (args != null && CustomTabUtils.hasAccountId(this, args,
activatedAccountKeys, accountKey)) {

View File

@ -32,6 +32,7 @@ import org.mariotaku.twidere.annotation.NotificationType
import org.mariotaku.twidere.annotation.ReadPositionTag
import org.mariotaku.twidere.constant.IntentConstants.BROADCAST_NOTIFICATION_DELETED
import org.mariotaku.twidere.model.StringLongPair
import org.mariotaku.twidere.model.Tab
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.util.CustomTabUtils
import org.mariotaku.twidere.util.UriExtraUtils
@ -56,7 +57,7 @@ class NotificationReceiver : BroadcastReceiver() {
val itemUserId = UriExtraUtils.getExtra(uri, "item_user_id")?.toLong(-1) ?: -1
val itemUserFollowing = UriExtraUtils.getExtra(uri, "item_user_following")?.toBoolean() ?: false
val timestamp = uri.getQueryParameter(QUERY_PARAM_TIMESTAMP)?.toLong() ?: -1
if (CustomTabType.NOTIFICATIONS_TIMELINE == CustomTabUtils.getTabTypeAlias(notificationType)
if (CustomTabType.NOTIFICATIONS_TIMELINE == Tab.getTypeAlias(notificationType)
&& accountKey != null && itemId != -1L && timestamp != -1L) {
val logger = holder.hotMobiLogger
logger.log(accountKey, NotificationEvent.deleted(context, timestamp, notificationType, accountKey,

View File

@ -274,8 +274,8 @@
<FrameLayout
android:id="@+id/quotedMediaPreviewContainer"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="@dimen/element_spacing_normal"
android:layout_marginLeft="@dimen/element_spacing_normal"
@ -300,13 +300,15 @@
</org.mariotaku.twidere.view.CardMediaContainer>
<ImageView
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/quotedMediaPreviewPlaceholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:scaleType="center"
android:src="@drawable/ic_action_gallery"/>
android:src="@drawable/ic_action_gallery"
android:visibility="visible"
app:iabColor="?android:textColorSecondary"
tools:visibility="gone"/>
</FrameLayout>
<LinearLayout
@ -362,8 +364,8 @@
android:drawablePadding="4dp"
android:drawableStart="@drawable/ic_indicator_location"
android:gravity="center_vertical"
android:maxLines="1"
android:padding="@dimen/element_spacing_normal"
android:singleLine="true"
android:tag="font_family|user"
android:text="@string/view_map"
android:textAppearance="?android:attr/textAppearanceSmall"