mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
language migration
This commit is contained in:
parent
841dfbda0d
commit
533d8ad26b
@ -297,10 +297,12 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "media")
|
||||
@CursorField(value = Statuses.MEDIA_JSON, converter = LoganSquareCursorFieldConverter.class)
|
||||
@Nullable
|
||||
public ParcelableMedia[] media;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "quoted_media")
|
||||
@CursorField(value = Statuses.QUOTED_MEDIA_JSON, converter = LoganSquareCursorFieldConverter.class)
|
||||
@Nullable
|
||||
public ParcelableMedia[] quoted_media;
|
||||
@Nullable
|
||||
@ParcelableThisPlease
|
||||
|
@ -1,86 +0,0 @@
|
||||
package org.mariotaku.twidere.menu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.ActionProvider;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
|
||||
public class AccountActionProvider extends ActionProvider implements TwidereConstants {
|
||||
|
||||
public static final int MENU_GROUP = 201;
|
||||
|
||||
private ParcelableAccount[] mAccounts;
|
||||
|
||||
private UserKey[] mAccountIds;
|
||||
private boolean mExclusive;
|
||||
|
||||
public AccountActionProvider(final Context context, final ParcelableAccount[] accounts) {
|
||||
super(context);
|
||||
setAccounts(accounts);
|
||||
}
|
||||
|
||||
public AccountActionProvider(final Context context) {
|
||||
this(context, ParcelableAccountUtils.getAccounts(context, false, false));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasSubMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateActionView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setAccounts(ParcelableAccount[] accounts) {
|
||||
mAccounts = accounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareSubMenu(final SubMenu subMenu) {
|
||||
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 Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_ACCOUNT, account);
|
||||
item.setIntent(intent);
|
||||
}
|
||||
subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
|
||||
if (mAccountIds == null) return;
|
||||
for (int i = 0, j = subMenu.size(); i < j; i++) {
|
||||
final MenuItem item = subMenu.getItem(i);
|
||||
final Intent intent = item.getIntent();
|
||||
final ParcelableAccount account = intent.getParcelableExtra(EXTRA_ACCOUNT);
|
||||
if (ArrayUtils.contains(mAccountIds, account.account_key)) {
|
||||
item.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExclusive() {
|
||||
return mExclusive;
|
||||
}
|
||||
|
||||
|
||||
public void setExclusive(boolean exclusive) {
|
||||
mExclusive = exclusive;
|
||||
}
|
||||
|
||||
public void setSelectedAccountIds(final UserKey... accountIds) {
|
||||
mAccountIds = accountIds;
|
||||
}
|
||||
|
||||
}
|
@ -286,6 +286,7 @@ public class ParcelableMediaUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ParcelableMedia[] getPrimaryMedia(ParcelableStatus status) {
|
||||
if (status.is_quote && ArrayUtils.isEmpty(status.media)) {
|
||||
return status.quoted_media;
|
||||
|
@ -1,247 +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;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.twitter.Extractor;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.BaseActivity;
|
||||
import org.mariotaku.twidere.menu.AccountActionProvider;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils;
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@SuppressLint("Registered")
|
||||
public class MultiSelectEventHandler implements Constants, ActionMode.Callback,
|
||||
MultiSelectManager.Callback {
|
||||
|
||||
@Inject
|
||||
AsyncTwitterWrapper mTwitterWrapper;
|
||||
|
||||
@Inject
|
||||
MultiSelectManager mMultiSelectManager;
|
||||
|
||||
private ActionMode mActionMode;
|
||||
|
||||
private final BaseActivity mActivity;
|
||||
|
||||
private AccountActionProvider mAccountActionProvider;
|
||||
|
||||
public static final int MENU_GROUP = 201;
|
||||
|
||||
public MultiSelectEventHandler(final BaseActivity activity) {
|
||||
GeneralComponentHelper.build(activity).inject(this);
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before super.onCreate
|
||||
*/
|
||||
public void dispatchOnCreate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after super.onStart
|
||||
*/
|
||||
public void dispatchOnStart() {
|
||||
mMultiSelectManager.registerCallback(this);
|
||||
updateMultiSelectState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before super.onStop
|
||||
*/
|
||||
public void dispatchOnStop() {
|
||||
mMultiSelectManager.unregisterCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
|
||||
final List<Object> selectedItems = mMultiSelectManager.getSelectedItems();
|
||||
if (selectedItems.isEmpty()) return false;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.reply: {
|
||||
final Extractor extractor = new Extractor();
|
||||
final Intent intent = new Intent(INTENT_ACTION_REPLY_MULTIPLE);
|
||||
final Bundle bundle = new Bundle();
|
||||
final String[] accountScreenNames = DataStoreUtils.getAccountScreenNames(mActivity);
|
||||
final Collection<String> allMentions = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
for (final Object object : selectedItems) {
|
||||
if (object instanceof ParcelableStatus) {
|
||||
final ParcelableStatus status = (ParcelableStatus) object;
|
||||
allMentions.add(status.user_screen_name);
|
||||
allMentions.addAll(extractor.extractMentionedScreennames(status.text_plain));
|
||||
} else if (object instanceof ParcelableUser) {
|
||||
final ParcelableUser user = (ParcelableUser) object;
|
||||
allMentions.add(user.screen_name);
|
||||
}
|
||||
}
|
||||
allMentions.removeAll(Arrays.asList(accountScreenNames));
|
||||
final Object firstObj = selectedItems.get(0);
|
||||
if (firstObj instanceof ParcelableStatus) {
|
||||
final ParcelableStatus first_status = (ParcelableStatus) firstObj;
|
||||
bundle.putString(EXTRA_IN_REPLY_TO_ID, first_status.id);
|
||||
}
|
||||
bundle.putParcelable(EXTRA_ACCOUNT_KEY, mMultiSelectManager.getAccountKey());
|
||||
bundle.putStringArray(EXTRA_SCREEN_NAMES, allMentions.toArray(new String[allMentions.size()]));
|
||||
intent.putExtras(bundle);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mActivity.startActivity(intent);
|
||||
mode.finish();
|
||||
break;
|
||||
}
|
||||
case R.id.mute_user: {
|
||||
final ContentResolver resolver = mActivity.getContentResolver();
|
||||
final ArrayList<ContentValues> valuesList = new ArrayList<>();
|
||||
final Set<UserKey> userIds = new HashSet<>();
|
||||
for (final Object object : selectedItems) {
|
||||
if (object instanceof ParcelableStatus) {
|
||||
final ParcelableStatus status = (ParcelableStatus) object;
|
||||
userIds.add(status.user_key);
|
||||
valuesList.add(ContentValuesCreator.createFilteredUser(status));
|
||||
} else if (object instanceof ParcelableUser) {
|
||||
final ParcelableUser user = (ParcelableUser) object;
|
||||
userIds.add(user.key);
|
||||
valuesList.add(ContentValuesCreator.createFilteredUser(user));
|
||||
}
|
||||
}
|
||||
ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI,
|
||||
Filters.Users.USER_KEY, userIds, null);
|
||||
ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, valuesList);
|
||||
Toast.makeText(mActivity, R.string.message_users_muted, Toast.LENGTH_SHORT).show();
|
||||
mode.finish();
|
||||
break;
|
||||
}
|
||||
case R.id.block: {
|
||||
final UserKey accountKey = mMultiSelectManager.getAccountKey();
|
||||
final String[] userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems));
|
||||
if (accountKey != null && userIds != null) {
|
||||
mTwitterWrapper.createMultiBlockAsync(accountKey, userIds);
|
||||
}
|
||||
mode.finish();
|
||||
break;
|
||||
}
|
||||
case R.id.report_spam: {
|
||||
final UserKey accountKey = mMultiSelectManager.getAccountKey();
|
||||
final String[] userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems));
|
||||
if (accountKey != null && userIds != null) {
|
||||
mTwitterWrapper.reportMultiSpam(accountKey, userIds);
|
||||
}
|
||||
mode.finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item.getGroupId() == AccountActionProvider.MENU_GROUP) {
|
||||
final Intent intent = item.getIntent();
|
||||
if (intent == null || !intent.hasExtra(EXTRA_ACCOUNT)) return false;
|
||||
final ParcelableAccount account = intent.getParcelableExtra(EXTRA_ACCOUNT);
|
||||
mMultiSelectManager.setAccountKey(account.account_key);
|
||||
if (mAccountActionProvider != null) {
|
||||
mAccountActionProvider.setSelectedAccountIds(account.account_key);
|
||||
}
|
||||
mode.invalidate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
|
||||
mode.getMenuInflater().inflate(R.menu.action_multi_select_contents, menu);
|
||||
mAccountActionProvider = (AccountActionProvider) menu.findItem(R.id.select_account).getActionProvider();
|
||||
mAccountActionProvider.setSelectedAccountIds(mMultiSelectManager.getFirstSelectAccountKey());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(final ActionMode mode) {
|
||||
if (mMultiSelectManager.getCount() != 0) {
|
||||
mMultiSelectManager.clearSelectedItems();
|
||||
}
|
||||
mAccountActionProvider = null;
|
||||
mActionMode = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemsCleared() {
|
||||
updateMultiSelectState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(final Object item) {
|
||||
updateMultiSelectState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemUnselected(final Object item) {
|
||||
updateMultiSelectState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
|
||||
updateSelectedCount(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateMultiSelectState() {
|
||||
if (mMultiSelectManager.isActive()) {
|
||||
if (mActionMode == null) {
|
||||
mActionMode = mActivity.startActionMode(this);
|
||||
}
|
||||
updateSelectedCount(mActionMode);
|
||||
} else {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
mActionMode = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSelectedCount(final ActionMode mode) {
|
||||
if (mode == null || mActivity == null || mMultiSelectManager == null) return;
|
||||
final int count = mMultiSelectManager.getCount();
|
||||
mode.setTitle(mActivity.getResources().getQuantityString(R.plurals.Nitems_selected, count, count));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.ActionMode
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import com.twitter.Extractor
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.BaseActivity
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.menu.AccountActionProvider
|
||||
import org.mariotaku.twidere.model.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@SuppressLint("Registered")
|
||||
class MultiSelectEventHandler(private val activity: BaseActivity) : Constants, ActionMode.Callback, MultiSelectManager.Callback {
|
||||
|
||||
@Inject
|
||||
lateinit var twitterWrapper: AsyncTwitterWrapper
|
||||
|
||||
@Inject
|
||||
lateinit var multiSelectManager: MultiSelectManager
|
||||
|
||||
private var mActionMode: ActionMode? = null
|
||||
|
||||
private var mAccountActionProvider: AccountActionProvider? = null
|
||||
|
||||
init {
|
||||
GeneralComponentHelper.build(activity).inject(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before super.onCreate
|
||||
*/
|
||||
fun dispatchOnCreate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after super.onStart
|
||||
*/
|
||||
fun dispatchOnStart() {
|
||||
multiSelectManager.registerCallback(this)
|
||||
updateMultiSelectState()
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before super.onStop
|
||||
*/
|
||||
fun dispatchOnStop() {
|
||||
multiSelectManager.unregisterCallback(this)
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
val selectedItems = multiSelectManager.selectedItems
|
||||
if (selectedItems.isEmpty()) return false
|
||||
when (item.itemId) {
|
||||
R.id.reply -> {
|
||||
val extractor = Extractor()
|
||||
val intent = Intent(INTENT_ACTION_REPLY_MULTIPLE)
|
||||
val bundle = Bundle()
|
||||
val accountScreenNames = DataStoreUtils.getAccountScreenNames(activity)
|
||||
val allMentions = TreeSet(String.CASE_INSENSITIVE_ORDER)
|
||||
for (`object` in selectedItems) {
|
||||
if (`object` is ParcelableStatus) {
|
||||
allMentions.add(`object`.user_screen_name)
|
||||
allMentions.addAll(extractor.extractMentionedScreennames(`object`.text_plain))
|
||||
} else if (`object` is ParcelableUser) {
|
||||
allMentions.add(`object`.screen_name)
|
||||
}
|
||||
}
|
||||
allMentions.removeAll(Arrays.asList(*accountScreenNames))
|
||||
val firstObj = selectedItems[0]
|
||||
if (firstObj is ParcelableStatus) {
|
||||
bundle.putString(EXTRA_IN_REPLY_TO_ID, firstObj.id)
|
||||
}
|
||||
bundle.putParcelable(EXTRA_ACCOUNT_KEY, multiSelectManager.accountKey)
|
||||
bundle.putStringArray(EXTRA_SCREEN_NAMES, allMentions.toTypedArray())
|
||||
intent.putExtras(bundle)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
activity!!.startActivity(intent)
|
||||
mode.finish()
|
||||
}
|
||||
R.id.mute_user -> {
|
||||
val resolver = activity!!.contentResolver
|
||||
val valuesList = ArrayList<ContentValues>()
|
||||
val userIds = HashSet<UserKey>()
|
||||
for (`object` in selectedItems) {
|
||||
if (`object` is ParcelableStatus) {
|
||||
userIds.add(`object`.user_key)
|
||||
valuesList.add(ContentValuesCreator.createFilteredUser(`object`))
|
||||
} else if (`object` is ParcelableUser) {
|
||||
userIds.add(`object`.key)
|
||||
valuesList.add(ContentValuesCreator.createFilteredUser(`object`))
|
||||
}
|
||||
}
|
||||
ContentResolverUtils.bulkDelete(resolver, Filters.Users.CONTENT_URI,
|
||||
Filters.Users.USER_KEY, userIds, null)
|
||||
ContentResolverUtils.bulkInsert(resolver, Filters.Users.CONTENT_URI, valuesList)
|
||||
Toast.makeText(activity, R.string.message_users_muted, Toast.LENGTH_SHORT).show()
|
||||
mode.finish()
|
||||
}
|
||||
R.id.block -> {
|
||||
val accountKey = multiSelectManager.accountKey
|
||||
val userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems))
|
||||
if (accountKey != null && userIds != null) {
|
||||
twitterWrapper.createMultiBlockAsync(accountKey, userIds)
|
||||
}
|
||||
mode.finish()
|
||||
}
|
||||
R.id.report_spam -> {
|
||||
val accountKey = multiSelectManager.accountKey
|
||||
val userIds = UserKey.getIds(MultiSelectManager.getSelectedUserIds(selectedItems))
|
||||
if (accountKey != null && userIds != null) {
|
||||
twitterWrapper.reportMultiSpam(accountKey, userIds)
|
||||
}
|
||||
mode.finish()
|
||||
}
|
||||
}
|
||||
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
|
||||
if (mAccountActionProvider != null) {
|
||||
mAccountActionProvider!!.selectedAccountIds = arrayOf(account.account_key)
|
||||
}
|
||||
mode.invalidate()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.action_multi_select_contents, menu)
|
||||
mAccountActionProvider = menu.findItem(R.id.select_account).actionProvider as AccountActionProvider
|
||||
mAccountActionProvider!!.selectedAccountIds = arrayOf(multiSelectManager.firstSelectAccountKey)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode) {
|
||||
if (multiSelectManager.count != 0) {
|
||||
multiSelectManager.clearSelectedItems()
|
||||
}
|
||||
mAccountActionProvider = null
|
||||
mActionMode = null
|
||||
}
|
||||
|
||||
override fun onItemsCleared() {
|
||||
updateMultiSelectState()
|
||||
}
|
||||
|
||||
override fun onItemSelected(item: Any) {
|
||||
updateMultiSelectState()
|
||||
}
|
||||
|
||||
override fun onItemUnselected(item: Any) {
|
||||
updateMultiSelectState()
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
updateSelectedCount(mode)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun updateMultiSelectState() {
|
||||
if (multiSelectManager.isActive) {
|
||||
if (mActionMode == null) {
|
||||
mActionMode = activity!!.startActionMode(this)
|
||||
}
|
||||
updateSelectedCount(mActionMode)
|
||||
} else {
|
||||
if (mActionMode != null) {
|
||||
mActionMode!!.finish()
|
||||
mActionMode = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSelectedCount(mode: ActionMode?) {
|
||||
if (mode == null || activity == null || multiSelectManager == null) return
|
||||
val count = multiSelectManager.count
|
||||
mode.title = activity.resources.getQuantityString(R.plurals.Nitems_selected, count, count)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val MENU_GROUP = 201
|
||||
}
|
||||
|
||||
}
|
@ -82,14 +82,14 @@ public class TwitterWrapper implements Constants {
|
||||
}
|
||||
|
||||
public static int removeUnreadCounts(final Context context, final int position, final long account_id,
|
||||
final long... status_ids) {
|
||||
if (context == null || position < 0 || status_ids == null || status_ids.length == 0)
|
||||
final long... statusIds) {
|
||||
if (context == null || position < 0 || statusIds == null || statusIds.length == 0)
|
||||
return 0;
|
||||
int result = 0;
|
||||
final Uri.Builder builder = UnreadCounts.CONTENT_URI.buildUpon();
|
||||
builder.appendPath(String.valueOf(position));
|
||||
builder.appendPath(String.valueOf(account_id));
|
||||
builder.appendPath(TwidereArrayUtils.toString(status_ids, ',', false));
|
||||
builder.appendPath(TwidereArrayUtils.toString(statusIds, ',', false));
|
||||
result += context.getContentResolver().delete(builder.build(), null, null);
|
||||
return result;
|
||||
}
|
||||
|
@ -93,8 +93,7 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||
final UserKey accountId, final long extraId,
|
||||
final OnMediaClickListener mediaClickListener,
|
||||
final MediaLoadingHandler loadingHandler) {
|
||||
displayMedia(loader, mediaClickListener, loadingHandler, mediaArray, accountId, extraId, false
|
||||
);
|
||||
displayMedia(loader, mediaClickListener, loadingHandler, mediaArray, accountId, extraId, false);
|
||||
}
|
||||
|
||||
public void displayMedia(@NonNull final MediaLoaderWrapper loader, final OnMediaClickListener mediaClickListener, final MediaLoadingHandler loadingHandler, @Nullable final ParcelableMedia[] mediaArray,
|
||||
|
@ -10,7 +10,6 @@ import android.view.View.OnClickListener
|
||||
import android.view.View.OnLongClickListener
|
||||
import android.widget.ImageView
|
||||
import kotlinx.android.synthetic.main.card_item_status_compact.view.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
|
||||
@ -289,8 +288,8 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
itemContent.drawEnd()
|
||||
}
|
||||
|
||||
val hasQuotedMedia = !ArrayUtils.isEmpty(status.quoted_media)
|
||||
val hasPrimaryMedia = !hasQuotedMedia && !ArrayUtils.isEmpty(status.media)
|
||||
val hasQuotedMedia = status.quoted_media?.isNotEmpty() ?: false
|
||||
val hasPrimaryMedia = !hasQuotedMedia && status.media?.isNotEmpty() ?: false
|
||||
|
||||
|
||||
if (!hasPrimaryMedia && !hasQuotedMedia) {
|
||||
|
@ -472,15 +472,12 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
val attachPreciseLocation = preferences.getBoolean(KEY_ATTACH_PRECISE_LOCATION)
|
||||
if (attachLocation) {
|
||||
if (attachPreciseLocation) {
|
||||
locationSwitch.checkedPosition = ArrayUtils.indexOf(LOCATION_OPTIONS,
|
||||
LOCATION_VALUE_COORDINATE)
|
||||
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_COORDINATE)
|
||||
} else {
|
||||
locationSwitch.checkedPosition = ArrayUtils.indexOf(LOCATION_OPTIONS,
|
||||
LOCATION_VALUE_PLACE)
|
||||
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_PLACE)
|
||||
}
|
||||
} else {
|
||||
locationSwitch.checkedPosition = ArrayUtils.indexOf(LOCATION_OPTIONS,
|
||||
LOCATION_VALUE_NONE)
|
||||
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_NONE)
|
||||
}
|
||||
locationSwitch.setOnCheckedChangeListener {
|
||||
val value = LOCATION_OPTIONS[locationSwitch.checkedPosition]
|
||||
@ -1093,7 +1090,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
private fun saveAccountSelection() {
|
||||
if (!shouldSaveAccounts) return
|
||||
val editor = preferences.edit()
|
||||
editor.putString(KEY_COMPOSE_ACCOUNTS, TwidereArrayUtils.toString(accountsAdapter!!.selectedAccountKeys, ',', false))
|
||||
|
||||
editor.putString(KEY_COMPOSE_ACCOUNTS, accountsAdapter!!.selectedAccountKeys.joinToString(","))
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
@ -1384,15 +1382,15 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
|
||||
internal class AccountIconsAdapter(private val activity: ComposeActivity) : BaseRecyclerViewAdapter<AccountIconViewHolder>(activity) {
|
||||
private val mInflater: LayoutInflater
|
||||
private val mSelection: MutableMap<UserKey, Boolean>
|
||||
private val selection: MutableMap<UserKey, Boolean>
|
||||
val isNameFirst: Boolean
|
||||
|
||||
private var mAccounts: Array<ParcelableCredentials>? = null
|
||||
private var accounts: Array<ParcelableCredentials>? = null
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
mInflater = activity.layoutInflater
|
||||
mSelection = HashMap<UserKey, Boolean>()
|
||||
selection = HashMap<UserKey, Boolean>()
|
||||
isNameFirst = preferences.getBoolean(KEY_NAME_FIRST)
|
||||
}
|
||||
|
||||
@ -1400,29 +1398,29 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
get() = mediaLoader
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return mAccounts!![position].hashCode().toLong()
|
||||
return accounts!![position].hashCode().toLong()
|
||||
}
|
||||
|
||||
val selectedAccountKeys: Array<UserKey>
|
||||
get() {
|
||||
val accounts = mAccounts ?: return emptyArray()
|
||||
return accounts.filter { mSelection[it.account_key] ?: false }
|
||||
val accounts = accounts ?: return emptyArray()
|
||||
return accounts.filter { selection[it.account_key] ?: false }
|
||||
.map { it.account_key!! }
|
||||
.toTypedArray()
|
||||
}
|
||||
|
||||
fun setSelectedAccountIds(vararg accountKeys: UserKey) {
|
||||
mSelection.clear()
|
||||
selection.clear()
|
||||
for (accountKey in accountKeys) {
|
||||
mSelection.put(accountKey, true)
|
||||
selection.put(accountKey, true)
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
val selectedAccounts: Array<ParcelableCredentials>
|
||||
get() {
|
||||
val accounts = mAccounts ?: return emptyArray()
|
||||
return accounts.filter { mSelection[it.account_key] ?: false }.toTypedArray()
|
||||
val accounts = accounts ?: return emptyArray()
|
||||
return accounts.filter { selection[it.account_key] ?: false }.toTypedArray()
|
||||
}
|
||||
|
||||
val isSelectionEmpty: Boolean
|
||||
@ -1434,24 +1432,24 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: AccountIconViewHolder, position: Int) {
|
||||
val account = mAccounts!![position]
|
||||
val isSelected = mSelection[account.account_key] ?: false
|
||||
val account = accounts!![position]
|
||||
val isSelected = selection[account.account_key] ?: false
|
||||
holder.showAccount(this, account, isSelected)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (mAccounts != null) mAccounts!!.size else 0
|
||||
return if (accounts != null) accounts!!.size else 0
|
||||
}
|
||||
|
||||
fun setAccounts(accounts: Array<ParcelableCredentials>) {
|
||||
mAccounts = accounts
|
||||
this.accounts = accounts
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
internal fun toggleSelection(position: Int) {
|
||||
if (mAccounts == null || position < 0) return
|
||||
val account = mAccounts!![position]
|
||||
mSelection.put(account.account_key, java.lang.Boolean.TRUE != mSelection[account.account_key])
|
||||
if (accounts == null || position < 0) return
|
||||
val account = accounts!![position]
|
||||
selection.put(account.account_key, java.lang.Boolean.TRUE != selection[account.account_key])
|
||||
activity.notifyAccountSelectionChanged()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import android.widget.Toast
|
||||
import com.afollestad.appthemeengine.Config
|
||||
import com.afollestad.appthemeengine.customizers.ATEToolbarCustomizer
|
||||
import kotlinx.android.synthetic.main.activity_media_viewer.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.ktextension.asTypedArray
|
||||
import org.mariotaku.mediaviewer.library.*
|
||||
import org.mariotaku.mediaviewer.library.subsampleimageview.SubsampleImageViewerFragment.EXTRA_MEDIA_URI
|
||||
@ -204,7 +203,7 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, ATEToolbarCustomi
|
||||
}
|
||||
|
||||
override fun getInitialPosition(): Int {
|
||||
return ArrayUtils.indexOf(media, initialMedia)
|
||||
return media.indexOf(initialMedia)
|
||||
}
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
|
@ -289,7 +289,7 @@ class ParcelableActivitiesAdapter(
|
||||
if (mentionsOnly) return ITEM_VIEW_TYPE_EMPTY
|
||||
if (filteredUserIds != null) {
|
||||
ParcelableActivityUtils.initAfterFilteredSourceIds(activity, filteredUserIds!!, followingOnly)
|
||||
if (ArrayUtils.isEmpty(activity.after_filtered_source_ids)) {
|
||||
if (activity.after_filtered_source_ids.isEmpty()) {
|
||||
return ITEM_VIEW_TYPE_EMPTY
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import edu.tsinghua.hotmobi.HotMobiLogger
|
||||
import edu.tsinghua.hotmobi.model.MediaEvent
|
||||
import edu.tsinghua.hotmobi.model.ScrollRecord
|
||||
import kotlinx.android.synthetic.main.fragment_content_recyclerview.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
@ -351,12 +350,12 @@ abstract class AbsActivitiesFragment protected constructor() : AbsContentListRec
|
||||
override fun onActivityClick(holder: ActivityTitleSummaryViewHolder, position: Int) {
|
||||
val activity = adapter!!.getActivity(position) ?: return
|
||||
val list = ArrayList<Parcelable>()
|
||||
if (!ArrayUtils.isEmpty(activity.target_object_statuses)) {
|
||||
Collections.addAll(list, *activity.target_object_statuses)
|
||||
} else if (!ArrayUtils.isEmpty(activity.target_statuses)) {
|
||||
Collections.addAll(list, *activity.target_statuses)
|
||||
if (activity.target_object_statuses?.isNotEmpty() ?: false) {
|
||||
list.addAll(activity.target_object_statuses)
|
||||
} else if (activity.target_statuses?.isNotEmpty() ?: false) {
|
||||
list.addAll(activity.target_statuses)
|
||||
}
|
||||
Collections.addAll(list, *ParcelableActivityUtils.getAfterFilteredSources(activity))
|
||||
list.addAll(ParcelableActivityUtils.getAfterFilteredSources(activity))
|
||||
IntentUtils.openItems(getActivity(), list)
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ import android.view.View.OnClickListener
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.ImageView
|
||||
import kotlinx.android.synthetic.main.header_drawer_account_selector.view.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.ktextension.setItemAvailability
|
||||
import org.mariotaku.ktextension.setMenuItemIcon
|
||||
import org.mariotaku.ktextension.setMenuItemTitle
|
||||
@ -60,7 +59,6 @@ import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.*
|
||||
import org.mariotaku.twidere.annotation.CustomTabType
|
||||
import org.mariotaku.twidere.annotation.Referral
|
||||
import org.mariotaku.twidere.constant.IntentConstants
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
||||
import org.mariotaku.twidere.fragment.AccountsDashboardFragment.AccountsInfo
|
||||
import org.mariotaku.twidere.menu.AccountToggleProvider
|
||||
@ -407,7 +405,7 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||
private fun hasAccountInTab(tab: SupportTabSpec, accountId: UserKey, isActivated: Boolean): Boolean {
|
||||
if (tab.args == null) return false
|
||||
val accountKeys = Utils.getAccountKeys(context, tab.args) ?: return isActivated
|
||||
return ArrayUtils.contains(accountKeys, accountId)
|
||||
return accountKeys.contains(accountId)
|
||||
}
|
||||
|
||||
private fun closeAccountsDrawer() {
|
||||
|
@ -43,7 +43,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
@ -92,8 +91,10 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
||||
} else {
|
||||
where = accountWhere
|
||||
}
|
||||
val accountSelectionArgs = TwidereArrayUtils.toStringArray(accountKeys, 0,
|
||||
accountKeys.size)
|
||||
|
||||
val accountSelectionArgs = Array(accountKeys.size) {
|
||||
accountKeys[it].toString()
|
||||
}
|
||||
val expression = processWhere(where, accountSelectionArgs)
|
||||
val selection = expression.sql
|
||||
val adapter = adapter!!
|
||||
|
@ -45,7 +45,6 @@ import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.DataStoreUtils.buildStatusFilterWhereClause
|
||||
import org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
@ -88,8 +87,9 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
||||
val adapter = adapter
|
||||
adapter!!.showAccountsColor = accountKeys.size > 1
|
||||
val projection = Statuses.COLUMNS
|
||||
val selectionArgs = TwidereArrayUtils.toStringArray(accountKeys, 0,
|
||||
accountKeys.size)
|
||||
val selectionArgs = Array(accountKeys.size) {
|
||||
accountKeys[it].toString()
|
||||
}
|
||||
val expression = processWhere(where, selectionArgs)
|
||||
return ExtendedObjectCursorLoader(context, ParcelableStatusCursorIndices::class.java, uri,
|
||||
projection, expression.sql, expression.parameters,
|
||||
|
@ -44,7 +44,6 @@ import android.widget.AdapterView
|
||||
import android.widget.AdapterView.OnItemClickListener
|
||||
import android.widget.ListView
|
||||
import kotlinx.android.synthetic.main.fragment_drafts.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.sqliteqb.library.Columns.Column
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.sqliteqb.library.RawItemArray
|
||||
@ -213,7 +212,7 @@ class DraftsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, OnItemCl
|
||||
if (item.action_extras is SendDirectMessageActionExtra) {
|
||||
recipientId = (item.action_extras as SendDirectMessageActionExtra).recipientId
|
||||
}
|
||||
if (ArrayUtils.isEmpty(item.account_keys) || recipientId == null) {
|
||||
if (item.account_keys?.isEmpty() ?: true || recipientId == null) {
|
||||
continue@loop
|
||||
}
|
||||
val accountId = item.account_keys!![0]
|
||||
|
@ -69,7 +69,6 @@ import kotlinx.android.synthetic.main.adapter_item_status_count_label.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_status.*
|
||||
import kotlinx.android.synthetic.main.header_status_common.view.*
|
||||
import kotlinx.android.synthetic.main.layout_content_fragment_common.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.TranslationResult
|
||||
@ -932,7 +931,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
||||
|
||||
val media = ParcelableMediaUtils.getPrimaryMedia(status)
|
||||
|
||||
if (ArrayUtils.isEmpty(media)) {
|
||||
if (media?.isEmpty() ?: true) {
|
||||
itemView.mediaPreviewContainer.visibility = View.GONE
|
||||
itemView.mediaPreview.visibility = View.GONE
|
||||
itemView.mediaPreviewLoad.visibility = View.GONE
|
||||
|
@ -24,7 +24,6 @@ import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.annotation.WorkerThread
|
||||
import android.util.Log
|
||||
import com.nostra13.universalimageloader.cache.disc.DiskCache
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.commons.logansquare.LoganSquareMapperFinder
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
@ -142,7 +141,7 @@ abstract class MicroBlogAPIStatusesLoader(
|
||||
}
|
||||
|
||||
// Insert a gap.
|
||||
val deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, maxId)
|
||||
val deletedOldGap = rowsDeleted > 0 && statusIds.contains(maxId)
|
||||
val noRowsDeleted = rowsDeleted == 0
|
||||
val insertGap = minIdx != -1 && (noRowsDeleted || deletedOldGap) && !noItemsBefore
|
||||
&& statuses.size >= loadItemLimit && !loadingMore
|
||||
|
@ -0,0 +1,58 @@
|
||||
package org.mariotaku.twidere.menu
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.ActionProvider
|
||||
import android.view.Menu
|
||||
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.ParcelableAccount
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils
|
||||
|
||||
class AccountActionProvider(
|
||||
context: Context,
|
||||
var accounts: Array<ParcelableAccount>? = ParcelableAccountUtils.getAccounts(context, false, false)
|
||||
) : ActionProvider(context), TwidereConstants {
|
||||
|
||||
var selectedAccountIds: Array<UserKey>? = null
|
||||
var isExclusive: Boolean = false
|
||||
|
||||
override fun hasSubMenu(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onCreateActionView(): View? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onPrepareSubMenu(subMenu: SubMenu) {
|
||||
subMenu.removeGroup(MENU_GROUP)
|
||||
if (accounts == null) return
|
||||
accounts?.forEachIndexed { idx, account ->
|
||||
val item = subMenu.add(MENU_GROUP, Menu.NONE, idx, account.name)
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_ACCOUNT, account)
|
||||
item.intent = intent
|
||||
}
|
||||
subMenu.setGroupCheckable(MENU_GROUP, true, isExclusive)
|
||||
selectedAccountIds?.let {
|
||||
for (i in 0 until subMenu.size()) {
|
||||
val item = subMenu.getItem(i)
|
||||
val intent = item.intent
|
||||
val account = intent.getParcelableExtra<ParcelableAccount>(EXTRA_ACCOUNT)
|
||||
if (it.contains(account.account_key)) {
|
||||
item.isChecked = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val MENU_GROUP = 201
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
@ -12,15 +11,15 @@ fun ParcelableActivity.getActivityStatus(): ParcelableStatus? {
|
||||
val status: ParcelableStatus
|
||||
when (action) {
|
||||
Activity.Action.MENTION -> {
|
||||
if (ArrayUtils.isEmpty(target_object_statuses)) return null
|
||||
if (target_object_statuses?.isEmpty() ?: true) return null
|
||||
status = target_object_statuses[0]
|
||||
}
|
||||
Activity.Action.REPLY -> {
|
||||
if (ArrayUtils.isEmpty(target_statuses)) return null
|
||||
if (target_statuses?.isEmpty() ?: true) return null
|
||||
status = target_statuses[0]
|
||||
}
|
||||
Activity.Action.QUOTE -> {
|
||||
if (ArrayUtils.isEmpty(target_statuses)) return null
|
||||
if (target_statuses?.isEmpty() ?: true) return null
|
||||
status = target_statuses[0]
|
||||
}
|
||||
else -> return null
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.microblog.library.twitter.model.Activity
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
@ -28,14 +27,14 @@ object ParcelableActivityUtils {
|
||||
followingOnly: Boolean): Boolean {
|
||||
if (activity.sources == null) return false
|
||||
if (activity.after_filtered_source_ids != null) return false
|
||||
if (followingOnly || !ArrayUtils.isEmpty(filteredUserIds)) {
|
||||
if (followingOnly || filteredUserIds.isNotEmpty()) {
|
||||
val list = ArrayList<UserKey>()
|
||||
for (user in activity.sources) {
|
||||
if (followingOnly && !user.is_following) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!ArrayUtils.contains(filteredUserIds, user.key)) {
|
||||
if (!filteredUserIds.contains(user.key)) {
|
||||
list.add(user.key)
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ import com.twitter.Extractor
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger
|
||||
import edu.tsinghua.hotmobi.model.TimelineType
|
||||
import edu.tsinghua.hotmobi.model.TweetEvent
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.apache.commons.lang3.math.NumberUtils
|
||||
import org.mariotaku.abstask.library.ManualTaskStarter
|
||||
import org.mariotaku.ktextension.asTypedArray
|
||||
import org.mariotaku.ktextension.configure
|
||||
@ -170,15 +168,12 @@ class BackgroundOperationService : IntentService("background_operation"), Consta
|
||||
updateStatuses(item.action_type, ParcelableStatusUpdateUtils.fromDraftItem(this, item))
|
||||
}
|
||||
Draft.Action.SEND_DIRECT_MESSAGE_COMPAT, Draft.Action.SEND_DIRECT_MESSAGE -> {
|
||||
var recipientId: String? = null
|
||||
if (item.action_extras is SendDirectMessageActionExtra) {
|
||||
recipientId = (item.action_extras as SendDirectMessageActionExtra).recipientId
|
||||
}
|
||||
if (ArrayUtils.isEmpty(item.account_keys) || recipientId == null) {
|
||||
val recipientId = (item.action_extras as? SendDirectMessageActionExtra)?.recipientId ?: return
|
||||
if (item.account_keys?.isEmpty() ?: true) {
|
||||
return
|
||||
}
|
||||
val accountKey = item.account_keys!![0]
|
||||
val imageUri = if (ArrayUtils.isEmpty(item.media)) null else item.media[0].uri
|
||||
val accountKey = item.account_keys!!.first()
|
||||
val imageUri = item.media.firstOrNull()?.uri
|
||||
sendMessage(accountKey, recipientId, item.text, imageUri)
|
||||
}
|
||||
}
|
||||
@ -187,11 +182,9 @@ class BackgroundOperationService : IntentService("background_operation"), Consta
|
||||
private fun handleDiscardDraftIntent(intent: Intent) {
|
||||
val data = intent.data ?: return
|
||||
notificationManager.cancel(data.toString(), NOTIFICATION_ID_DRAFTS)
|
||||
val cr = contentResolver
|
||||
val def: Long = -1
|
||||
val id = NumberUtils.toLong(data.lastPathSegment, def)
|
||||
val id = data.lastPathSegment.toLong(-1)
|
||||
val where = Expression.equals(Drafts._ID, id)
|
||||
cr.delete(Drafts.CONTENT_URI, where.sql, null)
|
||||
contentResolver.delete(Drafts.CONTENT_URI, where.sql, null)
|
||||
}
|
||||
|
||||
private fun handleSendDirectMessageIntent(intent: Intent) {
|
||||
|
@ -22,7 +22,6 @@ package org.mariotaku.twidere.util
|
||||
import android.graphics.Point
|
||||
import android.support.v4.app.Fragment
|
||||
import android.text.TextUtils
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.mariotaku.twidere.fragment.card.CardPollFragment
|
||||
import org.mariotaku.twidere.model.ParcelableCardEntity
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
@ -74,11 +73,11 @@ object TwitterCardUtils {
|
||||
val card = status.card ?: return false
|
||||
when (status.card_name) {
|
||||
CARD_NAME_PLAYER -> {
|
||||
if (!ArrayUtils.isEmpty(status.media)) {
|
||||
status.media?.let { mediaArray ->
|
||||
val appUrlResolved = ParcelableCardEntityUtils.getString(card, "app_url_resolved")
|
||||
val cardUrl = card.url
|
||||
for (media in status.media) {
|
||||
if (media.url == appUrlResolved || media.url == cardUrl) {
|
||||
mediaArray.forEach {
|
||||
if (it.url == appUrlResolved || it.url == cardUrl) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user