start to implement sticky header behavior

Signed-off-by: alex <alex.plutta@googlemail.com>
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
alex 2019-08-11 23:40:01 +02:00 committed by Andy Scherzinger
parent 259e106308
commit cd3d8dca12
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 79 additions and 24 deletions

View file

@ -60,7 +60,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
public class ActivitiesActivity extends FileActivity implements ActivityListInterface, ActivitiesContract.View {
public class ActivitiesActivity extends FileActivity implements ActivityListInterface, ActivityListElement, ActivitiesContract.View {
private static final String TAG = ActivitiesActivity.class.getSimpleName();
@BindView(R.id.empty_list_view)
@ -104,9 +104,9 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
protected void onCreate(Bundle savedInstanceState) {
Log_OC.v(TAG, "onCreate() start");
super.onCreate(savedInstanceState);
mActionListener = new ActivitiesPresenter(activitiesRepository, filesRepository, this);
setContentView(R.layout.activity_list_layout);
setContentView(R.layout.activity_list_layout);
unbinder = ButterKnife.bind(this);
@ -165,7 +165,7 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
private void setupContent() {
emptyContentIcon.setImageResource(R.drawable.ic_activity_light_grey);
emptyContentProgressBar.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryAccentColor(this),
PorterDuff.Mode.SRC_IN);
PorterDuff.Mode.SRC_IN);
FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
adapter = new ActivityListAdapter(this, getUserAccountManager(), this, storageManager, getCapabilities(), false);
@ -174,6 +174,7 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new ActivityListItemDecoration());
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
@ -186,7 +187,7 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
// synchronize loading state when item count changes
if (!isLoadingActivities && (totalItemCount - visibleItemCount) <= (firstVisibleItemIndex + 5)
&& nextPageUrl != null && !nextPageUrl.isEmpty()) {
&& nextPageUrl != null && !nextPageUrl.isEmpty()) {
// Almost reached the end, continue to load new activities
mActionListener.loadActivities(nextPageUrl);
}

View file

@ -0,0 +1,4 @@
package com.owncloud.android.ui.activities;
public interface ActivityListElement {
}

View file

@ -0,0 +1,14 @@
package com.owncloud.android.ui.activities;
public class ActivityListHeader implements ActivityListElement {
final private String headline;
public ActivityListHeader(String headline) {
this.headline = headline;
}
public String getHeadline() {
return headline;
}
}

View file

@ -0,0 +1,34 @@
package com.owncloud.android.ui.activities;
import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ActivityListItemDecoration extends RecyclerView.ItemDecoration {
private final String TAG = this.getClass().getSimpleName();
@Override
public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.onDrawOver(c, parent, state);
View topChild = parent.getChildAt(0);
View currentHeader = topChild;
if (currentHeader != null) {
drawHeader(c, currentHeader);
Log.d(TAG,"Attach new Header" );
}
}
private void drawHeader(Canvas c, View header) {
c.save();
c.translate(0, 0);
header.draw(c);
c.restore();
}
}

View file

@ -65,6 +65,7 @@ import com.owncloud.android.lib.resources.activities.models.PreviewObject;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.activities.ActivityListHeader;
import com.owncloud.android.ui.interfaces.ActivityListInterface;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
@ -141,7 +142,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
values.add(activity);
} else {
sTime = time;
values.add(sTime);
values.add(new ActivityListHeader(sTime));
values.add(activity);
}
}
@ -173,11 +174,11 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
if (activity.getRichSubjectElement() != null &&
!TextUtils.isEmpty(activity.getRichSubjectElement().getRichSubject())) {
!TextUtils.isEmpty(activity.getRichSubjectElement().getRichSubject())) {
activityViewHolder.subject.setVisibility(View.VISIBLE);
activityViewHolder.subject.setMovementMethod(LinkMovementMethod.getInstance());
activityViewHolder.subject.setText(addClickablePart(activity.getRichSubjectElement()),
TextView.BufferType.SPANNABLE);
TextView.BufferType.SPANNABLE);
activityViewHolder.subject.setVisibility(View.VISIBLE);
} else if (!TextUtils.isEmpty(activity.getSubject())) {
activityViewHolder.subject.setVisibility(View.VISIBLE);
@ -198,7 +199,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
if (activity.getRichSubjectElement() != null &&
activity.getRichSubjectElement().getRichObjectList().size() > 0) {
activity.getRichSubjectElement().getRichObjectList().size() > 0) {
activityViewHolder.list.setVisibility(View.VISIBLE);
activityViewHolder.list.removeAllViews();
@ -237,7 +238,8 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
} else {
ActivityViewHeaderHolder activityViewHeaderHolder = (ActivityViewHeaderHolder) holder;
activityViewHeaderHolder.title.setText((String) values.get(position));
ActivityListHeader header = (ActivityListHeader) values.get(position);
activityViewHeaderHolder.title.setText((String) header.getHeadline());
}
}
@ -325,23 +327,23 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private void downloadIcon(String icon, ImageView itemViewType) {
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context)
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
.from(Uri.class)
.as(SVG.class)
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
.sourceEncoder(new StreamEncoder())
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
.decoder(new SvgDecoder())
.placeholder(R.drawable.ic_activity)
.error(R.drawable.ic_activity)
.animate(android.R.anim.fade_in)
.listener(new SvgSoftwareLayerSetter<>());
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
.from(Uri.class)
.as(SVG.class)
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
.sourceEncoder(new StreamEncoder())
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
.decoder(new SvgDecoder())
.placeholder(R.drawable.ic_activity)
.error(R.drawable.ic_activity)
.animate(android.R.anim.fade_in)
.listener(new SvgSoftwareLayerSetter<>());
Uri uri = Uri.parse(icon);
requestBuilder
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(uri)
.into(itemViewType);
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(uri)
.into(itemViewType);
}
private SpannableStringBuilder addClickablePart(RichElement richElement) {
@ -418,7 +420,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
CharSequence getHeaderDateString(Context context, long modificationTimestamp) {
if ((System.currentTimeMillis() - modificationTimestamp) < DateUtils.WEEK_IN_MILLIS) {
return DisplayUtils.getRelativeDateTimeString(context, modificationTimestamp, DateUtils.DAY_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS, 0);
DateUtils.WEEK_IN_MILLIS, 0);
} else {
String pattern = "EEEE, MMMM d";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {