From e3b44ac7d1eea7292bf07d8c5d64aca5477d61d1 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 17 Aug 2016 23:08:26 -0400 Subject: [PATCH] Added rate app function and message passing for android --- src/Android/MainActivity.cs | 39 ++++++++++++++++++++++ src/Android/Properties/AndroidManifest.xml | 2 +- src/App/Pages/Settings/SettingsPage.cs | 16 ++++++--- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index f77914ca3..e24e351e3 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -13,6 +13,7 @@ using Plugin.Settings.Abstractions; using Plugin.Connectivity.Abstractions; using Acr.UserDialogs; using PushNotification.Plugin.Abstractions; +using Android.Content; namespace Bit.Android { @@ -44,6 +45,12 @@ namespace Bit.Android Resolver.Resolve(), Resolver.Resolve(), Resolver.Resolve())); + + Xamarin.Forms.MessagingCenter.Subscribe( + Xamarin.Forms.Application.Current, "RateApp", (sender) => + { + RateApp(); + }); } protected override void OnPause() @@ -81,5 +88,37 @@ namespace Bit.Android Console.WriteLine("A OnResume"); base.OnResume(); } + + public void RateApp() + { + try + { + var rateIntent = RateIntentForUrl("market://details"); + StartActivity(rateIntent); + } + catch(ActivityNotFoundException) + { + var rateIntent = RateIntentForUrl("https://play.google.com/store/apps/details"); + StartActivity(rateIntent); + } + } + + private Intent RateIntentForUrl(string url) + { + var intent = new Intent(Intent.ActionView, global::Android.Net.Uri.Parse($"{url}?id={PackageName}")); + var flags = ActivityFlags.NoHistory | ActivityFlags.MultipleTask; + if((int)Build.VERSION.SdkInt >= 21) + { + flags |= ActivityFlags.NewDocument; + } + else + { + // noinspection deprecation + flags |= ActivityFlags.ClearWhenTaskReset; + } + + intent.AddFlags(flags); + return intent; + } } } diff --git a/src/Android/Properties/AndroidManifest.xml b/src/Android/Properties/AndroidManifest.xml index f66dc3fce..81be2d7cf 100644 --- a/src/Android/Properties/AndroidManifest.xml +++ b/src/Android/Properties/AndroidManifest.xml @@ -6,7 +6,7 @@ - + \ No newline at end of file diff --git a/src/App/Pages/Settings/SettingsPage.cs b/src/App/Pages/Settings/SettingsPage.cs index b79faa36d..4d4a170c0 100644 --- a/src/App/Pages/Settings/SettingsPage.cs +++ b/src/App/Pages/Settings/SettingsPage.cs @@ -130,7 +130,8 @@ namespace Bit.App.Pages if(Device.OS == TargetPlatform.iOS) { - rateCell.Detail.Text = "App Store ratings are reset with every new version of bitwarden. Please consider helping us out with a good review!"; + rateCell.Detail.Text = "App Store ratings are reset with every new version of bitwarden." + + " Please consider helping us out with a good review!"; } else { @@ -240,11 +241,15 @@ namespace Bit.App.Pages private void RateCell_Tapped(object sender, EventArgs e) { + _googleAnalyticsService.TrackAppEvent("OpenedSetting", "RateApp"); if(Device.OS == TargetPlatform.iOS) { - _googleAnalyticsService.TrackAppEvent("OpenedSetting", "RateApp"); - var appStoreId = "1137397744"; - Device.OpenUri(new Uri($"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id={appStoreId}&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software")); + Device.OpenUri(new Uri($"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews" + + "?id=1137397744&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software")); + } + else if(Device.OS == TargetPlatform.Android) + { + MessagingCenter.Send(Application.Current, "RateApp"); } } @@ -262,7 +267,8 @@ namespace Bit.App.Pages private async void LogOutCell_Tapped(object sender, EventArgs e) { - if(!await _userDialogs.ConfirmAsync("Are you sure you want to log out?", null, AppResources.Yes, AppResources.Cancel)) + if(!await _userDialogs.ConfirmAsync( + "Are you sure you want to log out?", null, AppResources.Yes, AppResources.Cancel)) { return; }