From ae75cd1b38649ba4ef28d9d111fbb4b1769ec5a1 Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Fri, 11 Sep 2020 02:39:31 +0530 Subject: [PATCH 01/91] WIP #2335 --- custom/detekt_baseline.xml | 2 +- custom/src/main/AndroidManifest.xml | 28 +++++++---- .../custom/di/CustomActivityComponent.kt | 10 ++-- ...dActivity.kt => CustomDownloadFragment.kt} | 49 ++++++++++++++----- .../custom/main/CustomReaderFragment.kt | 17 +++++-- .../res/layout/activity_custom_download.xml | 1 + .../main/res/navigation/custom_nav_graph.xml | 10 ++-- 7 files changed, 80 insertions(+), 37 deletions(-) rename custom/src/main/java/org/kiwix/kiwixmobile/custom/download/{CustomDownloadActivity.kt => CustomDownloadFragment.kt} (67%) diff --git a/custom/detekt_baseline.xml b/custom/detekt_baseline.xml index d14ae3a4df..49228c6da2 100644 --- a/custom/detekt_baseline.xml +++ b/custom/detekt_baseline.xml @@ -3,7 +3,7 @@ LongParameterList:DownloadCustom.kt$DownloadCustom$( id: String = "", title: String = "", description: String = "", language: String = "", creator: String = "", publisher: String = "", date: String = "", url: String = "", articleCount: String = "", mediaCount: String = "", size: String = "", name: String = "", favIcon: String = "" ) - MagicNumber:CustomDownloadActivity.kt$CustomDownloadActivity$3 + MagicNumber:CustomDownloadFragment.kt$CustomDownloadActivity$3 TooGenericExceptionThrown:ActivityExtensions.kt$throw RuntimeException( """ applicationContext is ${applicationContext::class.java.simpleName} application is ${application::class.java.simpleName} """.trimIndent() ) diff --git a/custom/src/main/AndroidManifest.xml b/custom/src/main/AndroidManifest.xml index 593d70fd77..2ae88ceead 100644 --- a/custom/src/main/AndroidManifest.xml +++ b/custom/src/main/AndroidManifest.xml @@ -11,17 +11,10 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" tools:targetApi="m"> - - - + android:theme="@style/ThemeOverlay.KiwixTheme.Launcher"> @@ -30,6 +23,16 @@ + + + + @@ -52,7 +55,12 @@ - + + + + + + diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomActivityComponent.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomActivityComponent.kt index 56e494bf5c..81a1624f7d 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomActivityComponent.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomActivityComponent.kt @@ -23,17 +23,19 @@ import dagger.BindsInstance import dagger.Subcomponent import org.kiwix.kiwixmobile.core.di.ActivityScope import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent -import org.kiwix.kiwixmobile.custom.download.CustomDownloadActivity +import org.kiwix.kiwixmobile.custom.download.CustomDownloadFragment import org.kiwix.kiwixmobile.custom.main.CustomMainActivity import org.kiwix.kiwixmobile.custom.main.CustomReaderFragment -import org.kiwix.kiwixmobile.custom.settings.CustomSettingsFragment +import org.kiwix.kiwixmobile.custom.settings.CustomSettingsActivity +import org.kiwix.kiwixmobile.custom.splash.CustomSplashActivity @ActivityScope @Subcomponent(modules = [CustomActivityModule::class]) interface CustomActivityComponent : CoreActivityComponent { fun inject(customMainActivity: CustomMainActivity) - fun inject(customSettingsFragment: CustomSettingsFragment) - fun inject(customDownloadActivity: CustomDownloadActivity) + fun inject(customSettingsActivity: CustomSettingsActivity) + fun inject(customDownloadFragment: CustomDownloadFragment) + fun inject(customSplashActivity: CustomSplashActivity) fun inject(customReaderFragment: CustomReaderFragment) @Subcomponent.Builder diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt similarity index 67% rename from custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadActivity.kt rename to custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt index 241b597454..c24dbb8ee5 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt @@ -19,6 +19,10 @@ package org.kiwix.kiwixmobile.custom.download import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import io.reactivex.disposables.CompositeDisposable @@ -30,10 +34,11 @@ import kotlinx.android.synthetic.main.layout_custom_download_in_progress.cd_eta import kotlinx.android.synthetic.main.layout_custom_download_in_progress.cd_progress import kotlinx.android.synthetic.main.layout_custom_download_required.cd_download_button import org.kiwix.kiwixmobile.core.base.BaseActivity -import org.kiwix.kiwixmobile.core.di.components.CoreComponent +import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel import org.kiwix.kiwixmobile.core.extensions.setDistinctDisplayedChild +import org.kiwix.kiwixmobile.core.extensions.viewModel +import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.custom.R import org.kiwix.kiwixmobile.custom.customActivityComponent import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload @@ -44,10 +49,7 @@ import org.kiwix.kiwixmobile.custom.download.State.DownloadInProgress import org.kiwix.kiwixmobile.custom.download.State.DownloadRequired import javax.inject.Inject -class CustomDownloadActivity : BaseActivity() { - override fun injection(coreComponent: CoreComponent) { - customActivityComponent.inject(this) - } +class CustomDownloadFragment : BaseFragment() { private val downloadViewModel by lazy { viewModel(viewModelFactory) @@ -56,14 +58,37 @@ class CustomDownloadActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory private val compositeDisposable = CompositeDisposable() + override fun inject(baseActivity: BaseActivity) { + baseActivity.customActivityComponent.inject(this) + } - override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_custom_download) - downloadViewModel.state.observe(this, Observer(::render)) + val root = inflater.inflate(R.layout.activity_custom_download, container, false) + return root + } + + /** + * Called immediately after [.onCreateView] + * has returned, but before any saved state has been restored in to the view. + * This gives subclasses a chance to initialize themselves once + * they know their view hierarchy has been completely created. The fragment's + * view hierarchy is not however attached to its parent at this point. + * @param view The View returned by [.onCreateView]. + * @param savedInstanceState If non-null, this fragment is being re-constructed + * from a previous saved state as given here. + */ + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val activity = requireActivity() as CoreMainActivity + downloadViewModel.state.observe(viewLifecycleOwner, Observer(::render)) compositeDisposable.add( downloadViewModel.effects.subscribe( - { it.invokeWith(this) }, + { it.invokeWith(activity) }, Throwable::printStackTrace ) ) @@ -85,7 +110,7 @@ class CustomDownloadActivity : BaseActivity() { } is DownloadFailed -> { cd_view_animator.setDistinctDisplayedChild(2) - cd_error_text.text = state.downloadState.toReadableState(this) + cd_error_text.text = context?.let(state.downloadState::toReadableState) } DownloadComplete -> cd_view_animator.setDistinctDisplayedChild(3) } @@ -94,6 +119,6 @@ class CustomDownloadActivity : BaseActivity() { private fun render(downloadItem: DownloadItem) { cd_progress.progress = downloadItem.progress cd_eta.text = downloadItem.readableEta - cd_download_state.text = downloadItem.downloadState.toReadableState(this) + cd_download_state.text = context?.let(downloadItem.downloadState::toReadableState) } } diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 14a6d5b314..2f0855a26b 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -36,21 +36,23 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.drawerlayout.widget.DrawerLayout +import org.kiwix.kiwixmobile.core.R2.id.start import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super.ShouldCall +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setupDrawerToggle 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.reader.ZimFileReader.Companion.CONTENT_PREFIX +import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog -import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.custom.BuildConfig import org.kiwix.kiwixmobile.custom.R import org.kiwix.kiwixmobile.custom.customActivityComponent -import org.kiwix.kiwixmobile.custom.download.CustomDownloadActivity +import org.kiwix.kiwixmobile.custom.download.CustomDownloadFragment import java.util.Locale import javax.inject.Inject @@ -134,7 +136,16 @@ class CustomReaderFragment : CoreReaderFragment() { requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB) } else { activity?.finish() - activity?.start() + + // val manger = activity?.supportFragmentManager + // val trans = manger?.beginTransaction() + // val fragment = CustomDownloadFragment() + // // layoutInflater.inflate(R.layout.activity_custom_download) + // // trans?.apply { add(R.id.custom_drawer_container, fragment).commit() } + // trans?.add(R.id.custom_drawer_container, fragment) + // trans?.commit() + with(activity as AppCompatActivity) { navigate(R.id.customDownloadFragment) } + // activity?.start() // maybe a frag transaction will do the trick? } } ) diff --git a/custom/src/main/res/layout/activity_custom_download.xml b/custom/src/main/res/layout/activity_custom_download.xml index ffec0624bb..c3f3785a90 100644 --- a/custom/src/main/res/layout/activity_custom_download.xml +++ b/custom/src/main/res/layout/activity_custom_download.xml @@ -2,6 +2,7 @@ diff --git a/custom/src/main/res/navigation/custom_nav_graph.xml b/custom/src/main/res/navigation/custom_nav_graph.xml index 9e21c31ba8..41509fb6de 100644 --- a/custom/src/main/res/navigation/custom_nav_graph.xml +++ b/custom/src/main/res/navigation/custom_nav_graph.xml @@ -38,11 +38,7 @@ android:name="org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment" android:label="BookmarksFragment" /> - + android:id="@+id/customDownloadFragment" + android:name="org.kiwix.kiwixmobile.custom.download.CustomDownloadFragment" + android:label="CustomDownloadFragment" /> From 4fb6d60d96f73b8d2fa1b55775bdba3b4c6f9358 Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Fri, 11 Sep 2020 02:45:11 +0530 Subject: [PATCH 02/91] Removed Comments --- .../custom/download/CustomDownloadFragment.kt | 14 +------------- .../custom/main/CustomReaderFragment.kt | 13 +------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt index c24dbb8ee5..7c83dab1f0 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt @@ -22,7 +22,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import io.reactivex.disposables.CompositeDisposable @@ -68,20 +67,9 @@ class CustomDownloadFragment : BaseFragment() { savedInstanceState: Bundle? ): View? { super.onCreate(savedInstanceState) - val root = inflater.inflate(R.layout.activity_custom_download, container, false) - return root + return inflater.inflate(R.layout.activity_custom_download, container, false) } - /** - * Called immediately after [.onCreateView] - * has returned, but before any saved state has been restored in to the view. - * This gives subclasses a chance to initialize themselves once - * they know their view hierarchy has been completely created. The fragment's - * view hierarchy is not however attached to its parent at this point. - * @param view The View returned by [.onCreateView]. - * @param savedInstanceState If non-null, this fragment is being re-constructed - * from a previous saved state as given here. - */ override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val activity = requireActivity() as CoreMainActivity diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 2f0855a26b..3739cb8570 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -36,13 +36,11 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.drawerlayout.widget.DrawerLayout -import org.kiwix.kiwixmobile.core.R2.id.start import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super.ShouldCall import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setupDrawerToggle -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.reader.ZimFileReader.Companion.CONTENT_PREFIX @@ -52,7 +50,6 @@ import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog import org.kiwix.kiwixmobile.custom.BuildConfig import org.kiwix.kiwixmobile.custom.R import org.kiwix.kiwixmobile.custom.customActivityComponent -import org.kiwix.kiwixmobile.custom.download.CustomDownloadFragment import java.util.Locale import javax.inject.Inject @@ -136,16 +133,8 @@ class CustomReaderFragment : CoreReaderFragment() { requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB) } else { activity?.finish() - - // val manger = activity?.supportFragmentManager - // val trans = manger?.beginTransaction() - // val fragment = CustomDownloadFragment() - // // layoutInflater.inflate(R.layout.activity_custom_download) - // // trans?.apply { add(R.id.custom_drawer_container, fragment).commit() } - // trans?.add(R.id.custom_drawer_container, fragment) - // trans?.commit() + // trans?.apply { add(R.id.custom_drawer_container, fragment).commit() } with(activity as AppCompatActivity) { navigate(R.id.customDownloadFragment) } - // activity?.start() // maybe a frag transaction will do the trick? } } ) From 307d7807a53cc0f6215441be12c640e8ee82d45a Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Fri, 11 Sep 2020 12:52:10 +0530 Subject: [PATCH 03/91] Some minute fixes but crash still occurs --- .../kiwixmobile/core/main/CoreReaderFragment.java | 14 ++++++++++---- custom/detekt_baseline.xml | 2 +- .../custom/download/CustomDownloadFragment.kt | 11 ++++++----- .../custom/main/CustomReaderFragment.kt | 5 +++-- .../src/main/res/navigation/custom_nav_graph.xml | 3 +++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java index 91439d7397..f0d9757870 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java @@ -89,6 +89,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import javax.inject.Inject; import kotlin.Unit; import org.jetbrains.annotations.NotNull; @@ -753,10 +754,15 @@ protected void loadUrl(String url, KiwixWebView webview) { } private KiwixWebView initalizeWebView(String url) { - AttributeSet attrs = StyleUtils.getAttributes(requireActivity(), R.xml.webview); - KiwixWebView webView = createWebView(attrs); - loadUrl(url, webView); - return webView; + //if(requireContext() != null) { + AttributeSet attrs = StyleUtils.getAttributes(getActivity(), R.xml.webview); + KiwixWebView webView = createWebView(attrs); + loadUrl(url, webView); + return webView; + //} else{ + // Log.e("KIWIX", "initalizeWebView: CONTEXXT NOT FOUND, NULL"); + // return null; + //} } @NotNull protected ToolbarScrollingKiwixWebView createWebView(AttributeSet attrs) { diff --git a/custom/detekt_baseline.xml b/custom/detekt_baseline.xml index 49228c6da2..1c9b44536c 100644 --- a/custom/detekt_baseline.xml +++ b/custom/detekt_baseline.xml @@ -3,7 +3,7 @@ LongParameterList:DownloadCustom.kt$DownloadCustom$( id: String = "", title: String = "", description: String = "", language: String = "", creator: String = "", publisher: String = "", date: String = "", url: String = "", articleCount: String = "", mediaCount: String = "", size: String = "", name: String = "", favIcon: String = "" ) - MagicNumber:CustomDownloadFragment.kt$CustomDownloadActivity$3 + MagicNumber:CustomDownloadFragment.kt$CustomDownloadFragment$3 TooGenericExceptionThrown:ActivityExtensions.kt$throw RuntimeException( """ applicationContext is ${applicationContext::class.java.simpleName} application is ${application::class.java.simpleName} """.trimIndent() ) diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt index 7c83dab1f0..4f92057ef6 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt @@ -67,11 +67,7 @@ class CustomDownloadFragment : BaseFragment() { savedInstanceState: Bundle? ): View? { super.onCreate(savedInstanceState) - return inflater.inflate(R.layout.activity_custom_download, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + val root = inflater.inflate(R.layout.activity_custom_download, container, false) val activity = requireActivity() as CoreMainActivity downloadViewModel.state.observe(viewLifecycleOwner, Observer(::render)) compositeDisposable.add( @@ -80,6 +76,11 @@ class CustomDownloadFragment : BaseFragment() { Throwable::printStackTrace ) ) + return root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) cd_download_button.setOnClickListener { downloadViewModel.actions.offer(ClickedDownload) } cd_retry_button.setOnClickListener { downloadViewModel.actions.offer(ClickedRetry) } } diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 3739cb8570..2a804a153d 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -36,10 +36,10 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.drawerlayout.widget.DrawerLayout +import androidx.navigation.fragment.findNavController import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions.Super.ShouldCall -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setupDrawerToggle import org.kiwix.kiwixmobile.core.main.CoreReaderFragment import org.kiwix.kiwixmobile.core.main.MainMenu @@ -133,8 +133,9 @@ class CustomReaderFragment : CoreReaderFragment() { requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB) } else { activity?.finish() + // val acct = requireActivity() as AppCompatActivity // trans?.apply { add(R.id.custom_drawer_container, fragment).commit() } - with(activity as AppCompatActivity) { navigate(R.id.customDownloadFragment) } + findNavController().navigate(R.id.customDownloadFragment) } } ) diff --git a/custom/src/main/res/navigation/custom_nav_graph.xml b/custom/src/main/res/navigation/custom_nav_graph.xml index 41509fb6de..2da8d68289 100644 --- a/custom/src/main/res/navigation/custom_nav_graph.xml +++ b/custom/src/main/res/navigation/custom_nav_graph.xml @@ -28,6 +28,9 @@ android:name="pageUrl" android:defaultValue="" app:argType="string" /> + Date: Fri, 11 Sep 2020 13:14:50 +0530 Subject: [PATCH 04/91] Fixed Crash! Custom now works as expected --- .../org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java | 2 +- .../org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt | 3 --- custom/src/main/res/layout/activity_custom_download.xml | 1 - custom/src/main/res/navigation/custom_nav_graph.xml | 3 --- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java index f0d9757870..d2bdef0fec 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java @@ -755,7 +755,7 @@ protected void loadUrl(String url, KiwixWebView webview) { private KiwixWebView initalizeWebView(String url) { //if(requireContext() != null) { - AttributeSet attrs = StyleUtils.getAttributes(getActivity(), R.xml.webview); + AttributeSet attrs = StyleUtils.getAttributes(requireActivity(), R.xml.webview); KiwixWebView webView = createWebView(attrs); loadUrl(url, webView); return webView; diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index 2a804a153d..762755b6cd 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt @@ -132,9 +132,6 @@ class CustomReaderFragment : CoreReaderFragment() { ) { requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB) } else { - activity?.finish() - // val acct = requireActivity() as AppCompatActivity - // trans?.apply { add(R.id.custom_drawer_container, fragment).commit() } findNavController().navigate(R.id.customDownloadFragment) } } diff --git a/custom/src/main/res/layout/activity_custom_download.xml b/custom/src/main/res/layout/activity_custom_download.xml index c3f3785a90..ffec0624bb 100644 --- a/custom/src/main/res/layout/activity_custom_download.xml +++ b/custom/src/main/res/layout/activity_custom_download.xml @@ -2,7 +2,6 @@ diff --git a/custom/src/main/res/navigation/custom_nav_graph.xml b/custom/src/main/res/navigation/custom_nav_graph.xml index 2da8d68289..41509fb6de 100644 --- a/custom/src/main/res/navigation/custom_nav_graph.xml +++ b/custom/src/main/res/navigation/custom_nav_graph.xml @@ -28,9 +28,6 @@ android:name="pageUrl" android:defaultValue="" app:argType="string" /> - Date: Fri, 11 Sep 2020 13:18:05 +0530 Subject: [PATCH 05/91] #2335 Refactored Activity layout to Fragment --- .../kiwixmobile/custom/download/CustomDownloadFragment.kt | 4 ++-- ...ivity_custom_download.xml => fragment_custom_download.xml} | 0 .../src/main/res/layout/layout_custom_download_complete.xml | 2 +- custom/src/main/res/layout/layout_custom_download_error.xml | 2 +- .../src/main/res/layout/layout_custom_download_required.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename custom/src/main/res/layout/{activity_custom_download.xml => fragment_custom_download.xml} (100%) diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt index 4f92057ef6..0c74bbe910 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadFragment.kt @@ -25,7 +25,7 @@ import android.view.ViewGroup import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.activity_custom_download.cd_view_animator +import kotlinx.android.synthetic.main.fragment_custom_download.cd_view_animator import kotlinx.android.synthetic.main.layout_custom_download_error.cd_error_text import kotlinx.android.synthetic.main.layout_custom_download_error.cd_retry_button import kotlinx.android.synthetic.main.layout_custom_download_in_progress.cd_download_state @@ -67,7 +67,7 @@ class CustomDownloadFragment : BaseFragment() { savedInstanceState: Bundle? ): View? { super.onCreate(savedInstanceState) - val root = inflater.inflate(R.layout.activity_custom_download, container, false) + val root = inflater.inflate(R.layout.fragment_custom_download, container, false) val activity = requireActivity() as CoreMainActivity downloadViewModel.state.observe(viewLifecycleOwner, Observer(::render)) compositeDisposable.add( diff --git a/custom/src/main/res/layout/activity_custom_download.xml b/custom/src/main/res/layout/fragment_custom_download.xml similarity index 100% rename from custom/src/main/res/layout/activity_custom_download.xml rename to custom/src/main/res/layout/fragment_custom_download.xml diff --git a/custom/src/main/res/layout/layout_custom_download_complete.xml b/custom/src/main/res/layout/layout_custom_download_complete.xml index a0a8572aec..649ec1c978 100644 --- a/custom/src/main/res/layout/layout_custom_download_complete.xml +++ b/custom/src/main/res/layout/layout_custom_download_complete.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:showIn="@layout/activity_custom_download"> + tools:showIn="@layout/fragment_custom_download"> + tools:showIn="@layout/fragment_custom_download"> + tools:showIn="@layout/fragment_custom_download"> Date: Fri, 11 Sep 2020 15:52:54 +0530 Subject: [PATCH 06/91] Attempt to Avoid crash on relaunch without book downloaded --- .idea/codeStyles/Project.xml | 9 ++ .../core/main/CoreReaderFragment.java | 100 +++++++++--------- .../main/ToolbarScrollingKiwixWebView.java | 13 ++- 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 9ab52cb68d..4698dbeb3f 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -37,6 +37,15 @@ +