mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-10 07:48:30 -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>) {
|
fun insert(booksOnDisk: List<BookOnDisk>) {
|
||||||
box.store.callInTx {
|
box.store.callInTx {
|
||||||
box
|
val uniqueBooks = uniqueBooksByFile(booksOnDisk)
|
||||||
.query {
|
removeEntriesWithMatchingIds(uniqueBooks)
|
||||||
inValues(BookOnDiskEntity_.bookId, booksOnDisk.map { it.book.id }.toTypedArray())
|
box.put(uniqueBooks.distinctBy { it.book.id }.map(::BookOnDiskEntity))
|
||||||
}
|
|
||||||
.remove()
|
|
||||||
box.put(booksOnDisk.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) {
|
fun delete(databaseId: Long) {
|
||||||
box.remove(databaseId)
|
box.remove(databaseId)
|
||||||
}
|
}
|
||||||
|
@ -255,6 +255,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
private TextView tabSwitcherIcon;
|
private TextView tabSwitcherIcon;
|
||||||
private TableDrawerAdapter tableDrawerAdapter;
|
private TableDrawerAdapter tableDrawerAdapter;
|
||||||
private RecyclerView tableDrawerRight;
|
private RecyclerView tableDrawerRight;
|
||||||
|
private boolean hasLocalBooks;
|
||||||
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(@NonNull RecyclerView recyclerView,
|
public int getMovementFlags(@NonNull RecyclerView recyclerView,
|
||||||
@ -895,7 +896,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_openfile:
|
case R.id.menu_openfile:
|
||||||
manageZimFiles(1);
|
manageZimFiles(hasLocalBooks ? 0 : 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_settings:
|
case R.id.menu_settings:
|
||||||
@ -1182,7 +1183,10 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
storageObserver.getBooksOnFileSystem()
|
storageObserver.getBooksOnFileSystem()
|
||||||
.take(1)
|
.take(1)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.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
|
// Workaround for popup bottom menu on older devices
|
||||||
|
@ -74,6 +74,18 @@ class ZimFileReader(
|
|||||||
val description: String get() = jniKiwixReader.description
|
val description: String get() = jniKiwixReader.description
|
||||||
val favicon: String get() = jniKiwixReader.favicon
|
val favicon: String get() = jniKiwixReader.favicon
|
||||||
val language: String get() = jniKiwixReader.language
|
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) =
|
fun searchSuggestions(prefix: String, count: Int) =
|
||||||
jniKiwixReader.searchSuggestions(prefix, count)
|
jniKiwixReader.searchSuggestions(prefix, count)
|
||||||
@ -195,6 +207,9 @@ class ZimFileReader(
|
|||||||
date = this@ZimFileReader.date
|
date = this@ZimFileReader.date
|
||||||
description = this@ZimFileReader.description
|
description = this@ZimFileReader.description
|
||||||
language = this@ZimFileReader.language
|
language = this@ZimFileReader.language
|
||||||
|
articleCount = this@ZimFileReader.articleCount.toString()
|
||||||
|
mediaCount = this@ZimFileReader.mediaCount.toString()
|
||||||
|
bookName = name
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user