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