parent
db8ef0341d
commit
92f43caae0
1 changed files with 39 additions and 36 deletions
|
@ -34,6 +34,7 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
private LiveUpdatesFragmentPagerAdapter pagerAdapter;
|
private LiveUpdatesFragmentPagerAdapter pagerAdapter;
|
||||||
private InAppHelper inAppHelper;
|
private InAppHelper inAppHelper;
|
||||||
private boolean openSubscription;
|
private boolean openSubscription;
|
||||||
|
private GetLastUpdateDateTask getLastUpdateDateTask;
|
||||||
private static final String URL = "https://osmand.net/api/osmlive_status";
|
private static final String URL = "https://osmand.net/api/osmlive_status";
|
||||||
|
|
||||||
public InAppHelper getInAppHelper() {
|
public InAppHelper getInAppHelper() {
|
||||||
|
@ -53,42 +54,6 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
inAppHelper = null;
|
inAppHelper = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
new AsyncTask<Void, Void, String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(Void... params) {
|
|
||||||
try {
|
|
||||||
return AndroidNetworkUtils.sendRequest(getMyApplication(), URL, null, "Requesting map updates info...", false, false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Error: " + "Requesting map updates info error", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String response) {
|
|
||||||
if (response != null) {
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
|
||||||
if (actionBar != null) {
|
|
||||||
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
|
||||||
source.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
SimpleDateFormat dest = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
|
||||||
dest.setTimeZone(TimeZone.getDefault());
|
|
||||||
try {
|
|
||||||
Date parsed = source.parse(response);
|
|
||||||
actionBar.setSubtitle(dest.format(parsed));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent != null && intent.getExtras() != null) {
|
if (intent != null && intent.getExtras() != null) {
|
||||||
openSubscription = intent.getExtras().getBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, false);
|
openSubscription = intent.getExtras().getBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, false);
|
||||||
|
@ -101,6 +66,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
||||||
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
|
getLastUpdateDateTask = new GetLastUpdateDateTask();
|
||||||
|
getLastUpdateDateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,6 +105,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
if (inAppHelper != null) {
|
if (inAppHelper != null) {
|
||||||
inAppHelper.stop();
|
inAppHelper.stop();
|
||||||
}
|
}
|
||||||
|
if (getLastUpdateDateTask != null) {
|
||||||
|
getLastUpdateDateTask.cancel(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -158,6 +129,38 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
return openSubscription;
|
return openSubscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class GetLastUpdateDateTask extends AsyncTask<Void, Void, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(Void... params) {
|
||||||
|
try {
|
||||||
|
return AndroidNetworkUtils.sendRequest(getMyApplication(), URL, null, "Requesting map updates info...", false, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Error: " + "Requesting map updates info error", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String response) {
|
||||||
|
if (response != null) {
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
source.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
SimpleDateFormat dest = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
dest.setTimeZone(TimeZone.getDefault());
|
||||||
|
try {
|
||||||
|
Date parsed = source.parse(response);
|
||||||
|
actionBar.setSubtitle(dest.format(parsed));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class LiveUpdatesFragmentPagerAdapter extends FragmentPagerAdapter {
|
public static class LiveUpdatesFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||||
private final Fragment[] fragments = new Fragment[] { new LiveUpdatesFragment(), new ReportsFragment() };
|
private final Fragment[] fragments = new Fragment[] { new LiveUpdatesFragment(), new ReportsFragment() };
|
||||||
private static final int[] titleIds = new int[] { LiveUpdatesFragment.TITLE, ReportsFragment.TITLE };
|
private static final int[] titleIds = new int[] { LiveUpdatesFragment.TITLE, ReportsFragment.TITLE };
|
||||||
|
|
Loading…
Reference in a new issue