Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
04a68a628e
4 changed files with 304 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/spinnerListBackground"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -33,6 +34,127 @@
|
|||
|
||||
<include layout="@layout/shadow_bottom"/>
|
||||
|
||||
<LinearLayout
|
||||
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/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="Visible name"
|
||||
android:inputType="text"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<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:hint="E-mail address"
|
||||
android:inputType="textEmailAddress"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="72dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="We need your email address to send you reports, information about money spending"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
||||
|
||||
<CheckBox
|
||||
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="12dp"
|
||||
android:text="Don't show my address in reports"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="56dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
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:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="Prefered country"
|
||||
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:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:hint="Select country"
|
||||
android:drawableRight="@drawable/ic_action_arrow_drop_down"
|
||||
android:editable="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -82,25 +204,25 @@
|
|||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="10dp"
|
||||
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:paddingRight="10dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_gravity="right"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:text="Subscribe"/>
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="Subscribe"
|
||||
android:textColor="?attr/color_dialog_buttons"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
@ -141,4 +142,7 @@ public class AndroidUtils {
|
|||
return dm.heightPixels;
|
||||
}
|
||||
|
||||
public static boolean isValidEmail(CharSequence target) {
|
||||
return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -812,6 +812,9 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<String> USER_NAME = new StringPreference("user_name", "NoName").makeGlobal();
|
||||
|
||||
public final OsmandPreference<String> BILLING_USER_ID = new StringPreference("billing_user_id", "").makeGlobal();
|
||||
public final OsmandPreference<String> BILLING_USER_NAME = new StringPreference("billing_user_name", "").makeGlobal();
|
||||
public final OsmandPreference<String> BILLING_USER_EMAIL = new StringPreference("billing_user_email", "").makeGlobal();
|
||||
public final OsmandPreference<String> BILLING_USER_COUNTRY = new StringPreference("billing_user_country", "").makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<String> USER_OSM_BUG_NAME =
|
||||
|
|
|
@ -2,30 +2,54 @@ package net.osmand.plus.liveupdates;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.map.WorldRegion;
|
||||
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.liveupdates.SearchSelectionFragment.OnFragmentInteractionListener;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class SubscriptionFragment extends BaseOsmAndDialogFragment implements InAppCallbacks {
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SubscriptionFragment extends BaseOsmAndDialogFragment implements InAppCallbacks, OnFragmentInteractionListener{
|
||||
|
||||
public static final String TAG = "SubscriptionFragment";
|
||||
|
||||
private InAppHelper inAppHelper;
|
||||
private OsmandSettings settings;
|
||||
private ProgressDialog dlg;
|
||||
|
||||
private String userName;
|
||||
private String email;
|
||||
private String country;
|
||||
|
||||
ArrayList<String> regionNames = new ArrayList<>();
|
||||
private CountrySearchSelectionFragment searchSelectionFragment
|
||||
= new CountrySearchSelectionFragment();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
settings = getMyApplication().getSettings();
|
||||
inAppHelper = new InAppHelper(getMyApplication(), this);
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof OsmLiveActivity) {
|
||||
|
@ -41,7 +65,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
|
||||
View view = inflater.inflate(R.layout.subscription_fragment, container, false);
|
||||
ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
|
||||
//setThemedDrawable(closeButton, R.drawable.ic_action_remove_dark);
|
||||
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -49,16 +72,72 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
}
|
||||
});
|
||||
|
||||
initCountries();
|
||||
|
||||
userName = settings.BILLING_USER_NAME.get();
|
||||
final EditText userNameEdit = (EditText) view.findViewById(R.id.userNameEdit);
|
||||
if (!Algorithms.isEmpty(userName)) {
|
||||
userNameEdit.setText(userName);
|
||||
}
|
||||
|
||||
email = settings.BILLING_USER_EMAIL.get();
|
||||
final EditText emailEdit = (EditText) view.findViewById(R.id.emailEdit);
|
||||
if (!Algorithms.isEmpty(email)) {
|
||||
emailEdit.setText(email);
|
||||
}
|
||||
|
||||
country = settings.BILLING_USER_COUNTRY.get();
|
||||
final EditText selectCountryEdit = (EditText) view.findViewById(R.id.selectCountryEdit);
|
||||
if (!Algorithms.isEmpty(country)) {
|
||||
selectCountryEdit.setText(country);
|
||||
}
|
||||
selectCountryEdit.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
SearchSelectionFragment countrySearchSelectionFragment =
|
||||
searchSelectionFragment;
|
||||
countrySearchSelectionFragment
|
||||
.show(getChildFragmentManager(), "CountriesSearchSelectionFragment");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
Button subscribeButton = (Button) view.findViewById(R.id.subscribeButton);
|
||||
subscribeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (inAppHelper != null) {
|
||||
inAppHelper.purchaseLiveUpdates(getActivity(), "1@1.1", "userName", "Ukraine");
|
||||
userName = userNameEdit.getText().toString().trim();
|
||||
email = emailEdit.getText().toString().trim();
|
||||
country = selectCountryEdit.getText().toString().trim();
|
||||
|
||||
if (Algorithms.isEmpty(userName)) {
|
||||
getMyApplication().showToastMessage("Please enter visible name");
|
||||
return;
|
||||
}
|
||||
if (Algorithms.isEmpty(email) || !AndroidUtils.isValidEmail(email)) {
|
||||
getMyApplication().showToastMessage("Please enter valid E-mail address");
|
||||
return;
|
||||
}
|
||||
|
||||
settings.BILLING_USER_NAME.set(userName);
|
||||
settings.BILLING_USER_EMAIL.set(email);
|
||||
settings.BILLING_USER_COUNTRY.set(country);
|
||||
|
||||
final WorldRegion world = getMyApplication().getRegions().getWorldRegion();
|
||||
String countryParam = country.equals(world.getLocaleName()) ? "" : country;
|
||||
|
||||
inAppHelper.purchaseLiveUpdates(getActivity(), email, userName, countryParam);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setThemedDrawable((ImageView) view.findViewById(R.id.userNameIcon), R.drawable.ic_person);
|
||||
setThemedDrawable((ImageView) view.findViewById(R.id.emailIcon), R.drawable.ic_action_message);
|
||||
setThemedDrawable((ImageView) view.findViewById(R.id.countryIcon), R.drawable.ic_world_globe_dark);
|
||||
|
||||
dlg = new ProgressDialog(getActivity());
|
||||
dlg.setTitle("");
|
||||
dlg.setMessage(getString(R.string.wait_current_task_finished));
|
||||
|
@ -109,4 +188,90 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
dlg.hide();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchResult(String name) {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
EditText selectCountryEdit = (EditText) view.findViewById(R.id.selectCountryEdit);
|
||||
if (selectCountryEdit != null) {
|
||||
selectCountryEdit.setText(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initCountries() {
|
||||
final WorldRegion root = getMyApplication().getRegions().getWorldRegion();
|
||||
ArrayList<WorldRegion> groups = new ArrayList<>();
|
||||
groups.add(root);
|
||||
processGroup(root, groups, getActivity());
|
||||
Collections.sort(groups, new Comparator<WorldRegion>() {
|
||||
@Override
|
||||
public int compare(WorldRegion lhs, WorldRegion rhs) {
|
||||
if (lhs == root) {
|
||||
return -1;
|
||||
}
|
||||
if (rhs == root) {
|
||||
return 1;
|
||||
}
|
||||
return getHumanReadableName(lhs).compareTo(getHumanReadableName(rhs));
|
||||
}
|
||||
});
|
||||
for (WorldRegion group : groups) {
|
||||
String name = getHumanReadableName(group);
|
||||
regionNames.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processGroup(WorldRegion group,
|
||||
List<WorldRegion> nameList,
|
||||
Context context) {
|
||||
if (group.isRegionMapDownload()) {
|
||||
nameList.add(group);
|
||||
}
|
||||
|
||||
if (group.getSubregions() != null) {
|
||||
for (WorldRegion g : group.getSubregions()) {
|
||||
processGroup(g, nameList, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getHumanReadableName(WorldRegion group) {
|
||||
String name;
|
||||
if (group.getLevel() > 2 || (group.getLevel() == 2
|
||||
&& group.getSuperregion().getRegionId().equals(WorldRegion.RUSSIA_REGION_ID))) {
|
||||
WorldRegion parent = group.getSuperregion();
|
||||
WorldRegion parentsParent = group.getSuperregion().getSuperregion();
|
||||
if (group.getLevel() == 3) {
|
||||
if (parentsParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
|
||||
name = parentsParent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else if (!parent.getRegionId().equals(WorldRegion.UNITED_KINGDOM_REGION_ID)) {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = parent.getLocaleName() + " " + group.getLocaleName();
|
||||
}
|
||||
} else {
|
||||
name = group.getLocaleName();
|
||||
}
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static class CountrySearchSelectionFragment extends SearchSelectionFragment {
|
||||
@Override
|
||||
protected ArrayList<String> getList() {
|
||||
return ((SubscriptionFragment) getParentFragment()).regionNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getListItemIcon() {
|
||||
return R.drawable.ic_map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue