Animate states changed

This commit is contained in:
Vasiliy 2019-04-27 22:27:08 +03:00
parent 273f731dd5
commit 93f2518159
No known key found for this signature in database
GPG key ID: 9F74C4D2874D7523
16 changed files with 113 additions and 22 deletions

View file

@ -1287,7 +1287,7 @@ public class VideoDetailFragment
.subscribe(state -> {
final int seconds = (int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime());
positionView.setMax((int) info.getDuration());
positionView.setProgress(seconds);
positionView.setProgressAnimated(seconds);
detailPositionView.setText(Localization.getDurationString(seconds));
animateView(positionView, true, 500);
animateView(detailPositionView, true, 500);

View file

@ -101,7 +101,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
updateFlags = 0;
}
infoListAdapter.updateStates();
itemsList.post(infoListAdapter::updateStates);
}
/*//////////////////////////////////////////////////////////////////////////

View file

@ -312,9 +312,26 @@ public class InfoListAdapter extends StateObjectsListAdapter {
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List<Object> payloads) {
if (!payloads.isEmpty() && holder instanceof InfoItemHolder) {
for (Object payload : payloads) {
if (payload instanceof StreamStateEntity) {
((InfoItemHolder) holder).updateState(infoItemList.get(header == null ? position : position - 1),
(StreamStateEntity) payload);
} else if (payload instanceof Boolean) {
((InfoItemHolder) holder).updateState(infoItemList.get(header == null ? position : position - 1),
null);
}
}
} else {
onBindViewHolder(holder, position);
}
}
@Override
protected void onItemStateChanged(int position, @Nullable StreamStateEntity state) {
notifyItemChanged(header == null ? position : position + 1, state);
notifyItemChanged(header == null ? position : position + 1, state != null ? state : false);
}
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int spanCount) {

View file

@ -38,4 +38,7 @@ public abstract class InfoItemHolder extends RecyclerView.ViewHolder {
}
public abstract void updateFromItem(final InfoItem infoItem, @Nullable final StreamStateEntity state);
public void updateState(final InfoItem infoItem, @Nullable final StreamStateEntity state) {
}
}

View file

@ -5,7 +5,6 @@ import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.schabi.newpipe.R;
@ -14,8 +13,10 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.views.AnimatedProgressBar;
import java.util.concurrent.TimeUnit;
@ -25,7 +26,7 @@ public class StreamMiniInfoItemHolder extends InfoItemHolder {
public final TextView itemVideoTitleView;
public final TextView itemUploaderView;
public final TextView itemDurationView;
public final ProgressBar itemProgressView;
public final AnimatedProgressBar itemProgressView;
StreamMiniInfoItemHolder(InfoItemBuilder infoItemBuilder, int layoutId, ViewGroup parent) {
super(infoItemBuilder, layoutId, parent);
@ -99,6 +100,22 @@ public class StreamMiniInfoItemHolder extends InfoItemHolder {
}
}
@Override
public void updateState(final InfoItem infoItem, @Nullable final StreamStateEntity state) {
final StreamInfoItem item = (StreamInfoItem) infoItem;
if (state != null && item.getDuration() > 0 && item.getStreamType() != StreamType.LIVE_STREAM) {
itemProgressView.setMax((int) item.getDuration());
if (itemProgressView.getVisibility() == View.VISIBLE) {
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
} else {
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
AnimationUtils.animateView(itemProgressView, true, 500);
}
} else if (itemProgressView.getVisibility() == View.VISIBLE) {
AnimationUtils.animateView(itemProgressView, false, 500);
}
}
private void enableLongClick(final StreamInfoItem item) {
itemView.setLongClickable(true);
itemView.setOnLongClickListener(view -> {

View file

@ -76,7 +76,8 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
}
updateFlags = 0;
}
itemListAdapter.updateStates();
itemsList.post(itemListAdapter::updateStates);
}
/*//////////////////////////////////////////////////////////////////////////

View file

@ -285,9 +285,26 @@ public class LocalItemListAdapter extends StateObjectsListAdapter {
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List<Object> payloads) {
if (!payloads.isEmpty() && holder instanceof LocalItemHolder) {
for (Object payload : payloads) {
if (payload instanceof StreamStateEntity) {
((LocalItemHolder) holder).updateState(localItems.get(header == null ? position : position - 1),
(StreamStateEntity) payload);
} else if (payload instanceof Boolean) {
((LocalItemHolder) holder).updateState(localItems.get(header == null ? position : position - 1),
null);
}
}
} else {
onBindViewHolder(holder, position);
}
}
@Override
protected void onItemStateChanged(int position, @Nullable StreamStateEntity state) {
notifyItemChanged(header == null ? position : position + 1, state);
notifyItemChanged(header == null ? position : position + 1, state != null ? state : false);
}
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int spanCount) {

View file

@ -41,4 +41,7 @@ public abstract class LocalItemHolder extends RecyclerView.ViewHolder {
}
public abstract void updateFromItem(final LocalItem item, @Nullable final StreamStateEntity state, final DateFormat dateFormat);
public void updateState(final LocalItem localItem, @Nullable final StreamStateEntity state) {
}
}

View file

@ -6,7 +6,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.schabi.newpipe.R;
@ -15,8 +14,10 @@ import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.local.LocalItemBuilder;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.views.AnimatedProgressBar;
import java.text.DateFormat;
import java.util.concurrent.TimeUnit;
@ -28,7 +29,7 @@ public class LocalPlaylistStreamItemHolder extends LocalItemHolder {
public final TextView itemAdditionalDetailsView;
public final TextView itemDurationView;
public final View itemHandleView;
public final ProgressBar itemProgressView;
public final AnimatedProgressBar itemProgressView;
LocalPlaylistStreamItemHolder(LocalItemBuilder infoItemBuilder, int layoutId, ViewGroup parent) {
super(infoItemBuilder, layoutId, parent);
@ -92,6 +93,23 @@ public class LocalPlaylistStreamItemHolder extends LocalItemHolder {
itemHandleView.setOnTouchListener(getOnTouchListener(item));
}
@Override
public void updateState(LocalItem localItem, @Nullable StreamStateEntity state) {
if (!(localItem instanceof PlaylistStreamEntry)) return;
final PlaylistStreamEntry item = (PlaylistStreamEntry) localItem;
if (state != null && item.duration > 0) {
itemProgressView.setMax((int) item.duration);
if (itemProgressView.getVisibility() == View.VISIBLE) {
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
} else {
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
AnimationUtils.animateView(itemProgressView, true, 500);
}
} else if (itemProgressView.getVisibility() == View.VISIBLE) {
AnimationUtils.animateView(itemProgressView, false, 500);
}
}
private View.OnTouchListener getOnTouchListener(final PlaylistStreamEntry item) {
return (view, motionEvent) -> {
view.performClick();

View file

@ -5,7 +5,6 @@ import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.schabi.newpipe.R;
@ -14,8 +13,10 @@ import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.local.LocalItemBuilder;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.views.AnimatedProgressBar;
import java.text.DateFormat;
import java.util.concurrent.TimeUnit;
@ -48,7 +49,7 @@ public class LocalStatisticStreamItemHolder extends LocalItemHolder {
public final TextView itemDurationView;
@Nullable
public final TextView itemAdditionalDetails;
public final ProgressBar itemProgressView;
public final AnimatedProgressBar itemProgressView;
public LocalStatisticStreamItemHolder(LocalItemBuilder itemBuilder, ViewGroup parent) {
this(itemBuilder, R.layout.list_stream_item, parent);
@ -121,4 +122,21 @@ public class LocalStatisticStreamItemHolder extends LocalItemHolder {
return true;
});
}
@Override
public void updateState(LocalItem localItem, @Nullable StreamStateEntity state) {
if (!(localItem instanceof StreamStatisticsEntry)) return;
final StreamStatisticsEntry item = (StreamStatisticsEntry) localItem;
if (state != null && item.duration > 0) {
itemProgressView.setMax((int) item.duration);
if (itemProgressView.getVisibility() == View.VISIBLE) {
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
} else {
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS.toSeconds(state.getProgressTime()));
AnimationUtils.animateView(itemProgressView, true, 500);
}
} else if (itemProgressView.getVisibility() == View.VISIBLE) {
AnimationUtils.animateView(itemProgressView, false, 500);
}
}
}

View file

@ -153,6 +153,8 @@ public class SubscriptionFragment extends BaseStateFragment<List<SubscriptionEnt
}
updateFlags = 0;
}
itemsList.post(infoListAdapter::updateStates);
}
@Override

View file

@ -25,8 +25,7 @@ public final class AnimatedProgressBar extends ProgressBar {
super(context, attrs, defStyleAttr);
}
@Override
public synchronized void setProgress(int progress) {
public synchronized void setProgressAnimated(int progress) {
cancelAnimation();
animation = new ProgressBarAnimation(this, getProgress(), progress);
startAnimation(animation);
@ -40,10 +39,6 @@ public final class AnimatedProgressBar extends ProgressBar {
clearAnimation();
}
private void setProgressInternal(int progress) {
super.setProgress(progress);
}
private static class ProgressBarAnimation extends Animation {
private final AnimatedProgressBar progressBar;
@ -63,7 +58,7 @@ public final class AnimatedProgressBar extends ProgressBar {
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
float value = from + (to - from) * interpolatedTime;
progressBar.setProgressInternal((int) value);
progressBar.setProgress((int) value);
}
}
}

View file

@ -67,7 +67,7 @@
android:textSize="@dimen/video_item_search_uploader_text_size"
tools:text="Uploader"/>
<ProgressBar
<org.schabi.newpipe.views.AnimatedProgressBar
android:id="@+id/itemProgressView"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="?progress_horizontal_drawable"

View file

@ -80,7 +80,7 @@
android:textSize="@dimen/video_item_search_upload_date_text_size"
tools:text="2 years ago • 10M views"/>
<ProgressBar
<org.schabi.newpipe.views.AnimatedProgressBar
android:id="@+id/itemProgressView"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="?progress_horizontal_drawable"

View file

@ -70,7 +70,7 @@
android:textSize="@dimen/video_item_search_uploader_text_size"
tools:text="Uploader" />
<ProgressBar
<org.schabi.newpipe.views.AnimatedProgressBar
android:id="@+id/itemProgressView"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="?progress_horizontal_drawable"

View file

@ -83,7 +83,7 @@
android:textSize="@dimen/video_item_search_uploader_text_size"
tools:text="Uploader" />
<ProgressBar
<org.schabi.newpipe.views.AnimatedProgressBar
android:id="@+id/itemProgressView"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="?progress_horizontal_drawable"