Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-03-21 10:35:51 +01:00
commit ed54ac5e91
5 changed files with 238 additions and 5 deletions

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/search"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/ctx_menu_info_view_bg"
xmlns:osmand="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="@dimen/dash_margin_h"
android:layout_marginRight="@dimen/dash_margin_h"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:background="?attr/bg_card">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginBottom="10dp">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginRight="24dp"
android:src="@drawable/ic_action_message"
android:tint="?attr/color_dialog_buttons"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/subscribe_email_desc"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"
android:layout_marginLeft="64dp"/>
<LinearLayout
android:id="@+id/subscribe_btn"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/subscribe_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osm_live_subscribe_btn"
android:layout_marginLeft="64dp"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
osmand:textAllCapsCompat="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="subscribe_email_error">Error</string>
<string name="subscribe_email_desc">Subscribe to our email list about app discounts and get 3 more map downloads!</string>
<string name="depth_contour_descr">Set of maps allows you to see sea depth contour lines.</string>
<string name="sea_depth_thanks">Thank you for purchasing sea depth contours!</string>
<string name="index_item_depth_contours_osmand_ext">Depth contours</string>

View file

@ -920,6 +920,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
public final OsmandPreference<Boolean> FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal();
public final OsmandPreference<Boolean> DEPTH_CONTOURS_PURCHASED = new BooleanPreference("billing_sea_depth_purchased", false).makeGlobal();
public final OsmandPreference<Boolean> EMAIL_SUBSCRIBED = new BooleanPreference("email_subscribed", false).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();

View file

@ -413,6 +413,10 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
downloadHasFinished();
}
public void updateBanner() {
visibleBanner.updateBannerInProgress();
}
private int getCurrentTab() {
return viewPager.getCurrentItem();
}
@ -427,7 +431,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
return Math.max(downloadsLeft, 0) > 0;
}
private static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
public static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !application.getSettings().FULL_VERSION_PURCHASED.get())
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();

View file

@ -1,10 +1,15 @@
package net.osmand.plus.download.ui;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.LayoutInflater;
@ -14,11 +19,14 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -31,13 +39,20 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppHelper;
import net.osmand.plus.inapp.InAppHelper.InAppListener;
import net.osmand.util.Algorithms;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents,
InAppListener, OnChildClickListener {
@ -55,6 +70,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
private Toolbar toolbar;
private View searchView;
private View restorePurchasesView;
private View subscribeEmailView;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -105,8 +121,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
banner = null;
view.findViewById(R.id.freeVersionBanner).setVisibility(View.GONE);
}
listView = (ExpandableListView) view.findViewById(android.R.id.list);
addSubscribeEmailRow();
addSearchRow();
addRestorePurchasesRow();
listView.setOnChildClickListener(this);
@ -116,6 +132,25 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
return view;
}
private void addSubscribeEmailRow() {
if (DownloadActivity.shouldShowFreeVersionBanner(activity.getMyApplication())
&& !getMyApplication().getSettings().EMAIL_SUBSCRIBED.get()) {
subscribeEmailView = activity.getLayoutInflater().inflate(R.layout.subscribe_email_header, null, false);
subscribeEmailView.findViewById(R.id.subscribe_btn).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
subscribe();
}
});
listView.addHeaderView(subscribeEmailView);
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem == null || !worldBaseMapItem.isDownloaded()
|| DownloadActivity.isDownlodingPermitted(activity.getMyApplication().getSettings())) {
subscribeEmailView.findViewById(R.id.container).setVisibility(View.GONE);
}
}
}
private void addRestorePurchasesRow() {
if (!openAsDialog() && !InAppHelper.isInAppIntentoryRead()) {
restorePurchasesView = activity.getLayoutInflater().inflate(R.layout.restore_purchases_list_footer, null);
@ -177,6 +212,116 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
}
}
private void updateSubscribeEmailView() {
if (subscribeEmailView != null && subscribeEmailView.findViewById(R.id.container).getVisibility() == View.GONE
&& !DownloadActivity.isDownlodingPermitted(getMyApplication().getSettings())
&& !getMyApplication().getSettings().EMAIL_SUBSCRIBED.get()) {
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem != null && worldBaseMapItem.isDownloaded()) {
subscribeEmailView.findViewById(R.id.container).setVisibility(View.VISIBLE);
}
}
}
private void hideSubscribeEmailView() {
if (subscribeEmailView != null && subscribeEmailView.findViewById(R.id.container).getVisibility() == View.VISIBLE) {
subscribeEmailView.findViewById(R.id.container).setVisibility(View.GONE);
}
}
private void subscribe() {
AlertDialog.Builder b = new AlertDialog.Builder(activity);
b.setTitle(R.string.shared_string_email_address);
final EditText editText = new EditText(activity);
int leftPadding = AndroidUtils.dpToPx(activity, 24f);
int topPadding = AndroidUtils.dpToPx(activity, 4f);
b.setView(editText, leftPadding, topPadding, leftPadding, topPadding);
b.setPositiveButton(R.string.shared_string_ok, null);
b.setNegativeButton(R.string.shared_string_cancel, null);
final AlertDialog alertDialog = b.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = editText.getText().toString();
if (Algorithms.isEmpty(email) || !AndroidUtils.isValidEmail(email)) {
getMyApplication().showToastMessage(getString(R.string.osm_live_enter_email));
return;
}
doSubscribe(email);
alertDialog.dismiss();
}
});
}
});
alertDialog.show();
}
private void doSubscribe(final String email) {
new AsyncTask<Void, Void, String>() {
ProgressDialog dlg;
@Override
protected void onPreExecute() {
dlg = new ProgressDialog(getActivity());
dlg.setTitle("");
dlg.setMessage(getString(R.string.wait_current_task_finished));
dlg.setCancelable(false);
dlg.show();
}
@Override
protected String doInBackground(Void... params) {
try {
Map<String, String> parameters = new HashMap<>();
parameters.put("aid", Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID));
parameters.put("email", email);
return AndroidNetworkUtils.sendRequest(getMyApplication(),
"http://download.osmand.net/subscription/register_email.php",
parameters, "Subscribing email...", true, true);
} catch (Exception e) {
return null;
}
}
@Override
protected void onPostExecute(String response) {
if (dlg != null) {
dlg.dismiss();
dlg = null;
}
OsmandApplication app = getMyApplication();
if (response == null) {
app.showShortToastMessage(activity.getString(R.string.shared_string_unexpected_error));
} else {
try {
JSONObject obj = new JSONObject(response);
String responseEmail = obj.getString("email");
if (!email.equalsIgnoreCase(responseEmail)) {
app.showShortToastMessage(activity.getString(R.string.shared_string_unexpected_error));
} else {
app.getSettings().NUMBER_OF_FREE_DOWNLOADS.set(DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3);
app.getSettings().EMAIL_SUBSCRIBED.set(true);
hideSubscribeEmailView();
activity.updateBanner();
}
} catch (JSONException e) {
String message = "JSON parsing error: "
+ (e.getMessage() == null ? "unknown" : e.getMessage());
app.showShortToastMessage(MessageFormat.format(
activity.getString(R.string.error_message_pattern), message));
}
}
}
}.execute((Void) null);
}
@Override
public void onError(String error) {
}
@ -233,6 +378,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
if (!openAsDialog()) {
updateSearchView();
}
updateSubscribeEmailView();
DownloadResources indexes = activity.getDownloadThread().getIndexes();
group = indexes.getGroupById(groupId);
if (group != null) {
@ -258,7 +404,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
@Override
public void newDownloadIndexes() {
if(banner != null) {
if (banner != null) {
banner.updateBannerInProgress();
}
reloadData();
@ -266,15 +412,20 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
@Override
public void downloadHasFinished() {
if(banner != null) {
if (banner != null) {
banner.updateBannerInProgress();
}
if (subscribeEmailView != null
&& !DownloadActivity.isDownlodingPermitted(activity.getMyApplication().getSettings())
&& !getMyApplication().getSettings().EMAIL_SUBSCRIBED.get()) {
subscribeEmailView.findViewById(R.id.container).setVisibility(View.VISIBLE);
}
listAdapter.notifyDataSetChanged();
}
@Override
public void downloadInProgress() {
if(banner != null) {
if (banner != null) {
banner.updateBannerInProgress();
}
listAdapter.notifyDataSetChanged();