1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-18 15:37:42 +01:00
This commit is contained in:
Kyle Spearrin 2019-05-15 13:09:49 -04:00
parent 2c302985f8
commit 264028b623
5 changed files with 73 additions and 1 deletions

View File

@ -261,6 +261,21 @@ namespace Bit.Droid.Services
return result.Task; return result.Task;
} }
public void RateApp()
{
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
try
{
var rateIntent = RateIntentForUrl("market://details", activity);
activity.StartActivity(rateIntent);
}
catch(ActivityNotFoundException)
{
var rateIntent = RateIntentForUrl("https://play.google.com/store/apps/details", activity);
activity.StartActivity(rateIntent);
}
}
private bool DeleteDir(Java.IO.File dir) private bool DeleteDir(Java.IO.File dir)
{ {
if(dir != null && dir.IsDirectory) if(dir != null && dir.IsDirectory)
@ -315,5 +330,22 @@ namespace Bit.Droid.Services
} }
return intents; return intents;
} }
private Intent RateIntentForUrl(string url, Activity activity)
{
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse($"{url}?id={activity.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;
}
} }
} }

View File

@ -16,5 +16,6 @@ namespace Bit.App.Abstractions
Task SelectFileAsync(); Task SelectFileAsync();
Task<string> DisplayPromptAync(string title = null, string description = null, string text = null, Task<string> DisplayPromptAync(string title = null, string description = null, string text = null,
string okButtonText = null, string cancelButtonText = null); string okButtonText = null, string cancelButtonText = null);
void RateApp();
} }
} }

View File

@ -52,6 +52,10 @@ namespace Bit.App.Pages
{ {
await _vm.FingerprintAsync(); await _vm.FingerprintAsync();
} }
else if(item.Name == AppResources.RateTheApp)
{
_vm.Rate();
}
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Bit.App.Resources; using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using System; using System;
@ -13,12 +14,14 @@ namespace Bit.App.Pages
private readonly IPlatformUtilsService _platformUtilsService; private readonly IPlatformUtilsService _platformUtilsService;
private readonly ICryptoService _cryptoService; private readonly ICryptoService _cryptoService;
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IDeviceActionService _deviceActionService;
public SettingsPageViewModel() public SettingsPageViewModel()
{ {
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"); _platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService"); _cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
_userService = ServiceContainer.Resolve<IUserService>("userService"); _userService = ServiceContainer.Resolve<IUserService>("userService");
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
PageTitle = AppResources.Settings; PageTitle = AppResources.Settings;
BuildList(); BuildList();
@ -57,6 +60,11 @@ namespace Bit.App.Pages
} }
} }
public void Rate()
{
_deviceActionService.RateApp();
}
private void BuildList() private void BuildList()
{ {
var doUpper = Device.RuntimePlatform != Device.Android; var doUpper = Device.RuntimePlatform != Device.Android;

View File

@ -16,6 +16,7 @@ using Foundation;
using MobileCoreServices; using MobileCoreServices;
using Photos; using Photos;
using UIKit; using UIKit;
using Xamarin.Forms;
namespace Bit.iOS.Services namespace Bit.iOS.Services
{ {
@ -197,6 +198,21 @@ namespace Bit.iOS.Services
return result.Task; return result.Task;
} }
public void RateApp()
{
string uri = null;
if(SystemMajorVersion() < 11)
{
uri = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews" +
"?id=1137397744&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software";
}
else
{
uri = "itms-apps://itunes.apple.com/us/app/id1137397744?action=write-review";
}
Device.OpenUri(new Uri(uri));
}
private void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) private void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
{ {
if(sender is UIImagePickerController picker) if(sender is UIImagePickerController picker)
@ -313,5 +329,16 @@ namespace Bit.iOS.Services
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
return Path.Combine(documents, "..", "tmp"); return Path.Combine(documents, "..", "tmp");
} }
private int SystemMajorVersion()
{
var versionParts = UIDevice.CurrentDevice.SystemVersion.Split('.');
if(versionParts.Length > 0 && int.TryParse(versionParts[0], out int version))
{
return version;
}
// unable to determine version
return -1;
}
} }
} }