mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
fixes codefactor issues
This commit is contained in:
parent
f474cc21f9
commit
bc98a335b6
@ -109,6 +109,7 @@ class NetworkTest {
|
||||
try {
|
||||
Espresso.onView(ViewMatchers.withId(android.R.id.button1)).perform(ViewActions.click())
|
||||
} catch (e: RuntimeException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
clickOn(R.string.local_zims)
|
||||
try {
|
||||
|
@ -276,8 +276,7 @@ class CustomPageIndicator @JvmOverloads constructor(
|
||||
dotRevealFraction: Float
|
||||
): Path {
|
||||
unselectedDotPath.rewind()
|
||||
if ((joiningFraction == selectedFactor || joiningFraction == INVALID_FRACTION)
|
||||
) {
|
||||
if (joiningFraction == selectedFactor || joiningFraction == INVALID_FRACTION) {
|
||||
if (dotRevealFraction == selectedFactor && !(page == currentPage && selectedDotInPosition)) {
|
||||
// case #1 – At rest
|
||||
unselectedDotPath.addCircle(dotCenterX!![page], dotCenterY, dotRadius, Path.Direction.CW)
|
||||
|
@ -39,9 +39,8 @@ class ZimHostPresenter @Inject internal constructor(private val dataSource: Data
|
||||
books
|
||||
.filterIsInstance<BooksOnDiskListItem.BookOnDisk>()
|
||||
.forEach {
|
||||
it.isSelected = (
|
||||
it.isSelected =
|
||||
previouslyHostedBooks.contains(it.book.title) || previouslyHostedBooks.isEmpty()
|
||||
)
|
||||
}
|
||||
books
|
||||
}.subscribe(object : SingleObserver<List<BooksOnDiskListItem>> {
|
||||
|
@ -75,7 +75,7 @@ class AppConfigurer {
|
||||
applicationVariants.all {
|
||||
outputs.filterIsInstance<ApkVariantOutput>().forEach { output: ApkVariantOutput ->
|
||||
val abiVersionCode = abiCodes[output.getFilter(VariantOutput.FilterType.ABI)] ?: 7
|
||||
output.versionCodeOverride = (abiVersionCode * 1_000_000) + output.versionCode
|
||||
output.versionCodeOverride = abiVersionCode * 1_000_000 + output.versionCode
|
||||
if (output.outputFileName.contains("universal-nightly")) {
|
||||
// this is for issue https://github.com/kiwix/kiwix-android/issues/3103
|
||||
output.outputFileName = setNameForNightlyUniversalApk()
|
||||
|
@ -36,16 +36,19 @@ inline class Seconds(val seconds: Long) {
|
||||
context.getString(R.string.time_day),
|
||||
context.getString(R.string.time_left)
|
||||
)
|
||||
|
||||
(seconds / hours).roundToLong() > 0 -> String.format(
|
||||
Locale.getDefault(), "%d %s %s", (seconds / hours).roundToLong(),
|
||||
context.getString(R.string.time_hour),
|
||||
context.getString(R.string.time_left)
|
||||
)
|
||||
((seconds / minutes).roundToLong() > 0) -> String.format(
|
||||
|
||||
(seconds / minutes).roundToLong() > 0 -> String.format(
|
||||
Locale.getDefault(), "%d %s %s", (seconds / minutes).roundToLong(),
|
||||
context.getString(R.string.time_minute),
|
||||
context.getString(R.string.time_left)
|
||||
)
|
||||
|
||||
else -> String.format(
|
||||
Locale.getDefault(), "%d %s %s", seconds,
|
||||
context.getString(R.string.time_second),
|
||||
|
@ -500,10 +500,9 @@ abstract class CoreReaderFragment :
|
||||
|
||||
private fun handleIntentExtras(intent: Intent) {
|
||||
if (intent.hasExtra(TAG_FILE_SEARCHED)) {
|
||||
val openInNewTab = (
|
||||
val openInNewTab =
|
||||
isInTabSwitcher ||
|
||||
intent.getBooleanExtra(TAG_FILE_SEARCHED_NEW_TAB, false)
|
||||
)
|
||||
searchForTitle(
|
||||
intent.getStringExtra(TAG_FILE_SEARCHED),
|
||||
openInNewTab
|
||||
|
@ -72,8 +72,6 @@ open class OnSwipeTouchListener constructor(context: Context) : OnTouchListener
|
||||
} else if (abs(diffY) > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||
if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
} else {
|
||||
onSwipeTop()
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -86,7 +84,6 @@ open class OnSwipeTouchListener constructor(context: Context) : OnTouchListener
|
||||
|
||||
open fun onSwipeRight() {}
|
||||
open fun onSwipeLeft() {}
|
||||
fun onSwipeTop() {}
|
||||
open fun onSwipeBottom() {}
|
||||
open fun onTap(e: MotionEvent?) {}
|
||||
}
|
||||
|
@ -38,5 +38,5 @@ data class HistoryState(
|
||||
)
|
||||
|
||||
override fun copyWithNewItems(newItems: List<HistoryItem>): PageState<HistoryItem> =
|
||||
copy(pageItems = (newItems))
|
||||
copy(pageItems = newItems)
|
||||
}
|
||||
|
@ -60,7 +60,14 @@ class ZimSearchResultGenerator @Inject constructor() : SearchResultGenerator {
|
||||
|
||||
private suspend fun <T> createList(readSearchResult: suspend () -> T?): List<T> {
|
||||
return mutableListOf<T>().apply {
|
||||
while (true) readSearchResult()?.let(::add) ?: break
|
||||
while (true) {
|
||||
val result = readSearchResult()
|
||||
if (result != null) {
|
||||
add(result)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,9 @@ inline class KiloByte(private val kilobyteString: String?) {
|
||||
get() = kilobyteString?.toLongOrNull()?.let {
|
||||
val units = arrayOf("KB", "MB", "GB", "TB")
|
||||
val conversion = (log10(it.toDouble()) / log10(1024.0)).toInt()
|
||||
(
|
||||
DecimalFormat("#,##0.#")
|
||||
.format(it / 1024.0.pow(conversion.toDouble())) +
|
||||
" " +
|
||||
units[conversion]
|
||||
)
|
||||
} ?: ""
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ sealed class BookOnDiskDelegate<I : BooksOnDiskListItem, out VH : BookOnDiskView
|
||||
viewHolder: ViewHolder,
|
||||
itemToBind: BooksOnDiskListItem
|
||||
) {
|
||||
(viewHolder as BookViewHolder).bind((itemToBind as BookOnDisk), selectionMode)
|
||||
(viewHolder as BookViewHolder).bind(itemToBind as BookOnDisk, selectionMode)
|
||||
}
|
||||
|
||||
override fun createViewHolder(parent: ViewGroup) =
|
||||
|
@ -53,7 +53,7 @@ sealed class BookOnDiskViewHolder<in T : BooksOnDiskListItem>(containerView: Vie
|
||||
itemBookBinding.itemBookTitle.text = book.title
|
||||
itemBookBinding.itemBookDate.text = book.date
|
||||
itemBookBinding.itemBookDescription.text = book.description
|
||||
itemBookBinding.itemBookSize.text = (KiloByte(book.size).humanReadable)
|
||||
itemBookBinding.itemBookSize.text = KiloByte(book.size).humanReadable
|
||||
book.articleCount?.let {
|
||||
itemBookBinding.itemBookArticleCount.text =
|
||||
ArticleCount(it).toHumanReadable(containerView.context)
|
||||
|
@ -46,39 +46,39 @@ class NetworkUtilsTest {
|
||||
every { connectivity.allNetworkInfo } returns networkInfos
|
||||
|
||||
// one network is connected
|
||||
every { (networkInfo1.state) } returns NetworkInfo.State.CONNECTED
|
||||
every { (networkInfo2.state) } returns NetworkInfo.State.DISCONNECTING
|
||||
every { networkInfo1.state } returns NetworkInfo.State.CONNECTED
|
||||
every { networkInfo2.state } returns NetworkInfo.State.DISCONNECTING
|
||||
assertEquals(true, NetworkUtils.isNetworkAvailable(context))
|
||||
|
||||
every { (networkInfo1.state) } returns NetworkInfo.State.DISCONNECTING
|
||||
every { (networkInfo2.state) } returns NetworkInfo.State.CONNECTING
|
||||
every { networkInfo1.state } returns NetworkInfo.State.DISCONNECTING
|
||||
every { networkInfo2.state } returns NetworkInfo.State.CONNECTING
|
||||
assertEquals(false, NetworkUtils.isNetworkAvailable(context))
|
||||
|
||||
// no network is available
|
||||
every { (networkInfo1.state) } returns NetworkInfo.State.DISCONNECTED
|
||||
every { (networkInfo2.state) } returns NetworkInfo.State.DISCONNECTED
|
||||
every { networkInfo1.state } returns NetworkInfo.State.DISCONNECTED
|
||||
every { networkInfo2.state } returns NetworkInfo.State.DISCONNECTED
|
||||
assertEquals(false, NetworkUtils.isNetworkAvailable(context))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_isNetworkConnectionOK() {
|
||||
every { (networkInfo2.state) } returns NetworkInfo.State.CONNECTING
|
||||
every { networkInfo2.state } returns NetworkInfo.State.CONNECTING
|
||||
assertFalse(NetworkUtils.isNetworkConnectionOK(networkInfo2))
|
||||
|
||||
every { (networkInfo2.state) } returns NetworkInfo.State.CONNECTED
|
||||
every { networkInfo2.state } returns NetworkInfo.State.CONNECTED
|
||||
assertTrue(NetworkUtils.isNetworkConnectionOK(networkInfo2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWifiAvailability() {
|
||||
every { (context.getSystemService(Context.CONNECTIVITY_SERVICE)) } returns connectivity
|
||||
every { (connectivity.activeNetworkInfo) } returns networkInfo
|
||||
every { context.getSystemService(Context.CONNECTIVITY_SERVICE) } returns connectivity
|
||||
every { connectivity.activeNetworkInfo } returns networkInfo
|
||||
|
||||
// SDK >= 23
|
||||
NetworkUtils.sdkVersionForTesting = 23
|
||||
|
||||
// on Mobile Data
|
||||
every { (networkInfo.type) } returns ConnectivityManager.TYPE_MOBILE
|
||||
every { networkInfo.type } returns ConnectivityManager.TYPE_MOBILE
|
||||
assertEquals(false, NetworkUtils.isWiFi(context))
|
||||
// verify that the correct methods are used according to the build SDK version
|
||||
verify {
|
||||
@ -88,15 +88,15 @@ class NetworkUtilsTest {
|
||||
verify(exactly = 0) { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) }
|
||||
|
||||
// on WIFI connected
|
||||
every { (networkInfo.type) } returns ConnectivityManager.TYPE_WIFI
|
||||
every { (networkInfo.isConnected) } returns java.lang.Boolean.TRUE
|
||||
every { networkInfo.type } returns ConnectivityManager.TYPE_WIFI
|
||||
every { networkInfo.isConnected } returns java.lang.Boolean.TRUE
|
||||
assertEquals(true, NetworkUtils.isWiFi(context))
|
||||
verify(exactly = 2) { connectivity.activeNetworkInfo }
|
||||
verify(exactly = 0) { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) }
|
||||
|
||||
// on WIFI disconnected
|
||||
every { (networkInfo.type) } returns ConnectivityManager.TYPE_WIFI
|
||||
every { (networkInfo.isConnected) } returns java.lang.Boolean.FALSE
|
||||
every { networkInfo.type } returns ConnectivityManager.TYPE_WIFI
|
||||
every { networkInfo.isConnected } returns java.lang.Boolean.FALSE
|
||||
assertEquals(false, NetworkUtils.isWiFi(context))
|
||||
verify(exactly = 3) { connectivity.activeNetworkInfo }
|
||||
verify(exactly = 0) { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) }
|
||||
@ -105,14 +105,14 @@ class NetworkUtilsTest {
|
||||
NetworkUtils.sdkVersionForTesting = 22
|
||||
|
||||
// WIFI connected
|
||||
every { (connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI)) } returns networkInfo
|
||||
every { (networkInfo.isConnected) } returns true
|
||||
every { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) } returns networkInfo
|
||||
every { networkInfo.isConnected } returns true
|
||||
assertEquals(true, NetworkUtils.isWiFi(context))
|
||||
verify { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) }
|
||||
|
||||
// WIFI disconnected
|
||||
every { (connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI)) } returns networkInfo
|
||||
every { (networkInfo.isConnected) } returns false
|
||||
every { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) } returns networkInfo
|
||||
every { networkInfo.isConnected } returns false
|
||||
assertEquals(false, NetworkUtils.isWiFi(context))
|
||||
verify(exactly = 2) { connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI) }
|
||||
}
|
||||
@ -177,9 +177,9 @@ class NetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testParsedURL() {
|
||||
every { (context.getString(R.string.zim_no_pic)) } returns "No Pictures"
|
||||
every { (context.getString(R.string.zim_no_vid)) } returns "No Videos"
|
||||
every { (context.getString(R.string.zim_simple)) } returns "Simple"
|
||||
every { context.getString(R.string.zim_no_pic) } returns "No Pictures"
|
||||
every { context.getString(R.string.zim_no_vid) } returns "No Videos"
|
||||
every { context.getString(R.string.zim_simple) } returns "Simple"
|
||||
|
||||
assertEquals(
|
||||
"URL Parsing on empty string", "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user