public new void OnClick(Views.View v)
        {
            if (IsMasterDetail() && CoreSettings.AppNav.NavigationStack.Count <= 1)
            {
                CoreDependencyService.SendViewModelMessage(CoreSettings.MasterDetailIsPresented, null);
                return;
            }

            // Call the NavigationPage which will trigger the default behavior
            // The default behavior is to navigate back if the Page derived classes return true from OnBackButtonPressed override
            var curPage = Element.CurrentPage as BasePages;

            if (curPage == null)
            {
                Element.PopAsync();
            }
            else
            {
                if (curPage.NeedOverrideSoftBackButton)
                {
                    curPage.OnSoftBackButtonPressed();
                }
                else
                {
                    Element.PopAsync();
                }
            }
        }
Example #2
0
        public static async Task <PermissionStatus> RequestPermissions(this object caller, Permission permission, string dialogTitle, string dialogMessage)
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);

            if (status != PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(permission))
                {
                    CoreDependencyService.GetDependency <IDialogPrompt>().ShowMessage(new Prompt()
                    {
                        Title   = dialogTitle,
                        Message = dialogMessage
                    });
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { permission });

#if __ANDROID__
                if (Looper.MyLooper() == null)
                {
                    Looper.Prepare();
                }
#endif
                status = results[permission];
            }

            return(status);
        }
Example #3
0
 /// <summary>
 /// Save the state of the view model.  Used for when the application may teardown the memory losing the property
 /// values of the view model.
 /// </summary>
 /// <param name="vm">Vm.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void SaveState <T>(this T vm) where T : CoreViewModel, new()
 {
     Task.Run(async() =>
     {
         await CoreDependencyService.GetService <IFileStore, FileStore>(true)?.SaveAsync <T>(typeof(T).FullName, vm);
     });
 }
Example #4
0
 public static void Reload()
 {
     CoreDependencyService.DisposeServices();
     CoreDependencyService.ReleaseAllResources();
     Load();
     CoreDependencyService.ReloadAllResources();
 }
        private static void ParseCVS(string data)
        {
            var storage   = (IFileStore)CoreDependencyService.GetService <IFileStore, FileStore>(true);
            var lines     = data.Split('\r');
            var fileNames = lines[0].Split(',');
            var fileData  = new Dictionary <string, Dictionary <string, string> >();

            for (int x = 1; x < fileNames.Length; x++)
            {
                fileData.Add(fileNames[x], new Dictionary <string, string>());
            }

            for (int x = 1; x < lines.Length; x++)
            {
                var columns = lines[x].Split(',');
                var varName = columns[0];
                for (int y = 1; y < columns.Length; y++)
                {
                    var lang = fileNames[y];
                    fileData[lang].Add(varName, columns[y].Replace("\n", string.Empty));
                }
            }

            foreach (var key in fileData.Keys)
            {
                storage.SaveAsync <Dictionary <string, string> >($"{key}.json", fileData[key]).ContinueOn();
            }
        }
Example #6
0
 public void CallEndedEvent(CTCall call)
 {
     if (TelephoneManager.IsListening && call.CallState == "CTCallStateDisconnected")
     {
         TelephoneManager.IsListening = false;
         CoreDependencyService.SendViewModelMessage(TelephoneManager.CallBackKey, true);
     }
 }
Example #7
0
 /// <summary>
 /// Loads the state of the view model to ensure if torndown by the OS, it can regain the property values.
 /// </summary>
 /// <param name="vm">Vm.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void LoadState <T>(this T vm) where T : CoreViewModel, new()
 {
     Task.Run(async() =>
     {
         var result = await CoreDependencyService.GetService <IFileStore, FileStore>(true)?.GetAsync <T>(typeof(T).FullName);
         if (result.Error == null)
         {
             foreach (var prop in typeof(T).GetProperties())
             {
                 prop.SetValue(vm, prop.GetValue(result.Response));
             }
         }
     });
 }
        public LocalizationService()
        {
            var culture  = CoreDependencyService.GetDependency <ILocalize>().GetCurrentCultureInfo();
            var fileName = $"{culture.TwoLetterISOLanguageName.ToLower()}.json";

            var storage = (IFileStore)CoreDependencyService.GetService <IFileStore, FileStore>(true);

            storage.GetAsync <Dictionary <string, string> >(fileName).ContinueWith((data) =>
            {
                if (data.Result.Success)
                {
                    IsLoaded    = true;
                    localString = data.Result.Response;
                    CoreDependencyService.SendViewModelMessage(CoreSettings.LocalizationLoaded, null);
                }
            });
        }
        public static void Init(string version)
        {
            var savedVersion = CrossSettings.Current.GetValueOrDefault("localizationversion", null);

            if (savedVersion == null || !savedVersion.Equals(version))
            {
                var fileString = ResourceLoader.GetEmbeddedResourceString(Assembly.GetAssembly(typeof(ResourceLoader)), "localization.csv");
                if (fileString.Error == null)
                {
                    ParseCVS(fileString.Response);
                }
                CrossSettings.Current.AddOrUpdateValue("localizationversion", version);
                CoreDependencyService.GetService <ILocalizationService, LocalizationService>(true);
            }
            else
            {
                CoreDependencyService.GetService <ILocalizationService, LocalizationService>(true);
            }
        }
 public CoreMasterDetailPage()
 {
     VM = CoreDependencyService.GetViewModel <T>();
     this.BindingContext = VM;
 }
Example #11
0
 /// <summary>
 /// Broadcast message to a particular view model instance
 /// </summary>
 /// <param name="key">Key.</param>
 /// <param name="obj">Object.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 protected void SendViewMessage <T>(string key, object obj) where T : CoreViewModel
 {
     CoreDependencyService.SendViewModelMessage <T>(key, obj);
 }
Example #12
0
 /// <summary>
 /// Broadcast message to all view model instances
 /// </summary>
 /// <param name="key">Key.</param>
 /// <param name="obj">Object.</param>
 protected void SendViewMessage(string key, object obj)
 {
     CoreDependencyService.SendViewModelMessage(key, obj);
 }