Merge pull request #11240 from osmandapp/testing-purchase

Add purchases screen
This commit is contained in:
Vitaliy 2021-03-29 18:30:41 +03:00 committed by GitHub
commit 372e4e7f49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 1520 additions and 102 deletions

View file

@ -1,20 +1,23 @@
package net.osmand; package net.osmand;
import java.text.ParseException; import java.text.ParseException;
import java.util.Calendar;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Period { public class Period {
public enum PeriodUnit { public enum PeriodUnit {
YEAR("Y"), YEAR("Y", Calendar.YEAR),
MONTH("M"), MONTH("M", Calendar.MONTH),
WEEK("W"), WEEK("W", Calendar.WEEK_OF_YEAR),
DAY("D"); DAY("D", Calendar.DATE);
private String unitStr; private String unitStr;
private int calendarIdx;
PeriodUnit(String unitStr) { PeriodUnit(String unitStr, int calendarIdx) {
this.calendarIdx = calendarIdx;
this.unitStr = unitStr; this.unitStr = unitStr;
} }
@ -22,6 +25,10 @@ public class Period {
return unitStr; return unitStr;
} }
public int getCalendarIdx() {
return calendarIdx;
}
public double getMonthsValue() { public double getMonthsValue() {
switch (this) { switch (this) {
case YEAR: case YEAR:

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/osmand_live_active" />
<corners android:radius="26dp" />
</shape>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/osmand_live_cancelled" />
<corners android:radius="26dp" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/switch_button_active_dark" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/switch_button_active_light" />
</shape>

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/support_link_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/support_link_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_at_mail"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/support_link_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/title_padding"
android:layout_marginRight="@dimen/title_padding"
android:paddingTop="@dimen/contex_menu_top_shadow_height"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/contact_support_description"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout>
<LinearLayout
android:id="@+id/contact_support_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingStart="@dimen/action_bar_image_side_margin"
android:paddingLeft="@dimen/action_bar_image_side_margin"
android:paddingTop="@dimen/card_padding"
android:paddingEnd="@dimen/action_bar_image_side_margin"
android:paddingRight="@dimen/action_bar_image_side_margin"
android:paddingBottom="@dimen/card_padding"
android:clickable="true"
android:focusable="true">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/contact_support_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/contact_support"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
</LinearLayout>

View file

@ -45,7 +45,7 @@
osmand:typeface="@string/font_roboto_medium" /> osmand:typeface="@string/font_roboto_medium" />
<FrameLayout <FrameLayout
android:id="@+id/btn_save" android:id="@+id/btn_save_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="@dimen/content_padding_half" android:layout_marginRight="@dimen/content_padding_half"
@ -53,12 +53,12 @@
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/btn_save"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start" android:layout_gravity="start"
android:gravity="center_vertical" android:gravity="center_vertical"
android:duplicateParentState="true" android:duplicateParentState="true"
android:background="@drawable/btn_border_active"
android:paddingStart="@dimen/content_padding" android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_half" android:paddingTop="@dimen/content_padding_half"

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon_new_device_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_help_online"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/new_device_account_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/new_device_account"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
</LinearLayout>

View file

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="@dimen/map_widget_height"
android:layout_height="@dimen/context_menu_controller_height"
android:layout_gravity="center"
android:layout_marginTop="@dimen/favorites_my_places_icon_size"
android:layout_marginBottom="@dimen/favorites_my_places_icon_size"
app:srcCompat="@drawable/ic_action_purchases"
app:tint="?attr/default_icon_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/list_header_height"
android:layout_marginLeft="@dimen/list_header_height"
android:layout_marginEnd="@dimen/list_header_height"
android:layout_marginRight="@dimen/list_header_height"
android:layout_marginBottom="@dimen/default_title_line_height"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/any_purchases_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="@dimen/slider_thumb_size"
android:text="@string/no_purchases"
android:textColor="?attr/dialog_title_color"
android:textSize="@dimen/empty_state_text_desc_size"
osmand:typeface="@string/font_roboto_medium" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/info_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:letterSpacing="@dimen/description_letter_spacing"
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
android:minHeight="@dimen/dialog_button_ex_height"
android:text="@string/empty_purchases_description"
android:textColor="?attr/dialog_text_description_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<include
layout="@layout/simple_divider_item" />
<include
android:id="@+id/restore_purchases"
layout="@layout/restore_purchases_button" />
<include
layout="@layout/divider_half_item" />
<include
android:id="@+id/osmand_live"
layout="@layout/osm_live_banner_list_item" />
<include
layout="@layout/divider_half_item" />
<include
android:id="@+id/new_device_account_container"
layout="@layout/new_device_or_account_button" />
<include
layout="@layout/divider_half_item" />
<include
android:id="@+id/contact_support_container"
layout="@layout/contact_support" />
<include
layout="@layout/card_bottom_divider"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_min_width"
android:background="?attr/activity_background_color" />
</LinearLayout>

View file

@ -69,6 +69,7 @@
</LinearLayout> </LinearLayout>
<include <include
android:id="@+id/icon_toolbar"
layout="@layout/profile_button_small" layout="@layout/profile_button_small"
android:layout_width="@dimen/route_info_toolbar_button_size" android:layout_width="@dimen/route_info_toolbar_button_size"
android:layout_height="@dimen/route_info_toolbar_button_size" android:layout_height="@dimen/route_info_toolbar_button_size"

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color"
android:orientation="vertical"
android:focusableInTouchMode="false">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/cards_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
</LinearLayout>

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_reset_to_default_dark"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/restore_purchases"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
</LinearLayout>

View file

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/title_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/osmand_live_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_subscription_osmand_live" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_half"
android:text="@string/osmand_live"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/subscription_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/annual_subscription"
tools:visibility="visible"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/next_billing_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/next_billing_date"
tools:visibility="visible"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_gravity="center_vertical"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingTop="@dimen/content_padding_small_half"
android:paddingRight="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small_half"
android:textColor="?attr/app_bar_primary_item_color"
osmand:typeface="@string/font_roboto_medium"
tools:background="@drawable/bg_osmand_live_active"
tools:text="@string/osm_live_active" />
<FrameLayout
android:id="@+id/renewContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:visibility="gone"
tools:visibility="visible">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/renew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_half"
android:text="@string/renew_subscription"
android:textColor="?attr/colorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:background="@drawable/btn_solid_border_light"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/list_content_padding"
android:background="?attr/activity_background_color" />
<include
layout="@layout/divider" />
<FrameLayout
android:id="@+id/subscriptions_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/support_region_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="@dimen/setting_list_item_group_height"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_world_globe_dark"
app:tint="?attr/default_icon_color" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginBottom="@dimen/content_padding_small"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/support_region_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/osm_live_support_region"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/support_region"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:text="@string/osm_live_support_region"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/clear_updates_proposition_message"/>
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:srcCompat="@drawable/ic_action_settings"
app:tint="?attr/default_icon_color" />
</LinearLayout>
<include layout="@layout/simple_divider_item" />
<LinearLayout
android:id="@+id/report_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/report_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_file_report"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/report_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/report"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
</LinearLayout>
<include
android:id="@+id/dismiss_button"
layout="@layout/divider_half_item" />
<LinearLayout
android:id="@+id/live_updates_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/live_updates_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_at_mail"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/live_updates_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/card_button_progress_size_small"
android:layout_marginRight="@dimen/card_button_progress_size_small"
android:layout_weight="1"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/live_updates"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
</LinearLayout>
<include
android:id="@+id/dismiss_button"
layout="@layout/divider_half_item" />
<LinearLayout
android:id="@+id/manage_subscription_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/manage_subscription_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
app:srcCompat="@drawable/ic_action_purchases"
app:tint="?attr/active_color_basic" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/manage_subscription_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/card_button_progress_size_small"
android:layout_marginRight="@dimen/card_button_progress_size_small"
android:layout_weight="1"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/manage_subscription"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
</LinearLayout>
<include
layout="@layout/divider"/>
</LinearLayout>

View file

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

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/list_content_padding"
android:background="?attr/activity_background_color" />
<include
layout="@layout/divider" />
<LinearLayout
android:id="@+id/troubleshooting_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/list_item_height"
android:orientation="vertical"
android:paddingStart="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingTop="14dp"
android:paddingEnd="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingBottom="6dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/troubleshooting_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/map_widget_height"
android:layout_marginRight="@dimen/map_widget_height"
android:paddingBottom="@dimen/dialog_content_bottom_margin"
app:srcCompat="@drawable/ic_action_help"
app:tint="?attr/profile_icon_color_green" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/troubleshooting_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/card_button_progress_size_small"
android:layout_marginRight="@dimen/card_button_progress_size_small"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/troubleshooting"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_medium" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/troubleshooting_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/card_button_progress_size_small"
android:layout_marginRight="@dimen/card_button_progress_size_small"
android:letterSpacing="@dimen/description_letter_spacing"
android:text="@string/troubleshooting_description"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
app:typeface="@string/font_roboto_regular" />
</LinearLayout>
<include
android:id="@+id/restore_purchases"
layout="@layout/restore_purchases_button" />
<include
android:id="@+id/dismiss_button"
layout="@layout/divider_half_item" />
<include
android:id="@+id/new_device_account_container"
layout="@layout/new_device_or_account_button" />
<include
android:id="@+id/dismiss_button"
layout="@layout/divider" />
<include
android:id="@+id/contact_support_container"
layout="@layout/contact_support" />
<include
layout="@layout/divider"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_min_width"
android:background="?attr/activity_background_color" />
</LinearLayout>

View file

@ -124,6 +124,7 @@
<attr name="divider_color_basic" format="reference" /> <attr name="divider_color_basic" format="reference" />
<attr name="main_font_color_basic" format="reference" /> <attr name="main_font_color_basic" format="reference" />
<attr name="active_color_basic" format="reference" /> <attr name="active_color_basic" format="reference" />
<attr name="profile_icon_color_green" format="reference" />
<attr name="card_and_list_background_basic" format="reference" /> <attr name="card_and_list_background_basic" format="reference" />
<attr name="activity_background_basic" format="reference" /> <attr name="activity_background_basic" format="reference" />
<attr name="pages_bg" format="reference"/> <attr name="pages_bg" format="reference"/>

View file

@ -75,6 +75,8 @@
<color name="icon_color_osmand_dark">#d28521</color> <color name="icon_color_osmand_dark">#d28521</color>
<color name="icon_color_active_light">#237bff</color> <color name="icon_color_active_light">#237bff</color>
<color name="icon_color_active_dark">#d28521</color> <color name="icon_color_active_dark">#d28521</color>
<color name="osmand_live_active">#14CC70</color>
<color name="osmand_live_cancelled">#EE5622</color>
<color name="on_map_icon_color">#505050</color> <color name="on_map_icon_color">#505050</color>

View file

@ -18,6 +18,23 @@
• Added option to change the appearance of the navigation route line\n\n • Added option to change the appearance of the navigation route line\n\n
• Updated \"Trip recording\" dialog\n\n • Updated \"Trip recording\" dialog\n\n
</string> </string>
<string name="expired">Expired</string>
<string name="on_hold">On hold</string>
<string name="in_grace_period">In grace period</string>
<string name="renew_subscription">Renew subscription</string>
<string name="osmand_live_cancelled">Cancelled</string>
<string name="next_billing_date">Next billing date: %1$s</string>
<string name="three_months_subscription">Three months subscription</string>
<string name="monthly_subscription">Monthly subscription</string>
<string name="annual_subscription">Annual subscription</string>
<string name="osmand_live">OsmAnd Live</string>
<string name="troubleshooting_description">Please follow this link if you any issues with purchases.</string>
<string name="troubleshooting">Troubleshooting</string>
<string name="contact_support">Contact support</string>
<string name="empty_purchases_description">If your purchases don\'t show up here, tap on “%1$s”, or contact our support team.</string>
<string name="contact_support_description">If you have any questions, please contact us at %1$s.</string>
<string name="new_device_account">New device / new account</string>
<string name="no_purchases">You don\'t have any purchases</string>
<string name="specify_color_for_map_mode">Specify color for map mode: %1$s.</string> <string name="specify_color_for_map_mode">Specify color for map mode: %1$s.</string>
<string name="route_line_use_map_style_appearance">Route line would be use %1$s specified on selected map style: %2$s.</string> <string name="route_line_use_map_style_appearance">Route line would be use %1$s specified on selected map style: %2$s.</string>
<string name="shared_string_route_line">Route line</string> <string name="shared_string_route_line">Route line</string>

View file

@ -218,6 +218,7 @@
<item name="divider_color_basic">@color/divider_color_light</item> <item name="divider_color_basic">@color/divider_color_light</item>
<item name="main_font_color_basic">@color/text_color_primary_light</item> <item name="main_font_color_basic">@color/text_color_primary_light</item>
<item name="active_color_basic">@color/active_color_primary_light</item> <item name="active_color_basic">@color/active_color_primary_light</item>
<item name="profile_icon_color_green">@color/profile_icon_color_green_light</item>
<item name="card_and_list_background_basic">@color/card_and_list_background_light</item> <item name="card_and_list_background_basic">@color/card_and_list_background_light</item>
<item name="activity_background_basic">@color/activity_background_light</item> <item name="activity_background_basic">@color/activity_background_light</item>
<item name="pages_bg">@drawable/pages_bg_light</item> <item name="pages_bg">@drawable/pages_bg_light</item>
@ -519,6 +520,7 @@
<item name="divider_color_basic">@color/divider_color_dark</item> <item name="divider_color_basic">@color/divider_color_dark</item>
<item name="main_font_color_basic">@color/text_color_primary_dark</item> <item name="main_font_color_basic">@color/text_color_primary_dark</item>
<item name="active_color_basic">@color/active_color_primary_dark</item> <item name="active_color_basic">@color/active_color_primary_dark</item>
<item name="profile_icon_color_green">@color/profile_icon_color_green_dark</item>
<item name="card_and_list_background_basic">@color/card_and_list_background_dark</item> <item name="card_and_list_background_basic">@color/card_and_list_background_dark</item>
<item name="activity_background_basic">@color/activity_background_dark</item> <item name="activity_background_basic">@color/activity_background_dark</item>
<item name="pages_bg">@drawable/pages_bg_dark</item> <item name="pages_bg">@drawable/pages_bg_dark</item>

View file

@ -13,6 +13,13 @@
app:fragment="net.osmand.plus.settings.fragments.GlobalSettingsFragment" app:fragment="net.osmand.plus.settings.fragments.GlobalSettingsFragment"
tools:icon="@drawable/ic_action_settings" /> tools:icon="@drawable/ic_action_settings" />
<Preference
android:key="purchases_settings"
android:layout="@layout/preference_with_descr"
android:persistent="false"
android:title="@string/purchases"
tools:icon="@drawable/ic_action_purchases" />
<Preference <Preference
android:layout="@layout/list_item_divider" android:layout="@layout/list_item_divider"
android:selectable="false" /> android:selectable="false" />

View file

@ -2,15 +2,15 @@ package net.osmand.plus.inapp;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.billingclient.api.SkuDetails; import com.android.billingclient.api.SkuDetails;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class InAppPurchasesImpl extends InAppPurchases { public class InAppPurchasesImpl extends InAppPurchases {
private static final InAppPurchase FULL_VERSION = new InAppPurchaseFullVersion(); private static final InAppPurchase FULL_VERSION = new InAppPurchaseFullVersion();
@ -285,6 +285,11 @@ public class InAppPurchasesImpl extends InAppPurchases {
this.details = details; this.details = details;
} }
@Override
public int getPeriodTypeString() {
return R.string.monthly_subscription;
}
@Override @Override
public String getDefaultPrice(Context ctx) { public String getDefaultPrice(Context ctx) {
return ""; return "";

View file

@ -165,6 +165,11 @@ public class InAppPurchasesImpl extends InAppPurchases {
this.info = info; this.info = info;
} }
@Override
public int getPeriodTypeString() {
return R.string.monthly_subscription;
}
@Override @Override
public String getDefaultPrice(Context ctx) { public String getDefaultPrice(Context ctx) {
return ""; return "";

View file

@ -1030,22 +1030,6 @@ public class MapActivityActions implements DialogProvider {
}).createItem()); }).createItem());
*/ */
if (Version.isGooglePlayEnabled() || Version.isHuawei() || Version.isDeveloperVersion(app)) {
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.purchases, mapActivity)
.setId(DRAWER_OSMAND_LIVE_ID)
.setIcon(R.drawable.ic_action_purchases)
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
app.logEvent("drawer_osm_live_open");
Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(intent);
return true;
}
}).createItem());
}
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_help, mapActivity) optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_help, mapActivity)
.setId(DRAWER_HELP_ID) .setId(DRAWER_HELP_ID)
.setIcon(R.drawable.ic_action_help) .setIcon(R.drawable.ic_action_help)

View file

@ -22,17 +22,6 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -59,6 +48,17 @@ import org.apache.commons.logging.Log;
import java.util.List; import java.util.List;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment implements InAppPurchaseListener { public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment implements InAppPurchaseListener {
public static final String TAG = ChoosePlanDialogFragment.class.getSimpleName(); public static final String TAG = ChoosePlanDialogFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(ChoosePlanDialogFragment.class); private static final Log LOG = PlatformUtil.getLog(ChoosePlanDialogFragment.class);
@ -489,14 +489,18 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
buttonView.setOnClickListener(new OnClickListener() { buttonView.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
subscribe(s.getSku()); if (getActivity() != null) {
subscribe(app, getActivity(), purchaseHelper, s.getSku());
}
} }
}); });
} else { } else {
buttonExView.setOnClickListener(new OnClickListener() { buttonExView.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
subscribe(s.getSku()); if (getActivity() != null) {
subscribe(app, getActivity(), purchaseHelper, s.getSku());
}
} }
}); });
} }
@ -526,14 +530,14 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
} }
} }
private void subscribe(String sku) { public static void subscribe(@NonNull OsmandApplication app, Activity activity,
InAppPurchaseHelper purchaseHelper, String sku) {
if (!app.getSettings().isInternetConnectionAvailable(true)) { if (!app.getSettings().isInternetConnectionAvailable(true)) {
Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show(); Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show();
} else { } else {
FragmentActivity ctx = getActivity(); if (activity != null && purchaseHelper != null) {
if (ctx != null && purchaseHelper != null) {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
purchaseHelper.purchaseLiveUpdates(ctx, sku, purchaseHelper.purchaseLiveUpdates(activity, sku,
settings.BILLING_USER_EMAIL.get(), settings.BILLING_USER_EMAIL.get(),
settings.BILLING_USER_NAME.get(), settings.BILLING_USER_NAME.get(),
settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(), settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(),

View file

@ -8,9 +8,6 @@ import android.os.AsyncTask;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidNetworkUtils.OnRequestResultListener; import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
import net.osmand.AndroidNetworkUtils.OnRequestsResultListener; import net.osmand.AndroidNetworkUtils.OnRequestsResultListener;
@ -43,6 +40,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public abstract class InAppPurchaseHelper { public abstract class InAppPurchaseHelper {
// Debug tag, for logging // Debug tag, for logging
protected static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(InAppPurchaseHelper.class); protected static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(InAppPurchaseHelper.class);
@ -198,6 +198,18 @@ public abstract class InAppPurchaseHelper {
isDeveloperVersion = Version.isDeveloperVersion(ctx); isDeveloperVersion = Version.isDeveloperVersion(ctx);
} }
@NonNull
public List<InAppSubscription> getEverMadeSubscriptions() {
List<InAppSubscription> subscriptions = new ArrayList<>();
for (InAppSubscription subscription : getLiveUpdates().getVisibleSubscriptions()) {
SubscriptionState state = subscription.getState();
if (state != SubscriptionState.UNDEFINED) {
subscriptions.add(subscription);
}
}
return subscriptions;
}
public abstract void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback); public abstract void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback);
public boolean hasInventory() { public boolean hasInventory() {

View file

@ -7,10 +7,6 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Period; import net.osmand.Period;
import net.osmand.Period.PeriodUnit; import net.osmand.Period.PeriodUnit;
@ -32,6 +28,12 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
public abstract class InAppPurchases { public abstract class InAppPurchases {
protected InAppPurchase fullVersion; protected InAppPurchase fullVersion;
@ -580,24 +582,40 @@ public abstract class InAppPurchases {
private InAppSubscriptionIntroductoryInfo introductoryInfo; private InAppSubscriptionIntroductoryInfo introductoryInfo;
public enum SubscriptionState { public enum SubscriptionState {
UNDEFINED("undefined"), UNDEFINED("undefined", 0, 0),
ACTIVE("active"), ACTIVE("active", R.string.osm_live_active, R.drawable.bg_osmand_live_active),
CANCELLED("cancelled"), CANCELLED("cancelled", R.string.osmand_live_cancelled, R.drawable.bg_osmand_live_cancelled),
IN_GRACE_PERIOD("in_grace_period"), IN_GRACE_PERIOD("in_grace_period", R.string.in_grace_period, R.drawable.bg_osmand_live_active),
ON_HOLD("on_hold"), ON_HOLD("on_hold", R.string.on_hold, R.drawable.bg_osmand_live_cancelled),
PAUSED("paused"), PAUSED("paused", R.string.shared_string_paused, R.drawable.bg_osmand_live_cancelled),
EXPIRED("expired"); EXPIRED("expired", R.string.expired, R.drawable.bg_osmand_live_cancelled);
private final String stateStr; private final String stateStr;
@StringRes
private final int stringRes;
@DrawableRes
private final int backgroundRes;
SubscriptionState(@NonNull String stateStr) { SubscriptionState(@NonNull String stateStr, @StringRes int stringRes, @DrawableRes int backgroundRes) {
this.stateStr = stateStr; this.stateStr = stateStr;
this.stringRes = stringRes;
this.backgroundRes = backgroundRes;
} }
public String getStateStr() { public String getStateStr() {
return stateStr; return stateStr;
} }
@StringRes
public int getStringRes() {
return stringRes;
}
@DrawableRes
public int getBackgroundRes() {
return backgroundRes;
}
@NonNull @NonNull
public static SubscriptionState getByStateStr(@NonNull String stateStr) { public static SubscriptionState getByStateStr(@NonNull String stateStr) {
for (SubscriptionState state : SubscriptionState.values()) { for (SubscriptionState state : SubscriptionState.values()) {
@ -627,6 +645,9 @@ public abstract class InAppPurchases {
this.skuNoVersion = sku; this.skuNoVersion = sku;
} }
@StringRes
public abstract int getPeriodTypeString();
@NonNull @NonNull
private List<InAppSubscription> getUpgrades() { private List<InAppSubscription> getUpgrades() {
return new ArrayList<>(upgrades.values()); return new ArrayList<>(upgrades.values());
@ -817,6 +838,11 @@ public abstract class InAppPurchases {
this(sku, false); this(sku, false);
} }
@Override
public int getPeriodTypeString() {
return R.string.monthly_subscription;
}
@Override @Override
public void setPriceValue(double priceValue) { public void setPriceValue(double priceValue) {
super.setPriceValue(priceValue); super.setPriceValue(priceValue);
@ -865,6 +891,11 @@ public abstract class InAppPurchases {
super(sku, false); super(sku, false);
} }
@Override
public int getPeriodTypeString() {
return R.string.three_months_subscription;
}
@Override @Override
public void setPriceValue(double priceValue) { public void setPriceValue(double priceValue) {
super.setPriceValue(priceValue); super.setPriceValue(priceValue);
@ -908,6 +939,11 @@ public abstract class InAppPurchases {
super(sku, false); super(sku, false);
} }
@Override
public int getPeriodTypeString() {
return R.string.annual_subscription;
}
@Override @Override
public void setPriceValue(double priceValue) { public void setPriceValue(double priceValue) {
super.setPriceValue(priceValue); super.setPriceValue(priceValue);

View file

@ -35,6 +35,8 @@ import java.util.List;
public class CountrySelectionFragment extends BaseOsmAndDialogFragment { public class CountrySelectionFragment extends BaseOsmAndDialogFragment {
public static final String TAG = CountrySelectionFragment.class.getSimpleName();
private List<CountryItem> countryItems = new ArrayList<>(); private List<CountryItem> countryItems = new ArrayList<>();
private OnFragmentInteractionListener mListener; private OnFragmentInteractionListener mListener;

View file

@ -22,19 +22,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogType;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexHelper; import net.osmand.plus.activities.LocalIndexHelper;
@ -43,12 +31,15 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity; import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogType;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription; import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
import net.osmand.plus.resources.IncrementalChangesManager; import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
@ -59,6 +50,15 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import static net.osmand.plus.liveupdates.LiveUpdatesFragmentNew.showUpdateDialog; import static net.osmand.plus.liveupdates.LiveUpdatesFragmentNew.showUpdateDialog;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.DEFAULT_LAST_CHECK; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.DEFAULT_LAST_CHECK;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay;
@ -181,28 +181,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
statusTextView.setText(getString(R.string.osm_live_active)); statusTextView.setText(getString(R.string.osm_live_active));
statusIcon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_done)); statusIcon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_done));
regionNameHeaderTextView.setText(R.string.osm_live_support_region); String countryName = getSupportRegionName(app, getInAppPurchaseHelper());
String countryName = app.getSettings().BILLING_USER_COUNTRY.get(); String header = getSupportRegionHeader(app, countryName);
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); regionNameHeaderTextView.setText(header);
if (purchaseHelper != null) {
InAppSubscription monthlyPurchased = purchaseHelper.getPurchasedMonthlyLiveUpdates();
if (monthlyPurchased != null && monthlyPurchased.isDonationSupported()) {
if (Algorithms.isEmpty(countryName)) {
if (app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.get().equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
regionNameHeaderTextView.setText(R.string.default_buttons_support);
countryName = getString(R.string.osmand_team);
} else {
countryName = getString(R.string.shared_string_world);
}
}
} else {
regionNameHeaderTextView.setText(R.string.default_buttons_support);
countryName = getString(R.string.osmand_team);
}
} else {
regionNameHeaderTextView.setText(R.string.default_buttons_support);
countryName = getString(R.string.osmand_team);
}
regionNameTextView.setText(countryName); regionNameTextView.setText(countryName);
View subscriptionsButton = subscriptionHeader.findViewById(R.id.button_subscriptions); View subscriptionsButton = subscriptionHeader.findViewById(R.id.button_subscriptions);
@ -297,6 +278,41 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG); subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG);
} }
public static String getSupportRegionName(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
OsmandSettings settings = app.getSettings();
String countryName = settings.BILLING_USER_COUNTRY.get();
if (purchaseHelper != null) {
List<InAppSubscription> subscriptions = purchaseHelper.getLiveUpdates().getVisibleSubscriptions();
boolean donationSupported = false;
for (InAppSubscription s : subscriptions) {
if (s.isDonationSupported()) {
donationSupported = true;
break;
}
}
if (donationSupported) {
if (Algorithms.isEmpty(countryName)) {
if (OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER.equals(settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get())) {
countryName = app.getString(R.string.osmand_team);
} else {
countryName = app.getString(R.string.shared_string_world);
}
}
} else {
countryName = app.getString(R.string.osmand_team);
}
} else {
countryName = app.getString(R.string.osmand_team);
}
return countryName;
}
public static String getSupportRegionHeader(OsmandApplication app, String supportRegion) {
return supportRegion.equals(app.getString(R.string.osmand_team)) ?
app.getString(R.string.default_buttons_support) :
app.getString(R.string.osm_live_support_region);
}
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter { protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
public static final int SHOULD_UPDATE_GROUP_POSITION = 0; public static final int SHOULD_UPDATE_GROUP_POSITION = 0;
public static final int SHOULD_NOT_UPDATE_GROUP_POSITION = 1; public static final int SHOULD_NOT_UPDATE_GROUP_POSITION = 1;

View file

@ -177,7 +177,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
CountrySelectionFragment countryCountrySelectionFragment = CountrySelectionFragment countryCountrySelectionFragment =
countrySelectionFragment; countrySelectionFragment;
countryCountrySelectionFragment countryCountrySelectionFragment
.show(getChildFragmentManager(), "CountriesSearchSelectionFragment"); .show(getChildFragmentManager(), CountrySelectionFragment.TAG);
} }
return false; return false;
} }

View file

@ -6,7 +6,6 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference; import androidx.preference.Preference;
@ -44,6 +43,7 @@ public class MainSettingsFragment extends BaseSettingsFragment implements OnSele
private static final String CONFIGURE_PROFILE = "configure_profile"; private static final String CONFIGURE_PROFILE = "configure_profile";
private static final String APP_PROFILES = "app_profiles"; private static final String APP_PROFILES = "app_profiles";
private static final String PURCHASES_SETTINGS = "purchases_settings";
private static final String SELECTED_PROFILE = "selected_profile"; private static final String SELECTED_PROFILE = "selected_profile";
private static final String CREATE_PROFILE = "create_profile"; private static final String CREATE_PROFILE = "create_profile";
private static final String IMPORT_PROFILE = "import_profile"; private static final String IMPORT_PROFILE = "import_profile";
@ -70,10 +70,12 @@ public class MainSettingsFragment extends BaseSettingsFragment implements OnSele
availableAppModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication())); availableAppModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication()));
Preference globalSettings = findPreference("global_settings"); Preference globalSettings = findPreference("global_settings");
globalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings)); globalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings));
PreferenceCategory selectedProfile = (PreferenceCategory) findPreference(SELECTED_PROFILE); Preference purchasesSettings = findPreference(PURCHASES_SETTINGS);
purchasesSettings.setIcon(getContentIcon(R.drawable.ic_action_purchases));
PreferenceCategory selectedProfile = findPreference(SELECTED_PROFILE);
selectedProfile.setIconSpaceReserved(false); selectedProfile.setIconSpaceReserved(false);
setupConfigureProfilePref(); setupConfigureProfilePref();
PreferenceCategory appProfiles = (PreferenceCategory) findPreference(APP_PROFILES); PreferenceCategory appProfiles = findPreference(APP_PROFILES);
appProfiles.setIconSpaceReserved(false); appProfiles.setIconSpaceReserved(false);
setupAppProfiles(appProfiles); setupAppProfiles(appProfiles);
profileManagementPref(); profileManagementPref();
@ -148,7 +150,14 @@ public class MainSettingsFragment extends BaseSettingsFragment implements OnSele
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
ExportSettingsFragment.showInstance(fragmentManager, mode, true); ExportSettingsFragment.showInstance(fragmentManager, mode, true);
} }
} else if (PURCHASES_SETTINGS.equals(prefId)) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
PurchasesFragment.showInstance(fragmentManager);
} }
}
return super.onPreferenceClick(preference); return super.onPreferenceClick(preference);
} }

View file

@ -0,0 +1,208 @@
package net.osmand.plus.settings.fragments;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.material.appbar.AppBarLayout;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.liveupdates.CountrySelectionFragment;
import net.osmand.plus.liveupdates.CountrySelectionFragment.OnFragmentInteractionListener;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurchaseListener, OnFragmentInteractionListener {
private static final Log log = PlatformUtil.getLog(PurchasesFragment.class);
public static final String TAG = PurchasesFragment.class.getName();
public static final String KEY_IS_SUBSCRIBER = "action_is_new";
private static final String OSMAND_PURCHASES_URL = "https://docs.osmand.net/en/main@latest/osmand/purchases";
private OsmandApplication app;
private InAppPurchaseHelper purchaseHelper;
private ViewGroup cardsContainer;
private SubscriptionsCard subscriptionsCard;
private boolean nightMode;
private Boolean isPaidVersion;
public static boolean showInstance(FragmentManager fragmentManager) {
try {
PurchasesFragment fragment = new PurchasesFragment();
fragmentManager.beginTransaction()
.add(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
log.error(e);
return false;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
app = getMyApplication();
isPaidVersion = Version.isPaidVersion(app);
nightMode = !app.getSettings().isLightContent();
LayoutInflater themedInflater = UiUtilities.getInflater(getContext(), nightMode);
View mainView = themedInflater.inflate(R.layout.purchases_layout, container, false);
AndroidUtils.addStatusBarPadding21v(getActivity(), mainView);
createToolbar(mainView, nightMode);
cardsContainer = mainView.findViewById(R.id.cards_container);
return mainView;
}
@Override
public void onResume() {
super.onResume();
updateCards();
}
private void updateCards() {
MapActivity mapActivity = getMapActivity();
purchaseHelper = getInAppPurchaseHelper();
cardsContainer.removeAllViews();
if (mapActivity == null || purchaseHelper == null) {
return;
}
boolean hasSubscriptions = !Algorithms.isEmpty(purchaseHelper.getEverMadeSubscriptions());
if (hasSubscriptions) {
subscriptionsCard = new SubscriptionsCard(mapActivity, this, purchaseHelper);
cardsContainer.addView(subscriptionsCard.build(mapActivity));
}
cardsContainer.addView(new TroubleshootingOrPurchasingCard(mapActivity, purchaseHelper, isPaidVersion)
.build(mapActivity));
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_IS_SUBSCRIBER, isPaidVersion);
}
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
isPaidVersion = savedInstanceState.getBoolean(KEY_IS_SUBSCRIBER);
}
}
@Nullable
public InAppPurchaseHelper getInAppPurchaseHelper() {
Activity activity = getActivity();
if (activity instanceof OsmandInAppPurchaseActivity) {
return ((OsmandInAppPurchaseActivity) activity).getPurchaseHelper();
} else {
return null;
}
}
private void createToolbar(View mainView, final boolean nightMode) {
AppBarLayout appbar = mainView.findViewById(R.id.appbar);
View toolbar = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.profile_preference_toolbar_with_icon, appbar, false);
View iconToolbarContainer = toolbar.findViewById(R.id.icon_toolbar);
ImageView icon = iconToolbarContainer.findViewById(R.id.profile_icon);
icon.setImageResource(R.drawable.ic_action_help_online);
icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getContext() != null) {
WikipediaDialogFragment.showFullArticle(getContext(), Uri.parse(OSMAND_PURCHASES_URL), nightMode);
}
}
});
ImageButton backButton = toolbar.findViewById(R.id.close_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setText(getString(R.string.purchases));
appbar.addView(toolbar);
}
@Override
public void onError(InAppPurchaseHelper.InAppPurchaseTaskType taskType, String error) {
}
@Override
public void onGetItems() {
if (app != null) {
isPaidVersion = Version.isPaidVersion(app);
}
updateCards();
}
@Override
public void onItemPurchased(String sku, boolean active) {
isPaidVersion = true;
if (purchaseHelper != null) {
purchaseHelper.requestInventory();
}
}
@Override
public void showProgress(InAppPurchaseHelper.InAppPurchaseTaskType taskType) {
}
@Override
public void dismissProgress(InAppPurchaseHelper.InAppPurchaseTaskType taskType) {
}
@Override
public void onSearchResult(CountrySelectionFragment.CountryItem name) {
if (subscriptionsCard != null) {
subscriptionsCard.onSupportRegionSelected(name);
}
}
private MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
}

View file

@ -0,0 +1,146 @@
package net.osmand.plus.settings.fragments;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.liveupdates.CountrySelectionFragment;
import net.osmand.plus.liveupdates.LiveUpdatesFragment;
import net.osmand.plus.liveupdates.LiveUpdatesFragmentNew;
import net.osmand.plus.liveupdates.OsmLiveActivity;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
public class SubscriptionsCard extends BaseCard {
private static final String PLAY_STORE_SUBSCRIPTION_URL = "https://play.google.com/store/account/subscriptions";
private static final String PLAY_STORE_SUBSCRIPTION_DEEPLINK_URL = "https://play.google.com/store/account/subscriptions?sku=%s&package=%s";
private Fragment target;
private CountrySelectionFragment countrySelectionFragment = new CountrySelectionFragment();
private SubscriptionsListCard subscriptionsListCard;
private InAppPurchaseHelper purchaseHelper;
@Override
public int getCardLayoutId() {
return R.layout.subscriptions_card;
}
public SubscriptionsCard(@NonNull MapActivity mapActivity, @NonNull Fragment target, @NonNull InAppPurchaseHelper purchaseHelper) {
super(mapActivity);
this.target = target;
this.purchaseHelper = purchaseHelper;
}
@Override
protected void updateContent() {
if (purchaseHelper == null || Algorithms.isEmpty(purchaseHelper.getEverMadeSubscriptions())) {
AndroidUiHelper.updateVisibility(view, false);
return;
} else {
AndroidUiHelper.updateVisibility(view, true);
}
updateSubscriptionsListCard();
setupSupportRegion();
LinearLayout reportContainer = view.findViewById(R.id.report_container);
reportContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(intent);
}
});
LinearLayout liveUpdatesContainer = view.findViewById(R.id.live_updates_container);
liveUpdatesContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LiveUpdatesFragmentNew.showInstance(mapActivity.getSupportFragmentManager(), target);
}
});
final String subscriptionUrl = getSubscriptionUrl();
LinearLayout manageSubscriptionContainer = view.findViewById(R.id.manage_subscription_container);
manageSubscriptionContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(subscriptionUrl));
if (AndroidUtils.isIntentSafe(mapActivity, intent)) {
target.startActivity(intent);
}
}
});
}
public void updateSubscriptionsListCard() {
if (subscriptionsListCard == null) {
ViewGroup subscriptionsListContainer = view.findViewById(R.id.subscriptions_list_container);
subscriptionsListContainer.removeAllViews();
subscriptionsListCard = new SubscriptionsListCard(mapActivity, purchaseHelper);
subscriptionsListContainer.addView(subscriptionsListCard.build(mapActivity));
} else {
subscriptionsListCard.update();
}
}
private void setupSupportRegion() {
String region = LiveUpdatesFragment.getSupportRegionName(app, purchaseHelper);
String header = LiveUpdatesFragment.getSupportRegionHeader(app, region);
TextView supportRegionHeader = view.findViewById(R.id.support_region_header);
TextView supportRegion = view.findViewById(R.id.support_region);
supportRegionHeader.setText(header);
supportRegion.setText(region);
View supportRegionContainer = view.findViewById(R.id.support_region_container);
supportRegionContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CountrySelectionFragment countryCountrySelectionFragment = countrySelectionFragment;
countryCountrySelectionFragment.show(target.getChildFragmentManager(), CountrySelectionFragment.TAG);
}
});
countrySelectionFragment.initCountries(app);
}
private String getSubscriptionUrl() {
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null && purchaseHelper.getFullVersion() != null) {
String sku = purchaseHelper.getFullVersion().getSku();
return String.format(PLAY_STORE_SUBSCRIPTION_DEEPLINK_URL,
sku, mapActivity.getPackageName());
} else {
return PLAY_STORE_SUBSCRIPTION_URL;
}
}
public void onSupportRegionSelected(CountrySelectionFragment.CountryItem selectedCountryItem) {
String countryName = selectedCountryItem != null ? selectedCountryItem.getLocalName() : "";
String countryDownloadName = selectedCountryItem != null ?
selectedCountryItem.getDownloadName() : OsmandSettings.BILLING_USER_DONATION_WORLD_PARAMETER;
TextView supportRegionHeader = view.findViewById(R.id.support_region_header);
TextView supportRegion = view.findViewById(R.id.support_region);
supportRegionHeader.setText(LiveUpdatesFragment.getSupportRegionHeader(app, countryName));
supportRegion.setText(countryName);
app.getSettings().BILLING_USER_COUNTRY.set(countryName);
app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.set(countryDownloadName);
}
}

View file

@ -0,0 +1,124 @@
package net.osmand.plus.settings.fragments;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.Period;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription.SubscriptionState;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.util.Algorithms;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import androidx.annotation.NonNull;
public class SubscriptionsListCard extends BaseCard {
private final InAppPurchaseHelper purchaseHelper;
private final SimpleDateFormat dateFormat;
@Override
public int getCardLayoutId() {
return R.layout.subscriptions_list_card;
}
public SubscriptionsListCard(@NonNull MapActivity mapActivity, @NonNull InAppPurchaseHelper purchaseHelper) {
super(mapActivity);
this.purchaseHelper = purchaseHelper;
this.dateFormat = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault());
}
@Override
protected void updateContent() {
if (purchaseHelper == null || Algorithms.isEmpty(purchaseHelper.getEverMadeSubscriptions())) {
AndroidUiHelper.updateVisibility(view, false);
return;
} else {
AndroidUiHelper.updateVisibility(view, true);
}
LayoutInflater inflater = UiUtilities.getInflater(mapActivity, nightMode);
((ViewGroup) view).removeAllViews();
List<InAppSubscription> subscriptions = purchaseHelper.getEverMadeSubscriptions();
for (int i = 0; i < subscriptions.size(); i++) {
InAppSubscription subscription = subscriptions.get(i);
SubscriptionState state = subscription.getState();
boolean autoRenewed = state == SubscriptionState.ACTIVE || state == SubscriptionState.IN_GRACE_PERIOD;
View card = inflater.inflate(R.layout.subscription_layout, null, false);
((ViewGroup) view).addView(card);
TextView subscriptionPeriod = card.findViewById(R.id.subscription_type);
String period = app.getString(subscription.getPeriodTypeString());
if (!Algorithms.isEmpty(period)) {
subscriptionPeriod.setText(period);
AndroidUiHelper.updateVisibility(subscriptionPeriod, true);
}
if (autoRenewed) {
TextView nextBillingDate = card.findViewById(R.id.next_billing_date);
String date = getHumanDate(subscription.getPurchaseTime(), subscription.getSubscriptionPeriod());
if (!Algorithms.isEmpty(date)) {
nextBillingDate.setText(app.getString(R.string.next_billing_date, date));
AndroidUiHelper.updateVisibility(nextBillingDate, true);
}
} else {
View renewContainer = card.findViewById(R.id.renewContainer);
AndroidUiHelper.updateVisibility(renewContainer, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(mapActivity, renewContainer, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(mapActivity, renewContainer, nightMode, R.drawable.btn_unstroked_light, R.drawable.btn_unstroked_dark);
}
final String sku = subscription.getSku();
renewContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChoosePlanDialogFragment.subscribe(app, mapActivity, purchaseHelper, sku);
}
});
View renew = card.findViewById(R.id.renew);
AndroidUtils.setBackground(mapActivity, renew, nightMode,
R.drawable.btn_solid_border_light, R.drawable.btn_solid_border_dark);
}
TextView status = card.findViewById(R.id.status);
status.setText(app.getString(state.getStringRes()));
AndroidUtils.setBackground(status, app.getUIUtilities().getIcon(state.getBackgroundRes()));
int dividerLayout = i + 1 == subscriptions.size() ? R.layout.simple_divider_item : R.layout.divider_half_item;
View divider = inflater.inflate(dividerLayout, (ViewGroup) view, false);
((ViewGroup) view).addView(divider);
}
}
private String getHumanDate(long time, Period period) {
if (period == null || period.getUnit() == null) {
return "";
}
Date date = new Date(time);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(period.getUnit().getCalendarIdx(), period.getNumberOfUnits());
date = calendar.getTime();
return dateFormat.format(date);
}
}

View file

@ -0,0 +1,126 @@
package net.osmand.plus.settings.fragments;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
public class TroubleshootingOrPurchasingCard extends BaseCard {
private static final String OSMAND_NEW_DEVICE_URL = "https://docs.osmand.net/en/main@latest/osmand/purchases#new-device--new-account";
private static final String OSMAND_EMAIL = "support@osmand.net";
private static final String EMAIL_DEEPLINK_URI = "mailto:support@osmand.net";
protected InAppPurchaseHelper purchaseHelper;
private final boolean isPaidVersion;
@Override
public int getCardLayoutId() {
return isPaidVersion ? R.layout.troubleshooting_card : R.layout.no_purchases_card;
}
public TroubleshootingOrPurchasingCard(@NonNull MapActivity mapActivity, @NonNull InAppPurchaseHelper purchaseHelper, boolean isPaidVersion) {
super(mapActivity);
this.purchaseHelper = purchaseHelper;
this.isPaidVersion = isPaidVersion;
}
@Override
protected void updateContent() {
setupRestorePurchasesBtn(R.id.restore_purchases);
setupNewDeviceOrAccountBtn(R.id.new_device_account_container);
setupSupportDescription();
setupContactUsLink();
if (!isPaidVersion) {
TextView infoDescription = view.findViewById(R.id.info_description);
String restorePurchases = app.getString(R.string.restore_purchases);
String infoPurchases = String.format(app.getString(R.string.empty_purchases_description), restorePurchases);
infoDescription.setText(infoPurchases);
View osmandLive = view.findViewById(R.id.osmand_live);
osmandLive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChoosePlanDialogFragment.showDialogInstance(getMyApplication(),
mapActivity.getSupportFragmentManager(),
ChoosePlanDialogFragment.ChoosePlanDialogType.OSM_LIVE);
}
});
CardView getItButtonContainer = view.findViewById(R.id.card_view);
int colorRes = nightMode ? R.color.switch_button_active_dark : R.color.switch_button_active_light;
getItButtonContainer.setCardBackgroundColor(ContextCompat.getColor(mapActivity, colorRes));
View getItButton = view.findViewById(R.id.card_container);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(mapActivity, getItButton, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(mapActivity, getItButton, nightMode, R.drawable.btn_unstroked_light, R.drawable.btn_unstroked_dark);
}
}
}
protected void setupRestorePurchasesBtn(@IdRes int btnId) {
View purchasesRestore = view.findViewById(btnId);
purchasesRestore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (purchaseHelper != null) {
purchaseHelper.requestInventory();
}
}
});
}
protected void setupNewDeviceOrAccountBtn(@IdRes int btnId) {
View newDeviceAccountContainer = view.findViewById(btnId);
newDeviceAccountContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(OSMAND_NEW_DEVICE_URL), nightMode);
}
});
}
protected void setupSupportDescription() {
TextView supportDescription = view.findViewById(R.id.support_link_title);
String supportDescriptionString = app.getString(R.string.contact_support_description, OSMAND_EMAIL);
SpannableString spannableStringMail = new SpannableString(supportDescriptionString);
int startIndex = supportDescriptionString.indexOf(OSMAND_EMAIL);
int endIndex = startIndex + OSMAND_EMAIL.length();
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
spannableStringMail.setSpan(boldSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
supportDescription.setText(spannableStringMail);
}
protected void setupContactUsLink() {
TextView contactSupportLink = view.findViewById(R.id.contact_support_title);
SpannableString spannableStringSupport = new SpannableString(app.getString(R.string.contact_support));
spannableStringSupport.setSpan(new URLSpan(EMAIL_DEEPLINK_URI), 0, spannableStringSupport.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contactSupportLink.setText(spannableStringSupport);
AndroidUtils.removeLinkUnderline(contactSupportLink);
contactSupportLink.setMovementMethod(LinkMovementMethod.getInstance());
}
}

View file

@ -110,9 +110,8 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
} }
private void setupSaveButton(View view) { private void setupSaveButton(View view) {
View btnSave = view.findViewById(R.id.btn_save); View btnSaveContainer = view.findViewById(R.id.btn_save_container);
btnSaveContainer.setOnClickListener(new View.OnClickListener() {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Editable editable = editableHtml.getText(); Editable editable = editableHtml.getText();
@ -122,12 +121,16 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
} }
}); });
Context ctx = btnSave.getContext(); Context ctx = btnSaveContainer.getContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(ctx, btnSave, isNightMode(true), R.drawable.ripple_light, R.drawable.ripple_dark); AndroidUtils.setBackground(ctx, btnSaveContainer, isNightMode(true), R.drawable.ripple_light, R.drawable.ripple_dark);
} else { } else {
AndroidUtils.setBackground(ctx, btnSave, isNightMode(true), R.drawable.btn_unstroked_light, R.drawable.btn_unstroked_dark); AndroidUtils.setBackground(ctx, btnSaveContainer, isNightMode(true), R.drawable.btn_unstroked_light, R.drawable.btn_unstroked_dark);
} }
View btnSave = view.findViewById(R.id.btn_save);
int drawableRes = isNightMode(true) ? R.drawable.btn_solid_border_dark : R.drawable.btn_solid_border_light;
AndroidUtils.setBackground(btnSave, getMyApplication().getUIUtilities().getIcon(drawableRes));
} }
private void showDismissDialog() { private void showDismissDialog() {