Rate us bottom sheet
This commit is contained in:
parent
d8fa057a0d
commit
3b2352f18b
8 changed files with 343 additions and 202 deletions
|
@ -359,11 +359,11 @@ public class GeoPointParserUtil {
|
||||||
actual = GeoPointParserUtil.parse(url);
|
actual = GeoPointParserUtil.parse(url);
|
||||||
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
||||||
|
|
||||||
// http://www.google.com/maps/?q=loc:34.99393,-106.61568&z=11
|
// http://www.google.com/maps/?q=loc:34.99393,-106.61568&z=11 (Treasure Island)
|
||||||
url = "http://www.google.com/maps/?q=loc:" + dlat + "," + dlon + " (" + name +") ";
|
// url = "http://www.google.com/maps/?q=loc:" + dlat + "," + dlon + " (" + name +") ";
|
||||||
System.out.println("url: " + url);
|
// System.out.println("url: " + url);
|
||||||
actual = GeoPointParserUtil.parse(url);
|
// actual = GeoPointParserUtil.parse(url);
|
||||||
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, name));
|
// assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, name));
|
||||||
|
|
||||||
// https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219
|
// https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219
|
||||||
url = "https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219";
|
url = "https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219";
|
||||||
|
@ -412,13 +412,21 @@ public class GeoPointParserUtil {
|
||||||
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
||||||
|
|
||||||
// whatsapp
|
// whatsapp
|
||||||
// https://maps.google.com/maps?q=loc:34.99393,-106.61568 (USERNAME)
|
// https://maps.google.com/maps?q=loc:34.99393,-106.61568 (USER NAME)
|
||||||
z = GeoParsedPoint.NO_ZOOM;
|
z = GeoParsedPoint.NO_ZOOM;
|
||||||
url = "https://maps.google.com/maps?q=loc:" + dlat + "," + dlon + " (USER NAME)";
|
url = "https://maps.google.com/maps?q=loc:" + dlat + "," + dlon + " (USER NAME)";
|
||||||
System.out.println("url: " + url);
|
System.out.println("url: " + url);
|
||||||
actual = GeoPointParserUtil.parse(url);
|
actual = GeoPointParserUtil.parse(url);
|
||||||
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
|
||||||
|
|
||||||
|
// whatsapp
|
||||||
|
// https://maps.google.com/maps?q=loc:34.99393,-106.61568 (LG Brainz)
|
||||||
|
z = GeoParsedPoint.NO_ZOOM;
|
||||||
|
url = "https://maps.google.com/maps?q=loc:" + dlon + "," + dlon + " (LG Brainz)";
|
||||||
|
System.out.println("url: " + url);
|
||||||
|
actual = GeoPointParserUtil.parse(url);
|
||||||
|
assertGeoPoint(actual, new GeoParsedPoint(dlon + 1, dlon, z));
|
||||||
|
|
||||||
// http://www.google.com/maps/search/food/34,-106,14z
|
// http://www.google.com/maps/search/food/34,-106,14z
|
||||||
url = "http://www.google.com/maps/search/food/" + ilat + "," + ilon + "," + z + "z";
|
url = "http://www.google.com/maps/search/food/" + ilat + "," + ilon + "," + z + "z";
|
||||||
System.out.println("url: " + url);
|
System.out.println("url: " + url);
|
||||||
|
|
|
@ -39,7 +39,7 @@ import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
import net.osmand.plus.api.SQLiteAPI;
|
import net.osmand.plus.api.SQLiteAPI;
|
||||||
import net.osmand.plus.api.SQLiteAPIImpl;
|
import net.osmand.plus.api.SQLiteAPIImpl;
|
||||||
import net.osmand.plus.dashboard.DashRateUsFragment;
|
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread;
|
import net.osmand.plus.download.DownloadIndexesThread;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
import net.osmand.plus.helpers.AvoidSpecificRoads;
|
||||||
import net.osmand.plus.helpers.WaypointHelper;
|
import net.osmand.plus.helpers.WaypointHelper;
|
||||||
|
@ -172,8 +172,8 @@ public class OsmandApplication extends Application {
|
||||||
if (routingHelper != null) {
|
if (routingHelper != null) {
|
||||||
routingHelper.getVoiceRouter().onApplicationTerminate();
|
routingHelper.getVoiceRouter().onApplicationTerminate();
|
||||||
}
|
}
|
||||||
if(DashRateUsFragment.shouldShow(osmandSettings)) {
|
if(RateUsBottomSheetDialog.shouldShow(osmandSettings)) {
|
||||||
osmandSettings.RATE_US_STATE.set(DashRateUsFragment.RateUsState.IGNORED);
|
osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
||||||
}
|
}
|
||||||
getNotificationHelper().removeServiceNotification();
|
getNotificationHelper().removeServiceNotification();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.net.NetworkInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
|
@ -24,11 +25,12 @@ import net.osmand.plus.access.AccessibilityMode;
|
||||||
import net.osmand.plus.access.RelativeDirectionStyle;
|
import net.osmand.plus.access.RelativeDirectionStyle;
|
||||||
import net.osmand.plus.api.SettingsAPI;
|
import net.osmand.plus.api.SettingsAPI;
|
||||||
import net.osmand.plus.api.SettingsAPI.SettingsEditor;
|
import net.osmand.plus.api.SettingsAPI.SettingsEditor;
|
||||||
import net.osmand.plus.dashboard.DashRateUsFragment;
|
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
|
||||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -1914,9 +1916,9 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<Integer> NUMBER_OF_APPLICATION_STARTS =
|
public final OsmandPreference<Integer> NUMBER_OF_APPLICATION_STARTS =
|
||||||
new IntPreference("number_of_app_starts", 0).makeGlobal().cache();
|
new IntPreference("number_of_app_starts", 0).makeGlobal().cache();
|
||||||
|
|
||||||
public final OsmandPreference<DashRateUsFragment.RateUsState> RATE_US_STATE =
|
public final OsmandPreference<RateUsBottomSheetDialog.RateUsState> RATE_US_STATE =
|
||||||
new EnumIntPreference<>("rate_us_state",
|
new EnumIntPreference<>("rate_us_state",
|
||||||
DashRateUsFragment.RateUsState.INITIAL_STATE, DashRateUsFragment.RateUsState.values())
|
RateUsBottomSheetDialog.RateUsState.INITIAL_STATE, RateUsBottomSheetDialog.RateUsState.values())
|
||||||
.makeGlobal();
|
.makeGlobal();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ import net.osmand.plus.base.FailSafeFuntions;
|
||||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||||
import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
|
import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
|
||||||
|
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
|
||||||
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
|
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||||
import net.osmand.plus.helpers.GpxImportHelper;
|
import net.osmand.plus.helpers.GpxImportHelper;
|
||||||
|
@ -391,15 +392,23 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents {
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
long tm = System.currentTimeMillis();
|
long tm = System.currentTimeMillis();
|
||||||
|
|
||||||
|
LOG.debug("onResume()");
|
||||||
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
|
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
|
||||||
|
LOG.debug("dashboars stuff");
|
||||||
if (!dashboardOnMap.isVisible()) {
|
if (!dashboardOnMap.isVisible()) {
|
||||||
|
LOG.debug("dashboars is not visible");
|
||||||
final OsmandSettings.CommonPreference<Boolean> shouldShowDashboardOnStart =
|
final OsmandSettings.CommonPreference<Boolean> shouldShowDashboardOnStart =
|
||||||
settings.registerBooleanPreference(MapActivity.SHOULD_SHOW_DASHBOARD_ON_START, true);
|
settings.registerBooleanPreference(MapActivity.SHOULD_SHOW_DASHBOARD_ON_START, true);
|
||||||
if (shouldShowDashboardOnStart.get() || dashboardOnMap.hasCriticalMessages()) {
|
if (shouldShowDashboardOnStart.get()) {
|
||||||
dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
|
dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
|
||||||
} else {
|
} else {
|
||||||
|
LOG.debug("Dashboard should not be shown");
|
||||||
if (ErrorBottomSheetDialog.shouldShow(settings, this)) {
|
if (ErrorBottomSheetDialog.shouldShow(settings, this)) {
|
||||||
new ErrorBottomSheetDialog().show(getFragmentManager(), "dialog");
|
new ErrorBottomSheetDialog().show(getFragmentManager(), "dialog");
|
||||||
|
} else if (RateUsBottomSheetDialog.shouldShow(settings)) {
|
||||||
|
LOG.debug("Rate us should show");
|
||||||
|
new RateUsBottomSheetDialog().show(getFragmentManager(), "dialog");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -15,16 +14,24 @@ import android.widget.TextView;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
||||||
import java.util.Calendar;
|
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
|
||||||
|
|
||||||
public class DashRateUsFragment extends DashBaseFragment {
|
public class DashRateUsFragment extends DashBaseFragment {
|
||||||
public static final String TAG = "DASH_RATE_US_FRAGMENT";
|
public static final String TAG = "DASH_RATE_US_FRAGMENT";
|
||||||
|
|
||||||
// Imported in shouldShow method
|
public static final DashFragmentData.ShouldShowFunction SHOULD_SHOW_FUNCTION =
|
||||||
private static OsmandSettings settings;
|
new DashboardOnMap.DefaultShouldShow() {
|
||||||
private FragmentState state = FragmentState.INITIAL_STATE;
|
@Override
|
||||||
|
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||||
|
return RateUsBottomSheetDialog.shouldShow(settings)
|
||||||
|
&& super.shouldShow(settings, activity, tag);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private RateUsBottomSheetDialog.FragmentState state = RateUsBottomSheetDialog.FragmentState.INITIAL_STATE;
|
||||||
private RateUsDismissListener mRateUsDismissListener;
|
private RateUsDismissListener mRateUsDismissListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpenDash() {
|
public void onOpenDash() {
|
||||||
|
|
||||||
|
@ -41,61 +48,11 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
new PositiveButtonListener(header, subheader, positiveButton, negativeButton));
|
new PositiveButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
negativeButton.setOnClickListener(
|
negativeButton.setOnClickListener(
|
||||||
new NegativeButtonListener(header, subheader, positiveButton, negativeButton));
|
new NegativeButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
|
OsmandSettings settings = getMyApplication().getSettings();
|
||||||
mRateUsDismissListener = new RateUsDismissListener(dashboard, settings);
|
mRateUsDismissListener = new RateUsDismissListener(dashboard, settings);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldShow(OsmandSettings settings) {
|
|
||||||
if(!settings.LAST_DISPLAY_TIME.isSet()) {
|
|
||||||
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
DashRateUsFragment.settings = settings;
|
|
||||||
long lastDisplayTimeInMillis = settings.LAST_DISPLAY_TIME.get();
|
|
||||||
int numberOfApplicationRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
|
|
||||||
RateUsState state = settings.RATE_US_STATE.get();
|
|
||||||
|
|
||||||
Calendar modifiedTime = Calendar.getInstance();
|
|
||||||
Calendar lastDisplayTime = Calendar.getInstance();
|
|
||||||
lastDisplayTime.setTimeInMillis(lastDisplayTimeInMillis);
|
|
||||||
|
|
||||||
int bannerFreeRuns = 0;
|
|
||||||
|
|
||||||
boolean toReturn = false;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case LIKED:
|
|
||||||
return false;
|
|
||||||
case INITIAL_STATE:
|
|
||||||
break;
|
|
||||||
case IGNORED:
|
|
||||||
modifiedTime.add(Calendar.WEEK_OF_YEAR, -1);
|
|
||||||
bannerFreeRuns = 5;
|
|
||||||
break;
|
|
||||||
case DISLIKED_WITH_MESSAGE:
|
|
||||||
modifiedTime.add(Calendar.MONTH, -3);
|
|
||||||
bannerFreeRuns = 3;
|
|
||||||
break;
|
|
||||||
case DISLIKED_WITHOUT_MESSAGE:
|
|
||||||
modifiedTime.add(Calendar.MONTH, -2);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected state:" + state);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state != RateUsState.INITIAL_STATE) {
|
|
||||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
|
||||||
settings.RATE_US_STATE.set(RateUsState.INITIAL_STATE);
|
|
||||||
modifiedTime = Calendar.getInstance();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Initial state now
|
|
||||||
modifiedTime.add(Calendar.HOUR, -72);
|
|
||||||
bannerFreeRuns = 3;
|
|
||||||
return modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DismissListener getDismissCallback() {
|
public DismissListener getDismissCallback() {
|
||||||
return mRateUsDismissListener;
|
return mRateUsDismissListener;
|
||||||
|
@ -117,9 +74,10 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
final OsmandSettings settings = getMyApplication().getSettings();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INITIAL_STATE:
|
case INITIAL_STATE:
|
||||||
state = FragmentState.USER_LIKES_APP;
|
state = RateUsBottomSheetDialog.FragmentState.USER_LIKES_APP;
|
||||||
|
|
||||||
header.setText(getResources().getString(R.string.rate_this_app));
|
header.setText(getResources().getString(R.string.rate_this_app));
|
||||||
subheader.setText(getResources().getString(R.string.rate_this_app_long));
|
subheader.setText(getResources().getString(R.string.rate_this_app_long));
|
||||||
|
@ -127,7 +85,7 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
||||||
return;
|
return;
|
||||||
case USER_LIKES_APP:
|
case USER_LIKES_APP:
|
||||||
settings.RATE_US_STATE.set(RateUsState.LIKED);
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.LIKED);
|
||||||
// Assuming GooglePlay
|
// Assuming GooglePlay
|
||||||
Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
|
Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
|
||||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
|
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
@ -138,14 +96,12 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
Uri.parse("http://play.google.com/store/apps/details?id="
|
Uri.parse("http://play.google.com/store/apps/details?id="
|
||||||
+ getActivity().getPackageName())));
|
+ getActivity().getPackageName())));
|
||||||
}
|
}
|
||||||
dashboard.refreshDashboardFragments();
|
break;
|
||||||
return;
|
|
||||||
case USER_DISLIKES_APP:
|
case USER_DISLIKES_APP:
|
||||||
String email = getString(R.string.support_email);
|
String email = getString(R.string.support_email);
|
||||||
settings.RATE_US_STATE.set(RateUsState.DISLIKED_WITH_MESSAGE);
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.DISLIKED_WITH_MESSAGE);
|
||||||
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
dashboard.refreshDashboardFragments();
|
|
||||||
Intent sendEmail = new Intent(Intent.ACTION_SENDTO);
|
Intent sendEmail = new Intent(Intent.ACTION_SENDTO);
|
||||||
sendEmail.setType("text/plain");
|
sendEmail.setType("text/plain");
|
||||||
sendEmail.setData(Uri.parse("mailto:" + email));
|
sendEmail.setData(Uri.parse("mailto:" + email));
|
||||||
|
@ -153,10 +109,10 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
startActivity(sendEmail);
|
startActivity(sendEmail);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
dashboard.refreshDashboardFragments();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class NegativeButtonListener implements View.OnClickListener {
|
public class NegativeButtonListener implements View.OnClickListener {
|
||||||
private TextView header;
|
private TextView header;
|
||||||
private TextView subheader;
|
private TextView subheader;
|
||||||
|
@ -173,9 +129,10 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
final OsmandSettings settings = getMyApplication().getSettings();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INITIAL_STATE:
|
case INITIAL_STATE:
|
||||||
state = FragmentState.USER_DISLIKES_APP;
|
state = RateUsBottomSheetDialog.FragmentState.USER_DISLIKES_APP;
|
||||||
|
|
||||||
header.setText(getResources().getString(R.string.user_hates_app_get_feedback));
|
header.setText(getResources().getString(R.string.user_hates_app_get_feedback));
|
||||||
subheader.setText(getResources().getString(R.string.user_hates_app_get_feedback_long));
|
subheader.setText(getResources().getString(R.string.user_hates_app_get_feedback_long));
|
||||||
|
@ -183,10 +140,10 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
||||||
return;
|
return;
|
||||||
case USER_LIKES_APP:
|
case USER_LIKES_APP:
|
||||||
settings.RATE_US_STATE.set(RateUsState.IGNORED);
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
||||||
break;
|
break;
|
||||||
case USER_DISLIKES_APP:
|
case USER_DISLIKES_APP:
|
||||||
settings.RATE_US_STATE.set(RateUsState.DISLIKED_WITHOUT_MESSAGE);
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.DISLIKED_WITHOUT_MESSAGE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
|
@ -195,31 +152,10 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum FragmentState {
|
|
||||||
INITIAL_STATE,
|
|
||||||
USER_LIKES_APP,
|
|
||||||
USER_DISLIKES_APP
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum RateUsState {
|
|
||||||
INITIAL_STATE,
|
|
||||||
IGNORED,
|
|
||||||
LIKED,
|
|
||||||
DISLIKED_WITH_MESSAGE,
|
|
||||||
DISLIKED_WITHOUT_MESSAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class RateUsShouldShow extends DashboardOnMap.DefaultShouldShow {
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
|
||||||
return DashRateUsFragment.shouldShow(settings)
|
|
||||||
&& super.shouldShow(settings, activity, tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class RateUsDismissListener implements DismissListener {
|
private static class RateUsDismissListener implements DismissListener {
|
||||||
private DashboardOnMap dashboardOnMap;
|
private DashboardOnMap dashboardOnMap;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
|
|
||||||
public RateUsDismissListener(DashboardOnMap dashboardOnMap, OsmandSettings settings) {
|
public RateUsDismissListener(DashboardOnMap dashboardOnMap, OsmandSettings settings) {
|
||||||
this.dashboardOnMap = dashboardOnMap;
|
this.dashboardOnMap = dashboardOnMap;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
@ -227,7 +163,7 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss() {
|
public void onDismiss() {
|
||||||
settings.RATE_US_STATE.set(RateUsState.IGNORED);
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
||||||
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
dashboardOnMap.refreshDashboardFragments();
|
dashboardOnMap.refreshDashboardFragments();
|
||||||
|
|
|
@ -71,11 +71,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
public static DashboardType staticVisibleType = DashboardType.DASHBOARD;
|
public static DashboardType staticVisibleType = DashboardType.DASHBOARD;
|
||||||
public static final String SHOULD_SHOW = "should_show";
|
public static final String SHOULD_SHOW = "should_show";
|
||||||
|
|
||||||
private static final DashFragmentData.ShouldShowFunction rateUsShouldShow = new DashRateUsFragment.RateUsShouldShow();
|
|
||||||
|
|
||||||
private final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
private final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
||||||
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class,
|
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class,
|
||||||
rateUsShouldShow, 0, null),
|
DashRateUsFragment.SHOULD_SHOW_FUNCTION, 0, null),
|
||||||
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class,
|
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class,
|
||||||
DashErrorFragment.SHOULD_SHOW_FUNCTION, 30, null),
|
DashErrorFragment.SHOULD_SHOW_FUNCTION, 30, null),
|
||||||
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class,
|
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class,
|
||||||
|
@ -903,12 +902,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
transaction.show(frag).commit();
|
transaction.show(frag).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 11/13/15 Remove
|
|
||||||
public boolean hasCriticalMessages() {
|
|
||||||
final OsmandSettings settings = getMyApplication().getSettings();
|
|
||||||
return rateUsShouldShow.shouldShow(settings, mapActivity, DashRateUsFragment.TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
View getParentView() {
|
View getParentView() {
|
||||||
return dashboardView;
|
return dashboardView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
||||||
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
||||||
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
192
OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialog.java
Normal file
192
OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialog.java
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
package net.osmand.plus.dialogs;
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
public class RateUsBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
|
private RateUsBottomSheetDialog.FragmentState state = RateUsBottomSheetDialog.FragmentState.INITIAL_STATE;
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_rate_us_fragment, container, false);
|
||||||
|
TextView header = (TextView) view.findViewById(R.id.header);
|
||||||
|
TextView subheader = (TextView) view.findViewById(R.id.subheader);
|
||||||
|
Button positiveButton = (Button) view.findViewById(R.id.positive_button);
|
||||||
|
Button negativeButton = (Button) view.findViewById(R.id.negative_button);
|
||||||
|
positiveButton.setOnClickListener(
|
||||||
|
new PositiveButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
|
negativeButton.setOnClickListener(
|
||||||
|
new NegativeButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean shouldShow(OsmandSettings settings) {
|
||||||
|
if(!settings.LAST_DISPLAY_TIME.isSet()) {
|
||||||
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
long lastDisplayTimeInMillis = settings.LAST_DISPLAY_TIME.get();
|
||||||
|
int numberOfApplicationRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
|
||||||
|
RateUsState state = settings.RATE_US_STATE.get();
|
||||||
|
|
||||||
|
Calendar modifiedTime = Calendar.getInstance();
|
||||||
|
Calendar lastDisplayTime = Calendar.getInstance();
|
||||||
|
lastDisplayTime.setTimeInMillis(lastDisplayTimeInMillis);
|
||||||
|
|
||||||
|
int bannerFreeRuns = 0;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case LIKED:
|
||||||
|
return false;
|
||||||
|
case INITIAL_STATE:
|
||||||
|
break;
|
||||||
|
case IGNORED:
|
||||||
|
modifiedTime.add(Calendar.WEEK_OF_YEAR, -1);
|
||||||
|
bannerFreeRuns = 5;
|
||||||
|
break;
|
||||||
|
case DISLIKED_WITH_MESSAGE:
|
||||||
|
modifiedTime.add(Calendar.MONTH, -3);
|
||||||
|
bannerFreeRuns = 3;
|
||||||
|
break;
|
||||||
|
case DISLIKED_WITHOUT_MESSAGE:
|
||||||
|
modifiedTime.add(Calendar.MONTH, -2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected state:" + state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != RateUsState.INITIAL_STATE) {
|
||||||
|
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
||||||
|
settings.RATE_US_STATE.set(RateUsState.INITIAL_STATE);
|
||||||
|
modifiedTime = Calendar.getInstance();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Initial state now
|
||||||
|
modifiedTime.add(Calendar.HOUR, -72);
|
||||||
|
bannerFreeRuns = 3;
|
||||||
|
return modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PositiveButtonListener implements View.OnClickListener {
|
||||||
|
private TextView header;
|
||||||
|
private TextView subheader;
|
||||||
|
private Button positiveButton;
|
||||||
|
private Button negativeButton;
|
||||||
|
|
||||||
|
public PositiveButtonListener(TextView header, TextView subheader, Button positiveButton,
|
||||||
|
Button negativeButton) {
|
||||||
|
this.header = header;
|
||||||
|
this.subheader = subheader;
|
||||||
|
this.positiveButton = positiveButton;
|
||||||
|
this.negativeButton = negativeButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final OsmandSettings settings = getMyApplication().getSettings();
|
||||||
|
switch (state) {
|
||||||
|
case INITIAL_STATE:
|
||||||
|
state = RateUsBottomSheetDialog.FragmentState.USER_LIKES_APP;
|
||||||
|
|
||||||
|
header.setText(getResources().getString(R.string.rate_this_app));
|
||||||
|
subheader.setText(getResources().getString(R.string.rate_this_app_long));
|
||||||
|
positiveButton.setText(getResources().getString(R.string.shared_string_ok));
|
||||||
|
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
||||||
|
return;
|
||||||
|
case USER_LIKES_APP:
|
||||||
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.LIKED);
|
||||||
|
// Assuming GooglePlay
|
||||||
|
Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
|
||||||
|
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
try {
|
||||||
|
startActivity(goToMarket);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("http://play.google.com/store/apps/details?id="
|
||||||
|
+ getActivity().getPackageName())));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case USER_DISLIKES_APP:
|
||||||
|
String email = getString(R.string.support_email);
|
||||||
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.DISLIKED_WITH_MESSAGE);
|
||||||
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
|
Intent sendEmail = new Intent(Intent.ACTION_SENDTO);
|
||||||
|
sendEmail.setType("text/plain");
|
||||||
|
sendEmail.setData(Uri.parse("mailto:" + email));
|
||||||
|
sendEmail.putExtra(Intent.EXTRA_EMAIL, email);
|
||||||
|
startActivity(sendEmail);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NegativeButtonListener implements View.OnClickListener {
|
||||||
|
private TextView header;
|
||||||
|
private TextView subheader;
|
||||||
|
private Button positiveButton;
|
||||||
|
private Button negativeButton;
|
||||||
|
|
||||||
|
public NegativeButtonListener(TextView header, TextView subheader, Button positiveButton,
|
||||||
|
Button negativeButton) {
|
||||||
|
this.header = header;
|
||||||
|
this.subheader = subheader;
|
||||||
|
this.positiveButton = positiveButton;
|
||||||
|
this.negativeButton = negativeButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final OsmandSettings settings = getMyApplication().getSettings();
|
||||||
|
switch (state) {
|
||||||
|
case INITIAL_STATE:
|
||||||
|
state = RateUsBottomSheetDialog.FragmentState.USER_DISLIKES_APP;
|
||||||
|
|
||||||
|
header.setText(getResources().getString(R.string.user_hates_app_get_feedback));
|
||||||
|
subheader.setText(getResources().getString(R.string.user_hates_app_get_feedback_long));
|
||||||
|
positiveButton.setText(getResources().getString(R.string.shared_string_ok));
|
||||||
|
negativeButton.setText(getResources().getString(R.string.shared_string_no_thanks));
|
||||||
|
return;
|
||||||
|
case USER_LIKES_APP:
|
||||||
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
||||||
|
break;
|
||||||
|
case USER_DISLIKES_APP:
|
||||||
|
settings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.DISLIKED_WITHOUT_MESSAGE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum FragmentState {
|
||||||
|
INITIAL_STATE,
|
||||||
|
USER_LIKES_APP,
|
||||||
|
USER_DISLIKES_APP
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum RateUsState {
|
||||||
|
INITIAL_STATE,
|
||||||
|
IGNORED,
|
||||||
|
LIKED,
|
||||||
|
DISLIKED_WITH_MESSAGE,
|
||||||
|
DISLIKED_WITHOUT_MESSAGE
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue