Skip to content

Commit 973f3b2

Browse files
docs: Documented the rest of the classes
1 parent 3fa67f0 commit 973f3b2

File tree

10 files changed

+125
-26
lines changed

10 files changed

+125
-26
lines changed

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/DefaultSkeletonFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import androidx.annotation.LayoutRes;
77
import androidx.recyclerview.widget.RecyclerView;
88

9+
/**
10+
* A static facade for {@link SkeletonFactory#getDefault()}.
11+
* Any static call {@code DefaultSkeletonFactory.XYZ()} is equivalent to calling {@code SkeletonFactory.getDefault().XYZ()}.
12+
* Mostly used for convenience.
13+
* @author Enginecrafter77
14+
*/
915
public class DefaultSkeletonFactory {
1016
public static DetachableSkeleton createSkeleton(View view)
1117
{

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/DetachableSkeleton.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
*/
1717
package dev.enginecrafter77.skeletonlayoutng;
1818

19+
/**
20+
* DetachableSkeleton is a simple extension to {@link Skeleton} allowing it to be completely
21+
* uninstalled from the associated element.
22+
* @author Enginecrafter77
23+
*/
1924
public interface DetachableSkeleton extends Skeleton {
25+
/**
26+
* <p>Detaches the skeleton from the associated element.</p>
27+
*
28+
* <p>
29+
* Upon call to this method, {@link #showSkeleton()} and {@link #hideSkeleton()} methods
30+
* should become NO-OP, and the result of {@link #isActive()} becomes undefined.
31+
* </p>
32+
*
33+
* <p>This method is idempotent. Subsequent calls to this method should be NO-OP.</p>
34+
*/
2035
public void detachSkeleton();
2136
}

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/RecyclerViewSkeleton.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
import androidx.annotation.Nullable;
2323
import androidx.recyclerview.widget.RecyclerView;
2424

25+
/**
26+
* <p>
27+
* RecyclerViewSkeleton is a {@link Skeleton} implementation forattaching {@link SkeletonAdapter} to a recyclerview
28+
* in accordance with the Skeleton behavior.
29+
* </p>
30+
*
31+
* <p>
32+
* RecyclerViewSkeleton makes sure that when activating the skeleton, no state is lost. The original adapter is
33+
* still remembered, and upon hiding the skeleton the suppressed adapter is restored.
34+
* </p>
35+
* @author Enginecrafter77
36+
*/
2537
public class RecyclerViewSkeleton implements Skeleton {
2638
private final RecyclerView view;
2739
private final SkeletonAdapter skeletonAdapter;

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonAdapter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
import java.util.ArrayList;
3030
import java.util.List;
3131

32+
/**
33+
* SkeletonAdapter is a {@link RecyclerView.Adapter} implementation that displays skeleton children in the RecyclerView.
34+
* @author Enginecrafter77
35+
*/
3236
public class SkeletonAdapter extends RecyclerView.Adapter<SkeletonAdapter.SkeletonItem> {
3337
private final SkeletonFactory skeletonFactory;
3438

@@ -40,6 +44,12 @@ public class SkeletonAdapter extends RecyclerView.Adapter<SkeletonAdapter.Skelet
4044

4145
private int itemCount;
4246

47+
/**
48+
* Create a SkeletonAdapter using the given parameters.
49+
* @param itemLayout The layout resource for children
50+
* @param itemSkeletons The item IDs in the child layout that should be made into skeletons
51+
* @param skeletonFactory The skeleton factory used to make the child skeletons
52+
*/
4353
public SkeletonAdapter(@LayoutRes int itemLayout, @IdRes int[] itemSkeletons, SkeletonFactory skeletonFactory)
4454
{
4555
this.skeletonFactory = skeletonFactory;

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonDrawable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
import androidx.annotation.NonNull;
3535
import androidx.annotation.Nullable;
3636

37+
/**
38+
* <p>SkeletonDrawable is the main means of displaying skeletons.</p>
39+
*
40+
* <p>
41+
* SkeletonDrawable takes the form of a simple strip with a running shimmer animation covering the whole element bounds.
42+
* </p>
43+
*
44+
* <p>
45+
* SkeletonDrawable can be configured by using {@link #setStyle(SkeletonStyle)}.
46+
* </p>
47+
* @author Enginecrafter77
48+
*/
3749
public class SkeletonDrawable extends Drawable implements Skeleton {
3850
private final Matrix shimmerBoundMatrix;
3951
private final Matrix shimmerOutMatrix;

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
import java.util.stream.Collectors;
2828
import java.util.stream.Stream;
2929

30+
/**
31+
* <p>SkeletonFactory is a class that creates skeletons for various elements (maily Views).</p>
32+
*
33+
* <p>
34+
* The main goal of an abstract SkeletonFactory is that it can be supplied with user-specified {@link SkeletonStyle},
35+
* which is subsequently passed down onto the children (as is case in {@link SkeletonAdapter} for example).
36+
* </p>
37+
* @author Enginecrafter77
38+
*/
3039
public class SkeletonFactory {
3140
@Nullable
3241
private final SkeletonStyle style;

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonGroup.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,33 @@
1818

1919
import com.google.common.collect.ImmutableSet;
2020

21+
/**
22+
* <p>
23+
* SkeletonGroup is a {@link Skeleton} implementation that is used to
24+
* synchronize the Skeleton behavior of one or more other skeleton instances.
25+
* </p>
26+
*
27+
* <p>
28+
* As is case with other Skeleton implementations, upon group formation the
29+
* state of its constituents is undefined, and therefore the state of the
30+
* whole group is undefined as well. The value returned by {@link #isActive()}
31+
* should not be relied upon. Only after a call to {@link #showSkeleton()}
32+
* or {@link #hideSkeleton()} can the state be considered defined, and {@link #isActive()}
33+
* will return the expected result.
34+
* </p>
35+
* @author Enginecrafter77
36+
*/
2137
public class SkeletonGroup implements Skeleton {
2238
private final ImmutableSet<Skeleton> skeletons;
2339

2440
private boolean active;
2541

26-
protected SkeletonGroup(ImmutableSet<Skeleton> skeletons)
42+
public SkeletonGroup(ImmutableSet<Skeleton> skeletons)
2743
{
2844
this.skeletons = skeletons;
2945
this.active = false;
3046
}
3147

32-
protected void sync()
33-
{
34-
int numActive = 0;
35-
int numInactive = 0;
36-
37-
for(Skeleton member : this.skeletons)
38-
{
39-
if(member.isActive())
40-
++numActive;
41-
else
42-
++numInactive;
43-
}
44-
45-
boolean active = numActive >= numInactive;
46-
if(active)
47-
this.showSkeleton();
48-
else
49-
this.hideSkeleton();
50-
}
51-
5248
@Override
5349
public boolean isActive()
5450
{
@@ -73,9 +69,7 @@ public void hideSkeleton()
7369

7470
public static SkeletonGroup create(Iterable<Skeleton> skeletons)
7571
{
76-
SkeletonGroup group = new SkeletonGroup(ImmutableSet.copyOf(skeletons));
77-
group.sync();
78-
return group;
72+
return new SkeletonGroup(ImmutableSet.copyOf(skeletons));
7973
}
8074

8175
public static SkeletonGroup create(Skeleton... skeletons)

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonLayout.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
import androidx.annotation.NonNull;
2525
import androidx.annotation.Nullable;
2626

27+
/**
28+
* <p>SkeletonLayout is a simple {@link FrameLayout} with an implicitly constructed {@link Skeleton}.</p>
29+
*
30+
* <p>
31+
* SkeletonLayout can be used as an XML-explicit declaration of skeleton covering a view. This instance
32+
* can then directly be used to control the skeleton covering the view.
33+
* </p>
34+
*
35+
* <p>
36+
* Upon construction, the skeleton state is undefined. Therefore, it is advised to call either
37+
* {@link #showSkeleton()} or {@link #hideSkeleton()} before the view gets displayed.
38+
* </p>
39+
* @author Enginecrafter77
40+
*/
2741
public class SkeletonLayout extends FrameLayout implements Skeleton {
2842
private final SkeletonDrawable skeletonDrawable;
2943

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonOverlay.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@ public class SkeletonOverlay extends SkeletonDrawable implements DetachableSkele
2525

2626
private final View view;
2727

28+
private boolean installed;
29+
2830
public SkeletonOverlay(View view)
2931
{
3032
super();
3133
this.view = view;
3234
this.onLayoutChangeListener = this::onViewLayoutChange;
35+
this.installed = false;
3336
}
3437

35-
protected void install()
38+
protected synchronized void install()
3639
{
40+
if(this.installed)
41+
return;
42+
3743
this.view.getOverlay().add(this);
3844
this.view.addOnLayoutChangeListener(this.onLayoutChangeListener);
45+
this.installed = true;
3946
}
4047

4148
@UiThread
@@ -45,9 +52,13 @@ protected void onViewLayoutChange(View view, int left, int top, int right, int b
4552
}
4653

4754
@Override
48-
public void detachSkeleton()
55+
public synchronized void detachSkeleton()
4956
{
57+
if(!this.installed)
58+
return;
59+
5060
this.view.getOverlay().remove(this);
5161
this.view.removeOnLayoutChangeListener(this.onLayoutChangeListener);
62+
this.installed = false;
5263
}
5364
}

skeletonlayoutng/src/main/java/dev/enginecrafter77/skeletonlayoutng/SkeletonStyle.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,35 @@
2525

2626
import java.util.Objects;
2727

28+
/**
29+
* SkeletonStyle is an immutable object that controls the appearance of {@link SkeletonDrawable}.
30+
* @author Enginecrafter77
31+
*/
2832
public class SkeletonStyle {
2933
public static final SkeletonStyle DEFAULT = new SkeletonStyle(0xFFE0E0E0, 0xFFD5D5D5, 5F, 8F, 1500);
3034

35+
/** The color the strip will be filled with */
3136
@ColorInt
3237
public final int fillColor;
3338

39+
/** The color of the running shimmer. Should normally be only slightly different from {@link #fillColor} */
3440
@ColorInt
3541
public final int shimmerColor;
3642

43+
/**
44+
* The angle (in degrees) the shimmer should be tilted in counter-clockwise direction.
45+
* Angle o 0deg describes perfect left-to-right shimmer, 90deg makes it go from bottom to top.
46+
* It is not advised to use angles in excess of 45deg as that can produce undesirable visual effects.
47+
*/
3748
public final float shimmerAngle;
3849

50+
/** The radius of skeleton strip borders in partial pixels. */
3951
public final float borderRadius;
4052

53+
/**
54+
* The duration of 1 iteration of the shimmer animation.
55+
* The shimmer animation will spend 2/7 of that time running, and the rest dwelling.
56+
*/
4157
public final int shimmerPeriodMs;
4258

4359
public SkeletonStyle(int fillColor, int shimmerColor, float shimmerAngle, float borderRadius, int shimmerPeriodMs)

0 commit comments

Comments
 (0)