1
0
Fork 0
mirror of https://github.com/KokaKiwi/BarInsta synced 2026-03-05 03:51:36 +00:00
This commit is contained in:
Austin Huang 2020-07-01 13:08:28 -04:00
commit 13beabf741
No known key found for this signature in database
GPG key ID: 84C23AA04587A91F
275 changed files with 22638 additions and 0 deletions

View file

@ -0,0 +1,40 @@
package thoughtbot.expandableadapter;
import java.util.ArrayList;
import java.util.List;
import awais.instagrabber.models.FollowModel;
public class ExpandableGroup {
private final String title;
private final List<FollowModel> items;
public ExpandableGroup(final String title, final List<FollowModel> items) {
this.title = title;
this.items = items;
}
public String getTitle() {
return title;
}
public List<FollowModel> getItems(final boolean filtered) {
if (!filtered) return items;
final ArrayList<FollowModel> followModels = new ArrayList<>();
for (final FollowModel followModel : items) if (followModel.isShown()) followModels.add(followModel);
return followModels;
}
public int getItemCount(final boolean filtered) {
if (items != null) {
final int size = items.size();
if (filtered) {
int finalSize = 0;
for (int i = 0; i < size; ++i) if (items.get(i).isShown()) ++finalSize;
return finalSize;
}
return size;
}
return 0;
}
}

View file

@ -0,0 +1,51 @@
package thoughtbot.expandableadapter;
import androidx.annotation.NonNull;
import java.util.ArrayList;
public final class ExpandableList {
private final int groupsSize;
public final ArrayList<ExpandableGroup> groups;
public final boolean[] expandedGroupIndexes;
public ExpandableList(@NonNull final ArrayList<ExpandableGroup> groups) {
this.groups = groups;
this.groupsSize = groups.size();
this.expandedGroupIndexes = new boolean[groupsSize];
}
public int getVisibleItemCount() {
int count = 0;
for (int i = 0; i < groupsSize; i++) count = count + numberOfVisibleItemsInGroup(i);
return count;
}
@NonNull
public ExpandableListPosition getUnflattenedPosition(final int flPos) {
int adapted = flPos;
for (int i = 0; i < groupsSize; i++) {
final int groupItemCount = numberOfVisibleItemsInGroup(i);
if (adapted == 0)
return ExpandableListPosition.obtain(ExpandableListPosition.GROUP, i, -1, flPos);
else if (adapted < groupItemCount)
return ExpandableListPosition.obtain(ExpandableListPosition.CHILD, i, adapted - 1, flPos);
adapted = adapted - groupItemCount;
}
throw new RuntimeException("Unknown state");
}
private int numberOfVisibleItemsInGroup(final int group) {
return expandedGroupIndexes[group] ? groups.get(group).getItemCount(true) + 1 : 1;
}
public int getFlattenedGroupIndex(@NonNull final ExpandableListPosition listPosition) {
int runningTotal = 0;
for (int i = 0; i < listPosition.groupPos; i++) runningTotal = runningTotal + numberOfVisibleItemsInGroup(i);
return runningTotal;
}
public ExpandableGroup getExpandableGroup(@NonNull ExpandableListPosition listPosition) {
return groups.get(listPosition.groupPos);
}
}

View file

@ -0,0 +1,41 @@
package thoughtbot.expandableadapter;
import androidx.annotation.NonNull;
public class ExpandableListPosition {
private static final ExpandableListPosition LIST_POSITION = new ExpandableListPosition();
public final static int CHILD = 1;
public final static int GROUP = 2;
private int flatListPos;
public int groupPos;
public int childPos;
public int type;
@NonNull
public static ExpandableListPosition obtain(final int type, final int groupPos, final int childPos, final int flatListPos) {
LIST_POSITION.type = type;
LIST_POSITION.groupPos = groupPos;
LIST_POSITION.childPos = childPos;
LIST_POSITION.flatListPos = flatListPos;
return LIST_POSITION;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
//if (o != null && getClass() == o.getClass()) {
if (o instanceof ExpandableListPosition) {
final ExpandableListPosition that = (ExpandableListPosition) o;
if (groupPos != that.groupPos) return false;
if (childPos != that.childPos) return false;
if (flatListPos != that.flatListPos) return false;
return type == that.type;
}
return false;
}
@Override
public int hashCode() {
return 31 * (31 * (31 * groupPos + childPos) + flatListPos) + type;
}
}

View file

@ -0,0 +1,39 @@
package thoughtbot.expandableadapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import awais.instagrabber.R;
import awais.instagrabber.interfaces.OnGroupClickListener;
public class GroupViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final OnGroupClickListener listener;
private final TextView title;
private final ImageView arrow;
public GroupViewHolder(@NonNull final View itemView, final OnGroupClickListener listener) {
super(itemView);
this.listener = listener;
this.title = itemView.findViewById(android.R.id.text1);
this.arrow = itemView.findViewById(R.id.collapsingArrow);
this.title.setBackgroundColor(0x80_1565C0);
itemView.setOnClickListener(this);
}
public void setTitle(@NonNull final String title) {
this.title.setText(title);
}
@Override
public void onClick(final View v) {
if (listener != null) listener.toggleGroup(getLayoutPosition());
}
public void toggle(final boolean expand) {
arrow.setImageResource(expand ? R.drawable.collapse : R.drawable.expand);
}
}