Merge pull request #4409 from osmandapp/osm_live_fix

Osm live fix
This commit is contained in:
vshcherb 2017-09-06 12:51:35 +02:00 committed by GitHub
commit 20c2dd9d54
2 changed files with 55 additions and 5 deletions

View file

@ -365,20 +365,24 @@
<style name="Widget.Styled.ActionBarLight" parent="Widget.AppCompat.Light.ActionBar.Solid"> <style name="Widget.Styled.ActionBarLight" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">@color/actionbar_light_color</item> <item name="background">@color/actionbar_light_color</item>
<item name="android:background">@color/actionbar_light_color</item> <item name="android:background">@color/actionbar_light_color</item>
<item name="titleTextStyle">@style/Widget.Styled.LightActionBarHeader</item> <item name="titleTextStyle">@style/Widget.Styled.LightActionBarTitle</item>
<item name="subtitleTextStyle">@style/Widget.Styled.LightActionBarHeader</item> <item name="subtitleTextStyle">@style/Widget.Styled.LightActionBarSubtitle</item>
<item name="actionBarWidgetTheme">@style/Theme.AppCompat</item> <item name="actionBarWidgetTheme">@style/Theme.AppCompat</item>
<item name="android:titleTextStyle">@style/Widget.Styled.LightActionBarHeader</item> <item name="android:titleTextStyle">@style/Widget.Styled.LightActionBarTitle</item>
<item name="android:subtitleTextStyle">@style/Widget.Styled.LightActionBarHeader</item> <item name="android:subtitleTextStyle">@style/Widget.Styled.LightActionBarSubtitle</item>
<item name="android:actionBarWidgetTheme">@style/Theme.AppCompat</item> <item name="android:actionBarWidgetTheme">@style/Theme.AppCompat</item>
<item name="elevation">0dp</item> <item name="elevation">0dp</item>
</style> </style>
<style name="Widget.Styled.LightActionBarHeader" parent="@android:style/TextAppearance"> <style name="Widget.Styled.LightActionBarTitle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/color_white</item> <item name="android:textColor">@color/color_white</item>
</style> </style>
<style name="Widget.Styled.LightActionBarSubtitle" parent="TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
<item name="android:textColor">@color/white_80_transparent</item>
</style>
<style name="WhiteActionMode" parent="@style/Widget.AppCompat.ActionMode"> <style name="WhiteActionMode" parent="@style/Widget.AppCompat.ActionMode">
<item name="titleTextStyle">@style/WhiteActionModeTitleTextStyle</item> <item name="titleTextStyle">@style/WhiteActionModeTitleTextStyle</item>
<item name="android:titleTextStyle">@style/WhiteActionModeTitleTextStyle</item> <item name="android:titleTextStyle">@style/WhiteActionModeTitleTextStyle</item>

View file

@ -2,14 +2,17 @@ package net.osmand.plus.liveupdates;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.MenuItem; import android.view.MenuItem;
import net.osmand.AndroidNetworkUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
@ -19,12 +22,19 @@ import net.osmand.plus.inapp.InAppHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class OsmLiveActivity extends AbstractDownloadActivity implements DownloadIndexesThread.DownloadEvents { public class OsmLiveActivity extends AbstractDownloadActivity implements DownloadIndexesThread.DownloadEvents {
private final static Log LOG = PlatformUtil.getLog(OsmLiveActivity.class); private final static Log LOG = PlatformUtil.getLog(OsmLiveActivity.class);
public final static String OPEN_SUBSCRIPTION_INTENT_PARAM = "open_subscription_intent_param"; public final static String OPEN_SUBSCRIPTION_INTENT_PARAM = "open_subscription_intent_param";
private LiveUpdatesFragmentPagerAdapter pagerAdapter; private LiveUpdatesFragmentPagerAdapter pagerAdapter;
private InAppHelper inAppHelper; private InAppHelper inAppHelper;
private boolean openSubscription; private boolean openSubscription;
private static final String URL = "https://osmand.net/api/osmlive_status";
public InAppHelper getInAppHelper() { public InAppHelper getInAppHelper() {
return inAppHelper; return inAppHelper;
@ -43,6 +53,42 @@ 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);