diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java index 1ac8487cb..3bf198ff0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsActivitiesFragment.java @@ -22,10 +22,12 @@ package org.mariotaku.twidere.fragment.support; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.Loader; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -39,6 +41,8 @@ import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.util.AsyncTwitterWrapper; +import org.mariotaku.twidere.util.KeyboardShortcutsHandler; +import org.mariotaku.twidere.util.RecyclerViewNavigationHelper; import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback; import org.mariotaku.twidere.view.holder.GapViewHolder; @@ -47,17 +51,16 @@ import org.mariotaku.twidere.view.holder.GapViewHolder; */ public abstract class AbsActivitiesFragment extends AbsContentRecyclerViewFragment> implements LoaderCallbacks, OnRefreshListener, DrawerCallback, RefreshScrollTopInterface, - ActivityAdapterListener { + ActivityAdapterListener, KeyboardShortcutsHandler.KeyboardShortcutCallback { private final Object mStatusesBusCallback; + private SharedPreferences mPreferences; + private RecyclerViewNavigationHelper mNavigationHelper; protected AbsActivitiesFragment() { mStatusesBusCallback = createMessageBusCallback(); } - private SharedPreferences mPreferences; - - @Override public void onGapClick(GapViewHolder holder, int position) { final ParcelableActivity activity = getAdapter().getActivity(position); @@ -66,6 +69,16 @@ public abstract class AbsActivitiesFragment extends AbsContentRecyclerView getActivities(accountIds, maxIds, null); } + @Override + public boolean handleKeyboardShortcutSingle(@NonNull KeyboardShortcutsHandler handler, int keyCode, @NonNull KeyEvent event) { + return false; + } + + @Override + public boolean handleKeyboardShortcutRepeat(@NonNull KeyboardShortcutsHandler handler, final int keyCode, final int repeatCount, + @NonNull final KeyEvent event) { + return mNavigationHelper.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event); + } public SharedPreferences getSharedPreferences() { if (mPreferences != null) return mPreferences; @@ -82,9 +95,11 @@ public abstract class AbsActivitiesFragment extends AbsContentRecyclerView @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + final AbsActivitiesAdapter adapter = getAdapter(); + mNavigationHelper = new RecyclerViewNavigationHelper(getRecyclerView(), getLayoutManager(), adapter); final View view = getView(); if (view == null) throw new AssertionError(); - getAdapter().setListener(this); + adapter.setListener(this); getLoaderManager().initLoader(0, getArguments(), this); showProgress(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index 64be3e128..79837b7e0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -114,6 +114,10 @@ public abstract class AbsStatusesFragment extends AbsContentRecyclerViewFr if (position == -1) return false; final ParcelableStatus status = getAdapter().getStatus(position); if (status == null) return false; + if (keyCode == KeyEvent.KEYCODE_ENTER) { + Utils.openStatus(getActivity(), status, null); + return true; + } if (action == null) { action = handler.getKeyAction(CONTEXT_TAG_STATUS, keyCode, event); } diff --git a/twidere/src/main/res/layout/card_item_status_compact.xml b/twidere/src/main/res/layout/card_item_status_compact.xml index ff067a81d..3fb82184b 100644 --- a/twidere/src/main/res/layout/card_item_status_compact.xml +++ b/twidere/src/main/res/layout/card_item_status_compact.xml @@ -16,11 +16,10 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> - @@ -41,8 +40,8 @@ style="?profileImageStyle" android:layout_width="@dimen/element_size_small" android:layout_height="@dimen/element_size_small" - android:layout_alignRight="@id/profile_image_space" android:layout_alignEnd="@id/profile_image_space" + android:layout_alignRight="@id/profile_image_space" android:layout_alignTop="@id/reply_retweet_status" android:layout_marginLeft="@dimen/element_spacing_small" android:layout_marginStart="@dimen/element_spacing_small" @@ -60,25 +59,25 @@ android:layout_alignLeft="@+id/status_content" android:layout_alignStart="@+id/status_content" android:layout_marginBottom="@dimen/element_spacing_small" - android:layout_marginRight="@dimen/element_spacing_normal" android:layout_marginEnd="@dimen/element_spacing_normal" + android:layout_marginRight="@dimen/element_spacing_normal" android:layout_marginTop="@dimen/element_spacing_minus_small" android:ellipsize="end" android:gravity="center_vertical|start" android:minHeight="@dimen/element_size_small" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceSmall" - tools:textSize="@dimen/text_size_extra_small" android:visibility="gone" tools:text="Retweeted by Mariotaku" + tools:textSize="@dimen/text_size_extra_small" tools:visibility="visible" /> @@ -194,8 +193,8 @@ android:layout_height="wrap_content" android:layout_alignBottom="@+id/text" android:layout_alignTop="@+id/quoted_name_container" - android:layout_marginRight="@dimen/element_spacing_normal" android:layout_marginEnd="@dimen/element_spacing_normal" + android:layout_marginRight="@dimen/element_spacing_normal" android:background="?android:dividerHorizontal" android:visibility="gone" tools:visibility="visible" /> @@ -205,8 +204,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/quote_text" - android:layout_toRightOf="@+id/quote_indicator" android:layout_toEndOf="@+id/quote_indicator" + android:layout_toRightOf="@+id/quote_indicator" android:gravity="center_vertical|start" android:orientation="horizontal" android:visibility="gone" @@ -242,8 +241,8 @@ android:layout_height="wrap_content" android:layout_below="@+id/quoted_name_container" android:layout_marginTop="@dimen/element_spacing_small" - android:layout_toRightOf="@+id/quote_indicator" android:layout_toEndOf="@+id/quote_indicator" + android:layout_toRightOf="@+id/quote_indicator" android:horizontalSpacing="@dimen/element_spacing_xsmall" android:verticalSpacing="@dimen/element_spacing_xsmall"> @@ -257,8 +256,8 @@ android:layout_height="wrap_content" android:layout_below="@id/media_preview" android:layout_marginTop="@dimen/element_spacing_small" - android:layout_toRightOf="@+id/quote_indicator" android:layout_toEndOf="@+id/quote_indicator" + android:layout_toRightOf="@+id/quote_indicator" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?android:attr/textColorPrimary" tools:text="@string/sample_status_text" /> @@ -336,8 +335,8 @@ android:layout_width="@dimen/button_size_content_card" android:layout_height="wrap_content" android:layout_alignBottom="@+id/action_buttons" - android:layout_alignParentRight="true" android:layout_alignParentEnd="true" + android:layout_alignParentRight="true" android:layout_alignTop="@+id/action_buttons" android:layout_marginTop="@dimen/element_spacing_minus_normal" android:color="?android:textColorTertiary"