feature: support db import on Android
This commit is contained in:
parent
8ba6f4bf85
commit
d3af69b31e
@ -24,8 +24,11 @@ namespace Billing
|
|||||||
private static List<Account> accounts;
|
private static List<Account> accounts;
|
||||||
private static List<Category> categories;
|
private static List<Category> categories;
|
||||||
|
|
||||||
public App()
|
private string initialUrl;
|
||||||
|
|
||||||
|
public App(string url = null)
|
||||||
{
|
{
|
||||||
|
initialUrl = url;
|
||||||
CurrentCulture = new PlatformCulture();
|
CurrentCulture = new PlatformCulture();
|
||||||
InitResources();
|
InitResources();
|
||||||
|
|
||||||
@ -36,6 +39,13 @@ namespace Billing
|
|||||||
{
|
{
|
||||||
Helper.Debug($"personal folder: {StoreHelper.PersonalFolder}");
|
Helper.Debug($"personal folder: {StoreHelper.PersonalFolder}");
|
||||||
Helper.Debug($"cache folder: {StoreHelper.CacheFolder}");
|
Helper.Debug($"cache folder: {StoreHelper.CacheFolder}");
|
||||||
|
|
||||||
|
if (initialUrl != null)
|
||||||
|
{
|
||||||
|
var url = initialUrl;
|
||||||
|
initialUrl = null;
|
||||||
|
_ = OpenUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task InitializeData()
|
public static async Task InitializeData()
|
||||||
@ -83,17 +93,25 @@ namespace Billing
|
|||||||
Resources = instance;
|
Resources = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool OpenUrl(Uri uri)
|
public static async Task<bool> OpenUrl(string url)
|
||||||
{
|
{
|
||||||
if (uri == null || !uri.IsFile)
|
if (string.IsNullOrEmpty(url))
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
var absolute = uri.AbsolutePath;
|
|
||||||
var url = System.Net.WebUtility.UrlDecode(absolute);
|
|
||||||
if (File.Exists(url))
|
if (File.Exists(url))
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
var status = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
|
||||||
|
if (status != PermissionStatus.Disabled &&
|
||||||
|
status != PermissionStatus.Granted)
|
||||||
|
{
|
||||||
|
status = await Permissions.RequestAsync<Permissions.StorageRead>();
|
||||||
|
}
|
||||||
|
if (status != PermissionStatus.Granted)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var result = await StoreHelper.ReloadDatabase(url);
|
var result = await StoreHelper.ReloadDatabase(url);
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -37,11 +37,11 @@
|
|||||||
<EnableLLVM>false</EnableLLVM>
|
<EnableLLVM>false</EnableLLVM>
|
||||||
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
|
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
|
||||||
<BundleAssemblies>false</BundleAssemblies>
|
<BundleAssemblies>false</BundleAssemblies>
|
||||||
<AndroidSupportedAbis>x86_64;x86</AndroidSupportedAbis>
|
<AndroidSupportedAbis>x86;x86_64;arm64-v8a</AndroidSupportedAbis>
|
||||||
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
|
<EmbedAssembliesIntoApk>false</EmbedAssembliesIntoApk>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>false</DebugSymbols>
|
||||||
<DebugType>portable</DebugType>
|
<DebugType>portable</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release</OutputPath>
|
<OutputPath>bin\Release</OutputPath>
|
||||||
@ -54,6 +54,10 @@
|
|||||||
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
|
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
|
||||||
<BundleAssemblies>false</BundleAssemblies>
|
<BundleAssemblies>false</BundleAssemblies>
|
||||||
<AndroidSupportedAbis>arm64-v8a</AndroidSupportedAbis>
|
<AndroidSupportedAbis>arm64-v8a</AndroidSupportedAbis>
|
||||||
|
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
|
||||||
|
<AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
|
||||||
|
<AndroidLinkTool>r8</AndroidLinkTool>
|
||||||
|
<MandroidI18n />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Mono.Android" />
|
<Reference Include="Mono.Android" />
|
||||||
@ -130,44 +134,64 @@
|
|||||||
</Generator>
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\layout\RadioGroup.xml">
|
<AndroidResource Include="Resources\layout\RadioGroup.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\layout\RadioButton.xml">
|
<AndroidResource Include="Resources\layout\RadioButton.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\color\segmented_control_text.xml">
|
<AndroidResource Include="Resources\color\segmented_control_text.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable\segmented_control_background.xml">
|
<AndroidResource Include="Resources\drawable\segmented_control_background.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable\segmented_control_first_background.xml">
|
<AndroidResource Include="Resources\drawable\segmented_control_first_background.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable\segmented_control_last_background.xml">
|
<AndroidResource Include="Resources\drawable\segmented_control_last_background.xml">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable\share.png">
|
<AndroidResource Include="Resources\drawable\share.png">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable-mdpi\share.png">
|
<AndroidResource Include="Resources\drawable-mdpi\share.png">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable-xhdpi\share.png">
|
<AndroidResource Include="Resources\drawable-xhdpi\share.png">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
<AndroidResource Include="Resources\drawable-xxhdpi\share.png">
|
<AndroidResource Include="Resources\drawable-xxhdpi\share.png">
|
||||||
<SubType></SubType>
|
<SubType>
|
||||||
<Generator></Generator>
|
</SubType>
|
||||||
|
<Generator>
|
||||||
|
</Generator>
|
||||||
</AndroidResource>
|
</AndroidResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -583,10 +607,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AndroidResource Include="Resources\drawable\left.png" />
|
<AndroidResource Include="Resources\drawable\left.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="Resources\layout\" />
|
|
||||||
<Folder Include="Resources\color\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="..\..\Billing.Shared\Billing.Shared.projitems" Label="Shared" />
|
<Import Project="..\..\Billing.Shared\Billing.Shared.projitems" Label="Shared" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -1,7 +1,9 @@
|
|||||||
using Android.App;
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
using Android.Runtime;
|
using Android.Runtime;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
|
using Android.Net;
|
||||||
|
|
||||||
namespace Billing.Droid
|
namespace Billing.Droid
|
||||||
{
|
{
|
||||||
@ -18,9 +20,22 @@ namespace Billing.Droid
|
|||||||
{
|
{
|
||||||
base.OnCreate(savedInstanceState);
|
base.OnCreate(savedInstanceState);
|
||||||
|
|
||||||
|
string url;
|
||||||
|
if (Intent.ActionView.Equals(Intent.Action) && Intent.Data is Uri uri)
|
||||||
|
{
|
||||||
|
url = uri.Path;
|
||||||
|
if (url != null && url.StartsWith("/root"))
|
||||||
|
{
|
||||||
|
url = url[5..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = null;
|
||||||
|
}
|
||||||
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
||||||
Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
||||||
LoadApplication(new App());
|
LoadApplication(new App(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
|
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
|
||||||
|
@ -27,3 +27,4 @@ using Android.App;
|
|||||||
// Add some common permissions, these can be removed if not needed
|
// Add some common permissions, these can be removed if not needed
|
||||||
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
|
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
|
||||||
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
|
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
|
||||||
|
[assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)]
|
||||||
|
@ -14,7 +14,7 @@ namespace Billing.Droid
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.2.0.155")]
|
||||||
public partial class Resource
|
public partial class Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
|
using Android.Net;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using AndroidX.AppCompat.App;
|
using AndroidX.AppCompat.App;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,6 +12,12 @@ namespace Billing.Droid
|
|||||||
NoHistory = true,
|
NoHistory = true,
|
||||||
Theme = "@style/MainTheme.Splash",
|
Theme = "@style/MainTheme.Splash",
|
||||||
Name = "org.tsanie.billing.SplashScreen")]
|
Name = "org.tsanie.billing.SplashScreen")]
|
||||||
|
[IntentFilter(
|
||||||
|
new[] { Intent.ActionView },
|
||||||
|
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
|
||||||
|
DataScheme = "file",
|
||||||
|
DataMimeType = "*/*",
|
||||||
|
DataPathPattern = ".*\\\\.db3")]
|
||||||
public class SplashActivity : AppCompatActivity
|
public class SplashActivity : AppCompatActivity
|
||||||
{
|
{
|
||||||
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
|
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
|
||||||
@ -23,7 +30,16 @@ namespace Billing.Droid
|
|||||||
protected override void OnResume()
|
protected override void OnResume()
|
||||||
{
|
{
|
||||||
base.OnResume();
|
base.OnResume();
|
||||||
Task.Run(() => StartActivity(new Intent(Application.Context, typeof(MainActivity))));
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var intent = new Intent(Application.Context, typeof(MainActivity));
|
||||||
|
if (Intent?.Data is Uri uri)
|
||||||
|
{
|
||||||
|
intent.SetAction(Intent.ActionView);
|
||||||
|
intent.SetData(uri);
|
||||||
|
}
|
||||||
|
StartActivity(intent);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,7 +26,11 @@ namespace Billing.iOS
|
|||||||
|
|
||||||
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
|
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
|
||||||
{
|
{
|
||||||
return App.OpenUrl(url);
|
if (url?.IsFileUrl == true)
|
||||||
|
{
|
||||||
|
return App.OpenUrl(url.Path).Result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user