Esempio n. 1
0
        public void drawTable(View view)
        {
            //Console.WriteLine ("inside drawable");
            TableLayout tl = (TableLayout)view.FindViewById(Resource.Id.table);
            //TableRow headers = (TableRow)view.FindViewById (Resource.Id.tableHeaders);
            TableLayout tb = (TableLayout)view.FindViewById(Resource.Id.tableHeaders);
            ScrollView  ts = (ScrollView)view.FindViewById(Resource.Id.tableScroll);

            string canvass = NetworkCalls.getJobs(DataController.token);

            if (DataController.canvassID != null)
            {
                string response = NetworkCalls.getProperties(DataController.token);
                //Console.WriteLine ("response got");
                addresses = DataController.addresses;
                //addresses = MockingController.getProperties();
            }
            else
            {
                Toast newProperties = new Toast(this.Activity);
                newProperties = Toast.MakeText(Activity.ApplicationContext, "There isn't an assined canvass!", ToastLength.Short);
                //Console.WriteLine("assigning canvass");
                newProperties.Show();
                return;
            }
            addresses = DataController.addresses;
            //Console.WriteLine("sharedPreference1");
            ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(this.Activity);
            ISharedPreferencesEditor editor = prefs.Edit();


            if (prefs.Contains("properties"))
            {
                int currProperties = prefs.GetInt("properties", 0);
                if (currProperties < addresses.Count)
                {
                    //Console.WriteLine("prefs2");
                    int difference = addresses.Count - currProperties;
                    editor.PutInt("properties", addresses.Count);
                    Toast newProperties = new Toast(this.Activity);
                    //Console.WriteLine("prefs3");
                    newProperties = Toast.MakeText(Activity.ApplicationContext, "New Properties, You have " + difference + " new properties!", ToastLength.Short);
                    newProperties.Show();
                }
                else
                {
                    editor.PutInt("properties", addresses.Count);
                    //Console.WriteLine("prefsElse");
                }
            }
            else
            {
                //Console.WriteLine("prefs4");


                if (addresses != null)
                {
                    editor.PutInt("properties", addresses.Count);

                    Toast newProperties = new Toast(this.Activity);
                    newProperties = Toast.MakeText(Activity.ApplicationContext, "New Properties, You have " + addresses.Count + " new properties!", ToastLength.Short);
                    //Console.WriteLine("prefs5");
                    newProperties.Show();
                }
            }
            editor.Apply();



            if (addresses != null && addresses.Count > 0)
            {
                //tl = (TableLayout)view.FindViewById (Resource.Id.table);
                tl.StretchAllColumns = true;
                tl.BringToFront();
                TableRow headings = new TableRow(this.Activity);
                headings.SetBackgroundColor(Resources.GetColor(Resource.Color.headers));
                headings.Tag = "headers";
                TextView heading1 = new TextView(this.Activity);
                heading1.Text = " Address";
                heading1.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading1.TextSize = 15.0f;
                float density = this.Activity.Resources.DisplayMetrics.Density;
                heading1.SetWidth((int)(350 * density));
                TextView heading2 = new TextView(this.Activity);
                heading2.Text = "No Ans";
                heading2.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading2.TextSize = 15.0f;
                TextView heading3 = new TextView(this.Activity);
                heading3.Text = "Empty";
                heading3.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading3.TextSize = 15.0f;
                TextView heading4 = new TextView(this.Activity);
                heading4.Text = "Derelict";
                heading4.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading4.TextSize = 15.0f;
                TextView heading5 = new TextView(this.Activity);
                heading5.Text = "HEF R";
                heading5.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading5.TextSize = 15.0f;
                TextView heading7 = new TextView(this.Activity);
                heading7.Text = "HEF D";
                heading7.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading7.TextSize = 15.0f;

                TextView heading8 = new TextView(this.Activity);
                heading8.Text = "ITR";
                heading8.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading8.TextSize = 15.0f;

                TextView heading6 = new TextView(this.Activity);
                heading6.Text = "Residents";
                heading6.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading6.TextSize = 15.0f;


                headings.AddView(heading1);
                headings.AddView(heading2);
                headings.AddView(heading3);
                headings.AddView(heading4);
                headings.AddView(heading5);
                headings.AddView(heading7);
                headings.AddView(heading8);
                headings.AddView(heading6);
                tl.AddView(headings);

                for (int i = 0; i < addresses.Count; i++)
                {
                    //Dictionary<string, object> propertyDict = new Dictionary<string, object> ();

                    propertyDict = addresses [i];
                    //Console.WriteLine("for");

                    TableRow tr = new TableRow(this.Activity);

                    tr.Tag = propertyDict ["uprn"].ToString();
                    tr.Id  = i;

//					if (propertyDict ["status"].ToString () != "NV" && propertyDict ["status"].ToString () != "VNA") {
//						tr.SetBackgroundColor (Resources.GetColor (Resource.Color.highlight));
//						rowToLock = tr;
//					} else
                    if (propertyDict ["visitCount"].ToString() == "3")
                    {
                        tr.SetBackgroundColor(Resources.GetColor(Resource.Color.highlight));
                    }
                    else
                    if (i % 2 == 0)
                    {
                        tr.SetBackgroundColor(Resources.GetColor(Resource.Color.even));
                    }
                    else
                    {
                        tr.SetBackgroundColor(Resources.GetColor(Resource.Color.odd));
                    }

                    TextView address = new TextView(this.Activity);
                    //Console.WriteLine("assign1");

                    address.Text = propertyDict ["fullAddress"].ToString();
                    address.Tag  = propertyDict ["canvassID"].ToString();
                    //Console.WriteLine("assign 2");
                    address.TextSize = 18.0f;
                    address.SetTextColor(Resources.GetColor(Resource.Color.tableText));
                    float density1 = this.Activity.Resources.DisplayMetrics.Density;
                    address.SetWidth((int)(350 * density1));
                    address.SetPadding(5, 5, 0, 5);
                    address.LongClick += (object sender, View.LongClickEventArgs e) =>
                    {
                        unlockRow(tr.Tag.ToString());
                    };

                    CheckBox noAnswer = new CheckBox(this.Activity);
                    noAnswer.Tag = propertyDict ["uprn"].ToString();
                    noAnswer.Id  = 0;
                    string visitCount = propertyDict ["visitCount"].ToString();
                    noAnswer.Text = propertyDict ["visitCount"].ToString();
                    if (Convert.ToInt32(noAnswer.Text) == 0)
                    {
                        noAnswer.Text = "";
                    }
                    else if (Convert.ToInt32(noAnswer.Text) == 2)
                    {
                        noAnswer.SetTextColor(Resources.GetColor(Resource.Color.secondVisit));
                    }
                    else if (Convert.ToInt32(noAnswer.Text) == 3)
                    {
                        noAnswer.Checked = true;
                        noAnswer.Enabled = false;
                        noAnswer.SetTextColor(Resources.GetColor(Resource.Color.thirdVisit));
                    }
                    else
                    {
                        noAnswer.SetTextColor(Resources.GetColor(Resource.Color.tableText));
                    }
                    noAnswer.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkNoAnswer(noAnswer);
                    };

                    CheckBox empty = new CheckBox(this.Activity);
                    empty.Tag = propertyDict ["uprn"].ToString();
                    empty.Id  = 1;
                    if (propertyDict ["status"].ToString() == "E")
                    {
                        empty.Checked = true;
                    }
                    if (noAnswer.Text == "3")
                    {
                        empty.Enabled = false;
                    }
                    empty.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkEmpty(empty);
                    };

                    CheckBox derelict = new CheckBox(this.Activity);
                    derelict.Tag = propertyDict ["uprn"].ToString();
                    derelict.Id  = 2;
                    if (propertyDict ["status"].ToString() == "D")
                    {
                        derelict.Checked = true;
                    }
                    if (noAnswer.Text == "3")
                    {
                        derelict.Enabled = false;
                    }
                    derelict.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkDerelict(derelict);
                    };

                    CheckBox postalRequest = new CheckBox(this.Activity);
                    postalRequest.Tag = propertyDict ["uprn"].ToString();
                    postalRequest.Id  = 3;

                    if (propertyDict ["status"].ToString() == "HEF-R")
                    {
                        postalRequest.Checked = true;
                    }
                    if (noAnswer.Text == "3")
                    {
                        postalRequest.Enabled = false;
                    }
                    postalRequest.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkRequestPostal(postalRequest);
                    };

                    CheckBox DeliveredRequest = new CheckBox(this.Activity);
                    DeliveredRequest.Tag = propertyDict ["uprn"].ToString();
                    DeliveredRequest.Id  = 4;

                    if (propertyDict ["status"].ToString() == "HEF-D")
                    {
                        DeliveredRequest.Checked = true;
                    }
                    if (noAnswer.Text == "3")
                    {
                        DeliveredRequest.Enabled = false;
                    }
                    DeliveredRequest.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkDeliveredRequest(DeliveredRequest);
                    };


                    ImageView itr = new ImageView(this.Activity);
                    itr.Tag = propertyDict ["canvassID"].ToString();
                    itr.SetPadding(5, 5, 0, 5);

                    if (propertyDict ["itr_added"] != null)
                    {
                        itr.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.itr6));
                        itr.Background = null;
                    }
                    else
                    {
                        itr.SetImageDrawable(null);
                        itr.Background = null;
                    }



                    ImageButton residents = new ImageButton(this.Activity);
                    residents.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.residents));
                    residents.Background = null;
                    residents.Tag        = propertyDict ["uprn"].ToString();
                    if (DataController.fileType == "HALAROSE")
                    {
                        residents.Id = Convert.ToInt32(propertyDict ["houseID"].ToString());
                    }

                    //residents.Id = i;
                    if (noAnswer.Text == "3")
                    {
                        //residents.Enabled = false;
                    }
                    residents.Click += (object sender, EventArgs e) => {
                        showResidents(residents);
                    };



                    tr.AddView(address);
                    tr.AddView(noAnswer);
                    tr.AddView(empty);
                    tr.AddView(derelict);
                    tr.AddView(postalRequest);
                    tr.AddView(DeliveredRequest);
                    tr.AddView(itr);
                    tr.AddView(residents);
                    tl.AddView(tr);
                    if (rowToLock != null)
                    {
                        lockRow(rowToLock);
                        rowToLock = null;
                    }
                }
                View headers = tl.FindViewWithTag("headers");
                tl.RemoveView(tl.FindViewWithTag("headers"));
                tb.RemoveAllViews();
//					//tb.RemoveView (tl);
                tb.AddView(headers);
                tb.StretchAllColumns = true;
                ts.RemoveAllViews();
                ts.AddView(tl);
                tb.AddView(ts);
                //tb.AddView(tl);
                //tb.AddView (tl);
            }
            else
            {
                Toast changed = new Toast(this.Activity);
                changed = Toast.MakeText(Activity.ApplicationContext, "No Properties, You have not been assigned any properties.", ToastLength.Long);
                changed.Show();
            }
        }
Esempio n. 2
0
        public void drawTable(View view)
        {
            if (checkNetwork())
            {
                string canvass = NetworkCalls.getJobs(DataController.token);

                string response         = NetworkCalls.getProperties(DataController.token);
                string responseResident = NetworkCalls.getResidents(DataController.token, DataController.canvassID, DataController.uprn);
                //residents = MockingController.getResidentsPrev();
                residents = DataController.residents;
                addresses = DataController.addresses;


                TableLayout tl = (TableLayout)view.FindViewById(Resource.Id.residentstable);
                TableLayout tb = (TableLayout)view.FindViewById(Resource.Id.tableHeaders);
                ScrollView  ts = (ScrollView)view.FindViewById(Resource.Id.tableScroll);

                tl.StretchAllColumns = true;
                tl.BringToFront();
                TableRow headings = new TableRow(this.Activity);
                headings.SetBackgroundColor(Resources.GetColor(Resource.Color.headers));
                headings.Tag = "headers";

                TextView heading0 = new TextView(this.Activity);
                heading0.Text = " ITR";
                float density = this.Activity.Resources.DisplayMetrics.Density;
                heading0.SetWidth((int)(40 * density));
                heading0.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading0.TextSize = 15.0f;



                TextView heading1 = new TextView(this.Activity);
                heading1.Text = " Name";
                heading1.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading1.TextSize = 15.0f;
                heading1.SetWidth((int)(220 * density));
                TextView heading2 = new TextView(this.Activity);
                heading2.Text = "Nationality";
                heading2.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading2.TextSize = 15.0f;
                TextView heading3 = new TextView(this.Activity);
                heading3.Text = "Opt Out";
                heading3.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading3.TextSize = 15.0f;
                TextView heading4 = new TextView(this.Activity);
                heading4.Text = "Absent Vote";
                heading4.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading4.TextSize = 15.0f;
                TextView heading5 = new TextView(this.Activity);
                heading5.Text = "Jury Duty";
                heading5.SetTextColor(Resources.GetColor(Resource.Color.odd));
                heading5.TextSize = 15.0f;
                //			TextView heading6 = new TextView(this.Activity);
                //			heading6.Text = "Residents";

                headings.AddView(heading0);
                headings.AddView(heading1);
                headings.AddView(heading2);
                headings.AddView(heading3);
                headings.AddView(heading4);
                headings.AddView(heading5);
                //headings.AddView(heading6);
                tl.AddView(headings);


                for (int i = 0; i < residents.Count; i++)
                {
                    Dictionary <string, object> residentDict = new Dictionary <string, object> ();
                    //String OptOut, Absent, Jury;


                    residentDict = residents [i];

                    TableRow tr = new TableRow(this.Activity);

                    if (i % 2 == 0)
                    {
                        tr.SetBackgroundColor(Resources.GetColor(Resource.Color.even));
                    }
                    else
                    {
                        tr.SetBackgroundColor(Resources.GetColor(Resource.Color.odd));
                    }

                    tr.Tag = residentDict ["id"].ToString();
                    tr.Id  = i;
                    TextView name = new TextView(this.Activity);

                    name.Text = " " + residentDict ["fullName"].ToString();


                    float density1 = this.Activity.Resources.DisplayMetrics.Density;
                    name.SetWidth((int)(200 * density1));
                    name.SetPadding(5, 5, 0, 5);


                    name.Tag      = "name" + i;
                    name.TextSize = 18.0f;
                    name.SetTextColor(Resources.GetColor(Resource.Color.tableText));
                    name.Click += (object sender, EventArgs e) => {
                        nameCorrect(name);
                    };


                    ImageView itr = new ImageView(this.Activity);


                    if (residentDict ["itr_added"] != null)
                    {
                        itr.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.itr6));
                        itr.Background = null;
                    }
                    else
                    {
                        itr.SetImageDrawable(null);
                        itr.Background = null;
                    }

                    itr.SetPadding((int)(-50 * density1), 5, 0, 5);



                    TextView nationality = new TextView(this.Activity);
                    nationality.Text = residentDict ["nationality"].ToString();
                    //residentUpdate[i].Add ("nationality", residentDict ["nationality"].ToString ());
                    nationality.Tag      = i;
                    nationality.TextSize = 18.0f;
                    nationality.SetTextColor(Resources.GetColor(Resource.Color.tableText));
                    nationality.Click += (object sender, EventArgs e) => {
                        nationalityCorrect(nationality);
                    };
                    CheckBox optOut = new CheckBox(this.Activity);
                    optOut.Tag = i;
                    if (residentDict ["optOut"].ToString() == "YES")
                    {
                        optOut.Checked = true;
                        //OptOut = "YES";
                    }
                    else
                    {
                        optOut.Checked = false;
                        //OptOut = "NO";
                    }
                    optOut.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkOptOut(optOut);
                    };
                    //residentUpdate[i].Add ("optOut");
                    CheckBox absentVote = new CheckBox(this.Activity);

                    //absentVote.Enabled = false;
                    absentVote.Tag = i;
                    if (residentDict ["absent"].ToString() == "YES")
                    {
                        absentVote.Checked = true;
                        //Absent = "YES";
                    }
                    else
                    {
                        absentVote.Checked = false;
                        //Absent = "NO";
                    }
                    absentVote.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkAbsentVote(absentVote);
                    };
                    //residentUpdate[i].Add ("absent");
                    CheckBox juryDuty = new CheckBox(this.Activity);
                    juryDuty.Tag = i;
                    if (residentDict ["jury"].ToString() == "YES")
                    {
                        juryDuty.Checked = true;
                        //Jury = "YES";
                    }
                    else
                    {
                        juryDuty.Checked = false;
                        //Jury = "NO";
                    }
                    juryDuty.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                        checkJuryDuty(juryDuty);
                    };
                    //residentUpdate[i].Add ("jury");

                    TableRow.LayoutParams stretchRow = new TableRow.LayoutParams();
                    stretchRow.Width = (int)(10 * density1);


                    tr.AddView(itr, stretchRow);
                    tr.AddView(name);
                    tr.AddView(nationality);
                    tr.AddView(optOut);
                    tr.AddView(absentVote);
                    tr.AddView(juryDuty);
                    tl.AddView(tr);
                }
                View headers = tl.FindViewWithTag("headers");
                tl.RemoveView(tl.FindViewWithTag("headers"));
                tb.RemoveAllViews();
                //					//tb.RemoveView (tl);
                tb.AddView(headers);
                tb.StretchAllColumns = true;
                ts.RemoveAllViews();
                ts.AddView(tl);
                tb.AddView(ts);

                addITR(tl);
            }
        }