Skip to content

Commit

Permalink
Added buttons to skip between top-level comments
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed May 6, 2017
1 parent edbde4c commit 9004dd2
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
78/1.9.8
Added buttons to skip between top-level comments
Added ability to edit self-posts (thanks to Clubfan22)
Added long-click menu for links and album list items (thanks to Clubfan22)
Image captions are now shown in the album list view (thanks to Clubfan22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public int getItemCount() {
return count;
}

public Item getItemAtPosition(final int position) {
return getItemInternal(position);
}

public void appendToGroup(final int group, final Item item) {

final int position = getItemPositionInternal(group + 1, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ public void updateHiddenStatus() {
General.checkThisIsUIThread();
mAdapter.updateHiddenStatus();
}

public GroupedRecyclerViewAdapter.Item getItemAtPosition(final int position) {
return mAdapter.getItemAtPosition(position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static boolean isRestartRequired(Context context, String key) {
|| context.getString(R.string.pref_behaviour_bezel_toolbar_swipezone_key).equals(key)
|| context.getString(R.string.pref_appearance_hide_username_main_menu_key).equals(key)
|| context.getString(R.string.pref_appearance_hide_android_status_key).equals(key)
|| context.getString(R.string.pref_appearance_comments_show_floating_toolbar_key).equals(key)
|| context.getString(R.string.pref_behaviour_enable_swipe_refresh_key).equals(key);
}

Expand Down Expand Up @@ -267,6 +268,10 @@ public static boolean pref_appearance_image_viewer_show_floating_toolbar(final C
return getBoolean(R.string.pref_appearance_image_viewer_show_floating_toolbar_key, true, context, sharedPreferences);
}

public static boolean pref_appearance_comments_show_floating_toolbar(final Context context, final SharedPreferences sharedPreferences) {
return getBoolean(R.string.pref_appearance_comments_show_floating_toolbar_key, true, context, sharedPreferences);
}

public static boolean pref_appearance_indentlines(final Context context, final SharedPreferences sharedPreferences) {
return getBoolean(R.string.pref_appearance_indentlines_key, false, context, sharedPreferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.*;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
Expand All @@ -37,6 +44,7 @@
import org.quantumbadger.redreader.activities.CommentReplyActivity;
import org.quantumbadger.redreader.activities.OptionsMenuUtility;
import org.quantumbadger.redreader.adapters.FilteredCommentListingManager;
import org.quantumbadger.redreader.adapters.GroupedRecyclerViewAdapter;
import org.quantumbadger.redreader.cache.downloadstrategy.DownloadStrategy;
import org.quantumbadger.redreader.cache.downloadstrategy.DownloadStrategyAlways;
import org.quantumbadger.redreader.cache.downloadstrategy.DownloadStrategyIfNotCached;
Expand Down Expand Up @@ -82,6 +90,7 @@ public class CommentListingFragment extends RRFragment
private final RecyclerView mRecyclerView;

private final FrameLayout mOuterFrame;
private final @Nullable LinearLayout mFloatingToolbar;

private final float mCommentFontScale;
private final boolean mShowLinkButtons;
Expand Down Expand Up @@ -162,6 +171,110 @@ public void onRefresh() {
}
*/

if(!PrefsUtility.pref_appearance_comments_show_floating_toolbar(context, prefs)) {
mFloatingToolbar = null;

} else {
mFloatingToolbar = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.floating_toolbar, mOuterFrame, false);

// We need a container so that setVisible() doesn't mess with the Z-order
final FrameLayout floatingToolbarContainer = new FrameLayout(context);

floatingToolbarContainer.addView(mFloatingToolbar);
mOuterFrame.addView(floatingToolbarContainer);

if(PrefsUtility.isNightMode(context)) {
mFloatingToolbar.setBackgroundColor(Color.argb(0xCC, 0x33, 0x33, 0x33));
}

final int buttonVPadding = General.dpToPixels(context, 12);
final int buttonHPadding = General.dpToPixels(context, 16);

{
final ImageButton previousButton = (ImageButton) LayoutInflater.from(context).inflate(
R.layout.flat_image_button, mFloatingToolbar, false);

previousButton.setPadding(buttonHPadding, buttonVPadding, buttonHPadding, buttonVPadding);
previousButton.setImageResource(R.drawable.ic_ff_up_dark);
previousButton.setContentDescription(getString(R.string.button_prev_comment_parent));
mFloatingToolbar.addView(previousButton);

previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {

final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();

for(int pos = layoutManager.findFirstVisibleItemPosition() - 1;
pos > 0;
pos--) {

final GroupedRecyclerViewAdapter.Item item = mCommentListingManager.getItemAtPosition(pos);

if(item instanceof RedditCommentListItem
&& ((RedditCommentListItem) item).isComment()
&& ((RedditCommentListItem) item).getIndent() == 0) {

layoutManager.scrollToPositionWithOffset(pos, 0);
return;
}
}

layoutManager.scrollToPositionWithOffset(0, 0);
}
});

previousButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View view) {
General.quickToast(context, R.string.button_prev_comment_parent);
return true;
}
});
}

{
final ImageButton nextButton = (ImageButton) LayoutInflater.from(context).inflate(
R.layout.flat_image_button, mFloatingToolbar, false);

nextButton.setPadding(buttonHPadding, buttonVPadding, buttonHPadding, buttonVPadding);
nextButton.setImageResource(R.drawable.ic_ff_down_dark);
nextButton.setContentDescription(getString(R.string.button_next_comment_parent));
mFloatingToolbar.addView(nextButton);

nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {

final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();

for(int pos = layoutManager.findFirstVisibleItemPosition() + 1;
pos < layoutManager.getItemCount();
pos++) {

final GroupedRecyclerViewAdapter.Item item = mCommentListingManager.getItemAtPosition(pos);

if(item instanceof RedditCommentListItem
&& ((RedditCommentListItem) item).isComment()
&& ((RedditCommentListItem) item).getIndent() == 0) {

layoutManager.scrollToPositionWithOffset(pos, 0);
break;
}
}
}
});

nextButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View view) {
General.quickToast(context, R.string.button_next_comment_parent);
return true;
}
});
}
}

final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(context);

final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(context, new BezelSwipeOverlay.BezelSwipeListener() {
Expand Down Expand Up @@ -443,6 +556,13 @@ public void onCommentListingRequestAllItemsDownloaded(final ArrayList<RedditComm

mCommentListingManager.addComments(items);

if(mFloatingToolbar != null) {
mFloatingToolbar.setVisibility(View.VISIBLE);
final Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.slide_in_from_bottom);
animation.setInterpolator(new OvershootInterpolator());
mFloatingToolbar.startAnimation(animation);
}

mUrlsToDownload.removeFirst();

final LinearLayoutManager layoutManager = (LinearLayoutManager)mRecyclerView.getLayoutManager();
Expand All @@ -460,6 +580,7 @@ public void onCommentListingRequestAllItemsDownloaded(final ArrayList<RedditComm
if(mUrlsToDownload.isEmpty()) {

if(mCommentListingManager.getCommentCount() == 0) {

final View emptyView = LayoutInflater.from(getContext()).inflate(
R.layout.no_comments_yet,
mRecyclerView,
Expand All @@ -470,6 +591,13 @@ public void onCommentListingRequestAllItemsDownloaded(final ArrayList<RedditComm
}

mCommentListingManager.addViewToItems(emptyView);

} else {

final View blankView = new View(getContext());
blankView.setMinimumWidth(1);
blankView.setMinimumHeight(General.dpToPixels(getContext(), 96));
mCommentListingManager.addViewToItems(blankView);
}

mCommentListingManager.setLoadingVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import org.quantumbadger.redreader.common.General;

public class VerticalToolbar extends FrameLayout {

Expand All @@ -33,6 +35,11 @@ public VerticalToolbar(Context context) {
super(context);

setBackgroundColor(Color.argb(192, 0, 0, 0)); // TODO change color based on theme?

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setElevation(General.dpToPixels(context, 10));
}

// TODO add light, vertical line on swipe side

buttons = new LinearLayout(context);
Expand Down
33 changes: 33 additions & 0 deletions src/main/res/anim/slide_in_from_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ This file is part of RedReader.
~
~ RedReader 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.
~
~ RedReader 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 RedReader. If not, see <http://www.gnu.org/licenses/>.
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:fillAfter="true"
android:duration="500"/>

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:fillAfter="true"
android:duration="500"/>
</set>
25 changes: 25 additions & 0 deletions src/main/res/drawable/ic_ff_down_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24" >

<path
android:fillColor="#FFFFFFFF"
android:pathData="M18.0,4.0l-6.0,8.5L6.0,4.0L18.0,4.0zM6.0,13.0l12.0,0.0l-6.0,8.5L6.0,13.0z"/>
</vector>
24 changes: 24 additions & 0 deletions src/main/res/drawable/ic_ff_up_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24" >
<path
android:fillColor="#FFFFFFFF"
android:pathData="M18.0,11.0L6.0,11.0l6.0,-8.5L18.0,11.0zM12.0,11.5l6.0,8.5L6.0,20.0L12.0,11.5z"/>
</vector>
2 changes: 1 addition & 1 deletion src/main/res/layout/flat_image_button.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?selectableItemBackgroundBorderless"
android:background="@drawable/rr_actionbar_selector"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
23 changes: 21 additions & 2 deletions src/main/res/layout/floating_toolbar.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ This file is part of RedReader.
~
~ RedReader 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.
~
~ RedReader 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 RedReader. If not, see <http://www.gnu.org/licenses/>.
-->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="24dp"
android:background="#c8000000"
android:orientation="vertical"
android:visibility="gone"/>
android:orientation="horizontal"
android:visibility="gone"
android:elevation="2dp"/>
7 changes: 7 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,11 @@
<!-- 2017-04-14 -->
<string name="collapsed_self_post">Self-post collapsed</string>

<!-- 2017-05-08 -->
<string name="button_next_comment_parent">Next Parent Comment</string>
<string name="button_prev_comment_parent">Previous Parent Comment</string>

<string name="pref_appearance_comments_show_floating_toolbar_title">Show floating toolbar over comments</string>
<string name="pref_appearance_comments_show_floating_toolbar_key" translatable="false">pref_appearance_comments_show_floating_toolbar</string>

</resources>

0 comments on commit 9004dd2

Please sign in to comment.