for sync
This commit is contained in:
parent
248781a524
commit
d672aa89e5
|
@ -19,11 +19,17 @@
|
|||
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.simplerestapi.method.POST;
|
||||
import org.mariotaku.simplerestapi.param.Path;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public interface PrivateDirectMessagesResources extends PrivateResources {
|
||||
|
||||
void destroyDirectMessagesConversation(long userId) throws TwitterException;
|
||||
@POST("/dm/conversation/{conversation_id}/delete.json")
|
||||
void destroyDirectMessagesConversation(@Path("conversation_id") String conversationId) throws TwitterException;
|
||||
|
||||
@POST("/dm/conversation/{account_id}-{user_id}/delete.json")
|
||||
void destroyDirectMessagesConversation(@Path("account_id") long accountId, @Path("user_id") long userId) throws TwitterException;
|
||||
|
||||
}
|
||||
|
|
|
@ -126,10 +126,14 @@ public class ParcelableAccount implements Parcelable {
|
|||
out.writeInt(color);
|
||||
}
|
||||
|
||||
public static ParcelableAccount dummyInstance() {
|
||||
public static ParcelableAccount dummyAccount() {
|
||||
return new ParcelableAccount();
|
||||
}
|
||||
|
||||
public static ParcelableCredentials dummyCredentials() {
|
||||
return new ParcelableCredentials();
|
||||
}
|
||||
|
||||
public static ParcelableAccount getAccount(final Context context, final long account_id) {
|
||||
if (context == null) return null;
|
||||
final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI,
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package org.mariotaku.twidere.test;
|
||||
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class TwidereApplicationTest extends ApplicationTestCase<TwidereApplication> {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public TwidereApplicationTest() {
|
||||
super(TwidereApplication.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -298,11 +298,11 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement
|
|||
mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
|
||||
final boolean accountIdRequired = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
|
||||
if (!accountIdRequired) {
|
||||
mAccountsAdapter.add(ParcelableAccount.dummyInstance());
|
||||
mAccountsAdapter.add(ParcelableAccount.dummyCredentials());
|
||||
}
|
||||
final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
|
||||
final boolean forcePrivateAPIs = intent.getBooleanExtra(KEY_FORCE_USING_PRIVATE_APIS, false);
|
||||
mAccountsAdapter.addAll(ParcelableAccount.getAccountsList(this, false, !forcePrivateAPIs && officialKeyOnly));
|
||||
mAccountsAdapter.addAll(ParcelableAccount.getCredentialsList(this, false, !forcePrivateAPIs && officialKeyOnly));
|
||||
mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
|
||||
switch (conf.getSecondaryFieldType()) {
|
||||
case CustomTabConfiguration.FIELD_TYPE_USER: {
|
||||
|
|
|
@ -801,20 +801,20 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
mTabIndicator.setItemContext(ThemeUtils.getActionBarThemedContext(this, themeResId, themeColor));
|
||||
ViewSupport.setBackground(mActionBarContainer, ThemeUtils.getActionBarBackground(this, themeResId, themeColor,
|
||||
backgroundOption, true));
|
||||
final int statusBarColor;
|
||||
final int actionBarColor;
|
||||
final int[] foregroundColors = new int[2];
|
||||
ThemeUtils.getColorForegroundAndInverse(this, foregroundColors);
|
||||
if (ThemeUtils.isDarkTheme(themeResId)) {
|
||||
statusBarColor = getResources().getColor(R.color.background_color_action_bar_dark);
|
||||
actionBarColor = getResources().getColor(R.color.background_color_action_bar_dark);
|
||||
final int actionItemColor = ThemeUtils.getContrastForegroundColor(this,
|
||||
getCurrentThemeResourceId(), themeColor);
|
||||
homeActionButton.setButtonColor(statusBarColor);
|
||||
homeActionButton.setButtonColor(actionBarColor);
|
||||
homeActionButton.setIconColor(actionItemColor, Mode.SRC_ATOP);
|
||||
mTabIndicator.setStripColor(themeColor);
|
||||
mTabIndicator.setIconColor(foregroundColors[0]);
|
||||
mTabIndicator.setLabelColor(foregroundColors[0]);
|
||||
} else {
|
||||
statusBarColor = themeColor;
|
||||
actionBarColor = themeColor;
|
||||
final int actionItemColor = ThemeUtils.getContrastForegroundColor(this,
|
||||
getCurrentThemeResourceId(), themeColor);
|
||||
final int contrastColor = TwidereColorUtils.getContrastYIQ(themeColor,
|
||||
|
@ -828,8 +828,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
}
|
||||
mColorStatusFrameLayout.setDrawColor(true);
|
||||
mColorStatusFrameLayout.setDrawShadow(false);
|
||||
mColorStatusFrameLayout.setColor(statusBarColor, actionBarAlpha);
|
||||
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(statusBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
mColorStatusFrameLayout.setColor(actionBarColor, actionBarAlpha);
|
||||
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(actionBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
mColorStatusFrameLayout.setFactor(1);
|
||||
mActionBarWithOverlay.setAlpha(actionBarAlpha / 255f);
|
||||
mActionsButton.setAlpha(actionBarAlpha / 255f);
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.mariotaku.twidere.activity.support.QuickSearchBarActivity.SuggestionI
|
|||
import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUser.CachedIndices;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers;
|
||||
|
@ -206,7 +207,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_quick_search_bar);
|
||||
final List<ParcelableAccount> accounts = ParcelableAccount.getAccountsList(this, false);
|
||||
final List<ParcelableCredentials> accounts = ParcelableAccount.getCredentialsList(this, false);
|
||||
final AccountsSpinnerAdapter accountsSpinnerAdapter = new AccountsSpinnerAdapter(this, R.layout.spinner_item_account_icon);
|
||||
accountsSpinnerAdapter.setDropDownViewResource(R.layout.list_item_user);
|
||||
accountsSpinnerAdapter.addAll(accounts);
|
||||
|
|
|
@ -28,12 +28,12 @@ import android.widget.TextView;
|
|||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.fragment.support.MessagesConversationFragment;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class AccountsSpinnerAdapter extends ArrayAdapter<ParcelableAccount> {
|
||||
public class AccountsSpinnerAdapter extends ArrayAdapter<ParcelableCredentials> {
|
||||
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final boolean mDisplayProfileImage;
|
||||
|
@ -52,7 +52,7 @@ public class AccountsSpinnerAdapter extends ArrayAdapter<ParcelableAccount> {
|
|||
Context.MODE_PRIVATE).getBoolean(MessagesConversationFragment.KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
}
|
||||
|
||||
public AccountsSpinnerAdapter(final Context context, final Collection<ParcelableAccount> accounts) {
|
||||
public AccountsSpinnerAdapter(final Context context, final Collection<ParcelableCredentials> accounts) {
|
||||
this(context);
|
||||
addAll(accounts);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class AccountsSpinnerAdapter extends ArrayAdapter<ParcelableAccount> {
|
|||
return view;
|
||||
}
|
||||
|
||||
private void bindView(final View view, final ParcelableAccount item) {
|
||||
private void bindView(final View view, final ParcelableCredentials item) {
|
||||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||
final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
|
||||
final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
package org.mariotaku.twidere.fragment.support;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
|
@ -83,6 +86,7 @@ import org.mariotaku.twidere.app.TwidereApplication;
|
|||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.loader.support.UserSearchLoader;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessage;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUser.CachedIndices;
|
||||
|
@ -100,6 +104,7 @@ import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
|||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.TakeAllKeyboardShortcut;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.MenuUtils;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
|
@ -196,7 +201,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
private ParcelableDirectMessage mSelectedDirectMessage;
|
||||
private boolean mLoaderInitialized;
|
||||
private String mImageUri;
|
||||
private ParcelableAccount mAccount;
|
||||
private ParcelableCredentials mAccount;
|
||||
private ParcelableUser mRecipient;
|
||||
private boolean mTextChanged, mQueryTextChanged;
|
||||
private View mInputPanel;
|
||||
|
@ -253,7 +258,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
mAccountSpinner = (Spinner) actionBarView.findViewById(R.id.account_spinner);
|
||||
mEditUserQuery = (EditText) actionBarView.findViewById(R.id.user_query);
|
||||
mQueryButton = actionBarView.findViewById(R.id.query_button);
|
||||
final List<ParcelableAccount> accounts = ParcelableAccount.getAccountsList(activity, false);
|
||||
final List<ParcelableCredentials> accounts = ParcelableCredentials.getCredentialsList(activity, false);
|
||||
final AccountsSpinnerAdapter accountsSpinnerAdapter = new AccountsSpinnerAdapter(
|
||||
actionBar.getThemedContext(), R.layout.spinner_item_account_icon);
|
||||
accountsSpinnerAdapter.setDropDownViewResource(R.layout.list_item_user);
|
||||
|
@ -288,7 +293,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
mUsersSearchList.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem();
|
||||
final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem();
|
||||
showConversation(account, mUsersSearchAdapter.getItem(position));
|
||||
updateRecipientInfo();
|
||||
}
|
||||
|
@ -301,14 +306,14 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
mAddImageButton.setOnClickListener(this);
|
||||
mSendButton.setEnabled(false);
|
||||
if (savedInstanceState != null) {
|
||||
final ParcelableAccount account = savedInstanceState.getParcelable(EXTRA_ACCOUNT);
|
||||
final ParcelableCredentials account = savedInstanceState.getParcelable(EXTRA_ACCOUNT);
|
||||
final ParcelableUser recipient = savedInstanceState.getParcelable(EXTRA_USER);
|
||||
showConversation(account, recipient);
|
||||
mEditText.setText(savedInstanceState.getString(EXTRA_TEXT));
|
||||
mImageUri = savedInstanceState.getString(EXTRA_IMAGE_URI);
|
||||
} else {
|
||||
final Bundle args = getArguments();
|
||||
final ParcelableAccount account;
|
||||
final ParcelableCredentials account;
|
||||
final ParcelableUser recipient;
|
||||
if (args != null) {
|
||||
if (args.containsKey(EXTRA_ACCOUNT)) {
|
||||
|
@ -381,7 +386,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
mPopupMenu.dismiss();
|
||||
}
|
||||
|
||||
final ParcelableAccount account = mAccount;
|
||||
final ParcelableCredentials account = mAccount;
|
||||
final ParcelableUser recipient = mRecipient;
|
||||
if (account != null && recipient != null) {
|
||||
final String key = getDraftsTextKey(account.account_id, recipient.id);
|
||||
|
@ -400,9 +405,21 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
MenuUtils.setMenuItemAvailability(menu, MENU_DELETE_ALL, mRecipient != null && Utils.isOfficialCredentials(getActivity(), mAccount));
|
||||
updateRecipientInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_DELETE_ALL: {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBaseViewCreated(final View view, final Bundle savedInstanceState) {
|
||||
super.onBaseViewCreated(view, savedInstanceState);
|
||||
|
@ -450,7 +467,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
break;
|
||||
}
|
||||
case R.id.query_button: {
|
||||
final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem();
|
||||
final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem();
|
||||
searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false);
|
||||
break;
|
||||
}
|
||||
|
@ -459,7 +476,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
|
||||
@Override
|
||||
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos, final long id) {
|
||||
final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem();
|
||||
final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem();
|
||||
if (account != null) {
|
||||
mAccount = account;
|
||||
updateRecipientInfo();
|
||||
|
@ -547,7 +564,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
}
|
||||
|
||||
|
||||
public void showConversation(final ParcelableAccount account, final ParcelableUser recipient) {
|
||||
public void showConversation(final ParcelableCredentials account, final ParcelableUser recipient) {
|
||||
mAccount = account;
|
||||
mRecipient = recipient;
|
||||
if (account == null || recipient == null) return;
|
||||
|
@ -618,7 +635,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
// }
|
||||
|
||||
private void sendDirectMessage() {
|
||||
final ParcelableAccount account = mAccount;
|
||||
final ParcelableCredentials account = mAccount;
|
||||
final ParcelableUser recipient = mRecipient;
|
||||
if (mAccount == null || mRecipient == null) return;
|
||||
final String message = mEditText.getText().toString();
|
||||
|
@ -638,7 +655,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
final EditTextEnterHandler queryEnterHandler = EditTextEnterHandler.attach(mEditUserQuery, new EnterListener() {
|
||||
@Override
|
||||
public void onHitEnter() {
|
||||
final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem();
|
||||
final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem();
|
||||
if (account == null) return;
|
||||
mEditText.setAccountId(account.account_id);
|
||||
searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false);
|
||||
|
@ -656,7 +673,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
final ParcelableAccount account = (ParcelableAccount) mAccountSpinner.getSelectedItem();
|
||||
final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem();
|
||||
if (account == null) return;
|
||||
mEditText.setAccountId(account.account_id);
|
||||
searchUsers(account.account_id, ParseUtils.parseString(s), true);
|
||||
|
@ -857,13 +874,38 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
public static class DeleteConversationConfirmDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.delete_conversation_confirm_message);
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE: {
|
||||
final ParcelableCredentials account = getArguments().getParcelable(EXTRA_ACCOUNT);
|
||||
final ParcelableUser user = getArguments().getParcelable(EXTRA_USER);
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
twitter.destroyMessageConversationAsync(account.account_id, user.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetReadStateTask extends AsyncTask<Object, Object, Cursor> {
|
||||
private final Context mContext;
|
||||
private final ReadStateManager mReadStateManager;
|
||||
private final ParcelableAccount mAccount;
|
||||
private final ParcelableCredentials mAccount;
|
||||
private final ParcelableUser mRecipient;
|
||||
|
||||
public SetReadStateTask(Context context, ParcelableAccount account, ParcelableUser recipient) {
|
||||
public SetReadStateTask(Context context, ParcelableCredentials account, ParcelableUser recipient) {
|
||||
mContext = context;
|
||||
mReadStateManager = TwidereApplication.getInstance(context).getReadStateManager();
|
||||
mAccount = account;
|
||||
|
|
|
@ -88,14 +88,14 @@ public class CardPreviewPreference extends Preference implements Constants, OnSh
|
|||
|
||||
@Override
|
||||
protected View onCreateView(final ViewGroup parent) {
|
||||
final View view;
|
||||
final View statusView;
|
||||
if (mPreferences != null && mPreferences.getBoolean(KEY_COMPACT_CARDS, false)) {
|
||||
view = mInflater.inflate(R.layout.card_item_status_compact, parent, false);
|
||||
statusView = mInflater.inflate(R.layout.card_item_status_compact, parent, false);
|
||||
} else {
|
||||
view = mInflater.inflate(R.layout.card_item_status, parent, false);
|
||||
statusView = mInflater.inflate(R.layout.card_item_status, parent, false);
|
||||
}
|
||||
mHolder = new StatusViewHolder(mAdapter, view);
|
||||
return view;
|
||||
mHolder = new StatusViewHolder(mAdapter, statusView);
|
||||
return statusView;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -242,6 +242,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||
return mAsyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyMessageConversationAsync(final long accountId, final long userId) {
|
||||
final DestroyMessageConversationTask task = new DestroyMessageConversationTask(accountId, userId);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int destroyFavoriteAsync(final long accountId, final long status_id) {
|
||||
final DestroyFavoriteTask task = new DestroyFavoriteTask(accountId, status_id);
|
||||
return mAsyncTaskManager.add(task, true);
|
||||
|
@ -1414,6 +1419,65 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
|||
|
||||
}
|
||||
|
||||
|
||||
class DestroyMessageConversationTask extends ManagedAsyncTask<Object, Object, SingleResponse<Void>> {
|
||||
|
||||
private final long userId;
|
||||
private final long accountId;
|
||||
|
||||
public DestroyMessageConversationTask(final long accountId, final long userId) {
|
||||
super(mContext, mAsyncTaskManager);
|
||||
|
||||
this.accountId = accountId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
private void deleteMessages(final long accountId, final long userId) {
|
||||
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, Expression.and(Expression.equals(Inbox.ACCOUNT_ID, accountId),
|
||||
Expression.equals(Inbox.SENDER_ID, userId)).getSQL(), null);
|
||||
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, Expression.and(Expression.equals(Outbox.ACCOUNT_ID, accountId),
|
||||
Expression.equals(Outbox.RECIPIENT_ID, userId)).getSQL(), null);
|
||||
}
|
||||
|
||||
private boolean isMessageNotFound(final Exception e) {
|
||||
if (!(e instanceof TwitterException)) return false;
|
||||
final TwitterException te = (TwitterException) e;
|
||||
return te.getErrorCode() == StatusCodeMessageUtils.PAGE_NOT_FOUND
|
||||
|| te.getStatusCode() == HttpResponseCode.NOT_FOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SingleResponse<Void> doInBackground(final Object... args) {
|
||||
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(mContext, accountId, false);
|
||||
if (twitter == null) return SingleResponse.getInstance();
|
||||
try {
|
||||
twitter.destroyDirectMessagesConversation(accountId, userId);
|
||||
deleteMessages(accountId, userId);
|
||||
return SingleResponse.getInstance();
|
||||
} catch (final TwitterException e) {
|
||||
if (isMessageNotFound(e)) {
|
||||
deleteMessages(accountId, userId);
|
||||
}
|
||||
return SingleResponse.getInstance(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<Void> result) {
|
||||
super.onPostExecute(result);
|
||||
if (result == null) return;
|
||||
if (result.hasData() || isMessageNotFound(result.getException())) {
|
||||
showInfoMessage(mContext, R.string.direct_message_deleted, false);
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_deleting, result.getException(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DestroyFavoriteTask extends ManagedAsyncTask<Object, Object, SingleResponse<ParcelableStatus>> {
|
||||
|
||||
private final long account_id;
|
||||
|
|
|
@ -21,13 +21,14 @@ package org.mariotaku.twidere.view;
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
import android.os.Build;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.util.AttributeSet;
|
||||
|
@ -35,7 +36,6 @@ import android.util.Property;
|
|||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
|
@ -104,7 +104,13 @@ public class HomeActionButton extends FrameLayout implements IHomeActionButton {
|
|||
|
||||
@Override
|
||||
public void setButtonColor(int color) {
|
||||
ViewSupport.setBackground(this, new ColorDrawable(color));
|
||||
if (isInEditMode()) {
|
||||
final ShapeDrawable sd = new ShapeDrawable(new OvalShape());
|
||||
sd.getPaint().setColor(color);
|
||||
ViewSupport.setBackground(this, sd);
|
||||
} else {
|
||||
ViewSupport.setBackground(this, new ColorDrawable(color));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,11 +133,6 @@ public class HomeActionButton extends FrameLayout implements IHomeActionButton {
|
|||
mIconView.setColorFilter(color, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowProgress(final boolean showProgress) {
|
||||
mIconView.setVisibility(showProgress ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(final CharSequence title) {
|
||||
setContentDescription(title);
|
||||
|
|
|
@ -101,11 +101,6 @@ public class HomeActionButtonCompat extends FrameLayout implements IHomeActionBu
|
|||
mIconView.setColorFilter(color, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowProgress(final boolean showProgress) {
|
||||
mIconView.setVisibility(showProgress ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(final CharSequence title) {
|
||||
setContentDescription(title);
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.res.Resources;
|
|||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
|
@ -19,6 +20,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -65,7 +67,6 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
|
|||
setLayoutManager(mLayoutManager = new TabLayoutManager(this));
|
||||
setItemContext(context);
|
||||
setAdapter(mIndicatorAdapter);
|
||||
setTabDisplayOption(ICON);
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPagerIndicator);
|
||||
setTabExpandEnabled(a.getBoolean(R.styleable.TabPagerIndicator_tabExpandEnabled, false));
|
||||
setHorizontalPadding(a.getDimensionPixelSize(R.styleable.TabPagerIndicator_tabHorizontalPadding, 0));
|
||||
|
@ -269,6 +270,109 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
|
|||
public @interface DisplayOption {
|
||||
}
|
||||
|
||||
public static final class SampleView extends LinearLayout {
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final int stripHeight;
|
||||
private int horizontalPadding;
|
||||
private int verticalPadding;
|
||||
private int stripColor;
|
||||
private int iconColor;
|
||||
private int labelColor;
|
||||
private int tabDisplayOption;
|
||||
private boolean tabShowDivider;
|
||||
private boolean tabExpandEnabled;
|
||||
|
||||
public SampleView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public SampleView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SampleView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
inflater = LayoutInflater.from(context);
|
||||
setOrientation(HORIZONTAL);
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPagerIndicator);
|
||||
this.setHorizontalPadding(a.getDimensionPixelSize(R.styleable.TabPagerIndicator_tabHorizontalPadding, 0));
|
||||
this.setTabExpandEnabled(a.getBoolean(R.styleable.TabPagerIndicator_tabExpandEnabled, false));
|
||||
this.setVerticalPadding(a.getDimensionPixelSize(R.styleable.TabPagerIndicator_tabVerticalPadding, 0));
|
||||
this.setStripColor(a.getColor(R.styleable.TabPagerIndicator_tabStripColor, 0));
|
||||
this.setIconColor(a.getColor(R.styleable.TabPagerIndicator_tabIconColor, 0));
|
||||
this.setLabelColor(a.getColor(R.styleable.TabPagerIndicator_tabLabelColor, ThemeUtils.getTextColorPrimary(context)));
|
||||
this.setTabDisplayOption(a.getInt(R.styleable.TabPagerIndicator_tabDisplayOption, ICON));
|
||||
this.setTabShowDivider(a.getBoolean(R.styleable.TabPagerIndicator_tabShowDivider, false));
|
||||
a.recycle();
|
||||
|
||||
stripHeight = context.getResources().getDimensionPixelSize(R.dimen.element_spacing_small);
|
||||
}
|
||||
|
||||
public void setHorizontalPadding(int horizontalPadding) {
|
||||
this.horizontalPadding = horizontalPadding;
|
||||
}
|
||||
|
||||
public void setVerticalPadding(int verticalPadding) {
|
||||
this.verticalPadding = verticalPadding;
|
||||
}
|
||||
|
||||
public void setStripColor(int stripColor) {
|
||||
this.stripColor = stripColor;
|
||||
}
|
||||
|
||||
public void setIconColor(int iconColor) {
|
||||
this.iconColor = iconColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(int labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
public void setTabDisplayOption(int tabDisplayOption) {
|
||||
this.tabDisplayOption = tabDisplayOption;
|
||||
}
|
||||
|
||||
public void setTabShowDivider(boolean tabShowDivider) {
|
||||
this.tabShowDivider = tabShowDivider;
|
||||
}
|
||||
|
||||
public void addTab(int icon, CharSequence label, int unread, boolean isCurrent) {
|
||||
final ItemLayout layout = (ItemLayout) inflater.inflate(R.layout.layout_tab_item, this, false);
|
||||
final ImageView tabIcon = (ImageView) layout.findViewById(R.id.tab_icon);
|
||||
final BadgeView badgeView = (BadgeView) layout.findViewById(R.id.unread_indicator);
|
||||
final TextView tabLabel = (TextView) layout.findViewById(R.id.tab_label);
|
||||
|
||||
layout.setStripColor(stripColor);
|
||||
layout.setStripHeight(stripHeight);
|
||||
layout.setIsCurrent(isCurrent);
|
||||
|
||||
tabIcon.setImageResource(icon);
|
||||
tabIcon.setColorFilter(iconColor, PorterDuff.Mode.SRC_ATOP);
|
||||
tabIcon.setVisibility((tabDisplayOption & ICON) != 0 ? VISIBLE : GONE);
|
||||
|
||||
tabLabel.setText(label);
|
||||
tabLabel.setTextColor(labelColor);
|
||||
tabLabel.setVisibility((tabDisplayOption & LABEL) != 0 ? VISIBLE : GONE);
|
||||
|
||||
badgeView.setText(String.valueOf(unread));
|
||||
badgeView.setVisibility(unread != 0 ? VISIBLE : GONE);
|
||||
|
||||
final LayoutParams params;
|
||||
if (tabExpandEnabled) {
|
||||
params = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
|
||||
} else {
|
||||
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 0);
|
||||
}
|
||||
addView(layout, params);
|
||||
}
|
||||
|
||||
public void setTabExpandEnabled(boolean tabExpandEnabled) {
|
||||
this.tabExpandEnabled = tabExpandEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ItemLayout extends RelativeLayout {
|
||||
|
||||
private final Paint mStripPaint;
|
||||
|
|
|
@ -18,8 +18,6 @@ public interface IHomeActionButton {
|
|||
|
||||
void setIconColor(int color, PorterDuff.Mode mode);
|
||||
|
||||
void setShowProgress(boolean showProgress);
|
||||
|
||||
void setTitle(CharSequence title);
|
||||
|
||||
void setTitle(int title);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -19,11 +18,10 @@
|
|||
-->
|
||||
|
||||
<org.mariotaku.twidere.view.HomeActionButton
|
||||
android:id="@+id/actions_button"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/actions_button"
|
||||
android:layout_width="@dimen/float_action_button_size"
|
||||
android:layout_height="@dimen/float_action_button_size"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/element_spacing_large"
|
||||
android:elevation="@dimen/element_spacing_small"
|
||||
android:visibility="visible"/>
|
||||
android:elevation="@dimen/element_spacing_small" />
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -24,7 +23,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?selectableItemBackground"
|
||||
android:duplicateParentState="true"/>
|
||||
android:duplicateParentState="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/icon"
|
||||
|
@ -33,6 +32,6 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_margin="@dimen/element_spacing_normal"
|
||||
android:contentDescription="@string/compose"
|
||||
android:scaleType="centerInside"/>
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
</merge>
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -19,6 +18,12 @@
|
|||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@id/delete_all"
|
||||
android:enabled="false"
|
||||
android:icon="@drawable/ic_action_delete"
|
||||
android:title="@string/delete_conversation"
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
|
@ -742,4 +742,6 @@
|
|||
<string name="dont_restart">Don\'t restart</string>
|
||||
<string name="user_list_details">List details</string>
|
||||
<string name="invalid_list_name">Must start with a letter and can consist only letters, numbers, \"-\", or \"_\".</string>
|
||||
<string name="delete_conversation">Delete conversation</string>
|
||||
<string name="delete_conversation_confirm_message">Delete all messages of this conversation?</string>
|
||||
</resources>
|
Loading…
Reference in New Issue