Exemplo n.º 1
0
        private async void Brefresh_Click(object sender, EventArgs e)
        {
            DB_Singleton db = DB_Singleton.Instance;

            RequestHandler request = new RequestHandler(this.BaseContext);

            var response = await request.GetInvitations(db.Retrieve("Token"));

            activeInvites = ConvertJson(response);

            //Prevents duplicating notifications when refreshing
            if (prevent_duplicates != activeInvites.Count)
            {
                //create messages for the listview
                for (int i = 0; i < activeInvites.Count; ++i)
                {
                    message.Insert(i, activeInvites.ElementAt <Invitations>(i).Invitee +
                                   " has invited you to join " + activeInvites.ElementAt <Invitations>(i).Groupname);

                    notif_type.Insert(i, "Group Invite");
                }
                notificationslistview.Adapter = new GroupListAdapter(this, notif_type, message);
            }

            prevent_duplicates = activeInvites.Count;
        }
Exemplo n.º 2
0
        private async Task <List <string> > GetUsers()

        {
            DB_Singleton   db      = DB_Singleton.Instance;
            RequestHandler request = new RequestHandler(Context);

            List <string> users    = new List <string>();
            var           response = await request.GetUserLocations(db.Retrieve("Token"), db.GetActiveGroup().GroupID);

            if (response.Content != "" && response.Content != "[]")
            {
                JArray members = JArray.Parse(response.Content);

                foreach (JToken member in members)
                {
                    string username = (string)member["UserName"];
                    string userid   = (string)member["UserID"];

                    users.Add((username));
                    userIDs.Add(userid);
                }
            }

            return(users);
        }
Exemplo n.º 3
0
        private async void NetworkList_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var listView = sender as ListView;
            var position = e.Position;

            string selected = WifiNetworks.ElementAt <string>(position);

            //Send new location information to database

            DB_Singleton db    = DB_Singleton.Instance;
            var          group = db.GetActiveGroup();

            //adds location to the db using the db_singleton active groupID

            FragmentTransaction transaction = FragmentManager.BeginTransaction();
            List <string>       locations   = await GetLocations();

            if (locations.Contains(selected))
            {
                SsidTaken();
            }
            else
            {
                LocationAddName AddLocationNameDialog = new LocationAddName(db.Retrieve("Token"), selected, group.GroupID);
                AddLocationNameDialog.Show(transaction, "dialog fragment AddLocationName");
            }
        }
Exemplo n.º 4
0
        private void ListView_LongClick(object sender, AdapterView.ItemLongClickEventArgs e)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.SetTitle("Are you sure you want to delete this list?");

            alert.SetPositiveButton("Yes", async(senderAlert, args) =>
            {
                DB_Singleton db = DB_Singleton.Instance;

                //TODO Test this when fixed on the server
                var response = await new RequestHandler(this).DeleteList(db.Retrieve("Token"), db.GetActiveGroup().GroupID, listoflists[e.Position].Topicid);

                if ((int)response.StatusCode == 200)
                {
                    Toast.MakeText(this, "Succesfully Deleted", ToastLength.Long);
                }
                else
                {
                    Toast.MakeText(this, "Error Deleting", ToastLength.Long);
                }

                await UpdateLists();
            });

            alert.SetNegativeButton("No", (senderAlert, args) => { });

            Dialog dialog = alert.Create();

            dialog.Show();
        }
Exemplo n.º 5
0
        private async Task DeleteItem(int position)
        {
            RequestHandler request = new RequestHandler(this);

            DB_Singleton db       = DB_Singleton.Instance;
            string       token    = db.Retrieve("Token");
            var          response = await request.DeleteMessageReply(token, db.GetActiveGroup().GroupID, comment_objs[position].Topicid);
        }
Exemplo n.º 6
0
        private async void M_Bconfirm_Click(object sender, EventArgs e)
        {
            string user     = "";
            string userid   = "";
            string category = (string)m_select_user.SelectedItem;
            string title    = m_title.Text;
            string amount   = m_amount.Text;

            for (int i = 0; i < m_listview.Count; ++i)
            {
                if (m_listview.IsItemChecked(i))
                {
                    //only used for testing
                    user = (string)m_listview.GetItemAtPosition(i);
                }
                //users.Add((string)m_listview.GetItemAtPosition(i));
            }
            //get userid
            if (users.Contains(user))
            {
                userid = userIDs.ElementAt(users.IndexOf(user));
            }

            //Dismiss();
            //if the bill is not split equally, start the dialog that asks for splits
            if (!m_checkbox.Checked)
            {
                FragmentTransaction    transaction = FragmentManager.BeginTransaction();
                BillsNewSpecifyAmounts Dialog      = new BillsNewSpecifyAmounts();
                Dialog.Show(transaction, "dialog fragment specify bill amounts");
            }

            DB_Singleton db = DB_Singleton.Instance;

            if (category == "Rent")
            {
                category = "2";
            }
            else if (category == "Utilities")
            {
                category = "3";
            }
            else if (category == "Groceries")
            {
                category = "4";
            }
            else
            {
                category = "1";
            }

            RequestHandler request = new RequestHandler(Context);
            await request.PutBill(db.Retrieve("Token"), db.GetActiveGroup().GroupID, userid, category, title, "description", amount, DateTime.Now.ToString());

            await((Bills)Activity).UpdateAllBills();

            Dismiss();
        }
        private void InsertInDB(string[] decodedToken)
        {
            DB_Singleton instance = DB_Singleton.Instance;

            instance.InitDB();

            instance.InitialInsert(decodedToken[0], decodedToken[1],
                                   decodedToken[2], decodedToken[3]);
        }
Exemplo n.º 8
0
        private async void NewBillReq(BillObj bill)
        {
            DB_Singleton db = DB_Singleton.Instance;

            string token   = db.Retrieve("Token");
            string groupid = db.GetActiveGroup().GroupID;

            RequestHandler request  = new RequestHandler(Context);
            var            response = await request.PutBill(token, groupid, bill.Recipientname, bill.Categoryid, bill.Title, bill.Description, bill.Amount, bill.Date);
        }
        private void InsertInDB(string username, string email, string firstname, IRestResponse response)
        {
            //DB_Singleton InitDB

            DB_Singleton instance = DB_Singleton.Instance;

            instance.InitDB();

            JObject respJson = JObject.Parse(response.Content);

            string token = (string)respJson["token"];

            instance.InitialInsert(token, username, email, firstname);
        }
Exemplo n.º 10
0
        private async Task GetLocations()
        {
            DB_Singleton db = DB_Singleton.Instance;

            RequestHandler request = new RequestHandler(this);

            //get locations from database
            var response = await request.GetLocations(db.Retrieve("Token"), db.GetActiveGroup().GroupID);

            //convert locations from json format
            db_locations = ConvertJson(response);
            //add locations into list adapter
            //LocationList.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, db_locations);

            await UpdateLocation();
        }
Exemplo n.º 11
0
        public async Task UpdateAllBills()
        {
            DB_Singleton   db       = DB_Singleton.Instance;
            RequestHandler request  = new RequestHandler(this);
            var            response = await request.GetBills(db.Retrieve("Token"), db.GetActiveGroup().GroupID);

            Console.WriteLine("!!!!!!!!!!!!!!!!!!!BILLS!!!!!!!!!!!!!!!!!!!!!!");
            JArray allbills = JArray.Parse(response.Content);

            foreach (JToken token in allbills)
            {
                all_bill_objs.Add(new BillObj(token));
                Console.WriteLine(new BillObj(token).ToString());
            }

            listview.Adapter = new BillsListAdapter(this, all_bill_objs);
        }
Exemplo n.º 12
0
        private async Task PostItem()
        {
            RequestHandler request  = new RequestHandler(Context);
            DB_Singleton   db       = DB_Singleton.Instance;
            string         token    = db.Retrieve("Token");
            string         groupid  = db.GetActiveGroup().GroupID;
            var            response = await request.PostNewListItem(token, groupid, m_list.Topicid, editText.Text);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Item Posted", ToastLength.Long);
            }
            else
            {
                Toast.MakeText(Context, "Post Failed", ToastLength.Long);
            }
            //JArray preParse = JArray.Parse(response.Content);
        }
Exemplo n.º 13
0
        //This may need to change. If selecting multiple times is an issue
        private async void FireCheckItem(string itemid, bool selected)
        {
            List <ItemObj> groupLists = new List <ItemObj>();
            RequestHandler request    = new RequestHandler(this);
            DB_Singleton   db         = DB_Singleton.Instance;
            string         token      = db.Retrieve("Token");
            string         groupid    = db.GetActiveGroup().GroupID;
            var            response   = await request.PutListItem(token, groupid, list.Topicid, itemid, selected);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(this, "Item Updated", ToastLength.Long);
            }
            else
            {
                Toast.MakeText(this, "Connection Failed", ToastLength.Long);
            }
        }
        private async void BAccpet_Click(object sender, EventArgs e)
        {
            RequestHandler request  = new RequestHandler(Context);
            DB_Singleton   db       = DB_Singleton.Instance;
            string         token    = db.Retrieve("Token");
            var            response = await request.RespondInvitation(token, groupid, false);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Accepted Invite", ToastLength.Long);
                AddGroup(groupid, groupname);
            }
            else
            {
                Toast.MakeText(Context, "Invite response failed", ToastLength.Long);
            }
            Dismiss();
        }
        private async void BDecline_Click(object sender, EventArgs e)
        {
            //request.RespondInvitation(db.Retrieve("Token"), db.SearchGroup(groupname), false);
            RequestHandler request = new RequestHandler(Context);
            DB_Singleton   db      = DB_Singleton.Instance;

            var response = await request.RespondInvitation(db.Retrieve("Token"), groupid, true);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Rejected Invite", ToastLength.Long);
            }
            else
            {
                Toast.MakeText(Context, "Invite response failed", ToastLength.Long);
            }
            Dismiss();
        }
        private async void MakeReq()
        {
            //submit comment logic
            RequestHandler request = new RequestHandler(Context);
            DB_Singleton   db      = DB_Singleton.Instance;
            string         token   = db.Retrieve("Token");
            string         groupid = db.GetActiveGroup().GroupID;

            var response = await request.PostMessageReply(token, groupid, post.Topicid, message);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Post Succesful", ToastLength.Long);
            }
            else
            {
            }
            Dismiss();
        }
Exemplo n.º 17
0
        public async Task UpdateLocation()
        {
            DB_Singleton db = DB_Singleton.Instance;

            if (db.IsOnline())
            {
                WifiManager wifimanager = (WifiManager)GetSystemService(Context.WifiService);

                string permission = Manifest.Permission.AccessFineLocation;
                if (CheckSelfPermission(permission) == (int)Permission.Granted)
                {
                    var InRange = wifimanager.ScanResults;

                    foreach (ScanResult network in InRange)
                    {
                        WifiNetworks.Add(network.Ssid);
                        //WifiNetworkKey.Add(network.Bssid);
                    }
                }

                RequestHandler request = new RequestHandler(this);

                var results = WifiNetworks.Intersect(db_locations);

                current_location = null;
                if (results.Count() != 0)
                {
                    current_location = results.ElementAt(0);
                }

                var response = await request.UpdateLocation(db.Retrieve("Token"), current_location);

                if (current_location != null)
                {
                    CurrentLocation.Text = "Current location: " + current_location;
                }
                else
                {
                    CurrentLocation.Text = "Not in range of location";
                }
                CurrentLocation.RefreshDrawableState();
            }
        }
Exemplo n.º 18
0
        public async Task UpdateComments()
        {
            List <string> comments  = new List <string>();
            List <string> usernames = new List <string>();

            //deserializes the title and message that were converted to json in the messageboard.cs
            //title = JsonConvert.DeserializeObject<string>(Intent.GetStringExtra("Title"));
            //msg = JsonConvert.DeserializeObject<string>(Intent.GetStringExtra("Message"));
            comment_objs = new List <CommentObj>();

            DB_Singleton   db      = DB_Singleton.Instance;
            RequestHandler request = new RequestHandler(this);
            string         token   = db.Retrieve("Token");
            string         groupid = db.GetActiveGroup().GroupID;

            var response = await request.GetMessageReplies(token, groupid, post.Topicid);

            if ((int)response.StatusCode == 200)
            {
                if (response.Content != "[]")
                {
                    JArray JPosts = JArray.Parse(response.Content);

                    foreach (JToken Jpost in JPosts)
                    {
                        comment_objs.Add(new CommentObj(Jpost));
                    }
                }
            }
            else
            {
                Toast.MakeText(this, "Error getting comments", ToastLength.Long);
            }

            var minus_first_comment = comment_objs;

            minus_first_comment.RemoveAt(0);
            commentlistview.Adapter = new BulletinCommentListAdapter(this, minus_first_comment);


            //set onClick method for message that will open the full message text in another window
        }
Exemplo n.º 19
0
        private async void BConfirm_Click(object sender, EventArgs e)
        {
            //CreateGroup(View.FindViewById<EditText>(Resource.Id.edittextNewGroup).Text);
            string         groupname = View.FindViewById <EditText>(Resource.Id.edittextNewGroup).Text;
            RequestHandler request   = new RequestHandler(Context);

            DB_Singleton db       = DB_Singleton.Instance;
            string       token    = db.Retrieve("Token");
            var          response = await request.CreateGroup(groupname, token);

            int statusCode = (int)response.StatusCode;

            if ((int)response.StatusCode == 200)
            {
                db.AddGroup(groupname, (string)JObject.Parse(response.Content)["groupID"]);
                Success();
            }
            else
            {
                Failure();
            }

            /*
             * AlertDialog.Builder alert = new AlertDialog.Builder(this.Context);
             * alert.SetTitle("Create the new group " + EditTextGroupName.Text + "?");
             *
             * //Send new location information to database
             * alert.SetPositiveButton("Confirm", (senderAlert, args) =>
             * {
             * //                Task create = CreateGroup().Text);
             *  Dismiss();
             * });
             *
             * //Close dialog and cancel add
             * alert.SetNegativeButton("Cancel", (senderAlert, args) =>
             * {});
             *
             * Dialog dialog = alert.Create();
             * dialog.Show();
             */
        }
Exemplo n.º 20
0
        public async void PostBulletin(object sender, EventArgs e)
        {
            string MsgTitle = View.FindViewById <EditText>(Resource.Id.edittexttitle).Text;
            string MsgBody  = View.FindViewById <EditText>(Resource.Id.edittextmessage).Text;

            //create dialog to show data that was taken from text fields
            //Currently serves a purpose in testing, may be left in as confirmation to the user
            AlertDialog.Builder alert = new AlertDialog.Builder(this.Context);
            alert.SetTitle("New Message Submitted:");
            alert.SetMessage(string.Format("Subject: " + MsgTitle + "\nMessage:\n" + MsgBody));

            Dialog dialog = alert.Create();

            dialog.Show();

            Intent intent = new Intent(this.Activity.ApplicationContext, typeof(BulletinBoard));

            Notification(intent, "A new message has been posted in ", "groupname", 0, 0);

            RequestHandler request = new RequestHandler(Context);
            DB_Singleton   db      = DB_Singleton.Instance;
            string         token   = db.Retrieve("Token");
            string         groupid = db.GetActiveGroup().GroupID;

            //set private values equal to equal values from dialog box
            title   = MsgTitle;
            message = MsgBody;
            var response = await request.PostMessages(token, groupid, title, message);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Succesfully Posted", ToastLength.Long);
            }
            else
            {
                Toast.MakeText(Context, "Post Failed", ToastLength.Long);
            }
            //closes message dialog box
            await((BulletinBoard)Activity).UpdatePosts();
            Dismiss();
        }
Exemplo n.º 21
0
        private void InitializeLocations()
        {
            DB_Singleton db = DB_Singleton.Instance;

            appendUsername = db.Retrieve("UserName");
            appendEmail    = db.Retrieve("Email");

            TextView username = FindViewById <TextView>(Resource.Id.textviewSettingsMenuUsername);
            TextView email    = FindViewById <TextView>(Resource.Id.textviewSettingsMenuEmail);

            //This is where the text values for the username and email are set
            username.Text = "Username: "******"Email: " + appendEmail;


            //initializes a switch object to the one found in the settings page
            Switch s = FindViewById <Switch>(Resource.Id.SwitchSettingsMenu);

            //sets the function used when toggle is checked or unchecked
            s.CheckedChange += ToggleLocations;
        }
Exemplo n.º 22
0
        private async Task PostNewList()
        {
            RequestHandler request = new RequestHandler(Context);
            DB_Singleton   db      = DB_Singleton.Instance;

            string token   = db.Retrieve("Token");
            string groupid = db.GetActiveGroup().GroupID;

            var response = await request.PostNewList(token, groupid, editText.Text);

            if ((int)response.StatusCode == 200)
            {
                Toast.MakeText(Context, "Succesfully posted", ToastLength.Long);
            }
            else
            {
                Toast.MakeText(Context, "Error posting message", ToastLength.Long);
            }

            Dismiss();
        }
Exemplo n.º 23
0
        public async void UpdateGroups()
        {
            DB_Singleton     db            = DB_Singleton.Instance;
            string           token         = db.Retrieve("Token");
            List <UserGroup> userGroupList = await PullGroups(token);

            foreach (UserGroup group in userGroupList)
            {
                //number of members in each group also needs to be added here
                groupnames.Add(group.GroupName);
            }

            listView         = FindViewById <ListView>(Resource.Id.listviewGroups);
            listView.Adapter = new GroupListAdapter(this, groupnames, nummembers);
            textView         = FindViewById <TextView>(Resource.Id.textviewGroups);

            try
            { textView.Text = "Current Group: " + db.GetActiveGroup().GroupName; }
            catch
            { Console.WriteLine("No active group selected: Groups"); }
            //Set itemclick function for when a group is selected
            listView.ItemClick += OnGroupItemClick;
        }
Exemplo n.º 24
0
        private void Select_Click(object sender, EventArgs e)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(this.Context);
            alert.SetTitle("Make " + groupname + " your current group?");

            //Set current group
            alert.SetPositiveButton("Confirm", (senderAlert, args) =>
            {
                //This is where current group is set
                DB_Singleton db  = DB_Singleton.Instance;
                UserGroup active = db.SearchGroup(groupname);
                db.ChangeActiveGroup(active);
            });

            //Close dialog
            alert.SetNegativeButton("Cancel", (senderAlert, args) =>
            {
                Dismiss();
            });
            Dialog dialog = alert.Create();

            dialog.Show();
            Dismiss();
        }
Exemplo n.º 25
0
        private async void InitializeFormat()
        {
            AddLocation        = FindViewById <Button>(Resource.Id.NewLocationButton);
            AddLocation.Click += AddLocation_Click;


            LocationList    = FindViewById <ListView>(Resource.Id.locationlistview);
            CurrentLocation = FindViewById <TextView>(Resource.Id.textCurrentLocation);

            //This block asks the user for location permissions
            //Or checks if the user already gave permissions
            string permission = Manifest.Permission.AccessFineLocation;

            if (CheckSelfPermission(permission) != (int)Permission.Granted)
            {
                string[] request_permissions = new string[1];
                request_permissions[0] = Manifest.Permission.AccessFineLocation;
                ActivityCompat.RequestPermissions(this, request_permissions, 0);
            }
            DB_Singleton db = DB_Singleton.Instance;

            try
            {
                db.GetActiveGroup();
            }
            catch
            {
                Console.WriteLine("No active group selected: Locations");
            }

            await GetLocations();

            var GroupMemberLocs = await GetActiveUsers();

            LocationList.Adapter = new LocationsListAdapter(this, GroupMemberLocs);
        }
Exemplo n.º 26
0
        private async Task <List <Tuple <string, string> > > GetActiveUsers()

        {
            DB_Singleton   db      = DB_Singleton.Instance;
            RequestHandler request = new RequestHandler(this);

            List <Tuple <string, string> > tup_list = new List <Tuple <string, string> >();
            var response = await request.GetUserLocations(db.Retrieve("Token"), db.GetActiveGroup().GroupID);

            if (response.Content != "" && response.Content != "[]")
            {
                JArray members = JArray.Parse(response.Content);

                foreach (JToken member in members)
                {
                    string username     = (string)member["UserName"];
                    string locationname = (string)member["NetName"];

                    tup_list.Add(new Tuple <string, string>(username, locationname));
                }
            }

            return(tup_list);
        }
        private async void UpdateGroups()
        {
            DB_Singleton   db       = DB_Singleton.Instance;
            string         token    = db.Retrieve("Token");
            RequestHandler request  = new RequestHandler(Context);
            IRestResponse  response = await request.PullGroups(token);

            List <UserGroup> userGroupList = ReformatResponse(response.Content);

            foreach (UserGroup user in userGroupList)
            {
                db.AddGroup(user.GroupName, user.GroupID);
            }
            if (userGroupList.Count > 0)
            {
                db.ChangeActiveGroup(userGroupList[0]);
            }
            //CAUTION A NEW USER THAT TRIES TO ACCESS ELEMENTS
            //WITHOUT A GROUP WILL CRASH THE APP
            else
            {
                db.ChangeActiveGroup(new UserGroup(null, null));
            }
        }
Exemplo n.º 28
0
 private void Invite(string username, string groupname)
 {
     RequestHandler request = new RequestHandler(Context);
     DB_Singleton   db      = DB_Singleton.Instance;
     //await request.InviteToGroup(db.SearchGroup(groupname).GroupID, username, db.Retrieve("Token"));
 }