Merge pull request #3817 from ByteHamster/viewpager
Added Viewpager indicator that shows if chapters are present
This commit is contained in:
commit
6a327f252c
|
@ -161,7 +161,6 @@ dependencies {
|
|||
implementation "com.joanzapata.iconify:android-iconify-fontawesome:$iconifyVersion"
|
||||
implementation "com.joanzapata.iconify:android-iconify-material:$iconifyVersion"
|
||||
implementation "com.yqritc:recyclerview-flexibledivider:$recyclerviewFlexibledividerVersion"
|
||||
implementation "com.githang:viewpagerindicator:2.5.1@aar"
|
||||
implementation "com.github.shts:TriangleLabelView:$triangleLabelViewVersion"
|
||||
implementation 'com.leinardi.android:speed-dial:3.0.0'
|
||||
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"
|
||||
|
|
|
@ -28,8 +28,6 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.viewpagerindicator.CirclePageIndicator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
|
@ -38,6 +36,7 @@ import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
|||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||
import de.danoeh.antennapod.core.event.MessageEvent;
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
|
@ -59,6 +58,7 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
|||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||
import de.danoeh.antennapod.view.PagerIndicatorView;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
@ -102,6 +102,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
|||
private int mPosition = -1;
|
||||
|
||||
private ViewPager pager;
|
||||
private PagerIndicatorView pageIndicator;
|
||||
private MediaplayerInfoPagerAdapter pagerAdapter;
|
||||
|
||||
private Disposable disposable;
|
||||
|
@ -261,14 +262,26 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
|||
pager.setOffscreenPageLimit(3);
|
||||
pagerAdapter = new MediaplayerInfoPagerAdapter(getSupportFragmentManager());
|
||||
pager.setAdapter(pagerAdapter);
|
||||
CirclePageIndicator pageIndicator = findViewById(R.id.page_indicator);
|
||||
pageIndicator = findViewById(R.id.page_indicator);
|
||||
pageIndicator.setViewPager(pager);
|
||||
pageIndicator.setOnClickListener(v
|
||||
-> pager.setCurrentItem((pager.getCurrentItem() + 1) % pager.getChildCount()));
|
||||
loadLastFragment();
|
||||
pager.onSaveInstanceState();
|
||||
|
||||
navList.post(this::supportStartPostponedEnterTransition);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean loadMediaInfo() {
|
||||
if (controller != null) {
|
||||
List<Chapter> chapters = controller.getMedia().getChapters();
|
||||
boolean hasChapters = chapters != null && !chapters.isEmpty();
|
||||
pageIndicator.setDisabledPage(hasChapters ? -1 : 2);
|
||||
}
|
||||
return super.loadMediaInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReloadNotification(int notificationCode) {
|
||||
if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) {
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package de.danoeh.antennapod.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.vectordrawable.graphics.drawable.ArgbEvaluator;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
public class PagerIndicatorView extends View {
|
||||
private final Paint paint = new Paint();
|
||||
private float position = 0;
|
||||
private int numPages = 0;
|
||||
private int disabledPage = -1;
|
||||
private int circleColor = 0;
|
||||
private int circleColorHighlight = -1;
|
||||
|
||||
public PagerIndicatorView(Context context) {
|
||||
super(context);
|
||||
setup();
|
||||
}
|
||||
|
||||
public PagerIndicatorView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setup();
|
||||
}
|
||||
|
||||
public PagerIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
|
||||
int[] colorAttrs = new int[] { android.R.attr.textColorSecondary };
|
||||
TypedArray a = getContext().obtainStyledAttributes(colorAttrs);
|
||||
circleColorHighlight = a.getColor(0, 0xffffffff);
|
||||
circleColor = (Integer) new ArgbEvaluator().evaluate(0.8f, 0x00ffffff, circleColorHighlight);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setViewPager(ViewPager pager) {
|
||||
numPages = pager.getAdapter().getCount();
|
||||
pager.getAdapter().registerDataSetObserver(new DataSetObserver() {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
numPages = pager.getAdapter().getCount();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
PagerIndicatorView.this.position = position + positionOffset;
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setDisabledPage(int disabledPage) {
|
||||
this.disabledPage = disabledPage;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
for (int i = 0; i < numPages; i++) {
|
||||
if ((int) Math.floor(position) == i) {
|
||||
// This is the current dot
|
||||
drawCircle(canvas, i, (float) (1 - (position - Math.floor(position))));
|
||||
} else if ((int) Math.ceil(position) == i) {
|
||||
// This is the next dot
|
||||
drawCircle(canvas, i, (float) (position - Math.floor(position)));
|
||||
} else {
|
||||
drawCircle(canvas, i, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCircle(Canvas canvas, int position, float frac) {
|
||||
float circleRadiusSmall = canvas.getHeight() * 0.26f;
|
||||
float circleRadiusBig = canvas.getHeight() * 0.35f;
|
||||
float circleRadiusDelta = (circleRadiusBig - circleRadiusSmall);
|
||||
float start = 0.5f * (canvas.getWidth() - numPages * 1.5f * canvas.getHeight());
|
||||
paint.setStrokeWidth(canvas.getHeight() * 0.3f);
|
||||
|
||||
if (position == disabledPage) {
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
} else {
|
||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
}
|
||||
|
||||
paint.setColor((Integer) new ArgbEvaluator().evaluate(frac, circleColor, circleColorHighlight));
|
||||
canvas.drawCircle(start + (position * 1.5f + 0.75f) * canvas.getHeight(), 0.5f * canvas.getHeight(),
|
||||
circleRadiusSmall + frac * circleRadiusDelta, paint);
|
||||
}
|
||||
}
|
|
@ -26,16 +26,14 @@
|
|||
android:minHeight="?attr/actionBarSize"
|
||||
tools:background="@android:color/darker_gray"/>
|
||||
|
||||
<com.viewpagerindicator.CirclePageIndicator
|
||||
<de.danoeh.antennapod.view.PagerIndicatorView
|
||||
android:id="@+id/page_indicator"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_marginTop="-12dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:fillColor="?android:attr/textColorSecondary"
|
||||
app:strokeColor="?android:attr/textColorSecondary"
|
||||
app:radius="4dp" />
|
||||
android:paddingBottom="4dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue