fixed build problems
This commit is contained in:
parent
40ffa4a47e
commit
94ee907417
|
@ -1,11 +1,12 @@
|
|||
package org.mariotaku.twidere.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
||||
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorField;
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorObject;
|
||||
import org.mariotaku.microblog.library.twitter.model.Relationship;
|
||||
import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
||||
|
@ -13,8 +14,9 @@ import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
|||
/**
|
||||
* Created by mariotaku on 16/2/1.
|
||||
*/
|
||||
@ParcelablePlease
|
||||
@CursorObject(valuesCreator = true, tableInfo = true)
|
||||
public class CachedRelationship {
|
||||
public class ParcelableRelationship implements Parcelable {
|
||||
|
||||
@CursorField(value = CachedRelationships.ACCOUNT_KEY, converter = UserKeyCursorFieldConverter.class)
|
||||
public UserKey account_key;
|
||||
|
@ -43,20 +45,29 @@ public class CachedRelationship {
|
|||
@CursorField(value = CachedRelationships._ID, excludeWrite = true, type = TwidereDataStore.TYPE_PRIMARY_KEY)
|
||||
public long _id;
|
||||
|
||||
public CachedRelationship() {
|
||||
public boolean can_dm;
|
||||
|
||||
public boolean filtering;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public CachedRelationship(@Nullable Relationship relationship, @NonNull UserKey accountKey, @NonNull UserKey userKey) {
|
||||
account_key = accountKey;
|
||||
user_key = userKey;
|
||||
if (relationship != null) {
|
||||
following = relationship.isSourceFollowingTarget();
|
||||
followed_by = relationship.isSourceFollowedByTarget();
|
||||
blocking = relationship.isSourceBlockingTarget();
|
||||
blocked_by = relationship.isSourceBlockedByTarget();
|
||||
muting = relationship.isSourceMutingTarget();
|
||||
retweet_enabled = relationship.isSourceWantRetweetsFromTarget();
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
ParcelableRelationshipParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public static final Creator<ParcelableRelationship> CREATOR = new Creator<ParcelableRelationship>() {
|
||||
public ParcelableRelationship createFromParcel(Parcel source) {
|
||||
ParcelableRelationship target = new ParcelableRelationship();
|
||||
ParcelableRelationshipParcelablePlease.readFromParcel(target, source);
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
public ParcelableRelationship[] newArray(int size) {
|
||||
return new ParcelableRelationship[size];
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.Relationship;
|
||||
import org.mariotaku.twidere.model.ParcelableRelationship;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/11/26.
|
||||
*/
|
||||
|
||||
public class ParcelableRelationshipUtils {
|
||||
|
||||
public static ParcelableRelationship create(@NonNull UserKey accountKey, @NonNull UserKey userKey,
|
||||
@Nullable Relationship relationship, boolean filtering) {
|
||||
ParcelableRelationship obj = new ParcelableRelationship();
|
||||
obj.account_key = accountKey;
|
||||
obj.user_key = userKey;
|
||||
if (relationship != null) {
|
||||
obj.following = relationship.isSourceFollowingTarget();
|
||||
obj.followed_by = relationship.isSourceFollowedByTarget();
|
||||
obj.blocking = relationship.isSourceBlockingTarget();
|
||||
obj.blocked_by = relationship.isSourceBlockedByTarget();
|
||||
obj.muting = relationship.isSourceMutingTarget();
|
||||
obj.retweet_enabled = relationship.isSourceWantRetweetsFromTarget();
|
||||
obj.can_dm = relationship.canSourceDMTarget();
|
||||
}
|
||||
obj.filtering = filtering;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static ParcelableRelationship create(ParcelableUser user, boolean filtering) {
|
||||
ParcelableRelationship obj = new ParcelableRelationship();
|
||||
obj.account_key = user.account_key;
|
||||
obj.user_key = user.key;
|
||||
obj.filtering = filtering;
|
||||
if (user.extras != null) {
|
||||
obj.following = user.is_following;
|
||||
obj.followed_by = user.extras.followed_by;
|
||||
obj.blocking = user.extras.blocking;
|
||||
obj.blocked_by = user.extras.blocked_by;
|
||||
obj.can_dm = user.extras.followed_by;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
|
@ -1,93 +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.task;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
|
||||
import com.twitter.Extractor;
|
||||
|
||||
import org.mariotaku.abstask.library.AbstractTask;
|
||||
import org.mariotaku.microblog.library.twitter.model.Status;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedHashtags;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers;
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator;
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils;
|
||||
import org.mariotaku.twidere.util.TwitterWrapper.TwitterListResponse;
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CacheUsersStatusesTask extends AbstractTask<TwitterListResponse<Status>, Object, Object> {
|
||||
|
||||
private final Context context;
|
||||
|
||||
public CacheUsersStatusesTask(final Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object doLongOperation(final TwitterListResponse<Status> params) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final Extractor extractor = new Extractor();
|
||||
|
||||
if (params == null || !params.hasData()) {
|
||||
return null;
|
||||
}
|
||||
final List<Status> list = params.getData();
|
||||
for (int bulkIdx = 0, totalSize = list.size(); bulkIdx < totalSize; bulkIdx += 100) {
|
||||
for (int idx = bulkIdx, end = Math.min(totalSize, bulkIdx + ContentResolverUtils.MAX_BULK_COUNT); idx < end; idx++) {
|
||||
final Status status = list.get(idx);
|
||||
|
||||
final Set<ContentValues> usersValues = new HashSet<>();
|
||||
final Set<ContentValues> statusesValues = new HashSet<>();
|
||||
final Set<ContentValues> hashTagValues = new HashSet<>();
|
||||
|
||||
final UserKey accountKey = params.accountKey;
|
||||
statusesValues.add(ContentValuesCreator.createStatus(status, accountKey));
|
||||
final String text = InternalTwitterContentUtils.unescapeTwitterStatusText(status.getExtendedText());
|
||||
for (final String hashtag : extractor.extractHashtags(text)) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(CachedHashtags.NAME, hashtag);
|
||||
hashTagValues.add(values);
|
||||
}
|
||||
final ContentValues cachedUser = ContentValuesCreator.createCachedUser(status.getUser());
|
||||
cachedUser.put(CachedUsers.LAST_SEEN, System.currentTimeMillis());
|
||||
usersValues.add(cachedUser);
|
||||
if (status.isRetweet()) {
|
||||
final ContentValues cachedRetweetedUser = ContentValuesCreator.createCachedUser(status.getRetweetedStatus().getUser());
|
||||
cachedRetweetedUser.put(CachedUsers.LAST_SEEN, System.currentTimeMillis());
|
||||
usersValues.add(cachedRetweetedUser);
|
||||
}
|
||||
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues);
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues);
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,15 +23,12 @@ import android.content.ContentValues;
|
|||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.DirectMessage;
|
||||
import org.mariotaku.microblog.library.twitter.model.Relationship;
|
||||
import org.mariotaku.microblog.library.twitter.model.SavedSearch;
|
||||
import org.mariotaku.microblog.library.twitter.model.Status;
|
||||
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.CachedRelationship;
|
||||
import org.mariotaku.twidere.model.CachedRelationshipValuesCreator;
|
||||
import org.mariotaku.twidere.model.Draft;
|
||||
import org.mariotaku.twidere.model.ParcelableActivity;
|
||||
import org.mariotaku.twidere.model.ParcelableActivityValuesCreator;
|
||||
|
@ -63,13 +60,6 @@ public final class ContentValuesCreator implements TwidereConstants {
|
|||
private ContentValuesCreator() {
|
||||
}
|
||||
|
||||
public static ContentValues createCachedRelationship(final Relationship relationship,
|
||||
final UserKey accountKey,
|
||||
final UserKey userKey) {
|
||||
CachedRelationship cached = new CachedRelationship(relationship, accountKey, userKey);
|
||||
return CachedRelationshipValuesCreator.create(cached);
|
||||
}
|
||||
|
||||
public static ContentValues createCachedUser(final User user) {
|
||||
if (user == null) return null;
|
||||
final ContentValues values = new ContentValues();
|
||||
|
|
|
@ -22,14 +22,14 @@ package org.mariotaku.twidere.util;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nostra13.universalimageloader.utils.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.mariotaku.twidere.util.Utils.closeSilently;
|
||||
|
||||
public class ImageValidator {
|
||||
|
||||
public static int INVALID = 0;
|
||||
|
@ -103,7 +103,7 @@ public class ImageValidator {
|
|||
} catch (final IOException e) {
|
||||
return INVALID;
|
||||
} finally {
|
||||
closeSilently(raf);
|
||||
IoUtils.closeSilently(raf);
|
||||
}
|
||||
return VALID_FOR_ALL;
|
||||
}
|
||||
|
|
|
@ -90,9 +90,7 @@ import org.apache.commons.lang3.math.NumberUtils;
|
|||
import org.json.JSONException;
|
||||
import org.mariotaku.microblog.library.MicroBlog;
|
||||
import org.mariotaku.microblog.library.MicroBlogException;
|
||||
import org.mariotaku.microblog.library.twitter.model.GeoLocation;
|
||||
import org.mariotaku.microblog.library.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.microblog.library.twitter.model.Relationship;
|
||||
import org.mariotaku.microblog.library.twitter.model.Status;
|
||||
import org.mariotaku.sqliteqb.library.AllColumns;
|
||||
import org.mariotaku.sqliteqb.library.Columns;
|
||||
|
@ -125,7 +123,6 @@ import org.mariotaku.twidere.model.util.ParcelableUserUtils;
|
|||
import org.mariotaku.twidere.model.util.UserKeyUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages;
|
||||
|
@ -324,12 +321,6 @@ public final class Utils implements Constants {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean closeSilently(final Cursor c) {
|
||||
if (c == null) return false;
|
||||
c.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void configBaseAdapter(final Context context, final IBaseAdapter adapter) {
|
||||
if (context == null) return;
|
||||
final SharedPreferences pref = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
|
@ -1269,14 +1260,6 @@ public final class Utils implements Constants {
|
|||
return orig.replaceAll("\\n+", "\n");
|
||||
}
|
||||
|
||||
public static void updateRelationship(Context context, UserKey accountKey, UserKey userKey,
|
||||
Relationship relationship) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final ContentValues values = ContentValuesCreator.createCachedRelationship(relationship,
|
||||
accountKey, userKey);
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, values);
|
||||
}
|
||||
|
||||
private static Drawable getMetadataDrawable(final PackageManager pm, final ActivityInfo info, final String key) {
|
||||
if (pm == null || info == null || info.metaData == null || key == null || !info.metaData.containsKey(key))
|
||||
return null;
|
||||
|
@ -1482,13 +1465,6 @@ public final class Utils implements Constants {
|
|||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GeoLocation getCachedGeoLocation(Context context) {
|
||||
final Location location = getCachedLocation(context);
|
||||
if (location == null) return null;
|
||||
return new GeoLocation(location.getLatitude(), location.getLongitude());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Location getCachedLocation(Context context) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
|
|
@ -62,7 +62,6 @@ import org.mariotaku.twidere.util.TwidereQueryBuilder.DirectMessagesQueryBuilder
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.mariotaku.twidere.util.Utils.trim;
|
||||
import static org.mariotaku.twidere.util.content.DatabaseUpgradeHelper.safeUpgrade;
|
||||
|
||||
public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements Constants {
|
||||
|
@ -210,10 +209,12 @@ public final class TwidereSQLiteOpenHelper extends SQLiteOpenHelper implements C
|
|||
.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
// Here I use old consumer key/secret because it's default key for
|
||||
// older versions
|
||||
final String pref_consumer_key = prefs.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY_LEGACY);
|
||||
final String pref_consumer_secret = prefs.getString(KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET_LEGACY);
|
||||
values.put(Accounts.CONSUMER_KEY, trim(pref_consumer_key));
|
||||
values.put(Accounts.CONSUMER_SECRET, trim(pref_consumer_secret));
|
||||
final String prefConsumerKey = prefs.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY_LEGACY);
|
||||
final String prefConsumerSecret = prefs.getString(KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET_LEGACY);
|
||||
if (prefConsumerKey != null && prefConsumerSecret != null) {
|
||||
values.put(Accounts.CONSUMER_KEY, prefConsumerKey.trim());
|
||||
values.put(Accounts.CONSUMER_SECRET, prefConsumerSecret.trim());
|
||||
}
|
||||
db.update(Accounts.TABLE_NAME, values, null, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,8 +250,8 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
|
|||
apiUrlFormat = savedInstanceState.getString(Accounts.API_URL_FORMAT)
|
||||
authType = savedInstanceState.getInt(Accounts.AUTH_TYPE)
|
||||
sameOAuthSigningUrl = savedInstanceState.getBoolean(Accounts.SAME_OAUTH_SIGNING_URL)
|
||||
consumerKey = Utils.trim(savedInstanceState.getString(Accounts.CONSUMER_KEY))
|
||||
consumerSecret = Utils.trim(savedInstanceState.getString(Accounts.CONSUMER_SECRET))
|
||||
consumerKey = savedInstanceState.getString(Accounts.CONSUMER_KEY)?.trim()
|
||||
consumerSecret = savedInstanceState.getString(Accounts.CONSUMER_SECRET)?.trim()
|
||||
apiChangeTimestamp = savedInstanceState.getLong(EXTRA_API_LAST_CHANGE)
|
||||
}
|
||||
|
||||
|
|
|
@ -144,12 +144,12 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
|||
|
||||
setContentView(R.layout.activity_api_editor)
|
||||
|
||||
val apiUrlFormat: String
|
||||
val apiUrlFormat: String?
|
||||
val authType: Int
|
||||
val sameOAuthSigningUrl: Boolean
|
||||
val noVersionSuffix: Boolean
|
||||
val consumerKey: String
|
||||
val consumerSecret: String
|
||||
val consumerKey: String?
|
||||
val consumerSecret: String?
|
||||
|
||||
val pref = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
val prefApiUrlFormat = Utils.getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT)
|
||||
|
@ -166,12 +166,12 @@ class APIEditorActivity : BaseActivity(), OnCheckedChangeListener, OnClickListen
|
|||
} else {
|
||||
bundle = Bundle()
|
||||
}
|
||||
apiUrlFormat = Utils.trim(bundle.getString(Accounts.API_URL_FORMAT, prefApiUrlFormat))
|
||||
apiUrlFormat = bundle.getString(Accounts.API_URL_FORMAT, prefApiUrlFormat)?.trim()
|
||||
authType = bundle.getInt(Accounts.AUTH_TYPE, prefAuthType)
|
||||
sameOAuthSigningUrl = bundle.getBoolean(Accounts.SAME_OAUTH_SIGNING_URL, prefSameOAuthSigningUrl)
|
||||
noVersionSuffix = bundle.getBoolean(Accounts.NO_VERSION_SUFFIX, prefNoVersionSuffix)
|
||||
consumerKey = Utils.trim(bundle.getString(Accounts.CONSUMER_KEY, prefConsumerKey))
|
||||
consumerSecret = Utils.trim(bundle.getString(Accounts.CONSUMER_SECRET, prefConsumerSecret))
|
||||
consumerKey = bundle.getString(Accounts.CONSUMER_KEY, prefConsumerKey)?.trim()
|
||||
consumerSecret = bundle.getString(Accounts.CONSUMER_SECRET, prefConsumerSecret)?.trim()
|
||||
|
||||
editAuthType.setOnCheckedChangeListener(this)
|
||||
editNoVersionSuffix.setOnCheckedChangeListener(this)
|
||||
|
|
|
@ -181,12 +181,12 @@ class ImagePageFragment : SubsampleImageViewerFragment() {
|
|||
|
||||
@Throws(IOException::class)
|
||||
internal fun decodeBitmap(cr: ContentResolver, uri: Uri, o: BitmapFactory.Options): Bitmap? {
|
||||
var `is`: InputStream? = null
|
||||
var st: InputStream? = null
|
||||
try {
|
||||
`is` = cr.openInputStream(uri)
|
||||
return BitmapFactory.decodeStream(`is`, null, o)
|
||||
st = cr.openInputStream(uri)
|
||||
return BitmapFactory.decodeStream(st, null, o)
|
||||
} finally {
|
||||
Utils.closeSilently(`is`)
|
||||
Utils.closeSilently(st)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,6 @@ import org.mariotaku.ktextension.toTypedArray
|
|||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.FriendshipUpdate
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.Relationship
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.R
|
||||
|
@ -145,7 +144,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
var user: ParcelableUser? = null
|
||||
private set
|
||||
private var account: ParcelableAccount? = null
|
||||
private var relationship: UserRelationship? = null
|
||||
private var relationship: ParcelableRelationship? = null
|
||||
private var locale: Locale? = null
|
||||
private var mGetUserInfoLoaderInitialized: Boolean = false
|
||||
private var mGetFriendShipLoaderInitialized: Boolean = false
|
||||
|
@ -161,9 +160,9 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
private var mHideBirthdayView: Boolean = false
|
||||
private var userEvent: UserEvent? = null
|
||||
|
||||
private val friendshipLoaderCallbacks = object : LoaderCallbacks<SingleResponse<UserRelationship>> {
|
||||
private val friendshipLoaderCallbacks = object : LoaderCallbacks<SingleResponse<ParcelableRelationship>> {
|
||||
|
||||
override fun onCreateLoader(id: Int, args: Bundle): Loader<SingleResponse<UserRelationship>> {
|
||||
override fun onCreateLoader(id: Int, args: Bundle): Loader<SingleResponse<ParcelableRelationship>> {
|
||||
invalidateOptionsMenu()
|
||||
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
|
||||
val user = args.getParcelable<ParcelableUser>(EXTRA_USER)
|
||||
|
@ -179,12 +178,12 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
return UserRelationshipLoader(activity, accountKey, user)
|
||||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<SingleResponse<UserRelationship>>) {
|
||||
override fun onLoaderReset(loader: Loader<SingleResponse<ParcelableRelationship>>) {
|
||||
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<SingleResponse<UserRelationship>>,
|
||||
data: SingleResponse<UserRelationship>) {
|
||||
override fun onLoadFinished(loader: Loader<SingleResponse<ParcelableRelationship>>,
|
||||
data: SingleResponse<ParcelableRelationship>) {
|
||||
followProgress!!.visibility = View.GONE
|
||||
val relationship = data.data
|
||||
displayRelationship(user, relationship)
|
||||
|
@ -263,7 +262,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
}
|
||||
|
||||
private fun displayRelationship(user: ParcelableUser?,
|
||||
userRelationship: UserRelationship?) {
|
||||
userRelationship: ParcelableRelationship?) {
|
||||
if (user == null) {
|
||||
relationship = null
|
||||
return
|
||||
|
@ -311,7 +310,7 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
task {
|
||||
val resolver = contentResolver;
|
||||
resolver.insert(CachedUsers.CONTENT_URI, ParcelableUserValuesCreator.create(user))
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, CachedRelationshipValuesCreator.create(userRelationship))
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, ParcelableRelationshipValuesCreator.create(userRelationship))
|
||||
}
|
||||
followContainer.follow.visibility = View.VISIBLE
|
||||
}
|
||||
|
@ -1527,26 +1526,26 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
context: Context,
|
||||
private val accountKey: UserKey?,
|
||||
private val user: ParcelableUser?
|
||||
) : AsyncTaskLoader<SingleResponse<UserRelationship>>(context) {
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableRelationship>>(context) {
|
||||
|
||||
override fun loadInBackground(): SingleResponse<UserRelationship> {
|
||||
override fun loadInBackground(): SingleResponse<ParcelableRelationship> {
|
||||
if (accountKey == null || user == null) {
|
||||
return SingleResponse.Companion.getInstance<UserRelationship>(MicroBlogException("Null parameters"))
|
||||
return SingleResponse.Companion.getInstance<ParcelableRelationship>(MicroBlogException("Null parameters"))
|
||||
}
|
||||
val userKey = user.key
|
||||
val isFiltering = DataStoreUtils.isFilteringUser(context, userKey)
|
||||
if (accountKey == user.key) {
|
||||
return SingleResponse.Companion.getInstance(UserRelationship(accountKey, userKey,
|
||||
return SingleResponse.getInstance(ParcelableRelationshipUtils.create(accountKey, userKey,
|
||||
null, isFiltering))
|
||||
}
|
||||
val credentials = ParcelableCredentialsUtils.getCredentials(context,
|
||||
accountKey) ?: return SingleResponse.Companion.getInstance<UserRelationship>(MicroBlogException("No Account"))
|
||||
accountKey) ?: return SingleResponse.getInstance<ParcelableRelationship>(MicroBlogException("No Account"))
|
||||
if (MicroBlogAPIFactory.isStatusNetCredentials(credentials)) {
|
||||
if (!UserKeyUtils.isSameHost(accountKey, user.key)) {
|
||||
return SingleResponse.Companion.getInstance(UserRelationship(user, isFiltering))
|
||||
return SingleResponse.getInstance(ParcelableRelationshipUtils.create(user, isFiltering))
|
||||
}
|
||||
}
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, accountKey, false) ?: return SingleResponse.Companion.getInstance<UserRelationship>(MicroBlogException("No Account"))
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, accountKey, false) ?: return SingleResponse.Companion.getInstance<ParcelableRelationship>(MicroBlogException("No Account"))
|
||||
try {
|
||||
val relationship = twitter.showFriendship(user.key.id)
|
||||
if (relationship.isSourceBlockingTarget || relationship.isSourceBlockedByTarget) {
|
||||
|
@ -1554,11 +1553,14 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
} else {
|
||||
Utils.setLastSeen(context, userKey, System.currentTimeMillis())
|
||||
}
|
||||
Utils.updateRelationship(context, accountKey, userKey, relationship)
|
||||
return SingleResponse.Companion.getInstance(UserRelationship(accountKey, userKey,
|
||||
relationship, isFiltering))
|
||||
val data = ParcelableRelationshipUtils.create(accountKey, userKey, relationship,
|
||||
isFiltering)
|
||||
val resolver = context.contentResolver
|
||||
val values = ParcelableRelationshipValuesCreator.create(data)
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, values)
|
||||
return SingleResponse.getInstance(data)
|
||||
} catch (e: MicroBlogException) {
|
||||
return SingleResponse.Companion.getInstance<UserRelationship>(e)
|
||||
return SingleResponse.Companion.getInstance<ParcelableRelationship>(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1568,40 +1570,15 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
|||
}
|
||||
}
|
||||
|
||||
internal class UserRelationship : CachedRelationship {
|
||||
var filtering: Boolean = false
|
||||
var can_dm: Boolean = false
|
||||
|
||||
constructor(accountKey: UserKey, userKey: UserKey,
|
||||
relationship: Relationship?, filtering: Boolean) : super(relationship, accountKey, userKey) {
|
||||
this.filtering = filtering
|
||||
if (relationship != null) {
|
||||
this.can_dm = relationship.canSourceDMTarget()
|
||||
}
|
||||
private fun ParcelableRelationship.check(user: ParcelableUser): Boolean {
|
||||
if (account_key != user.account_key) {
|
||||
return false
|
||||
}
|
||||
|
||||
constructor(user: ParcelableUser, filtering: Boolean) {
|
||||
this.account_key = user.account_key
|
||||
this.user_key = user.key
|
||||
this.filtering = filtering
|
||||
if (user.extras != null) {
|
||||
this.following = user.is_following
|
||||
this.followed_by = user.extras.followed_by
|
||||
this.blocking = user.extras.blocking
|
||||
this.blocked_by = user.extras.blocked_by
|
||||
this.can_dm = user.extras.followed_by
|
||||
}
|
||||
}
|
||||
|
||||
fun check(user: ParcelableUser): Boolean {
|
||||
if (account_key != user.account_key) {
|
||||
return false
|
||||
}
|
||||
return user.extras != null && TextUtils.equals(user_key.id, user.extras.unique_id) || TextUtils.equals(user_key.id, user.key.id)
|
||||
}
|
||||
|
||||
return user.extras != null && TextUtils.equals(user_key.id, user.extras.unique_id) || TextUtils.equals(user_key.id, user.key.id)
|
||||
}
|
||||
|
||||
|
||||
class AddRemoveUserListDialogFragment : BaseDialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val lists = arguments.getParcelableArray(EXTRA_USER_LISTS).toTypedArray(ParcelableUserList.CREATOR)
|
||||
|
|
|
@ -79,14 +79,6 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), MediaPlayer.OnPrep
|
|||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onCompletion(mp: MediaPlayer) {
|
||||
updatePlayerState()
|
||||
// mVideoViewProgress.removeCallbacks(mVideoProgressRunnable);
|
||||
|
|
|
@ -219,11 +219,11 @@ class BackgroundOperationService : IntentService("background_operation"), Consta
|
|||
|
||||
val resolver = contentResolver
|
||||
if (result.hasData()) {
|
||||
val message = result.data
|
||||
val message = result.data!!
|
||||
val values = ContentValuesCreator.createDirectMessage(message)
|
||||
val deleteWhere = Expression.and(Expression.equalsArgs(DirectMessages.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(DirectMessages.MESSAGE_ID)).sql
|
||||
val deleteWhereArgs = arrayOf(message!!.account_key.toString(), message.id)
|
||||
val deleteWhereArgs = arrayOf(message.account_key.toString(), message.id)
|
||||
resolver.delete(DirectMessages.Outbox.CONTENT_URI, deleteWhere, deleteWhereArgs)
|
||||
resolver.insert(DirectMessages.Outbox.CONTENT_URI, values)
|
||||
showOkMessage(R.string.direct_message_sent, false)
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.task
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import com.twitter.Extractor
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils
|
||||
import org.mariotaku.twidere.util.TwitterWrapper.TwitterListResponse
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils
|
||||
import java.util.*
|
||||
|
||||
class CacheUsersStatusesTask(private val context: Context) : AbstractTask<TwitterListResponse<Status>, Any, Any>() {
|
||||
|
||||
public override fun doLongOperation(params: TwitterListResponse<Status>): Any? {
|
||||
val resolver = context.contentResolver
|
||||
val extractor = Extractor()
|
||||
val list = params.data ?: return null
|
||||
var bulkIdx = 0
|
||||
val totalSize = list.size
|
||||
while (bulkIdx < totalSize) {
|
||||
var idx = bulkIdx
|
||||
val end = Math.min(totalSize, bulkIdx + ContentResolverUtils.MAX_BULK_COUNT)
|
||||
while (idx < end) {
|
||||
val status = list.get(idx)
|
||||
|
||||
val usersValues = HashSet<ContentValues>()
|
||||
val statusesValues = HashSet<ContentValues>()
|
||||
val hashTagValues = HashSet<ContentValues>()
|
||||
|
||||
val accountKey = params.accountKey
|
||||
statusesValues.add(ContentValuesCreator.createStatus(status, accountKey))
|
||||
val text = InternalTwitterContentUtils.unescapeTwitterStatusText(status.getExtendedText())
|
||||
for (hashtag in extractor.extractHashtags(text)) {
|
||||
val values = ContentValues()
|
||||
values.put(CachedHashtags.NAME, hashtag)
|
||||
hashTagValues.add(values)
|
||||
}
|
||||
val cachedUser = ContentValuesCreator.createCachedUser(status.getUser())
|
||||
cachedUser.put(CachedUsers.LAST_SEEN, System.currentTimeMillis())
|
||||
usersValues.add(cachedUser)
|
||||
if (status.isRetweet()) {
|
||||
val cachedRetweetedUser = ContentValuesCreator.createCachedUser(status.getRetweetedStatus().getUser())
|
||||
cachedRetweetedUser.put(CachedUsers.LAST_SEEN, System.currentTimeMillis())
|
||||
usersValues.add(cachedRetweetedUser)
|
||||
}
|
||||
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues)
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues)
|
||||
ContentResolverUtils.bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues)
|
||||
idx++
|
||||
}
|
||||
bulkIdx += 100
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue