Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-01-29 19:14:09 +01:00
commit 5689d7b38b
16 changed files with 467 additions and 373 deletions

View file

@ -43,6 +43,7 @@
<string name="osm_live_thanks">Thank you for subscribing to live updates!</string>
<string name="osm_live_region_desc">Part your donation will be sent to OSM users who submit changes to the map in that region</string>
<string name="osm_live_subscription_settings">Subscription settings</string>
<string name="osm_live_ask_for_purchase">Please purchase OSM Live subscription first</string>
<string name="osm_live_header">This subscription enables hourly updates for all maps around the world.
Major part of the income goes back to OSM community and is paid out per each OSM contribution.

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottomShadowView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topShadowView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

View file

@ -1,13 +1,30 @@
<ExpandableListView
android:id="@android:id/list"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:footerDividersEnabled="false"
android:groupIndicator="@null"
android:headerDividersEnabled="false"
android:orientation="vertical"
android:drawSelectorOnTop="true"
tools:context=".liveupdates.LiveUpdatesFragment"/>
android:layout_height="match_parent">
<ExpandableListView
android:id="@android:id/list"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:drawSelectorOnTop="true"
android:footerDividersEnabled="false"
android:groupIndicator="@null"
android:headerDividersEnabled="false"
android:orientation="vertical"
tools:context=".liveupdates.LiveUpdatesFragment"/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="top"
android:indeterminate="true"
android:padding="0dp"
android:visibility="invisible"/>
</FrameLayout>

View file

@ -6,7 +6,7 @@
android:orientation="vertical"
tools:context="net.osmand.plus.liveupdates.ReportsFragment">
<include layout="@layout/shadow_top"/>
<include layout="@layout/card_top_divider"/>
<FrameLayout
android:layout_width="match_parent"
@ -145,6 +145,6 @@
tools:progress="50"/>
</FrameLayout>
<include layout="@layout/shadow_bottom"/>
<include layout="@layout/card_bottom_divider"/>
</LinearLayout>

View file

@ -23,19 +23,25 @@
android:id="@+id/searchEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:background="@null"
android:gravity="center_vertical"
android:lines="1"
android:background="@null"
android:layout_marginLeft="16dp"
tools:text="Search request"/>
</LinearLayout>
<include layout="@layout/shadow_bottom"/>
<ListView
android:id="@android:id/list"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
android:layout_height="match_parent">
<include layout="@layout/card_bottom_divider"/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"/>
</FrameLayout>
</LinearLayout>

View file

@ -6,14 +6,14 @@
android:layout_height="64dp"
android:orientation="vertical">
<include layout="@layout/shadow_bottom"/>
<include layout="@layout/card_bottom_divider"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<include layout="@layout/shadow_top"/>
<include layout="@layout/card_top_divider"/>
<LinearLayout
android:layout_width="match_parent"
@ -41,9 +41,4 @@
tools:visibility="visible"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
</LinearLayout>

View file

@ -7,7 +7,7 @@
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
android:paddingTop="16dp">
<LinearLayout
android:id="@+id/subscription_banner"
@ -176,32 +176,6 @@
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/subscribeButtonRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:minHeight="48dp">
<Button
android:id="@+id/subscribeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="6dp"
android:background="?attr/selectableItemBackground"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/osm_live_subscribe_btn"
android:textColor="?attr/color_dialog_buttons"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomShadowView"
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/bg_shadow_list_bottom"
tools:showIn="@layout/list_group_title_with_switch"/>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/bg_shadow_list_top"
tools:showIn="@layout/list_group_title_with_switch"/>

View file

@ -33,53 +33,15 @@
</LinearLayout>
<include layout="@layout/shadow_bottom"/>
<ScrollView
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
<include layout="@layout/card_bottom_divider"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="56dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/emailIcon"
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_action_message"/>
<EditText
android:id="@+id/emailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:paddingLeft="2dp"
android:hint="@string/shared_string_email_address"
android:inputType="textEmailAddress"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="2dp"
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:text="@string/osm_live_email_desc"
android:textColor="?android:attr/textColorSecondary"/>
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
@ -93,188 +55,232 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/userNameIcon"
android:id="@+id/emailIcon"
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_person"/>
android:src="@drawable/ic_action_message"/>
<EditText
android:id="@+id/userNameEdit"
android:id="@+id/emailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:paddingLeft="2dp"
android:hint="@string/osm_live_user_public_name"
android:inputType="text"/>
android:hint="@string/shared_string_email_address"
android:inputType="textEmailAddress"
android:paddingLeft="2dp"/>
</LinearLayout>
<CheckBox
android:id="@+id/hideUserNameCheckbox"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:paddingLeft="2dp"
android:text="@string/osm_live_hide_user_name"
android:textColor="?android:attr/textColorPrimary"/>
android:text="@string/osm_live_email_desc"
android:textColor="?android:attr/textColorSecondary"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp"
android:minHeight="56dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/countryIcon"
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_world_globe_dark"/>
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:minHeight="56dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/userNameIcon"
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_person"/>
<EditText
android:id="@+id/userNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="@string/osm_live_user_public_name"
android:inputType="text"
android:paddingLeft="2dp"/>
</LinearLayout>
<CheckBox
android:id="@+id/hideUserNameCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:orientation="vertical">
android:paddingLeft="2dp"
android:text="@string/osm_live_hide_user_name"
android:textColor="?android:attr/textColorPrimary"/>
<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="4dp"
android:minHeight="56dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/countryIcon"
android:layout_width="56dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_world_globe_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:textColor="?android:attr/textColorSecondary"
android:text="@string/osm_live_support_region"/>
<net.osmand.plus.widgets.AutoCompleteTextViewEx
android:id="@+id/selectCountryEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:paddingRight="0dp"
android:drawableRight="@drawable/ic_action_arrow_drop_down"
android:editable="false"
android:text="Ukraine"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:textColor="?android:attr/textColorSecondary"
android:text="@string/osm_live_region_desc"/>
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:text="@string/osm_live_support_region"
android:textColor="?android:attr/textColorSecondary"/>
<net.osmand.plus.widgets.AutoCompleteTextViewEx
android:id="@+id/selectCountryEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_arrow_drop_down"
android:editable="false"
android:paddingLeft="2dp"
android:paddingRight="0dp"
android:text="Ukraine"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingLeft="2dp"
android:text="@string/osm_live_region_desc"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/editModeBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:visibility="gone">
<Button
android:id="@+id/saveChangesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/color_white"
android:background="@drawable/btn_round_blue"
android:text="@string/shared_string_save_changes"/>
</LinearLayout>
<LinearLayout
android:id="@+id/purchaseCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="?attr/bg_card"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:id="@+id/editModeBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:visibility="gone">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/osm_live_month_cost"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/priceTextView"
<Button
android:id="@+id/saveChangesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:gravity="right"
android:text="@string/osm_live_default_price"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:background="@drawable/btn_round_blue"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/shared_string_save_changes"
android:textColor="@color/color_white"/>
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
<LinearLayout
android:id="@+id/purchaseCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/osm_live_month_cost_desc"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
android:layout_margin="8dp"
android:background="?attr/bg_card"
android:orientation="vertical"
android:visibility="visible">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:background="?attr/divider_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<Button
android:id="@+id/subscribeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="6dp"
android:background="?attr/selectableItemBackground"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/osm_live_subscribe_btn"
android:textColor="?attr/color_dialog_buttons"/>
<net.osmand.plus.widgets.TextViewEx
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/osm_live_month_cost"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/priceTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:gravity="right"
android:text="@string/osm_live_default_price"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/osm_live_month_cost_desc"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:background="?attr/divider_color"/>
<Button
android:id="@+id/subscribeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="6dp"
android:background="?attr/selectableItemBackground"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/osm_live_subscribe_btn"
android:textColor="?attr/color_dialog_buttons"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>
</FrameLayout>
</LinearLayout>

View file

@ -41,7 +41,6 @@ import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppHelper;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
@ -134,12 +133,6 @@ public class OsmandApplication extends MultiDexApplication {
// targetPointsHelper.clearPointToNavigate(false);
// }
//Check inapps
if (osmandSettings.isInternetConnectionAvailable()) {
InAppHelper inAppHelper = new InAppHelper(this, null);
inAppHelper.start(true);
}
startApplication();
System.out.println("Time to start application " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms");
timeToStart = System.currentTimeMillis();

View file

@ -32,11 +32,13 @@ public class InAppHelper {
private static boolean mSubscribedToLiveUpdates = false;
private static String mLiveUpdatesPrice;
private static long lastValidationCheckTime;
private static final String SKU_LIVE_UPDATES_FULL = "osm_live_subscription_2";
private static final String SKU_LIVE_UPDATES_FREE = "osm_free_live_subscription_2";
private static String SKU_LIVE_UPDATES;
private static final long PURCHASE_VALIDATION_PERIOD_MSEC = 1000 * 60 * 60 * 24; // daily
// (arbitrary) request code for the purchase flow
private static final int RC_REQUEST = 10001;
@ -45,9 +47,9 @@ public class InAppHelper {
private boolean stopAfterResult = false;
private OsmandApplication ctx;
private InAppCallbacks callbacks;
private List<InAppListener> listeners = new ArrayList<>();
public interface InAppCallbacks {
public interface InAppListener {
void onError(String error);
void onGetItems();
@ -71,9 +73,8 @@ public class InAppHelper {
return SKU_LIVE_UPDATES;
}
public InAppHelper(OsmandApplication ctx, InAppCallbacks callbacks) {
public InAppHelper(OsmandApplication ctx) {
this.ctx = ctx;
this.callbacks = callbacks;
if (SKU_LIVE_UPDATES == null) {
if (Version.isFreeVersion(ctx)) {
SKU_LIVE_UPDATES = SKU_LIVE_UPDATES_FREE;
@ -81,6 +82,10 @@ public class InAppHelper {
SKU_LIVE_UPDATES = SKU_LIVE_UPDATES_FULL;
}
}
if (Version.isDeveloperVersion(ctx)) {
mSubscribedToLiveUpdates = true;
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
}
public void start(final boolean stopAfterResult) {
@ -120,9 +125,7 @@ public class InAppHelper {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
complain("Problem setting up in-app billing: " + result);
if (callbacks != null) {
callbacks.onError(result.getMessage());
}
notifyError(result.getMessage());
if (stopAfterResult) {
stop();
}
@ -132,11 +135,16 @@ public class InAppHelper {
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// IAB is fully set up. Now, let's get an inventory of stuff we own.
logDebug("Setup successful. Querying inventory.");
List<String> skus = new ArrayList<>();
skus.add(SKU_LIVE_UPDATES);
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
// IAB is fully set up. Now, let's get an inventory of stuff we own if needed.
if (!mSubscribedToLiveUpdates
|| !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get()
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC) {
logDebug("Setup successful. Querying inventory.");
List<String> skus = new ArrayList<>();
skus.add(SKU_LIVE_UPDATES);
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
}
}
});
}
@ -152,9 +160,7 @@ public class InAppHelper {
// Is it a failure?
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
if (callbacks != null) {
callbacks.onError(result.getMessage());
}
notifyError(result.getMessage());
if (stopAfterResult) {
stop();
}
@ -171,10 +177,11 @@ public class InAppHelper {
// Do we have the live updates?
Purchase liveUpdatesPurchase = inventory.getPurchase(SKU_LIVE_UPDATES);
mSubscribedToLiveUpdates = (liveUpdatesPurchase != null);
mSubscribedToLiveUpdates = (liveUpdatesPurchase != null) || Version.isDeveloperVersion(ctx);
if (mSubscribedToLiveUpdates) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
lastValidationCheckTime = System.currentTimeMillis();
logDebug("User " + (mSubscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
+ " live updates purchased.");
@ -187,10 +194,8 @@ public class InAppHelper {
sendToken(liveUpdatesPurchase.getToken());
}
if (callbacks != null) {
callbacks.dismissProgress();
callbacks.onGetItems();
}
notifyDismissProgress();
notifyGetItems();
if (stopAfterResult) {
stop();
}
@ -203,18 +208,14 @@ public class InAppHelper {
final String countryDownloadName, final boolean hideUserName) {
if (!mHelper.subscriptionsSupported()) {
complain("Subscriptions not supported on your device yet. Sorry!");
if (callbacks != null) {
callbacks.onError("Subscriptions not supported on your device yet. Sorry!");
}
notifyError("Subscriptions not supported on your device yet. Sorry!");
if (stopAfterResult) {
stop();
}
return;
}
if (callbacks != null) {
callbacks.showProgress();
}
notifyShowProgress();
new AsyncTask<Void, Void, String>() {
@ -247,10 +248,8 @@ public class InAppHelper {
logDebug("Response=" + response);
if (response == null) {
complain("Cannot retrieve userId from server.");
if (callbacks != null) {
callbacks.dismissProgress();
callbacks.onError("Cannot retrieve userId from server.");
}
notifyDismissProgress();
notifyError("Cannot retrieve userId from server.");
if (stopAfterResult) {
stop();
}
@ -266,19 +265,15 @@ public class InAppHelper {
String message = "JSON parsing error: "
+ (e.getMessage() == null ? "unknown" : e.getMessage());
complain(message);
if (callbacks != null) {
callbacks.dismissProgress();
callbacks.onError(message);
}
notifyDismissProgress();
notifyError(message);
if (stopAfterResult) {
stop();
}
}
}
if (callbacks != null) {
callbacks.dismissProgress();
}
notifyDismissProgress();
if (!Algorithms.isEmpty(userId)) {
logDebug("Launching purchase flow for live updates subscription for userId=" + userId);
String payload = userId;
@ -288,9 +283,7 @@ public class InAppHelper {
RC_REQUEST, mPurchaseFinishedListener, payload);
}
} else {
if (callbacks != null) {
callbacks.onError("Empty userId");
}
notifyError("Empty userId");
if (stopAfterResult) {
stop();
}
@ -331,10 +324,8 @@ public class InAppHelper {
if (result.isFailure()) {
complain("Error purchasing: " + result);
if (callbacks != null) {
callbacks.dismissProgress();
callbacks.onError("Error purchasing: " + result);
}
notifyDismissProgress();
notifyError("Error purchasing: " + result);
if (stopAfterResult) {
stop();
}
@ -352,10 +343,8 @@ public class InAppHelper {
mSubscribedToLiveUpdates = true;
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
if (callbacks != null) {
callbacks.dismissProgress();
callbacks.onItemPurchased(SKU_LIVE_UPDATES);
}
notifyDismissProgress();
notifyItemPurchased(SKU_LIVE_UPDATES);
if (stopAfterResult) {
stop();
}
@ -407,6 +396,44 @@ public class InAppHelper {
}
}
private void notifyError(String message) {
for (InAppListener l : listeners) {
l.onError(message);
}
}
private void notifyGetItems() {
for (InAppListener l : listeners) {
l.onGetItems();
}
}
private void notifyItemPurchased(String sku) {
for (InAppListener l : listeners) {
l.onItemPurchased(sku);
}
}
private void notifyShowProgress() {
for (InAppListener l : listeners) {
l.showProgress();
}
}
private void notifyDismissProgress() {
for (InAppListener l : listeners) {
l.dismissProgress();
}
}
public void addListener(InAppListener listener) {
this.listeners.add(listener);
}
public void removeListener(InAppListener listener) {
this.listeners.remove(listener);
}
private void complain(String message) {
logError("**** InAppHelper Error: " + message);
showToast("Error: " + message);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.liveupdates;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
@ -28,6 +29,7 @@ import android.widget.CompoundButton;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.map.WorldRegion;
@ -40,6 +42,7 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.inapp.InAppHelper;
import net.osmand.plus.inapp.InAppHelper.InAppListener;
import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.util.Algorithms;
@ -63,7 +66,7 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceTimeOfDayT
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent;
public class LiveUpdatesFragment extends BaseOsmAndFragment {
public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppListener {
public static final String TITLE = "Live Updates";
private static final int SUBSCRIPTION_SETTINGS = 5;
public static final Comparator<LocalIndexInfo> LOCAL_INDEX_INFO_COMPARATOR = new Comparator<LocalIndexInfo>() {
@ -77,10 +80,30 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
private LocalIndexesAdapter adapter;
private AsyncTask<Void, LocalIndexInfo, List<LocalIndexInfo>> loadLocalIndexesTask;
private ProgressBar progressBar;
private boolean processing;
public InAppHelper getInAppHelper() {
Activity activity = getActivity();
if (activity instanceof OsmLiveActivity) {
return ((OsmLiveActivity) activity).getInAppHelper();
} else {
return null;
}
}
private boolean isProcessing() {
return processing;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
InAppHelper helper = getInAppHelper();
if (helper != null) {
helper.addListener(this);
}
}
@Override
@ -89,7 +112,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
View view = inflater.inflate(R.layout.fragment_live_updates, container, false);
listView = (ExpandableListView) view.findViewById(android.R.id.list);
View bottomShadowView = inflater.inflate(R.layout.shadow_bottom, listView, false);
View bottomShadowView = inflater.inflate(R.layout.card_bottom_divider, listView, false);
listView.addFooterView(bottomShadowView);
adapter = new LocalIndexesAdapter(this);
listView.setAdapter(adapter);
@ -104,6 +127,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
}
});
progressBar = (ProgressBar) view.findViewById(R.id.progress);
//test
//getSettings().LIVE_UPDATES_PURCHASED.set(true);
@ -123,43 +148,21 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
ImageView statusIcon = (ImageView) subscriptionHeader.findViewById(R.id.statusIcon);
TextView statusTextView = (TextView) subscriptionHeader.findViewById(R.id.statusTextView);
TextView regionNameTextView = (TextView) subscriptionHeader.findViewById(R.id.regionTextView);
statusTextView.setText(getString(R.string.osm_live_active));
statusIcon.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_done));
if (InAppHelper.isSubscribedToLiveUpdates()) {
statusTextView.setText(getString(R.string.osm_live_active));
statusIcon.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_done));
} else {
statusTextView.setText(getString(R.string.osm_live_not_active));
statusIcon.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark));
}
OsmandSettings settings = getMyApplication().getSettings();
String countryName = settings.BILLING_USER_COUNTRY.get();
String countryName = getSettings().BILLING_USER_COUNTRY.get();
if (Algorithms.isEmpty(countryName)) {
WorldRegion world = getMyApplication().getRegions().getWorldRegion();
countryName = world.getLocaleName();
}
regionNameTextView.setText(countryName);
View subscribeButtonRow = subscriptionHeader.findViewById(R.id.subscribeButtonRow);
if (InAppHelper.isSubscribedToLiveUpdates()) {
subscribeButtonRow.setVisibility(View.GONE);
} else {
subscribeButtonRow.setVisibility(View.VISIBLE);
Button subscribeButton = (Button) subscriptionHeader.findViewById(R.id.subscribeButton);
subscribeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG);
}
});
}
subscriptionBanner.setVisibility(View.GONE);
subscriptionInfo.setVisibility(View.VISIBLE);
} else {
Button readMoreBtn = (Button) subscriptionHeader.findViewById(R.id.read_more_button);
readMoreBtn.setEnabled(!processing);
readMoreBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -169,6 +172,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
}
});
Button subscriptionButton = (Button) subscriptionHeader.findViewById(R.id.subscription_button);
subscriptionButton.setEnabled(!processing);
subscriptionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -182,12 +186,31 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
}
}
@Override
public void onResume() {
super.onResume();
InAppHelper helper = getInAppHelper();
if (helper != null) {
enableProgress();
helper.start(false);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
loadLocalIndexesTask.cancel(true);
}
@Override
public void onDestroy() {
super.onDestroy();
InAppHelper helper = getInAppHelper();
if (helper != null) {
helper.removeListener(this);
}
}
public void notifyLiveUpdatesChanged() {
if (adapter != null) {
adapter.notifyLiveUpdatesChanged();
@ -321,7 +344,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
view.setOnClickListener(null);
SwitchCompat liveUpdatesSwitch = (SwitchCompat) view.findViewById(R.id.liveUpdatesSwitch);
final SwitchCompat liveUpdatesSwitch = (SwitchCompat) view.findViewById(R.id.liveUpdatesSwitch);
View topShadowView = view.findViewById(R.id.bottomShadowView);
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
topShadowView.setVisibility(View.GONE);
@ -329,26 +352,21 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
OsmandApplication application = (OsmandApplication) ctx.getApplicationContext();
final OsmandSettings settings = application.getSettings();
liveUpdatesSwitch.setChecked(settings.IS_LIVE_UPDATES_ON.get());
liveUpdatesSwitch.setEnabled(!processing);
liveUpdatesSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
settings.IS_LIVE_UPDATES_ON.set(isChecked);
AlarmManager alarmMgr = (AlarmManager) getActivity()
.getSystemService(Context.ALARM_SERVICE);
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
PendingIntent alarmIntent = getPendingIntent(getActivity(),
localIndexInfo);
if (isChecked) {
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(localIndexInfo, getSettings());
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(localIndexInfo, getSettings());
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
if (isChecked) {
if (InAppHelper.isSubscribedToLiveUpdates()) {
settings.IS_LIVE_UPDATES_ON.set(true);
enableLiveUpdates(true);
} else {
alarmMgr.cancel(alarmIntent);
liveUpdatesSwitch.setChecked(false);
getMyApplication().showToastMessage(getString(R.string.osm_live_ask_for_purchase));
}
} else {
settings.IS_LIVE_UPDATES_ON.set(false);
enableLiveUpdates(false);
}
}
});
@ -359,6 +377,26 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
return view;
}
private void enableLiveUpdates(boolean enable) {
AlarmManager alarmMgr = (AlarmManager) getActivity()
.getSystemService(Context.ALARM_SERVICE);
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
PendingIntent alarmIntent = getPendingIntent(getActivity(),
localIndexInfo);
if (enable) {
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(localIndexInfo, getSettings());
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(localIndexInfo, getSettings());
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
} else {
alarmMgr.cancel(alarmIntent);
}
}
}
@Override
public int getChildrenCount(int groupPosition) {
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
@ -487,6 +525,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
LiveUpdatesSettingsDialogFragment.createInstance(item).show(fragmentManager, "settings");
}
};
options.setEnabled(!fragment.isProcessing());
options.setOnClickListener(clickListener);
if (isLastChild) {
@ -547,7 +586,55 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment {
}
}
private void enableProgress() {
processing = true;
progressBar.setVisibility(View.VISIBLE);
updateSubscriptionHeader();
adapter.notifyDataSetChanged();
listView.setEnabled(false);
}
private void disableProgress() {
processing = false;
progressBar.setVisibility(View.INVISIBLE);
updateSubscriptionHeader();
adapter.notifyDataSetChanged();
listView.setEnabled(true);
}
public static float dpToPx(final Context context, final float dp) {
return dp * context.getResources().getDisplayMetrics().density;
}
@Override
public void onError(String error) {
disableProgress();
}
@Override
public void onGetItems() {
getSettings().LIVE_UPDATES_PURCHASED.set(InAppHelper.isSubscribedToLiveUpdates());
if (!InAppHelper.isSubscribedToLiveUpdates()) {
getSettings().IS_LIVE_UPDATES_ON.set(false);
adapter.enableLiveUpdates(false);
}
disableProgress();
}
@Override
public void onItemPurchased(String sku) {
if (InAppHelper.getSkuLiveUpdates().equals(sku)) {
updateSubscriptionHeader();
}
}
@Override
public void showProgress() {
enableProgress();
}
@Override
public void dismissProgress() {
disableProgress();
}
}

View file

@ -23,8 +23,8 @@ public class OsmLiveActivity extends AbstractDownloadActivity
private LiveUpdatesFragmentPagerAdapter pagerAdapter;
private InAppHelper inAppHelper;
public void setInAppHelper(InAppHelper inAppHelper) {
this.inAppHelper = inAppHelper;
public InAppHelper getInAppHelper() {
return inAppHelper;
}
@Override
@ -33,6 +33,8 @@ public class OsmLiveActivity extends AbstractDownloadActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_livie_updates);
inAppHelper = new InAppHelper(getMyApplication());
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
pagerAdapter = new LiveUpdatesFragmentPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
@ -64,6 +66,14 @@ public class OsmLiveActivity extends AbstractDownloadActivity
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (inAppHelper != null) {
inAppHelper.stop();
}
}
@Override
public void newDownloadIndexes() {

View file

@ -22,7 +22,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.inapp.InAppHelper;
import net.osmand.plus.inapp.InAppHelper.InAppCallbacks;
import net.osmand.plus.inapp.InAppHelper.InAppListener;
import net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem;
import net.osmand.plus.liveupdates.CountrySelectionFragment.OnFragmentInteractionListener;
import net.osmand.util.Algorithms;
@ -33,7 +33,7 @@ import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class SubscriptionFragment extends BaseOsmAndDialogFragment implements InAppCallbacks, OnFragmentInteractionListener {
public class SubscriptionFragment extends BaseOsmAndDialogFragment implements InAppListener, OnFragmentInteractionListener {
public static final String TAG = "SubscriptionFragment";
private static final String EDIT_MODE_ID = "edit_mode_id";
@ -42,7 +42,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
private static final String COUNTRY_ITEM_ID = "country_id";
private static final String HIDE_USER_NAME_ID = "hide_user_name_id";
private InAppHelper inAppHelper;
private OsmandSettings settings;
private ProgressDialog dlg;
private boolean editMode;
@ -56,6 +55,15 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
this.editMode = editMode;
}
public InAppHelper getInAppHelper() {
Activity activity = getActivity();
if (activity instanceof OsmLiveActivity) {
return ((OsmLiveActivity) activity).getInAppHelper();
} else {
return null;
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(EDIT_MODE_ID, editMode);
@ -86,20 +94,17 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
settings = getMyApplication().getSettings();
prevEmail = settings.BILLING_USER_EMAIL.get();
if (!editMode) {
inAppHelper = new InAppHelper(getMyApplication(), this);
Activity activity = getActivity();
if (activity instanceof OsmLiveActivity) {
((OsmLiveActivity) activity).setInAppHelper(inAppHelper);
}
inAppHelper.start(false);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
InAppHelper helper = getInAppHelper();
if (helper != null) {
helper.addListener(this);
}
String userName = settings.BILLING_USER_NAME.get();
String email = settings.BILLING_USER_EMAIL.get();
String countryDownloadName = settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get();
@ -253,11 +258,12 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
subscribeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (inAppHelper != null) {
InAppHelper helper = getInAppHelper();
if (helper != null) {
if (applySettings(userNameEdit.getText().toString().trim(),
emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
inAppHelper.purchaseLiveUpdates(getActivity(),
helper.purchaseLiveUpdates(getActivity(),
settings.BILLING_USER_EMAIL.get(),
settings.BILLING_USER_NAME.get(),
settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(),
@ -280,16 +286,13 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
@Override
public void onDestroy() {
super.onDestroy();
if (inAppHelper != null) {
inAppHelper.stop();
InAppHelper helper = getInAppHelper();
if (helper != null) {
helper.removeListener(this);
}
if (dlg != null && dlg.isShowing()) {
dlg.hide();
}
Activity activity = getActivity();
if (activity instanceof OsmLiveActivity) {
((OsmLiveActivity) activity).setInAppHelper(null);
}
}
private boolean applySettings(String userName, String email, boolean hideUserName) {
@ -325,14 +328,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
@Override
public void onItemPurchased(String sku) {
if (InAppHelper.getSkuLiveUpdates().equals(sku)) {
Fragment parentFragment = getParentFragment();
if (parentFragment instanceof LiveUpdatesFragment) {
((LiveUpdatesFragment) parentFragment).updateSubscriptionHeader();
}
}
dismiss();
}