private void UpdateView() { ISharedPreferences prefs = Application.Context.GetSharedPreferences("Settings", FileCreationMode.Private); var isDark = prefs.GetBoolean("appThemeDark", false); if (isDark) { this.SetTheme(global::Android.Resource.Style.ThemeHolo); } else this.SetTheme(global::Android.Resource.Style.ThemeHoloLight); adapter = new GalleryAdapter(this, _books); ListView listView = FindViewById<ListView>(Resource.Id.ListView); listView.Adapter = adapter; if ((CurrentBook = TranslyteDbGateway.GetCurrentBook()) != null) { ImageView image = FindViewById<ImageView>(Resource.Id.CoverCurrent); if (CurrentBook.Cover != null) { var img = new BitmapConverteHelper().GetCover(CurrentBook.Cover); image.SetImageBitmap(img); } TextView title = FindViewById<TextView>(Resource.Id.TitleCurrent); title.Text = CurrentBook.Title; TextView author = FindViewById<TextView>(Resource.Id.AuthorCurrent); author.Text = CurrentBook.Author; } RunOnUiThread(() => { Thread.CurrentThread.IsBackground = true; Java.IO.File dir = new Java.IO.File(EnvironmentAnd.ExternalStorageDirectory.AbsolutePath + @"/translyte"); var files = dir.ListFiles (); var localBooks = TranslyteDbGateway.GetBooksLocalReview (); foreach(var file in files) { var isLocal = localBooks.Any (ss=>ss.BookPath.Equals(file.AbsolutePath)); if (!isLocal) { TranslyteDbGateway.SaveBookLocal(new BookLocal(){BookPath = file.AbsolutePath, Position = 0, IsCurrent = false}); } } _books = TranslyteDbGateway.GetBooksLocalReviewWithoutCurrent(); adapter = new GalleryAdapter(this, _books); }); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.LibraryView); _context = this; SetupMenu(); var sqliteFilename = "TaskDB.db3"; string libraryPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); var path = Path.Combine(libraryPath, sqliteFilename); conn = new Connection(path); TranslyteDbGateway = new TranslyteDbGateway(conn); Java.IO.File dir = new Java.IO.File(EnvironmentAnd.ExternalStorageDirectory.AbsolutePath + @"/translyte"); if (!dir.Exists ()) { dir.Mkdirs (); TranslyteDbGateway.DeleteAllBooks (); } UpdateView (); //_books = TranslyteDbGateway.GetBooksLocalReviewWithoutCurrent(); //adapter = new GalleryAdapter(this, _books); ListView listView = FindViewById<ListView>(Resource.Id.ListView); listView.Adapter = adapter; listView.ItemClick += OnListItemClick; if ((CurrentBook = TranslyteDbGateway.GetCurrentBook()) != null) { ImageView image = FindViewById<ImageView>(Resource.Id.CoverCurrent); if (CurrentBook.Cover != null) { var img = new BitmapConverteHelper().GetCover(CurrentBook.Cover); image.SetImageBitmap(img); } LinearLayout last_book_view = FindViewById<LinearLayout>(Resource.Id.last_book_view); last_book_view.Click += delegate { string jsonModel = JsonConvert.SerializeObject(CurrentBook); var fragment = new BookView(); Bundle bookBundle = new Bundle(); bookBundle.PutString("book", jsonModel); fragment.Arguments = bookBundle; ChangeFragment(fragment); }; TextView title = FindViewById<TextView>(Resource.Id.TitleCurrent); title.Text = CurrentBook.Title; TextView author = FindViewById<TextView>(Resource.Id.AuthorCurrent); author.Text = CurrentBook.Author; } }