Skip to content

Commit

Permalink
Fixed CI and lint failure
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Feb 2, 2023
1 parent 8505b40 commit 67fbbc2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* Copyright (c) 2023 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
Expand All @@ -16,7 +16,7 @@
*
*/

package org.kiwix.kiwixmobile.core.utils
package org.kiwix.kiwixmobile.utils

import android.app.Activity
import android.content.Intent
Expand All @@ -31,6 +31,8 @@ import io.mockk.verify
import org.junit.jupiter.api.Test
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
import java.net.URL
Expand All @@ -42,7 +44,7 @@ internal class ExternalLinkOpenerTest {
private val activity: Activity = mockk()

@Test
internal fun `alertDialogShower opens link if confirm-button is clicked`() {
internal fun alertDialogShowerOpensLinkIfConfirmButtonIsClicked() {
every { intent.resolveActivity(activity.packageManager) } returns mockk()
every { sharedPreferenceUtil.prefExternalLinkPopup } returns true
val url = URL("https://github.com/")
Expand All @@ -63,7 +65,7 @@ internal class ExternalLinkOpenerTest {
}

@Test
internal fun `alertDialogShower does not open link if negative-button is clicked`() {
internal fun alertDialogShowerDoesNoOpenLinkIfNegativeButtonIsClicked() {
every { intent.resolveActivity(activity.packageManager) } returns mockk()
every { sharedPreferenceUtil.prefExternalLinkPopup } returns true
every { intent.data } returns Uri.parse("https://github.com/")
Expand All @@ -83,7 +85,7 @@ internal class ExternalLinkOpenerTest {
}

@Test
internal fun `alertDialogShower opens link and saves preferences if neutral-button is clicked`() {
internal fun alertDialogShowerOpensLinkAndSavesPreferencesIfNeutralButtonIsClicked() {
every { intent.resolveActivity(activity.packageManager) } returns mockk()
every { sharedPreferenceUtil.prefExternalLinkPopup } returns true
every { intent.data } returns Uri.parse("https://github.com/")
Expand All @@ -106,7 +108,7 @@ internal class ExternalLinkOpenerTest {
}

@Test
internal fun `intent is started if external link popup preference is false`() {
internal fun intentIsStartedIfExternalLinkPopupPreferenceIsFalse() {
every { intent.resolveActivity(activity.packageManager) } returns mockk()
every { sharedPreferenceUtil.prefExternalLinkPopup } returns false
val externalLinkOpener = ExternalLinkOpener(activity, sharedPreferenceUtil, alertDialogShower)
Expand All @@ -115,7 +117,7 @@ internal class ExternalLinkOpenerTest {
}

@Test
internal fun `toast if packageManager is null`() {
internal fun toastIfPackageManagerIsNull() {
every { intent.resolveActivity(activity.packageManager) } returns null
val externalLinkOpener = ExternalLinkOpener(activity, sharedPreferenceUtil, alertDialogShower)
mockkStatic(Toast::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.kiwix.kiwixmobile.core.utils.dialog

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.ClipData
Expand All @@ -29,20 +30,22 @@ import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import org.kiwix.kiwixmobile.core.R
import java.net.URL
import javax.inject.Inject

@Suppress("MagicNumber")
class AlertDialogShower @Inject constructor(private val activity: Activity) :
DialogShower {
private val viewSpacingLeftForLink = 0
private val viewSpacingRightForLink = 0
private val viewSpacingTopForLink = 10
private val viewSpacingBottomForLink = 0
private val externalLinkLeftMargin = 0
private val externalLinkRightMargin = 0
private val externalLinkTopMargin = 10
private val externalLinkBottomMargin = 0

override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit, url: URL?) =
create(dialog, *clickListeners, url = url).show()

@SuppressLint("RestrictedApi")
override fun create(dialog: KiwixDialog, vararg clickListeners: () -> Unit, url: URL?): Dialog {
return AlertDialog.Builder(activity)
.apply {
Expand All @@ -66,7 +69,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
?.invoke()
}
}
if (url != null) {
url?.let {
val textView = TextView(activity.baseContext)
textView.setPadding(5, 5, 5, 5)
textView.gravity = Gravity.CENTER
Expand All @@ -78,7 +81,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
clipboard?.setPrimaryClip(clip)
Toast.makeText(
activity.baseContext,
"External Link Copied to Clipboard",
R.string.external_link_copied_message,
Toast.LENGTH_SHORT
).show()
true
Expand All @@ -87,10 +90,10 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :

setView(
textView,
viewSpacingLeftForLink,
viewSpacingTopForLink,
viewSpacingRightForLink,
viewSpacingBottomForLink
externalLinkLeftMargin,
externalLinkTopMargin,
externalLinkRightMargin,
externalLinkBottomMargin
)
}
dialog.getView?.let { setView(it()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface DialogShower {
dialog: KiwixDialog,
vararg clickListeners: (() -> Unit),
url: URL? = null

)

fun create(
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,5 @@
<string name="delete_selected_notes">Delete Selected Notes?</string>
<string name="download_tts_language_title">Download this language for read aloud feature</string>
<string name="download_tts_language_message">Please click the Download button. It will automatically download the required language.</string>
<string name="external_link_copied_message">External Link Copied to Clipboard</string>
</resources>

0 comments on commit 67fbbc2

Please sign in to comment.