예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            rssReaderService = new RssReaderService(Constants.ConnectionString);

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.Title = GetString(Resource.String.home_header);

            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeAsUpIndicator(Android.Resource.Drawable.IcMenuMore);

            navigationView = FindViewById <NavigationView>(Resource.Id.main_navigationview);
            drawer         = FindViewById <DrawerLayout>(Resource.Id.main_drawer);
            rootview       = FindViewById <RelativeLayout>(Resource.Id.main_rootview);

            addBtn        = FindViewById <FloatingActionButton>(Resource.Id.main_addBtn);
            addBtn.Click += AddBtn_Click;

            rssSourcesListView            = FindViewById <ListView>(Resource.Id.main_rsssourcesListview);
            rssSourceAdapter              = new RssSourceAdapter(this, rssReaderService.GetAllRssSources());
            rssSourcesListView.Adapter    = rssSourceAdapter;
            rssSourcesListView.ItemClick += RssSourcesListView_ItemClick;

            navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

            RegisterForContextMenu(rssSourcesListView);

            var pr = PeriodicWorkRequest.Builder.From <SyncWorker>(TimeSpan.FromSeconds(15))
                     .AddTag("fr.orsys.rssreader.syncworker")
                     .Build();

            WorkManager.Instance.EnqueueUniquePeriodicWork("fr.orsys.rssreader.syncworker", ExistingPeriodicWorkPolicy.Replace, pr);
        }
예제 #2
0
        public override bool OnContextItemSelected(IMenuItem item)
        {
            var menuInfo = (AdapterContextMenuInfo)item.MenuInfo;
            var position = menuInfo.Position;

            if (item.ItemId == 1)
            {
                var rssSource = rssSourceAdapter[position];

                rssReaderService.DeleteRssSource(rssSource.Id);

                rssSourceAdapter = new RssSourceAdapter(this, rssReaderService.GetAllRssSources());

                rssSourcesListView.Adapter = rssSourceAdapter;

                return(true);
            }

            return(base.OnContextItemSelected(item));
        }