Skip to content

Commit a184345

Browse files
AlexNi245AndyScherzinger
authored andcommitted
first implementation of sticky header logic.
Signed-off-by: alex <alex.plutta@googlemail.com> Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent cd3d8dc commit a184345

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/main/java/com/owncloud/android/ui/activities/ActivityListItemDecoration.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
package com.owncloud.android.ui.activities;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.graphics.Canvas;
56
import android.util.Log;
67
import android.view.View;
78

9+
import com.owncloud.android.ui.adapter.ActivityListAdapter;
10+
811
import androidx.annotation.NonNull;
912
import androidx.recyclerview.widget.RecyclerView;
1013

1114
public class ActivityListItemDecoration extends RecyclerView.ItemDecoration {
1215
private final String TAG = this.getClass().getSimpleName();
16+
private View currentHeader;
17+
1318
@Override
1419
public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
1520
super.onDrawOver(c, parent, state);
1621

17-
View topChild = parent.getChildAt(0);
18-
View currentHeader = topChild;
1922

23+
View topChild = parent.getChildAt(0);
24+
int topChildPosition = parent.getChildAdapterPosition(topChild);
25+
if (topChildPosition == -1) {
26+
return;
27+
}
28+
ActivityListAdapter adapter = (ActivityListAdapter) parent.getAdapter();
2029

30+
Object topElement = adapter.getActivityAtByPosition(topChildPosition);
2131

22-
if (currentHeader != null) {
23-
drawHeader(c, currentHeader);
24-
Log.d(TAG,"Attach new Header" );
32+
if (topElement instanceof ActivityListHeader) {
33+
currentHeader = parent.getChildAt(0);
2534
}
35+
drawHeader(c, currentHeader);
2636
}
2737

2838
private void drawHeader(Canvas c, View header) {

src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
243243
}
244244
}
245245

246+
public Object getActivityAtByPosition(int pos) {
247+
return values.get(pos);
248+
249+
}
250+
246251
private ImageView createThumbnailNew(PreviewObject previewObject) {
247252
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(px, px);
248253
params.setMargins(10, 10, 10, 10);

0 commit comments

Comments
 (0)