private void CheckServerNotifications(Context pContext, string sClan, string sName) { XElement pResponse = null; //try //{ string sPrevClan = Master.GetActiveClan(); string sPrevUser = Master.GetActiveUserName(); Master.SetActiveClan(sClan); Master.SetActiveUserName(sName); string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetUnseenNotifications", Master.BuildCommonBody(), true); pResponse = Master.ReadResponse(sResponse); Master.SetActiveClan(sPrevClan); Master.SetActiveUserName(sPrevUser); //} //catch (Exception e) { return; } if (pResponse.Element("Data") != null && pResponse.Element("Data").Element("Notifications").Value != "") { List <XElement> pNotifications = pResponse.Element("Data").Element("Notifications").Elements("Notification").ToList(); foreach (XElement pNotification in pNotifications) { string sContent = pNotification.Value; string sGameID = pNotification.Attribute("GameID").Value; string sGameName = pNotification.Attribute("GameName").Value; Notification.Builder pBuilder = new Notification.Builder(pContext); pBuilder.SetContentTitle(sClan + " - " + sGameName); pBuilder.SetContentText(sContent); pBuilder.SetSmallIcon(Resource.Drawable.Icon); pBuilder.SetVibrate(new long[] { 200, 50, 200, 50 }); pBuilder.SetVisibility(NotificationVisibility.Public); pBuilder.SetPriority((int)NotificationPriority.Default); Intent pIntent = null; if (sGameID.Contains("Zendo")) { pIntent = new Intent(pContext, typeof(ZendoActivity)); } pIntent.SetAction(sGameID); pIntent.PutExtra("GameName", sGameName); pBuilder.SetContentIntent(PendingIntent.GetActivity(pContext, 0, pIntent, 0)); pBuilder.SetStyle(new Notification.BigTextStyle().BigText(sContent)); Notification pNotif = pBuilder.Build(); NotificationManager pManager = (NotificationManager)pContext.GetSystemService(Context.NotificationService); pManager.Notify((int)Java.Lang.JavaSystem.CurrentTimeMillis(), pNotif); // using time to make different ID every time, so doesn't replace old notification //pManager.Notify(DateTime.Now.Millisecond, pNotif); // using time to make different ID every time, so doesn't replace old notification } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); _hidden.InitializeWeb(); _RunTempCommands(); // TODO: REMOVE if (!this.CheckVersion()) { return; } // make sure that all the necessary files exist if (!File.Exists(Master.GetBaseDir() + "_clans.dat")) { File.Create(Master.GetBaseDir() + "_clans.dat").Dispose(); } if (!File.Exists(Master.GetBaseDir() + "_settings.dat")) { File.WriteAllText(Master.GetBaseDir() + "_settings.dat", "notifications=on"); } if (!File.Exists(Master.GetBaseDir() + "_key.dat")) { //Intent pIntent = new Intent(this, (new KeyActivity().Class)); Intent pIntent = new Intent(this, typeof(RegisterOrLogInActivity)); StartActivity(pIntent); } else { Master.FillKeyEmail(); } // TODO: save temp currently active clan so persistent between app open times, and load it here if (File.Exists(Master.GetBaseDir() + "_active.dat")) { string[] aLines = File.ReadAllLines(Master.GetBaseDir() + "_active.dat"); Master.SetActiveClan(aLines[0]); Master.SetActiveUserName(aLines[1]); } // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); base.CreateDrawer(); if (Master.GetActiveClan() != "") { this.Title = Master.GetActiveClan() + " - " + Master.GetActiveUserName(); this.BuildHomeDashboard(); } //StartService(new Intent(this, typeof(NotificationsService))); }
private void BuildHomeDashboard() { // get the scoreboard from the server string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetClanLeaderboard", Master.BuildCommonBody(), true); XElement pResponse = Master.ReadResponse(sResponse); // build the scoreboard if (pResponse.Element("Data").Element("Leaderboard") != null) { XElement pLeaderboard = pResponse.Element("Data").Element("Leaderboard"); TextView pMyUser = FindViewById <TextView>(Resource.Id.lblMyStatsName); TextView pMyScore = FindViewById <TextView>(Resource.Id.lblMyStatsScore); TextView pMyPlace = FindViewById <TextView>(Resource.Id.lblMyStatsPlace); pMyUser.Text = Master.GetActiveUserName(); pMyScore.Text = pLeaderboard.Attribute("Score").Value; pMyPlace.Text = pLeaderboard.Attribute("Place").Value; LinearLayout pScoreboardLayout = FindViewById <LinearLayout>(Resource.Id.lstScoreBoard); pScoreboardLayout.RemoveAllViews(); foreach (XElement pScoreXml in pLeaderboard.Elements("Score")) { View pScoreRow = LayoutInflater.From(this).Inflate(Resource.Layout.ScoreRow, pScoreboardLayout, false); TextView pUser = pScoreRow.FindViewById <TextView>(Resource.Id.lblScoreName); TextView pPlace = pScoreRow.FindViewById <TextView>(Resource.Id.lblScorePlace); TextView pScore = pScoreRow.FindViewById <TextView>(Resource.Id.lblScoreScore); pUser.Text = pScoreXml.Attribute("User").Value; pPlace.Text = pScoreXml.Attribute("Place").Value; pScore.Text = pScoreXml.Attribute("Score").Value; pScoreboardLayout.AddView(pScoreRow); } } // get the notifcations list from the server sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetUnreadNotifications", Master.BuildCommonBody(), true); pResponse = Master.ReadResponse(sResponse); LinearLayout pNotifLayout = FindViewById <LinearLayout>(Resource.Id.lstNotifications); pNotifLayout.RemoveAllViews(); if (pResponse.Element("Data").Element("Notifications") != null) { foreach (XElement pNotif in pResponse.Element("Data").Element("Notifications").Elements("Notification")) { // make the datarow layout View pDataRow = LayoutInflater.From(this).Inflate(Resource.Layout.DataRow, pNotifLayout, false); TextView pDataText = pDataRow.FindViewById <TextView>(Resource.Id.txtText); pDataText.Text = pNotif.Attribute("GameName").Value + " - " + pNotif.Value; // reset event handler pDataText.Click -= m_pDataTextDelegate; m_pDataTextDelegate = delegate { string sGameID = pNotif.Attribute("GameID").Value; Intent pIntent = null; if (sGameID.Contains("Zendo")) { pIntent = new Intent(this, typeof(ZendoActivity)); } pIntent.SetAction(sGameID); pIntent.PutExtra("GameName", pNotif.Attribute("GameName").Value); this.Finish(); StartActivity(pIntent); }; pDataText.Click += m_pDataTextDelegate; /*pDataText.Click += delegate * { * string sGameID = pNotif.Attribute("GameID").Value; * Intent pIntent = null; * if (sGameID.Contains("Zendo")) { pIntent = new Intent(this, typeof(ZendoActivity)); } * pIntent.SetAction(sGameID); * pIntent.PutExtra("GameName", pNotif.Attribute("GameName").Value); * this.Finish(); * StartActivity(pIntent); * };*/ pNotifLayout.AddView(pDataRow); } } Button pMarkRead = FindViewById <Button>(Resource.Id.btnMarkRead); pMarkRead.Click += delegate { WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "MarkUnreadNotificationsRead", Master.BuildCommonBody(), true); this.BuildHomeDashboard(); }; }