diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 21466c0ae9..57236bb360 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -99,7 +99,6 @@ play { } dependencies { - implementation(Libs.squidb) androidTestImplementation(Libs.leakcanary_android_instrumentation) } task("generateVersionCodeAndName") { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt deleted file mode 100644 index b724156f18..0000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.data.local - -import android.content.Context -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import androidx.test.platform.app.InstrumentationRegistry -import com.yahoo.squidb.sql.Query -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.kiwix.kiwixmobile.core.data.local.KiwixDatabase -import org.kiwix.kiwixmobile.core.data.local.entity.Bookmark -import java.io.BufferedWriter -import java.io.File -import java.io.FileOutputStream -import java.io.IOException -import java.io.OutputStreamWriter -import java.io.Writer - -@RunWith(AndroidJUnit4::class) -@SmallTest -class KiwixDatabaseTest { - private val context: Context = InstrumentationRegistry.getInstrumentation().targetContext - - @Test @Throws(IOException::class) // Standard charset throws exception on < API19 - fun testMigrateDatabase() { - val kiwixDatabase = KiwixDatabase( - context, - null, - null, - null, - null - ) - kiwixDatabase.recreate() - val testId = "8ce5775a-10a9-bbf3-178a-9df69f23263c" - val testBookmarks = arrayOf("Test1", "Test2", "Test3") - val fileName = context.filesDir.absolutePath + File.separator + testId + ".txt" - val f = File(fileName) - if (!f.createNewFile()) { - throw IOException("Unable to create file for testing migration") - } - val writer: Writer = BufferedWriter( - OutputStreamWriter( - FileOutputStream(fileName), - "UTF-8" - ) - ) - for (bookmark in testBookmarks) { - writer.write( - """ - $bookmark - - """.trimIndent() - ) - } - writer.close() - kiwixDatabase.migrateBookmarksVersion6() - val bookmarkTitles = ArrayList() - try { - val bookmarkCursor = kiwixDatabase.query( - Bookmark::class.java, - Query.selectDistinct(Bookmark.BOOKMARK_TITLE) - .where( - Bookmark.ZIM_ID.eq(testId) - .or(Bookmark.ZIM_NAME.eq("")) - ) - .orderBy(Bookmark.BOOKMARK_TITLE.asc()) - ) - while (bookmarkCursor.moveToNext()) { - bookmarkTitles.add(bookmarkCursor.get(Bookmark.BOOKMARK_TITLE)) - } - } catch (exception: Exception) { - exception.printStackTrace() - } - Assert.assertArrayEquals(testBookmarks, bookmarkTitles.toTypedArray()) - - // TODO Add new migration test for version 16 - } -} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/BookDaoTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/BookDaoTest.kt deleted file mode 100644 index d94130a29f..0000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/BookDaoTest.kt +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.data.local.dao - -import android.content.Context -import androidx.test.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.jupiter.api.fail -import org.junit.runner.RunWith -import org.kiwix.kiwixmobile.core.data.local.KiwixDatabase -import org.kiwix.kiwixmobile.core.data.local.dao.BookDao -import org.kiwix.kiwixmobile.core.data.local.entity.BookDatabaseEntity -import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book -import java.io.File -import java.io.IOException -import java.util.ArrayList - -@RunWith(AndroidJUnit4::class) -class BookDaoTest { - private var testDir: File? = null - - @Before - fun executeBefore() { - testDir = InstrumentationRegistry.getTargetContext().getDir("testDir", Context.MODE_PRIVATE) - } - - // TODO : test books are saved after downloading the list of available zim files - @Test @Throws(IOException::class) - fun testGetBooks() { // Save the fake data to test - val kiwixDatabase = mockk() - val bookDao = BookDao(kiwixDatabase) - val testId = "6qq5301d-2cr0-ebg5-474h-6db70j52864p" - val fileName = testDir?.path + "/" + testId + "testFile" - val booksToAdd = getFakeData(fileName) - every { kiwixDatabase.deleteWhere(any(), any()) } returns 0 - val booksRetrieved = - bookDao.filterBookResults(booksToAdd) - if (!booksRetrieved.contains(booksToAdd[0])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[0].file?.path) - ) - } - if (booksRetrieved.contains(booksToAdd[1])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[1].file?.path) - ) - } - if (booksRetrieved.contains(booksToAdd[2])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[2].file?.path) - ) - } - if (booksRetrieved.contains(booksToAdd[3])) fail() - verify { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[3].file?.path) - ) - } - if (!booksRetrieved.contains(booksToAdd[4])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[4].file?.path) - ) - } - if (!booksRetrieved.contains(booksToAdd[5])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[5].file?.path) - ) - } - if (booksRetrieved.contains(booksToAdd[6])) fail() - verify { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[6].file?.path) - ) - } - if (!booksRetrieved.contains(booksToAdd[7])) fail() - verify(exactly = 0) { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[7].file?.path) - ) - } - if (booksRetrieved.contains(booksToAdd[8])) fail() - verify { - kiwixDatabase.deleteWhere( - BookDatabaseEntity::class.java, - BookDatabaseEntity.URL.eq(booksToAdd[8].file?.path) - ) - } - } - - private fun fail() { - fail { "shouldn't happen" } - } - - @Throws(IOException::class) - private fun getFakeData(baseFileName: String): ArrayList { - val books = - ArrayList() - for (i in 0..8) { - val book = Book() - book.bookName = "Test Copy $i" - book.id = "Test ID $i" - val fileName = baseFileName + i - when (i) { - 0 -> { - book.file = File("$fileName.zim") - book.file?.createNewFile() - } - 1 -> { - book.file = File("$fileName.part") - book.file?.createNewFile() - } - 2 -> { - book.file = File("$fileName.zim") - val t2 = File("$fileName.zim.part") - t2.createNewFile() - } - 3 -> book.file = File("$fileName.zim") - 4 -> { - book.file = File("$fileName.zim") - book.file?.createNewFile() - val t4 = File("$fileName.zim.part") - t4.createNewFile() - } - 5 -> { - book.file = File("$fileName.zimdg") - setupCase1(fileName) - } - 6 -> { - book.file = File("$fileName.zimyr") - setupCase2(fileName) - } - 7 -> { - book.file = File("$fileName.zimdg") - setupCase1(fileName) - } - 8 -> { - book.file = File("$fileName.zimyr") - setupCase2(fileName) - } - } - books.add(book) - } - return books - } - - @Throws(IOException::class) - private fun setupCase1(fileName: String) { - var char1 = 'a' - while (char1 <= 'z') { - var char2 = 'a' - while (char2 <= 'z') { - val file = File("$fileName.zim$char1$char2") - file.createNewFile() - if (char1 == 'd' && char2 == 'r') { - break - } - char2++ - } - if (char1 == 'd') { - break - } - char1++ - } - } - - @Throws(IOException::class) - private fun setupCase2(fileName: String) { - var char1 = 'a' - while (char1 <= 'z') { - var char2 = 'a' - while (char2 <= 'z') { - val file = File("$fileName.zim$char1$char2") - file.createNewFile() - if (char1 == 'd' && char2 == 'r') { - break - } - char2++ - } - if (char1 == 'd') { - break - } - char1++ - } - val t = File("$fileName.zimcp.part") - } - - @After fun removeTestDirectory() { - for (child in testDir?.listFiles() ?: emptyArray()) { - child.delete() - } - testDir?.delete() - } -} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/RecentSearchDaoTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/RecentSearchDaoTest.kt deleted file mode 100644 index 4fecbbb790..0000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/dao/RecentSearchDaoTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.data.local.dao - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.yahoo.squidb.data.AbstractModel -import com.yahoo.squidb.data.SquidCursor -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import org.junit.Test -import org.junit.runner.RunWith -import org.kiwix.kiwixmobile.core.data.local.KiwixDatabase -import org.kiwix.kiwixmobile.core.data.local.dao.RecentSearchDao - -@RunWith(AndroidJUnit4::class) -class RecentSearchDaoTest { - - @Test fun testGetRecentSearches() { - val kiwixDatabase = mockk() - every { - kiwixDatabase.query(any>(), any()) - } returns mockk>(relaxed = true) - RecentSearchDao(kiwixDatabase).getRecentSearches() - verify { kiwixDatabase.query(any>(), any()) } - } -} diff --git a/app/src/main/assets/credits.html b/app/src/main/assets/credits.html index 5ccec14f47..cd0a10b109 100644 --- a/app/src/main/assets/credits.html +++ b/app/src/main/assets/credits.html @@ -102,11 +102,6 @@

Apache


Copyright 2015 RxAndroid Authors -
  • - SquiDb -
    - Copyright 2013 Yahoo, Inc. -
  • diff --git a/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt b/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt index 33a731d552..de904086c1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt @@ -17,13 +17,16 @@ */ package org.kiwix.kiwixmobile.language.viewmodel +import android.annotation.SuppressLint import androidx.appcompat.app.AppCompatActivity import io.reactivex.Flowable +import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.zim_manager.Language +@SuppressLint("CheckResult") data class SaveLanguagesAndFinish( val languages: List, val languageDao: NewLanguagesDao @@ -32,6 +35,7 @@ data class SaveLanguagesAndFinish( override fun invokeWith(activity: AppCompatActivity) { Flowable.fromCallable { languageDao.insert(languages) } .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) .subscribe({ activity.onBackPressed() }, Throwable::printStackTrace) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index 6588b1f914..00617025a9 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -36,6 +36,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.Toolbar +import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.ContextCompat import androidx.core.net.toUri import androidx.fragment.app.FragmentActivity @@ -43,6 +44,7 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.bottomnavigation.BottomNavigationView import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import org.kiwix.kiwixmobile.R @@ -149,6 +151,12 @@ class LocalLibraryFragment : BaseFragment() { .also { coreMainActivity.navHostContainer .setBottomMarginToFragmentContainerView(0) + + val bottomNavigationView = + requireActivity().findViewById(R.id.bottom_nav_view) + bottomNavigationView?.let { + setBottomMarginToSwipeRefreshLayout(bottomNavigationView.measuredHeight) + } } disposable.add(sideEffects()) zimManageViewModel.deviceListIsRefreshing.observe(viewLifecycleOwner) { @@ -164,6 +172,14 @@ class LocalLibraryFragment : BaseFragment() { hideFilePickerButton() } + private fun setBottomMarginToSwipeRefreshLayout(marginBottom: Int) { + fragmentDestinationLibraryBinding?.zimSwiperefresh?.apply { + val params = layoutParams as CoordinatorLayout.LayoutParams? + params?.bottomMargin = marginBottom + requestLayout() + } + } + private fun hideFilePickerButton() { if (sharedPreferenceUtil.isPlayStoreBuild) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index 9243b46f0e..956ec3adcd 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -177,7 +177,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { viewLifecycleOwner ) { if (it) { - showInternetPermissionDialog() + showInternetAccessViaMobileNetworkDialog() } } @@ -189,19 +189,14 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } } ) - - fragmentDestinationDownloadBinding?.allowInternetPermissionButton?.setOnClickListener { - showInternetPermissionDialog() - } } - private fun showInternetPermissionDialog() { + private fun showInternetAccessViaMobileNetworkDialog() { dialogShower.show( WifiOnly, { onRefreshStateChange(true) - fragmentDestinationDownloadBinding?.libraryErrorText?.visibility = View.GONE - fragmentDestinationDownloadBinding?.allowInternetPermissionButton?.visibility = View.GONE + showRecyclerviewAndHideSwipeDownForLibraryErrorText() sharedPreferenceUtil.putPrefWifiOnly(false) zimManageViewModel.shouldShowWifiOnlyDialog.value = false }, @@ -211,15 +206,28 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { resources.getString(R.string.denied_internet_permission_message), Toast.LENGTH_SHORT ) - fragmentDestinationDownloadBinding?.libraryErrorText?.setText( - R.string.allow_internet_permission_message - ) - fragmentDestinationDownloadBinding?.libraryErrorText?.visibility = View.VISIBLE - fragmentDestinationDownloadBinding?.allowInternetPermissionButton?.visibility = View.VISIBLE + hideRecyclerviewAndShowSwipeDownForLibraryErrorText() } ) } + private fun showRecyclerviewAndHideSwipeDownForLibraryErrorText() { + fragmentDestinationDownloadBinding?.apply { + libraryErrorText.visibility = View.GONE + libraryList.visibility = View.VISIBLE + } + } + + private fun hideRecyclerviewAndShowSwipeDownForLibraryErrorText() { + fragmentDestinationDownloadBinding?.apply { + libraryErrorText.setText( + R.string.swipe_down_for_library + ) + libraryErrorText.visibility = View.VISIBLE + libraryList.visibility = View.GONE + } + } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { super.onCreateOptionsMenu(menu, inflater) inflater.inflate(R.menu.menu_zim_manager, menu) @@ -245,6 +253,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { override fun onDestroyView() { super.onDestroyView() + availableSpaceCalculator.dispose() fragmentDestinationDownloadBinding?.libraryList?.adapter = null fragmentDestinationDownloadBinding = null } @@ -261,6 +270,13 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { private fun onNetworkStateChange(networkState: NetworkState?) { when (networkState) { NetworkState.CONNECTED -> { + if (NetworkUtils.isWiFi(requireContext())) { + onRefreshStateChange(true) + refreshFragment() + } else if (noWifiWithWifiOnlyPreferenceSet) { + onRefreshStateChange(false) + hideRecyclerviewAndShowSwipeDownForLibraryErrorText() + } } NetworkState.NOT_CONNECTED -> { if (libraryAdapter.itemCount > 0) { @@ -271,7 +287,6 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { ) fragmentDestinationDownloadBinding?.libraryErrorText?.visibility = View.VISIBLE } - fragmentDestinationDownloadBinding?.allowInternetPermissionButton?.visibility = View.GONE fragmentDestinationDownloadBinding?.librarySwipeRefresh?.isRefreshing = false } else -> {} @@ -301,7 +316,6 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } else { fragmentDestinationDownloadBinding?.libraryErrorText?.visibility = View.GONE } - fragmentDestinationDownloadBinding?.allowInternetPermissionButton?.visibility = View.GONE } private fun refreshFragment() { @@ -310,6 +324,8 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } else { zimManageViewModel.requestDownloadLibrary.onNext(Unit) } + fragmentDestinationDownloadBinding?.libraryErrorText?.visibility = View.GONE + fragmentDestinationDownloadBinding?.libraryList?.visibility = View.VISIBLE } private fun downloadFile() { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.kt index 7ced19e691..09920833f6 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.kt @@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.webserver import android.util.Log import io.reactivex.Flowable import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.Disposable import org.kiwix.kiwixmobile.core.utils.DEFAULT_PORT import org.kiwix.kiwixmobile.core.utils.ServerUtils import org.kiwix.kiwixmobile.core.utils.ServerUtils.INVALID_IP @@ -40,6 +41,7 @@ class WebServerHelper @Inject constructor( ) { private var kiwixServer: KiwixServer? = null private var isServerStarted = false + private var validIpAddressDisposable: Disposable? = null fun startServerHelper(selectedBooksPath: ArrayList): Boolean { val ip = getIpAddress() @@ -79,7 +81,7 @@ class WebServerHelper @Inject constructor( // If no ip is found after 15 seconds, dismisses the progress dialog @Suppress("MagicNumber") fun pollForValidIpAddress() { - Flowable.interval(1, TimeUnit.SECONDS) + validIpAddressDisposable = Flowable.interval(1, TimeUnit.SECONDS) .map { getIp() } .filter { s: String? -> s != INVALID_IP } .timeout(15, TimeUnit.SECONDS) @@ -96,6 +98,10 @@ class WebServerHelper @Inject constructor( } } + fun dispose() { + validIpAddressDisposable?.dispose() + } + companion object { private const val TAG = "WebServerHelper" } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt index fca38f16e9..50daf99610 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt @@ -64,6 +64,7 @@ class HotspotService : } override fun onDestroy() { + webServerHelper?.dispose() hotspotStateReceiver?.let(this@HotspotService::unregisterReceiver) super.onDestroy() } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt index 740081e7cd..1ced19f793 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt @@ -17,6 +17,7 @@ */ package org.kiwix.kiwixmobile.zimManager +import android.annotation.SuppressLint import android.os.FileObserver import io.reactivex.Flowable import io.reactivex.functions.BiFunction @@ -32,6 +33,7 @@ import org.kiwix.kiwixmobile.zimManager.FileSystemCapability.CAN_WRITE_4GB import org.kiwix.kiwixmobile.zimManager.FileSystemCapability.INCONCLUSIVE import java.io.File +@SuppressLint("CheckResult") class Fat32Checker constructor( sharedPreferenceUtil: SharedPreferenceUtil, private val fileSystemCheckers: List diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt index a614c6c1c0..b447ee6617 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt @@ -246,12 +246,14 @@ class ZimManageViewModel @Inject constructor( .observeOn(Schedulers.io()) .subscribe( { - kiwixService.library - .retry(5) - .subscribe(library::onNext) { - it.printStackTrace() - library.onNext(LibraryNetworkEntity().apply { book = LinkedList() }) - } + compositeDisposable?.add( + kiwixService.library + .retry(5) + .subscribe(library::onNext) { + it.printStackTrace() + library.onNext(LibraryNetworkEntity().apply { book = LinkedList() }) + } + ) }, Throwable::printStackTrace ) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt index 1c466ef14a..66647a0373 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt @@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile.zimManager.libraryView import eu.mhutti1.utils.storage.Bytes import eu.mhutti1.utils.storage.Kb import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel @@ -32,12 +33,13 @@ class AvailableSpaceCalculator @Inject constructor( private val downloadDao: FetchDownloadDao, private val storageCalculator: StorageCalculator ) { + private var availableSpaceCalculatorDisposable: Disposable? = null fun hasAvailableSpaceFor( bookItem: LibraryListItem.BookItem, successAction: (LibraryListItem.BookItem) -> Unit, failureAction: (String) -> Unit ) { - downloadDao.allDownloads() + availableSpaceCalculatorDisposable = downloadDao.allDownloads() .map { it.map(DownloadModel::bytesRemaining).sum() } .map { bytesToBeDownloaded -> storageCalculator.availableBytes() - bytesToBeDownloaded } .subscribeOn(Schedulers.io()) @@ -50,4 +52,8 @@ class AvailableSpaceCalculator @Inject constructor( } } } + + fun dispose() { + availableSpaceCalculatorDisposable?.dispose() + } } diff --git a/app/src/main/res/layout/fragment_destination_download.xml b/app/src/main/res/layout/fragment_destination_download.xml index 9d71a38410..3a6c07d194 100644 --- a/app/src/main/res/layout/fragment_destination_download.xml +++ b/app/src/main/res/layout/fragment_destination_download.xml @@ -65,16 +65,4 @@ app:layout_constraintVertical_bias="0.45" tools:ignore="RequiredSize" /> -