mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 14:52:13 -04:00
#1502 Navigate to correct tab and fix double insertions
This commit is contained in:
parent
bf044e9ddb
commit
35e2da81e4
@ -39,15 +39,30 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||
|
||||
fun insert(booksOnDisk: List<BookOnDisk>) {
|
||||
box.store.callInTx {
|
||||
box
|
||||
.query {
|
||||
inValues(BookOnDiskEntity_.bookId, booksOnDisk.map { it.book.id }.toTypedArray())
|
||||
}
|
||||
.remove()
|
||||
box.put(booksOnDisk.distinctBy { it.book.id }.map(::BookOnDiskEntity))
|
||||
val uniqueBooks = uniqueBooksByFile(booksOnDisk)
|
||||
removeEntriesWithMatchingIds(uniqueBooks)
|
||||
box.put(uniqueBooks.distinctBy { it.book.id }.map(::BookOnDiskEntity))
|
||||
}
|
||||
}
|
||||
|
||||
private fun uniqueBooksByFile(booksOnDisk: List<BookOnDisk>): List<BookOnDisk> {
|
||||
val booksThatPointToSameLocation = box
|
||||
.query {
|
||||
inValues(BookOnDiskEntity_.file, booksOnDisk.map { it.file.path }.toTypedArray())
|
||||
}.find().map(::BookOnDisk)
|
||||
return booksOnDisk.filter { bookOnDisk: BookOnDisk ->
|
||||
booksThatPointToSameLocation.find { it.file.path == bookOnDisk.file.path } == null
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeEntriesWithMatchingIds(newBooks: List<BookOnDisk>) {
|
||||
box
|
||||
.query {
|
||||
inValues(BookOnDiskEntity_.bookId, newBooks.map { it.book.id }.toTypedArray())
|
||||
}
|
||||
.remove()
|
||||
}
|
||||
|
||||
fun delete(databaseId: Long) {
|
||||
box.remove(databaseId)
|
||||
}
|
||||
|
@ -255,6 +255,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
private TextView tabSwitcherIcon;
|
||||
private TableDrawerAdapter tableDrawerAdapter;
|
||||
private RecyclerView tableDrawerRight;
|
||||
private boolean hasLocalBooks;
|
||||
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
||||
@Override
|
||||
public int getMovementFlags(@NonNull RecyclerView recyclerView,
|
||||
@ -895,7 +896,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
return true;
|
||||
|
||||
case R.id.menu_openfile:
|
||||
manageZimFiles(1);
|
||||
manageZimFiles(hasLocalBooks ? 0 : 1);
|
||||
break;
|
||||
|
||||
case R.id.menu_settings:
|
||||
@ -1182,7 +1183,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
storageObserver.getBooksOnFileSystem()
|
||||
.take(1)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(presenter::saveBooks, Throwable::printStackTrace);
|
||||
.subscribe(books -> {
|
||||
presenter.saveBooks(books);
|
||||
hasLocalBooks = !books.isEmpty();
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
// Workaround for popup bottom menu on older devices
|
||||
|
@ -74,6 +74,18 @@ class ZimFileReader(
|
||||
val description: String get() = jniKiwixReader.description
|
||||
val favicon: String get() = jniKiwixReader.favicon
|
||||
val language: String get() = jniKiwixReader.language
|
||||
private val mediaCount: Int?
|
||||
get() = try {
|
||||
jniKiwixReader.mediaCount
|
||||
} catch (ignore: UnsatisfiedLinkError) {
|
||||
null
|
||||
}
|
||||
private val articleCount: Int?
|
||||
get() = try {
|
||||
jniKiwixReader.articleCount
|
||||
} catch (ignore: UnsatisfiedLinkError) {
|
||||
null
|
||||
}
|
||||
|
||||
fun searchSuggestions(prefix: String, count: Int) =
|
||||
jniKiwixReader.searchSuggestions(prefix, count)
|
||||
@ -195,6 +207,9 @@ class ZimFileReader(
|
||||
date = this@ZimFileReader.date
|
||||
description = this@ZimFileReader.description
|
||||
language = this@ZimFileReader.language
|
||||
articleCount = this@ZimFileReader.articleCount.toString()
|
||||
mediaCount = this@ZimFileReader.mediaCount.toString()
|
||||
bookName = name
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Loading…
x
Reference in New Issue
Block a user