stats
This commit is contained in:
parent
237b77d085
commit
a2ba1be8bd
|
@ -20,6 +20,7 @@ import android.app.DatePickerDialog;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
@ -30,21 +31,31 @@ import android.view.ViewGroup;
|
|||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.LineDataSet;
|
||||
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
||||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.asynctasks.RetrieveChartsAsyncTask;
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
|
@ -197,7 +208,6 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -211,27 +221,21 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
int i = 0;
|
||||
for (int boost : charts.getBoosts()) {
|
||||
boostsEntry.add(new Entry(charts.getxValues().get(i), boost));
|
||||
Log.v(Helper.TAG,"boost: " + boost);
|
||||
i++;
|
||||
}
|
||||
Log.v(Helper.TAG,"boostsEntry: " + boostsEntry.size());
|
||||
|
||||
List<Entry> repliesEntry = new ArrayList<>();
|
||||
i = 0;
|
||||
for (int reply : charts.getReplies()) {
|
||||
repliesEntry.add(new Entry(charts.getxValues().get(i), reply));
|
||||
Log.v(Helper.TAG,"reply: " + reply);
|
||||
i++;
|
||||
}
|
||||
Log.v(Helper.TAG,"repliesEntry: " + repliesEntry.size());
|
||||
List<Entry> statusesEntry = new ArrayList<>();
|
||||
i = 0;
|
||||
for (int status : charts.getStatuses()) {
|
||||
statusesEntry.add(new Entry(charts.getxValues().get(i), status));
|
||||
Log.v(Helper.TAG,"status: " + status);
|
||||
i++;
|
||||
}
|
||||
Log.v(Helper.TAG,"statusesEntry: " + statusesEntry.size());
|
||||
LineDataSet dataSetBoosts = new LineDataSet(boostsEntry, getString(R.string.reblog));
|
||||
dataSetBoosts.setColor(ContextCompat.getColor(OwnerChartsActivity.this, R.color.chart_boost));
|
||||
dataSetBoosts.setValueTextColor(ContextCompat.getColor(OwnerChartsActivity.this, R.color.chart_boost));
|
||||
|
@ -252,18 +256,43 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
dataSets.add(dataSetStatuses);
|
||||
|
||||
|
||||
|
||||
XAxis xAxis = chart.getXAxis();
|
||||
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||
xAxis.setTextSize(10f);
|
||||
xAxis.setLabelRotationAngle(45);
|
||||
//xAxis.setTextColor(Color.RED);
|
||||
xAxis.setTextColor(Color.RED);
|
||||
xAxis.setDrawAxisLine(true);
|
||||
xAxis.setDrawGridLines(false);
|
||||
|
||||
xAxis.setValueFormatter(new MyXAxisValueFormatter());
|
||||
LineData data = new LineData(dataSets);
|
||||
chart.setData(data);
|
||||
|
||||
chart.invalidate();
|
||||
}
|
||||
|
||||
|
||||
public class MyXAxisValueFormatter extends ValueFormatter {
|
||||
private DateFormat mDataFormat;
|
||||
private Date mDate;
|
||||
|
||||
MyXAxisValueFormatter() {
|
||||
this.mDataFormat = new SimpleDateFormat("dd.MM", Locale.getDefault());
|
||||
this.mDate = new Date();
|
||||
}
|
||||
@Override
|
||||
public String getFormattedValue(float value) {
|
||||
return getDateString((long) value);
|
||||
}
|
||||
|
||||
private String getDateString(long timestamp) {
|
||||
try {
|
||||
mDate.setTime(timestamp);
|
||||
return mDataFormat.format(mDate);
|
||||
} catch(Exception ex) {
|
||||
return "xx";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class Charts {
|
|||
|
||||
private List<String> xLabels;
|
||||
private List<String> yLabels;
|
||||
private List<Integer> xValues;
|
||||
private List<Long> xValues;
|
||||
private List<Integer> statuses;
|
||||
private List<Integer> boosts;
|
||||
private List<Integer> replies;
|
||||
|
@ -42,11 +42,11 @@ public class Charts {
|
|||
this.yLabels = yLabels;
|
||||
}
|
||||
|
||||
public List<Integer> getxValues() {
|
||||
public List<Long> getxValues() {
|
||||
return xValues;
|
||||
}
|
||||
|
||||
public void setxValues(List<Integer> xValues) {
|
||||
public void setxValues(List<Long> xValues) {
|
||||
this.xValues = xValues;
|
||||
}
|
||||
|
||||
|
|
|
@ -467,7 +467,7 @@ public class StatusCacheDAO {
|
|||
}
|
||||
int inc = 0;
|
||||
List<String> xLabel = new ArrayList<>();
|
||||
List<Integer> xValues = new ArrayList<>();
|
||||
List<Long> xValues = new ArrayList<>();
|
||||
List<Integer> statuses = new ArrayList<>();
|
||||
List<Integer> boosts = new ArrayList<>();
|
||||
List<Integer> replies = new ArrayList<>();
|
||||
|
@ -476,7 +476,7 @@ public class StatusCacheDAO {
|
|||
Date targetDay = start.getTime();
|
||||
Date dateLimite = new Date(targetDay.getTime() + TimeUnit.DAYS.toMillis(1));
|
||||
xLabel.add(Helper.shortDateToString(targetDay));
|
||||
xValues.add(inc);
|
||||
xValues.add(targetDay.getTime());
|
||||
int boostsCount = 0;
|
||||
int repliesCount = 0;
|
||||
int statusesCount = 0;
|
||||
|
|
|
@ -68,11 +68,10 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue