protected override void OnHandleIntent(Intent intent) { if (!IsNetworkAvailableAndConnected()) { return; } var query = QueryPreferences.GetStoredQuery(this); var lastResultId = QueryPreferences.GetLastResultId(this); List <GalleryItem> items; if (query == null) { items = new FlickrFetchr().FetchRecentPhotos(); } else { items = new FlickrFetchr().SearchPhotos(query); } if (items.Count != 0) { var resultId = items[0].Id; if (resultId.Equals(lastResultId)) { Log.Info(Tag, $"Got an old result: {resultId}"); } else { Log.Info(Tag, $"Got a new result: {resultId}"); var activityIntent = PhotoGalleryActivity.NewIntent(this); var pendingIntent = PendingIntent.GetActivity(this, 0, activityIntent, 0); var notification = new NotificationCompat.Builder(this, ChannelId) .SetTicker(Resources.GetString(Resource.String.new_pictures_title)) .SetSmallIcon(Android.Resource.Drawable.IcMenuReportImage) .SetContentTitle(Resources.GetString(Resource.String.new_pictures_title)) .SetContentText(Resources.GetString(Resource.String.new_pictures_text)) .SetContentIntent(pendingIntent) .SetAutoCancel(true) .Build(); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var name = GetString(Resource.String.channel_name); var description = GetString(Resource.String.channel_description); var importance = NotificationImportance.Default; var channel = new NotificationChannel(ChannelId, name, importance); var notificationManager = NotificationManager.FromContext(this); notificationManager.CreateNotificationChannel(channel); } NotificationManagerCompat.From(this).Notify(0, notification); } QueryPreferences.SetLastResultId(this, resultId); } }
private void UpdateItems() { var query = QueryPreferences.GetStoredQuery(Activity); new FetchItemsTask(query) { OnPostExecuteImpl = OnItemsFetched }.Execute(); }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.menu_item_clear: QueryPreferences.SetStoredQuery(Activity, null); UpdateItems(); return(true); case Resource.Id.menu_item_toggle_polling: var shouldStartAlarm = !PollService.IsServiceAlarmOn(Activity); PollService.SetServiceAlarm(Activity, shouldStartAlarm); Activity.InvalidateOptionsMenu(); return(true); default: return(base.OnOptionsItemSelected(item)); } }
private void QueryTextSubmitted(object sender, Android.Support.V7.Widget.SearchView.QueryTextSubmitEventArgs e) { Log.Debug(Tag, $"QueryTextSubmit: {e.Query}"); QueryPreferences.SetStoredQuery(Activity, e.Query); UpdateItems(); }
private void SearchViewClicked() { var query = QueryPreferences.GetStoredQuery(Activity); _searchView.SetQuery(query, false); }