mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -04:00
#2272 merge with one-activity
This commit is contained in:
commit
4f9078b6be
@ -18,30 +18,46 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.settings;
|
package org.kiwix.kiwixmobile.settings;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import androidx.test.rule.ActivityTestRule;
|
import androidx.test.rule.ActivityTestRule;
|
||||||
|
import androidx.test.rule.GrantPermissionRule;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.kiwix.kiwixmobile.core.R;
|
import org.kiwix.kiwixmobile.core.R;
|
||||||
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity;
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
import static androidx.test.espresso.action.ViewActions.click;
|
||||||
import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem;
|
import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
|
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
|
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed;
|
import static com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed;
|
||||||
import static org.hamcrest.Matchers.anyOf;
|
import static org.hamcrest.Matchers.anyOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.kiwix.kiwixmobile.utils.StandardActions.enterSettings;
|
||||||
|
import static org.kiwix.kiwixmobile.utils.StandardActions.openDrawer;
|
||||||
|
|
||||||
public class KiwixSettingsActivityTest {
|
public class KiwixSettingsFragmentTest {
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityTestRule<KiwixSettingsActivity> activityTestRule =
|
public ActivityTestRule<KiwixMainActivity> activityTestRule =
|
||||||
new ActivityTestRule<>(KiwixSettingsActivity.class);
|
new ActivityTestRule<>(KiwixMainActivity.class);
|
||||||
|
@Rule
|
||||||
|
public GrantPermissionRule readPermissionRule =
|
||||||
|
GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
@Rule
|
||||||
|
public GrantPermissionRule writePermissionRule =
|
||||||
|
GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
openDrawer();
|
||||||
|
enterSettings();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToggle() {
|
public void testToggle() {
|
||||||
@ -56,7 +72,7 @@ public class KiwixSettingsActivityTest {
|
|||||||
for (int i = 0; i < stringIds.length; i++) {
|
for (int i = 0; i < stringIds.length; i++) {
|
||||||
matchers[i] = withText(stringIds[i]);
|
matchers[i] = withText(stringIds[i]);
|
||||||
}
|
}
|
||||||
onView(withClassName(is(RecyclerView.class.getName())))
|
onView(withId(R.id.recycler_view))
|
||||||
.perform(actionOnItem(hasDescendant(anyOf(matchers)), click()));
|
.perform(actionOnItem(hasDescendant(anyOf(matchers)), click()));
|
||||||
}
|
}
|
||||||
|
|
@ -132,12 +132,6 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".settings.KiwixSettingsActivity">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name=".language.LanguageActivity" />
|
<activity android:name=".language.LanguageActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".local_file_transfer.LocalFileTransferActivity"
|
android:name=".local_file_transfer.LocalFileTransferActivity"
|
||||||
|
@ -31,7 +31,7 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
|||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment
|
import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity
|
import org.kiwix.kiwixmobile.settings.KiwixSettingsFragment
|
||||||
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
||||||
import org.kiwix.kiwixmobile.webserver.ZimHostModule
|
import org.kiwix.kiwixmobile.webserver.ZimHostModule
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles
|
||||||
@ -52,7 +52,7 @@ interface KiwixActivityComponent : CoreActivityComponent {
|
|||||||
fun inject(deleteFiles: DeleteFiles)
|
fun inject(deleteFiles: DeleteFiles)
|
||||||
fun inject(localFileTransferActivity: LocalFileTransferActivity)
|
fun inject(localFileTransferActivity: LocalFileTransferActivity)
|
||||||
fun inject(languageActivity: LanguageActivity)
|
fun inject(languageActivity: LanguageActivity)
|
||||||
fun inject(kiwixSettingsActivity: KiwixSettingsActivity)
|
fun inject(kiwixSettingsFragment: KiwixSettingsFragment)
|
||||||
fun inject(zimHostActivity: ZimHostActivity)
|
fun inject(zimHostActivity: ZimHostActivity)
|
||||||
fun inject(introActivity: IntroFragment)
|
fun inject(introActivity: IntroFragment)
|
||||||
fun inject(kiwixMainActivity: KiwixMainActivity)
|
fun inject(kiwixMainActivity: KiwixMainActivity)
|
||||||
|
@ -37,14 +37,11 @@ import kotlinx.android.synthetic.main.activity_kiwix_main.reader_drawer_nav_view
|
|||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
|
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
|
||||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
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.extensions.ActivityExtensions.start
|
||||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||||
import org.kiwix.kiwixmobile.core.main.PAGE_URL_KEY
|
import org.kiwix.kiwixmobile.core.main.PAGE_URL_KEY
|
||||||
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
|
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
|
||||||
import org.kiwix.kiwixmobile.core.utils.REQUEST_PREFERENCES
|
|
||||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity
|
|
||||||
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
import org.kiwix.kiwixmobile.webserver.ZimHostActivity
|
||||||
|
|
||||||
class KiwixMainActivity : CoreMainActivity() {
|
class KiwixMainActivity : CoreMainActivity() {
|
||||||
@ -55,6 +52,7 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
override val drawerContainerLayout: DrawerLayout by lazy { navigation_container }
|
override val drawerContainerLayout: DrawerLayout by lazy { navigation_container }
|
||||||
override val drawerNavView: NavigationView by lazy { drawer_nav_view }
|
override val drawerNavView: NavigationView by lazy { drawer_nav_view }
|
||||||
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
|
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
|
||||||
|
override val settingsFragmentResId: Int = R.id.kiwixSettingsFragment
|
||||||
override val historyFragmentResId: Int = R.id.historyFragment
|
override val historyFragmentResId: Int = R.id.historyFragment
|
||||||
override val topLevelDestinations =
|
override val topLevelDestinations =
|
||||||
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)
|
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)
|
||||||
@ -139,10 +137,6 @@ class KiwixMainActivity : CoreMainActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openSettingsActivity() {
|
|
||||||
startActivityForResult(intent<KiwixSettingsActivity>(), REQUEST_PREFERENCES)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun openPage(pageUrl: String, zimFilePath: String) {
|
override fun openPage(pageUrl: String, zimFilePath: String) {
|
||||||
navigate(
|
navigate(
|
||||||
R.id.readerFragment,
|
R.id.readerFragment,
|
||||||
|
@ -18,15 +18,15 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.settings
|
package org.kiwix.kiwixmobile.settings
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||||
import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity
|
import org.kiwix.kiwixmobile.core.settings.CoreSettingsFragment
|
||||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
|
|
||||||
class KiwixSettingsActivity : CoreSettingsActivity() {
|
class KiwixSettingsFragment : CoreSettingsFragment() {
|
||||||
|
|
||||||
override fun injection(coreComponent: CoreComponent) {
|
|
||||||
kiwixActivityComponent.inject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createPreferenceFragment() = KiwixPrefsFragment()
|
override fun createPreferenceFragment() = KiwixPrefsFragment()
|
||||||
|
|
||||||
|
override fun inject(baseActivity: BaseActivity) {
|
||||||
|
(baseActivity as KiwixMainActivity).cachedComponent.inject(this)
|
||||||
|
}
|
||||||
}
|
}
|
@ -65,4 +65,8 @@
|
|||||||
android:id="@+id/historyFragment"
|
android:id="@+id/historyFragment"
|
||||||
android:name="org.kiwix.kiwixmobile.core.page.history.HistoryFragment"
|
android:name="org.kiwix.kiwixmobile.core.page.history.HistoryFragment"
|
||||||
android:label="HistoryFragment" />
|
android:label="HistoryFragment" />
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/kiwixSettingsFragment"
|
||||||
|
android:name="org.kiwix.kiwixmobile.settings.KiwixSettingsFragment"
|
||||||
|
android:label="KiwixSettingsFragment" />
|
||||||
</navigation>
|
</navigation>
|
||||||
|
@ -50,7 +50,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
|||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||||
import org.kiwix.kiwixmobile.core.search.SearchActivity
|
import org.kiwix.kiwixmobile.core.search.SearchActivity
|
||||||
import org.kiwix.kiwixmobile.core.search.viewmodel.SearchResultGenerator
|
import org.kiwix.kiwixmobile.core.search.viewmodel.SearchResultGenerator
|
||||||
import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity
|
import org.kiwix.kiwixmobile.core.settings.CoreSettingsFragment
|
||||||
import org.kiwix.kiwixmobile.core.utils.BookUtils
|
import org.kiwix.kiwixmobile.core.utils.BookUtils
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -107,5 +107,5 @@ interface CoreComponent {
|
|||||||
fun inject(searchActivity: SearchActivity)
|
fun inject(searchActivity: SearchActivity)
|
||||||
|
|
||||||
fun inject(helpActivity: HelpActivity)
|
fun inject(helpActivity: HelpActivity)
|
||||||
fun inject(settingsActivity: CoreSettingsActivity)
|
fun inject(settingsFragment: CoreSettingsFragment)
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,12 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
|
|
||||||
@Inject lateinit var externalLinkOpener: ExternalLinkOpener
|
@Inject lateinit var externalLinkOpener: ExternalLinkOpener
|
||||||
protected lateinit var drawerToggle: ActionBarDrawerToggle
|
protected lateinit var drawerToggle: ActionBarDrawerToggle
|
||||||
|
|
||||||
abstract val navController: NavController
|
abstract val navController: NavController
|
||||||
|
|
||||||
abstract val drawerContainerLayout: DrawerLayout
|
abstract val drawerContainerLayout: DrawerLayout
|
||||||
abstract val drawerNavView: NavigationView
|
abstract val drawerNavView: NavigationView
|
||||||
abstract val bookmarksFragmentResId: Int
|
abstract val bookmarksFragmentResId: Int
|
||||||
|
abstract val settingsFragmentResId: Int
|
||||||
abstract val historyFragmentResId: Int
|
abstract val historyFragmentResId: Int
|
||||||
abstract val initialDestinationFragmentId: Int
|
abstract val initialDestinationFragmentId: Int
|
||||||
abstract val cachedComponent: CoreActivityComponent
|
abstract val cachedComponent: CoreActivityComponent
|
||||||
@ -148,7 +149,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
open fun onNavigationItemSelected(item: MenuItem): Boolean {
|
open fun onNavigationItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_support_kiwix -> openSupportKiwixExternalLink()
|
R.id.menu_support_kiwix -> openSupportKiwixExternalLink()
|
||||||
R.id.menu_settings -> openSettingsActivity()
|
R.id.menu_settings -> openSettings()
|
||||||
R.id.menu_help -> start<HelpActivity>()
|
R.id.menu_help -> start<HelpActivity>()
|
||||||
R.id.menu_history -> openHistoryActivity()
|
R.id.menu_history -> openHistoryActivity()
|
||||||
R.id.menu_bookmarks_list -> openBookmarksActivity()
|
R.id.menu_bookmarks_list -> openBookmarksActivity()
|
||||||
@ -212,7 +213,10 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
|||||||
navController.navigate(fragmentId, bundle)
|
navController.navigate(fragmentId, bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun openSettingsActivity()
|
fun openSettings() {
|
||||||
|
handleDrawerOnNavigation()
|
||||||
|
navigate(settingsFragmentResId)
|
||||||
|
}
|
||||||
|
|
||||||
private fun openHistoryActivity() {
|
private fun openHistoryActivity() {
|
||||||
navigate(historyFragmentResId)
|
navigate(historyFragmentResId)
|
||||||
|
@ -96,13 +96,13 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
|
super<BaseFragment>.onCreateOptionsMenu(menu, inflater)
|
||||||
inflater.inflate(R.menu.menu_page, menu)
|
inflater.inflate(R.menu.menu_page, menu)
|
||||||
val search = menu.findItem(R.id.menu_page_search).actionView as SearchView
|
val search = menu.findItem(R.id.menu_page_search).actionView as SearchView
|
||||||
search.queryHint = searchQueryHint
|
search.queryHint = searchQueryHint
|
||||||
search.setOnQueryTextListener(SimpleTextListener {
|
search.setOnQueryTextListener(SimpleTextListener {
|
||||||
pageViewModel.actions.offer(Action.Filter(it))
|
pageViewModel.actions.offer(Action.Filter(it))
|
||||||
})
|
})
|
||||||
super<BaseFragment>.onCreateOptionsMenu(menu, inflater)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
@ -203,7 +203,6 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
|
|||||||
private void clearAllHistoryDialog() {
|
private void clearAllHistoryDialog() {
|
||||||
alertDialogShower.show(KiwixDialog.ClearAllHistory.INSTANCE, () -> {
|
alertDialogShower.show(KiwixDialog.ClearAllHistory.INSTANCE, () -> {
|
||||||
presenter.clearHistory();
|
presenter.clearHistory();
|
||||||
CoreSettingsActivity.allHistoryCleared = true;
|
|
||||||
Snackbar.make(getView(), R.string.all_history_cleared, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(getView(), R.string.all_history_cleared, Snackbar.LENGTH_SHORT).show();
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
});
|
});
|
||||||
|
@ -1,72 +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.settings;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import org.kiwix.kiwixmobile.core.R;
|
|
||||||
import org.kiwix.kiwixmobile.core.base.BaseActivity;
|
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.EXTRA_WEBVIEWS_LIST;
|
|
||||||
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.RESULT_HISTORY_CLEARED;
|
|
||||||
|
|
||||||
public abstract class CoreSettingsActivity extends BaseActivity {
|
|
||||||
|
|
||||||
public static boolean allHistoryCleared = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.settings);
|
|
||||||
|
|
||||||
allHistoryCleared = false;
|
|
||||||
|
|
||||||
getSupportFragmentManager()
|
|
||||||
.beginTransaction().
|
|
||||||
replace(R.id.content_frame, createPreferenceFragment())
|
|
||||||
.commit();
|
|
||||||
|
|
||||||
setUpToolbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Fragment createPreferenceFragment();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
getWindow().setWindowAnimations(0);
|
|
||||||
if (allHistoryCleared) {
|
|
||||||
Intent data = new Intent();
|
|
||||||
data.putExtra(EXTRA_WEBVIEWS_LIST, allHistoryCleared);
|
|
||||||
setResult(RESULT_HISTORY_CLEARED, data);
|
|
||||||
}
|
|
||||||
super.onBackPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpToolbar() {
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
getSupportActionBar().setTitle(getString(R.string.menu_settings));
|
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
toolbar.setNavigationOnClickListener(v -> onBackPressed());
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.settings
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import kotlinx.android.synthetic.main.layout_toolbar.toolbar
|
||||||
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.base.BaseFragment
|
||||||
|
|
||||||
|
abstract class CoreSettingsFragment : BaseFragment() {
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
requireActivity().supportFragmentManager
|
||||||
|
.beginTransaction().replace(R.id.content_frame, createPreferenceFragment())
|
||||||
|
.commit()
|
||||||
|
setUpToolbar()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View = inflater.inflate(R.layout.settings, container, false)
|
||||||
|
|
||||||
|
protected abstract fun createPreferenceFragment(): Fragment
|
||||||
|
|
||||||
|
private fun setUpToolbar() {
|
||||||
|
val activity = requireActivity() as AppCompatActivity
|
||||||
|
activity.setSupportActionBar(toolbar)
|
||||||
|
activity.supportActionBar!!.title = getString(R.string.menu_settings)
|
||||||
|
activity.supportActionBar!!.setHomeButtonEnabled(true)
|
||||||
|
activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,14 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:showIn="@layout/activity_help">
|
tools:showIn="@layout/activity_help">
|
||||||
|
|
||||||
<include layout="@layout/layout_toolbar" />
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:popupTheme="@style/KiwixTheme"
|
||||||
|
app:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
|
||||||
|
tools:showIn="@layout/activity_search" />
|
||||||
|
|
||||||
<Switch
|
<Switch
|
||||||
android:id="@+id/page_switch"
|
android:id="@+id/page_switch"
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include layout="@layout/layout_standard_app_bar" />
|
<include layout="@layout/layout_toolbar" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/content_frame"
|
android:id="@+id/content_frame"
|
||||||
|
@ -52,12 +52,6 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".settings.CustomSettingsActivity">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name=".download.CustomDownloadActivity" />
|
<activity android:name=".download.CustomDownloadActivity" />
|
||||||
|
|
||||||
<receiver android:name=".main.CustomSearchWidget">
|
<receiver android:name=".main.CustomSearchWidget">
|
||||||
|
@ -26,13 +26,13 @@ import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent
|
|||||||
import org.kiwix.kiwixmobile.custom.download.CustomDownloadActivity
|
import org.kiwix.kiwixmobile.custom.download.CustomDownloadActivity
|
||||||
import org.kiwix.kiwixmobile.custom.main.CustomMainActivity
|
import org.kiwix.kiwixmobile.custom.main.CustomMainActivity
|
||||||
import org.kiwix.kiwixmobile.custom.main.CustomReaderFragment
|
import org.kiwix.kiwixmobile.custom.main.CustomReaderFragment
|
||||||
import org.kiwix.kiwixmobile.custom.settings.CustomSettingsActivity
|
import org.kiwix.kiwixmobile.custom.settings.CustomSettingsFragment
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Subcomponent(modules = [CustomActivityModule::class])
|
@Subcomponent(modules = [CustomActivityModule::class])
|
||||||
interface CustomActivityComponent : CoreActivityComponent {
|
interface CustomActivityComponent : CoreActivityComponent {
|
||||||
fun inject(customMainActivity: CustomMainActivity)
|
fun inject(customMainActivity: CustomMainActivity)
|
||||||
fun inject(customSettingsActivity: CustomSettingsActivity)
|
fun inject(customSettingsFragment: CustomSettingsFragment)
|
||||||
fun inject(customDownloadActivity: CustomDownloadActivity)
|
fun inject(customDownloadActivity: CustomDownloadActivity)
|
||||||
fun inject(customReaderFragment: CustomReaderFragment)
|
fun inject(customReaderFragment: CustomReaderFragment)
|
||||||
|
|
||||||
|
@ -29,13 +29,10 @@ import com.google.android.material.navigation.NavigationView
|
|||||||
import kotlinx.android.synthetic.main.activity_main.custom_drawer_container
|
import kotlinx.android.synthetic.main.activity_main.custom_drawer_container
|
||||||
import kotlinx.android.synthetic.main.activity_main.drawer_nav_view
|
import kotlinx.android.synthetic.main.activity_main.drawer_nav_view
|
||||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
||||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.intent
|
|
||||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||||
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
|
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
|
||||||
import org.kiwix.kiwixmobile.core.utils.REQUEST_PREFERENCES
|
|
||||||
import org.kiwix.kiwixmobile.custom.R
|
import org.kiwix.kiwixmobile.custom.R
|
||||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
||||||
import org.kiwix.kiwixmobile.custom.settings.CustomSettingsActivity
|
|
||||||
|
|
||||||
const val REQUEST_READ_FOR_OBB = 5002
|
const val REQUEST_READ_FOR_OBB = 5002
|
||||||
|
|
||||||
@ -47,6 +44,7 @@ class CustomMainActivity : CoreMainActivity() {
|
|||||||
override val drawerContainerLayout: DrawerLayout by lazy { custom_drawer_container }
|
override val drawerContainerLayout: DrawerLayout by lazy { custom_drawer_container }
|
||||||
override val drawerNavView: NavigationView by lazy { drawer_nav_view }
|
override val drawerNavView: NavigationView by lazy { drawer_nav_view }
|
||||||
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
|
override val bookmarksFragmentResId: Int = R.id.bookmarksFragment
|
||||||
|
override val settingsFragmentResId: Int = R.id.customSettingsFragment
|
||||||
override val historyFragmentResId: Int = R.id.historyFragment
|
override val historyFragmentResId: Int = R.id.historyFragment
|
||||||
override val initialDestinationFragmentId: Int = R.id.customReaderFragment
|
override val initialDestinationFragmentId: Int = R.id.customReaderFragment
|
||||||
override val cachedComponent by lazy { customActivityComponent }
|
override val cachedComponent by lazy { customActivityComponent }
|
||||||
@ -92,10 +90,6 @@ class CustomMainActivity : CoreMainActivity() {
|
|||||||
.isVisible = false
|
.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openSettingsActivity() {
|
|
||||||
startActivityForResult(intent<CustomSettingsActivity>(), REQUEST_PREFERENCES)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun openPage(pageUrl: String, zimFilePath: String) {
|
override fun openPage(pageUrl: String, zimFilePath: String) {
|
||||||
val bundle = bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
|
val bundle = bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
|
||||||
navigate(R.id.customReaderFragment, bundle)
|
navigate(R.id.customReaderFragment, bundle)
|
||||||
|
@ -18,15 +18,15 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.custom.settings
|
package org.kiwix.kiwixmobile.custom.settings
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||||
import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity
|
import org.kiwix.kiwixmobile.core.settings.CoreSettingsFragment
|
||||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
import org.kiwix.kiwixmobile.custom.main.CustomMainActivity
|
||||||
|
|
||||||
class CustomSettingsActivity : CoreSettingsActivity() {
|
class CustomSettingsFragment : CoreSettingsFragment() {
|
||||||
|
|
||||||
override fun injection(coreComponent: CoreComponent) {
|
|
||||||
customActivityComponent.inject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createPreferenceFragment() = CustomPrefsFragment()
|
override fun createPreferenceFragment() = CustomPrefsFragment()
|
||||||
|
|
||||||
|
override fun inject(baseActivity: BaseActivity) {
|
||||||
|
(baseActivity as CustomMainActivity).cachedComponent.inject(this)
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,4 +37,8 @@
|
|||||||
android:id="@+id/bookmarksFragment"
|
android:id="@+id/bookmarksFragment"
|
||||||
android:name="org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment"
|
android:name="org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment"
|
||||||
android:label="BookmarksFragment" />
|
android:label="BookmarksFragment" />
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/customSettingsFragment"
|
||||||
|
android:name="org.kiwix.kiwixmobile.custom.settings.CustomSettingsFragment"
|
||||||
|
android:label="CustomSettingsFragment" />
|
||||||
</navigation>
|
</navigation>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user