Improve speed for drawing charts
This commit is contained in:
parent
b726456b54
commit
1c75676b8a
|
@ -59,8 +59,10 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.asynctasks.RetrieveChartsAsyncTask;
|
import app.fedilab.android.asynctasks.RetrieveChartsAsyncTask;
|
||||||
|
@ -324,23 +326,29 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
||||||
|
|
||||||
List<Entry> boostsEntry = new ArrayList<>();
|
List<Entry> boostsEntry = new ArrayList<>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int boost : charts.getBoosts()) {
|
Iterator it = charts.getBoosts().entrySet().iterator();
|
||||||
boostsEntry.add(new Entry(charts.getxValues().get(i), boost));
|
while (it.hasNext()) {
|
||||||
i++;
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
|
boostsEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Entry> repliesEntry = new ArrayList<>();
|
List<Entry> repliesEntry = new ArrayList<>();
|
||||||
i = 0;
|
it = charts.getReplies().entrySet().iterator();
|
||||||
for (int reply : charts.getReplies()) {
|
while (it.hasNext()) {
|
||||||
repliesEntry.add(new Entry(charts.getxValues().get(i), reply));
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
i++;
|
repliesEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Entry> statusesEntry = new ArrayList<>();
|
List<Entry> statusesEntry = new ArrayList<>();
|
||||||
i = 0;
|
it = charts.getStatuses().entrySet().iterator();
|
||||||
for (int status : charts.getStatuses()) {
|
while (it.hasNext()) {
|
||||||
statusesEntry.add(new Entry(charts.getxValues().get(i), status));
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
i++;
|
statusesEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
LineDataSet dataSetBoosts = new LineDataSet(boostsEntry, getString(R.string.reblog));
|
LineDataSet dataSetBoosts = new LineDataSet(boostsEntry, getString(R.string.reblog));
|
||||||
dataSetBoosts.setColor(ContextCompat.getColor(OwnerChartsActivity.this, R.color.chart_boost));
|
dataSetBoosts.setColor(ContextCompat.getColor(OwnerChartsActivity.this, R.color.chart_boost));
|
||||||
dataSetBoosts.setValueTextSize(12f);
|
dataSetBoosts.setValueTextSize(12f);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package app.fedilab.android.client.Entities;
|
package app.fedilab.android.client.Entities;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/* Copyright 2019 Thomas Schneider
|
/* Copyright 2019 Thomas Schneider
|
||||||
|
@ -21,10 +23,9 @@ public class Charts {
|
||||||
|
|
||||||
private List<String> xLabels;
|
private List<String> xLabels;
|
||||||
private List<String> yLabels;
|
private List<String> yLabels;
|
||||||
private List<Long> xValues;
|
private LinkedHashMap<Long, Integer> statuses;
|
||||||
private List<Integer> statuses;
|
private LinkedHashMap<Long, Integer> boosts;
|
||||||
private List<Integer> boosts;
|
private LinkedHashMap<Long, Integer> replies;
|
||||||
private List<Integer> replies;
|
|
||||||
|
|
||||||
public List<String> getxLabels() {
|
public List<String> getxLabels() {
|
||||||
return xLabels;
|
return xLabels;
|
||||||
|
@ -42,35 +43,27 @@ public class Charts {
|
||||||
this.yLabels = yLabels;
|
this.yLabels = yLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Long> getxValues() {
|
public LinkedHashMap<Long, Integer> getStatuses() {
|
||||||
return xValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setxValues(List<Long> xValues) {
|
|
||||||
this.xValues = xValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getStatuses() {
|
|
||||||
return statuses;
|
return statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatuses(List<Integer> statuses) {
|
public void setStatuses(LinkedHashMap<Long, Integer> statuses) {
|
||||||
this.statuses = statuses;
|
this.statuses = statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getBoosts() {
|
public LinkedHashMap<Long, Integer> getBoosts() {
|
||||||
return boosts;
|
return boosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoosts(List<Integer> boosts) {
|
public void setBoosts(LinkedHashMap<Long, Integer> boosts) {
|
||||||
this.boosts = boosts;
|
this.boosts = boosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getReplies() {
|
public LinkedHashMap<Long, Integer> getReplies() {
|
||||||
return replies;
|
return replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplies(List<Integer> replies) {
|
public void setReplies(LinkedHashMap<Long, Integer> replies) {
|
||||||
this.replies = replies;
|
this.replies = replies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -466,16 +467,11 @@ public class StatusCacheDAO {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
int inc = 0;
|
|
||||||
List<String> xLabel = new ArrayList<>();
|
List<String> xLabel = new ArrayList<>();
|
||||||
List<Long> xValues = new ArrayList<>();
|
|
||||||
List<Integer> statuses = new ArrayList<>();
|
|
||||||
List<Integer> boosts = new ArrayList<>();
|
|
||||||
List<Integer> replies = new ArrayList<>();
|
|
||||||
|
|
||||||
int boostsCount = 0;
|
charts.setStatuses(new LinkedHashMap<>());
|
||||||
int repliesCount = 0;
|
charts.setBoosts(new LinkedHashMap<>());
|
||||||
int statusesCount = 0;
|
charts.setReplies(new LinkedHashMap<>());
|
||||||
if( data != null) {
|
if( data != null) {
|
||||||
for (Status status : data) {
|
for (Status status : data) {
|
||||||
Calendar tempdate = Calendar.getInstance();
|
Calendar tempdate = Calendar.getInstance();
|
||||||
|
@ -483,24 +479,30 @@ public class StatusCacheDAO {
|
||||||
tempdate.set(Calendar.HOUR_OF_DAY, 0);
|
tempdate.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
tempdate.set(Calendar.MINUTE, 0);
|
tempdate.set(Calendar.MINUTE, 0);
|
||||||
tempdate.set(Calendar.SECOND, 0);
|
tempdate.set(Calendar.SECOND, 0);
|
||||||
xValues.add(tempdate.getTimeInMillis());
|
long date = tempdate.getTimeInMillis();
|
||||||
if (status.getReblog() != null) {
|
if (status.getReblog() != null) {
|
||||||
boostsCount++;
|
if(charts.getBoosts().containsKey(date)){
|
||||||
|
charts.getBoosts().put(date,(charts.getBoosts().get(date)+1));
|
||||||
|
}else{
|
||||||
|
charts.getBoosts().put(date,1);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) {
|
} else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) {
|
||||||
repliesCount++;
|
if(charts.getReplies().containsKey(date)){
|
||||||
|
charts.getReplies().put(date,(charts.getReplies().get(date)+1));
|
||||||
|
}else{
|
||||||
|
charts.getReplies().put(date,1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
statusesCount++;
|
if(charts.getStatuses().containsKey(date)){
|
||||||
|
charts.getStatuses().put(date,(charts.getStatuses().get(date)+1));
|
||||||
|
}else{
|
||||||
|
charts.getStatuses().put(date,1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boosts.add(boostsCount);
|
|
||||||
replies.add(repliesCount);
|
|
||||||
statuses.add(statusesCount);
|
|
||||||
charts.setxLabels(xLabel);
|
charts.setxLabels(xLabel);
|
||||||
charts.setxValues(xValues);
|
|
||||||
charts.setBoosts(boosts);
|
|
||||||
charts.setReplies(replies);
|
|
||||||
charts.setStatuses(statuses);
|
|
||||||
return charts;
|
return charts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue