Skip to content

Commit 30c7296

Browse files
authored
Remove shopgun and RtlViewPager dependencies (#291)
1 parent 3cc8b5e commit 30c7296

File tree

5 files changed

+557
-15
lines changed

5 files changed

+557
-15
lines changed

readium/navigator/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ dependencies {
8585
implementation(libs.androidx.webkit)
8686
// Needed to avoid a crash with API 31, see https://stackoverflow.com/a/69152986/1474476
8787
implementation("androidx.work:work-runtime-ktx:2.7.1")
88-
implementation("com.duolingo.open:rtl-viewpager:1.0.3")
8988
// ChrisBane/PhotoView ( for the Zoom handling )
9089
implementation(libs.photoview)
9190

@@ -94,7 +93,6 @@ dependencies {
9493
api(libs.bundles.exoplayer)
9594
implementation(libs.google.material)
9695
implementation(libs.timber)
97-
implementation("com.shopgun.android:utils:1.0.9")
9896
implementation(libs.joda.time)
9997
implementation(libs.bundles.coroutines)
10098
implementation(libs.kotlinx.serialization.json)

readium/navigator/src/main/java/org/readium/r2/navigator/epub/fxl/R2FXLLayout.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import android.view.animation.DecelerateInterpolator
2121
import android.view.animation.Interpolator
2222
import android.widget.FrameLayout
2323
import androidx.core.view.ViewCompat
24-
import com.shopgun.android.utils.NumberUtils
2524
import java.util.*
25+
import kotlin.math.abs
2626
import kotlin.math.min
2727
import kotlin.math.roundToInt
2828
import kotlin.math.roundToLong
@@ -94,12 +94,15 @@ class R2FXLLayout : FrameLayout {
9494
private var mOnDoubleTapListeners: MutableList<OnDoubleTapListener>? = null
9595
private var onLongTapListeners: MutableList<OnLongTapListener>? = null
9696

97+
private fun Float.equalsDelta(other: Float, delta: Float = 0.001f) =
98+
this == other || abs(this - other) < delta
99+
97100
var scale: Float
98101
get() = getMatrixValue(scaleMatrix, Matrix.MSCALE_X)
99102
set(scale) = setScale(scale, true)
100103

101104
val isScaled: Boolean
102-
get() = !NumberUtils.isEqual(scale, 1.0f, 0.05f)
105+
get() = !scale.equalsDelta(1.0f, 0.05f)
103106

104107
private val translateDeltaBounds: RectF
105108
get() {
@@ -317,8 +320,8 @@ class R2FXLLayout : FrameLayout {
317320

318321
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
319322
val scale = scale
320-
val newScale = NumberUtils.clamp(minScale, scale, maxScale)
321-
if (NumberUtils.isEqual(newScale, scale)) {
323+
val newScale = scale.coerceIn(minScale, maxScale)
324+
if (newScale.equalsDelta(scale)) {
322325
// only fling if no scale is needed - scale will happen on ACTION_UP
323326
flingRunnable = FlingRunnable(context)
324327
flingRunnable!!.fling(velocityX.toInt(), velocityY.toInt())
@@ -424,7 +427,7 @@ class R2FXLLayout : FrameLayout {
424427
}
425428
fixFocusPoint(focusX, focusY)
426429
if (!isAllowOverScale) {
427-
newScale = NumberUtils.clamp(minScale, newScale, maxScale)
430+
newScale = newScale.coerceIn(minScale, maxScale)
428431
}
429432
if (animate) {
430433
animatedZoomRunnable = AnimatedZoomRunnable()
@@ -443,12 +446,12 @@ class R2FXLLayout : FrameLayout {
443446
var tdy = dy
444447
if (clamp) {
445448
val bounds = translateDeltaBounds
446-
tdx = NumberUtils.clamp(bounds.left, dx, bounds.right)
447-
tdy = NumberUtils.clamp(bounds.top, dy, bounds.bottom)
449+
tdx = dx.coerceIn(bounds.left, bounds.right)
450+
tdy = dy.coerceIn(bounds.top, bounds.bottom)
448451
}
449452
val destPosX = tdx + posX
450453
val destPosY = tdy + posY
451-
if (!NumberUtils.isEqual(destPosX, posX) || !NumberUtils.isEqual(destPosY, posY)) {
454+
if (!destPosX.equalsDelta(posX) || !destPosY.equalsDelta(posY)) {
452455
translateMatrix.setTranslate(-destPosX, -destPosY)
453456
matrixUpdated()
454457
invalidate()
@@ -519,16 +522,16 @@ class R2FXLLayout : FrameLayout {
519522
private var mTargetY: Float = 0.toFloat()
520523

521524
internal fun doScale(): Boolean {
522-
return !NumberUtils.isEqual(mZoomStart, mZoomEnd)
525+
return !mZoomStart.equalsDelta(mZoomEnd)
523526
}
524527

525528
internal fun doTranslate(): Boolean {
526-
return !NumberUtils.isEqual(mStartX, mTargetX) || !NumberUtils.isEqual(mStartY, mTargetY)
529+
return !mStartX.equalsDelta(mTargetX) || !mStartY.equalsDelta(mTargetY)
527530
}
528531

529532
internal fun runValidation(): Boolean {
530533
val scale = scale
531-
val newScale = NumberUtils.clamp(minScale, scale, maxScale)
534+
val newScale = scale.coerceIn(minScale, maxScale)
532535
scale(scale, newScale, focusX, focusY, true)
533536
if (animatedZoomRunnable!!.doScale() || animatedZoomRunnable!!.doTranslate()) {
534537
ViewCompat.postOnAnimation(this@R2FXLLayout, animatedZoomRunnable!!)
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package org.readium.r2.navigator.pager;
2+
3+
/*
4+
* Copyright 2016–2020 Duolingo
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import android.database.DataSetObserver;
20+
import android.os.Parcelable;
21+
import android.view.View;
22+
import android.view.ViewGroup;
23+
24+
import androidx.annotation.NonNull;
25+
import androidx.viewpager.widget.PagerAdapter;
26+
27+
public class DelegatingPagerAdapter extends PagerAdapter {
28+
29+
private final PagerAdapter mDelegate;
30+
31+
DelegatingPagerAdapter(@NonNull final PagerAdapter delegate) {
32+
this.mDelegate = delegate;
33+
delegate.registerDataSetObserver(new MyDataSetObserver(this));
34+
}
35+
36+
PagerAdapter getDelegate() {
37+
return mDelegate;
38+
}
39+
40+
@Override
41+
public int getCount() {
42+
return mDelegate.getCount();
43+
}
44+
45+
@Override
46+
public void startUpdate(@NonNull ViewGroup container) {
47+
mDelegate.startUpdate(container);
48+
}
49+
50+
@Override
51+
public @NonNull
52+
Object instantiateItem(@NonNull ViewGroup container, int position) {
53+
return mDelegate.instantiateItem(container, position);
54+
}
55+
56+
@Override
57+
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
58+
mDelegate.destroyItem(container, position, object);
59+
}
60+
61+
@Override
62+
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
63+
mDelegate.setPrimaryItem(container, position, object);
64+
}
65+
66+
@Override
67+
public void finishUpdate(@NonNull ViewGroup container) {
68+
mDelegate.finishUpdate(container);
69+
}
70+
71+
@Deprecated
72+
@Override
73+
public void startUpdate(@NonNull View container) {
74+
mDelegate.startUpdate(container);
75+
}
76+
77+
@Deprecated
78+
@Override
79+
public @NonNull
80+
Object instantiateItem(@NonNull View container, int position) {
81+
return mDelegate.instantiateItem(container, position);
82+
}
83+
84+
@Deprecated
85+
@Override
86+
public void destroyItem(@NonNull View container, int position, @NonNull Object object) {
87+
mDelegate.destroyItem(container, position, object);
88+
}
89+
90+
@Deprecated
91+
@Override
92+
public void setPrimaryItem(@NonNull View container, int position, @NonNull Object object) {
93+
mDelegate.setPrimaryItem(container, position, object);
94+
}
95+
96+
@Deprecated
97+
@Override
98+
public void finishUpdate(@NonNull View container) {
99+
mDelegate.finishUpdate(container);
100+
}
101+
102+
@Override
103+
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
104+
return mDelegate.isViewFromObject(view, object);
105+
}
106+
107+
@Override
108+
public Parcelable saveState() {
109+
return mDelegate.saveState();
110+
}
111+
112+
@Override
113+
public void restoreState(Parcelable state, ClassLoader loader) {
114+
mDelegate.restoreState(state, loader);
115+
}
116+
117+
@Override
118+
public int getItemPosition(@NonNull Object object) {
119+
return mDelegate.getItemPosition(object);
120+
}
121+
122+
@Override
123+
public void notifyDataSetChanged() {
124+
mDelegate.notifyDataSetChanged();
125+
}
126+
127+
@Override
128+
public void registerDataSetObserver(@NonNull DataSetObserver observer) {
129+
mDelegate.registerDataSetObserver(observer);
130+
}
131+
132+
@Override
133+
public void unregisterDataSetObserver(@NonNull DataSetObserver observer) {
134+
mDelegate.unregisterDataSetObserver(observer);
135+
}
136+
137+
@Override
138+
public CharSequence getPageTitle(int position) {
139+
return mDelegate.getPageTitle(position);
140+
}
141+
142+
@Override
143+
public float getPageWidth(int position) {
144+
return mDelegate.getPageWidth(position);
145+
}
146+
147+
private void superNotifyDataSetChanged() {
148+
super.notifyDataSetChanged();
149+
}
150+
151+
private static class MyDataSetObserver extends DataSetObserver {
152+
153+
final DelegatingPagerAdapter mParent;
154+
155+
private MyDataSetObserver(DelegatingPagerAdapter mParent) {
156+
this.mParent = mParent;
157+
}
158+
159+
@Override
160+
public void onChanged() {
161+
if (mParent != null) {
162+
mParent.superNotifyDataSetChanged();
163+
}
164+
}
165+
166+
@Override
167+
public void onInvalidated() {
168+
onChanged();
169+
}
170+
171+
}
172+
173+
}

readium/navigator/src/main/java/org/readium/r2/navigator/pager/R2RTLViewPager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import androidx.viewpager.widget.PagerAdapter;
3131
import androidx.viewpager.widget.ViewPager;
3232

33-
import com.duolingo.open.rtlviewpager.DelegatingPagerAdapter;
34-
3533
import org.readium.r2.shared.publication.ReadingProgression;
3634

3735
import java.util.HashMap;

0 commit comments

Comments
 (0)