improved card action button

This commit is contained in:
Mariotaku Lee 2016-03-20 14:16:48 +08:00
parent 8cff3f83c4
commit b228d3671b
7 changed files with 239 additions and 137 deletions

View File

@ -96,6 +96,7 @@ import org.mariotaku.twidere.util.media.MediaExtra;
import org.mariotaku.twidere.util.media.preview.provider.TwitterMediaProvider; import org.mariotaku.twidere.util.media.preview.provider.TwitterMediaProvider;
import java.io.File; import java.io.File;
import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
@ -623,9 +624,6 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
getDelegate().invalidateOptionsMenu(); getDelegate().invalidateOptionsMenu();
} }
/**
* @hide
*/
@Override @Override
public void invalidateOptionsMenu() { public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu(); getDelegate().invalidateOptionsMenu();
@ -1043,9 +1041,11 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
protected Uri getDownloadUri() { protected Uri getDownloadUri() {
final Pair<String, String> bestVideoUrlAndType = getBestVideoUrlAndType(getMedia(), final Pair<String, String> bestVideoUrlAndType = getBestVideoUrlAndType(getMedia(),
SUPPORTED_VIDEO_TYPES); SUPPORTED_VIDEO_TYPES);
if (bestVideoUrlAndType == null || bestVideoUrlAndType.first == null) return null; if (bestVideoUrlAndType != null && bestVideoUrlAndType.first != null) {
return Uri.parse(bestVideoUrlAndType.first); return Uri.parse(bestVideoUrlAndType.first);
} }
return getArguments().getParcelable(ImagePageFragment.EXTRA_MEDIA_URI);
}
@Override @Override
@ -1168,7 +1168,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
} }
@Nullable @Nullable
private Pair<String, String> getBestVideoUrlAndType(final ParcelableMedia media, private Pair<String, String> getBestVideoUrlAndType(@Nullable final ParcelableMedia media,
@NonNull final String[] supportedTypes) { @NonNull final String[] supportedTypes) {
if (media == null) return null; if (media == null) return null;
switch (media.type) { switch (media.type) {
@ -1265,6 +1265,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
} }
} }
@Nullable
private ParcelableMedia getMedia() { private ParcelableMedia getMedia() {
return getArguments().getParcelable(EXTRA_MEDIA); return getArguments().getParcelable(EXTRA_MEDIA);
} }
@ -1298,8 +1299,8 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
mProgressBar.setProgress(Math.round(1000 * position / (float) duration)); mProgressBar.setProgress(Math.round(1000 * position / (float) duration));
final long durationSecs = TimeUnit.SECONDS.convert(duration, TimeUnit.MILLISECONDS), final long durationSecs = TimeUnit.SECONDS.convert(duration, TimeUnit.MILLISECONDS),
positionSecs = TimeUnit.SECONDS.convert(position, TimeUnit.MILLISECONDS); positionSecs = TimeUnit.SECONDS.convert(position, TimeUnit.MILLISECONDS);
mDurationLabel.setText(String.format("%02d:%02d", durationSecs / 60, durationSecs % 60)); mDurationLabel.setText(String.format(Locale.ROOT, "%02d:%02d", durationSecs / 60, durationSecs % 60));
mPositionLabel.setText(String.format("%02d:%02d", positionSecs / 60, positionSecs % 60)); mPositionLabel.setText(String.format(Locale.ROOT, "%02d:%02d", positionSecs / 60, positionSecs % 60));
mHandler.postDelayed(this, 16); mHandler.postDelayed(this, 16);
} }
} }

View File

@ -70,8 +70,10 @@ public class CardPreviewPreference extends Preference implements Constants, OnSh
protected void setLayoutResources(SharedPreferences preferences) { protected void setLayoutResources(SharedPreferences preferences) {
if (preferences.getBoolean(KEY_COMPACT_CARDS, false)) { if (preferences.getBoolean(KEY_COMPACT_CARDS, false)) {
setLayoutResource(R.layout.layout_preferences_card_preview_compact); setLayoutResource(R.layout.layout_preferences_card_preview_compact);
mHolder = null;
} else { } else {
setLayoutResource(R.layout.layout_preferences_card_preview); setLayoutResource(R.layout.layout_preferences_card_preview);
mHolder = null;
} }
} }

View File

@ -0,0 +1,47 @@
package org.mariotaku.twidere.util.media.preview.provider;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.util.UriUtils;
/**
* Created by mariotaku on 16/3/20.
*/
public class ImgurProvider implements Provider {
@Override
public boolean supports(@NonNull String link) {
final String authority = UriUtils.getAuthority(link);
if (authority == null) return false;
switch (authority) {
case "i.imgur.com":
return true;
default:
return false;
}
}
@Nullable
@Override
public ParcelableMedia from(@NonNull String url) {
final String authority = UriUtils.getAuthority(url);
if (authority == null) return null;
switch (authority) {
case "i.imgur.com": {
final String path = UriUtils.getPath(url);
if (path == null) return null;
ParcelableMedia media = new ParcelableMedia();
media.url = url;
}
}
return null;
}
@Nullable
@Override
public ParcelableMedia from(@NonNull String link, @NonNull RestHttpClient client, @Nullable Object extra) {
return from(link);
}
}

View File

@ -11,6 +11,7 @@ import org.mariotaku.twidere.util.UriUtils;
import java.util.Locale; import java.util.Locale;
/** /**
* Process instagram image links
* Created by mariotaku on 16/1/1. * Created by mariotaku on 16/1/1.
*/ */
public class InstagramProvider implements Provider { public class InstagramProvider implements Provider {

View File

@ -34,10 +34,10 @@ import org.mariotaku.twidere.util.TwitterCardUtils;
import org.mariotaku.twidere.util.UnitConvertUtils; import org.mariotaku.twidere.util.UnitConvertUtils;
import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.IconActionButton;
import org.mariotaku.twidere.view.ActionIconThemedTextView; import org.mariotaku.twidere.view.ActionIconThemedTextView;
import org.mariotaku.twidere.view.CardMediaContainer; import org.mariotaku.twidere.view.CardMediaContainer;
import org.mariotaku.twidere.view.ForegroundColorView; import org.mariotaku.twidere.view.ForegroundColorView;
import org.mariotaku.twidere.view.IconActionView;
import org.mariotaku.twidere.view.NameView; import org.mariotaku.twidere.view.NameView;
import org.mariotaku.twidere.view.ShortTimeView; import org.mariotaku.twidere.view.ShortTimeView;
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder; import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder;
@ -69,8 +69,9 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
private final TextView statusInfoLabel; private final TextView statusInfoLabel;
private final ShortTimeView timeView; private final ShortTimeView timeView;
private final CardMediaContainer mediaPreview, quoteMediaPreview; private final CardMediaContainer mediaPreview, quoteMediaPreview;
private final IconActionButton replyIconView, retweetIconView, favoriteIconView; private final IconActionView replyIconView, retweetIconView, favoriteIconView;
private final TextView replyCountView, retweetCountView, favoriteCountView; private final TextView replyCountView, retweetCountView, favoriteCountView;
private final View replyView, retweetView, favoriteView;
private final IColorLabelView itemContent; private final IColorLabelView itemContent;
private final ForegroundColorView quoteIndicator; private final ForegroundColorView quoteIndicator;
private final View actionButtons; private final View actionButtons;
@ -111,9 +112,13 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
itemMenu = itemView.findViewById(R.id.item_menu); itemMenu = itemView.findViewById(R.id.item_menu);
actionButtons = itemView.findViewById(R.id.action_buttons); actionButtons = itemView.findViewById(R.id.action_buttons);
replyIconView = (IconActionButton) itemView.findViewById(R.id.reply_icon); replyView = itemView.findViewById(R.id.reply);
retweetIconView = (IconActionButton) itemView.findViewById(R.id.retweet_icon); retweetView = itemView.findViewById(R.id.retweet);
favoriteIconView = (IconActionButton) itemView.findViewById(R.id.favorite_icon); favoriteView = itemView.findViewById(R.id.favorite);
replyIconView = (IconActionView) itemView.findViewById(R.id.reply_icon);
retweetIconView = (IconActionView) itemView.findViewById(R.id.retweet_icon);
favoriteIconView = (IconActionView) itemView.findViewById(R.id.favorite_icon);
replyCountView = (ActionIconThemedTextView) itemView.findViewById(R.id.reply_count); replyCountView = (ActionIconThemedTextView) itemView.findViewById(R.id.reply_count);
retweetCountView = (ActionIconThemedTextView) itemView.findViewById(R.id.retweet_count); retweetCountView = (ActionIconThemedTextView) itemView.findViewById(R.id.retweet_count);
@ -461,9 +466,9 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
itemMenu.setOnClickListener(eventListener); itemMenu.setOnClickListener(eventListener);
profileImageView.setOnClickListener(eventListener); profileImageView.setOnClickListener(eventListener);
replyIconView.setOnClickListener(eventListener); replyView.setOnClickListener(eventListener);
retweetIconView.setOnClickListener(eventListener); retweetView.setOnClickListener(eventListener);
favoriteIconView.setOnClickListener(eventListener); favoriteView.setOnClickListener(eventListener);
} }
@Override @Override
@ -606,17 +611,20 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
break; break;
} }
case R.id.reply_count: case R.id.reply_count:
case R.id.reply_icon: { case R.id.reply_icon:
case R.id.reply: {
listener.onItemActionClick(holder, R.id.reply, position); listener.onItemActionClick(holder, R.id.reply, position);
break; break;
} }
case R.id.retweet_count: case R.id.retweet_count:
case R.id.retweet_icon: { case R.id.retweet_icon:
case R.id.retweet: {
listener.onItemActionClick(holder, R.id.retweet, position); listener.onItemActionClick(holder, R.id.retweet, position);
break; break;
} }
case R.id.favorite_count: case R.id.favorite_count:
case R.id.favorite_icon: { case R.id.favorite_icon:
case R.id.favorite: {
listener.onItemActionClick(holder, R.id.favorite, position); listener.onItemActionClick(holder, R.id.favorite, position);
break; break;
} }

View File

@ -321,12 +321,18 @@
android:paddingLeft="@dimen/element_spacing_small" android:paddingLeft="@dimen/element_spacing_small"
android:paddingRight="@dimen/element_spacing_small"> android:paddingRight="@dimen/element_spacing_small">
<org.mariotaku.twidere.view.IconActionButton <LinearLayout
android:id="@+id/reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/reply_icon" android:id="@+id/reply_icon"
android:layout_width="@dimen/button_size_content_card" android:layout_width="@dimen/button_size_content_card"
android:layout_height="@dimen/button_size_content_card" android:layout_height="@dimen/button_size_content_card"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/reply" android:contentDescription="@string/reply"
android:scaleType="centerInside" android:scaleType="centerInside"
android:src="@drawable/ic_action_reply" android:src="@drawable/ic_action_reply"
@ -343,13 +349,20 @@
android:tag="font_family|user" android:tag="font_family|user"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
tools:text="255"/> tools:text="255"/>
</LinearLayout>
<org.mariotaku.twidere.view.IconActionButton <LinearLayout
android:id="@+id/retweet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/retweet_icon" android:id="@+id/retweet_icon"
android:layout_width="@dimen/button_size_content_card" android:layout_width="@dimen/button_size_content_card"
android:layout_height="@dimen/button_size_content_card" android:layout_height="@dimen/button_size_content_card"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/retweet" android:contentDescription="@string/retweet"
android:scaleType="centerInside" android:scaleType="centerInside"
android:src="@drawable/ic_action_retweet" android:src="@drawable/ic_action_retweet"
@ -367,12 +380,20 @@
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
tools:text="255"/> tools:text="255"/>
<org.mariotaku.twidere.view.IconActionButton </LinearLayout>
<LinearLayout
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/favorite_icon" android:id="@+id/favorite_icon"
android:layout_width="@dimen/button_size_content_card" android:layout_width="@dimen/button_size_content_card"
android:layout_height="@dimen/button_size_content_card" android:layout_height="@dimen/button_size_content_card"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/like" android:contentDescription="@string/like"
android:scaleType="centerInside" android:scaleType="centerInside"
android:src="@drawable/ic_action_heart" android:src="@drawable/ic_action_heart"
@ -391,6 +412,7 @@
tools:text="255"/> tools:text="255"/>
</LinearLayout> </LinearLayout>
</LinearLayout>
<org.mariotaku.twidere.view.IconActionButton <org.mariotaku.twidere.view.IconActionButton
android:id="@+id/item_menu" android:id="@+id/item_menu"

View File

@ -280,12 +280,18 @@
android:orientation="horizontal" android:orientation="horizontal"
tools:visibility="visible"> tools:visibility="visible">
<org.mariotaku.twidere.view.IconActionButton <LinearLayout
android:id="@+id/reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/reply_icon" android:id="@+id/reply_icon"
android:layout_width="@dimen/button_size_content_card_compact" android:layout_width="@dimen/button_size_content_card_compact"
android:layout_height="@dimen/button_size_content_card_compact" android:layout_height="@dimen/button_size_content_card_compact"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/reply" android:contentDescription="@string/reply"
android:focusable="false" android:focusable="false"
android:gravity="center" android:gravity="center"
@ -304,13 +310,20 @@
android:tag="font_family|user" android:tag="font_family|user"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
tools:text="255"/> tools:text="255"/>
</LinearLayout>
<org.mariotaku.twidere.view.IconActionButton <LinearLayout
android:id="@+id/retweet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/retweet_icon" android:id="@+id/retweet_icon"
android:layout_width="@dimen/button_size_content_card_compact" android:layout_width="@dimen/button_size_content_card_compact"
android:layout_height="@dimen/button_size_content_card_compact" android:layout_height="@dimen/button_size_content_card_compact"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/retweet" android:contentDescription="@string/retweet"
android:focusable="false" android:focusable="false"
android:gravity="center" android:gravity="center"
@ -330,12 +343,20 @@
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
tools:text="255"/> tools:text="255"/>
<org.mariotaku.twidere.view.IconActionButton </LinearLayout>
<LinearLayout
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="false">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/favorite_icon" android:id="@+id/favorite_icon"
android:layout_width="@dimen/button_size_content_card_compact" android:layout_width="@dimen/button_size_content_card_compact"
android:layout_height="@dimen/button_size_content_card_compact" android:layout_height="@dimen/button_size_content_card_compact"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/like" android:contentDescription="@string/like"
android:focusable="false" android:focusable="false"
android:gravity="center" android:gravity="center"
@ -354,7 +375,7 @@
android:tag="font_family|user" android:tag="font_family|user"
android:textAppearance="?android:textAppearanceSmall" android:textAppearance="?android:textAppearanceSmall"
tools:text="255"/> tools:text="255"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
<org.mariotaku.twidere.view.IconActionButton <org.mariotaku.twidere.view.IconActionButton