private void LoadConfig() { if (PermissionChecker.HasManageStoragePermission(this)) { SelectFile(); } else { AndroidApplication.Logger.Debug(() => $"MainActivity:LoadConfig - permission not granted - requesting"); PermissionRequester.RequestManageStoragePermission(this, PermissionRequester.REQUEST_CODE_WRITE_EXTERNAL_STORAGE_PERMISSION, AndroidApplication.PackageName); } }
public override bool OnOptionsItemSelected(IMenuItem item) { if (!PermissionChecker.HasManageStoragePermission(this)) { ToastMessage(GetString(Resource.String.manage_external_permissions_rationale)); return(base.OnOptionsItemSelected(item)); } if (ViewModel.ActionSelected(item.ItemId)) { return(true); } return(base.OnOptionsItemSelected(item)); }
protected override void OnResume() { AndroidApplication.Logger.Debug(() => $"MainActivity:OnResume - observers {GetObserverCount()}"); base.OnResume(); if (PermissionChecker.HasManageStoragePermission(this)) { AndroidApplication.Logger.Debug(() => $"MainActivity:OnResume - we have manage storage"); ViewModel?.RefreshFileSystemInfo(); AndroidApplication.Logger.Debug(() => $"MainActivity:OnResume - write storage permission = {PermissionChecker.HasWriteStoragePermission(this)}"); if (!PermissionChecker.HasWriteStoragePermission(this)) { PermissionRequester.RequestWriteStoragePermission(this, PermissionRequester.REQUEST_CODE_WRITE_EXTERNAL_STORAGE_PERMISSION); } } }
protected override void OnCreate(Bundle savedInstanceState) { AndroidApplication = Application as AndroidApplication; AndroidApplication.Logger.Debug(() => $"MainActivity:OnCreate"); base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); DriveInfoContainerView = FindViewById <LinearLayout>(Resource.Id.drive_info_container); NoDriveDataView = FindViewById <TextView>(Resource.Id.txtNoData); RvFeeds = FindViewById <EmptyRecyclerView>(Resource.Id.feed_list); NoFeedView = FindViewById <LinearLayout>(Resource.Id.layNoFeed); CacheRoot = FindViewById <TextView>(Resource.Id.cache_root_value); FeedsTitle = FindViewById <TextView>(Resource.Id.feed_list_label); RvFeeds.SetLayoutManager(new LinearLayoutManager(this)); RvFeeds.AddItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.Vertical)); RvFeeds.SetEmptyView(NoFeedView); FeedAdapter = new PodcastFeedRecyclerItemAdapter(this); RvFeeds.SetAdapter(FeedAdapter); var factory = AndroidApplication.IocContainer.Resolve <ViewModelFactory>(); ViewModel = new ViewModelProvider(this, factory).Get(Java.Lang.Class.FromType(typeof(MainViewModel))) as MainViewModel; Lifecycle.AddObserver(ViewModel); SetupViewModelObservers(); ViewModel.Initialise(); if (!PermissionChecker.HasManageStoragePermission(this)) { AndroidApplication.Logger.Debug(() => $"MainActivity:OnCreate - manage storage permission not granted - requesting"); PermissionRequester.RequestManageStoragePermission(this, PermissionRequester.REQUEST_CODE_WRITE_EXTERNAL_STORAGE_PERMISSION, AndroidApplication.PackageName); } AndroidApplication.Logger.Debug(() => $"MainActivity:OnCreate - end - observers {GetObserverCount()}"); }