Exemplo n.º 1
0
        private void ChangeBestBeforeDate(StorageItemQuantityResult storageItem, StorageItemQuantityListViewAdapter adapter)
        {
            DateTime?date = storageItem.BestBefore;

            // Haltbarkeitsdatum erfassen (kann aber auch weggelassen werden)
            storageItem.IsChanged = true;
            adapter.NotifyDataSetInvalidated();


            if (!UseAltDatePicker)
            {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime? time)
                {
                    if (time.HasValue)
                    {
                        storageItem.BestBefore = time.Value;
                    }
                    else
                    {
                        storageItem.BestBefore = null;
                    }

                    storageItem.IsChanged = true;
                    adapter.NotifyDataSetInvalidated();

                    if (this.quantity > 0)
                    {
                        this.ChangeQuantity(storageItem, adapter);
                    }
                }, date);
                frag.ShowsDialog = true;
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            }
            else
            {
                AltDatePickerFragment frag = AltDatePickerFragment.NewInstance(delegate(DateTime? time)
                {
                    if (time.HasValue)
                    {
                        storageItem.BestBefore = time.Value;
                    }
                    else
                    {
                        storageItem.BestBefore = null;
                    }

                    storageItem.IsChanged = true;
                    adapter.NotifyDataSetInvalidated();

                    if (this.quantity > 0)
                    {
                        this.ChangeQuantity(storageItem, adapter);
                    }
                }, date);
                frag.ShowsDialog = true;
                frag.Show(FragmentManager, AltDatePickerFragment.TAG);
            }
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            MainActivity.Strings_Manufacturer  = Resources.GetString(Resource.String.ArticleDetails_Manufacturer);
            MainActivity.Strings_Size          = Resources.GetString(Resource.String.ArticleDetails_Size);
            MainActivity.Strings_WarnenInTagen = Resources.GetString(Resource.String.ArticleDetails_WarningInDays);
            MainActivity.Strings_Calories      = Resources.GetString(Resource.String.ArticleDetails_Calories);
            MainActivity.Strings_Category      = Resources.GetString(Resource.String.ArticleDetails_Category);
            MainActivity.Strings_SubCategory   = Resources.GetString(Resource.String.ArticleDetails_SubCategory);
            MainActivity.Strings_Supermarket   = Resources.GetString(Resource.String.ArticleDetails_SupermarketLabel);
            MainActivity.Strings_Price         = Resources.GetString(Resource.String.ArticleDetails_Price);
            MainActivity.Strings_Storage       = Resources.GetString(Resource.String.ArticleDetails_StorageLabel);
            MainActivity.Strings_MinQuantity   = Resources.GetString(Resource.String.ArticleDetails_MinQuantityLabel);
            MainActivity.Strings_PrefQuantity  = Resources.GetString(Resource.String.ArticleDetails_PrefQuantityLabel);
            MainActivity.Strings_EANCode       = Resources.GetString(Resource.String.ArticleDetails_EANCode);
            MainActivity.Strings_Amount        = Resources.GetString(Resource.String.ArticleDetails_Amount);
            MainActivity.Strings_Notes         = Resources.GetString(Resource.String.ArticleDetails_Notes);

            // Damit Pre-Launch von Google Play Store nicht immer wieder
            // in die EAN Scan "Falle" tappt und da nicht wieder rauskommt.
            // (meistens nächster Tag)
            MainActivity.preLaunchTestEndDay = new DateTime(2020, 12, 21);

            base.OnCreate(bundle);

            if (Debugger.IsAttached)
            {
                ShoppingListHelper.UnitTest();
            }

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // ActionBar Hintergrund Farbe setzen
            var backgroundPaint = ContextCompat.GetDrawable(this, Resource.Color.Application_ActionBar_Background);

            backgroundPaint.SetBounds(0, 0, 10, 10);
            ActionBar.SetBackgroundDrawable(backgroundPaint);
            ActionBar.SetDisplayShowHomeEnabled(true);

            string storageDir = this.GetExternalFilesDir(null).AbsolutePath;

            //File.WriteAllText(storageDir + "/Test.txt", "Das ist ein Test.");

            // Datenbanken erstellen
            Android_Database.Instance.RestoreSampleDatabaseFromResources();

            // Initialisierung für EAN Scanner
            ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);

            // Zugriff auf die SD Karte anfordern
            new SdCardAccess().Grand(this);

            // Klick auf den "abgelaufen" Text bringt die Liste der (bald) abgelaufender Artieln.
            FindViewById <TextView>(Resource.Id.Main_Text).Click  += ArticlesNearExpiryDate_Click;
            FindViewById <TextView>(Resource.Id.Main_Text1).Click += ArticlesNearExpiryDate_Click;
            FindViewById <TextView>(Resource.Id.Main_Text2).Click += ArticlesNearExpiryDate_Click;

            // Auswahl nach Kategorien
            Button buttonKategorie = FindViewById <Button>(Resource.Id.MainButton_Kategorie);

            buttonKategorie.Click += delegate { this.ShowCategoriesSelection(); };

            // Lagerbestand
            Button buttonLagerbestand = FindViewById <Button>(Resource.Id.MainButton_Lagerbestand);

            buttonLagerbestand.Click += delegate { StartActivityForResult(new Intent(this, typeof(StorageItemListActivity)), EditStorageItemQuantityId); };

            // Artikeldaten
            Button buttonArticle = FindViewById <Button>(Resource.Id.MainButton_Artikeldaten);

            buttonArticle.Click += delegate { StartActivityForResult(new Intent(this, typeof(ArticleListActivity)), ArticleListId); };

            // Einkaufsliste
            Button buttonShoppingList = FindViewById <Button>(Resource.Id.MainButton_ShoppingList);

            buttonShoppingList.Click += delegate { StartActivity(new Intent(this, typeof(ShoppingListActivity))); };

            // Barcode scannen
            Button buttonBarcode = FindViewById <Button>(Resource.Id.MainButton_Barcode);

            buttonBarcode.Click += ButtonBarcode_Click;

            // Einstellungen für Warnhinweis beim OpenFoodFacts.org
            ArticleDetailsActivity.showCostMessage = Settings.GetBoolean("ShowOpenFoodFactsInternetCostsMessage", true);

            StorageItemQuantityActivity.UseAltDatePicker = Settings.GetBoolean("UseAltDatePicker", false);

            // DatePicker-DEBUG
            if (debug_date_picker)
            {
                Android_Database.UseTestDatabase = true;
                Button b = new Button(this.ApplicationContext);
                b.Text   = "Test DP";
                b.Click += delegate
                {
                    AltDatePickerFragment frag = AltDatePickerFragment.NewInstance(delegate(DateTime? time) { b.Text = time != null ? time.Value.ToShortDateString() : "Kein Datum"; }, DateTime.Today);
                    frag.ShowsDialog = true;
                    frag.Show(this.FragmentManager, AltDatePickerFragment.TAG);
                };
                FindViewById <LinearLayout>(Resource.Id.Main_LinearLayout).AddView(b);
                AltDatePickerFragment frag2 = AltDatePickerFragment.NewInstance(delegate(DateTime? time) { b.Text = time != null ? time.Value.ToShortDateString() : "Kein Datum"; }, DateTime.Today);
                frag2.ShowsDialog = true;
                frag2.Show(this.FragmentManager, AltDatePickerFragment.TAG);
            }


            if (MainActivity.IsGooglePlayPreLaunchTestMode)
            {
                Android_Database.UseTestDatabase = true;
            }
            else
            {
                this.ShowInfoAufTestdatenbank();
            }

            // Datenbankverbindung initialisieren
            this.InitializeDatabase();

            // Hinweis bei Pre-Launch Untersuchung
            this.ShowInfoAufTestversion();
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            MainActivity.Strings_Manufacturer  = Resources.GetString(Resource.String.ArticleDetails_Manufacturer);
            MainActivity.Strings_Size          = Resources.GetString(Resource.String.ArticleDetails_Size);
            MainActivity.Strings_WarnenInTagen = Resources.GetString(Resource.String.ArticleDetails_WarningInDays);
            MainActivity.Strings_Calories      = Resources.GetString(Resource.String.ArticleDetails_Calories);
            MainActivity.Strings_Category      = Resources.GetString(Resource.String.ArticleDetails_Category);
            MainActivity.Strings_SubCategory   = Resources.GetString(Resource.String.ArticleDetails_SubCategory);
            MainActivity.Strings_Supermarket   = Resources.GetString(Resource.String.ArticleDetails_SupermarketLabel);
            MainActivity.Strings_Price         = Resources.GetString(Resource.String.ArticleDetails_Price);
            MainActivity.Strings_Storage       = Resources.GetString(Resource.String.ArticleDetails_StorageLabel);
            MainActivity.Strings_MinQuantity   = Resources.GetString(Resource.String.ArticleDetails_MinQuantityLabel);
            MainActivity.Strings_PrefQuantity  = Resources.GetString(Resource.String.ArticleDetails_PrefQuantityLabel);
            MainActivity.Strings_EANCode       = Resources.GetString(Resource.String.ArticleDetails_EANCode);
            MainActivity.Strings_Amount        = Resources.GetString(Resource.String.ArticleDetails_Amount);
            MainActivity.Strings_Notes         = Resources.GetString(Resource.String.ArticleDetails_Notes);

            // Damit Pre-Launch von Google Play Store nicht immer wieder
            // in die EAN Scan "Falle" tappt und da nicht wieder rauskommt.
            // (meistens nächster Tag)
            MainActivity.preLaunchTestEndDay = new DateTime(2021, 05, 22);

            // Zusammen mit minSdkVersion="19" verhindert das den Fehler: Android.Content.Res.Resources+NotFoundException: 'File res/drawable/abc_vector_test.xml from drawable resource ID
            //AppCompatDelegate.CompatVectorFromResourcesEnabled = true;

            base.OnCreate(bundle);

            Xamarin.Essentials.Platform.Init(this, bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // ActionBar Hintergrund Farbe setzen
            var backgroundPaint = ContextCompat.GetDrawable(this, Resource.Color.Application_ActionBar_Background);

            backgroundPaint.SetBounds(0, 0, 10, 10);
            this.SupportActionBar.SetBackgroundDrawable(backgroundPaint);
            this.SupportActionBar.SetDisplayShowHomeEnabled(true);

            // Datenbanken erstellen
            Android_Database.Instance.RestoreSampleDatabaseFromResources(this);

            List <string> databases;

            Android_Database.LoadDatabaseFileListSafe(this, out databases);

            if ((databases.Count > 0) && (string.IsNullOrEmpty(Android_Database.SelectedDatabaseName)))
            {
                string lastSelectedDatabase = Settings.GetString("LastSelectedDatabase", null);

                if (string.IsNullOrEmpty(lastSelectedDatabase))
                {
                    // Datenbanken auswählen
                    this.SwitchDatabase();
                }
                else
                {
                    Android_Database.SelectedDatabaseName = lastSelectedDatabase;
                }
            }

            // Zugriff auf die SD Karte anfordern
            new SdCardAccess().Grand(this);

            // Klick auf den "abgelaufen" Text bringt die Liste der (bald) abgelaufender Artieln.
            FindViewById <TextView>(Resource.Id.Main_Text).Click  += ArticlesNearExpiryDate_Click;
            FindViewById <TextView>(Resource.Id.Main_Text1).Click += ArticlesNearExpiryDate_Click;
            FindViewById <TextView>(Resource.Id.Main_Text2).Click += ArticlesNearExpiryDate_Click;

            // Auswahl nach Kategorien
            Button buttonKategorie = FindViewById <Button>(Resource.Id.MainButton_Kategorie);

            buttonKategorie.Click += delegate { this.ShowCategoriesSelection(); };

            // Lagerbestand
            Button buttonLagerbestand = FindViewById <Button>(Resource.Id.MainButton_Lagerbestand);

            buttonLagerbestand.Click += delegate { StartActivityForResult(new Intent(this, typeof(StorageItemListActivity)), EditStorageItemQuantityId); };

            // Artikeldaten
            Button buttonArticle = FindViewById <Button>(Resource.Id.MainButton_Artikeldaten);

            buttonArticle.Click += delegate { StartActivityForResult(new Intent(this, typeof(ArticleListActivity)), ArticleListId); };

            // Einkaufsliste
            Button buttonShoppingList = FindViewById <Button>(Resource.Id.MainButton_ShoppingList);

            buttonShoppingList.Click += delegate { StartActivity(new Intent(this, typeof(ShoppingListActivity))); };

            // Barcode scannen
            Button buttonBarcode = FindViewById <Button>(Resource.Id.MainButton_Barcode);

            buttonBarcode.Click += ButtonBarcode_Click;

            // Einstellungen für Warnhinweis beim OpenFoodFacts.org
            ArticleDetailsActivity.showCostMessage = Settings.GetBoolean("ShowOpenFoodFactsInternetCostsMessage", true);

            StorageItemQuantityActivity.UseAltDatePicker = Settings.GetBoolean("UseAltDatePicker", false);

            // DatePicker-DEBUG
            if (debug_date_picker)
            {
                Android_Database.UseTestDatabase = true;
                Button b = new Button(this.ApplicationContext)
                {
                    Text = "Test DP"
                };
                b.Click += delegate
                {
                    AltDatePickerFragment frag = AltDatePickerFragment.NewInstance(delegate(DateTime? time) { b.Text = time != null ? time.Value.ToShortDateString() : "Kein Datum"; }, DateTime.Today);
                    frag.ShowsDialog = true;
                    frag.Show(this.SupportFragmentManager, AltDatePickerFragment.TAG);
                };
                FindViewById <LinearLayout>(Resource.Id.Main_LinearLayout).AddView(b);
                AltDatePickerFragment frag2 = AltDatePickerFragment.NewInstance(delegate(DateTime? time) { b.Text = time != null ? time.Value.ToShortDateString() : "Kein Datum"; }, DateTime.Today);
                frag2.ShowsDialog = true;
                frag2.Show(this.SupportFragmentManager, AltDatePickerFragment.TAG);
            }


            if (MainActivity.IsGooglePlayPreLaunchTestMode)
            {
                Android_Database.UseTestDatabase = true;
            }
            else
            {
                this.ShowInfoAufTestdatenbank();
            }

            // Datenbankverbindung initialisieren
            this.InitializeDatabase();

            // Hinweis bei Pre-Launch Untersuchung
            this.ShowInfoAufTestModus();

            // Backup erstellen?
            this.CreateBackup();
        }
Exemplo n.º 4
0
        private void AddArticle_Click(object sender, EventArgs e)
        {
            var storageName = FindViewById <EditText>(Resource.Id.StorageItemQuantity_StorageText).Text;

            StorageItemQuantityResult storageItemQuantity = new StorageItemQuantityResult();

            storageItemQuantity.ArticleId   = this.articleId;
            storageItemQuantity.Quantity    = 1;
            storageItemQuantity.BestBefore  = DateTime.Today;
            storageItemQuantity.StorageName = storageName;
            storageItemQuantity.IsChanged   = true;

            if (this.quantity > 1)
            {
                storageItemQuantity.Quantity = (decimal)this.quantity;
            }

            StorageItemQuantityListView itemView = new StorageItemQuantityListView(storageItemQuantity);

            ListView listView = FindViewById <ListView>(Resource.Id.ArticleList);
            var      adapter  = (StorageItemQuantityListViewAdapter)listView.Adapter;

            adapter.Add(itemView);
            listView.InvalidateViews();

            if (!this.durableInfinity)
            {
                // Haltbarkeitsdatum erfassen (kann aber auch weggelassen werden)
                listView.InvalidateViews();
                if (!UseAltDatePicker)
                {
                    DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime? time)
                    {
                        if (time.HasValue)
                        {
                            storageItemQuantity.BestBefore = time.Value;
                        }
                        else
                        {
                            storageItemQuantity.BestBefore = null;
                        }

                        listView.InvalidateViews();

                        if (this.quantity > 0)
                        {
                            this.ChangeQuantity(storageItemQuantity, adapter);
                        }
                    }, DateTime.Today);
                    frag.ShowsDialog = true;
                    frag.Show(FragmentManager, DatePickerFragment.TAG);
                }
                else
                {
                    AltDatePickerFragment frag = AltDatePickerFragment.NewInstance(delegate(DateTime? time)
                    {
                        if (time.HasValue)
                        {
                            storageItemQuantity.BestBefore = time.Value;
                        }
                        else
                        {
                            storageItemQuantity.BestBefore = null;
                        }

                        listView.InvalidateViews();

                        if (this.quantity > 0)
                        {
                            this.ChangeQuantity(storageItemQuantity, adapter);
                        }
                    }, DateTime.Today);
                    frag.ShowsDialog = true;
                    frag.Show(FragmentManager, AltDatePickerFragment.TAG);
                }
            }
            else
            {
                // Ist ohne Haltbarkeitsdatum (unendlich haltbar)
                // Datum muss nicht erfasst werden.
                storageItemQuantity.BestBefore = null;
                listView.InvalidateViews();
            }
        }