using System;
using Serilog;
using ShareeBike.Model.Device;
using Xamarin.Forms;
[assembly: Dependency(typeof(ShareeBike.Droid.Model.Device.SpecialFolder))]
namespace ShareeBike.Droid.Model.Device
{
public class SpecialFolder : ISpecialFolder
{
/// Get the folder name of external folder to write to.
/// Name of the external folder.
public string GetExternalFilesDir()
{
string baseFolderPath = string.Empty;
try
{
var context = Android.App.Application.Context;
Java.IO.File[] dirs = context.GetExternalFilesDirs(null);
foreach (Java.IO.File folder in dirs)
{
bool IsRemovable = Android.OS.Environment.InvokeIsExternalStorageRemovable(folder);
bool IsEmulated = Android.OS.Environment.InvokeIsExternalStorageEmulated(folder);
if (IsRemovable
&& !IsEmulated)
{
baseFolderPath = folder.Path;
}
}
}
catch (Exception l_oException)
{
Log.Error("Getting external files directory failed. {@l_oException}", l_oException);
}
return baseFolderPath;
}
/// Gets the folder name of the personal data folder dir on internal storage.
/// Directory name.
public string GetInternalPersonalDir()
{
return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
}
}
}