mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 02:48:08 -04:00
#2227 merge with feature/navigation
This commit is contained in:
commit
8aba2fa5e5
@ -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);
|
||||
|
@ -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<ZimManageActivity> 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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,103 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// /*
|
||||
// * Kiwix Android
|
||||
// * Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
// * 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 <http://www.gnu.org/licenses/>.
|
||||
// *
|
||||
// */
|
||||
//
|
||||
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<ZimManageActivity>() {
|
||||
|
||||
override var activityRule = activityTestRule<ZimManageActivity> {
|
||||
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<ZimManageActivity>() {
|
||||
//
|
||||
// override var activityRule = activityTestRule<ZimManageActivity> {
|
||||
// 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("/")}"
|
||||
// }
|
||||
|
@ -1,106 +1,106 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
// /*
|
||||
// * Kiwix Android
|
||||
// * Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
// * 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 <http://www.gnu.org/licenses/>.
|
||||
// *
|
||||
// */
|
||||
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))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
@ -33,14 +33,6 @@
|
||||
<activity android:name=".intro.IntroActivity" />
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".main.KiwixNewNavigationActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".main.KiwixMainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
@ -54,6 +46,7 @@
|
||||
|
||||
<data android:scheme="content" />
|
||||
<data android:mimeType="application/octet-stream" />
|
||||
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
@ -150,17 +143,6 @@
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".zim_manager.ZimManageActivity"
|
||||
android:label="@string/choose_file"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.TEXT_CLICKED" />
|
||||
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.ICON_CLICKED" />
|
||||
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.MIC_CLICKED" />
|
||||
<action android:name="org.kiwix.kiwixmobile.utils.KiwixSearchWidget.STAR_CLICKED" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".language.LanguageActivity" />
|
||||
<activity
|
||||
android:name=".local_file_transfer.LocalFileTransferActivity"
|
||||
@ -183,6 +165,10 @@
|
||||
<service android:name=".webserver.wifi_hotspot.HotspotService" />
|
||||
|
||||
<receiver android:name=".main.KiwixSearchWidget">
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/kiwix_widget_provider_info" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="KiwixSearchWidget.TEXT_CLICKED" />
|
||||
@ -190,10 +176,6 @@
|
||||
<action android:name="KiwixSearchWidget.MIC_CLICKED" />
|
||||
<action android:name="KiwixSearchWidget.STAR_CLICKED" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/kiwix_widget_provider_info" />
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>REPLACE_menu_home</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="display:none;">REPLACE_menu_home</h1>
|
||||
</body>
|
||||
</html>
|
@ -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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* 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<BaseFragmentActivityExtensions>().forEach {
|
||||
if (it.onBackPressed(this) == BaseFragmentActivityExtensions.Super.ShouldCall) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
supportFragmentManager.fragments.filterIsInstance<BaseFragmentActivityExtensions>().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<HelpActivity>()
|
||||
R.id.menu_host_books -> start<ZimHostActivity>()
|
||||
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<HistoryActivity>(),
|
||||
REQUEST_HISTORY_ITEM_CHOSEN
|
||||
)
|
||||
}
|
||||
|
||||
private fun openBookmarksActivity() {
|
||||
startActivity(
|
||||
intent<BookmarksActivity>()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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<BaseFragmentActivityExtensions>().forEach {
|
||||
if (it.onBackPressed(this) == BaseFragmentActivityExtensions.Super.ShouldCall) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
supportFragmentManager.fragments.filterIsInstance<BaseFragmentActivityExtensions>().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<HelpActivity>()
|
||||
R.id.menu_host_books -> start<ZimHostActivity>()
|
||||
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<HistoryActivity>(),
|
||||
REQUEST_HISTORY_ITEM_CHOSEN
|
||||
)
|
||||
}
|
||||
|
||||
private fun openBookmarksActivity() {
|
||||
startActivity(
|
||||
intent<BookmarksActivity>()
|
||||
)
|
||||
}
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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<ZimManageActivity> { 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<ZimHostActivity>()
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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)
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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<ZimManageActivity> { putExtra(ZimManageActivity.TAB_EXTRA, tab) }
|
||||
}
|
||||
|
||||
override fun onNewIntent(
|
||||
intent: Intent,
|
||||
activity: AppCompatActivity
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<PagerData> =
|
||||
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<BaseFragment>,
|
||||
val title: Int
|
||||
)
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<ZimManageViewModel>(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<Toolbar>(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<LanguageActivity>()
|
||||
R.id.get_zim_nearby_device -> start<LocalFileTransferActivity>()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAB_EXTRA = "TAB"
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* 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(
|
||||
|
@ -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(
|
||||
|
@ -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" />
|
||||
|
||||
<Button
|
||||
|
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Kiwix Android
|
||||
~ Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
~ 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 <http://www.gnu.org/licenses/>.
|
||||
~
|
||||
-->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/kiwix_fragment_containter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -19,7 +19,7 @@
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:id="@+id/new_navigation_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/zim_manager_main_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.kiwix.kiwixmobile.zim_manager.ZimManageActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<include layout="@layout/layout_toolbar" />
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:tabGravity="fill"
|
||||
app:tabMaxWidth="0dp" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/manageViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -25,11 +25,10 @@ import dagger.Provides
|
||||
import org.kiwix.kiwixmobile.core.data.DataSource
|
||||
import org.kiwix.kiwixmobile.core.di.ActivityScope
|
||||
import org.kiwix.kiwixmobile.core.main.KiwixWebView
|
||||
import org.kiwix.kiwixmobile.core.main.MainContract
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu.Factory
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu.MenuClickListener
|
||||
import org.kiwix.kiwixmobile.core.main.MainPresenter
|
||||
import org.kiwix.kiwixmobile.core.main.MainRepositoryActions
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
@ -45,8 +44,8 @@ abstract class ActivityModule {
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@ActivityScope
|
||||
fun providesMainPresenter(dataSource: DataSource): MainContract.Presenter =
|
||||
MainPresenter(dataSource)
|
||||
fun providesMainPresenter(dataSource: DataSource): MainRepositoryActions =
|
||||
MainRepositoryActions(dataSource)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
|
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
|
@ -57,7 +57,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
@ -120,9 +119,6 @@ import org.kiwix.kiwixmobile.core.utils.NetworkUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
|
||||
import org.kiwix.kiwixmobile.core.utils.StyleUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils;
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate;
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter;
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem;
|
||||
|
||||
import static android.app.Activity.RESULT_CANCELED;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
@ -152,12 +148,10 @@ import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_CURRENT_POSITIONS
|
||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_CURRENT_TAB;
|
||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_FILE_SEARCHED;
|
||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_KIWIX;
|
||||
import static org.kiwix.kiwixmobile.core.utils.LanguageUtils.getResourceString;
|
||||
import static org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.PREF_KIWIX_MOBILE;
|
||||
|
||||
public abstract class CoreReaderFragment extends BaseFragment
|
||||
implements WebViewCallback,
|
||||
MainContract.View,
|
||||
MainMenu.MenuClickListener, BaseFragmentActivityExtensions, WebViewProvider {
|
||||
protected final List<KiwixWebView> webViewList = new ArrayList<>();
|
||||
private final BehaviorProcessor<String> webUrlsProcessor = BehaviorProcessor.create();
|
||||
@ -209,8 +203,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
@BindView(R2.id.activity_main_root)
|
||||
protected View activityMainRoot;
|
||||
|
||||
@Inject
|
||||
protected MainContract.Presenter presenter;
|
||||
@Inject
|
||||
StorageObserver storageObserver;
|
||||
@Inject
|
||||
@ -229,6 +221,8 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
protected DialogShower alertDialogShower;
|
||||
@Inject
|
||||
protected NightModeViewPainter painter;
|
||||
@Inject
|
||||
MainRepositoryActions repositoryActions;
|
||||
|
||||
private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) {
|
||||
@Override
|
||||
@ -257,12 +251,9 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
private RateAppCounter visitCounterPref;
|
||||
private int tempVisitCount;
|
||||
private boolean isFirstRun;
|
||||
private BooksOnDiskAdapter booksAdapter;
|
||||
private AppCompatButton downloadBookButton;
|
||||
protected ActionBar actionBar;
|
||||
private TableDrawerAdapter tableDrawerAdapter;
|
||||
private RecyclerView tableDrawerRight;
|
||||
private boolean hasLocalBooks;
|
||||
protected MainMenu mainMenu;
|
||||
private ItemTouchHelper.Callback tabCallback = new ItemTouchHelper.Callback() {
|
||||
@Override
|
||||
@ -334,7 +325,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
presenter.attachView(this);
|
||||
new WebView(activity).destroy(); // Workaround for buggy webViews see #710
|
||||
handleLocaleCheck();
|
||||
activity.setSupportActionBar(toolbar);
|
||||
@ -393,25 +383,13 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
compatCallback = new CompatFindActionModeCallback(activity);
|
||||
setUpTTS();
|
||||
|
||||
setupDocumentParser(activity);
|
||||
setupDocumentParser();
|
||||
|
||||
loadPrefs();
|
||||
updateTitle();
|
||||
|
||||
handleIntentExtras(getActivity().getIntent());
|
||||
|
||||
booksAdapter = new BooksOnDiskAdapter(
|
||||
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
||||
bookOnDiskItem -> {
|
||||
open(bookOnDiskItem);
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
null,
|
||||
null),
|
||||
BookOnDiskDelegate.LanguageDelegate.INSTANCE
|
||||
);
|
||||
|
||||
searchFiles();
|
||||
tabRecyclerView.setAdapter(tabsAdapter);
|
||||
new ItemTouchHelper(tabCallback).attachToRecyclerView(tabRecyclerView);
|
||||
|
||||
@ -469,24 +447,14 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDocumentParser(AppCompatActivity activity) {
|
||||
private void setupDocumentParser() {
|
||||
documentParser = new DocumentParser(new DocumentParser.SectionsListener() {
|
||||
@Override
|
||||
public void sectionsLoaded(String title, List<TableDrawerAdapter.DocumentSection> sections) {
|
||||
if (isAdded()) {
|
||||
for (TableDrawerAdapter.DocumentSection section : sections) {
|
||||
if (section.title.contains("REPLACE_")) {
|
||||
section.title =
|
||||
getResourceString(activity.getBaseContext(), section.title);
|
||||
}
|
||||
}
|
||||
documentSections.addAll(sections);
|
||||
if (title.contains("REPLACE_")) {
|
||||
tableDrawerAdapter.setTitle(
|
||||
getResourceString(activity.getBaseContext(), title));
|
||||
} else {
|
||||
tableDrawerAdapter.setTitle(title);
|
||||
}
|
||||
tableDrawerAdapter.setTitle(title);
|
||||
|
||||
tableDrawerAdapter.setSections(documentSections);
|
||||
tableDrawerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
@ -600,12 +568,12 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
tabSwitcherRoot.setVisibility(View.GONE);
|
||||
startAnimation(tabSwitcherRoot, R.anim.slide_up);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
progressBar.hide();
|
||||
contentFrame.setVisibility(View.VISIBLE);
|
||||
}
|
||||
progressBar.hide();
|
||||
selectTab(currentWebViewIndex);
|
||||
if (mainMenu != null) {
|
||||
mainMenu.showWebViewOptions(!urlIsInvalid());
|
||||
mainMenu.showWebViewOptions(urlIsValid());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -806,13 +774,8 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
@Override public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
safeDispose();
|
||||
presenter.detachView();
|
||||
if (downloadBookButton != null) {
|
||||
downloadBookButton.setOnClickListener(null);
|
||||
}
|
||||
super.onDestroy();
|
||||
tabCallback = null;
|
||||
downloadBookButton = null;
|
||||
hideBackToTopTimer.cancel();
|
||||
hideBackToTopTimer = null;
|
||||
// TODO create a base Activity class that class this.
|
||||
@ -844,15 +807,11 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
@NotNull protected ToolbarScrollingKiwixWebView createWebView(AttributeSet attrs) {
|
||||
return new ToolbarScrollingKiwixWebView(
|
||||
getActivity(), this, attrs, (ViewGroup) activityMainRoot, videoView,
|
||||
createWebClient(this, zimReaderContainer),
|
||||
new CoreWebViewClient(this, zimReaderContainer),
|
||||
toolbarContainer, bottomToolbar,
|
||||
sharedPreferenceUtil);
|
||||
}
|
||||
|
||||
protected abstract CoreWebViewClient createWebClient(
|
||||
WebViewCallback webViewCallback,
|
||||
ZimReaderContainer zimReaderContainer);
|
||||
|
||||
protected KiwixWebView newMainPageTab() {
|
||||
return newTab(contentUrl(zimReaderContainer.getMainPage()));
|
||||
}
|
||||
@ -985,10 +944,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onLibraryMenuClicked() {
|
||||
manageZimFiles(hasLocalBooks ? 0 : 1);
|
||||
}
|
||||
|
||||
@Override public void onRandomArticleMenuClicked() {
|
||||
openRandomArticle();
|
||||
}
|
||||
@ -1149,7 +1104,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
} else {
|
||||
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
||||
ContextExtensionsKt.toast(getActivity(), R.string.error_file_not_found, Toast.LENGTH_LONG);
|
||||
showHomePage();
|
||||
}
|
||||
} else {
|
||||
this.file = file;
|
||||
@ -1181,7 +1135,7 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
final ZimFileReader zimFileReader = zimReaderContainer.getZimFileReader();
|
||||
if (zimFileReader != null) {
|
||||
if (mainMenu != null) {
|
||||
mainMenu.onFileOpened(zimFileReader, !urlIsInvalid());
|
||||
mainMenu.onFileOpened(zimFileReader, urlIsValid());
|
||||
}
|
||||
openMainPage();
|
||||
safeDispose();
|
||||
@ -1200,7 +1154,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
updateUrlProcessor();
|
||||
} else {
|
||||
ContextExtensionsKt.toast(getActivity(), R.string.error_file_invalid, Toast.LENGTH_LONG);
|
||||
showHomePage();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1223,7 +1176,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
if (file != null) {
|
||||
openZimFile(file);
|
||||
}
|
||||
scanStorageForZims();
|
||||
} else {
|
||||
Snackbar.make(snackbarRoot, R.string.request_storage, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.menu_settings, view -> {
|
||||
@ -1253,16 +1205,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void scanStorageForZims() {
|
||||
storageObserver.getBooksOnFileSystem()
|
||||
.take(1)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(books -> {
|
||||
presenter.saveBooks(books);
|
||||
hasLocalBooks = !books.isEmpty();
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
@OnClick(R2.id.tab_switcher_close_all_tabs)
|
||||
void closeAllTabs() {
|
||||
rotate(closeAllTabsButton);
|
||||
@ -1296,12 +1238,12 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
String articleUrl = getCurrentWebView().getUrl();
|
||||
if (articleUrl != null) {
|
||||
if (isBookmarked) {
|
||||
presenter.deleteBookmark(articleUrl);
|
||||
repositoryActions.deleteBookmark(articleUrl);
|
||||
ViewExtensionsKt.snack(snackbarRoot, R.string.bookmark_removed);
|
||||
} else {
|
||||
final ZimFileReader zimFileReader = zimReaderContainer.getZimFileReader();
|
||||
if (zimFileReader != null) {
|
||||
presenter.saveBookmark(
|
||||
repositoryActions.saveBookmark(
|
||||
new BookmarkItem(getCurrentWebView().getTitle(), articleUrl, zimFileReader)
|
||||
);
|
||||
ViewExtensionsKt.snack(
|
||||
@ -1327,7 +1269,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
super.onResume();
|
||||
|
||||
updateBottomToolbarVisibility();
|
||||
presenter.loadBooks();
|
||||
updateNightMode();
|
||||
}
|
||||
|
||||
@ -1339,7 +1280,7 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
|
||||
private void updateBottomToolbarVisibility() {
|
||||
if (checkNull(bottomToolbar)) {
|
||||
if (!urlIsInvalid()
|
||||
if (urlIsValid()
|
||||
&& tabSwitcherRoot.getVisibility() != View.VISIBLE) {
|
||||
bottomToolbar.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
@ -1362,10 +1303,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
if (intent.getAction() != null) {
|
||||
if (zimReaderContainer.getId() != null) {
|
||||
startIntentBasedOnAction(intent);
|
||||
} else {
|
||||
if (CoreSearchWidget.MIC_CLICKED.equals(intent.getAction())) {
|
||||
manageZimFiles(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1578,11 +1515,11 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
}
|
||||
|
||||
@NotNull protected MainMenu createMainMenu(Menu menu) {
|
||||
return menuFactory.create(menu, webViewList, !urlIsInvalid(), this, false, false);
|
||||
return menuFactory.create(menu, webViewList, urlIsValid(), this, false, false);
|
||||
}
|
||||
|
||||
protected boolean urlIsInvalid() {
|
||||
return getCurrentWebView().getUrl() == null;
|
||||
protected boolean urlIsValid() {
|
||||
return getCurrentWebView().getUrl() != null;
|
||||
}
|
||||
|
||||
private void updateUrlProcessor() {
|
||||
@ -1674,7 +1611,7 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
timeStamp,
|
||||
zimFileReader
|
||||
);
|
||||
presenter.saveHistory(history);
|
||||
repositoryActions.saveHistory(history);
|
||||
}
|
||||
updateBottomToolbarVisibility();
|
||||
openFullScreenIfEnabled();
|
||||
@ -1764,34 +1701,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomePage(View view) {
|
||||
painter.deactivateNightMode(getCurrentWebView(), videoView);
|
||||
RecyclerView homeRecyclerView = view.findViewById(R.id.recycler_view);
|
||||
presenter.loadBooks();
|
||||
homeRecyclerView.setAdapter(booksAdapter);
|
||||
downloadBookButton = view.findViewById(R.id.content_main_card_download_button);
|
||||
downloadBookButton.setOnClickListener(v -> manageZimFiles(1));
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
private void open(BooksOnDiskListItem.BookOnDisk bookOnDisk) {
|
||||
openZimFile(bookOnDisk.getFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBooks(List<BooksOnDiskListItem> books) {
|
||||
booksAdapter.setItems(books);
|
||||
}
|
||||
|
||||
private void searchFiles() {
|
||||
if (hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
scanStorageForZims();
|
||||
} else {
|
||||
requestExternalStoragePermission();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkNull(View view) {
|
||||
return view != null;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ package org.kiwix.kiwixmobile.core.main;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
@ -30,7 +28,6 @@ import android.webkit.WebViewClient;
|
||||
import androidx.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import org.kiwix.kiwixmobile.core.CoreApp;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
|
||||
|
||||
import static org.kiwix.kiwixmobile.core.reader.ZimFileReader.CONTENT_PREFIX;
|
||||
@ -38,14 +35,13 @@ import static org.kiwix.kiwixmobile.core.reader.ZimFileReader.UI_URI;
|
||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.EXTRA_EXTERNAL_LINK;
|
||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_KIWIX;
|
||||
|
||||
public abstract class CoreWebViewClient extends WebViewClient {
|
||||
public class CoreWebViewClient extends WebViewClient {
|
||||
private static final HashMap<String, String> DOCUMENT_TYPES = new HashMap<String, String>() {{
|
||||
put("epub", "application/epub+zip");
|
||||
put("pdf", "application/pdf");
|
||||
}};
|
||||
protected final WebViewCallback callback;
|
||||
protected final ZimReaderContainer zimReaderContainer;
|
||||
private View home;
|
||||
private static String LEGACY_CONTENT_PREFIX =
|
||||
Uri.parse("content://" + CoreApp.getInstance().getPackageName() + ".zim.base/").toString();
|
||||
private String urlWithAnchor;
|
||||
@ -119,15 +115,14 @@ public abstract class CoreWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
boolean invalidUrl =
|
||||
url.equals("content://" + CoreApp.getInstance().getPackageName() + ".zim.base/null");
|
||||
url.equals(CONTENT_PREFIX + "null");
|
||||
|
||||
Log.d(TAG_KIWIX, "invalidUrl = " + invalidUrl);
|
||||
|
||||
if (invalidUrl) {
|
||||
onInvalidUrl(view);
|
||||
return;
|
||||
}
|
||||
|
||||
view.removeView(home);
|
||||
jumpToAnchor(view, url);
|
||||
callback.webViewUrlFinishedLoading();
|
||||
}
|
||||
@ -143,18 +138,6 @@ public abstract class CoreWebViewClient extends WebViewClient {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onInvalidUrl(WebView view);
|
||||
|
||||
protected abstract void onUrlEqualToHome(WebView view);
|
||||
|
||||
protected void inflateHomeView(WebView view) {
|
||||
LayoutInflater inflater = LayoutInflater.from(view.getContext());
|
||||
home = inflater.inflate(R.layout.content_main, view, false);
|
||||
callback.setHomePage(home);
|
||||
view.removeAllViews();
|
||||
view.addView(home);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
|
@ -21,7 +21,6 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioManager.OnAudioFocusChangeListener;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import java.util.List;
|
||||
import org.kiwix.kiwixmobile.core.base.BaseContract;
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem;
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem;
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem;
|
||||
|
||||
/**
|
||||
* The contract between {@link CoreMainActivity} and {@link MainPresenter}.
|
||||
*/
|
||||
|
||||
public class MainContract {
|
||||
|
||||
interface View extends BaseContract.View<Presenter> {
|
||||
void addBooks(List<BooksOnDiskListItem> books);
|
||||
}
|
||||
|
||||
public interface Presenter extends BaseContract.Presenter<View> {
|
||||
void loadBooks();
|
||||
|
||||
void saveBooks(List<BooksOnDiskListItem.BookOnDisk> books);
|
||||
|
||||
void saveHistory(HistoryListItem.HistoryItem history);
|
||||
|
||||
void saveBookmark(BookmarkItem bookmark);
|
||||
|
||||
void deleteBookmark(String bookmarkUrl);
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ import android.view.MenuItem
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.R2.id.menu_add_note
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.intent
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
import org.kiwix.kiwixmobile.core.search.SearchActivity
|
||||
@ -60,12 +61,10 @@ class MainMenu(
|
||||
fun onAddNoteMenuClicked()
|
||||
fun onBookmarksMenuClicked()
|
||||
fun onRandomArticleMenuClicked()
|
||||
fun onLibraryMenuClicked()
|
||||
fun onReadAloudMenuClicked()
|
||||
fun onFullscreenMenuClicked()
|
||||
fun onSupportKiwixMenuClicked()
|
||||
fun onHostBooksMenuClicked()
|
||||
fun onNewNavigationMenuClicked()
|
||||
}
|
||||
|
||||
init {
|
||||
|
@ -18,44 +18,28 @@
|
||||
package org.kiwix.kiwixmobile.core.main
|
||||
|
||||
import android.util.Log
|
||||
import org.kiwix.kiwixmobile.core.base.BasePresenter
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.data.DataSource
|
||||
import org.kiwix.kiwixmobile.core.di.ActivityScope
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
import org.kiwix.kiwixmobile.core.main.MainContract.Presenter
|
||||
import org.kiwix.kiwixmobile.core.main.MainContract.View
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val TAG = "MainPresenter"
|
||||
|
||||
@ActivityScope
|
||||
internal class MainPresenter @Inject constructor(private val dataSource: DataSource) :
|
||||
BasePresenter<View?>(), Presenter {
|
||||
override fun loadBooks() {
|
||||
compositeDisposable.add(
|
||||
dataSource.languageCategorizedBooks.subscribe(
|
||||
{ view?.addBooks(it) }
|
||||
) { e -> Log.e(TAG, "Unable to load books", e) })
|
||||
}
|
||||
class MainRepositoryActions @Inject constructor(private val dataSource: DataSource) {
|
||||
|
||||
override fun saveBooks(book: List<BookOnDisk>) {
|
||||
dataSource.saveBooks(book)
|
||||
.subscribe(::loadBooks) { e -> Log.e(TAG, "Unable to save books", e) }
|
||||
}
|
||||
|
||||
override fun saveHistory(history: HistoryItem) {
|
||||
fun saveHistory(history: HistoryItem) {
|
||||
dataSource.saveHistory(history)
|
||||
.subscribe({}, { e -> Log.e(TAG, "Unable to save history", e) })
|
||||
}
|
||||
|
||||
override fun saveBookmark(bookmark: BookmarkItem) {
|
||||
fun saveBookmark(bookmark: BookmarkItem) {
|
||||
dataSource.saveBookmark(bookmark)
|
||||
.subscribe({}, { e -> Log.e(TAG, "Unable to save bookmark", e) })
|
||||
}
|
||||
|
||||
override fun deleteBookmark(bookmarkUrl: String) {
|
||||
fun deleteBookmark(bookmarkUrl: String) {
|
||||
dataSource.deleteBookmark(bookmarkUrl)
|
||||
.subscribe({}, { e -> Log.e(TAG, "Unable to delete bookmark", e) })
|
||||
}
|
@ -40,7 +40,6 @@ import static org.kiwix.kiwixmobile.core.utils.DimenUtils.getToolbarHeight;
|
||||
import static org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowHeight;
|
||||
import static org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowWidth;
|
||||
import static org.kiwix.kiwixmobile.core.utils.ImageUtils.getBitmapFromView;
|
||||
import static org.kiwix.kiwixmobile.core.utils.LanguageUtils.getResourceString;
|
||||
import static org.kiwix.kiwixmobile.core.utils.StyleUtils.fromHtml;
|
||||
|
||||
public class TabsAdapter extends RecyclerView.Adapter<TabsAdapter.ViewHolder> {
|
||||
@ -134,12 +133,6 @@ public class TabsAdapter extends RecyclerView.Adapter<TabsAdapter.ViewHolder> {
|
||||
((ViewGroup) webView.getParent()).removeView(webView);
|
||||
}
|
||||
String webViewTitle = fromHtml(webView.getTitle()).toString();
|
||||
if (webViewTitle.contains("REPLACE_")) {
|
||||
webViewTitle =
|
||||
getResourceString(holder.title.getContext().getApplicationContext(), webViewTitle);
|
||||
} else if (webViewTitle.contains("content://org.kiwix")) {
|
||||
webViewTitle = activity.getString(R.string.menu_home);
|
||||
}
|
||||
holder.title.setText(webViewTitle);
|
||||
holder.close.setOnClickListener(v -> listener.onCloseTab(v, holder.getAdapterPosition()));
|
||||
holder.content.setImageBitmap(
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
||||
public interface WebViewCallback {
|
||||
void webViewUrlLoading();
|
||||
@ -27,12 +26,8 @@ public interface WebViewCallback {
|
||||
|
||||
void webViewFailedLoading(String failingUrl);
|
||||
|
||||
void showHomePage();
|
||||
|
||||
void openExternalUrl(Intent intent);
|
||||
|
||||
void manageZimFiles(int tab);
|
||||
|
||||
void webViewProgressChanged(int progress);
|
||||
|
||||
void webViewTitleUpdated(String title);
|
||||
@ -40,6 +35,4 @@ public interface WebViewCallback {
|
||||
void webViewPageChanged(int page, int maxPages);
|
||||
|
||||
void webViewLongClick(String url);
|
||||
|
||||
void setHomePage(View view);
|
||||
}
|
||||
|
@ -223,16 +223,5 @@ class LanguageUtils(private val context: Context) {
|
||||
@JvmStatic
|
||||
fun getTypeface(languageCode: String) =
|
||||
fontExceptions[languageCode] ?: "fonts/DejaVuSansCondensed.ttf"
|
||||
|
||||
@JvmStatic
|
||||
fun getResourceString(appContext: Context, str: String): String {
|
||||
var resourceName = str
|
||||
if (resourceName.contains("REPLACE_")) {
|
||||
resourceName = resourceName.replace("REPLACE_", "")
|
||||
}
|
||||
val resourceId = appContext.resources
|
||||
.getIdentifier(resourceName, "string", appContext.packageName)
|
||||
return appContext.resources.getString(resourceId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?colorSurface"
|
||||
tools:ignore="Overdraw">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/content_main_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardCornerRadius="4dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="144dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_home_kiwix_banner"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- constraintRight_toRightOf is used as android:layoutDirection is supported from API 17 -->
|
||||
<Button
|
||||
android:id="@+id/content_main_card_download_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/activity_horizontal_margin"
|
||||
android:text="@string/download_books"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/home_list_margin"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/content_main_card"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/content_main_card" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
@ -84,6 +84,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginBottom="?attr/actionBarSize"
|
||||
android:visibility="gone"
|
||||
app:fabSize="mini"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -45,5 +45,5 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="never"
|
||||
tools:visible="true" />
|
||||
|
||||
|
||||
</menu>
|
||||
|
@ -265,4 +265,4 @@
|
||||
<string name="off">تعطيل</string>
|
||||
<string name="auto">تلقائي</string>
|
||||
<string name="crash_checkbox_file_system">تفاصيل نظام الملفات</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -273,4 +273,4 @@
|
||||
<string name="diagnostic_report_message">Zašlete prosím všechny následující podrobnosti, abychom mohli problém diagnostikovat</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Zvětšit text</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -272,4 +272,4 @@
|
||||
<string name="diagnostic_report_message">Bitte übermittle alle nachfolgend aufgeführte Details, damit wir das Problem feststellen können</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Text Zoom</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -214,4 +214,4 @@
|
||||
<string name="crash_checkbox_file_system">Datos del sistema operativo</string>
|
||||
<string name="diagnostic_report">Informe de diagnóstico</string>
|
||||
<string name="diagnostic_report_message">Envíe todos los detalles siguientes para que podamos diagnosticar el problema.</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -281,4 +281,4 @@
|
||||
<string name="diagnostic_report_message">Veuillez envoyer tous les détails suivants afin que nous puissions diagnostiquer le problème</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Zoomer le texte</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -103,4 +103,4 @@
|
||||
<string name="no_bookmarks">Nessun segnalibro</string>
|
||||
<string name="delete_history">Cancellare tutta la cronologia?</string>
|
||||
<string name="delete_bookmarks">Cancellare tutti i segnalibri?</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -270,4 +270,4 @@
|
||||
<string name="crash_checkbox_file_system">פרטי מערכת קבצים</string>
|
||||
<string name="diagnostic_report">דוח אבחון</string>
|
||||
<string name="diagnostic_report_message">נא לשלוח את כל הפרטים הבאים כדי שנוכל לאבחן את התקלה</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -119,4 +119,4 @@
|
||||
<string name="on">Un</string>
|
||||
<string name="off">Aus</string>
|
||||
<string name="auto">Automatesch</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -268,4 +268,4 @@
|
||||
<string name="diagnostic_report_message">Испратете ги сите следни поединости за да можеме да го дијагностицираме проблемот</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Приближување на текст</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -106,4 +106,4 @@
|
||||
<string name="delete_selected_history">रोजिएको इतिहास मेटाउने?</string>
|
||||
<string name="delete_bookmarks">सबै बुकमार्कहरू मेटाउने?</string>
|
||||
<string name="delete_selected_bookmarks">रोजिएका बुकमार्कहरू मेटाउने?</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -274,4 +274,4 @@
|
||||
<string name="diagnostic_report_message">Envie todos os detalhes a seguir para que possamos diagnosticar o problema</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Zoom de texto</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -54,7 +54,7 @@
|
||||
<string name="open_library">The action of opening the library destination, used on a button.</string>
|
||||
<string name="download">The title of the fragment/place where books are downloaded.</string>
|
||||
<string name="reader">The title of the fragment/place where books are read.</string>
|
||||
<string name="delete_history">Ask if the user wants to delete all history items.</string>
|
||||
<string name="delete_history">Ask if the user wants to delete all history items.</string>
|
||||
<string name="delete_selected_history">Ask if the user wants to delete a number of selected history items.</string>
|
||||
<string name="delete_bookmarks">Ask if the user wants to delete all bookmarks.</string>
|
||||
<string name="delete_selected_bookmarks">Ask if the user wants to delete a number of selected bookmarks.</string>
|
||||
|
@ -283,4 +283,4 @@
|
||||
<string name="diagnostic_report_message">Пожалуйста, пришлите нам всю информацию ниже, чтобы мы смогли обнаружить проблему</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Масштаб Текста</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -94,4 +94,4 @@
|
||||
<string name="crash_checkbox_file_system">Детаљи о систему датотека</string>
|
||||
<string name="diagnostic_report">Дијагностички извештај</string>
|
||||
<string name="diagnostic_report_message">Пошаљите све детаље како бисмо могли да дијагностикујемо проблем</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -279,4 +279,4 @@
|
||||
<string name="diagnostic_report_message">Sorunu teşhis edebilmemiz için lütfen aşağıdaki tüm ayrıntıları gönderin</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Metin Yakınlığı</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -273,4 +273,4 @@
|
||||
<string name="diagnostic_report_message">請傳送所有以下詳細資訊,以讓我們可以方便診斷問題</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">文字縮放</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
<dimen name="kiwix_search_widget_margin">1dp</dimen>
|
||||
<dimen name="progress_view_height">2dp</dimen>
|
||||
<dimen name="home_list_margin">8dp</dimen>
|
||||
<dimen name="title_text_margin">16dp</dimen>
|
||||
<dimen name="title_text_padding">16dp</dimen>
|
||||
<dimen name="kiwix_search_widget_padding">0dp</dimen>
|
||||
|
@ -277,7 +277,7 @@
|
||||
<string name="diagnostic_report_message">Please send all the following details so we can diagnose the problem</string>
|
||||
<string name="percentage">%d%%</string>
|
||||
<string name="pref_text_zoom_title">Text Zoom</string>
|
||||
<string name="reader">Reader</string>
|
||||
<string name="reader">Reader</string>
|
||||
<string name="no_open_book">No open book</string>
|
||||
<string name="open_library">Open library</string>
|
||||
<string name="tab_restored">Tab restored</string>
|
||||
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>REPLACE_menu_home</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="display:none;">REPLACE_menu_home</h1>
|
||||
</body>
|
||||
</html>
|
@ -28,7 +28,6 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.widget.ImageView
|
||||
@ -42,9 +41,7 @@ import org.kiwix.kiwixmobile.core.base.BaseFragmentActivityExtensions.Super.Shou
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.core.main.CoreReaderFragment
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu
|
||||
import org.kiwix.kiwixmobile.core.main.WebViewCallback
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_PREFIX
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
||||
@ -156,15 +153,6 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
|
||||
override fun getIconResId() = R.mipmap.ic_launcher
|
||||
|
||||
override fun createWebClient(
|
||||
webViewCallback: WebViewCallback,
|
||||
zimReaderContainer: ZimReaderContainer
|
||||
) = CustomWebViewClient(webViewCallback, zimReaderContainer)
|
||||
|
||||
override fun onNewNavigationMenuClicked() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private fun enforcedLanguage(): Boolean {
|
||||
val currentLocaleCode = Locale.getDefault().toString()
|
||||
if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) {
|
||||
@ -180,7 +168,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
return menuFactory.create(
|
||||
menu!!,
|
||||
webViewList,
|
||||
!urlIsInvalid(),
|
||||
urlIsValid(),
|
||||
this,
|
||||
BuildConfig.DISABLE_READ_ALOUD,
|
||||
BuildConfig.DISABLE_TABS
|
||||
@ -199,14 +187,6 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
super.configureWebViewSelectionHandler(menu)
|
||||
}
|
||||
|
||||
override fun manageZimFiles(tab: Int) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
override fun showHomePage() {
|
||||
Log.e("CustomMain", "tried to show home page")
|
||||
}
|
||||
|
||||
override fun createNewTab() {
|
||||
newMainPageTab()
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.custom.main
|
||||
|
||||
import android.util.Log
|
||||
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
|
||||
import org.kiwix.kiwixmobile.core.utils.TAG_KIWIX
|
||||
|
||||
class CustomWebViewClient internal constructor(
|
||||
callback: WebViewCallback,
|
||||
zimReaderContainer: ZimReaderContainer
|
||||
) : CoreWebViewClient(callback, zimReaderContainer) {
|
||||
|
||||
override fun onUrlEqualToHome(view: WebView) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun onInvalidUrl(view: WebView) {
|
||||
Log.e(
|
||||
TAG_KIWIX,
|
||||
"Abandoning WebView as there's a problem getting the content for this custom app."
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user