Esempio n. 1
0
        public CategoryListAdapter(Activity context, short categoryValue, string searchFilter, XDocument xmlDoc) //We need a context to inflate our row view from
            : base()
        {
            this.context  = context;
            this.category = categoryValue;

            if (category == -1)
            {
                this.items = BusinessListings.getBusinessesThatMatchName(searchFilter, xmlDoc);
            }
            else if (category == (short)Categories.CategoriesTypes.Favorites)
            {
                string[] favList = searchFilter.Split(',');
                this.items = BusinessListings.getBusinessesByFavorites(favList, xmlDoc);
            }
            else
            {
                this.items = BusinessListings.getBusinessesByCategory(categoryValue, xmlDoc);
            }
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.details);

            Stream    mystream2  = Assets.Open("BusinessListings.xml");
            XDocument xt         = XDocument.Load(mystream2);
            int       businessID = Convert.ToInt32(Intent.GetStringExtra("BusinessID"));

            business = BusinessListings.getBusinessesByID(businessID, xt);

            var txtName = FindViewById <TextView>(Resource.Id.textName);

            txtName.Text = business.Name;
            var txtAddress = FindViewById <TextView>(Resource.Id.textAddress);

            txtAddress.Text = business.Address;
            var txtPhone = FindViewById <TextView>(Resource.Id.textPhone);

            txtPhone.Text = business.Phone;
            var txtCity = FindViewById <TextView>(Resource.Id.textCity);

            txtCity.Text = business.City + ", " + business.Province + ", " + business.Postal;
            var txtWebsite = FindViewById <TextView>(Resource.Id.textWebsite);

            txtWebsite.Text = business.Website;

            var btnAddToFavorites       = FindViewById <Button>(Resource.Id.btnAddToFavorites);
            ISharedPreferences prefFav  = GetSharedPreferences("favoritesFile", FileCreationMode.Private);
            string             favValue = prefFav.GetString("favoritesList", "");

            if (favValue.Contains("," + businessID + ",") == false)
            {
                btnAddToFavorites.SetBackgroundResource(Resource.Drawable.btn_green_matte);
                btnAddToFavorites.SetText(Resource.String.Add);
            }
            else
            {
                btnAddToFavorites.SetBackgroundResource(Resource.Drawable.btn_red_matte);
                btnAddToFavorites.SetText(Resource.String.Del);
            }
#if DEBUG
            business.Phone = "5556";
#endif



            btnAddToFavorites.Click += (sender, e) =>
            {
                ISharedPreferences pref  = GetSharedPreferences("favoritesFile", FileCreationMode.Private);
                string             value = pref.GetString("favoritesList", "");

                if (value.Contains("," + business.BusinessID + ","))
                {
                    value += businessID + ",";
                    ISharedPreferencesEditor ePref = pref.Edit();
                    ePref.PutString("favoritesList", value);
                    ePref.Commit();
                    var btnAdd = FindViewById <Button>(Resource.Id.btnAddToFavorites);
                    btnAdd.SetBackgroundResource(Resource.Drawable.btn_green_matte);
                    btnAdd.SetText(Resource.String.Add);
                    Toast.MakeText(Application, "Removed From Favorites " + value, ToastLength.Short).Show();
                }
                else
                {
                    value = value.Replace("," + business.BusinessID, "");
                    ISharedPreferencesEditor ePref = pref.Edit();
                    ePref.PutString("favoritesList", value);
                    ePref.Commit();
                    var btnAdd = FindViewById <Button>(Resource.Id.btnAddToFavorites);
                    btnAdd.SetBackgroundResource(Resource.Drawable.btn_red_matte);
                    btnAdd.SetText(Resource.String.Del);
                    Toast.MakeText(Application, "Added To Favorites " + value, ToastLength.Short).Show();
                }
            };


            var btnMap = FindViewById <Button>(Resource.Id.btnMap);
            btnMap.Click += (sender, e) =>
            {
                string url       = business.Address + "+" + business.City + "+" + business.Postal + "+" + business.Province;
                var    geoUri    = Android.Net.Uri.Parse("geo:0,0?q=" + url);
                var    mapIntent = new Intent(Intent.ActionView, geoUri);
                StartActivity(mapIntent);
            };


            var btnSMS = FindViewById <Button>(Resource.Id.btnSMS);
            btnSMS.Click += (sender, e) =>
            {
                StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.FromParts("sms", business.Phone, null)));
            };

            var btnCall = FindViewById <Button>(Resource.Id.btnCall);
            btnCall.Click += (sender, e) =>
            {
                var callIntent = new Intent(Intent.ActionDial);
                callIntent.SetData(Android.Net.Uri.Parse("tel:+" + business.Phone));
                StartActivity(callIntent);
            };

            var btnHome = FindViewById <Button>(Resource.Id.btnHome);
            btnHome.Click += (sender, e) =>
            {
                StartActivity(typeof(ApnaPages.HomeActivity));
            };
            var btnDirectory = FindViewById <Button>(Resource.Id.btnDirectory);
            btnDirectory.Click += (sender, e) =>
            {
                StartActivity(typeof(ApnaPages.DirectoryActivity));
            };
            var btnFavorite = FindViewById <Button>(Resource.Id.btnFavorite);
            btnFavorite.Click += (sender, e) =>
            {
                ISharedPreferences pref = GetSharedPreferences("favoritesFile", FileCreationMode.Private);
                string             val  = pref.GetString("favoritesList", "");
                Toast.MakeText(Application, "Favorites " + val, ToastLength.Short).Show();
                var targetActivity = new Intent(this, typeof(CategoryActivity));
                targetActivity.PutExtra("SearchFilter", val);
                targetActivity.PutExtra("Category", "1000");
                StartActivity(targetActivity);
            };

            var btnShare = FindViewById <Button>(Resource.Id.btnShare);
            btnShare.Click += (sender, e) =>
            {
                ShowDialog(DIALOG_LIST);
            };
        }