Skip to content

Commit

Permalink
Added transitions for enhacement #9. Solved a problem with new cache job
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Mar 6, 2018
1 parent 7d44f45 commit ff4e5c8
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 11 deletions.
Expand Up @@ -40,7 +40,7 @@ public class CheckUpdates {
private static JSONArray RETRIEVED_DATA;
private static String LATEST_VERSION;
private static String DOWNLOAD_URL = null;
private static String MORE_INFO = "https://play.google.com/store/apps/details?id=com.fastaccess.github";
private static String MORE_INFO = Constants.GOOGLE_PLAY_URL;
private static String APK_NAME;
private static boolean HTML_PAGE = false;

Expand Down
Expand Up @@ -68,14 +68,16 @@ void putNotification() {
notificationText = BitCoinApp.getAppContext().getString(R.string.lowerPriceX) + SPECIFIC_VALUE;
NOTIFIED_HIGH = false;
NOTIFIED_LOW = true;
notify = true;
//notify = true;
notify = (MPU != -1);
} else if ((MPU > SPECIFIC_VALUE) && !NOTIFIED_HIGH) {
notificationTitle = BitCoinApp.getAppContext().getString(R.string.morePrice);
notificationTextLong = BitCoinApp.getAppContext().getString(R.string.morePriceX) + SPECIFIC_VALUE + ". " + BitCoinApp.getAppContext().getString(R.string.actualCost) + MPU;
notificationText = BitCoinApp.getAppContext().getString(R.string.morePriceX) + SPECIFIC_VALUE;
NOTIFIED_HIGH = true;
NOTIFIED_LOW = false;
notify = true;
//notify = true;
notify = (MPU != -1);
}
if (notify) {
Log.d(Constants.LOG.NTAG, Constants.LOG.NOTIFYING);
Expand Down Expand Up @@ -130,8 +132,8 @@ private static float initMPU() {
market.execute("https://api.blockchain.info/stats");
try {
return MainActivity.round((float) market.get().getDouble("market_price_usd"), 2);
} catch (InterruptedException | ExecutionException | JSONException e) {
return 0;
} catch (InterruptedException | ExecutionException | JSONException | NullPointerException e) {
return -1;
}
}

Expand Down
27 changes: 23 additions & 4 deletions app/src/main/java/javinator9889/bitcoinpools/BitCoinApp.java
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

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

if (!(SHARED_PREFERENCES.getBoolean(Constants.SHARED_PREFERENCES.CACHE_JOB, false)) || isCacheCreated) {
JobScheduler cacheJobScheduler = (JobScheduler) APPLICATION_CONTEXT.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (isJobCreationNeeded(mJobScheduler)) {
//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()));


Expand All @@ -84,8 +85,8 @@ private static void startBackgroundJobs() {
cacheBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
cacheBuilder.setBackoffCriteria(Constants.BACKOFF_CRITERIA, JobInfo.BACKOFF_POLICY_LINEAR);

assert cacheJobScheduler != null;
if (cacheJobScheduler.schedule(cacheBuilder.build()) == JobScheduler.RESULT_FAILURE) {
//assert cacheJobScheduler != null;
if (mJobScheduler.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();
Expand Down Expand Up @@ -134,4 +135,22 @@ public static String appVersion() {
return "1.0";
}
}

public static boolean isJobCreationNeeded(JobScheduler applicationJobScheduler) {
//SHARED_PREFERENCES.getBoolean(Constants.SHARED_PREFERENCES.CACHE_JOB, false);
if (SHARED_PREFERENCES.contains(Constants.SHARED_PREFERENCES.CACHE_JOB)) {
List<JobInfo> pendingJobs = applicationJobScheduler.getAllPendingJobs();
Iterator<JobInfo> currentPendingJob = pendingJobs.iterator();
boolean equals = false;
while (currentPendingJob.hasNext() && !equals) {
equals = currentPendingJob.next().toString().equals("job:2/javinator9889.bitcoinpools/.BackgroundJobs.CacheJobSchedulerService");
}
return !equals;
} else {
SharedPreferences.Editor newEntry = SHARED_PREFERENCES.edit();
newEntry.putBoolean(Constants.SHARED_PREFERENCES.CACHE_JOB, false);
newEntry.apply();
return true;
}
}
}
Expand Up @@ -20,6 +20,7 @@ public static class PAYMENTS {
"ntpsync.donation.13"};
public static final String PAYPALME = "https://paypal.me/Javinator9889";
}
public static final String GOOGLE_PLAY_URL = "https://play.google.com/store/apps/details?id=javinator9889.bitcoinpools";
public static final String API_URL = "https://api.coindesk.com/v1/bpi/historical/close.json";
public static final class SHARED_PREFERENCES {
public static final String SHARED_PREFERENCES_KEY = "javinator9889.bitcoinpools.usrPreferences";
Expand Down
Expand Up @@ -104,6 +104,7 @@ protected void onPostExecute(Boolean result) {
activityMainIntent.putExtra("CARDS", cardsData);
activityMainIntent.putExtra("BTCPRICE", btcPrice);
startActivity(activityMainIntent);
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
//DataLoaderScreen.this.finish();
} else {
Log.i("DLS", "Data non-loaded...");
Expand Down
Expand Up @@ -57,6 +57,12 @@ public void onClick(View v) {
});
}

@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/javinator9889/bitcoinpools/License.java
Expand Up @@ -21,6 +21,12 @@
*/

public class License extends AppCompatActivity {
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/javinator9889/bitcoinpools/MainActivity.java
Expand Up @@ -139,7 +139,11 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d(Constants.LOG.MATAG, Constants.LOG.CREATING_CHART);

Log.d(Constants.LOG.MATAG, Constants.LOG.LISTENING);
ck.checkForUpdates(this, getString(R.string.updateAvailable), getString(R.string.updateDescrip), getString(R.string.updateNow), getString(R.string.updateLater), getString(R.string.updatePage));
try {
ck.checkForUpdates(this, getString(R.string.updateAvailable), getString(R.string.updateDescrip), getString(R.string.updateNow), getString(R.string.updateLater), getString(R.string.updatePage));
} catch (NullPointerException e) {
Log.e(Constants.LOG.MATAG, "Unable to get updates");
}
//DataLoaderScreen.progressDialog.setProgress(DataLoaderScreen.progressDialog.getCurrentProgress() + 10);
/*} else {
new MaterialDialog.Builder(this)
Expand Down Expand Up @@ -190,6 +194,11 @@ protected void onResume() {
//DataLoaderScreen.progressDialog.dismiss();
}

@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down Expand Up @@ -224,6 +233,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void run() {
Intent intentSettings = new Intent(MainActivity.this, SpinnerActivity.class);
startActivity(intentSettings);
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
//MainActivity.this.finish();
}
};
Expand All @@ -235,6 +245,7 @@ public void run() {
public void run() {
Intent intentLicense = new Intent(MainActivity.this, License.class);
startActivity(intentLicense);
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
}
};
licenseThread.setName("license_thread");
Expand All @@ -253,13 +264,14 @@ public void run() {
Intent shareAppIntent = new Intent(Intent.ACTION_SEND);
shareAppIntent.setType("text/plain");
shareAppIntent.putExtra(Intent.EXTRA_SUBJECT, "BitCoin Pools");
final Uri googlePlayLink = Uri.parse("https://play.google.com/store/apps/details?id=com.fastaccess.github");
final Uri googlePlayLink = Uri.parse(Constants.GOOGLE_PLAY_URL);
shareAppIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.inv_message) + " - Google Play Store: " + googlePlayLink.toString());
startActivity(Intent.createChooser(shareAppIntent, getString(R.string.invitation_title)));
break;
case R.id.donate:
Intent donateIntent = new Intent(MainActivity.this, DonationsActivity.class);
startActivity(donateIntent);
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
break;
}
return true;
Expand Down
Expand Up @@ -124,6 +124,7 @@ public void onBackPressed() {
}
//refresh();
super.onBackPressed();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}

private void refresh() {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/anim/accelerate_interpolator.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<accelerateInterpolator
xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="10" />
12 changes: 12 additions & 0 deletions app/src/main/res/anim/activity_back_in.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
<translate
android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="500" />

<!--<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="800" />-->
</set>
12 changes: 12 additions & 0 deletions app/src/main/res/anim/activity_back_out.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="500" />

<!--<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500" />-->
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/activity_in.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="200" />
<!--<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="800" />-->
</set>
12 changes: 12 additions & 0 deletions app/src/main/res/anim/activity_out.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="500" />

<!--<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500" />-->
</set>

0 comments on commit ff4e5c8

Please sign in to comment.