Skip to content

Commit

Permalink
Completed requirement #4
Browse files Browse the repository at this point in the history
Now, next to the cards, a percentage will appear with the evolution of the field by the latest 24 hours
  • Loading branch information
Javinator9889 committed Mar 5, 2018
1 parent 7acf264 commit cadc982
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 34 deletions.
4 changes: 4 additions & 0 deletions Green_Arrow_Up_Darker.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Red_Arrow_Down.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "javinator9889.bitcoinpools"
minSdkVersion 21
targetSdkVersion 27
versionCode 36
versionName "1.18"
versionCode 40
versionName "1.18-beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file added app/debug/app-debug.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/debug/output.json
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":36},"path":"app-debug.apk","properties":{"packageId":"javinator9889.bitcoinpools","split":"","minSdkVersion":"21"}}]
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -40,14 +40,16 @@
android:name=".SpinnerActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".FragmentViews$DonationsActivity" />
<activity android:name=".FragmentViews.DonationsActivity"
tools:ignore="InnerclassSeparator" />

<service
android:name=".BackgroundJobs.JobSchedulerService"
android:permission="android.permission.BIND_JOB_SERVICE"
tools:ignore="InnerclassSeparator" />
<service android:name=".BackgroundJobs.CacheJobSchedulerService"
android:permission="android.permission.BIND_JOB_SERVICE" />
android:permission="android.permission.BIND_JOB_SERVICE"
tools:ignore="InnerclassSeparator" />

</application>

Expand Down
Expand Up @@ -78,7 +78,7 @@ public boolean onStopJob(JobParameters params) {
}

private void updateCache() {
String date = new SimpleDateFormat("dd-MM-yyyy", Locale.US).format(Calendar.getInstance().getTime());
String date = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.US).format(Calendar.getInstance().getTime());
CacheManaging cache = CacheManaging.newInstance(BitCoinApp.getAppContext());
try {
cache.setupFile();
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/javinator9889/bitcoinpools/BitCoinApp.java
Expand Up @@ -15,6 +15,7 @@

import com.crashlytics.android.Crashlytics;

import java.io.IOException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -34,6 +35,7 @@ public class BitCoinApp extends Application {
@SuppressLint("StaticFieldLeak")
private static Context APPLICATION_CONTEXT;
private static SharedPreferences SHARED_PREFERENCES;
private static boolean isCacheCreated = false;

public static Context getAppContext() {
return APPLICATION_CONTEXT;
Expand All @@ -48,20 +50,17 @@ public void onCreate() {
APPLICATION_CONTEXT = getApplicationContext();
SHARED_PREFERENCES = getSharedPreferences(Constants.SHARED_PREFERENCES.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
initSharedPreferences();
startBackgroundJobs();
try {
System.out.println(CacheManaging.newInstance(this).readCache());
} catch (Exception e) {
System.out.println("No cache values found");
isCacheCreated = CacheManaging.newInstance(this).setupFile();
} catch (IOException e) {
isCacheCreated = false;
}
startBackgroundJobs();
super.onCreate();
Log.d(Constants.LOG.BCTAG, Constants.LOG.CREATED_APP);
}

private static void startBackgroundJobs() {
JobScheduler globalJobScheduler = (JobScheduler) APPLICATION_CONTEXT.getSystemService(Context.JOB_SCHEDULER_SERVICE);
List<JobInfo> pendingJobs = globalJobScheduler != null ? globalJobScheduler.getAllPendingJobs() : new ArrayList<JobInfo>(0);

JobScheduler mJobScheduler = (JobScheduler) APPLICATION_CONTEXT.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(1, new ComponentName(APPLICATION_CONTEXT.getPackageName(), JobSchedulerService.class.getName()));

Expand All @@ -75,22 +74,25 @@ private static void startBackgroundJobs() {
Log.e(Constants.LOG.BCTAG, Constants.LOG.NO_INIT + "JobScheduler" + mJobScheduler.getAllPendingJobs().toString());
}

JobScheduler cacheJobScheduler = (JobScheduler) APPLICATION_CONTEXT.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder cacheBuilder = new JobInfo.Builder(2, new ComponentName(APPLICATION_CONTEXT.getPackageName(), CacheJobSchedulerService.class.getName()));
if (!(SHARED_PREFERENCES.getBoolean(Constants.SHARED_PREFERENCES.CACHE_JOB, false)) || isCacheCreated) {
JobScheduler cacheJobScheduler = (JobScheduler) APPLICATION_CONTEXT.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder cacheBuilder = new JobInfo.Builder(2, new ComponentName(APPLICATION_CONTEXT.getPackageName(), CacheJobSchedulerService.class.getName()));


cacheBuilder.setPeriodic(TimeUnit.DAYS.toMillis(1));
cacheBuilder.setPersisted(Constants.PERSISTED);
cacheBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
cacheBuilder.setBackoffCriteria(Constants.BACKOFF_CRITERIA, JobInfo.BACKOFF_POLICY_LINEAR);
cacheBuilder.setPeriodic(TimeUnit.DAYS.toMillis(1));
cacheBuilder.setPersisted(Constants.PERSISTED);
cacheBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
cacheBuilder.setBackoffCriteria(Constants.BACKOFF_CRITERIA, JobInfo.BACKOFF_POLICY_LINEAR);

if ((pendingJobs.size() != 0) && !(pendingJobs.contains(cacheBuilder.build()))) {
assert cacheJobScheduler != null;
if (cacheJobScheduler.schedule(cacheBuilder.build()) == JobScheduler.RESULT_FAILURE) {
Log.e(Constants.LOG.BCTAG, Constants.LOG.NO_INIT + "JobScheduler" + mJobScheduler.getAllPendingJobs().toString());
} else {
SharedPreferences.Editor newValueForStartedJob = SHARED_PREFERENCES.edit();
newValueForStartedJob.putBoolean(Constants.SHARED_PREFERENCES.CACHE_JOB, true);
newValueForStartedJob.apply();
}
} else
System.out.println("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE EL JOB YA EXISTE");
}
}

private void initSharedPreferences() {
Expand Down
Expand Up @@ -30,6 +30,7 @@ public static final class SHARED_PREFERENCES {
public static final String VALUE_TO_CHECK = "value_to_check";
public static final String SHARED_PREFERENCES_INITIALIZED = "initialized";
public static final String APP_VERSION = "APP_VERSION";
public static final String CACHE_JOB = "CACHE_JOB";
}
public static final String CHANNEL_ID = "javinator9889.bitcoinpools.Alerts";
public static final int NOTIFICATION_ID = 1;
Expand Down
@@ -1,5 +1,6 @@
package javinator9889.bitcoinpools;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
Expand Down Expand Up @@ -52,14 +53,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.cancelable(false)
.title(R.string.loadingData)
.content(R.string.please_wait)
.progress(true, 0)
.progress(false, 100)
.build();
progressDialog.show();
new DataLoader().execute();
//new MainActivity.DataLoader().execute();
}
}

@SuppressLint("StaticFieldLeak")
class DataLoader extends AsyncTask<Void, Void, Boolean> {
private Thread marketPriceThread;
private Thread poolsDataThread;
Expand All @@ -86,7 +88,7 @@ protected void onPostExecute(Boolean result) {
activityMainIntent.putExtra("CARDS", cardsData);
activityMainIntent.putExtra("BTCPRICE", btcPrice);
startActivity(activityMainIntent);
//DataLoaderScreen.this.finish();
DataLoaderScreen.this.finish();
} else {
Log.i("DLS", "Data non-loaded...");
if (progressDialog != null) {
Expand Down Expand Up @@ -156,6 +158,7 @@ public void run() {
}*/
try {
mpu = round((float) getHTTPSRequest(Constants.STATS_URL).getDouble(Constants.MARKET_NAME), 2);
progressDialog.setProgress(progressDialog.getCurrentProgress() + 20);
} catch (Exception e) {
Log.e(Constants.LOG.MATAG, Constants.LOG.MARKET_PRICE_ERROR + e.getMessage());
mpu = -1;
Expand Down Expand Up @@ -183,6 +186,7 @@ public void run() {
}*/
try {
retrievedData = JSONTools.convert2HashMap(getHTTPSRequest(url));
progressDialog.setProgress(progressDialog.getCurrentProgress() + 20);
} catch (Exception e) {
retrievedData = null;
Log.e(Constants.LOG.MATAG, Constants.LOG.DATA_ERROR + e.getMessage());
Expand All @@ -209,6 +213,7 @@ public void run() {
}*/
try {
cardsData = JSONTools.convert2HashMap(getHTTPSRequest(Constants.STATS_URL));
progressDialog.setProgress(progressDialog.getCurrentProgress() + 20);
} catch (Exception e) {
cardsData = null;
Log.e(Constants.LOG.MATAG, Constants.LOG.DATA_ERROR + e.getMessage());
Expand All @@ -233,6 +238,7 @@ public void run() {
}*/
try {
btcPrice = JSONTools.convert2DateHashMap(getHTTPSRequest(Constants.API_URL).getJSONObject("bpi"));
progressDialog.setProgress(progressDialog.getCurrentProgress() + 20);
} catch (Exception e) {
btcPrice = null;
Log.e(Constants.LOG.MATAG, Constants.LOG.DATA_ERROR + e.getMessage());
Expand Down
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Locale;

import javinator9889.bitcoinpools.BitCoinApp;
import javinator9889.bitcoinpools.R;

/**
Expand Down Expand Up @@ -76,11 +75,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(pricePercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(pricePercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -97,11 +98,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(powerPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(powerPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -123,11 +126,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(difficultyPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(- difficultyPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -144,11 +149,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(blockPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(blockPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -170,11 +177,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(minutesPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(minutesPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -196,11 +205,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(feePercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(feePercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -217,11 +228,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(transPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(transPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand All @@ -238,11 +251,13 @@ public void onBindViewHolder(final MyViewHolder holder, @SuppressLint("RecyclerV
String positiveText = "+" + decimalFormat.format(benefitPercentage) + "%";
holder.oldData.setText(positiveText);
holder.oldData.setTextColor(Color.GREEN);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_green_arrow_up_darker, 0, 0, 0);
break;
case -1:
String negativeText = decimalFormat.format(benefitPercentage) + "%";
holder.oldData.setText(negativeText);
holder.oldData.setTextColor(Color.RED);
holder.oldData.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_red_arrow_down, 0, 0, 0);
break;
}
break;
Expand Down
Expand Up @@ -33,6 +33,7 @@

import javinator9889.bitcoinpools.BitCoinApp;
import javinator9889.bitcoinpools.Constants;
import javinator9889.bitcoinpools.DataLoaderScreen;
import javinator9889.bitcoinpools.JSONTools.JSONTools;
import javinator9889.bitcoinpools.MainActivity;
import javinator9889.bitcoinpools.NetTools.net;
Expand Down Expand Up @@ -97,6 +98,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
createTable(tableLayout, createdView);
try {
tableThread.join();
DataLoaderScreen.progressDialog.setProgress(DataLoaderScreen.progressDialog.getCurrentProgress() + 10);
return createdView;
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down
Expand Up @@ -55,6 +55,7 @@
import javinator9889.bitcoinpools.BitCoinApp;
import javinator9889.bitcoinpools.CacheManaging;
import javinator9889.bitcoinpools.Constants;
import javinator9889.bitcoinpools.DataLoaderScreen;
import javinator9889.bitcoinpools.JSONTools.JSONTools;
import javinator9889.bitcoinpools.MainActivity;
import javinator9889.bitcoinpools.NetTools.net;
Expand Down Expand Up @@ -160,6 +161,8 @@ public void onClick(View v) {
longPressInfo = getString(R.string.longclick);
((TextView) createdView.findViewById(R.id.longPressInfo)).setText(longPressInfo);
return createdView;
} finally {
DataLoaderScreen.progressDialog.setProgress(DataLoaderScreen.progressDialog.getCurrentProgress() + 10);
}
}

Expand Down

0 comments on commit cadc982

Please sign in to comment.