Skip to content

Commit

Permalink
Notifications images
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Dec 2, 2018
1 parent 7f55ee3 commit d4dbe3f
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "javinator9889.bitcoinpools"
minSdkVersion 21
targetSdkVersion 28
versionCode 98
versionName "1.19"
versionCode 100
versionName "1.19.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
bundle {
Expand Down Expand Up @@ -101,7 +101,7 @@ tasks.withType(JavaCompile) {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
implementation 'androidx.media:media:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand All @@ -110,8 +110,8 @@ dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-invites:16.0.5'
implementation 'com.google.firebase:firebase-appindexing:16.0.2'
implementation 'com.google.firebase:firebase-perf:16.2.0'
implementation 'com.google.firebase:firebase-appindexing:17.1.0'
implementation 'com.google.firebase:firebase-perf:16.2.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.6@aar') {
transitive = true
}
Expand Down
Binary file modified app/release/BitCoinPools-1.19.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"apkInfo": {
"type": "MAIN",
"splits": [],
"versionCode": 95,
"versionCode": 98,
"versionName": "1.19",
"enabled": true,
"outputFile": "app-release.apk",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean handleMessage(Message msg) {
public boolean onStartJob(JobParameters params) {
Log.d(Constants.LOG.JTAG, Constants.LOG.STARTING_JOB + Constants.JOB_ID);
jobWorking = true;
notificationHandler = NotificationHandler.newInstance();
notificationHandler = NotificationHandler.newInstance(this);
jobHandler.sendMessage(Message.obtain(jobHandler, Constants.JOB_ID, params));
return jobWorking;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,42 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.os.Build;
import android.util.Log;

import com.github.mikephil.charting.charts.LineChart;
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.LargeValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import org.json.JSONException;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import javinator9889.bitcoinpools.BitCoinApp;
import javinator9889.bitcoinpools.Constants;
import javinator9889.bitcoinpools.DataLoaderScreen;
import javinator9889.bitcoinpools.FragmentViews.CustomMarkerView;
import javinator9889.bitcoinpools.JSONTools.JSONTools;
import javinator9889.bitcoinpools.MainActivity;
import javinator9889.bitcoinpools.NetTools.net;
import javinator9889.bitcoinpools.R;

import static javinator9889.bitcoinpools.Constants.API_URL;

/**
* Created by Javinator9889 on 23/01/2018.
* Based on: https://stackoverflow.com/a/46991229
Expand All @@ -33,9 +54,11 @@ class NotificationHandler {
private static boolean NOTIFIED_LOW = false;
private static int SPECIFIC_VALUE = 0;
private static float MPU;
private Context mContext;

private NotificationHandler() {
private NotificationHandler(@NonNull Context context) {
final SharedPreferences sp = BitCoinApp.getSharedPreferences();
mContext = context;
Log.d(Constants.LOG.NTAG, Constants.LOG.CREATING_NOTIFICATION);
NOTIFICATIONS_ENABLED = sp.getBoolean(Constants.SHARED_PREFERENCES.NOTIFICATIONS_ENABLED,
false);
Expand Down Expand Up @@ -88,6 +111,9 @@ void putNotification() {
}
if (notify) {
Log.d(Constants.LOG.NTAG, Constants.LOG.NOTIFYING);
updatePreferences();
final LineChart chart = new LineChart(mContext);
Bitmap chartBitmap = generateLineChart(chart);
String name = BitCoinApp.getAppContext().getString(R.string.alerts);
String description = BitCoinApp.getAppContext().getString(R.string.description);
Notification.Builder notification;
Expand Down Expand Up @@ -126,6 +152,8 @@ void putNotification() {
.setStyle(new Notification.BigTextStyle()
.bigText(notificationTextLong));
}
if (chartBitmap != null)
notification.setLargeIcon(chartBitmap);
notification.setContentIntent(clickIntent);
assert notificationManager != null;
notificationManager.notify(Constants.NOTIFICATION_ID, notification.build());
Expand All @@ -134,9 +162,73 @@ void putNotification() {
}
}

private Bitmap generateLineChart(@NonNull final LineChart lineChart) {
Map<Date, Float> pricesMap;
Calendar start = Calendar.getInstance();
start.add(Calendar.DAY_OF_MONTH, -7);
String startDate = String.format(Locale.US, "%d-%02d-%02d",
start.get(Calendar.YEAR),
start.get(Calendar.MONTH),
start.get(Calendar.DAY_OF_MONTH));
String url = API_URL + "?start=" + startDate + "&end=" +
new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Calendar.getInstance().getTime());
pricesMap = getValuesByDatedURL(url);
if (pricesMap == null)
return null;
lineChart.setDrawGridBackground(false);
lineChart.getDescription().setEnabled(false);
CustomMarkerView markerView = new CustomMarkerView(mContext, R.layout.marker_view);
markerView.setChartView(lineChart);
lineChart.setMarker(markerView);
ArrayList<Entry> values = new ArrayList<>(pricesMap.size());
int i = 0;
for (Date currentDate : pricesMap.keySet()) {
values.add(new Entry(i, pricesMap.get(currentDate)));
++i;
}
LineDataSet lineDataSet = new LineDataSet(values, mContext.getString(R.string
.latest_7_days));
lineDataSet.setDrawIcons(false);
lineDataSet.enableDashedLine(10f, 5f, 0f);
lineDataSet.enableDashedHighlightLine(10f, 5f, 0f);
lineDataSet.setColor(Color.BLACK);
lineDataSet.setCircleColor(Color.BLACK);
lineDataSet.setLineWidth(1f);
lineDataSet.setCircleRadius(3f);
lineDataSet.setDrawCircleHole(false);
lineDataSet.setValueTextSize(9f);
lineDataSet.setDrawFilled(true);
lineDataSet.setFormLineWidth(1f);
lineDataSet.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f},
0f));
lineDataSet.setFormSize(15.f);
lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
lineDataSet.setFillDrawable(ContextCompat.getDrawable(mContext, R.drawable.fade_red));
lineDataSet.setDrawCircles(false);
ArrayList<ILineDataSet> dataSets = new ArrayList<>(1);
dataSets.add(lineDataSet);
LineData data = new LineData(dataSets);
lineChart.setData(data);
lineChart.getAxisLeft().setValueFormatter(new LargeValueFormatter());
lineChart.invalidate();
return lineChart.getChartBitmap();
}

private Map<Date, Float> getValuesByDatedURL(@NonNull String url) {
net netRequest = new net();
netRequest.execute(url);
try {
return JSONTools.sortDateByValue(
JSONTools.convert2DateHashMap(netRequest.get().getJSONObject("bpi")));
} catch (InterruptedException | ExecutionException |
JSONException | NullPointerException ignored) {
return null;
}
}

@NonNull
static NotificationHandler newInstance() {
return new NotificationHandler();
static NotificationHandler newInstance(@NonNull Context context) {
return new NotificationHandler(context);
}

private static float initMPU() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@
uno o más servidores para así obtener los últimos datos sobre el BitCoin.

Por favor, inténtalo más tarde.</string>
<string name="latest_7_days">Evolución en los últimos 7 días</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,5 @@ SOFTWARE.<br />
connection to one or more servers in order to obtain the latest BitCoin data.

Please, try again later.</string>
<string name="latest_7_days">BitCoin evolution latest 7 days</string>
</resources>

0 comments on commit d4dbe3f

Please sign in to comment.