Пример #1
0
        private async void SwitchDatabase()
        {
            string database = await MainActivity.SelectDatabase(this, "Datenbank öffnen:");

            if (string.IsNullOrEmpty(database))
            {
                return;
            }

            Android_Database.TryOpenDatabase(database);

            Settings.PutString("LastSelectedDatabase", database);

            this.CheckAndMoveArticleImages();

            this.ShowDatabaseName();

            this.ShowDatabaseInfoText();
        }
Пример #2
0
        internal static Task <string> SelectDatabase(Context context, string title, string except = null)
        {
            var tcs = new TaskCompletionSource <string>();

            Exception ex = Android_Database.LoadDatabaseFileListSafe(context, out List <string> fileList);

            if (ex != null)
            {
                Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
            }

            if (!string.IsNullOrEmpty(except))
            {
                if (fileList.Contains(except))
                {
                    fileList.Remove(except);
                }
            }

            if (fileList.Count == 0)
            {
                tcs.TrySetResult(null);
                return(tcs.Task);
            }

            string[] databaseNames = new string[fileList.Count];

            for (int i = 0; i < fileList.Count; i++)
            {
                databaseNames[i] = Path.GetFileNameWithoutExtension(fileList[i]);
            }

            using (AlertDialog.Builder builder = new AlertDialog.Builder(context))
            {
                builder.SetTitle(title);
                builder.SetItems(databaseNames, (sender2, args) => { tcs.TrySetResult(fileList[args.Which]); });
                builder.SetOnCancelListener(new ActionDismissListener(() => { tcs.TrySetResult(null); }));
                builder.Show();
            }

            return(tcs.Task);
        }
        /// <summary>
        /// Datenbankauswahl (bei mehreren Datenbanken)
        /// </summary>
        /// <returns>true - Datenbank wurde ausgewählt. false - Datenbankauswahl wird angezeigt.</returns>
        private bool SelectDatabase()
        {
            List <string> fileList;

            Exception ex = Android_Database.LoadDatabaseFileListSafe(this, out fileList);

            if (ex != null)
            {
                TRACE(ex);

                string text = "Bitte ggf. den Eintrag 'Zusätzlicher Datenbankpfad' in den Einstellungen prüfen.";
                TRACE("SplashScreen: {0}", ex.Message);
                TRACE("SplashScreen: {0}", text);

                text = ex.Message + "\n\n" + text;

                Toast.MakeText(this, text, ToastLength.Long).Show();
            }

            if (fileList.Count == 1)
            {
                Android_Database.TryOpenDatabase(fileList[0]);
                return(true);
            }

            if (fileList.Count == 0)
            {
                return(true);
            }

            string[] databaseNames = new string[fileList.Count];

            for (int i = 0; i < fileList.Count; i++)
            {
                databaseNames[i] = Path.GetFileNameWithoutExtension(fileList[i]);
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetTitle("Datenbank auswählen:");
            builder.SetItems(databaseNames, (sender2, args) =>
            {
                string database = fileList[args.Which];

                Android_Database.TryOpenDatabase(database);

                Settings.PutString("LastSelectedDatabase", database);

                this.ConvertAndStartMainScreen();
            });

            builder.SetOnCancelListener(new ActionDismissListener(() =>
            {
                Android_Database.TryOpenDatabase(fileList[0]);

                this.ConvertAndStartMainScreen();
            }));

            builder.Show();

            return(false);

            /*
             * bool emulator = Android.OS.Environment.IsExternalStorageEmulated;
             * string status = Android.OS.Environment.ExternalStorageState;
             * bool canWrite = Android.OS.Environment.ExternalStorageDirectory.CanWrite();
             * string sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
             * string databasePath = Android_Database.Instance.GetDatabasePath();
             *
             * TRACE("********************************************");
             * TRACE("Is SD card emulated : {0}", emulator);
             * TRACE("SD card state       : {0}", status);
             * TRACE("Can write SD card   : {0}", canWrite);
             * TRACE("SD card path        : {0}", sdCardPath);
             * TRACE("Database path       : {0}", databasePath);
             * TRACE("Database on SD card : {0}", Android_Database.IsDatabaseOnSdCard);
             * TRACE("********************************************");
             *
             * for (int progress=0; progress<100; progress+=10)
             * {
             *  System.Threading.Thread.Sleep(1000);
             *
             *  RunOnUiThread(() =>
             *  {
             *      this.progressText.SetText(progress.ToString(), TextView.BufferType.Normal);
             *  });
             * }
             */
        }
Пример #4
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();
        }
Пример #5
0
        private void ButtonDeleteDb_Click(object sender, EventArgs e)
        {
            List <string> fileList;

            Exception ex = Android_Database.LoadDatabaseFileListSafe(this, out fileList);

            if (ex != null)
            {
                var message = new AlertDialog.Builder(this);
                message.SetMessage(ex.Message);
                message.SetPositiveButton("OK", (s, e) => { });
                message.Create().Show();
            }

            if (fileList.Count == 0)
            {
                return;
            }

            string currentDatabaseName = Android_Database.Instance.GetDatabasePath();

            if (!string.IsNullOrEmpty(currentDatabaseName))
            {
                fileList.Remove(currentDatabaseName);
            }

            string[] databaseNames = new string[fileList.Count];

            for (int i = 0; i < fileList.Count; i++)
            {
                databaseNames[i] = Path.GetFileNameWithoutExtension(fileList[i]);
            }

            string selectedDatabasePath = null;

            var builder = new AlertDialog.Builder(this);

            builder.SetTitle("Datenbank löschen");
            builder.SetSingleChoiceItems(databaseNames, -1,
                                         new EventHandler <DialogClickEventArgs>(delegate(object sender, DialogClickEventArgs e)
            {
                // Get reference to AlertDialog
                var d = (sender as Android.App.AlertDialog);

                // Auswahl merken
                selectedDatabasePath = fileList[e.Which];
            }));
            builder.SetPositiveButton("LÖSCHEN", (s, e) =>
            {
                if (string.IsNullOrEmpty(selectedDatabasePath))
                {
                    return;
                }

                Exception ex = Android_Database.Instance.DeleteDatabase(selectedDatabasePath);

                if (ex != null)
                {
                    var message = new AlertDialog.Builder(this);
                    message.SetMessage(ex.Message);
                    message.SetPositiveButton("OK", (s, e) => { });
                    message.Create().Show();
                }
            });

            builder.SetNegativeButton("Abbruch", (s, e) => { });
            builder.Show();
        }