diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/DownloadTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/DownloadTest.java index 7f270da48..ed05cfdec 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/DownloadTest.java +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/DownloadTest.java @@ -22,7 +22,6 @@ import android.Manifest; import android.util.Log; import androidx.test.espresso.IdlingPolicies; import androidx.test.espresso.IdlingRegistry; -import androidx.test.espresso.ViewInteraction; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import androidx.test.rule.ActivityTestRule; @@ -41,15 +40,11 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity; import org.kiwix.kiwixmobile.utils.KiwixIdlingResource; import static androidx.test.espresso.Espresso.onData; -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withParent; import static com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed; import static com.schibsted.spain.barista.interaction.BaristaClickInteractions.clickOn; import static com.schibsted.spain.barista.interaction.BaristaSwipeRefreshInteractions.refresh; import static junit.framework.Assert.fail; -import static org.hamcrest.Matchers.allOf; import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS; import static org.kiwix.kiwixmobile.testutils.TestUtils.allowPermissionsIfNeeded; import static org.kiwix.kiwixmobile.testutils.TestUtils.captureAndSaveScreenshot; @@ -98,11 +93,6 @@ public class DownloadTest { clickOn(R.string.remote_zims); captureAndSaveScreenshot("Before-checking-for-ZimManager-Main-Activity"); - ViewInteraction viewPager2 = onView( - allOf(withId(R.id.manageViewPager), - withParent(allOf(withId(R.id.zim_manager_main_activity), - withParent(withId(android.R.id.content)))), - isDisplayed())); captureAndSaveScreenshot("After-the-check-completed"); BaristaSleepInteractions.sleep(TEST_PAUSE_MS); diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageActivityTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageActivityTest.java index 8e12b0096..31790a4e0 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageActivityTest.java +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageActivityTest.java @@ -24,7 +24,6 @@ import androidx.test.espresso.intent.Intents; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.rule.GrantPermissionRule; import com.schibsted.spain.barista.interaction.BaristaSleepInteractions; -import com.schibsted.spain.barista.rule.BaristaRule; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -32,7 +31,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.kiwix.kiwixmobile.R; -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -54,9 +52,6 @@ import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS; public class LanguageActivityTest { @Rule - public BaristaRule activityTestRule = - BaristaRule.create(ZimManageActivity.class); - @Rule public GrantPermissionRule readPermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE); @Rule @@ -66,7 +61,6 @@ public class LanguageActivityTest { @Before public void setUp() { Intents.init(); - activityTestRule.launchActivity(); } @Test @@ -86,7 +80,7 @@ public class LanguageActivityTest { String language2 = "german"; // References for the checkboxes for the corresponding languages - ViewInteraction checkBox1, checkBox2; + ViewInteraction checkBox1; // Initialise Test test languages // Search for a particular language diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java index 4a48cc17d..54302a445 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java @@ -25,6 +25,7 @@ import androidx.test.rule.ActivityTestRule; import androidx.test.rule.GrantPermissionRule; import com.schibsted.spain.barista.interaction.BaristaMenuClickInteractions; import com.schibsted.spain.barista.interaction.BaristaSleepInteractions; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,6 +49,12 @@ public class MainActivityTest { public GrantPermissionRule writePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); + @Before + public void setup() { + BaristaSleepInteractions.sleep(TEST_PAUSE_MS); + clickOn(R.string.reader); + } + @Test public void navigateHelp() { BaristaSleepInteractions.sleep(TEST_PAUSE_MS); @@ -69,16 +76,12 @@ public class MainActivityTest { @Test public void navigateDeviceContent() { BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - BaristaMenuClickInteractions.clickMenu(getResourceString(R.string.library)); - BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - clickOn(R.string.local_zims); + clickOn(R.string.library); } @Test public void navigateOnlineContent() { BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - BaristaMenuClickInteractions.clickMenu(getResourceString(R.string.library)); - BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - clickOn(R.string.remote_zims); + clickOn(R.string.download); } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainRobot.kt index e4bc08ae2..9d4910eed 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainRobot.kt @@ -19,12 +19,12 @@ package org.kiwix.kiwixmobile.main import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.core.R.id +import org.kiwix.kiwixmobile.R fun main(func: MainRobot.() -> Unit) = MainRobot().apply(func) class MainRobot : BaseRobot() { init { - isVisible(ViewId(id.activity_main_root)) + isVisible(ViewId(R.id.new_navigation_container)) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt index b082f3de0..137e54a4b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt @@ -1,103 +1,103 @@ -/* - * 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 . - * - */ - +// /* +// * 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.zim_manager - -import android.os.Build -import androidx.test.filters.SdkSuppress -import attempt -import okhttp3.mockwebserver.MockResponse -import org.junit.Ignore -import org.junit.Test -import org.kiwix.kiwixmobile.BaseActivityTest -import org.kiwix.kiwixmobile.KiwixMockServer -import org.kiwix.kiwixmobile.core.CoreApp -import org.kiwix.kiwixmobile.core.data.remote.KiwixService.LIBRARY_NETWORK_PATH -import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity -import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil -import org.kiwix.sharedFunctions.book -import org.kiwix.sharedFunctions.libraryNetworkEntity -import org.kiwix.sharedFunctions.metaLinkNetworkEntity -import java.util.concurrent.TimeUnit.SECONDS - -@SdkSuppress(minSdkVersion = Build.VERSION_CODES.JELLY_BEAN_MR2) -class ZimManageActivityTest : BaseActivityTest() { - - override var activityRule = activityTestRule { - CoreApp.coreComponent = testComponent() - } - private val book = book() - - private val mockServer = KiwixMockServer().apply { - map( - LIBRARY_NETWORK_PATH to libraryNetworkEntity(listOf(book)), - book.networkPath to metaLinkNetworkEntity() - ) - } - - @Test - @Ignore("Ignored due to flakiness on nightly build") - fun testZimManageDataFlow() { - SharedPreferenceUtil(activityRule.activity).putPrefWifiOnly(false) - zimManage { - clickOnOnline { - clickOnSearch() - searchFor(book(title = "zzzzz")) - waitForEmptyView() - searchFor(book) - pressBack() - pressBack() - forceResponse("012345678901234567890123456789012345678901234567890123456789012345678") - attempt(10) { - clickOn(book) - clickStop() - clickNegativeDialogButton() - clickStop() - clickPositiveDialogButton() - } - forceResponse("01234") - clickOn(book) - waitForEmptyView() - } - clickOnDevice { - longClickOn(book) - clickCloseActionMode() - longClickOn(book) - clickDelete() - clickNegativeDialogButton() - longClickOn(book) - clickDelete() - clickPositiveDialogButton() - waitForEmptyView() - } - clickOnOnline { - } clickOnLanguageIcon { } - } - } - - private fun forceResponse(body: String) { - mockServer.forceResponse( - MockResponse() - .setBody(body) - .throttleBody(1L, 1L, SECONDS) - ) - } - - private val LibraryNetworkEntity.Book.networkPath - get() = "/${url.substringAfterLast("/")}" -} +// +// import android.os.Build +// import androidx.test.filters.SdkSuppress +// import attempt +// import okhttp3.mockwebserver.MockResponse +// import org.junit.Ignore +// import org.junit.Test +// import org.kiwix.kiwixmobile.BaseActivityTest +// import org.kiwix.kiwixmobile.KiwixMockServer +// import org.kiwix.kiwixmobile.core.CoreApp +// import org.kiwix.kiwixmobile.core.data.remote.KiwixService.LIBRARY_NETWORK_PATH +// import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity +// import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +// import org.kiwix.sharedFunctions.book +// import org.kiwix.sharedFunctions.libraryNetworkEntity +// import org.kiwix.sharedFunctions.metaLinkNetworkEntity +// import java.util.concurrent.TimeUnit.SECONDS +// +// @SdkSuppress(minSdkVersion = Build.VERSION_CODES.JELLY_BEAN_MR2) +// class ZimManageActivityTest : BaseActivityTest() { +// +// override var activityRule = activityTestRule { +// CoreApp.coreComponent = testComponent() +// } +// private val book = book() +// +// private val mockServer = KiwixMockServer().apply { +// map( +// LIBRARY_NETWORK_PATH to libraryNetworkEntity(listOf(book)), +// book.networkPath to metaLinkNetworkEntity() +// ) +// } +// +// @Test +// @Ignore("Ignored due to flakiness on nightly build") +// fun testZimManageDataFlow() { +// SharedPreferenceUtil(activityRule.activity).putPrefWifiOnly(false) +// zimManage { +// clickOnOnline { +// clickOnSearch() +// searchFor(book(title = "zzzzz")) +// waitForEmptyView() +// searchFor(book) +// pressBack() +// pressBack() +// forceResponse("012345678901234567890123456789012345678901234567890123456789012345678") +// attempt(10) { +// clickOn(book) +// clickStop() +// clickNegativeDialogButton() +// clickStop() +// clickPositiveDialogButton() +// } +// forceResponse("01234") +// clickOn(book) +// waitForEmptyView() +// } +// clickOnDevice { +// longClickOn(book) +// clickCloseActionMode() +// longClickOn(book) +// clickDelete() +// clickNegativeDialogButton() +// longClickOn(book) +// clickDelete() +// clickPositiveDialogButton() +// waitForEmptyView() +// } +// clickOnOnline { +// } clickOnLanguageIcon { } +// } +// } +// +// private fun forceResponse(body: String) { +// mockServer.forceResponse( +// MockResponse() +// .setBody(body) +// .throttleBody(1L, 1L, SECONDS) +// ) +// } +// +// private val LibraryNetworkEntity.Book.networkPath +// get() = "/${url.substringAfterLast("/")}" +// } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt index efcee32ec..513f23a24 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt @@ -1,106 +1,106 @@ -/* - * 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 . - * - */ +// /* +// * 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.zim_manager - -import applyWithViewHierarchyPrinting -import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.StringId.TextId -import org.kiwix.kiwixmobile.Findable.Text -import org.kiwix.kiwixmobile.Findable.ViewId -import org.kiwix.kiwixmobile.LONG_WAIT -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.VERY_LONG_WAIT -import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book -import org.kiwix.kiwixmobile.language.LanguageRobot -import org.kiwix.kiwixmobile.language.language - -fun zimManage(func: ZimManageRobot.() -> Unit) = - ZimManageRobot().applyWithViewHierarchyPrinting(func) - -class ZimManageRobot : BaseRobot() { - init { - isVisible(ViewId(R.id.manageViewPager), VERY_LONG_WAIT) - } - - fun clickOnOnline(func: LibraryRobot.() -> Unit): LibraryRobot { - clickOnTab(R.string.remote_zims) - return library(func) - } - - fun clickOnDevice(func: DeviceRobot.() -> Unit): DeviceRobot { - clickOnTab(R.string.local_zims) - return device(func) - } - - private fun library(func: LibraryRobot.() -> Unit) = LibraryRobot().apply(func) - inner class LibraryRobot : BaseRobot() { - init { - isVisible(ViewId(R.id.libraryList)) - } - - fun clickOn(book: Book) { - clickOn(Text(book.title)) - } - - fun clickOnSearch() { - clickOn(ViewId(R.id.action_search), LONG_WAIT) - } - - fun searchFor(book: Book) { - isVisible(ViewId(R.id.search_src_text)).text = book.title - } - - fun waitForEmptyView() { - isVisible(ViewId(R.id.libraryErrorText), VERY_LONG_WAIT) - } - - fun clickStop() { - clickOn(ViewId(R.id.stop), LONG_WAIT) - } - - infix fun clickOnLanguageIcon(function: LanguageRobot.() -> Unit): LanguageRobot { - TextId(R.string.remote_zims) - clickOn(ViewId(R.id.select_language)) - return language(function) - } - } - - private fun device(func: DeviceRobot.() -> Unit) = DeviceRobot().apply(func) - inner class DeviceRobot : BaseRobot() { - init { - isVisible(ViewId(R.id.zimfilelist)) - } - - fun longClickOn(book: Book) { - longClickOn(Text(book.title)) - } - - fun clickCloseActionMode() { - clickOn(ViewId(R.id.action_mode_close_button)) - } - - fun clickDelete() { - clickOn(ViewId(R.id.zim_file_delete_item)) - } - - fun waitForEmptyView() { - isVisible(ViewId(R.id.file_management_no_files)) - isVisible(ViewId(R.id.go_to_downloads_button_no_files)) - } - } -} +// +// import applyWithViewHierarchyPrinting +// import org.kiwix.kiwixmobile.BaseRobot +// import org.kiwix.kiwixmobile.Findable.StringId.TextId +// import org.kiwix.kiwixmobile.Findable.Text +// import org.kiwix.kiwixmobile.Findable.ViewId +// import org.kiwix.kiwixmobile.LONG_WAIT +// import org.kiwix.kiwixmobile.R +// import org.kiwix.kiwixmobile.VERY_LONG_WAIT +// import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book +// import org.kiwix.kiwixmobile.language.LanguageRobot +// import org.kiwix.kiwixmobile.language.language +// +// fun zimManage(func: ZimManageRobot.() -> Unit) = +// ZimManageRobot().applyWithViewHierarchyPrinting(func) +// +// class ZimManageRobot : BaseRobot() { +// init { +// isVisible(ViewId(R.id.manageViewPager), VERY_LONG_WAIT) +// } +// +// fun clickOnOnline(func: LibraryRobot.() -> Unit): LibraryRobot { +// clickOnTab(R.string.remote_zims) +// return library(func) +// } +// +// fun clickOnDevice(func: DeviceRobot.() -> Unit): DeviceRobot { +// clickOnTab(R.string.local_zims) +// return device(func) +// } +// +// private fun library(func: LibraryRobot.() -> Unit) = LibraryRobot().apply(func) +// inner class LibraryRobot : BaseRobot() { +// init { +// isVisible(ViewId(R.id.libraryList)) +// } +// +// fun clickOn(book: Book) { +// clickOn(Text(book.title)) +// } +// +// fun clickOnSearch() { +// clickOn(ViewId(R.id.action_search), LONG_WAIT) +// } +// +// fun searchFor(book: Book) { +// isVisible(ViewId(R.id.search_src_text)).text = book.title +// } +// +// fun waitForEmptyView() { +// isVisible(ViewId(R.id.libraryErrorText), VERY_LONG_WAIT) +// } +// +// fun clickStop() { +// clickOn(ViewId(R.id.stop), LONG_WAIT) +// } +// +// infix fun clickOnLanguageIcon(function: LanguageRobot.() -> Unit): LanguageRobot { +// TextId(R.string.remote_zims) +// clickOn(ViewId(R.id.select_language)) +// return language(function) +// } +// } +// +// private fun device(func: DeviceRobot.() -> Unit) = DeviceRobot().apply(func) +// inner class DeviceRobot : BaseRobot() { +// init { +// isVisible(ViewId(R.id.zimfilelist)) +// } +// +// fun longClickOn(book: Book) { +// longClickOn(Text(book.title)) +// } +// +// fun clickCloseActionMode() { +// clickOn(ViewId(R.id.action_mode_close_button)) +// } +// +// fun clickDelete() { +// clickOn(ViewId(R.id.zim_file_delete_item)) +// } +// +// fun waitForEmptyView() { +// isVisible(ViewId(R.id.file_management_no_files)) +// isVisible(ViewId(R.id.go_to_downloads_button_no_files)) +// } +// } +// } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6cf3e19c3..e4e7493cf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,14 +33,6 @@ - - - + @@ -150,17 +143,6 @@ - - - - - - - - + + @@ -190,10 +176,6 @@ - - diff --git a/app/src/main/assets/home.html b/app/src/main/assets/home.html deleted file mode 100644 index b478bb5bf..000000000 --- a/app/src/main/assets/home.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - REPLACE_menu_home - - -

REPLACE_menu_home

- - diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt b/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt index 7aafbdf66..ef4e7b680 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt @@ -27,8 +27,6 @@ import org.kiwix.kiwixmobile.intro.IntroModule import org.kiwix.kiwixmobile.language.LanguageActivity import org.kiwix.kiwixmobile.local_file_transfer.LocalFileTransferActivity import org.kiwix.kiwixmobile.main.KiwixMainActivity -import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity -import org.kiwix.kiwixmobile.main.KiwixReaderFragment import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment import org.kiwix.kiwixmobile.nav.destination.reader.ReaderFragment @@ -36,7 +34,6 @@ import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity import org.kiwix.kiwixmobile.splash.KiwixSplashActivity import org.kiwix.kiwixmobile.webserver.ZimHostActivity import org.kiwix.kiwixmobile.webserver.ZimHostModule -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment @@ -56,16 +53,13 @@ interface KiwixActivityComponent { fun inject(localLibraryFragment: LocalLibraryFragment) fun inject(deleteFiles: DeleteFiles) fun inject(localFileTransferActivity: LocalFileTransferActivity) - fun inject(zimManageActivity: ZimManageActivity) fun inject(languageActivity: LanguageActivity) - fun inject(kiwixMainActivity: KiwixMainActivity) fun inject(kiwixSettingsActivity: KiwixSettingsActivity) fun inject(zimHostActivity: ZimHostActivity) fun inject(introActivity: IntroActivity) fun inject(kiwixSplashActivity: KiwixSplashActivity) - fun inject(kiwixNewNavigationActivity: KiwixNewNavigationActivity) + fun inject(kiwixMainActivity: KiwixMainActivity) fun inject(onlineLibraryFragment: OnlineLibraryFragment) - fun inject(kiwixMainFragment: KiwixReaderFragment) @Subcomponent.Builder interface Builder { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index b6dfb6c30..6ea9f1f6b 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -1,6 +1,6 @@ /* * Kiwix Android - * Copyright (c) 2019 Kiwix + * Copyright (c) 2020 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 @@ -18,25 +18,172 @@ package org.kiwix.kiwixmobile.main +import android.content.Intent +import android.net.Uri import android.os.Bundle +import android.view.MenuItem +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.appcompat.view.ActionMode +import androidx.appcompat.widget.Toolbar +import androidx.navigation.NavController +import androidx.navigation.findNavController +import androidx.navigation.ui.AppBarConfiguration +import androidx.navigation.ui.onNavDestinationSelected +import androidx.navigation.ui.setupWithNavController +import com.google.android.material.navigation.NavigationView +import kotlinx.android.synthetic.main.activity_new_navigation.bottom_nav_view +import kotlinx.android.synthetic.main.activity_new_navigation.drawer_nav_view +import kotlinx.android.synthetic.main.activity_new_navigation.new_navigation_container +import kotlinx.android.synthetic.main.activity_new_navigation.reader_drawer_nav_view import org.kiwix.kiwixmobile.R +import org.kiwix.kiwixmobile.core.Intents +import org.kiwix.kiwixmobile.core.base.BaseFragmentActivityExtensions import org.kiwix.kiwixmobile.core.di.components.CoreComponent +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.intent +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start +import org.kiwix.kiwixmobile.core.help.HelpActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity +import org.kiwix.kiwixmobile.core.page.bookmark.BookmarksActivity +import org.kiwix.kiwixmobile.core.page.history.HistoryActivity +import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity +import org.kiwix.kiwixmobile.core.utils.AlertDialogShower +import org.kiwix.kiwixmobile.core.utils.EXTRA_EXTERNAL_LINK +import org.kiwix.kiwixmobile.core.utils.KiwixDialog +import org.kiwix.kiwixmobile.core.utils.REQUEST_HISTORY_ITEM_CHOSEN +import org.kiwix.kiwixmobile.core.utils.REQUEST_PREFERENCES import org.kiwix.kiwixmobile.kiwixActivityComponent +import org.kiwix.kiwixmobile.webserver.ZimHostActivity +import javax.inject.Inject + +class KiwixMainActivity : CoreMainActivity(), NavigationView.OnNavigationItemSelectedListener { + private lateinit var navController: NavController + private lateinit var appBarConfiguration: AppBarConfiguration + private lateinit var drawerToggle: ActionBarDrawerToggle + private var actionMode: ActionMode? = null + @Inject lateinit var alertDialogShower: AlertDialogShower + val cachedComponent by lazy { kiwixActivityComponent } -class KiwixMainActivity : CoreMainActivity() { override fun injection(coreComponent: CoreComponent) { - kiwixActivityComponent.inject(this) + cachedComponent.inject(this) } + private val finishActionModeOnDestinationChange = + NavController.OnDestinationChangedListener { controller, destination, arguments -> + actionMode?.finish() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_kiwix_new_navigation) + setContentView(R.layout.activity_new_navigation) - if (savedInstanceState != null) { + navController = findNavController(R.id.nav_host_fragment) + navController.addOnDestinationChangedListener(finishActionModeOnDestinationChange) + appBarConfiguration = AppBarConfiguration( + setOf( + R.id.navigation_downloads, + R.id.navigation_library, + R.id.navigation_reader + ), new_navigation_container + ) + drawer_nav_view.setupWithNavController(navController) + drawer_nav_view.setNavigationItemSelectedListener(this) + bottom_nav_view.setupWithNavController(navController) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (drawerToggle.onOptionsItemSelected(item)) { + return true + } + return item.onNavDestinationSelected(navController) || super.onOptionsItemSelected(item) + } + + override fun onSupportActionModeStarted(mode: ActionMode) { + super.onSupportActionModeStarted(mode) + actionMode = mode + } + + fun setupDrawerToggle(toolbar: Toolbar) { + drawerToggle = + ActionBarDrawerToggle( + this, new_navigation_container, toolbar, R.string.open, R.string.close_all_tabs + ) + new_navigation_container.addDrawerListener(drawerToggle) + drawerToggle.isDrawerIndicatorEnabled = true + drawerToggle.syncState() + } + + override fun onSupportNavigateUp(): Boolean { + val navController = findNavController(R.id.nav_host_fragment) + return navController.navigateUp() || + super.onSupportNavigateUp() + } + + override fun onBackPressed() { + if (new_navigation_container.isDrawerOpen(drawer_nav_view)) { + new_navigation_container.closeDrawer(drawer_nav_view) + return + } else if (new_navigation_container.isDrawerOpen(reader_drawer_nav_view)) { + new_navigation_container.closeDrawer(reader_drawer_nav_view) return } - supportFragmentManager.beginTransaction() - .add(R.id.kiwix_fragment_containter, KiwixReaderFragment()).commit() + supportFragmentManager.fragments.filterIsInstance().forEach { + if (it.onBackPressed(this) == BaseFragmentActivityExtensions.Super.ShouldCall) { + super.onBackPressed() + } + } + } + + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + supportFragmentManager.fragments.filterIsInstance().forEach { + it.onNewIntent(intent, this) + } + } + + override fun onNavigationItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_support_kiwix -> openSupportKiwixExternalLink() + R.id.menu_settings -> openSettingsActivity() + R.id.menu_help -> start() + R.id.menu_host_books -> start() + R.id.menu_history -> openHistoryActivity() + R.id.menu_bookmarks_list -> openBookmarksActivity() + else -> return false + } + return true + } + + private fun openSupportKiwixExternalLink() { + val intent = Intent( + Intent.ACTION_VIEW, + Uri.parse("https://www.kiwix.org/support") + ).putExtra(EXTRA_EXTERNAL_LINK, true) + alertDialogShower.show( + KiwixDialog.ExternalLinkPopup, + { startActivity(intent) }, { + sharedPreferenceUtil.putPrefExternalLinkPopup(false) + startActivity(intent) + } + ) + } + + private fun openSettingsActivity() { + startActivityForResult( + Intents.internal(CoreSettingsActivity::class.java), + REQUEST_PREFERENCES + ) + } + + private fun openHistoryActivity() { + startActivityForResult( + intent(), + REQUEST_HISTORY_ITEM_CHOSEN + ) + } + + private fun openBookmarksActivity() { + startActivity( + intent() + ) } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixNewNavigationActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixNewNavigationActivity.kt deleted file mode 100644 index 07b967dfd..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixNewNavigationActivity.kt +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2020 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.main - -import android.content.Intent -import android.net.Uri -import android.os.Bundle -import android.view.MenuItem -import androidx.appcompat.app.ActionBarDrawerToggle -import androidx.appcompat.view.ActionMode -import androidx.appcompat.widget.Toolbar -import androidx.navigation.NavController -import androidx.navigation.findNavController -import androidx.navigation.ui.AppBarConfiguration -import androidx.navigation.ui.onNavDestinationSelected -import androidx.navigation.ui.setupWithNavController -import com.google.android.material.navigation.NavigationView -import kotlinx.android.synthetic.main.activity_new_navigation.bottom_nav_view -import kotlinx.android.synthetic.main.activity_new_navigation.container -import kotlinx.android.synthetic.main.activity_new_navigation.drawer_nav_view -import kotlinx.android.synthetic.main.activity_new_navigation.reader_drawer_nav_view -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.Intents -import org.kiwix.kiwixmobile.core.base.BaseFragmentActivityExtensions -import org.kiwix.kiwixmobile.core.di.components.CoreComponent -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.intent -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start -import org.kiwix.kiwixmobile.core.help.HelpActivity -import org.kiwix.kiwixmobile.core.main.CoreMainActivity -import org.kiwix.kiwixmobile.core.page.bookmark.BookmarksActivity -import org.kiwix.kiwixmobile.core.page.history.HistoryActivity -import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity -import org.kiwix.kiwixmobile.core.utils.AlertDialogShower -import org.kiwix.kiwixmobile.core.utils.EXTRA_EXTERNAL_LINK -import org.kiwix.kiwixmobile.core.utils.KiwixDialog -import org.kiwix.kiwixmobile.core.utils.REQUEST_HISTORY_ITEM_CHOSEN -import org.kiwix.kiwixmobile.core.utils.REQUEST_PREFERENCES -import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.webserver.ZimHostActivity -import javax.inject.Inject - -class KiwixNewNavigationActivity : CoreMainActivity(), - NavigationView.OnNavigationItemSelectedListener { - private lateinit var navController: NavController - private lateinit var appBarConfiguration: AppBarConfiguration - private lateinit var drawerToggle: ActionBarDrawerToggle - private var actionMode: ActionMode? = null - @Inject lateinit var alertDialogShower: AlertDialogShower - - override fun injection(coreComponent: CoreComponent) { - kiwixActivityComponent.inject(this) - } - - private val finishActionModeOnDestinationChange = - NavController.OnDestinationChangedListener { controller, destination, arguments -> - actionMode?.finish() - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_new_navigation) - - navController = findNavController(R.id.nav_host_fragment) - navController.addOnDestinationChangedListener(finishActionModeOnDestinationChange) - appBarConfiguration = AppBarConfiguration( - setOf( - R.id.navigation_downloads, - R.id.navigation_library, - R.id.navigation_reader - ), container - ) - drawer_nav_view.setupWithNavController(navController) - drawer_nav_view.setNavigationItemSelectedListener(this) - bottom_nav_view.setupWithNavController(navController) - } - - override fun onSupportActionModeStarted(mode: ActionMode) { - super.onSupportActionModeStarted(mode) - actionMode = mode - } - - fun setupDrawerToggle(toolbar: Toolbar) { - drawerToggle = - ActionBarDrawerToggle( - this, container, toolbar, R.string.open, R.string.close_all_tabs - ) - container.addDrawerListener(drawerToggle) - drawerToggle.isDrawerIndicatorEnabled = true - drawerToggle.syncState() - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (drawerToggle.onOptionsItemSelected(item)) { - return true - } - return item.onNavDestinationSelected(navController) || super.onOptionsItemSelected(item) - } - - override fun onSupportNavigateUp(): Boolean { - val navController = findNavController(R.id.nav_host_fragment) - return navController.navigateUp() || - super.onSupportNavigateUp() - } - - override fun onBackPressed() { - if (container.isDrawerOpen(drawer_nav_view)) { - container.closeDrawer(drawer_nav_view) - return - } else if (container.isDrawerOpen(reader_drawer_nav_view)) { - container.closeDrawer(reader_drawer_nav_view) - return - } - supportFragmentManager.fragments.filterIsInstance().forEach { - if (it.onBackPressed(this) == BaseFragmentActivityExtensions.Super.ShouldCall) { - super.onBackPressed() - } - } - } - - override fun onNewIntent(intent: Intent) { - super.onNewIntent(intent) - supportFragmentManager.fragments.filterIsInstance().forEach { - it.onNewIntent(intent, this) - } - } - - override fun onNavigationItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.menu_support_kiwix -> openSupportKiwixExternalLink() - R.id.menu_settings -> openSettingsActivity() - R.id.menu_help -> start() - R.id.menu_host_books -> start() - R.id.menu_history -> openHistoryActivity() - R.id.menu_bookmarks_list -> openBookmarksActivity() - else -> return false - } - return true - } - - private fun openSupportKiwixExternalLink() { - val intent = Intent( - Intent.ACTION_VIEW, - Uri.parse("https://www.kiwix.org/support") - ).putExtra(EXTRA_EXTERNAL_LINK, true) - alertDialogShower.show(KiwixDialog.ExternalLinkPopup, - { startActivity(intent) }, { - sharedPreferenceUtil.putPrefExternalLinkPopup(false) - startActivity(intent) - } - ) - } - - private fun openSettingsActivity() { - startActivityForResult( - Intents.internal(CoreSettingsActivity::class.java), - REQUEST_PREFERENCES - ) - } - - private fun openHistoryActivity() { - startActivityForResult( - intent(), - REQUEST_HISTORY_ITEM_CHOSEN - ) - } - - private fun openBookmarksActivity() { - startActivity( - intent() - ) - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixReaderFragment.kt deleted file mode 100644 index 45759c205..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixReaderFragment.kt +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2020 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.main - -import android.content.Intent -import android.os.Bundle -import android.util.Log -import android.view.Menu -import androidx.appcompat.app.AppCompatActivity -import androidx.core.net.toFile -import androidx.core.net.toUri -import org.json.JSONArray -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.base.BaseActivity -import org.kiwix.kiwixmobile.core.base.BaseFragmentActivityExtensions.Super -import org.kiwix.kiwixmobile.core.base.BaseFragmentActivityExtensions.Super.ShouldCall -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start -import org.kiwix.kiwixmobile.core.extensions.snack -import org.kiwix.kiwixmobile.core.extensions.toast -import org.kiwix.kiwixmobile.core.main.CoreReaderFragment -import org.kiwix.kiwixmobile.core.main.WebViewCallback -import org.kiwix.kiwixmobile.core.reader.ZimFileReader -import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer -import org.kiwix.kiwixmobile.core.utils.EXTRA_ZIM_FILE -import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil -import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES -import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE -import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_POSITIONS -import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_TAB -import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX -import org.kiwix.kiwixmobile.core.utils.UpdateUtils -import org.kiwix.kiwixmobile.core.utils.files.FileUtils -import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.webserver.ZimHostActivity -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity -import java.io.File - -private const val HOME_URL = "file:///android_asset/home.html" - -class KiwixReaderFragment : CoreReaderFragment() { - - override fun inject(baseActivity: BaseActivity) { - baseActivity.kiwixActivityComponent.inject(this) - } - - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - manageExternalLaunchAndRestoringViewState() - } - - override fun onCreateOptionsMenu( - menu: Menu, - activity: AppCompatActivity - ): Super = ShouldCall - - override fun onResume() { - super.onResume() - if (zimReaderContainer.zimFile == null && HOME_URL != getCurrentWebView().url) { - showHomePage() - } - } - - override fun createWebClient( - webViewCallback: WebViewCallback, - zimReaderContainer: ZimReaderContainer - ) = KiwixWebViewClient(webViewCallback, zimReaderContainer) - - override fun onNewNavigationMenuClicked() { - startActivity(Intent(activity, KiwixNewNavigationActivity::class.java)) - } - - override fun onBackPressed(activity: AppCompatActivity): Super { - var callType = super.onBackPressed(activity) - if (callType == ShouldCall && getCurrentWebView().canGoBack() && - HOME_URL != getCurrentWebView().url - ) { - getCurrentWebView().goBack() - callType = Super.ShouldNotCall - } - return callType - } - - private fun manageExternalLaunchAndRestoringViewState() { - - val data = uriFromIntent() - if (data != null) { - val filePath = FileUtils.getLocalFilePathByUri(requireActivity().applicationContext, data) - - if (filePath == null || !File(filePath).exists()) { - getCurrentWebView().snack(R.string.error_file_not_found) - return - } - - Log.d( - TAG_KIWIX, "Kiwix started from a file manager. Intent filePath: " + - filePath + - " -> open this zim file and load menu_main page" - ) - openZimFile(File(filePath)) - } else { - val settings = activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0) - val zimFile = settings?.getString(TAG_CURRENT_FILE, null) - if (zimFile != null && File(zimFile).exists()) { - Log.d( - TAG_KIWIX, - "Kiwix normal start, zimFile loaded last time -> Open last used zimFile $zimFile" - ) - restoreTabStates() - // Alternative would be to restore webView state. But more effort to implement, and actually - // fits better normal android behavior if after closing app ("back" button) state is not maintained. - } else { - Log.d(TAG_KIWIX, "Kiwix normal start, no zimFile loaded last time -> display home page") - showHomePage() - } - } - } - - override fun hasValidFileAndUrl(url: String?, zimFileReader: ZimFileReader?) = - super.hasValidFileAndUrl(url, zimFileReader) && url != HOME_URL - - override fun getIconResId() = R.mipmap.ic_launcher - - override fun urlIsInvalid() = - super.urlIsInvalid() || getCurrentWebView().url == HOME_URL - - override fun showHomePage() { - getCurrentWebView().removeAllViews() - getCurrentWebView().loadUrl(HOME_URL) - } - - override fun createNewTab() { - newTab(HOME_URL) - } - - override fun isInvalidTitle(zimFileTitle: String?) = - super.isInvalidTitle(zimFileTitle) || HOME_URL == getCurrentWebView().url - - private fun uriFromIntent() = - activity?.intent?.data ?: activity?.intent?.getStringExtra(EXTRA_ZIM_FILE)?.let { - File(FileUtils.getFileName(it)).toUri() - } - - private fun restoreTabStates() { - val settings = requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0) - val zimFile = settings.getString(TAG_CURRENT_FILE, null) - val zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null) - val zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null) - - val currentTab = settings.getInt(TAG_CURRENT_TAB, 0) - - if (zimFile != null) { - openZimFile(File(zimFile)) - } else { - getCurrentWebView().snack(R.string.zim_not_opened) - } - try { - val urls = JSONArray(zimArticles) - val positions = JSONArray(zimPositions) - var i = 0 - getCurrentWebView().loadUrl(UpdateUtils.reformatProviderUrl(urls.getString(i))) - getCurrentWebView().scrollY = positions.getInt(i) - i++ - while (i < urls.length()) { - newTab(UpdateUtils.reformatProviderUrl(urls.getString(i))) - getCurrentWebView().scrollY = positions.getInt(i) - i++ - } - selectTab(currentTab) - } catch (e: Exception) { - Log.w(TAG_KIWIX, "Kiwix shared preferences corrupted", e) - // TODO: Show to user - } - } - - override fun manageZimFiles(tab: Int) { - activity?.start { putExtra(ZimManageActivity.TAB_EXTRA, tab) } - } - - override fun onNewIntent( - intent: Intent, - activity: AppCompatActivity - ): Super { - super.onNewIntent(activity.intent, activity) - intent.data?.let { - if ("file" == it.scheme) openZimFile(it.toFile()) - else activity.toast(R.string.cannot_open_file) - } - return ShouldCall - } - - override fun onHostBooksMenuClicked() { - activity?.start() - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixWebViewClient.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixWebViewClient.kt deleted file mode 100644 index f791e3837..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixWebViewClient.kt +++ /dev/null @@ -1,37 +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.main - -import android.webkit.WebView -import org.kiwix.kiwixmobile.core.main.CoreWebViewClient -import org.kiwix.kiwixmobile.core.main.WebViewCallback -import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer - -class KiwixWebViewClient internal constructor( - callback: WebViewCallback, - zimReaderContainer: ZimReaderContainer -) : CoreWebViewClient(callback, zimReaderContainer) { - - override fun onUrlEqualToHome(view: WebView) { - inflateHomeView(view) - } - - override fun onInvalidUrl(view: WebView) { - inflateHomeView(view) - } -} 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 1f424580f..5a68dab66 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 @@ -35,7 +35,7 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.local_file_transfer.LocalFileTransferActivity -import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity +import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestMultiSelection import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestNavigateTo @@ -90,7 +90,7 @@ class LocalLibraryFragment : ZimFileSelectFragment() { activity.setSupportActionBar(toolbar) activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true) activity.supportActionBar!!.setTitle(R.string.library) - (activity as KiwixNewNavigationActivity).setupDrawerToggle(toolbar) + (activity as KiwixMainActivity).setupDrawerToggle(toolbar) return root } 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 317c3563d..909ab55d1 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 @@ -35,7 +35,7 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start import org.kiwix.kiwixmobile.core.utils.SimpleTextListener import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.language.LanguageActivity -import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity +import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment class OnlineLibraryFragment : LibraryFragment(), BaseFragmentActivityExtensions { @@ -81,7 +81,7 @@ class OnlineLibraryFragment : LibraryFragment(), BaseFragmentActivityExtensions activity.setSupportActionBar(toolbar) activity.supportActionBar!!.setTitle(R.string.download) activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true) - (activity as KiwixNewNavigationActivity).setupDrawerToggle(toolbar) + (activity as KiwixMainActivity).setupDrawerToggle(toolbar) return root } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/ReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/ReaderFragment.kt index a4165b3b2..82d63cfc9 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/ReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/ReaderFragment.kt @@ -48,9 +48,8 @@ import org.kiwix.kiwixmobile.core.extensions.setImageDrawableCompat import org.kiwix.kiwixmobile.core.extensions.snack import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.main.CoreReaderFragment +import org.kiwix.kiwixmobile.core.main.CoreWebViewClient import org.kiwix.kiwixmobile.core.main.ToolbarScrollingKiwixWebView -import org.kiwix.kiwixmobile.core.main.WebViewCallback -import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_FILE @@ -59,12 +58,9 @@ import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_TAB import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX import org.kiwix.kiwixmobile.core.utils.UpdateUtils import org.kiwix.kiwixmobile.core.utils.files.FileUtils -import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity -import org.kiwix.kiwixmobile.main.KiwixWebViewClient +import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.navigate import org.kiwix.kiwixmobile.webserver.ZimHostActivity -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity import java.io.File private const val HIDE_TAB_SWITCHER_DELAY: Long = 300 @@ -73,7 +69,7 @@ class ReaderFragment : CoreReaderFragment() { private val args: ReaderFragmentArgs by navArgs() override fun inject(baseActivity: BaseActivity) { - baseActivity.kiwixActivityComponent.inject(this) + (baseActivity as KiwixMainActivity).cachedComponent.inject(this) } override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -87,19 +83,15 @@ class ReaderFragment : CoreReaderFragment() { } (activity as AppCompatActivity).supportActionBar!!.setDisplayHomeAsUpEnabled(true) - (activity as KiwixNewNavigationActivity).setupDrawerToggle(toolbar) + (activity as KiwixMainActivity).setupDrawerToggle(toolbar) setFragmentContainerBottomMarginToSizeOfNavBar() } override fun loadDrawerViews() { - drawerLayout = requireActivity().findViewById(R.id.container) + drawerLayout = requireActivity().findViewById(R.id.new_navigation_container) tableDrawerRightContainer = requireActivity().findViewById(R.id.reader_drawer_nav_view) } - override fun showHomePage() { - exitBook() - } - private fun exitBook() { showNoBookOpenViews() bottomToolbar.visibility = GONE @@ -184,7 +176,7 @@ class ReaderFragment : CoreReaderFragment() { override fun onResume() { super.onResume() if (zimReaderContainer.zimFile == null) { - showHomePage() + exitBook() } } @@ -198,15 +190,6 @@ class ReaderFragment : CoreReaderFragment() { return ShouldNotCall } - override fun createWebClient( - webViewCallback: WebViewCallback, - zimReaderContainer: ZimReaderContainer - ) = KiwixWebViewClient(webViewCallback, zimReaderContainer) - - override fun onNewNavigationMenuClicked() { - // do nothing - } - private fun manageExternalLaunchAndRestoringViewState(uri: String) { if (uri.isNotEmpty()) { @@ -239,7 +222,7 @@ class ReaderFragment : CoreReaderFragment() { // fits better normal android behavior if after closing app ("back" button) state is not maintained. } else { Log.d(TAG_KIWIX, "Kiwix normal start, no zimFile loaded last time -> display home page") - showHomePage() + exitBook() } } } @@ -247,7 +230,7 @@ class ReaderFragment : CoreReaderFragment() { override fun createWebView(attrs: AttributeSet): ToolbarScrollingKiwixWebView { return ToolbarScrollingKiwixWebView( activity, this, attrs, activityMainRoot as ViewGroup, videoView, - createWebClient(this, zimReaderContainer), + CoreWebViewClient(this, zimReaderContainer), toolbarContainer, bottomToolbar, requireActivity().bottom_nav_view, sharedPreferenceUtil ) @@ -294,10 +277,6 @@ class ReaderFragment : CoreReaderFragment() { } } - override fun manageZimFiles(tab: Int) { - activity?.start { putExtra(ZimManageActivity.TAB_EXTRA, tab) } - } - override fun onNewIntent( intent: Intent, activity: AppCompatActivity diff --git a/app/src/main/java/org/kiwix/kiwixmobile/splash/KiwixSplashActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/splash/KiwixSplashActivity.kt index f1d99fc68..a02e3578d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/splash/KiwixSplashActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/splash/KiwixSplashActivity.kt @@ -23,7 +23,7 @@ import org.kiwix.kiwixmobile.core.di.components.CoreComponent import org.kiwix.kiwixmobile.core.splash.CoreSplashActivity import org.kiwix.kiwixmobile.intro.IntroActivity import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.main.KiwixNewNavigationActivity +import org.kiwix.kiwixmobile.main.KiwixMainActivity class KiwixSplashActivity : CoreSplashActivity() { @@ -35,5 +35,5 @@ class KiwixSplashActivity : CoreSplashActivity() { get() = if (sharedPreferenceUtil.showIntro()) Intent(this, IntroActivity::class.java) else - Intent(this, KiwixNewNavigationActivity::class.java) + Intent(this, KiwixMainActivity::class.java) } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt deleted file mode 100644 index 040a241b5..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt +++ /dev/null @@ -1,49 +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.zim_manager - -import android.content.Context -import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentPagerAdapter -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.base.BaseFragment -import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment -import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment -import kotlin.reflect.KFunction0 - -class SectionsPagerAdapter( - private val context: Context, - private val pagerData: Array = - arrayOf( - PagerData(::ZimFileSelectFragment, R.string.local_zims), - PagerData(::LibraryFragment, R.string.remote_zims) - ), - fm: FragmentManager -) : FragmentPagerAdapter(fm) { - - override fun getItem(position: Int) = pagerData[position].fragmentConstructor.invoke() - - override fun getCount() = pagerData.size - - override fun getPageTitle(position: Int): String = context.getString(pagerData[position].title) -} - -data class PagerData( - val fragmentConstructor: KFunction0, - val title: Int -) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt deleted file mode 100644 index c564d587b..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt +++ /dev/null @@ -1,135 +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.zim_manager - -import android.content.Intent -import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import androidx.appcompat.widget.SearchView -import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.ViewModelProvider -import kotlinx.android.synthetic.main.zim_manager.manageViewPager -import kotlinx.android.synthetic.main.zim_manager.tabs -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.base.BaseActivity -import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao -import org.kiwix.kiwixmobile.core.di.components.CoreComponent -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel -import org.kiwix.kiwixmobile.core.utils.LanguageUtils -import org.kiwix.kiwixmobile.core.utils.SimpleTextListener -import org.kiwix.kiwixmobile.kiwixActivityComponent -import org.kiwix.kiwixmobile.language.LanguageActivity -import org.kiwix.kiwixmobile.local_file_transfer.LocalFileTransferActivity -import javax.inject.Inject - -class ZimManageActivity : BaseActivity() { - override fun injection(coreComponent: CoreComponent) { - cachedComponent.inject(this) - } - - val cachedComponent by lazy { kiwixActivityComponent } - - private val zimManageViewModel by lazy { viewModel(viewModelFactory) } - private val sectionsPagerAdapter: SectionsPagerAdapter by lazy { - SectionsPagerAdapter(this, fm = supportFragmentManager) - } - - private var searchItem: MenuItem? = null - private var languageItem: MenuItem? = null - private var getZimItem: MenuItem? = null - - @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject lateinit var languagesDao: NewLanguagesDao - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil) - setContentView(R.layout.zim_manager) - - setUpToolbar() - manageViewPager.run { - adapter = sectionsPagerAdapter - offscreenPageLimit = sectionsPagerAdapter.count - 1 - tabs.setupWithViewPager(this) - addOnPageChangeListener(SimplePageChangeListener(::updateMenu)) - addOnPageChangeListener(SimplePageChangeListener(::updatePage)) - } - setViewPagerPositionFromIntent(intent) - } - - private fun updatePage(position: Int) { - zimManageViewModel.currentPage.offer(position) - } - - override fun onNewIntent(intent: Intent?) { - super.onNewIntent(intent) - setViewPagerPositionFromIntent(intent) - } - - private fun setViewPagerPositionFromIntent(intent: Intent?) { - if (intent?.hasExtra(TAB_EXTRA) == true) { - manageViewPager.currentItem = intent.getIntExtra(TAB_EXTRA, 0) - } - } - - private fun updateMenu(position: Int) { - searchItem?.isVisible = position == 1 - languageItem?.isVisible = position == 1 - getZimItem?.isVisible = position == 0 - } - - private fun setUpToolbar() { - val toolbar = findViewById(R.id.toolbar) - setSupportActionBar(toolbar) - supportActionBar!!.setHomeButtonEnabled(true) - supportActionBar!!.setDisplayHomeAsUpEnabled(true) - supportActionBar!!.setTitle(R.string.library) - toolbar.setNavigationOnClickListener { onBackPressed() } - toolbar.setOnClickListener { - if (manageViewPager.currentItem == 1) - searchItem?.expandActionView() - } - } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_zim_manager, menu) - searchItem = menu.findItem(R.id.action_search) - languageItem = menu.findItem(R.id.select_language) - getZimItem = menu.findItem(R.id.get_zim_nearby_device) - updateMenu(manageViewPager.currentItem) - (searchItem?.actionView as? SearchView)?.setOnQueryTextListener( - SimpleTextListener(zimManageViewModel.requestFiltering::onNext) - ) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.select_language -> start() - R.id.get_zim_nearby_device -> start() - } - return super.onOptionsItemSelected(item) - } - - companion object { - const val TAB_EXTRA = "TAB" - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/ZimFileSelectFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/ZimFileSelectFragment.kt index 841556b89..99c8ae69f 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/ZimFileSelectFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/ZimFileSelectFragment.kt @@ -1,6 +1,6 @@ /* * Kiwix Android - * Copyright (c) 2019 Kiwix + * Copyright (c) 2020 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 @@ -47,7 +47,7 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDisk import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate.LanguageDelegate import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity +import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel.FileSelectActions.RequestMultiSelection @@ -81,7 +81,7 @@ open class ZimFileSelectFragment : BaseFragment() { } override fun inject(baseActivity: BaseActivity) { - (baseActivity as ZimManageActivity).cachedComponent.inject(this) + baseActivity.kiwixActivityComponent.inject(this) } override fun onCreateView( diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt index ccb3442f1..91f9114ac 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt @@ -48,10 +48,10 @@ import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.WifiOnly import org.kiwix.kiwixmobile.core.utils.NetworkUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.zim_manager.NetworkState import org.kiwix.kiwixmobile.zim_manager.NetworkState.CONNECTED import org.kiwix.kiwixmobile.zim_manager.NetworkState.NOT_CONNECTED -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryAdapter import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryDelegate.BookDelegate @@ -91,7 +91,7 @@ open class LibraryFragment : BaseFragment() { private val isNotConnected get() = conMan.activeNetworkInfo?.isConnected == false override fun inject(baseActivity: BaseActivity) { - (baseActivity as ZimManageActivity).cachedComponent.inject(this) + baseActivity.kiwixActivityComponent.inject(this) } override fun onCreateView( diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index 67d37b8d4..423c1ee49 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -11,6 +11,8 @@ android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@id/get_started" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />