Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3366 from AmooHashem/issue#3100
Browse files Browse the repository at this point in the history
Replace Hashmap with SparseArray in PeekView.java and HistoryPosts.java
  • Loading branch information
ccrama authored Jun 17, 2021
2 parents bdead96 + 6b27050 commit 03ce6a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
26 changes: 11 additions & 15 deletions app/src/main/java/me/ccrama/redditslide/Adapters/HistoryPosts.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.ccrama.redditslide.Adapters;

import android.os.AsyncTask;
import android.util.SparseArray;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

Expand All @@ -12,10 +13,7 @@
import net.dean.jraw.paginators.FullnamesPaginator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import me.ccrama.redditslide.Authentication;
import me.ccrama.redditslide.PostMatch;
Expand All @@ -24,9 +22,9 @@
* Created by ccrama on 9/17/2015.
*/
public class HistoryPosts extends GeneralPosts {
private SwipeRefreshLayout refreshLayout;
private SwipeRefreshLayout refreshLayout;
private ContributionAdapter adapter;
public boolean loading;
public boolean loading;
String prefix = "";

public HistoryPosts() {
Expand Down Expand Up @@ -112,7 +110,7 @@ protected ArrayList<Contribution> doInBackground(String... subredditPaginators)
try {
if (reset || paginator == null) {
ArrayList<String> ids = new ArrayList<>();
HashMap<Long, String> idsSorted = new HashMap<>();
SparseArray<String> idsSorted = new SparseArray<>();
Map<String, String> values;
if (prefix.isEmpty()) {
values = KVStore.getInstance().getByContains("");
Expand All @@ -134,29 +132,27 @@ protected ArrayList<Contribution> doInBackground(String... subredditPaginators)
ids.add("t3_" + entry.getKey());
} else if (done instanceof Long) {
if (entry.getKey().contains("_")) {
idsSorted.put((Long) done, entry.getKey());
idsSorted.put((int) done, entry.getKey());
} else {
idsSorted.put((Long) done, "t3_" + entry.getKey());
idsSorted.put((int) done, "t3_" + entry.getKey());
}
}
}
} else {
String key = entry.getKey();
if(!key.contains("_")){
if (!key.contains("_")) {
key = "t3_" + key;
}
idsSorted.put((Long) done, key.replace(prefix, ""));
idsSorted.put((int) done, key.replace(prefix, ""));
}
}

if (!idsSorted.isEmpty()) {
TreeMap<Long, String> result2 = new TreeMap<>(Collections.reverseOrder());
result2.putAll(idsSorted);
ids.addAll(0, result2.values());
for (int i = 0; i < idsSorted.size(); i++) {
ids.add(0, idsSorted.valueAt(i));
}

paginator = new FullnamesPaginator(Authentication.reddit,
ids.toArray(new String[ids.size()-1]));
ids.toArray(new String[ids.size() - 1]));


}
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/me/ccrama/redditslide/ForceTouch/PeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.SparseArray;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -24,9 +25,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;

import jp.wasabeef.blurry.Blurry;
import me.ccrama.redditslide.ForceTouch.builder.PeekViewOptions;
import me.ccrama.redditslide.ForceTouch.callback.OnButtonUp;
Expand Down Expand Up @@ -96,12 +94,13 @@ public void onAnimationUpdate(ValueAnimator valueAnimator){
return;
}
}
for (Integer i : buttons.keySet()) {
final View v = content.findViewById(i);
for (int i = 0; i < buttons.size(); i++){
int key = buttons.keyAt(i);
final View v = content.findViewById(key);
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if(outRect.contains((int) event.getX(), (int) event.getY()) && i != currentHighlight){
currentHighlight = i;
if(outRect.contains((int) event.getX(), (int) event.getY()) && key != currentHighlight){
currentHighlight = key;
ValueAnimator animator = ValueAnimator.ofInt(eight * 2, eight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
Expand Down Expand Up @@ -135,15 +134,17 @@ public PeekView(Activity context, PeekViewOptions options, @NonNull View content
init(context, options, content, callbacks);
}

HashMap<Integer, OnButtonUp> buttons = new HashMap<>();
SparseArray<OnButtonUp> buttons = new SparseArray<>();

public void checkButtons(MotionEvent event) {
for (Map.Entry<Integer, OnButtonUp> entry : buttons.entrySet()) {
View v = content.findViewById(entry.getKey());
for (int i = 0; i < buttons.size(); i++) {
int key = buttons.keyAt(i);
OnButtonUp value = buttons.get(key);
View v = content.findViewById(key);
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if(outRect.contains((int) event.getX(), (int) event.getY())){
entry.getValue().onButtonUp();
if (outRect.contains((int) event.getX(), (int) event.getY())) {
value.onButtonUp();
}
}
}
Expand Down

0 comments on commit 03ce6a2

Please sign in to comment.