-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Activity data dividers #4294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AndyScherzinger
merged 20 commits into
nextcloud:master
from
AlexNi245:#2216-activity-data-divers-design
Aug 20, 2019
Merged
Activity data dividers #4294
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cd3d8dc
start to implement sticky header behavior
AlexNi245 a184345
first implementation of sticky header logic.
AlexNi245 13e7aff
increase height of header element and set backgroundcolor to white
AlexNi245 792a6b9
finish implementation of sticky header implementation. This feature w…
AlexNi245 b4764f7
remove unnecessary files
AlexNi245 c41dd38
optimize imports
AlexNi245 a26a895
apply changes to java doc
AlexNi245 7a30070
remove unnecessary TAG field and replace nested if statement with && …
AlexNi245 9012f43
set visibility from ActivityViewHeaderHolder back to protected
AlexNi245 b61f9e0
format ActivityListAdapter
AlexNi245 4ea9667
unit test for isHeader(int pos)
AlexNi245 0ac5a8b
add static import for com.owncloud.android.lib.resources.activities.m…
AlexNi245 cdd5d38
add getHeaderPositionForItem unit test
AlexNi245 6ffa9d0
remove duplicate entry of setContentView
AlexNi245 52a7ffe
add license text
AlexNi245 f4e964e
change class name of ActivityListItemDecoration to StickyHeaderItemDe…
AlexNi245 1dd2a5a
change naming of Canvas c to Canvas canvas
AlexNi245 5a3db5e
replace do while loop in getHeaderPositionForItem with while loop
AlexNi245 fa11565
fixed issue Avoid reassigning parameters such as 'itemPosition'
AlexNi245 9624019
activity header has now the same font size as a activity element
AlexNi245 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/main/java/com/owncloud/android/ui/activities/StickyHeaderItemDecoration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Nextcloud Android client application | ||
| * | ||
|
|
||
| * Copyright (C) 2019 Sevastyan Savanyuk | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program 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 Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.owncloud.android.ui.activities; | ||
|
|
||
| import android.graphics.Canvas; | ||
| import android.graphics.Color; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.owncloud.android.ui.adapter.StickyHeaderAdapter; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.recyclerview.widget.RecyclerView; | ||
|
|
||
| public class StickyHeaderItemDecoration extends RecyclerView.ItemDecoration { | ||
| private final StickyHeaderAdapter adapter; | ||
|
|
||
|
|
||
| public StickyHeaderItemDecoration(StickyHeaderAdapter stickyHeaderAdapter) { | ||
| this.adapter = stickyHeaderAdapter; | ||
| } | ||
|
|
||
| @Override | ||
| public void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { | ||
| super.onDrawOver(canvas, parent, state); | ||
|
|
||
| View topChild = parent.getChildAt(0); | ||
| if (topChild == null) { | ||
| return; | ||
| } | ||
| int topChildPosition = parent.getChildAdapterPosition(topChild); | ||
|
|
||
| if (topChildPosition == RecyclerView.NO_POSITION) { | ||
| return; | ||
| } | ||
| View currentHeader = getHeaderViewForItem(topChildPosition, parent); | ||
| fixLayoutSize(parent, currentHeader); | ||
| int contactPoint = currentHeader.getBottom(); | ||
| View childInContact = getChildInContact(parent, contactPoint); | ||
|
|
||
| if (childInContact == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (adapter.isHeader(parent.getChildAdapterPosition(childInContact))) { | ||
| moveHeader(canvas, currentHeader, childInContact); | ||
| return; | ||
| } | ||
|
|
||
| drawHeader(canvas, currentHeader); | ||
| } | ||
|
|
||
| private void drawHeader(Canvas canvas, View header) { | ||
| canvas.save(); | ||
| canvas.translate(0, 0); | ||
| header.draw(canvas); | ||
| canvas.restore(); | ||
| } | ||
|
|
||
| private void moveHeader(Canvas canvas, View currentHeader, View nextHeader) { | ||
| canvas.save(); | ||
| canvas.translate(0, nextHeader.getTop() - currentHeader.getHeight()); | ||
| currentHeader.draw(canvas); | ||
| canvas.restore(); | ||
| } | ||
|
|
||
| private View getChildInContact(RecyclerView parent, int contactPoint) { | ||
| View childInContact = null; | ||
| for (int i = 0; i < parent.getChildCount(); i++) { | ||
| View currentChild = parent.getChildAt(i); | ||
| if (currentChild.getBottom() > contactPoint && currentChild.getTop() <= contactPoint) { | ||
| childInContact = currentChild; | ||
| break; | ||
| } | ||
| } | ||
| return childInContact; | ||
| } | ||
|
|
||
| private View getHeaderViewForItem(int itemPosition, RecyclerView parent) { | ||
| int headerPosition = adapter.getHeaderPositionForItem(itemPosition); | ||
| int layoutId = adapter.getHeaderLayout(itemPosition); | ||
| View header = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); | ||
| header.setBackgroundColor(Color.WHITE); | ||
| adapter.bindHeaderData(header, headerPosition); | ||
| return header; | ||
| } | ||
|
|
||
| private void fixLayoutSize(ViewGroup parent, View view) { | ||
|
|
||
| // Specs for parent (RecyclerView) | ||
| int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); | ||
| int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); | ||
|
|
||
| // Specs for children (headers) | ||
| int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), view.getLayoutParams().width); | ||
| int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), view.getLayoutParams().height); | ||
|
|
||
| view.measure(childWidthSpec, childHeightSpec); | ||
| view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); | ||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/owncloud/android/ui/adapter/StickyHeaderAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Nextcloud Android client application | ||
| * | ||
|
|
||
| * Copyright (C) 2019 Sevastyan Savanyuk | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program 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 Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.owncloud.android.ui.adapter; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also licence here, please |
||
|
|
||
| import android.view.View; | ||
|
|
||
| import com.owncloud.android.ui.activities.StickyHeaderItemDecoration; | ||
|
|
||
| public interface StickyHeaderAdapter { | ||
| /** | ||
| * This method gets called by {@link StickyHeaderItemDecoration} to fetch the position of the header item in the adapter | ||
| * that is used for (represents) item at specified position. | ||
| * @param itemPosition int. Adapter's position of the item for which to do the search of the position of the header item. | ||
| * @return int. Position of the header item in the adapter. | ||
| */ | ||
| int getHeaderPositionForItem(int itemPosition); | ||
|
|
||
| /** | ||
| * This method gets called by {@link StickyHeaderItemDecoration} to get layout resource id for the header item at specified adapter's position. | ||
| * @param headerPosition int. Position of the header item in the adapter. | ||
| * @return int. Layout resource id. | ||
| */ | ||
| int getHeaderLayout(int headerPosition); | ||
|
|
||
| /** | ||
| * This method gets called by {@link StickyHeaderItemDecoration} to setup the header View. | ||
| * @param header View. Header to set the data on. | ||
| * @param headerPosition int. Position of the header item in the adapter. | ||
| */ | ||
| void bindHeaderData(View header, int headerPosition); | ||
|
|
||
| /** | ||
| * This method gets called by {@link StickyHeaderItemDecoration} to verify whether the item represents a header. | ||
| * @param itemPosition int. | ||
| * @return true, if item at the specified adapter's position represents a header. | ||
| */ | ||
| boolean isHeader(int itemPosition); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always have trouble reading do while loops, as they are so rarely used.
Can this maybe transformed in a regular while loop?