diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java index a2b3f44c3..765b4a748 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java @@ -1453,12 +1453,13 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL @Override protected Boolean doInBackground(final Object... params) { + InputStream is = null; + OutputStream os = null; try { final ContentResolver resolver = activity.getContentResolver(); - final InputStream is = resolver.openInputStream(src); - final OutputStream os = resolver.openOutputStream(dst); + is = resolver.openInputStream(src); + os = resolver.openOutputStream(dst); Utils.copyStream(is, os); - os.close(); if (ContentResolver.SCHEME_FILE.equals(src.getScheme()) && delete_src) { final File file = new File(src.getPath()); if (!file.delete()) { @@ -1468,6 +1469,9 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL } catch (final IOException e) { Log.w(LOGTAG, e); return false; + } finally { + Utils.closeSilently(os); + Utils.closeSilently(is); } return true; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java index f64daadc2..03658f8a4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentRecyclerViewFragment.java @@ -76,6 +76,7 @@ public abstract class AbsContentRecyclerViewFragment 0) { + final Menu menu = mPopupMenu.getMenu(); + final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status); + final MenuItem linkToQuotedStatus = menu.findItem(R.id.link_to_quoted_status); + final Uri statusLink; + final long inReplyToStatusId; + if (!status.is_quote) { + inReplyToStatusId = status.id; + statusLink = LinkCreator.getTwitterStatusLink(status.quoted_by_user_screen_name, status.id); + } else if (quoteOriginalStatus.isChecked()) { + inReplyToStatusId = status.quote_id; + statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.quote_id); + } else { + inReplyToStatusId = status.id; + statusLink = LinkCreator.getTwitterStatusLink(status.quoted_by_user_screen_name, status.id); + } + final String commentText = mEditComment.getText() + " " + statusLink; + twitter.updateStatusAsync(new long[]{status.account_id}, commentText, null, null, + linkToQuotedStatus.isChecked() ? inReplyToStatusId : -1, status.is_possibly_sensitive); + } else if (isMyRetweet(status)) { twitter.cancelRetweetAsync(status.account_id, status.id, status.my_retweet_id); } else { twitter.retweetStatusAsync(status.account_id, status.id); @@ -82,6 +113,8 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem final StatusViewHolder holder = new StatusViewHolder(new DummyStatusHolderAdapter(context), view.findViewById(R.id.item_content)); final ParcelableStatus status = getStatus(); + assert status != null; + builder.setView(view); builder.setTitle(R.string.retweet_quote_confirm_title); builder.setPositiveButton(isMyRetweet(status) ? R.string.cancel_retweet : R.string.retweet, this); @@ -93,6 +126,32 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem view.findViewById(R.id.item_menu).setVisibility(View.GONE); view.findViewById(R.id.action_buttons).setVisibility(View.GONE); view.findViewById(R.id.item_content).setFocusable(false); + mEditComment = (MaterialEditText) view.findViewById(R.id.edit_comment); + mCommentMenu = view.findViewById(R.id.comment_menu); + + mPopupMenu = new PopupMenu(context, mCommentMenu, Gravity.NO_GRAVITY, + R.attr.actionOverflowMenuStyle, 0); + mCommentMenu.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mPopupMenu.show(); + } + }); + mCommentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener()); + mPopupMenu.inflate(R.menu.menu_dialog_comment); + final Menu menu = mPopupMenu.getMenu(); + MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status, + status.retweet_id > 0 || status.quote_id > 0); + mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + if (item.isCheckable()) { + item.setChecked(!item.isChecked()); + return true; + } + return false; + } + }); return builder.create(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index baf4ebec7..7e6f85e5f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -1350,8 +1350,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener final AppCompatActivity activity = (AppCompatActivity) getActivity(); final IThemedActivity themed = (IThemedActivity) activity; final int themeRes = themed.getCurrentThemeResourceId(); - final int actionBarColor = ThemeUtils.getActionBarColor(activity, color, - themed.getCurrentThemeResourceId(), themed.getThemeBackgroundOption()); + final String backgroundOption = themed.getThemeBackgroundOption(); + final int actionBarColor = ThemeUtils.getActionBarColor(activity, color, themeRes, backgroundOption); if (mTintedStatusContent != null) { mTintedStatusContent.setColor(actionBarColor, themed.getCurrentThemeBackgroundAlpha()); } @@ -1363,7 +1363,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mProfileBannerView.setBackgroundColor(color); mLocationView.setLinkTextColor(color); mURLView.setLinkTextColor(color); - ViewSupport.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity, themeRes, color, true)); + ViewSupport.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity, + themeRes, color, backgroundOption, true)); final HeaderDrawerLayout drawer = mHeaderDrawerLayout; if (drawer != null) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/ColorPickerPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/ColorPickerPreference.java index f6c885278..5c9437545 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/ColorPickerPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/ColorPickerPreference.java @@ -83,12 +83,12 @@ public class ColorPickerPreference extends DialogPreference implements DialogInt @Override protected void onPrepareDialogBuilder(Builder builder) { mController = ColorPickerDialog.Controller.applyToDialogBuilder(builder); + mController.setAlphaEnabled(mAlphaSliderEnabled); final Resources res = builder.getContext().getResources(); for (int presetColor : PRESET_COLORS) { mController.addColor(res.getColor(presetColor)); } mController.setInitialColor(getValue()); - mController.setAlphaEnabled(mAlphaSliderEnabled); builder.setPositiveButton(res.getString(android.R.string.ok), this); builder.setNegativeButton(res.getString(android.R.string.cancel), this); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java index d7edd681e..b25952c8f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java @@ -65,7 +65,6 @@ import org.apache.commons.lang3.ArrayUtils; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IThemedActivity; -import org.mariotaku.twidere.activity.support.HomeActivity; import org.mariotaku.twidere.graphic.ActionBarColorDrawable; import org.mariotaku.twidere.graphic.ActionIconDrawable; import org.mariotaku.twidere.text.ParagraphSpacingSpan; @@ -101,7 +100,7 @@ public class ThemeUtils implements Constants { if (actionBar == null || context == null) return; actionBar.setBackgroundDrawable(getActionBarBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled)); actionBar.setSplitBackgroundDrawable(getActionBarSplitBackground(context, themeRes)); - actionBar.setStackedBackgroundDrawable(getActionBarStackedBackground(context, themeRes, accentColor, outlineEnabled)); + actionBar.setStackedBackgroundDrawable(getActionBarStackedBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled)); } @@ -110,7 +109,7 @@ public class ThemeUtils implements Constants { if (actionBar == null || context == null) return; actionBar.setPrimaryBackground(getActionBarBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled)); actionBar.setSplitBackground(getActionBarSplitBackground(context, themeRes)); - actionBar.setStackedBackground(getActionBarStackedBackground(context, themeRes, accentColor, outlineEnabled)); + actionBar.setStackedBackground(getActionBarStackedBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled)); } public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor, @@ -261,14 +260,9 @@ public class ThemeUtils implements Constants { @NonNull public static Drawable getActionBarStackedBackground(final Context context, final int themeRes, - final int accentColor, boolean outlineEnabled) { - final int actionBarColor; - if (isDarkTheme(themeRes)) { - actionBarColor = context.getResources().getColor(R.color.background_color_action_bar_dark); - } else { - actionBarColor = accentColor; - } - return ActionBarColorDrawable.create(actionBarColor, outlineEnabled); + final int accentColor, String backgroundOption, + boolean outlineEnabled) { + return getActionBarBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled); } public static int getCardBackgroundColor(final Context context, String backgroundOption, int themeAlpha) { @@ -717,6 +711,7 @@ public class ThemeUtils implements Constants { if (!(activity instanceof IThemedActivity)) return; final int themeRes = ((IThemedActivity) activity).getCurrentThemeResourceId(); final int themeColor = ((IThemedActivity) activity).getCurrentThemeColor(); + final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption(); final int colorDark, colorLight; final int[] textColors = new int[2]; getTextColorPrimaryAndInverse(activity, textColors); @@ -729,7 +724,7 @@ public class ThemeUtils implements Constants { } final int contrastColor = TwidereColorUtils.getContrastYIQ(themeColor, ACCENT_COLOR_THRESHOLD, colorDark, colorLight); - ViewSupport.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, true)); + ViewSupport.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, backgroundOption, true)); if (isDarkTheme(themeRes)) { final int foregroundColor = getThemeForegroundColor(activity); indicator.setIconColor(foregroundColor); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 045e2c6bf..2809c5cca 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -140,8 +140,15 @@ import org.mariotaku.twidere.activity.support.ColorPickerDialogActivity; import org.mariotaku.twidere.activity.support.MediaViewerActivity; import org.mariotaku.twidere.adapter.iface.IBaseAdapter; import org.mariotaku.twidere.adapter.iface.IBaseCardAdapter; -import org.mariotaku.twidere.api.twitter.model.Status; +import org.mariotaku.twidere.api.twitter.Twitter; +import org.mariotaku.twidere.api.twitter.TwitterConstants; +import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.auth.OAuthSupport; +import org.mariotaku.twidere.api.twitter.model.DirectMessage; +import org.mariotaku.twidere.api.twitter.model.RateLimitStatus; +import org.mariotaku.twidere.api.twitter.model.Relationship; +import org.mariotaku.twidere.api.twitter.model.Status; +import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback; import org.mariotaku.twidere.fragment.support.AccountsManagerFragment; import org.mariotaku.twidere.fragment.support.AddStatusFilterDialogFragment; @@ -249,13 +256,6 @@ import javax.net.ssl.SSLException; import edu.tsinghua.spice.SpiceService; import edu.ucdavis.earlybird.UCDService; -import org.mariotaku.twidere.api.twitter.model.DirectMessage; -import org.mariotaku.twidere.api.twitter.model.RateLimitStatus; -import org.mariotaku.twidere.api.twitter.model.Relationship; -import org.mariotaku.twidere.api.twitter.Twitter; -import org.mariotaku.twidere.api.twitter.TwitterConstants; -import org.mariotaku.twidere.api.twitter.TwitterException; -import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; import static android.text.TextUtils.isEmpty; import static android.text.format.DateUtils.getRelativeTimeSpanString; @@ -1023,9 +1023,13 @@ public final class Utils implements Constants, TwitterConstants { break; } case LINK_ID_SEARCH: { - final String param_query = uri.getQueryParameter(QUERY_PARAM_QUERY); - if (isEmpty(param_query)) return null; - args.putString(EXTRA_QUERY, param_query); + final String paramQuery = uri.getQueryParameter(QUERY_PARAM_QUERY); + if (!args.containsKey(EXTRA_QUERY) && !isEmpty(paramQuery)) { + args.putString(EXTRA_QUERY, paramQuery); + } + if (!args.containsKey(EXTRA_QUERY)) { + return null; + } fragment = new SearchFragment(); break; } @@ -2746,15 +2750,28 @@ public final class Utils implements Constants, TwitterConstants { activity.startActivity(intent); } - public static void openSearch(final Context context, final long account_id, final String query) { + public static void openSearch(final Context context, final long accountId, final String query) { + openSearch(context, accountId, query, null); + } + + public static void openSearch(final Context context, final long accountId, final String query, String type) { if (context == null) return; + final Intent intent = new Intent(Intent.ACTION_VIEW); + // Some devices cannot process query parameter with hashes well, so add this intent extra + intent.putExtra(EXTRA_QUERY, query); + intent.putExtra(EXTRA_ACCOUNT_ID, accountId); + final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_SEARCH); - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id)); + builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId)); builder.appendQueryParameter(QUERY_PARAM_QUERY, query); - final Uri uri = builder.build(); - final Intent intent = new Intent(Intent.ACTION_VIEW, uri); + if (!TextUtils.isEmpty(type)) { + builder.appendQueryParameter(QUERY_PARAM_TYPE, type); + intent.putExtra(EXTRA_TYPE, type); + } + intent.setData(builder.build()); + context.startActivity(intent); } @@ -2833,17 +2850,7 @@ public final class Utils implements Constants, TwitterConstants { } public static void openTweetSearch(final Context context, final long accountId, final String query) { - if (context == null) return; - final Uri.Builder builder = new Uri.Builder(); - builder.scheme(SCHEME_TWIDERE); - builder.authority(AUTHORITY_SEARCH); - builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId)); - builder.appendQueryParameter(QUERY_PARAM_TYPE, QUERY_PARAM_VALUE_TWEETS); - if (query != null) { - builder.appendQueryParameter(QUERY_PARAM_QUERY, query); - } - final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); - context.startActivity(intent); + openSearch(context, accountId, query, QUERY_PARAM_VALUE_TWEETS); } public static void openUserBlocks(final Activity activity, final long account_id) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/imageloader/TwidereImageDownloader.java b/twidere/src/main/java/org/mariotaku/twidere/util/imageloader/TwidereImageDownloader.java index 386cb21aa..380edf467 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/imageloader/TwidereImageDownloader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/imageloader/TwidereImageDownloader.java @@ -163,6 +163,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const additionalHeaders.add(Pair.create("Accept", "image/webp, */*")); } final String method = GET.METHOD; + final String requestUri; if (auth != null && auth.hasAuthorization()) { final Endpoint endpoint; if (auth instanceof OAuthAuthorization) { @@ -179,9 +180,8 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const final RequestInfo info = new RequestInfo(method, uri.getPath(), queries, null, additionalHeaders, null, null, null, null); additionalHeaders.add(Pair.create("Authorization", auth.getHeader(endpoint, info))); - } - final String requestUri; - if (mThumbor != null) { + requestUri = modifiedUri.toString(); + } else if (mThumbor != null) { requestUri = mThumbor.buildImage(modifiedUri.toString()).filter(ThumborUrlBuilder.quality(85)).toUrl(); } else { requestUri = modifiedUri.toString(); diff --git a/twidere/src/main/res/layout/dialog_status_quote_retweet.xml b/twidere/src/main/res/layout/dialog_status_quote_retweet.xml index 925afb86f..5f4852dd0 100644 --- a/twidere/src/main/res/layout/dialog_status_quote_retweet.xml +++ b/twidere/src/main/res/layout/dialog_status_quote_retweet.xml @@ -1,5 +1,4 @@ - - - - + android:paddingRight="@dimen/element_spacing_large" + android:paddingTop="@dimen/element_spacing_normal"> + android:layout_height="wrap_content" + android:orientation="vertical"> - + android:orientation="horizontal"> - + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/menu/menu_dialog_comment.xml b/twidere/src/main/res/menu/menu_dialog_comment.xml new file mode 100644 index 000000000..8cac89963 --- /dev/null +++ b/twidere/src/main/res/menu/menu_dialog_comment.xml @@ -0,0 +1,30 @@ + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index e24e692d3..98683b42f 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -406,6 +406,7 @@ Search \"%s\" deleted. Import from… Link to quoted tweet + Quote original tweet Followed %s. Sent follow request to %s. Unfollowed %s. @@ -746,4 +747,5 @@ Delete all messages of this conversation? Display name first Display @screenname first + Comment... \ No newline at end of file