From 77a9a1a469574d1e1ae8e1cedf93d23097472e19 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 23 Nov 2023 18:43:33 +0530 Subject: [PATCH] Upgraded few dependencies. * Upgraded kotlin to to make it compatible with gradle . * Upgraded dagger to to make it compatible with gradle . * Removed from project since it is not maintained from 2020 and new gradle is not compatible with this library, so we have changed the it with binding. --- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Libs.kt | 17 -- buildSrc/src/main/kotlin/Versions.kt | 4 +- .../kotlin/plugin/AllProjectConfigurer.kt | 2 - .../kiwixmobile/core/base/BaseActivity.kt | 15 -- .../core/main/CoreReaderFragment.kt | 217 ++++++++++-------- 6 files changed, 130 insertions(+), 127 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index bc22521aa5..e1c8c48607 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,7 +12,7 @@ repositories { dependencies { implementation("com.android.tools.build:gradle:8.1.3") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") implementation("org.jacoco:org.jacoco.core:0.8.8") implementation("org.jlleitschuh.gradle:ktlint-gradle:10.3.0") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev20230406-2.0.0") { diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index c3959acb66..9bf96dc940 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -138,23 +138,6 @@ object Libs { const val dagger_compiler: String = "com.google.dagger:dagger-compiler:" + Versions.com_google_dagger - /** - * https://github.com/JakeWharton/butterknife/ - */ - const val butterknife: String = "com.jakewharton:butterknife:" + Versions.com_jakewharton - - /** - * https://github.com/JakeWharton/butterknife/ - */ - const val butterknife_compiler: String = "com.jakewharton:butterknife-compiler:" + - Versions.com_jakewharton - - /** - * https://github.com/JakeWharton/butterknife/ - */ - const val butterknife_gradle_plugin: String = "com.jakewharton:butterknife-gradle-plugin:" + - Versions.com_jakewharton - /** * https://developer.android.com/testing */ diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index e5790a5d15..4f8580b023 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -22,13 +22,13 @@ object Versions { const val com_squareup_okhttp3: String = "4.9.0" - const val org_jetbrains_kotlin: String = "1.7.0" + const val org_jetbrains_kotlin: String = "1.9.20" const val androidx_navigation: String = "2.5.3" const val navigation_ui_ktx: String = "2.4.1" - const val com_google_dagger: String = "2.42" + const val com_google_dagger: String = "2.48.1" const val com_jakewharton: String = "10.2.3" diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index 2dbb1ed090..f3304443d8 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -219,8 +219,6 @@ class AllProjectConfigurer { implementation(Libs.core_ktx) implementation(Libs.fragment_ktx) implementation(Libs.collection_ktx) - implementation(Libs.butterknife) - kapt(Libs.butterknife_compiler) implementation(Libs.fetch) implementation(Libs.rxandroid) implementation(Libs.rxjava) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt index 550ac5eda3..26c863d176 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt @@ -18,10 +18,7 @@ package org.kiwix.kiwixmobile.core.base import android.os.Bundle -import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity -import butterknife.ButterKnife -import butterknife.Unbinder import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.di.components.CoreComponent import org.kiwix.kiwixmobile.core.utils.LanguageUtils @@ -33,8 +30,6 @@ abstract class BaseActivity : AppCompatActivity() { @Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil - private var unbinder: Unbinder? = null - protected abstract fun injection(coreComponent: CoreComponent) override fun onCreate(savedInstanceState: Bundle?) { @@ -42,14 +37,4 @@ abstract class BaseActivity : AppCompatActivity() { super.onCreate(savedInstanceState) LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil) } - - override fun setContentView(@LayoutRes layoutResID: Int) { - super.setContentView(layoutResID) - unbinder = ButterKnife.bind(this) - } - - override fun onDestroy() { - super.onDestroy() - unbinder?.unbind() - } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 7c25461f96..30ad5d8945 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -83,11 +83,6 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver -import butterknife.BindView -import butterknife.ButterKnife -import butterknife.OnClick -import butterknife.OnLongClick -import butterknife.Unbinder import com.google.android.material.appbar.AppBarLayout import com.google.android.material.bottomappbar.BottomAppBar import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -102,12 +97,12 @@ import org.json.JSONException import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.NightModeConfig import org.kiwix.kiwixmobile.core.R -import org.kiwix.kiwixmobile.core.R2 import org.kiwix.kiwixmobile.core.StorageObserver import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookmarksDao +import org.kiwix.kiwixmobile.core.databinding.FragmentReaderBinding import org.kiwix.kiwixmobile.core.downloader.fetch.DOWNLOAD_NOTIFICATION_TITLE import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.consumeObservable import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.hasNotificationPermission @@ -179,51 +174,52 @@ abstract class CoreReaderFragment : NavigationHistoryClickListener { protected val webViewList: MutableList = ArrayList() private val webUrlsProcessor = BehaviorProcessor.create() + private var fragmentReaderBinding: FragmentReaderBinding? = null - @JvmField - @BindView(R2.id.toolbar) - var toolbar: Toolbar? = null + val toolbar: Toolbar? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.toolbar) + } - @JvmField - @BindView(R2.id.fragment_main_app_bar) - var toolbarContainer: AppBarLayout? = null + val toolbarContainer: AppBarLayout? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.fragment_main_app_bar) + } - @JvmField - @BindView(R2.id.main_fragment_progress_view) - var progressBar: ContentLoadingProgressBar? = null + val progressBar: ContentLoadingProgressBar? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.main_fragment_progress_view) + } - @JvmField - @BindView(R2.id.navigation_fragment_main_drawer_layout) - var drawerLayout: DrawerLayout? = null + val drawerLayout: DrawerLayout? by lazy { + fragmentReaderBinding?.navigationFragmentMainDrawerLayout + } protected var tableDrawerRightContainer: NavigationView? = null - @JvmField - @BindView(R2.id.activity_main_content_frame) - var contentFrame: FrameLayout? = null + val contentFrame: FrameLayout? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_content_frame) + } - @JvmField - @BindView(R2.id.bottom_toolbar) - var bottomToolbar: BottomAppBar? = null + val bottomToolbar: BottomAppBar? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar) + } - @JvmField - @BindView(R2.id.activity_main_tab_switcher) - var tabSwitcherRoot: View? = null + val tabSwitcherRoot: View? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_tab_switcher) + } - @JvmField - @BindView(R2.id.tab_switcher_close_all_tabs) - var closeAllTabsButton: FloatingActionButton? = null + val closeAllTabsButton: FloatingActionButton? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.tab_switcher_close_all_tabs) + } - @JvmField - @BindView(R2.id.fullscreen_video_container) - var videoView: ViewGroup? = null + val videoView: ViewGroup? by lazy { + fragmentReaderBinding?.fullscreenVideoContainer + } - @JvmField - @BindView(R2.id.go_to_library_button_no_open_book) - var noOpenBookButton: Button? = null + val noOpenBookButton: Button? by lazy { + fragmentReaderBinding?.goToLibraryButtonNoOpenBook + } - @JvmField - @BindView(R2.id.activity_main_root) - var activityMainRoot: View? = null + val activityMainRoot: View? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_root) + } @JvmField @Inject @@ -260,49 +256,57 @@ abstract class CoreReaderFragment : protected var actionBar: ActionBar? = null protected var mainMenu: MainMenu? = null - @JvmField - @BindView(R2.id.activity_main_back_to_top_fab) - var backToTopButton: FloatingActionButton? = null + val backToTopButton: FloatingActionButton? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_back_to_top_fab) + } - @JvmField - @BindView(R2.id.activity_main_button_stop_tts) - var stopTTSButton: Button? = null + val stopTTSButton: Button? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_button_stop_tts) + } - @JvmField - @BindView(R2.id.activity_main_button_pause_tts) - var pauseTTSButton: Button? = null + val pauseTTSButton: Button? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_button_pause_tts) + } - @JvmField - @BindView(R2.id.activity_main_tts_controls) - var ttsControls: Group? = null + val ttsControls: Group? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_tts_controls) + } - @JvmField - @BindView(R2.id.activity_main_fullscreen_button) - var exitFullscreenButton: ImageButton? = null + val exitFullscreenButton: ImageButton? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.activity_main_fullscreen_button) + } - @JvmField - @BindView(R2.id.bottom_toolbar_bookmark) - var bottomToolbarBookmark: ImageView? = null + val bottomToolbarBookmark: ImageView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar_bookmark) + } - @JvmField - @BindView(R2.id.bottom_toolbar_arrow_back) - var bottomToolbarArrowBack: ImageView? = null + val bottomToolbarArrowBack: ImageView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar_arrow_back) + } - @JvmField - @BindView(R2.id.bottom_toolbar_arrow_forward) - var bottomToolbarArrowForward: ImageView? = null + val bottomToolbarArrowForward: ImageView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar_arrow_forward) + } - @JvmField - @BindView(R2.id.tab_switcher_recycler_view) - var tabRecyclerView: RecyclerView? = null + val bottomToolbarHome: ImageView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar_home) + } - @JvmField - @BindView(R2.id.snackbar_root) - var snackBarRoot: CoordinatorLayout? = null + val tabRecyclerView: RecyclerView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.tab_switcher_recycler_view) + } - @JvmField - @BindView(R2.id.no_open_book_text) - var noOpenBookText: TextView? = null + val snackBarRoot: CoordinatorLayout? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.snackbar_root) + } + + val noOpenBookText: TextView? by lazy { + fragmentReaderBinding?.noOpenBookText + } + + val bottomToolbarToc: ImageView? by lazy { + fragmentReaderBinding?.root?.findViewById(R.id.bottom_toolbar_toc) + } @JvmField @Inject @@ -335,7 +339,6 @@ abstract class CoreReaderFragment : private var tabCallback: ItemTouchHelper.Callback? = null private var bookmarkingDisposable: Disposable? = null private var isBookmarked = false - private var unbinder: Unbinder? = null private lateinit var serviceConnection: ServiceConnection private var readAloudService: ReadAloudService? = null private var navigationHistoryList: MutableList = ArrayList() @@ -516,6 +519,53 @@ abstract class CoreReaderFragment : viewLifecycleOwner, Observer(::openSearchItem) ) + backToTopButton?.setOnClickListener { + backToTop() + } + stopTTSButton?.setOnClickListener { + stopTts() + } + pauseTTSButton?.setOnClickListener { + pauseTts() + } + exitFullscreenButton?.setOnClickListener { + closeFullScreen() + } + bottomToolbarBookmark?.apply { + setOnClickListener { + toggleBookmark() + } + setOnLongClickListener { + goToBookmarks() + } + } + bottomToolbarArrowBack?.apply { + setOnClickListener { + goBack() + } + setOnLongClickListener { + showBackwardHistory() + true + } + } + bottomToolbarArrowForward?.apply { + setOnClickListener { + goForward() + } + setOnLongClickListener { + showForwardHistory() + true + } + } + bottomToolbarToc?.setOnClickListener { + openToc() + } + closeAllTabsButton?.setOnClickListener { + closeAllTabs() + } + bottomToolbarHome?.setOnClickListener { + openMainPage() + } } private fun initTabCallback() { @@ -575,9 +625,8 @@ abstract class CoreReaderFragment : container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val root = inflater.inflate(R.layout.fragment_reader, container, false) - unbinder = ButterKnife.bind(this, root) - return root + fragmentReaderBinding = FragmentReaderBinding.inflate(inflater, container, false) + return fragmentReaderBinding?.root } private fun handleIntentExtras(intent: Intent) { @@ -798,19 +847,18 @@ abstract class CoreReaderFragment : drawerLayout?.setDrawerLockMode(lockMode) } - @OnClick(R2.id.bottom_toolbar_arrow_back) fun goBack() { + fun goBack() { if (getCurrentWebView()?.canGoBack() == true) { getCurrentWebView()?.goBack() } } - @OnClick(R2.id.bottom_toolbar_arrow_forward) fun goForward() { + fun goForward() { if (getCurrentWebView()?.canGoForward() == true) { getCurrentWebView()?.goForward() } } - @OnLongClick(R2.id.bottom_toolbar_arrow_back) fun showBackwardHistory() { if (getCurrentWebView()?.canGoBack() == true) { getCurrentWebView()?.copyBackForwardList()?.let { historyList -> @@ -826,7 +874,6 @@ abstract class CoreReaderFragment : } } - @OnLongClick(R2.id.bottom_toolbar_arrow_forward) fun showForwardHistory() { if (getCurrentWebView()?.canGoForward() == true) { getCurrentWebView()?.copyBackForwardList()?.let { historyList -> @@ -903,7 +950,6 @@ abstract class CoreReaderFragment : } } - @OnClick(R2.id.bottom_toolbar_toc) fun openToc() { drawerLayout?.openDrawer(GravityCompat.END) } @@ -1023,7 +1069,6 @@ abstract class CoreReaderFragment : } } - @OnClick(R2.id.activity_main_button_pause_tts) fun pauseTts() { if (tts?.currentTTSTask == null) { tts?.stop() @@ -1043,7 +1088,6 @@ abstract class CoreReaderFragment : } } - @OnClick(R2.id.activity_main_button_stop_tts) fun stopTts() { tts?.stop() setActionAndStartTTSService(ACTION_STOP_TTS) @@ -1074,7 +1118,6 @@ abstract class CoreReaderFragment : tabRecyclerView?.adapter = null tableDrawerRight?.adapter = null tableDrawerAdapter = null - unbinder?.unbind() webViewList.clear() tempWebViewListForUndo.clear() // create a base Activity class that class this. @@ -1383,7 +1426,6 @@ abstract class CoreReaderFragment : return isPermissionGranted } - @OnLongClick(R2.id.bottom_toolbar_bookmark) fun goToBookmarks(): Boolean { val parentActivity = requireActivity() as CoreMainActivity parentActivity.navigate(parentActivity.bookmarksFragmentResId) @@ -1415,7 +1457,6 @@ abstract class CoreReaderFragment : } @Suppress("MagicNumber") - @OnClick(R2.id.activity_main_fullscreen_button) open fun closeFullScreen() { toolbarContainer?.visibility = View.VISIBLE updateBottomToolbarVisibility() @@ -1568,7 +1609,6 @@ abstract class CoreReaderFragment : } } - @OnClick(R2.id.tab_switcher_close_all_tabs) fun closeAllTabs() { closeAllTabsButton?.rotate() tempZimFileForUndo = zimReaderContainer?.zimFile @@ -1628,7 +1668,6 @@ abstract class CoreReaderFragment : } @Suppress("NestedBlockDepth") - @OnClick(R2.id.bottom_toolbar_bookmark) fun toggleBookmark() { getCurrentWebView()?.url?.let { articleUrl -> if (isBookmarked) { @@ -1806,7 +1845,6 @@ abstract class CoreReaderFragment : openArticle(articleUrl) } - @OnClick(R2.id.bottom_toolbar_home) fun openMainPage() { val articleUrl = zimReaderContainer?.mainPage openArticle(articleUrl) @@ -1818,7 +1856,6 @@ abstract class CoreReaderFragment : } } - @OnClick(R2.id.activity_main_back_to_top_fab) fun backToTop() { getCurrentWebView()?.pageUp(true) }