Finalize charts
This commit is contained in:
parent
b6232b1203
commit
596eff6ac0
|
@ -29,7 +29,9 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -39,14 +41,18 @@ import androidx.core.content.ContextCompat;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.Description;
|
||||
import com.github.mikephil.charting.components.IMarker;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.MarkerView;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
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.ValueFormatter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.MPPointF;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -81,6 +87,8 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
private Date dateIni, dateEnd;
|
||||
private LineChart chart;
|
||||
private int theme;
|
||||
private RelativeLayout loader;
|
||||
private ImageButton validate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -149,12 +157,58 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
chart = findViewById(R.id.chart);
|
||||
settings_time_from = findViewById(R.id.settings_time_from);
|
||||
settings_time_to = findViewById(R.id.settings_time_to);
|
||||
|
||||
loader = findViewById(R.id.loader);
|
||||
validate = findViewById(R.id.validate);
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(OwnerChartsActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
dateIni = new StatusCacheDAO(OwnerChartsActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
dateEnd = new StatusCacheDAO(OwnerChartsActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
|
||||
|
||||
int style;
|
||||
if( theme == Helper.THEME_DARK){
|
||||
style = R.style.DialogDark;
|
||||
}else if( theme == Helper.THEME_BLACK){
|
||||
style = R.style.DialogBlack;
|
||||
}else {
|
||||
style = R.style.Dialog;
|
||||
}
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(dateIni);
|
||||
int yearIni = c.get(Calendar.YEAR);
|
||||
int monthIni = c.get(Calendar.MONTH);
|
||||
int dayIni = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
final DatePickerDialog dateIniPickerDialog = new DatePickerDialog(
|
||||
OwnerChartsActivity.this, style, iniDateSetListener, yearIni, monthIni, dayIni);
|
||||
settings_time_from.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dateIniPickerDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Calendar ce = Calendar.getInstance();
|
||||
c.setTime(dateEnd);
|
||||
int yearEnd = ce.get(Calendar.YEAR);
|
||||
int monthEnd = ce.get(Calendar.MONTH);
|
||||
int dayEnd = ce.get(Calendar.DAY_OF_MONTH);
|
||||
final DatePickerDialog dateEndPickerDialog = new DatePickerDialog(
|
||||
OwnerChartsActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
|
||||
settings_time_to.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dateEndPickerDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
dateIniPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
|
||||
dateIniPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
|
||||
|
||||
dateEndPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
|
||||
dateEndPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(dateEnd);
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
|
@ -169,16 +223,48 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
dateEnd = new Date();
|
||||
}
|
||||
|
||||
String dateInitString = Helper.shortDateToString(dateIni);
|
||||
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||
|
||||
settings_time_from.setText(dateInitString);
|
||||
settings_time_to.setText(dateEndString);
|
||||
CustomMarkerView mv = new CustomMarkerView(getApplicationContext(), R.layout.markerview);
|
||||
chart.setMarkerView(mv);
|
||||
|
||||
validate.setOnClickListener(v->{
|
||||
loadGraph(dateIni, dateEnd);
|
||||
});
|
||||
|
||||
loadGraph(dateIni, dateEnd);
|
||||
|
||||
new RetrieveChartsAsyncTask(OwnerChartsActivity.this, dateIni, dateEnd, OwnerChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
||||
public class CustomMarkerView extends MarkerView {
|
||||
private TextView tvContent;
|
||||
|
||||
public CustomMarkerView(Context context, int layoutResource) {
|
||||
super(context, layoutResource);
|
||||
tvContent = findViewById(R.id.tvContent);
|
||||
if( theme == Helper.THEME_DARK){
|
||||
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
|
||||
}else if( theme == Helper.THEME_BLACK){
|
||||
tvContent.setTextColor(ContextCompat.getColor(context, R.color.dark_text));
|
||||
}else {
|
||||
tvContent.setTextColor(ContextCompat.getColor(context, R.color.black));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
Date date = new Date(((long) e.getX()));
|
||||
tvContent.setText(String.valueOf(Helper.shortDateToString(date) + " - " +(int)e.getY()));
|
||||
super.refreshContent(e, highlight);
|
||||
}
|
||||
private MPPointF mOffset;
|
||||
@Override
|
||||
public MPPointF getOffset() {
|
||||
if(mOffset == null) {
|
||||
mOffset = new MPPointF(-(getWidth() / 2), -getHeight());
|
||||
}
|
||||
return mOffset;
|
||||
}
|
||||
}
|
||||
|
||||
private DatePickerDialog.OnDateSetListener iniDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
|
@ -218,6 +304,18 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
}
|
||||
}
|
||||
|
||||
private void loadGraph(Date dateIni, Date dateEnd){
|
||||
String dateInitString = Helper.shortDateToString(dateIni);
|
||||
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||
|
||||
settings_time_from.setText(dateInitString);
|
||||
settings_time_to.setText(dateEndString);
|
||||
chart.setVisibility(View.GONE);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
validate.setEnabled(false);
|
||||
new RetrieveChartsAsyncTask(OwnerChartsActivity.this, dateIni, dateEnd, OwnerChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
@ -343,7 +441,9 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
xAxis.setValueFormatter(new MyXAxisValueFormatter());
|
||||
LineData data = new LineData(dataSets);
|
||||
chart.setData(data);
|
||||
|
||||
chart.setVisibility(View.VISIBLE);
|
||||
loader.setVisibility(View.GONE);
|
||||
validate.setEnabled(true);
|
||||
chart.invalidate();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import android.widget.Button;
|
|||
import android.widget.CheckBox;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
|
@ -547,7 +548,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
TextView first_toot_date = statsDialogView.findViewById(R.id.first_toot_date);
|
||||
TextView tags = statsDialogView.findViewById(R.id.tags);
|
||||
|
||||
Button charts = statsDialogView.findViewById(R.id.charts);
|
||||
ImageButton charts = statsDialogView.findViewById(R.id.charts);
|
||||
charts.setOnClickListener(w ->{
|
||||
Intent intent = new Intent(OwnerStatusActivity.this, OwnerChartsActivity.class);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM9,17L7,17v-7h2v7zM13,17h-2L11,7h2v10zM17,17h-2v-4h2v4z"/>
|
||||
</vector>
|
|
@ -34,9 +34,44 @@
|
|||
android:id="@+id/settings_time_to"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageButton
|
||||
android:id="@+id/validate"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:src="@drawable/ic_check_white_24"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:contentDescription="@string/validate" />
|
||||
</LinearLayout>
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/chart"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/collecting_data_wait"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<ProgressBar
|
||||
android:layout_below="@+id/text"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/chart"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text=""
|
||||
android:textSize="14sp"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -33,11 +33,26 @@
|
|||
android:paddingEnd="@dimen/activity_vertical_margin"
|
||||
android:paddingRight="@dimen/activity_vertical_margin"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:id="@+id/charts"
|
||||
android:text="@string/display_charts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/display_charts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageButton
|
||||
android:id="@+id/charts"
|
||||
android:layout_marginStart="15dp"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:src="@drawable/ic_insert_chart"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:contentDescription="@string/validate" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1142,6 +1142,7 @@
|
|||
<string name="set_disable_animated_emoji">Disable custom animated emojis</string>
|
||||
<string name="owner_charts">Charts</string>
|
||||
<string name="display_charts">Display charts</string>
|
||||
<string name="collecting_data_wait">The application collects your local data, please wait...</string>
|
||||
<plurals name="number_of_vote">
|
||||
<item quantity="one">%d vote</item>
|
||||
<item quantity="other">%d votes</item>
|
||||
|
|
Loading…
Reference in New Issue