mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Fixed the UnsafeCallOnNullableType
detekt issue in the project.
This commit is contained in:
parent
7493b842b7
commit
6e195fc42f
@ -49,6 +49,7 @@ import kotlin.math.min
|
||||
* We refactor this java file to kotlin file
|
||||
*/
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
class CustomPageIndicator @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@ -114,10 +115,10 @@ class CustomPageIndicator @JvmOverloads constructor(
|
||||
fun setViewPager(viewPager: ViewPager) {
|
||||
this.viewPager = viewPager
|
||||
viewPager.addOnPageChangeListener(this)
|
||||
setPageCount(viewPager.adapter!!.count)
|
||||
viewPager.adapter!!.registerDataSetObserver(object : DataSetObserver() {
|
||||
viewPager.adapter?.count?.let(::setPageCount)
|
||||
viewPager.adapter?.registerDataSetObserver(object : DataSetObserver() {
|
||||
override fun onChanged() {
|
||||
setPageCount(this@CustomPageIndicator.viewPager!!.adapter!!.count)
|
||||
this@CustomPageIndicator.viewPager?.adapter?.count?.let(::setPageCount)
|
||||
}
|
||||
})
|
||||
setCurrentPageImmediate()
|
||||
|
@ -46,7 +46,7 @@ class LanguageViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
compositeDisposable.addAll(
|
||||
actions.map { reduce(it, state.value!!) }
|
||||
actions.map { state.value?.let { value -> reduce(it, value) } }
|
||||
.distinctUntilChanged()
|
||||
.subscribe(state::postValue, Throwable::printStackTrace),
|
||||
languageDao.languages().filter { it.isNotEmpty() }
|
||||
|
@ -59,18 +59,21 @@ internal class SenderDevice(
|
||||
.forEachIndexed { fileIndex, fileItem ->
|
||||
try {
|
||||
Socket().use { socket ->
|
||||
context.contentResolver.openInputStream(fileItem?.fileUri!!).use { fileInputStream ->
|
||||
socket.bind(null)
|
||||
socket.connect(
|
||||
InetSocketAddress(hostAddress, WifiDirectManager.FILE_TRANSFER_PORT),
|
||||
TIME_OUT
|
||||
)
|
||||
Log.d(TAG, "Sender socket connected to server - " + socket.isConnected)
|
||||
publishProgress(fileIndex, FileItem.FileStatus.SENDING)
|
||||
val socketOutputStream = socket.getOutputStream()
|
||||
copyToOutputStream(fileInputStream!!, socketOutputStream)
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "Sender: Data written")
|
||||
publishProgress(fileIndex, FileItem.FileStatus.SENT)
|
||||
fileItem?.fileUri?.let {
|
||||
context.contentResolver.openInputStream(it).use { fileInputStream ->
|
||||
socket.bind(null)
|
||||
socket.connect(
|
||||
InetSocketAddress(hostAddress, WifiDirectManager.FILE_TRANSFER_PORT),
|
||||
TIME_OUT
|
||||
)
|
||||
Log.d(TAG, "Sender socket connected to server - " + socket.isConnected)
|
||||
publishProgress(fileIndex, FileItem.FileStatus.SENDING)
|
||||
val socketOutputStream = socket.getOutputStream()
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
copyToOutputStream(fileInputStream!!, socketOutputStream)
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "Sender: Data written")
|
||||
publishProgress(fileIndex, FileItem.FileStatus.SENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
|
@ -278,7 +278,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
}
|
||||
|
||||
private fun onRefreshStateChange(isRefreshing: Boolean?) {
|
||||
fragmentDestinationDownloadBinding?.librarySwipeRefresh?.isRefreshing = isRefreshing!!
|
||||
fragmentDestinationDownloadBinding?.librarySwipeRefresh?.isRefreshing = isRefreshing == true
|
||||
}
|
||||
|
||||
private fun onNetworkStateChange(networkState: NetworkState?) {
|
||||
@ -325,8 +325,10 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
}
|
||||
|
||||
private fun onLibraryItemsChange(it: List<LibraryListItem>?) {
|
||||
libraryAdapter.items = it!!
|
||||
if (it.isEmpty()) {
|
||||
if (it != null) {
|
||||
libraryAdapter.items = it
|
||||
}
|
||||
if (it?.isEmpty() == true) {
|
||||
fragmentDestinationDownloadBinding?.libraryErrorText?.setText(
|
||||
if (isNotConnected) R.string.no_network_connection
|
||||
else R.string.no_items_msg
|
||||
|
@ -262,6 +262,7 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
||||
restoreTabs(zimArticles, zimPositions, currentTab)
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
override fun createWebView(attrs: AttributeSet?): ToolbarScrollingKiwixWebView {
|
||||
return ToolbarScrollingKiwixWebView(
|
||||
requireContext(), this, attrs!!, activityMainRoot as ViewGroup, videoView!!,
|
||||
|
@ -68,11 +68,11 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
||||
showPermissionPreference()
|
||||
val externalStorageManager = Environment.isExternalStorageManager()
|
||||
if (externalStorageManager) {
|
||||
permissionPref!!.setSummary(org.kiwix.kiwixmobile.core.R.string.allowed)
|
||||
permissionPref?.setSummary(org.kiwix.kiwixmobile.core.R.string.allowed)
|
||||
} else {
|
||||
permissionPref!!.setSummary(org.kiwix.kiwixmobile.core.R.string.not_allowed)
|
||||
permissionPref?.setSummary(org.kiwix.kiwixmobile.core.R.string.not_allowed)
|
||||
}
|
||||
permissionPref.onPreferenceClickListener =
|
||||
permissionPref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
activity?.let(FragmentActivity::navigateToSettings)
|
||||
true
|
||||
@ -84,7 +84,7 @@ class KiwixPrefsFragment : CorePrefsFragment() {
|
||||
val preferenceCategory = findPreference<PreferenceCategory>(
|
||||
PREF_PERMISSION
|
||||
)
|
||||
preferenceCategory!!.isVisible = true
|
||||
preferenceCategory?.isVisible = true
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -358,6 +358,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
locale: Locale
|
||||
) = allLanguages.firstOrNull { it.languageCode == locale.isO3Language }?.active == true
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
private fun combineLibrarySources(
|
||||
booksOnFileSystem: List<BookOnDisk>,
|
||||
activeDownloads: List<DownloadModel>,
|
||||
|
@ -27,6 +27,7 @@ class AdapterDelegateManager<T> {
|
||||
delegates.put(delegates.size(), delegate)
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
fun createViewHolder(
|
||||
parent: ViewGroup,
|
||||
viewType: Int
|
||||
@ -36,7 +37,7 @@ class AdapterDelegateManager<T> {
|
||||
libraryListItem: T,
|
||||
holder: RecyclerView.ViewHolder
|
||||
) {
|
||||
delegates[holder.itemViewType]!!.bind(holder, libraryListItem)
|
||||
delegates[holder.itemViewType]?.bind(holder, libraryListItem)
|
||||
}
|
||||
|
||||
fun getViewTypeFor(item: T) = delegates.keyAt(getDelegateIndexFor(item))
|
||||
|
@ -75,6 +75,7 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||
box.remove(databaseId)
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
fun migrationInsert(books: List<Book>) {
|
||||
insert(books.map { BookOnDisk(book = it, file = it.file!!) })
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ open class DatabaseModule {
|
||||
var boxStore: BoxStore? = null
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
// NOT RECOMMENDED TODO use custom runner to load TestApplication
|
||||
@Provides @Singleton fun providesBoxStore(context: Context): BoxStore {
|
||||
if (boxStore == null) {
|
||||
|
@ -44,6 +44,7 @@ class DownloaderImpl @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
private fun urlProvider(book: Book): Observable<String> =
|
||||
if (book.url?.endsWith("meta4") == true) kiwixService.getMetaLinks(book.url!!)
|
||||
.map { it.relevantUrl.value }
|
||||
|
@ -63,7 +63,7 @@ open class ErrorActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
activityKiwixErrorBinding = ActivityKiwixErrorBinding.inflate(layoutInflater)
|
||||
setContentView(activityKiwixErrorBinding!!.root)
|
||||
setContentView(activityKiwixErrorBinding?.root)
|
||||
val extras = intent.extras
|
||||
exception = if (extras != null && safeContains(extras)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@ -134,7 +134,7 @@ open class ErrorActivity : BaseActivity() {
|
||||
private fun exceptionDetails(): String =
|
||||
"""
|
||||
Exception Details:
|
||||
${toStackTraceString(exception!!)}
|
||||
${exception?.let(::toStackTraceString)}
|
||||
""".trimIndent()
|
||||
|
||||
private fun zimFiles(): String {
|
||||
|
@ -610,16 +610,18 @@ abstract class CoreReaderFragment :
|
||||
}
|
||||
|
||||
private fun setupTabsAdapter() {
|
||||
tabsAdapter = TabsAdapter(
|
||||
requireActivity() as AppCompatActivity,
|
||||
webViewList,
|
||||
painter!!
|
||||
).apply {
|
||||
registerAdapterDataObserver(object : AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
mainMenu?.updateTabIcon(itemCount)
|
||||
}
|
||||
})
|
||||
tabsAdapter = painter?.let {
|
||||
TabsAdapter(
|
||||
requireActivity() as AppCompatActivity,
|
||||
webViewList,
|
||||
it
|
||||
).apply {
|
||||
registerAdapterDataObserver(object : AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
mainMenu?.updateTabIcon(itemCount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,7 +640,7 @@ abstract class CoreReaderFragment :
|
||||
override fun onSectionClick(view: View?, position: Int) {
|
||||
loadUrlWithCurrentWebview(
|
||||
"javascript:document.getElementById('" +
|
||||
documentSections!![position].id.replace("'", "\\'") +
|
||||
documentSections?.get(position)?.id?.replace("'", "\\'") +
|
||||
"').scrollIntoView();"
|
||||
)
|
||||
drawerLayout?.closeDrawers()
|
||||
@ -670,7 +672,7 @@ abstract class CoreReaderFragment :
|
||||
if (tabsAdapter.selected < webViewList.size &&
|
||||
recyclerView.layoutManager != null
|
||||
) {
|
||||
recyclerView.layoutManager!!.scrollToPosition(tabsAdapter.selected)
|
||||
recyclerView.layoutManager?.scrollToPosition(tabsAdapter.selected)
|
||||
}
|
||||
}
|
||||
// Notify the tabs adapter to update the UI when the tab switcher is shown
|
||||
@ -886,7 +888,8 @@ abstract class CoreReaderFragment :
|
||||
}
|
||||
|
||||
private fun getValidTitle(zimFileTitle: String?): String =
|
||||
if (isAdded && isInvalidTitle(zimFileTitle)) getString(R.string.app_name) else zimFileTitle!!
|
||||
if (isAdded && isInvalidTitle(zimFileTitle)) getString(R.string.app_name)
|
||||
else zimFileTitle.toString()
|
||||
|
||||
private fun isInvalidTitle(zimFileTitle: String?): Boolean =
|
||||
zimFileTitle == null || zimFileTitle.trim { it <= ' ' }.isEmpty()
|
||||
@ -1058,6 +1061,7 @@ abstract class CoreReaderFragment :
|
||||
return null
|
||||
}
|
||||
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
protected open fun createWebView(attrs: AttributeSet?): ToolbarScrollingKiwixWebView? {
|
||||
return if (activityMainRoot != null) {
|
||||
ToolbarScrollingKiwixWebView(
|
||||
@ -1739,10 +1743,10 @@ abstract class CoreReaderFragment :
|
||||
}
|
||||
|
||||
private fun searchForTitle(title: String?, openInNewTab: Boolean) {
|
||||
val articleUrl: String? = if (title!!.startsWith("A/")) {
|
||||
val articleUrl: String? = if (title?.startsWith("A/") == true) {
|
||||
title
|
||||
} else {
|
||||
zimReaderContainer?.getPageUrlFromTitle(title)
|
||||
title?.let { zimReaderContainer?.getPageUrlFromTitle(it) }
|
||||
}
|
||||
if (openInNewTab) {
|
||||
openArticleInNewTab(articleUrl)
|
||||
@ -1764,14 +1768,16 @@ abstract class CoreReaderFragment :
|
||||
}
|
||||
|
||||
protected open fun createMainMenu(menu: Menu?): MainMenu? =
|
||||
menuFactory?.create(
|
||||
menu!!,
|
||||
webViewList,
|
||||
urlIsValid(),
|
||||
menuClickListener = this,
|
||||
disableReadAloud = false,
|
||||
disableTabs = false
|
||||
)
|
||||
menu?.let {
|
||||
menuFactory?.create(
|
||||
it,
|
||||
webViewList,
|
||||
urlIsValid(),
|
||||
menuClickListener = this,
|
||||
disableReadAloud = false,
|
||||
disableTabs = false
|
||||
)
|
||||
}
|
||||
|
||||
protected fun urlIsValid(): Boolean = getCurrentWebView()?.url != null
|
||||
|
||||
@ -1851,6 +1857,7 @@ abstract class CoreReaderFragment :
|
||||
requireActivity()
|
||||
)
|
||||
)
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
getCurrentWebView()?.let {
|
||||
val history = HistoryItem(
|
||||
it.url!!,
|
||||
|
@ -66,7 +66,7 @@ abstract class PageViewModel<T : Page, S : PageState<T>>(
|
||||
}
|
||||
|
||||
private fun viewStateReducer(): Disposable =
|
||||
actions.map { reduce(it, state.value!!) }
|
||||
actions.map { state.value?.let { value -> reduce(it, value) } }
|
||||
.subscribe(state::postValue, Throwable::printStackTrace)
|
||||
|
||||
protected fun addDisposablesToCompositeDisposable() {
|
||||
|
@ -60,7 +60,7 @@ class RateDialogHandler @Inject constructor(
|
||||
fun checkForRateDialog(@IdRes iconResId: Int) {
|
||||
isFirstRun = sharedPreferenceUtil.prefIsFirstRun
|
||||
visitCounterPref = RateAppCounter(activity)
|
||||
tempVisitCount = visitCounterPref?.count!!
|
||||
tempVisitCount = visitCounterPref?.count ?: 0
|
||||
++tempVisitCount
|
||||
visitCounterPref?.count = tempVisitCount
|
||||
if (shouldShowRateDialog() && NetworkUtils.isNetworkAvailable(activity)) {
|
||||
|
@ -136,9 +136,9 @@ object FileUtils {
|
||||
null
|
||||
}
|
||||
} else if (uri.scheme != null) {
|
||||
if ("content".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
if ("content".equals(uri.scheme, ignoreCase = true)) {
|
||||
return contentQuery(context, uri)
|
||||
} else if ("file".equals(uri.scheme!!, ignoreCase = true)) {
|
||||
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
|
||||
return uri.path
|
||||
}
|
||||
} else {
|
||||
|
@ -59,7 +59,9 @@ class CustomDownloadViewModel @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private fun reducer() = actions.map { reduce(it, state.value!!) }
|
||||
private fun reducer() = actions.map {
|
||||
state.value?.let { value -> reduce(it, value) }
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.subscribe(state::postValue, Throwable::printStackTrace)
|
||||
|
||||
|
@ -76,7 +76,7 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
toolbarToc?.isEnabled = false
|
||||
}
|
||||
with(activity as AppCompatActivity) {
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
toolbar?.let { setupDrawerToggle(it) }
|
||||
}
|
||||
loadPageFromNavigationArguments()
|
||||
@ -187,14 +187,16 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
}
|
||||
|
||||
override fun createMainMenu(menu: Menu?): MainMenu? {
|
||||
return menuFactory?.create(
|
||||
menu!!,
|
||||
webViewList,
|
||||
urlIsValid(),
|
||||
this,
|
||||
BuildConfig.DISABLE_READ_ALOUD,
|
||||
BuildConfig.DISABLE_TABS
|
||||
)
|
||||
return menu?.let {
|
||||
menuFactory?.create(
|
||||
it,
|
||||
webViewList,
|
||||
urlIsValid(),
|
||||
this,
|
||||
BuildConfig.DISABLE_READ_ALOUD,
|
||||
BuildConfig.DISABLE_TABS
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showOpenInNewTabDialog(url: String) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user