path
stringlengths
4
297
contentHash
stringlengths
1
10
content
stringlengths
0
13M
CorouniteSample/app/src/main/java/com/example/corounitesample/Main.kt
2316781533
package com.example.corounitesample import android.widget.Toast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import java.util.Locale import kotlin.math.roundToInt val customCoroutineScope = CoroutineScope(Dispatchers.Default) fun main() { println("START MAIN") println("MAIN FUN") /* val values = listOf("А", "Б", "1", "2", "В", "3", "Г", "Д", "4", "5") val sortedValues = values.sortedWith(Comparator { a, b -> when { a.matches(Regex("[a-zA-Z]")) && b.matches(Regex("[0-9]")) -> -1 // буквенное значение идет перед числовым a.matches(Regex("[0-9]")) && b.matches(Regex("[a-zA-Z]")) -> 1 // числовое значение идет после буквенного else -> a.compareTo(b) // сортировка по умолчанию } }) println(sortedValues) */ // val strings = listOf("Привет", "Hello", "Мир", "World", "1", "2") // // val sortedStrings = strings.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.toLowerCase(Locale.getDefault()) }) // println(sortedStrings) customCoroutineScope.launch { (2..10).map { println("START $it") delay(100) getBasket() println("END $it") } } runBlocking { delay(2000) } } fun getBasket() = customCoroutineScope.launch { println("START GETBASKET") //delay(100) getPurchases() println("END GETBASKET") } suspend fun getPurchases() { // withContext(Dispatchers.IO) { println("START GETPURCHASES") (0..1).map { delay(50) println("PURCHASE $it") //getPurchasePrice(it.toString()) } println("END GETPURCHASES") // } } suspend fun getPurchasePrice(i: String) { println("START GETPURCHASEPRICE $i") savePurchase(i) println("END GETPURCHASEPRICE $i") } suspend fun savePurchase(i: String) { customCoroutineScope.launch(Dispatchers.IO) { println("START SAVEPURCHASE $i") delay(50) println("END SAVEPURCHASE $i") } } suspend fun coroutine() { customCoroutineScope.launch { println("start coroutine") suspendFuncWithDelay() println("end coroutine") } } suspend fun suspendFuncWithDelay() { println("start suspendFuncWithDelay") delay(100) println("end suspendFuncWithDelay") } private fun deviationVirtualTemperature(temperature: Double): Double { val map = mapOf(0..4 to 0.5, 5..9 to 0.5, 10..14 to 1.0, 15..24 to 1.0, 25..29 to 2.0, 30..39 to 3.5,) val interval = map.entries.find { temperature.roundToInt() in it.key }?.key val popravka = when (interval) { 0..4, 10..14 -> map[interval]!! 5..9, 15..24, 30..39, -> map[interval]!! + (temperature.roundToInt() - interval.first)*0.1 25..29 -> map[interval]!! + (temperature.roundToInt() - interval.first)*0.3 40..100 -> 4.5 else -> 0.0 } return temperature + popravka - 15.9 }
CorouniteSample/app/src/main/java/com/example/corounitesample/Deviation.kt
755316548
package com.example.corounitesample import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale import kotlin.math.atan2 import kotlin.math.cos import kotlin.math.pow import kotlin.math.roundToInt import kotlin.math.sin import kotlin.math.sqrt /* data class MeteoData(val pressure: Double, val height: Double, val temperature: Double, val humidity: Double, val averageMolecularWeight: Double, val windSpeed: Double, val windDirection: Double) fun interpolateMeteoData(targetHeight: Double, data1: MeteoData, data2: MeteoData): MeteoData { val fraction = (targetHeight - data1.height) / (data2.height - data1.height) return MeteoData( interpolate(data1.pressure, data2.pressure, fraction), targetHeight, interpolate(data1.temperature, data2.temperature, fraction), interpolate(data1.humidity, data2.humidity, fraction), interpolate(data1.averageMolecularWeight, data2.averageMolecularWeight, fraction), interpolate(data1.windSpeed, data2.windSpeed, fraction), interpolate(data1.windDirection, data2.windDirection, fraction) ) } fun interpolate(value1: Double, value2: Double, fraction: Double): Double { return value1 + fraction * (value2 - value1) } fun main() { val meteoDataList = listOf( MeteoData(1000.0, 108.0, -8.7, 74.0, 5621.0, 3.2, 0.0), MeteoData(975.0, 303.0, -10.7, 83.0, 5677.0, 5.2, 0.0), MeteoData(950.0, 502.0, -12.7, 93.0, 5700.0, 7.2, 31.0), MeteoData(925.0, 705.0, -13.8, 92.0, 118.0, 8.4, 33.0), MeteoData(900.0, 914.0, -12.6, 86.0, 288.0, 8.4, 14.0), MeteoData(850.0, 1353.0, -9.0, 91.0, 386.0, 5.5, 36.0), MeteoData(800.0, 1821.0, -9.6, 92.0, 571.0, 3.7, 45.0), MeteoData(700.0, 2845.0, -13.6, 76.0, 38.0, 7.5, 10.0), MeteoData(600.0, 4001.0, -20.5, 76.0, 5756.0, 3.6, 10.0), MeteoData(500.0, 5331.0, -27.8, 74.0, 3562.0, 6.6, 7.0), MeteoData(400.0, 6901.0, -38.5, 61.0, 3618.0, 10.0, 0.0), MeteoData(300.0, 8817.0, -52.5, 28.0, 3629.0, 12.8, 0.0), MeteoData(250.0, 9977.0, -58.0, 21.0, 3512.0, 16.4, 0.0), MeteoData(200.0, 11379.0, -58.5, 5.0, 3571.0, 17.6, 0.0), MeteoData(150.0, 13184.0, -59.0, 3.0, 3911.0, 15.9, 0.0), MeteoData(100.0, 15719.0, -60.8, 3.0, 4173.0, 13.5, 0.0), MeteoData(70.0, 17913.0, -65.0, 4.0, 4189.0, 17.8, 0.0), MeteoData(50.0, 19945.0, -68.4, 4.0, 4317.0, 24.0, 0.0), MeteoData(30.0, 23006.0, -69.8, 4.0, 4329.0, 29.0, 0.0) ) val targetHeights = listOf(0.0, 200.0, 400.0, 800.0, 1200.0, 1600.0, 2000.0, 2400.0, 3000.0, 4000.0, 5000.0, 6000.0, 8000.0, 10000.0, 12000.0, 14000.0, 18000.0, 22000.0, 26000.0, 30000.0) for (height in targetHeights) { val (data1, data2) = findClosestDataPoints(height, meteoDataList) val interpolatedData = interpolateMeteoData(height, data1, data2) println("На высоте $height м:") println("Давление: ${interpolatedData.pressure} гПа") println("Температура: ${interpolatedData.temperature} градусов Цельсия") println("Влажность: ${interpolatedData.humidity}%") println("Скорость ветра: ${interpolatedData.windSpeed} м/с") println("Направление ветра: ${interpolatedData.windDirection} градусов") println("-----------") } } fun findClosestDataPoints(targetHeight: Double, data: List<MeteoData>): Pair<MeteoData, MeteoData> { val sortedData = data.sortedBy { it.height } for (i in 0 until sortedData.size - 1) { val data1 = sortedData[i] val data2 = sortedData[i + 1] if (targetHeight >= data1.height && targetHeight <= data2.height) { return Pair(data1, data2) } } // Если не нашли точные данные для интерполяции, можно вернуть ближайшие return Pair(sortedData.last(), sortedData.first()) }*/
CorouniteSample/app/src/main/java/com/example/corounitesample/Zevs.kt
1609747460
package com.example.corounitesample import android.os.Build import androidx.annotation.RequiresApi import java.nio.ByteBuffer import java.text.SimpleDateFormat import java.time.LocalDateTime import java.time.ZoneId import java.util.Date import java.util.Locale import kotlin.math.E @RequiresApi(Build.VERSION_CODES.O) fun main() { // val knownHeight = 108 // высота в метрах // val knownTemperature = -8.7 // температура в градусах Цельсия // val knownWindDirection = 337 // направление ветра в градусах // val knownWindSpeed = 3.2 // скорость ветра в метрах в секунду // // // Высота, на которую нужно интерполировать данные // val targetHeight = 200 // высота в метрах // // // Гравитационный алгоритм для интерполяции температуры // val lapseRate = 0.0065 // адиабатический градиент // val deltaHeight = targetHeight - knownHeight // val targetTemperature = knownTemperature + lapseRate * deltaHeight // // // Интерполяция направления ветра // val deltaWindDirection = 0 // можно изменить в зависимости от данных // val targetWindDirection = knownWindDirection + deltaWindDirection // // // Интерполяция скорости ветра // val deltaWindSpeed = 0.0 // можно изменить в зависимости от данных // val targetWindSpeed = knownWindSpeed + deltaWindSpeed // // // Вывод результатов // println("На высоте $targetHeight м:") // println("Температура: $targetTemperature градусов Цельсия") // println("Направление ветра: $targetWindDirection градусов") // println("Скорость ветра: $targetWindSpeed м/с") //println(g().map { it.contentToString() }) //aaa() //sss() //m9g() //getHourlyList() println(test().convertToMeteo()) } data class MeteoTableData( val id: Int = 0, val B: Float, val L: Float, val time: String, val temperature: Double, val pressure: Double, val height: Double, val meteoAverage: List<MeteoData>, val state: MeteoTypes, val lastUpdate: String ) data class MeteoData( val height: Int, val dT: Int, val windDirection: Int, val windSpeed: Int, val type: MeteoTypes ) enum class MeteoTypes { AVERAGE, APPROXIMATE, UPDATED } fun ByteArray.convertToMeteo(): MeteoTableData { println("SIZE ${this.size}") val lat = this.copyOfRange(0, 4).toFloat() val lon = this.copyOfRange(4, 8).toFloat() val time = this.copyOfRange(8, 16).toLong() val temperature = this.copyOfRange(16, 20).toFloat() val pressure = this.copyOfRange(20, 24).toInt() val height = this.copyOfRange(24, 28).toInt() val meteoTable = mutableListOf<MeteoData>() (28..this.lastIndex step 4).map { println("STEP $it") meteoTable.add( MeteoData( this[it].toInt(), this[it+1].toInt(), this[it+2].toInt(), this[it+3].toInt(), type = MeteoTypes.AVERAGE ) ) } return MeteoTableData( B = lat, L = lon, time = convertMillisecondsToDateFormat(time), temperature = temperature.toDouble(), pressure = pressure.toDouble(), height = height.toDouble(), state = MeteoTypes.AVERAGE, lastUpdate = convertMillisecondsToDateFormat(time), meteoAverage = meteoTable.toList() ) } fun convertMillisecondsToDateFormat(milliseconds: Long): String { val dateFormat = SimpleDateFormat("dd.MM.yyyy-HH:mm:ss") val date = Date(milliseconds) return dateFormat.format(date) } fun test(): ByteArray { val data = "46.794044;19.079527;27.11.2023-10:19:54;1,2;760;0;0;64;39;3;2;63;44;5;4;62;46;7;8;61;48;10;12;61;48;12;16;61;49;12;20;61;49;12;24;61;49;13;30;61;50;14;40;61;50;15;50;61;51;17;60;61;51;19;80;61;52;24;10;61;53;28;12;60;52;29;14;59;52;29;18;59;52;29;22;59;51;29;26;59;51;29;30;59;51;29" val items = data.split(";") var byteArray = items[0].toFloat().toByteArray() + items[1].toFloat().toByteArray() + convertDateTimeToMilliseconds(items[2]).toByteArray() + items[3].replace(",", ".").toFloat().toByteArray() + items[4].toInt().toByteArray() + items[5].toInt().toByteArray() (6..items.lastIndex).map { byteArray += items[it].toInt().toByte() } return byteArray } fun convertDateTimeToMilliseconds(dateTime: String): Long { val format = SimpleDateFormat("dd.MM.yyyy-HH:mm:ss") val date = format.parse(dateTime) return date.time } fun Float.toByteArray(): ByteArray = ByteBuffer.allocate(Float.SIZE_BYTES).putFloat(this).array() fun Int.toByteArray(): ByteArray = ByteBuffer.allocate(Int.SIZE_BYTES).putInt(this).array() fun Long.toByteArray(): ByteArray = ByteBuffer.allocate(Long.SIZE_BYTES).putLong(this).array() fun Byte.toByteArray(): ByteArray = byteArrayOf(this) fun ByteArray.toFloat(): Float = ByteBuffer.wrap(this).float fun ByteArray.toInt(): Int = ByteBuffer.wrap(this).int fun ByteArray.toLong(): Long = ByteBuffer.wrap(this).long fun getHourlyList() { val list = mutableListOf<String>() val baseList = listOf( "temperature", "relative_humidity_2m", "precipitation", "weather_code","surface_pressure","cloud_cover", "cloud_cover_low","cloud_cover_mid","cloud_cover_high", "visibility","wind_speed_10m","wind_direction_10m") list.addAll(baseList) val heightList = listOf( "1000", "975", "950", "925", "900", "850", "700", "500", "400", "300", "250", "200", "150", "100", "70", "50", "30") val params = listOf("temperature_", "relative_humidity_", "cloud_cover_", "windspeed_", "winddirection_", "geopotential_height_") params.forEach {param -> heightList.forEach { height -> list.add(param+height+"hPa") } } println(list) } fun f(d3: Double): Double { return when { d3 < -2000.0 || d3 >= 9324.0 -> { if (d3 > 9324.0 && d3 <= 12000.0) { val pow = Math.pow(E, (0.1939 - Math.atan((12000.0 - d3) / 13750.0)) * -2.119) val d4 = 0.2923 pow * d4 } else if (d3 <= 12000.0) { 0.0 } else { val pow = Math.pow(E, (d3 - 12000.0) * -1.542E-4) val d4 = 0.1938 pow * d4 } } else -> Math.pow(1.0 - (d3 * 2.19E-5), 5.4) } } fun d(d3: Double): Double { return when { d3 < -2000.0 || d3 >= 9324.0 -> { when { d3 <= 9324.0 || d3 > 12000.0 -> if (d3 > 12000.0) 221.5 else 0.0 else -> { val d4 = d3 - 9324.0 (230.0 - (0.006328 * d4)) + (Math.pow(d4, 2.0) * 1.1718518518518518E-6) } } } else -> 288.9 - (d3 * 0.006328) } } fun aaa() { val f5042l1 = 700 val f5046m1 = -13.6 val f5050n1 = 76 val f5038k1 = 743 // Вычисление основной части температуры val baseTemperature = f5042l1 - (f(30000.0) * 750.0) // Вычисление параметров для расчета насыщенного давления водяного пара val saturationVaporPressure = Math.pow(E, (17.625 * f5046m1 + 243.04) / (f5046m1 + 273.0) * 6.1094) // Вычисление параметров для расчета относительной влажности val vaporPressure = f5046m1* 100.0 val saturationPressureCorrection = 0.378 * f5050n1 val relativeHumidity = ((f5050n1 * 0.622) / 100.0 * saturationVaporPressure) * (f5046m1 * 0.608) / (f5038k1 - (saturationPressureCorrection / 100.0) * saturationVaporPressure) // Вычисление параметров для расчета температуры точки росы val dewPointTemperature = (saturationVaporPressure * 4283.58 / Math.pow(f5046m1 + 243.04, 2.0) * (f5046m1 + 273.0) + 1.0) * vaporPressure - saturationPressureCorrection // Вычисление конечной температуры println((f5046m1 + relativeHumidity) - (d(30000.0) - 273.0)) } fun g(): Array<Array<String>> { val strArr = arrayOf( "0", "200", "400", "800", "1200", "1600", "2000", "2400", "3000", "4000", "5000", "6000", "8000", "10000", "12000", "14000", "18000", "22000", "26000", "30000" ) val strArr2 = Array(20) { Array(5) { "" } } for (i3 in 0 until 20) { strArr2[i3][0] = strArr[i3] val doubleValue = strArr[i3].toDouble() strArr2[i3][1] = String.format("%.3f", f(doubleValue) * (348.35562 / d(doubleValue))) strArr2[i3][2] = String.format("%.1f", f(doubleValue) * 750.0) strArr2[i3][3] = String.format("%.1f", d(doubleValue) - 273.0) strArr2[i3][4] = String.format("%.1f", Math.pow(d(doubleValue), 0.5) * 20.04679584) } return strArr2 } fun t(dArr: Array<DoubleArray>?): Array<DoubleArray>? { if (dArr == null) { return null } val dArr2 = Array(dArr.size) { DoubleArray(dArr[it].size) } for (i3 in dArr.indices) { val dArr3 = DoubleArray(dArr[i3].size) dArr2[i3] = dArr3 val dArr4 = dArr[i3] System.arraycopy(dArr4, 0, dArr3, 0, dArr4.size) } return dArr2 } val f5085w0 = SimpleDateFormat("DD", Locale.getDefault()).format(Date()).toInt() val f4983V0 = doubleArrayOf( 1000.0, 975.0, 950.0, 925.0, 900.0, 850.0, 800.0, 700.0, 600.0, 500.0, 400.0, 300.0, 250.0, 200.0, 150.0, 100.0, 70.0, 50.0, 30.0 ) val f4986W0 = doubleArrayOf( 0.0, 200.0, 400.0, 800.0, 1200.0, 1600.0, 2000.0, 2400.0, 3000.0, 4000.0, 5000.0, 6000.0, 8000.0, 10000.0, 12000.0, 14000.0, 18000.0, 22000.0, 26000.0, 30000.0 ) val geopotential_height_1000hPa = doubleArrayOf( 140.00, 139.00, 137.00, 135.00, 136.00, 137.00, 139.00, 139.00, 137.00, 138.00, 142.00, 146.00, 145.00, 144.00, 142.00, 142.00, 143.00, 142.00, 140.00, 138.00, 136.00, 138.00, 133.00, 130.00 ) val geopotential_height_975hPa = doubleArrayOf( 335.61, 334.61, 332.61, 330.61, 331.12, 332.12, 334.12, 334.12, 332.61, 333.61, 337.61, 341.61, 340.61, 339.61, 337.12, 337.61, 338.61, 337.61, 335.61, 334.11, 332.10, 333.61, 328.61, 325.12 ) val geopotential_height_950hPa = doubleArrayOf( 535.00, 534.00, 532.00, 530.00, 530.00, 531.00, 533.00, 533.00, 532.00, 533.00, 537.00, 541.00, 540.00, 539.00, 536.00, 537.00, 538.00, 537.00, 535.00, 534.00, 532.00, 533.00, 528.00, 524.00 ) val geopotential_height_925hPa = doubleArrayOf( 738.00, 737.00, 735.00, 733.00, 733.00, 734.00, 736.00, 735.00, 735.00, 736.00, 740.00, 744.00, 744.00, 742.00, 739.00, 740.00, 741.00, 740.00, 739.00, 737.00, 735.00, 736.00, 731.00, 728.00 ) val geopotential_height_900hPa = doubleArrayOf( 948.00, 946.00, 944.00, 942.00, 942.00, 943.00, 944.00, 944.00, 942.00, 943.00, 947.00, 951.00, 951.00, 950.00, 947.00, 947.00, 948.00, 948.00, 946.00, 945.00, 943.00, 944.00, 938.00, 935.00 ) val geopotential_height_850hPa = doubleArrayOf( 1388.00, 1386.00, 1383.00, 1381.00, 1382.00, 1382.00, 1384.00, 1383.00, 1381.00, 1381.00, 1384.00, 1387.00, 1386.00, 1384.00, 1381.00, 1381.00, 1381.00, 1380.00, 1378.00, 1376.00, 1373.00, 1374.00, 1369.00, 1367.00 ) val geopotential_height_800hPa = doubleArrayOf( 1855.00, 1853.00, 1850.00, 1847.00, 1847.00, 1848.00, 1850.00, 1848.00, 1846.00, 1845.00, 1847.00, 1849.00, 1848.00, 1845.00, 1840.00, 1840.00, 1839.00, 1838.00, 1836.00, 1833.00, 1829.00, 1829.00, 1825.00, 1823.00 ) val geopotential_height_700hPa = doubleArrayOf( 2871.00, 2867.00, 2865.00, 2862.00, 2861.00, 2861.00, 2862.00, 2859.00, 2856.00, 2853.00, 2854.00, 2855.00, 2852.00, 2848.00, 2842.00, 2840.00, 2839.00, 2836.00, 2832.00, 2827.00, 2822.00, 2821.00, 2817.00, 2816.00 ) val geopotential_height_600hPa = doubleArrayOf( 4016.00, 4011.00, 4009.00, 4006.00, 4005.00, 4005.00, 4006.00, 4004.00, 4000.00, 3997.00, 3997.00, 3997.00, 3993.00, 3988.00, 3981.00, 3977.00, 3975.00, 3972.00, 3968.00, 3962.00, 3956.00, 3955.00, 3950.00, 3950.00 ) val geopotential_height_500hPa = doubleArrayOf( 5323.00, 5318.00, 5314.00, 5311.00, 5311.00, 5312.00, 5313.00, 5311.00, 5307.00, 5304.00, 5303.00, 5303.00, 5298.00, 5292.00, 5284.00, 5280.00, 5278.00, 5275.00, 5271.00, 5266.00, 5260.00, 5260.00, 5257.00, 5257.00 ) val geopotential_height_400hPa = doubleArrayOf( 6867.90, 6860.49, 6855.56, 6853.09, 6853.09, 6854.32, 6855.56, 6853.09, 6849.38, 6844.44, 6841.98, 6840.74, 6834.57, 6827.16, 6817.28, 6813.58, 6811.11, 6809.88, 6806.17, 6801.23, 6797.53, 6800.00, 6797.53, 6801.23 ) val geopotential_height_300hPa = doubleArrayOf( 8775.81, 8767.74, 8761.29, 8756.45, 8753.23, 8751.61, 8751.61, 8746.77, 8741.94, 8735.48, 8732.26, 8730.65, 8724.19, 8717.74, 8709.68, 8706.45, 8706.45, 8706.45, 8704.84, 8703.23, 8703.23, 8709.68, 8712.90, 8722.58 ) val geopotential_height_250hPa = doubleArrayOf( 9935.24, 9927.62, 9920.00, 9914.29, 9912.38, 9910.48, 9912.38, 9910.48, 9906.67, 9902.86, 9900.95, 9900.95, 9897.14, 9893.33, 9887.62, 9887.62, 9889.52, 9891.43, 9889.52, 9889.52, 9889.52, 9897.14, 9900.95, 9908.57 ) val geopotential_height_200hPa = doubleArrayOf( 11344.19, 11339.54, 11334.88, 11327.91, 11327.91, 11327.91, 11332.56, 11332.56, 11327.91, 11325.58, 11325.58, 11327.91, 11325.58, 11325.58, 11323.26, 11325.58, 11327.91, 11330.23, 11330.23, 11330.23, 11332.56, 11339.54, 11341.86, 11346.51 ) val geopotential_height_150hPa = doubleArrayOf( 13167.16, 13164.18, 13158.21, 13149.25, 13149.25, 13152.24, 13158.21, 13155.22, 13152.24, 13149.25, 13155.22, 13158.21, 13158.21, 13158.21, 13158.21, 13158.21, 13164.18, 13170.15, 13170.15, 13170.15, 13173.13, 13179.10, 13182.09, 13188.06 ) val geopotential_height_100hPa = doubleArrayOf( 15700.00, 15691.67, 15683.33, 15679.17, 15683.33, 15687.50, 15691.67, 15687.50, 15683.33, 15687.50, 15691.67, 15695.83, 15700.00, 15695.83, 15695.83, 15695.83, 15704.17, 15708.33, 15708.33, 15712.50, 15716.67, 15725.00, 15725.00, 15733.33 ) val geopotential_height_70hPa = doubleArrayOf( 17879.78, 17868.85, 17863.39, 17863.39, 17863.39, 17868.85, 17874.32, 17868.85, 17868.85, 17868.85, 17874.32, 17879.78, 17885.25, 17885.25, 17879.78, 17885.25, 17890.71, 17896.18, 17896.18, 17907.10, 17907.10, 17912.57, 17918.03, 17928.96 ) val geopotential_height_50hPa = doubleArrayOf( 19903.45, 19896.55, 19889.66, 19889.66, 19889.66, 19896.55, 19896.55, 19896.55, 19896.55, 19896.55, 19903.45, 19910.35, 19917.24, 19910.35, 19903.45, 19910.35, 19924.14, 19931.04, 19937.93, 19937.93, 19937.93, 19944.83, 19951.72, 19958.62 ) val geopotential_height_30hPa = doubleArrayOf( 22943.93, 22934.58, 22934.58, 22925.23, 22925.23, 22925.23, 22925.23, 22934.58, 22934.58, 22934.58, 22943.93, 22943.93, 22943.93, 22943.93, 22943.93, 22953.27, 22962.62, 22971.96, 22971.96, 22971.96, 22971.96, 22981.31, 22981.31, 22990.66 ) val temperature_1000hPa = doubleArrayOf( -8.5, -8.6, -8.6, -8.4, -8.6, -8.7, -8.8, -8.7, -8.6, -8.4, -8.1, -8.1, -8.2, -8.4, -8.4, -8.4, -8.3, -8.2, -8.2, -8.1, -8.3, -8.5, -8.7, -8.9 ) val temperature_975hPa = doubleArrayOf( -10.3, -10.5, -10.5, -10.3, -10.5, -10.6, -10.7, -10.7, -10.6, -10.4, -10.1, -10.1, -10.2, -10.4, -10.4, -10.4, -10.2, -10.1, -10.1, -9.9, -10.0, -10.2, -10.5, -10.5 ) val temperature_950hPa = doubleArrayOf( -12.2, -12.3, -12.3, -12.2, -12.4, -12.5, -12.6, -12.7, -12.6, -12.4, -12.1, -12.1, -12.2, -12.4, -12.3, -12.3, -12.2, -12.0, -12.0, -11.8, -11.8, -12.0, -12.3, -12.1 ) val temperature_925hPa = doubleArrayOf( -13.0, -13.2, -13.6, -13.7, -14.0, -14.2, -14.3, -14.4, -14.4, -14.3, -14.1, -14.1, -14.1, -14.2, -14.1, -14.1, -14.0, -13.9, -13.9, -13.8, -13.6, -13.7, -13.9, -13.8 ) val temperature_900hPa = doubleArrayOf( -11.6, -11.9, -12.2, -12.2, -12.4, -12.5, -12.6, -12.8, -13.4, -14.0, -14.2, -14.2, -14.8, -14.8, -14.9, -15.1, -15.2, -15.7, -15.9, -15.7, -15.4, -15.5, -15.5, -15.6 ) val temperature_850hPa = doubleArrayOf( -9.5, -9.9, -10.0, -9.9, -9.9, -9.8, -10.0, -10.4, -11.0, -11.5, -11.7, -12.2, -12.7, -13.2, -13.5, -14.1, -14.5, -14.7, -14.8, -14.7, -14.8, -15.4, -15.2, -14.6 ) val temperature_800hPa = doubleArrayOf( -11.1, -11.4, -11.4, -11.5, -11.7, -11.9, -12.1, -12.2, -12.4, -12.7, -13.0, -13.5, -13.7, -14.6, -14.9, -15.3, -15.7, -15.9, -16.3, -17.0, -17.5, -17.5, -17.6, -17.4 ) val temperature_700hPa = doubleArrayOf( -16.0, -16.4, -16.4, -16.3, -16.1, -16.1, -16.0, -16.1, -16.3, -16.4, -16.4, -16.4, -16.7, -17.2, -18.1, -18.6, -19.0, -19.3, -19.6, -20.2, -20.8, -20.7, -20.5, -20.5 ) val temperature_600hPa = doubleArrayOf( -23.6, -23.6, -23.8, -23.8, -23.9, -23.8, -23.8, -23.6, -23.4, -23.6, -23.6, -23.8, -23.8, -23.9, -24.1, -24.3, -24.5, -24.5, -24.7, -24.7, -24.7, -24.5, -23.9, -23.8 ) val temperature_500hPa = doubleArrayOf( -32.0, -32.4, -32.7, -32.7, -32.7, -32.7, -32.9, -33.1, -33.4, -33.6, -33.6, -33.8, -33.8, -33.6, -33.6, -33.4, -33.4, -33.1, -33.1, -33.1, -32.9, -32.4, -32.4, -32.2 ) val temperature_400hPa = doubleArrayOf( -40.4, -40.4, -40.4, -40.4, -40.4, -40.7, -41.0, -41.4, -41.7, -41.7, -42.0, -42.3, -42.6, -43.3, -43.3, -43.3, -43.3, -43.0, -42.6, -42.6, -42.3, -42.0, -41.7, -40.7 ) val temperature_300hPa = doubleArrayOf( -53.0, -53.5, -53.5, -54.0, -54.0, -54.5, -54.0, -54.0, -54.0, -54.0, -53.5, -53.0, -53.0, -52.5, -52.0, -51.0, -50.5, -50.5, -51.0, -50.5, -50.0, -50.0, -49.0, -49.0 ) val temperature_250hPa = doubleArrayOf( -58.0, -57.5, -57.0, -57.0, -56.5, -56.5, -56.0, -56.0, -55.5, -55.5, -55.0, -54.5, -54.0, -53.5, -53.0, -52.5, -52.0, -52.0, -52.0, -51.5, -51.5, -51.5, -52.0, -52.0 ) val temperature_200hPa = doubleArrayOf( -56.5, -56.0, -56.0, -56.5, -56.5, -56.0, -56.0, -56.0, -56.0, -56.0, -55.5, -55.0, -54.5, -54.5, -54.0, -53.5, -54.0, -53.5, -53.0, -53.0, -53.0, -53.0, -53.0, -53.5 ) val temperature_150hPa = doubleArrayOf( -57.5, -57.5, -58.0, -58.0, -58.0, -57.5, -57.5, -57.5, -57.5, -57.0, -57.0, -56.5, -56.5, -56.5, -56.5, -57.0, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.0 ) val temperature_100hPa = doubleArrayOf( -62.5, -62.5, -62.5, -62.5, -62.0, -62.0, -62.0, -62.5, -62.0, -62.0, -62.0, -62.0, -62.0, -62.0, -62.0, -62.0, -61.5, -61.5, -61.5, -61.0, -61.0, -61.0, -61.0, -61.0 ) val temperature_70hPa = doubleArrayOf( -66.5, -66.5, -66.0, -66.0, -65.5, -65.5, -66.0, -65.5, -65.5, -65.5, -65.5, -65.5, -65.5, -66.0, -66.0, -65.5, -65.5, -65.5, -65.0, -65.0, -65.5, -65.0, -65.5, -65.0 ) val temperature_50hPa = doubleArrayOf( -69.0, -69.0, -69.0, -68.5, -68.5, -69.0, -69.0, -69.0, -69.0, -69.0, -69.0, -68.5, -69.0, -69.0, -68.5, -69.0, -68.0, -68.0, -68.5, -68.5, -68.5, -68.5, -69.0, -69.0 ) val temperature_30hPa = doubleArrayOf( -70.5, -70.0, -70.5, -70.5, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.0, -71.5, -71.5, -71.5, -71.5, -71.5, -71.5, -71.5, -71.0, -71.5 ) val relativehumidity_1000hPa = doubleArrayOf( 80.0, 80.0, 80.0, 80.0, 78.0, 78.0, 76.0, 76.0, 76.0, 73.0, 72.0, 72.0, 75.0, 75.0, 75.0, 75.0, 75.0, 75.0, 74.0, 70.0, 84.0, 74.0, 79.0, 84.0 ) val relativehumidity_975hPa = doubleArrayOf( 86.0, 87.0, 87.0, 88.0, 86.0, 87.0, 85.0, 85.0, 84.0, 82.0, 80.0, 80.0, 84.0, 85.0, 85.0, 84.0, 84.0, 82.0, 80.0, 76.0, 88.0, 81.0, 86.0, 88.0 ) val relativehumidity_950hPa = doubleArrayOf( 93.0, 94.0, 94.0, 96.0, 95.0, 96.0, 94.0, 94.0, 93.0, 91.0, 89.0, 88.0, 92.0, 95.0, 95.0, 93.0, 93.0, 90.0, 87.0, 83.0, 93.0, 88.0, 94.0, 92.0 ) val relativehumidity_925hPa = doubleArrayOf( 88.0, 89.0, 90.0, 92.0, 94.0, 99.0, 98.0, 99.0, 100.0, 100.0, 93.0, 96.0, 100.0, 100.0, 100.0, 100.0, 100.0, 98.0, 96.0, 92.0, 93.0, 88.0, 87.0, 93.0 ) val relativehumidity_900hPa = doubleArrayOf( 87.0, 88.0, 88.0, 89.0, 88.0, 90.0, 89.0, 88.0, 83.0, 84.0, 88.0, 89.0, 95.0, 89.0, 93.0, 97.0, 97.0, 100.0, 100.0, 100.0, 90.0, 89.0, 88.0, 90.0 ) val relativehumidity_850hPa = doubleArrayOf( 90.0, 91.0, 92.0, 93.0, 92.0, 91.0, 91.0, 91.0, 92.0, 65.0, 43.0, 53.0, 55.0, 56.0, 56.0, 63.0, 67.0, 64.0, 63.0, 58.0, 57.0, 61.0, 65.0, 58.0 ) val relativehumidity_800hPa = doubleArrayOf( 89.0, 90.0, 90.0, 90.0, 90.0, 90.0, 89.0, 89.0, 88.0, 90.0, 79.0, 63.0, 58.0, 40.0, 45.0, 49.0, 49.0, 41.0, 40.0, 43.0, 40.0, 32.0, 41.0, 37.0 ) val relativehumidity_700hPa = doubleArrayOf( 84.0, 87.0, 83.0, 82.0, 79.0, 78.0, 73.0, 43.0, 42.0, 36.0, 33.0, 30.0, 28.0, 31.0, 38.0, 34.0, 31.0, 32.0, 32.0, 33.0, 22.0, 16.0, 12.0, 10.0 ) val relativehumidity_600hPa = doubleArrayOf( 80.0, 79.0, 79.0, 76.0, 68.0, 58.0, 38.0, 30.0, 25.0, 22.0, 22.0, 16.0, 18.0, 22.0, 29.0, 32.0, 31.0, 30.0, 18.0, 18.0, 21.0, 16.0, 11.0, 10.0 ) val relativehumidity_500hPa = doubleArrayOf( 27.0, 26.0, 27.0, 26.0, 21.0, 24.0, 26.0, 26.0, 31.0, 34.0, 39.0, 37.0, 36.0, 27.0, 23.0, 21.0, 20.0, 19.0, 17.0, 16.0, 16.0, 17.0, 17.0, 14.0 ) val relativehumidity_400hPa = doubleArrayOf( 10.0, 12.0, 10.0, 10.0, 8.0, 10.0, 12.0, 13.0, 15.0, 13.0, 13.0, 13.0, 12.0, 13.0, 13.0, 13.0, 12.0, 12.0, 12.0, 10.0, 12.0, 12.0, 10.0, 7.0 ) val relativehumidity_300hPa = doubleArrayOf( 10.0, 8.0, 8.0, 10.0, 16.0, 18.0, 16.0, 16.0, 16.0, 14.0, 12.0, 10.0, 8.0, 8.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 6.0, 4.0 ) val relativehumidity_250hPa = doubleArrayOf( 9.0, 9.0, 7.0, 7.0, 4.0, 4.0, 4.0, 4.0, 4.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ) val relativehumidity_200hPa = doubleArrayOf( 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ) val relativehumidity_150hPa = doubleArrayOf( 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, ) val relativehumidity_100hPa = doubleArrayOf( 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, ) val relativehumidity_70hPa = doubleArrayOf( 4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0, ) val relativehumidity_50hPa = doubleArrayOf( 4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0, ) val relativehumidity_30hPa = doubleArrayOf( 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, ) val winddirection_1000hPa = doubleArrayOf( 325.0, 327.0, 327.0, 327.0, 327.0, 328.0, 328.0, 333.0, 336.0, 339.0, 334.0, 333.0, 334.0, 331.0, 333.0, 335.0, 336.0, 337.0, 336.0, 331.0, 308.0, 309.0, 312.0, 290.0 ) val winddirection_975hPa = doubleArrayOf( 339.0, 340.0, 339.0, 338.0, 336.0, 336.0, 336.0, 336.0, 339.0, 341.0, 336.0, 335.0, 335.0, 333.0, 336.0, 339.0, 341.0, 343.0, 344.0, 340.0, 319.0, 324.0, 322.0, 315.0 ) val winddirection_950hPa = doubleArrayOf( 343.0, 344.0, 343.0, 342.0, 340.0, 338.0, 339.0, 338.0, 340.0, 341.0, 336.0, 335.0, 335.0, 334.0, 337.0, 341.0, 342.0, 345.0, 346.0, 343.0, 322.0, 328.0, 326.0, 321.0 ) val winddirection_925hPa = doubleArrayOf( 6.0, 8.0, 7.0, 5.0, 1.0, 347.0, 348.0, 338.0, 343.0, 342.0, 337.0, 335.0, 335.0, 334.0, 338.0, 341.0, 343.0, 347.0, 349.0, 344.0, 335.0, 339.0, 336.0, 331.0 ) val winddirection_900hPa = doubleArrayOf( 2.0, 6.0, 8.0, 10.0, 10.0, 4.0, 356.0, 350.0, 349.0, 349.0, 346.0, 345.0, 347.0, 349.0, 348.0, 349.0, 352.0, 348.0, 349.0, 344.0, 342.0, 344.0, 336.0, 342.0 ) val winddirection_850hPa = doubleArrayOf( 350.0, 350.0, 354.0, 360.0, 3.0, 359.0, 351.0, 342.0, 339.0, 337.0, 348.0, 358.0, 7.0, 8.0, 6.0, 5.0, 1.0, 358.0, 351.0, 343.0, 341.0, 335.0, 344.0, 343.0 ) val winddirection_800hPa = doubleArrayOf( 14.0, 7.0, 356.0, 344.0, 342.0, 338.0, 334.0, 330.0, 324.0, 324.0, 324.0, 328.0, 332.0, 353.0, 357.0, 355.0, 356.0, 346.0, 337.0, 330.0, 326.0, 337.0, 342.0, 344.0 ) val winddirection_700hPa = doubleArrayOf( 343.0, 338.0, 334.0, 330.0, 327.0, 306.0, 285.0, 275.0, 278.0, 275.0, 285.0, 300.0, 307.0, 317.0, 327.0, 324.0, 316.0, 310.0, 309.0, 308.0, 312.0, 328.0, 335.0, 331.0 ) val winddirection_600hPa = doubleArrayOf( 338.0, 333.0, 325.0, 309.0, 302.0, 299.0, 298.0, 297.0, 294.0, 288.0, 280.0, 278.0, 283.0, 288.0, 293.0, 296.0, 292.0, 293.0, 296.0, 305.0, 313.0, 313.0, 317.0, 321.0 ) val winddirection_500hPa = doubleArrayOf( 297.0, 293.0, 295.0, 294.0, 298.0, 302.0, 299.0, 296.0, 289.0, 282.0, 272.0, 267.0, 267.0, 273.0, 280.0, 288.0, 297.0, 303.0, 312.0, 319.0, 321.0, 324.0, 327.0, 330.0 ) val winddirection_400hPa = doubleArrayOf( 235.0, 256.0, 272.0, 279.0, 285.0, 284.0, 279.0, 273.0, 270.0, 264.0, 262.0, 257.0, 258.0, 261.0, 268.0, 277.0, 291.0, 309.0, 320.0, 323.0, 325.0, 331.0, 338.0, 342.0 ) val winddirection_300hPa = doubleArrayOf( 236.0, 240.0, 243.0, 238.0, 245.0, 253.0, 251.0, 255.0, 256.0, 255.0, 252.0, 251.0, 254.0, 260.0, 268.0, 283.0, 306.0, 320.0, 332.0, 342.0, 343.0, 346.0, 347.0, 349.0 ) val winddirection_250hPa = doubleArrayOf( 229.0, 224.0, 224.0, 229.0, 237.0, 245.0, 250.0, 250.0, 251.0, 253.0, 257.0, 260.0, 267.0, 275.0, 287.0, 300.0, 313.0, 325.0, 333.0, 337.0, 343.0, 344.0, 344.0, 344.0 ) val winddirection_200hPa = doubleArrayOf( 238.0, 240.0, 246.0, 252.0, 254.0, 255.0, 254.0, 252.0, 252.0, 256.0, 263.0, 272.0, 284.0, 299.0, 312.0, 321.0, 329.0, 335.0, 338.0, 341.0, 339.0, 342.0, 343.0, 344.0 ) val winddirection_150hPa = doubleArrayOf( 253.0, 256.0, 255.0, 251.0, 247.0, 249.0, 256.0, 266.0, 274.0, 286.0, 299.0, 306.0, 309.0, 312.0, 321.0, 326.0, 331.0, 330.0, 335.0, 337.0, 340.0, 341.0, 342.0, 338.0 ) val winddirection_100hPa = doubleArrayOf( 250.0, 251.0, 256.0, 263.0, 272.0, 280.0, 284.0, 286.0, 283.0, 285.0, 290.0, 296.0, 299.0, 304.0, 310.0, 322.0, 327.0, 332.0, 335.0, 336.0, 333.0, 337.0, 342.0, 338.0) val winddirection_70hPa = doubleArrayOf( 251.0, 253.0, 259.0, 271.0, 281.0, 288.0, 289.0, 286.0, 288.0, 289.0, 291.0, 290.0, 297.0, 306.0, 315.0, 318.0, 324.0, 324.0, 327.0, 327.0, 337.0, 337.0, 337.0, 338.0 ) val winddirection_50hPa = doubleArrayOf( 270.0, 276.0, 279.0, 283.0, 281.0, 277.0, 270.0, 270.0, 276.0, 282.0, 286.0, 290.0, 295.0, 300.0, 306.0, 313.0, 314.0, 315.0, 322.0, 326.0, 326.0, 328.0, 331.0, 333.0 ) val winddirection_30hPa = doubleArrayOf( 262.0, 263.0, 264.0, 265.0, 266.0, 268.0, 272.0, 276.0, 280.0, 281.0, 282.0, 283.0, 284.0, 286.0, 289.0, 295.0, 299.0, 300.0, 302.0, 302.0, 303.0, 306.0, 310.0, 315.0 ) val windspeed_1000hPa = doubleArrayOf( 10.1, 9.9, 9.9, 9.9, 9.9, 10.2, 10.2, 11.3, 10.6, 11.2, 10.8, 11.3, 10.8, 11.1, 11.8, 11.9, 11.4, 10.2, 9.8, 9.0, 8.2, 10.2, 10.2, 8.4 ) val windspeed_975hPa = doubleArrayOf( 20.0, 19.9, 19.5, 18.9, 18.7, 19.2, 19.1, 19.9, 19.1, 19.5, 18.9, 19.5, 19.2, 19.7, 21.4, 23.1, 22.8, 21.8, 21.0, 20.2, 19.5, 21.5, 20.5, 20.5 ) val windspeed_950hPa = doubleArrayOf( 30.4, 30.3, 29.5, 28.2, 27.7, 28.3, 28.2, 28.5, 27.5, 27.8, 27.0, 27.7, 27.7, 28.4, 31.1, 34.4, 34.2, 33.6, 32.3, 31.6, 30.9, 33.2, 30.9, 33.6 ) val windspeed_925hPa = doubleArrayOf( 35.6, 35.7, 35.3, 33.9, 32.2, 31.8, 33.3, 29.4, 30.7, 29.6, 31.0, 29.3, 28.8, 29.1, 31.7, 35.7, 36.1, 38.3, 36.5, 35.9, 35.6, 40.0, 39.2, 36.9 ) val windspeed_900hPa = doubleArrayOf( 29.7, 32.0, 31.7, 29.3, 25.5, 22.7, 23.5, 27.2, 31.5, 31.6, 32.8, 30.8, 30.5, 29.9, 33.0, 36.2, 36.8, 39.4, 37.1, 36.6, 36.5, 37.4, 36.2, 34.4 ) val windspeed_850hPa = doubleArrayOf( 23.2, 25.0, 24.8, 23.2, 20.5, 18.2, 17.1, 17.7, 21.9, 25.3, 28.9, 31.9, 31.7, 33.6, 32.6, 34.3, 34.2, 32.4, 31.8, 30.4, 32.9, 35.3, 37.1, 34.9 ) val windspeed_800hPa = doubleArrayOf( 16.0, 15.6, 15.5, 16.6, 17.4, 17.7, 18.3, 20.2, 21.5, 25.4, 28.6, 28.3, 28.4, 27.2, 28.5, 29.6, 30.1, 29.8, 28.7, 30.5, 32.4, 32.5, 33.7, 32.8 ) val windspeed_700hPa = doubleArrayOf( 14.9, 14.8, 15.8, 15.0, 12.6, 11.5, 12.2, 15.6, 18.8, 21.2, 23.8, 26.4, 27.9, 29.0, 29.6, 28.4, 26.8, 26.9, 25.6, 25.2, 26.8, 31.5, 38.3, 39.7 ) val windspeed_600hPa = doubleArrayOf( 19.4, 18.3, 17.0, 18.0, 18.4, 20.5, 21.2, 22.0, 22.3, 23.3, 22.5, 24.0, 26.0, 25.9, 26.8, 26.3, 25.7, 27.5, 28.2, 30.0, 30.1, 29.0, 34.7, 40.1 ) val windspeed_500hPa = doubleArrayOf( 16.1, 18.3, 22.5, 29.0, 32.8, 34.0, 31.7, 30.6, 29.2, 28.2, 27.6, 26.4, 26.4, 26.4, 28.0, 27.7, 26.8, 28.6, 30.6, 33.2, 34.1, 38.6, 39.9, 41.4 ) val windspeed_400hPa = doubleArrayOf( 29.3, 29.7, 34.8, 38.9, 42.2, 44.5, 43.8, 43.3, 44.4, 44.7, 44.8, 44.3, 41.7, 36.5, 31.2, 29.0, 29.6, 32.4, 35.8, 36.0, 39.6, 46.7, 50.6, 60.7 ) val windspeed_300hPa = doubleArrayOf( 36.3, 33.3, 33.8, 31.3, 31.7, 33.8, 36.8, 41.0, 45.7, 49.8, 47.8, 44.4, 39.9, 35.3, 31.2, 25.9, 26.6, 31.5, 40.8, 49.3, 57.7, 63.2, 77.7, 102.6 ) val windspeed_250hPa = doubleArrayOf( 33.2, 33.1, 33.1, 33.2, 33.0, 34.4, 35.7, 34.6, 33.0, 32.6, 30.9, 28.0, 26.4, 25.3, 25.1, 26.3, 29.7, 35.3, 40.2, 49.5, 56.6, 63.8, 76.0, 88.5 ) val windspeed_200hPa = doubleArrayOf( 36.6, 33.3, 32.8, 30.4, 26.2, 23.6, 21.3, 22.8, 23.9, 24.7, 27.8, 28.8, 29.7, 30.1, 30.6, 34.1, 37.7, 39.7, 44.1, 48.2, 53.9, 61.9, 70.2, 76.3 ) val windspeed_150hPa = doubleArrayOf( 32.6, 29.7, 27.4, 25.4, 24.7, 27.0, 29.7, 31.3, 31.3, 31.2, 30.1, 26.6, 26.4, 28.9, 34.1, 36.3, 39.7, 45.7, 47.8, 52.2, 58.8, 63.4, 65.6, 73.8 ) val windspeed_100hPa = doubleArrayOf( 34.6, 36.8, 39.6, 39.9, 38.4, 34.1, 29.7, 26.2, 25.9, 28.5, 31.9, 33.3, 34.4, 38.9, 42.6, 44.4, 48.6, 48.8, 50.5, 52.6, 60.6, 69.3, 72.1, 76.4 ) val windspeed_70hPa = doubleArrayOf( 50.9, 53.9, 56.2, 55.2, 50.1, 42.9, 36.8, 34.9, 35.3, 36.8, 37.2, 38.3, 45.6, 49.0, 47.5, 50.1, 53.3, 55.0, 54.6, 66.9, 65.1, 66.7, 70.4, 75.3 ) val windspeed_50hPa = doubleArrayOf( 68.4, 61.5, 54.6, 49.2, 42.8, 41.1, 43.2, 50.4, 55.5, 56.5, 56.2, 58.8, 59.6, 59.7, 61.0, 62.0, 58.6, 62.8, 66.7, 62.2, 68.2, 69.6, 75.2, 78.4 ) val windspeed_30hPa = doubleArrayOf( 89.6, 88.3, 86.9, 84.3, 86.6, 87.6, 90.0, 89.3, 84.0, 77.0, 77.2, 77.7, 79.2, 79.8, 82.3, 84.8, 78.4, 81.7, 80.3, 79.2, 81.5, 84.3, 81.7, 86.5 ) val cloudcover_1000hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_975hPa = doubleArrayOf( 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.0, 0.0, 0.0, 4.0 ) val cloudcover_950hPa = doubleArrayOf( 32.0, 37.0, 37.0, 49.0, 42.0, 49.0, 37.0, 37.0, 32.0, 23.0, 15.0, 11.0, 27.0, 42.0, 42.0, 32.0, 32.0, 19.0, 7.0, 0.0, 32.0, 11.0, 37.0, 27.0 ) val cloudcover_925hPa = doubleArrayOf( 16.0, 20.0, 24.0, 32.0, 41.0, 76.0, 66.0, 76.0, 100.0, 100.0, 36.0, 52.0, 100.0, 100.0, 100.0, 100.0, 100.0, 66.0, 52.0, 32.0, 36.0, 16.0, 13.0, 36.0 ) val cloudcover_900hPa = doubleArrayOf( 17.0, 21.0, 21.0, 24.0, 21.0, 28.0, 24.0, 21.0, 6.0, 8.0, 21.0, 24.0, 49.0, 24.0, 39.0, 60.0, 60.0, 100.0, 100.0, 100.0, 28.0, 24.0, 21.0, 28.0 ) val cloudcover_850hPa = doubleArrayOf( 34.0, 37.0, 41.0, 45.0, 41.0, 37.0, 37.0, 37.0, 41.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_800hPa = doubleArrayOf( 35.0, 38.0, 38.0, 38.0, 38.0, 38.0, 35.0, 35.0, 32.0, 38.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_700hPa = doubleArrayOf( 27.0, 33.0, 25.0, 22.0, 15.0, 13.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_600hPa = doubleArrayOf( 18.0, 16.0, 16.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_500hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_400hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_300hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_250hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_200hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_150hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_100hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_70hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_50hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) val cloudcover_30hPa = doubleArrayOf( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ) @RequiresApi(Build.VERSION_CODES.O) fun m9g() { val dArr4 = f4983V0 //Атмосферное давление пересчитанное val f4992Y0: DoubleArray = DoubleArray(dArr4.size) //ПУстой массив. В итоге направление ветра по выбранному часу val f5010d1: DoubleArray = DoubleArray(dArr4.size) //ПУстой массив. В итоге температура по выбранному часу val f5002b1: DoubleArray = DoubleArray(dArr4.size) //Относительная влажность по выбранному часу val f5006c1: DoubleArray = DoubleArray(dArr4.size) // geopotential height val f4998a1: DoubleArray = DoubleArray(dArr4.size) //Направление ветра в тысячных??? val f5014e1: DoubleArray = DoubleArray(dArr4.size) // Скорость ветра val f5018f1: DoubleArray = DoubleArray(dArr4.size) // val f5022g1: DoubleArray = DoubleArray(dArr4.size) // облачность val f5026h1: DoubleArray = DoubleArray(dArr4.size) // Что то с ветром (зависит от f5022g1) val f5030i1: DoubleArray = DoubleArray(dArr4.size) // Что то с ветром (зависит от f5022g1) val f5034j1: DoubleArray = DoubleArray(dArr4.size) /**temperature*/ val f4968Q0: Array<DoubleArray> = arrayOf<DoubleArray>(temperature_1000hPa, temperature_975hPa, temperature_950hPa, temperature_925hPa, temperature_900hPa, temperature_850hPa, temperature_800hPa, temperature_700hPa, temperature_600hPa, temperature_500hPa, temperature_400hPa, temperature_300hPa, temperature_250hPa, temperature_200hPa, temperature_150hPa, temperature_100hPa, temperature_70hPa, temperature_50hPa, temperature_30hPa) /**temperature_2m*/ val f5089x0 = arrayOf( -8.8, -8.8, -8.9, -8.8, -8.9, -9.0, -9.0, -8.9, -8.7, -8.5, -8.1, -8.2, -8.4, -8.6, -8.6, -8.7, -8.6, -8.5, -8.5, -8.4, -8.6, -8.8, -9.1, -9.3 ) /**relativehumidity_2m*/ val f5093y0 = arrayOf( 80.0, 80.0, 80.0, 80.0, 79.0, 79.0, 77.0, 76.0, 76.0, 73.0, 73.0, 72.0, 76.0, 75.0, 75.0, 76.0, 76.0, 76.0, 74.0, 72.0, 85.0, 75.0, 80.0, 85.0 ) /**windspeed_10m*/ val f4909A0 = arrayOf( 9.9, 9.7, 9.7, 9.9, 9.9, 10.2, 10.0, 11.3, 10.6, 11.2, 10.8, 11.1, 10.8, 11.1, 11.6, 11.8, 11.3, 10.0, 9.5, 9.3, 8.2, 10.0, 9.7, 8.0 ) /**relativehumidity*/ val f4971R0: Array<DoubleArray> = arrayOf<DoubleArray>(relativehumidity_1000hPa, relativehumidity_975hPa, relativehumidity_950hPa, relativehumidity_925hPa, relativehumidity_900hPa, relativehumidity_850hPa, relativehumidity_800hPa, relativehumidity_700hPa, relativehumidity_600hPa, relativehumidity_500hPa, relativehumidity_400hPa, relativehumidity_300hPa, relativehumidity_250hPa, relativehumidity_200hPa, relativehumidity_150hPa, relativehumidity_100hPa, relativehumidity_70hPa, relativehumidity_50hPa, relativehumidity_30hPa) /**winddirection*/ val f4974S0: Array<DoubleArray> = arrayOf<DoubleArray>(winddirection_1000hPa, winddirection_975hPa, winddirection_950hPa, winddirection_925hPa, winddirection_900hPa, winddirection_850hPa, winddirection_800hPa, winddirection_700hPa, winddirection_600hPa, winddirection_500hPa, winddirection_400hPa, winddirection_300hPa, winddirection_250hPa, winddirection_200hPa, winddirection_150hPa, winddirection_100hPa, winddirection_70hPa, winddirection_50hPa, winddirection_30hPa) /**windspeed*/ val f4977T0: Array<DoubleArray> = arrayOf<DoubleArray>(windspeed_1000hPa, windspeed_975hPa, windspeed_950hPa, windspeed_925hPa, windspeed_900hPa, windspeed_850hPa, windspeed_800hPa, windspeed_700hPa, windspeed_600hPa, windspeed_500hPa, windspeed_400hPa, windspeed_300hPa, windspeed_250hPa, windspeed_200hPa, windspeed_150hPa, windspeed_100hPa, windspeed_70hPa, windspeed_50hPa, windspeed_30hPa) /**cloudcover*/ val f4980U0: Array<DoubleArray> = arrayOf<DoubleArray>( cloudcover_1000hPa, cloudcover_975hPa, cloudcover_950hPa, cloudcover_925hPa, cloudcover_900hPa, cloudcover_850hPa, cloudcover_800hPa, cloudcover_700hPa, cloudcover_600hPa, cloudcover_500hPa, cloudcover_400hPa, cloudcover_300hPa, cloudcover_250hPa, cloudcover_200hPa, cloudcover_150hPa, cloudcover_100hPa, cloudcover_70hPa, cloudcover_50hPa, cloudcover_30hPa ) /**visibility*/ val f4917C0: Array<Double> = arrayOf<Double>( 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 24140.00, 23480.00 ) /**cloudcover*/ val f4921D0: Array<Double> = arrayOf<Double>( 92.0, 97.0, 95.0, 90.0, 92.0, 92.0, 93.0, 99.0, 96.0, 100.0, 97.0, 97.0, 100.0, 100.0, 100.0, 100.0, 100.0, 91.0, 100.0, 93.0, 96.0, 73.0, 74.0, 79.0 ) /**precipiation*/ val f4925E0: Array<Double> = arrayOf<Double>( 0.10, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00) /**weathercode*/ val f4929F0: Array<Double> = arrayOf( 71.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 71.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0 ) /**Высота*/ val f5071s2 = 0 /**winddirection_10m*/ val f4913B0 = arrayOf( 327.0, 329.0, 329.0, 327.0, 327.0, 328.0, 330.0, 333.0, 336.0, 339.0, 334.0, 335.0, 334.0, 331.0, 334.0, 337.0, 338.0, 339.0, 335.0, 332.0, 308.0, 311.0, 312.0, 288.0 ) /**geopotential_height*/ val f4965P0: Array<DoubleArray> = arrayOf<DoubleArray>( geopotential_height_1000hPa, geopotential_height_975hPa, geopotential_height_950hPa, geopotential_height_925hPa, geopotential_height_900hPa, geopotential_height_850hPa, geopotential_height_800hPa, geopotential_height_700hPa, geopotential_height_600hPa, geopotential_height_500hPa, geopotential_height_400hPa, geopotential_height_300hPa, geopotential_height_250hPa, geopotential_height_200hPa, geopotential_height_150hPa, geopotential_height_100hPa, geopotential_height_70hPa, geopotential_height_50hPa, geopotential_height_30hPa ) val currentDateTime = LocalDateTime.now() val parseDouble = 8 val correctedParseDouble = if (parseDouble < 0) parseDouble + 24 else parseDouble val i = if (parseDouble == 384) parseDouble else correctedParseDouble + 1 val f4933G0 = SimpleDateFormat("ss.SSS", Locale.getDefault()).format(Date()).toDouble() + (SimpleDateFormat("mm", Locale.getDefault()).format(Date()).toDouble() * 60.0) val d = (f5089x0[i] - f5089x0[correctedParseDouble]) / 3600.0 * f4933G0 val f4937H0 = d + f5089x0[correctedParseDouble] val f4941I0 = (f5093y0[i] - f5093y0[correctedParseDouble]) / 3600.0 * f4933G0 + f5093y0[correctedParseDouble] // println("f4941I0 = $f4941I0") val f4945J0 = d val f4949K0 = d * 0.750063755419211 val f4953L0 = ((((f4909A0[i] - f4909A0[correctedParseDouble]) / 3600.0) * f4933G0 + f4909A0[correctedParseDouble]) * 1000.0) / 3600.0 val d3 = 6.0 val f4956M0 = ((((f4913B0[i] - f4913B0[correctedParseDouble]) / 3600.0) * f4933G0 + f4913B0[correctedParseDouble]) * 100.0) / 6.0 f4917C0.get(parseDouble) f4917C0.get(i) f4917C0.get(parseDouble) f4921D0.get(parseDouble) f4921D0.get(i) f4921D0.get(parseDouble) f4925E0[parseDouble] f4925E0[i] f4925E0[parseDouble] f4929F0.get(parseDouble) val f4959N0 = Math.cos(Math.toRadians(f4956M0 / 100.0 * 6.0)) * f4953L0 val f4962O0 = Math.sin(Math.toRadians(f4956M0 / 100.0 * 6.0)) * f4953L0 val dArr3: DoubleArray = f4986W0 val f4989X0 = DoubleArray(dArr3.size) for (i2 in dArr3.indices) { f4989X0[i2] = f5071s2.toDouble() + dArr3[i2] } for (i3 in 0 until f4983V0.size) { f4992Y0[i3] = f4983V0[i3] * 0.750063755419211 val dArr5 = f4965P0[i3] val d4 = dArr5.get(correctedParseDouble) val d5 = f4933G0 val d6 = (((dArr5.get(i) - d4) / 3600.0) * d5) + d4 dArr5[i3] = d6 f4998a1[i3] = (d6 * 6356863.0188) / (6356863.0188 - d6) val dArr7 = f5002b1 val dArr8 = f4968Q0[i3] val d7 = dArr8[correctedParseDouble] dArr7[i3] = (((dArr8[i] - d7) / 3600.0) * d5) + d7 val dArr9 = f5006c1 val dArr10 = f4971R0[i3] val d8 = dArr10[correctedParseDouble] dArr9[i3] = (((dArr10[i] - d8) / 3600.0) * d5) + d8 val dArr11 = f5010d1 val dArr12 = f4974S0[i3] val d9 = dArr12[correctedParseDouble] val d10 = (((dArr12[i] - d9) / 3600.0) * d5) + d9 dArr11[i3] = d10 val dArr13 = f5014e1 dArr13[i3] = (d10 * 100.0) / 6.0 val dArr14 = f5018f1 val dArr15 = f4977T0[i3] val d11 = dArr15[correctedParseDouble] val d12 = (((dArr15[i] - d11) / 3600.0) * d5) + d11 dArr14[i3] = d12 val dArr16 = f5022g1 dArr16[i3] = (d12 * 1000.0) / 3600.0 val dArr17 = f5026h1 val dArr18 = f4980U0[i3] val d13 = dArr18[correctedParseDouble] dArr17[i3] = (((dArr18[i] - d13) / 3600.0) * d5) + d13 f5030i1[i3] = Math.cos(Math.toRadians((dArr13[i3] / 100.0) * 6.0)) * dArr16[i3] f5034j1[i3] = Math.sin(Math.toRadians((f5014e1[i3] / 100.0) * 6.0)) * f5022g1[i3] } val dArr19 = f4989X0 //темп val f5038k1 = DoubleArray(dArr19.size) //темп val f5042l1 = DoubleArray(dArr19.size) //темп val f5046m1 = DoubleArray(dArr19.size) //скорость ветра val f5050n1 = DoubleArray(dArr19.size) //направление ветра val f5054o1 = DoubleArray(dArr19.size) //скорость ветра val f5058p1 = DoubleArray(dArr19.size) //скорость ветра val f5062q1 = DoubleArray(dArr19.size) //направление ветра val f5066r1 = DoubleArray(dArr19.size) var dArr = f4989X0 for (i4 in f4989X0.indices) { if (i4 == 0) { f5038k1[i4] = f4945J0 f5042l1[i4] = f4949K0 f5046m1[i4] = f4937H0 f5050n1[i4] = f4941I0 f5054o1[i4] = f4956M0 f5058p1[i4] = f4953L0 f5062q1[i4] = Math.cos(Math.toRadians((f5054o1[i4] / 100.0) * 6.0)) * f5058p1[i4] f5066r1[i4] = Math.sin(Math.toRadians((f5054o1[i4] / 100.0) * 6.0)) * f5058p1[i4] } if (i4 > 0) { var i5 = 0 val dArr20 = f4998a1 while (i5 < dArr20.size) { if (i5 < dArr20.size - 1) { val d14 = f4989X0[i4] val d15 = dArr20[i5] if (d14 >= d15) { val i6 = i5 + 1 val d16 = dArr20[i6] if (d14 < d16) { val d17 = (d14 - d15) / (d16 - d15) val dArr21 = f5038k1 val d18 = f4983V0[i5] dArr21[i4] = ((f4983V0[i6] - d18) * d17) + d18 val dArr22 = f5042l1 val dArr23 = f4992Y0 val d19 = dArr23[i5] dArr22[i4] = ((dArr23[i6] - d19) * d17) + d19 val dArr24 = f5046m1 val dArr25 = f5002b1 val d20 = dArr25[i5] dArr24[i4] = ((dArr25[i6] - d20) * d17) + d20 val dArr26 = f5050n1 val dArr27 = f5006c1 val d21 = dArr27[i5] dArr26[i4] = ((dArr27[i6] - d21) * d17) + d21 val dArr28 = f5054o1 val dArr29 = f5014e1 val d22 = dArr29[i5] dArr28[i4] = ((dArr29[i6] - d22) * d17) + d22 val dArr30 = f5058p1 val dArr31 = f5022g1 val d23 = dArr31[i5] dArr30[i4] = ((dArr31[i6] - d23) * d17) + d23 val dArr32 = f5062q1 val dArr33 = f5030i1 val d24 = dArr33[i5] dArr32[i4] = ((dArr33[i6] - d24) * d17) + d24 val dArr34 = f5066r1 val dArr35 = f5034j1 val d25 = dArr35[i5] dArr34[i4] = ((dArr35[i6] - d25) * d17) + d25 } } } else if (f4989X0[i4] >= dArr20[i5]) { val dArr36 = f5038k1 val i7 = i4 - 1 dArr36[i4] = dArr36[i7] val dArr37 = f5042l1 dArr37[i4] = dArr37[i7] val dArr38 = f5046m1 dArr38[i4] = dArr38[i7] val dArr39 = f5050n1 dArr39[i4] = dArr39[i7] val dArr40 = f5054o1 dArr40[i4] = dArr40[i7] val dArr41 = f5058p1 dArr41[i4] = dArr41[i7] val dArr42 = f5062q1 dArr42[i4] = dArr42[i7] val dArr43 = f5066r1 dArr43[i4] = dArr43[i7] } i5++ } } } val dArr44 = DoubleArray(dArr.size) val dArr45 = DoubleArray(dArr.size) var i8 = 0 val dArr2 = f4989X0 while (i8 < dArr2.size) { dArr44[i8] = f5042l1[i8] - (f(dArr3[i8]) * 750.0) val d26 = f5046m1[i8] val d27 = 17.625 * d26 val d28 = d26 + 243.04 val pow = Math.pow(E, d27 / d28) * 6.1094 Math.pow(Math.pow(((pow * 4283.58) / Math.pow(d28, 2.0)) * 0.0, 2.0), 0.5) val d29 = f5046m1[i8] val d30 = f5038k1[i8] val d31 = f5050n1[i8] val d32 = d29 + 273.0 val d33 = 0.378 * d31 val d34 = ((((d31 * 0.622) / 100.0) * pow) * (d32 * 0.608)) / (d30 - ((d33 / 100.0) * pow)) val d35 = d30 * 100.0 val d36 = d33 * 0.0 val pow2 = ((((((4283.58 / Math.pow(d29 + 243.04, 2.0)) * d32) + 1.0) * d35) - d36) * (((d31 * 0.608) * 0.622) * 0.0)) / Math.pow((pow * 100.0) - d36, 2.0) val d37 = d35 - d36 Math.pow(Math.pow(((((((d31 * 100.0) * 0.608) * 0.622) * 0.0) * d32) / Math.pow(d37, 2.0)) * 0.0, 2.0) + Math.pow((((((d35 * 0.608) * 0.622) * 0.0) * d32) / Math.pow(d37, 2.0)) * 0.0, 2.0) + Math.pow(pow2 * 0.0, 2.0), 0.5) dArr45[i8] = (f5046m1[i8] + d34) - (d(dArr3[i8]) - 273.0) i8++ } //темп val f5070s1 = DoubleArray(dArr2.size) val f5074t1 = DoubleArray(dArr2.size) //направление ветра 10 м val f5078u1 = DoubleArray(dArr2.size) // скорость ветра 10 м val f5082v1 = DoubleArray(dArr2.size) // val f5086w1 = DoubleArray(dArr2.size) val f5090x1 = DoubleArray(dArr2.size) var i9 = 0 val dArr46: DoubleArray = f4989X0 while (i9 < dArr46.size) { if (i9 == 0) { f5070s1[i9] = dArr44[i9] f5074t1[i9] = dArr45[i9] f5082v1[i9] = f5058p1[i9] f5078u1[i9] = f5054o1[i9] * 0.01 f5086w1[i9] = f5062q1[i9] f5090x1[i9] = f5066r1[i9] } if (i9 > 0) { val dArr47: DoubleArray = f5070s1 val i10 = i9 - 1 val d38 = dArr47[i10] val d39 = dArr46[i10] val d40 = dArr46[i9] dArr47[i9] = (d40 - d39) * dArr44[i9] / d40 + d38 * d39 / d40 val dArr48: DoubleArray = f5074t1 val d41 = dArr48[i10] val d42 = dArr46[i10] val d43 = dArr46[i9] dArr48[i9] = (d43 - d42) * dArr45[i9] / d43 + d41 * d42 / d43 val dArr49: DoubleArray = f5086w1 val d44 = dArr49[i10] val d45 = dArr46[i10] val d46 = dArr46[i9] dArr49[i9] = (d46 - d45) * f5062q1.get(i9) / d46 + d44 * d45 / d46 val dArr50: DoubleArray = f5090x1 val d47 = dArr50[i10] val d48 = dArr46[i10] val d49 = dArr46[i9] dArr50[i9] = (d49 - d48) * f5066r1.get(i9) / d49 + d47 * d48 / d49 f5082v1[i9] = Math.sqrt( Math.pow(Math.abs(f5090x1.get(i9)), 2.0) + Math.pow( Math.abs( dArr49[i9] ), 2.0 ) ) var acos = Math.acos(f5086w1.get(i9) / f5082v1.get(i9)) if (f5090x1.get(i9) < 0.0) { acos = 6.283185307179586 - acos } f5078u1[i9] = Math.toDegrees(acos) / 6.0 } i9++ } /**temperature 2 m*/ println(f5070s1.contentToString()) /**Первый параметр. Считается норм*/ println(f5074t1.contentToString()) /**Второй параметр. Считается норм*/ println(f5078u1.contentToString()) /**Третий параметр. Считается норм*/ println(f5082v1.contentToString()) println(f5086w1.contentToString()) println(f5090x1.contentToString()) }
LearnEnglishApp_AZE/app/src/androidTest/java/com/example/englishwordsapp/ExampleInstrumentedTest.kt
1459099181
package com.example.englishwordsapp import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.englishwordsapp", appContext.packageName) } }
LearnEnglishApp_AZE/app/src/test/java/com/example/englishwordsapp/ExampleUnitTest.kt
2394062741
package com.example.englishwordsapp import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/splash/SplashFragment.kt
20193281
package com.example.englishwordsapp.ui.splash import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.example.englishwordsapp.databinding.FragmentSplashBinding import com.example.englishwordsapp.ui.MainActivity import com.example.englishwordsapp.ui.MainActivityArgs class SplashFragment : Fragment() { private var binding: FragmentSplashBinding? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = FragmentSplashBinding.inflate(layoutInflater) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) launchMainScreen(true) } private fun launchMainScreen(isSignedIn: Boolean){ val intent = Intent(requireContext(), MainActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) val args = MainActivityArgs(isSignedIn) intent.putExtras(args.toBundle()) startActivity(intent) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/splash/SplashActivity.kt
3297761397
package com.example.englishwordsapp.ui.splash import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.example.englishwordsapp.R class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/MainActivity.kt
1640639601
package com.example.englishwordsapp.ui import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.ActivityMainBinding import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainActivity : AppCompatActivity() { private var binding: ActivityMainBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding?.root) } private fun isSignedIn(): Boolean { val bundle = intent.extras ?: throw IllegalStateException("No required arguments") val args = MainActivityArgs.fromBundle(bundle) return args.isSignedIn } private fun getMainNavigationGraphId(): Int = R.navigation.main_graph private fun getTabsDestination(): Int = R.id.tabsFragment private fun getSignInDestination(): Int = R.id.signInFragment }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/auth/SignInFragment.kt
2941021094
package com.example.englishwordsapp.ui.auth import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentSignInBinding class SignInFragment : Fragment() { private var binding: FragmentSignInBinding? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = FragmentSignInBinding.inflate(layoutInflater) return inflater.inflate(R.layout.fragment_sign_in, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/settings/SettingsFragment.kt
4009615908
package com.example.englishwordsapp.ui.main.settings import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.example.englishwordsapp.R class SettingsFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_settings, container, false) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/SimpleWordsModel.kt
1562681974
package com.example.englishwordsapp.ui.main.learn class SimpleWordsModel( val word: String?, val translationToAze: String?, val transcription: String?, val partOfSpeech: String?, val level: String?, ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/SpeechRecognitionAnswerWordState.kt
4225759167
package com.example.englishwordsapp.ui.main.learn.speechRecognition sealed class SpeechRecognitionAnswerWordState{ data object CORRECT : SpeechRecognitionAnswerWordState() data object WRONG : SpeechRecognitionAnswerWordState() data class Last(val countOfCorrectAnswer: Int) : SpeechRecognitionAnswerWordState() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/SoundPlayer.kt
3601314202
package com.example.englishwordsapp.ui.main.learn.speechRecognition import android.content.Context import android.speech.tts.TextToSpeech import java.util.Locale import javax.inject.Inject class SoundPlayer @Inject constructor() { private lateinit var textToSpeech: TextToSpeech fun playSound(word: String, context: Context){ textToSpeech = TextToSpeech(context, null) textToSpeech.setLanguage(Locale.US) textToSpeech.speak(word, TextToSpeech.QUEUE_FLUSH, null, null) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/SpeechRecognitionViewModel.kt
1142265546
package com.example.englishwordsapp.ui.main.learn.speechRecognition import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.repositories.SpeechRecognitionRepositoryImpl import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import javax.inject.Inject @HiltViewModel class SpeechRecognitionViewModel @Inject constructor( private val speechRecognitionRepository: SpeechRecognitionRepositoryImpl, private val soundPlayer: SoundPlayer, private val wordsAnswerChecker: SpeechRecognitionAnswerChecker, ) : ViewModel() { private val _word = MutableLiveData<SimpleWordsModel>() val word: LiveData<SimpleWordsModel> = _word private val _state = MutableLiveData<SpeechRecognitionAnswerWordState>() val state: LiveData<SpeechRecognitionAnswerWordState> = _state private val _progress = MutableLiveData(0) val progress: LiveData<Int> = _progress private var countOfCorrectAnswer = 0 private val _countOfQuestions = MutableLiveData(0) val countOfQuestions: LiveData<Int> = _countOfQuestions private val wordsList = mutableListOf<SimpleWordsModel>() private var questionModelForSkipButton: SimpleWordsModel? = null fun startRecognition() { val word = wordsList.removeLast() questionModelForSkipButton = word _word.value = word _progress.value = wordsList.size } fun checkAnswer(userAnswer: String) { val word = _word.value?.word val isCorrect = wordsAnswerChecker.checkAnswer(word.toString(), userAnswer) if (wordsList.isEmpty()) { _state.value = SpeechRecognitionAnswerWordState.Last(countOfCorrectAnswer) _progress.value = wordsList.size } else { if (isCorrect) { _state.value = SpeechRecognitionAnswerWordState.CORRECT _progress.value = wordsList.size countOfCorrectAnswer++ } else { _state.value = SpeechRecognitionAnswerWordState.WRONG _progress.value = wordsList.size } } } fun skipWord() { if (wordsList.isNotEmpty()) { questionModelForSkipButton?.let { wordsList.add(0, it) } val word = wordsList.removeLast() questionModelForSkipButton = word _word.value = word } } // fun playSound(word: String){ // soundPlayer.playSound(word, context) // } fun loadWords(difficultyLevel: String) { wordsModelData.postValue(WordRecognitionState.Loading(true)) viewModelScope.launch { withContext(Dispatchers.IO) { speechRecognitionRepository.getWordsList(difficultyLevel).collect { when (it) { is ResultWrapper.Success -> { wordsModelData.postValue(WordRecognitionState.Loading(false)) wordsList.addAll(it.data) withContext(Dispatchers.Main) { _countOfQuestions.value = wordsList.size val word = wordsList.removeLast() questionModelForSkipButton = word _word.value = word _progress.value = wordsList.size } wordsModelData.postValue(WordRecognitionState.Success(_word.value!!)) } is ResultWrapper.Error -> { wordsModelData.postValue(WordRecognitionState.Loading(false)) wordsModelData.postValue(WordRecognitionState.Error(it.error.orEmpty())) } else -> { wordsModelData.postValue(WordRecognitionState.Loading(false)) } } } } } } val wordsModelData = MutableLiveData<WordRecognitionState>() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/SpeechRecognitionFragment.kt
3888815845
package com.example.englishwordsapp.ui.main.learn.speechRecognition import android.content.Context import android.os.Bundle import android.speech.tts.TextToSpeech import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.InputMethodManager import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentSpeechRecognitionBinding import com.example.englishwordsapp.ui.main.learn.ResultDialogFragment import dagger.hilt.android.AndroidEntryPoint import java.util.Locale @AndroidEntryPoint class SpeechRecognitionFragment : Fragment() { private var binding: FragmentSpeechRecognitionBinding? = null private lateinit var textToSpeech: TextToSpeech private var countOfAllQuestions: Int? = null private var isResultShown = false private val viewModel by viewModels<SpeechRecognitionViewModel>() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = FragmentSpeechRecognitionBinding.inflate(layoutInflater) textToSpeech = TextToSpeech(requireContext(), null) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val difficultyLevel = arguments?.getString("difficultyLevel") difficultyLevel?.let { viewModel.loadWords(it) } viewModel.progress.observe(viewLifecycleOwner){count-> count?.let { binding?.tvProgressCount?.text = count.toString() binding?.progressIndicator?.progress = count } } viewModel.countOfQuestions.observe(viewLifecycleOwner){count-> count?.let { countOfAllQuestions = count binding?.progressIndicator?.max = count } } viewModel.wordsModelData.observe(viewLifecycleOwner){word-> when(word){ is WordRecognitionState.Success->{ binding?.progressBarLoadingData?.isVisible = false // viewModel.playSound(word.listOfQuestions.word!!) textToSpeech.setLanguage(Locale.US) textToSpeech.speak(word.listOfQuestions.word, TextToSpeech.QUEUE_FLUSH, null, null) } is WordRecognitionState.Error -> { } is WordRecognitionState.Loading -> { binding?.progressBarLoadingData?.isVisible = word.isLoading } } } binding?.btConfirm?.setOnClickListener { hideKeyboard(binding?.btConfirm!!) viewModel.state.observe(viewLifecycleOwner) { state -> state?.let { when (state) { is SpeechRecognitionAnswerWordState.CORRECT -> { changeContinueButtonState(ContinueBtStates.CORRECT) } is SpeechRecognitionAnswerWordState.WRONG -> { changeContinueButtonState(ContinueBtStates.WRONG) } is SpeechRecognitionAnswerWordState.Last -> { if (!isResultShown){ showResult(state.countOfCorrectAnswer) isResultShown = true } } } } } viewModel.checkAnswer(binding?.etInputCorrectAnswer?.text.toString() .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }) } binding?.imagePlaySpeaker?.setOnClickListener { viewModel.word.observe(viewLifecycleOwner){word-> word?.let { it.word?.let { it1 -> pronounceWord(it1) } // viewModel.playSound(word.word!!) } } } binding?.btContinue?.setOnClickListener { changeContinueButtonState(ContinueBtStates.NORMAL) viewModel.startRecognition() viewModel.word.observe(viewLifecycleOwner){word-> word?.let { it.word?.let { it1 -> pronounceWord(it1) } } } } binding?.btSkip?.setOnClickListener { viewModel.skipWord() viewModel.word.observe(viewLifecycleOwner){word-> word?.let { textToSpeech.setLanguage(Locale.US) textToSpeech.speak(it.word, TextToSpeech.QUEUE_FLUSH, null, null) } } } binding?.imageButtonClose?.setOnClickListener { findNavController().popBackStack() } } private fun hideKeyboard(view: View){ val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } private fun pronounceWord(word: String){ textToSpeech.setLanguage(Locale.US) textToSpeech.speak(word, TextToSpeech.QUEUE_FLUSH, null, null) } private fun showResult(countOfCorrectAnswer: Int){ countOfAllQuestions?.let { val wrongAnswer = it - countOfCorrectAnswer val dialogFragment = ResultDialogFragment() dialogFragment.isCancelable = false dialogFragment.setScore(countOfCorrectAnswer.toString(), wrongAnswer.toString()) dialogFragment.show( parentFragmentManager, ResultDialogFragment::class.java.canonicalName ) } } // // private fun increaseStep() { // binding?.tvProgressCount?.text = listOfWords.size.toString() // binding?.progressIndicator?.progress = binding?.progressIndicator?.progress?.plus(1) ?: 0 // } // private fun changeContinueButtonState(buttonState: ContinueBtStates){ when(buttonState){ ContinueBtStates.CORRECT -> { binding?.btSkip?.isVisible = false binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.green) binding?.imageView?.setImageResource(R.drawable.ic_correct) binding?.tvCorrectOrWrong?.text = "Correct!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.green)) } ContinueBtStates.WRONG ->{ binding?.btSkip?.isVisible = false binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.red) binding?.imageView?.setImageResource(R.drawable.ic_incorrect) binding?.tvCorrectOrWrong?.text = "Wrong!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.red)) } ContinueBtStates.NORMAL ->{ binding?.continueButtonLayout?.isVisible = false binding?.btSkip?.isVisible = true binding?.etInputCorrectAnswer?.text?.clear() } } } private fun Boolean.isClickable(){ binding?.imagePlaySpeaker?.isClickable = this binding?.btConfirm?.isClickable = this binding?.etInputCorrectAnswer?.isClickable = this binding?.etInputCorrectAnswer?.text?.clear() } private enum class ContinueBtStates{ NORMAL, CORRECT, WRONG } override fun onDestroy() { if (::textToSpeech.isInitialized) { textToSpeech.stop() textToSpeech.shutdown() } super.onDestroy() } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/WordRecognitionState.kt
123813200
package com.example.englishwordsapp.ui.main.learn.speechRecognition import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import com.example.englishwordsapp.ui.main.learn.vocabulary.VocabularyState sealed class WordRecognitionState { data class Error(val errorException: String): WordRecognitionState() data class Success(val listOfQuestions: SimpleWordsModel): WordRecognitionState() class Loading(val isLoading: Boolean): WordRecognitionState() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/speechRecognition/SpeechRecognitionAnswerChecker.kt
3329537089
package com.example.englishwordsapp.ui.main.learn.speechRecognition import javax.inject.Inject class SpeechRecognitionAnswerChecker @Inject constructor() { fun checkAnswer(wrightAnswer: String, userAnswer: String): Boolean{ return wrightAnswer == userAnswer } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/FilterWordsDialogFragment.kt
2458140648
package com.example.englishwordsapp.ui.main.learn import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import com.example.englishwordsapp.databinding.DialogFilterWordsBinding class FilterWordsDialogFragment: DialogFragment() { private var binding: DialogFilterWordsBinding? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = DialogFilterWordsBinding.inflate(layoutInflater) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding?.imageButtonClose?.setOnClickListener { dismiss() } binding?.btConfirm?.setOnClickListener { dismiss() } } enum class WordCategories{ NOUN,VERB } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/quiz/QuizState.kt
2461776870
package com.example.englishwordsapp.ui.main.learn.quiz sealed class QuizState { data class Error(val errorException: String): QuizState() data class Success(val listOfQuestions: List<QuizQuestionsModel>): QuizState() class Loading(val isLoading: Boolean): QuizState() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/quiz/QuizFragment.kt
2042605928
package com.example.englishwordsapp.ui.main.learn.quiz import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView import android.widget.Toast import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentQuizBinding import com.example.englishwordsapp.ui.main.learn.ResultDialogFragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class QuizFragment : Fragment() { private var binding: FragmentQuizBinding? = null private val viewModel by viewModels<QuizViewModel>() private val listOfWords = mutableListOf<QuizQuestionsModel>() private var correctAnswer: String? = null private var wrongAnswer = 0 private var countOfAllQuestions: Int? = null private var questionModel: QuizQuestionsModel? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = FragmentQuizBinding.inflate(layoutInflater, container, false) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val difficultyLevel = arguments?.getString("difficultyLevel") viewModel.questionModelData.observe(viewLifecycleOwner){result -> result?.let { when(result){ is QuizState.Success ->{ handleOnSuccessResult(result.listOfQuestions) } is QuizState.Error ->{ Toast.makeText(requireContext(), "Error: ${result.errorException}", Toast.LENGTH_LONG).show() } is QuizState.Loading ->{ binding?.progressBarLoadingData?.isVisible = result.isLoading } else -> {} } } } difficultyLevel?.let { viewModel.getQuestionList(it) } binding?.layoutVariant1?.setOnClickListener { if (correctAnswer == binding?.tvAnswer1?.text) { checkAnswer( binding?.layoutVariant1, binding?.tvAnswer1Nuber, binding?.tvAnswer1, VariantStates.CORRECT ) } else { checkAnswer( binding?.layoutVariant1, binding?.tvAnswer1Nuber, binding?.tvAnswer1, VariantStates.WRONG ) } } binding?.layoutVariant2?.setOnClickListener { if (correctAnswer == binding?.tvAnswer2?.text) { checkAnswer( binding?.layoutVariant2, binding?.tvAnswer2Nuber, binding?.tvAnswer2, VariantStates.CORRECT ) } else { checkAnswer( binding?.layoutVariant2, binding?.tvAnswer2Nuber, binding?.tvAnswer2, VariantStates.WRONG ) } } binding?.layoutVariant3?.setOnClickListener { if (correctAnswer == binding?.tvAnswer3?.text) { checkAnswer( binding?.layoutVariant3, binding?.tvAnswer3Nuber, binding?.tvAnswer3, VariantStates.CORRECT ) } else { checkAnswer( binding?.layoutVariant3, binding?.tvAnswer3Nuber, binding?.tvAnswer3, VariantStates.WRONG ) } } binding?.layoutVariant4?.setOnClickListener { if (correctAnswer == binding?.tvAnswer4?.text) { checkAnswer( binding?.layoutVariant4, binding?.tvAnswer4Nuber, binding?.tvAnswer4, VariantStates.CORRECT ) } else { checkAnswer( binding?.layoutVariant4, binding?.tvAnswer4Nuber, binding?.tvAnswer4, VariantStates.WRONG ) } } binding?.btContinue?.setOnClickListener { changeContinueButtonState(ContinueBtStates.NORMAL) checkAnswer(binding?.layoutVariant1, binding?.tvAnswer1Nuber, binding?.tvAnswer1, VariantStates.NORMAL ) checkAnswer(binding?.layoutVariant2, binding?.tvAnswer2Nuber, binding?.tvAnswer2, VariantStates.NORMAL ) checkAnswer(binding?.layoutVariant4, binding?.tvAnswer4Nuber, binding?.tvAnswer4,VariantStates.NORMAL ) checkAnswer(binding?.layoutVariant3, binding?.tvAnswer3Nuber, binding?.tvAnswer3,VariantStates.NORMAL ) increaseStep() if(listOfWords.size > 0) { showQuestion() }else { showResult() } } binding?.btSkip?.setOnClickListener { questionModel?.let { listOfWords.add(0, it) } if (listOfWords.size > 0) { showQuestion() } else { showResult() } } binding?.imageButtonClose?.setOnClickListener { findNavController().popBackStack() } } private fun handleOnSuccessResult(listOfQuestions: List<QuizQuestionsModel>){ listOfWords.addAll(listOfQuestions) binding?.progressIndicator?.max = listOfWords.size binding?.tvProgressCount?.text = listOfWords.size.toString() countOfAllQuestions = listOfWords.size listOfWords.shuffle() showQuestion() binding?.progressBarLoadingData?.isVisible = false } private fun increaseStep() { binding?.tvProgressCount?.text = listOfWords.size.toString() binding?.progressIndicator?.progress = binding?.progressIndicator?.progress?.plus(1) ?: 0 } private fun showQuestion(){ questionModel = listOfWords.last() listOfWords.removeLast() val questionWord = questionModel?.question val answerWords = questionModel?.answers?.shuffled() correctAnswer = questionModel?.correctAnswer binding?.tvQuestionWord?.text = questionWord binding?.tvAnswer1?.text = answerWords?.get(0) binding?.tvAnswer2?.text = answerWords?.get(1) binding?.tvAnswer3?.text = answerWords?.get(2) binding?.tvAnswer4?.text = answerWords?.get(3) } private fun showResult(){ countOfAllQuestions?.let { val countOfCorrectAnswer = it - wrongAnswer val dialogFragment = ResultDialogFragment() dialogFragment.isCancelable = false dialogFragment.setScore(countOfCorrectAnswer.toString(), wrongAnswer.toString()) dialogFragment.show( parentFragmentManager, ResultDialogFragment::class.java.canonicalName ) } } private fun changeContinueButtonState(buttonState: ContinueBtStates){ when(buttonState){ ContinueBtStates.CORRECT -> handleCorrectAnswerButton() ContinueBtStates.WRONG -> handleWrongAnswerButton() ContinueBtStates.NORMAL -> normalStateContinueButton() } } private fun handleCorrectAnswerButton() { binding?.btSkip?.isVisible = false binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.green) binding?.imageView?.setImageResource(R.drawable.ic_correct) binding?.tvCorrectOrWrong?.text = "Correct!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.green)) false.changeVariantsClickState() } private fun handleWrongAnswerButton() { binding?.btSkip?.isVisible = false binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.red) binding?.imageView?.setImageResource(R.drawable.ic_incorrect) binding?.tvCorrectOrWrong?.text = "Wrong!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.red)) false.changeVariantsClickState() } private fun normalStateContinueButton() { binding?.continueButtonLayout?.isVisible = false binding?.btSkip?.isVisible = true true.changeVariantsClickState() } private fun Boolean.changeVariantsClickState() { binding?.layoutVariant1?.isClickable = this binding?.layoutVariant2?.isClickable = this binding?.layoutVariant3?.isClickable = this binding?.layoutVariant4?.isClickable = this } private fun checkAnswer( layout: LinearLayout?, textViewVariantNumber: TextView?, textViewVariantValue: TextView?, variantStates: VariantStates ) { when (variantStates) { VariantStates.CORRECT -> handleCorrectAnswer( layout, textViewVariantNumber, textViewVariantValue ) VariantStates.WRONG -> handleWrongAnswer( layout, textViewVariantNumber, textViewVariantValue ) VariantStates.NORMAL -> variantsNormalState( layout, textViewVariantNumber, textViewVariantValue ) } } private fun handleCorrectAnswer( layout: LinearLayout?, textViewVariantNumber: TextView?, textViewVariantValue: TextView?, ) { layout?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_containers_correct ) textViewVariantNumber?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_variants_correct ) textViewVariantNumber?.setTextColor( ContextCompat.getColor( requireContext(), R.color.white ) ) textViewVariantValue?.setTextColor( ContextCompat.getColor( requireContext(), R.color.green ) ) changeContinueButtonState(ContinueBtStates.CORRECT) } private fun handleWrongAnswer( layout: LinearLayout?, textViewVariantNumber: TextView?, textViewVariantValue: TextView?, ){ layout?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_containers_wrong ) textViewVariantNumber?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_variants_wrong ) textViewVariantNumber?.setTextColor( ContextCompat.getColor( requireContext(), R.color.white ) ) textViewVariantValue?.setTextColor(ContextCompat.getColor( requireContext(), R.color.red )) wrongAnswer++ when(correctAnswer){ binding?.tvAnswer1?.text -> { handleCorrectAnswer( binding?.layoutVariant1, binding?.tvAnswer1Nuber, binding?.tvAnswer1 ) } binding?.tvAnswer2?.text ->{ handleCorrectAnswer( binding?.layoutVariant2, binding?.tvAnswer2Nuber, binding?.tvAnswer2 ) } binding?.tvAnswer3?.text ->{ handleCorrectAnswer( binding?.layoutVariant3, binding?.tvAnswer3Nuber, binding?.tvAnswer3 ) } binding?.tvAnswer4?.text ->{ handleCorrectAnswer( binding?.layoutVariant4, binding?.tvAnswer4Nuber, binding?.tvAnswer4 ) } } changeContinueButtonState(ContinueBtStates.WRONG) } private fun variantsNormalState( layout: LinearLayout?, textViewVariantNumber: TextView?, textViewVariantValue: TextView?, ) { layout?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_containers ) textViewVariantNumber?.background = ContextCompat.getDrawable( requireContext(), R.drawable.shape_rounded_variants ) textViewVariantNumber?.setTextColor( ContextCompat.getColor( requireContext(), R.color.textVariantsColor ) ) textViewVariantValue?.setTextColor( ContextCompat.getColor( requireContext(), R.color.textVariantsColor ) ) changeContinueButtonState(ContinueBtStates.NORMAL) } private enum class ContinueBtStates{ NORMAL, CORRECT, WRONG } private enum class VariantStates { NORMAL, CORRECT, WRONG } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/quiz/QuizViewModel.kt
2629750192
package com.example.englishwordsapp.ui.main.learn.quiz import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.repositories.QuizRepositoryImpl import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import javax.inject.Inject @HiltViewModel class QuizViewModel @Inject constructor( private val quizRepository: QuizRepositoryImpl ): ViewModel() { val questionModelData = MutableLiveData<QuizState>() fun getQuestionList(difficultyLevel: String){ questionModelData.postValue(QuizState.Loading(true)) viewModelScope.launch { withContext(Dispatchers.IO){ quizRepository.getQuestionList(difficultyLevel).collect{ when(it){ is ResultWrapper.Success ->{ questionModelData.postValue(QuizState.Loading(false)) questionModelData.postValue(QuizState.Success(it.data)) } is ResultWrapper.Error->{ questionModelData.postValue(QuizState.Loading(false)) questionModelData.postValue(QuizState.Error(it.error.orEmpty())) } else -> { questionModelData.postValue(QuizState.Loading(false)) } } } } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/quiz/QuizQuestionsModel.kt
1892619698
package com.example.englishwordsapp.ui.main.learn.quiz class QuizQuestionsModel( val question: String, val correctAnswer: String, val answers: List<String>, ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/LevelSetDialogFragment.kt
320798245
package com.example.englishwordsapp.ui.main.learn import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.LevelSetDialogFragmentBinding class LevelSetDialogFragment : DialogFragment() { private var binding: LevelSetDialogFragmentBinding? = null var onLevelSelectedListener: OnLevelSelectedListener? = null override fun onDismiss(dialog: DialogInterface) { super.onDismiss(dialog) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = LevelSetDialogFragmentBinding.inflate(layoutInflater) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val width = resources.getDimensionPixelSize(R.dimen.dialog_width) val height = resources.getDimensionPixelSize(R.dimen.level_dialog_height) dialog?.window?.setLayout(width, height) binding?.btStart?.setOnClickListener { var selectedLevel: String? = null when (binding?.radioGroupLevels?.checkedRadioButtonId) { binding?.beginnerLevel?.id -> selectedLevel = "beginner_level" binding?.elementaryLevel?.id -> selectedLevel = "elementary_level" binding?.intermediateLevel?.id -> selectedLevel = "intermediate_level" binding?.advanceLevel?.id -> selectedLevel = "advance_level" } if (selectedLevel != null) { onLevelSelectedListener?.onLevelSelected(selectedLevel) } dismiss() } } interface OnLevelSelectedListener { fun onLevelSelected(level: String) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/ResultDialogFragment.kt
4072818348
package com.example.englishwordsapp.ui.main.learn import android.app.Dialog import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.DialogEndQuestBinding class ResultDialogFragment: DialogFragment() { private var binding: DialogEndQuestBinding? = null private var countOfCorrectAnswer: String? = null private var countOfWrongAnswer: String? = null fun setScore(correct: String, wrong: String){ countOfCorrectAnswer = correct countOfWrongAnswer = wrong } override fun onDismiss(dialog: DialogInterface) { super.onDismiss(dialog) } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return super.onCreateDialog(savedInstanceState) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = DialogEndQuestBinding.inflate(layoutInflater, container, false) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val width = resources.getDimensionPixelSize(R.dimen.dialog_width) val height = resources.getDimensionPixelSize(R.dimen.dialog_height) dialog?.window?.setLayout(width, height) binding?.tvCorrectScore?.text = countOfCorrectAnswer binding?.tvWrongScore?.text = countOfWrongAnswer binding?.btClose?.setOnClickListener { findNavController().popBackStack() dismiss() } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/sentenceBuild/SentenceModel.kt
4277481917
package com.example.englishwordsapp.ui.main.learn.sentenceBuild class SentenceModel( val question: String, val answerWordsList: List<String> ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/sentenceBuild/SentenceBuildFragment.kt
431624593
package com.example.englishwordsapp.ui.main.learn.sentenceBuild import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentSentenceBuildBinding import com.google.android.material.chip.Chip import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class SentenceBuildFragment : Fragment() { private var binding: FragmentSentenceBuildBinding? = null private val viewModel by viewModels<SentenceBuildViewModel>() private val answerList = mutableListOf<String>() private val suggestedList = mutableListOf<String>() private var listOfSentences = mutableListOf<SentenceModel>() private var sentenceModelForSkipButton: SentenceModel? = null private var sentenceIndex = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = FragmentSentenceBuildBinding.inflate(layoutInflater) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val difficultyLevel = arguments?.getString("difficultyLevel") viewModel.questionModelData.observe(viewLifecycleOwner) { result -> result?.let { when (result) { is SentenceBuildState.Success -> { handleOnSuccessResult(result.listOfQuestions) } is SentenceBuildState.Error -> { Toast.makeText( requireContext(), "Error: ${result.errorException}", Toast.LENGTH_LONG ).show() } is SentenceBuildState.Loading -> { binding?.progressBarLoadingData?.isVisible = result.isLoading } } } } difficultyLevel?.let { viewModel.getSentenceModel(it) } binding?.btConfirm?.setOnClickListener { checkAnswerList() } binding?.btSkip?.setOnClickListener { sentenceModelForSkipButton?.let { listOfSentences.add(0, it) } changeContinueButtonState(ContinueBtStates.NORMAL) if (listOfSentences.size > 0){ setQuestion() }else{ Toast.makeText(requireContext(), "Result", Toast.LENGTH_SHORT).show() } } binding?.btContinue?.setOnClickListener { checkAnswerList() changeContinueButtonState(ContinueBtStates.NORMAL) } binding?.imageButtonClose?.setOnClickListener { findNavController().popBackStack() } } private fun handleOnSuccessResult(listOfQuestions: List<SentenceModel>){ listOfSentences.addAll(listOfQuestions) listOfSentences.shuffle() setQuestion() binding?.progressIndicator?.max = listOfSentences.size binding?.tvProgressCount?.text = listOfSentences.size.toString() binding?.progressBarLoadingData?.isVisible = false } private fun setQuestion(){ binding?.suggestedChipGroup?.removeAllViews() binding?.answerChipGroup?.removeAllViews() suggestedList.clear() answerList.clear() binding?.tvSentenceInAze?.text = listOfSentences.last().question sentenceModelForSkipButton = listOfSentences.last() suggestedList.addAll(listOfSentences.last().answerWordsList) suggestedList.shuffle() createSuggestedView() createAnsweredView() listOfSentences.removeLast() } private fun createSuggestedView() { suggestedList.forEach { item -> addSuggestedViewItem(item) } } private fun createAnsweredView() { answerList.forEach { item -> addEmptyViewItem(item) } } private fun onSuggestedItemClicked(item: String) { answerList.add(item) removeSuggestedViewItem(item) addEmptyViewItem(item) } private fun onAnsweredItemClicked(item: String) { answerList.remove(item) removeEmptyViewItem(item) addSuggestedViewItem(item) } private fun addSuggestedViewItem(item: String) { val chip = Chip(requireContext()) chip.text = item chip.tag = item chip.setOnClickListener { onSuggestedItemClicked(item) } binding?.suggestedChipGroup?.addView(chip) } private fun removeSuggestedViewItem(tag: String) { val chip = binding?.suggestedChipGroup?.findViewWithTag<Chip>(tag) binding?.suggestedChipGroup?.removeView(chip) } private fun addEmptyViewItem(item: String) { val chip = Chip(requireContext()) chip.text = item chip.tag = item chip.setOnClickListener { onAnsweredItemClicked(item) } binding?.answerChipGroup?.addView(chip) } private fun removeEmptyViewItem(tag: String) { val chip = binding?.answerChipGroup?.findViewWithTag<Chip>(tag) binding?.answerChipGroup?.removeView(chip) } private fun checkAnswerList() { if (listOfSentences.size > 0) { val rightAnswerList = sentenceModelForSkipButton?.answerWordsList var isRight = false isRight = answerList.size != 0 && answerList == rightAnswerList changeContinueButtonState(ContinueBtStates.CORRECT) if (isRight) { setQuestion() binding?.tvProgressCount?.text = listOfSentences.size.toString() binding?.progressIndicator?.progress = binding?.progressIndicator?.progress!! + 1 } else { changeContinueButtonState(ContinueBtStates.WRONG) } }else { val sentence = listOfSentences[sentenceIndex] val rightAnswerList = sentence.answerWordsList if(answerList.size != 0 && answerList == rightAnswerList){ Toast.makeText(requireContext(), "Done", Toast.LENGTH_LONG).show() }else{ changeContinueButtonState(ContinueBtStates.WRONG) } } } private fun changeContinueButtonState(buttonState: ContinueBtStates){ when(buttonState){ ContinueBtStates.CORRECT -> handleCorrectAnswerButton() ContinueBtStates.WRONG -> handleWrongAnswerButton() ContinueBtStates.NORMAL -> normalStateContinueButton() } } private fun handleCorrectAnswerButton() { binding?.btSkip?.isVisible = false binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.green) binding?.imageView?.setImageResource(R.drawable.ic_correct) binding?.tvCorrectOrWrong?.text = "Correct!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.green)) } private fun handleWrongAnswerButton() { binding?.continueButtonLayout?.isVisible = true binding?.continueButtonLayout?.setBackgroundResource(R.color.red) binding?.imageView?.setImageResource(R.drawable.ic_incorrect) binding?.tvCorrectOrWrong?.text = "Wrong!" binding?.btContinue?.setTextColor(ContextCompat.getColor(requireContext(), R.color.red)) } private fun normalStateContinueButton() { binding?.continueButtonLayout?.isVisible = false binding?.btSkip?.isVisible = true } private enum class ContinueBtStates{ NORMAL, CORRECT, WRONG } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/sentenceBuild/SentenceBuildState.kt
1823529449
package com.example.englishwordsapp.ui.main.learn.sentenceBuild sealed class SentenceBuildState { data class Error(val errorException: String): SentenceBuildState() data class Success(val listOfQuestions: List<SentenceModel>): SentenceBuildState() class Loading(val isLoading: Boolean): SentenceBuildState() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/sentenceBuild/Sentences.kt
4278813316
package com.example.englishwordsapp.ui.main.learn.sentenceBuild object Sentences { val listOfStentences = mutableListOf<SentenceModel>( SentenceModel("Sənin adın nədir?", mutableListOf("what", "is", "your", "name", "?")), SentenceModel("Sənin neçə yaşın var?", mutableListOf("how", "old", "are", "you", "?")), SentenceModel("Mənim adım Əlidir.", mutableListOf("my", "name", "is", "Ali")), // SentenceModel("Mən hər gün məktəbə gedirəm.", mutableListOf("I", "go", "to", "school", "every", "day")), // SentenceModel("Qələm masanın üstündədir.", mutableListOf("the", "pen", "is", "on", "the", "table")), // SentenceModel("Mənim iki qardaşım var.", mutableListOf("I", "have", "2", "brothers")), // SentenceModel("Pişik mənim ən sevdiyim heyvandır.", mutableListOf("cat", "is", "my", "favorite", "animal")), // SentenceModel("Sənin atan mühəndisdir?", mutableListOf("is", "your", "father", "an", "engineer", "?")), // SentenceModel("Bakı Azərbaycanın paytaxtıdır.", mutableListOf("Baku", "capital", "of", "Azerbaijan")), // SentenceModel("Çatntamda çoxlu kitablar var.", mutableListOf("there", "are", "a", "lot", "of", "books", "in", "my", "bag")), ) }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/sentenceBuild/SentenceBuildViewModel.kt
3071553125
package com.example.englishwordsapp.ui.main.learn.sentenceBuild import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.repositories.SentenceBuildRepositoryImpl import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import javax.inject.Inject @HiltViewModel class SentenceBuildViewModel @Inject constructor( private val sentenceBuildRepository: SentenceBuildRepositoryImpl ) : ViewModel() { val questionModelData = MutableLiveData<SentenceBuildState>() fun getSentenceModel(level: String) { questionModelData.postValue(SentenceBuildState.Loading(true)) viewModelScope.launch { withContext(Dispatchers.IO) { sentenceBuildRepository.getSentencesList(level).collect{ when(it){ is ResultWrapper.Success ->{ questionModelData.postValue(SentenceBuildState.Loading(false)) questionModelData.postValue(SentenceBuildState.Success(it.data)) } is ResultWrapper.Error ->{ questionModelData.postValue(SentenceBuildState.Loading(false)) questionModelData.postValue(SentenceBuildState.Error(it.error.orEmpty())) } else -> { questionModelData.postValue(SentenceBuildState.Loading(false)) } } } } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/vocabulary/VocabularyTranslationViewModel.kt
3405584789
package com.example.englishwordsapp.ui.main.learn.vocabulary import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.repositories.VocabularyRepositoryImpl import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import javax.inject.Inject @HiltViewModel class VocabularyTranslationViewModel @Inject constructor( private val vocabularyRepository: VocabularyRepositoryImpl ) : ViewModel() { val wordsModelData = MutableLiveData<VocabularyState>() fun getWordsList(difficultyLevel: String) { wordsModelData.postValue(VocabularyState.Loading(true)) viewModelScope.launch { withContext(Dispatchers.IO) { vocabularyRepository.getWordsList(difficultyLevel).collect { when (it) { is ResultWrapper.Success -> { wordsModelData.postValue(VocabularyState.Loading(false)) wordsModelData.postValue(VocabularyState.Success(it.data)) } is ResultWrapper.Error -> { wordsModelData.postValue(VocabularyState.Loading(false)) wordsModelData.postValue(VocabularyState.Error(it.error.orEmpty())) } else -> {} } } } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/vocabulary/VocabularyListAdapter.kt
1409924576
package com.example.englishwordsapp.ui.main.learn.vocabulary import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.example.englishwordsapp.databinding.ExampleWordTranslationBinding import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel class VocabularyListAdapter: ListAdapter<SimpleWordsModel, VocabularyListAdapter.VocabularyWH>(DIFF_UTIL) { private var onItemClik: ((word: SimpleWordsModel) -> Unit)? = null fun onItemClickListener(onItemClick: (word: SimpleWordsModel) -> Unit){ this.onItemClik = onItemClick } class VocabularyWH( private val binding: ExampleWordTranslationBinding ): ViewHolder(binding.root) { fun bind(data: SimpleWordsModel, onItemClick: ((word: SimpleWordsModel) -> Unit)?){ binding.tvWordInEng.text = data.word binding.tvWordInAze.text = data.translationToAze binding.tvWordTranscript.text = data.transcription binding.imagePlaySpeaker.setOnClickListener { onItemClick?.invoke(data) } } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VocabularyWH { val inflater = LayoutInflater.from(parent.context) val binding = ExampleWordTranslationBinding.inflate(inflater, parent, false) return VocabularyWH(binding) } override fun onBindViewHolder(holder: VocabularyWH, position: Int) { holder.bind(currentList[position], onItemClik) } companion object{ val DIFF_UTIL = object : DiffUtil.ItemCallback<SimpleWordsModel>(){ override fun areItemsTheSame( oldItem: SimpleWordsModel, newItem: SimpleWordsModel ): Boolean { return oldItem.word == newItem.word } override fun areContentsTheSame( oldItem: SimpleWordsModel, newItem: SimpleWordsModel ): Boolean { return oldItem.word == newItem.word && oldItem.transcription == newItem.transcription && oldItem.translationToAze == newItem.translationToAze && oldItem.level == newItem.level && oldItem.partOfSpeech == newItem.partOfSpeech } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/vocabulary/TranslationWordsFragment.kt
601603024
package com.example.englishwordsapp.ui.main.learn.vocabulary import android.os.Bundle import android.speech.tts.TextToSpeech import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.SearchView import android.widget.Toast import androidx.core.view.isVisible import androidx.fragment.app.viewModels import com.example.englishwordsapp.databinding.FragmentTranslationWordsBinding import com.example.englishwordsapp.ui.main.learn.FilterWordsDialogFragment import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import dagger.hilt.android.AndroidEntryPoint import java.util.Locale @AndroidEntryPoint class TranslationWordsFragment : Fragment() { private var binding: FragmentTranslationWordsBinding? = null private val adapterForWords by lazy { VocabularyListAdapter() } private val listOfWords = mutableListOf<SimpleWordsModel>() private lateinit var textToSpeech: TextToSpeech private val viewModel by viewModels<VocabularyTranslationViewModel>() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = FragmentTranslationWordsBinding.inflate(layoutInflater, container, false) // textToSpeech = TextToSpeech(requireContext()) { status -> // if (status == TextToSpeech.SUCCESS) { // val result = textToSpeech.setLanguage(Locale.US) // if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { // // Обработка ошибки // } // } else { // // Обработка ошибки // } // } textToSpeech = TextToSpeech(requireContext(), null) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding?.rcView?.adapter = adapterForWords viewModel.wordsModelData.observe(viewLifecycleOwner) { result -> result?.let { when (result) { is VocabularyState.Success -> { adapterForWords.submitList(result.listOfQuestions) listOfWords.addAll(result.listOfQuestions) binding?.progressBarLoadingData?.isVisible = false } is VocabularyState.Error -> { Toast.makeText( requireContext(), "Error: ${result.errorException}", Toast.LENGTH_SHORT ).show() } is VocabularyState.Loading -> { binding?.progressBarLoadingData?.isVisible = result.isLoading } else -> { } } } } viewModel.getWordsList("beginner_level") adapterForWords.onItemClickListener { word-> textToSpeech.setLanguage(Locale.US) textToSpeech.speak(word.word, TextToSpeech.QUEUE_FLUSH, null, null) } // adapterForWords.setOnClickListener(object : VocabularyAdapter.RvOnClickListener { // override fun onClick(data: SimpleWordsModel) { // } // override fun playSpeaker(text: String, position: Int) { // textToSpeech.setLanguage(Locale.US) // textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null) // } // }) binding?.searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(p0: String?): Boolean { return true } override fun onQueryTextChange(newText: String?): Boolean { newText?.let { query -> val filteredList = listOfWords.filter { item -> item.word?.contains( query, ignoreCase = true ) == true || item.translationToAze?.contains( query, ignoreCase = true ) == true }.toMutableList() adapterForWords.submitList(filteredList) return true } return false } }) binding?.ivFilterginSearch?.setOnClickListener { showFilterDialog() } } override fun onDestroy() { if (::textToSpeech.isInitialized) { textToSpeech.stop() textToSpeech.shutdown() } super.onDestroy() } private fun showFilterDialog(){ val dialog = FilterWordsDialogFragment() dialog.show(childFragmentManager, "FilterDialog") } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/vocabulary/VocabularyState.kt
2673249023
package com.example.englishwordsapp.ui.main.learn.vocabulary import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel sealed class VocabularyState { data class Error(val errorException: String): VocabularyState() data class Success(val listOfQuestions: List<SimpleWordsModel>): VocabularyState() class Loading(val isLoading: Boolean): VocabularyState() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/learn/LearnFragment.kt
2281734879
package com.example.englishwordsapp.ui.main.learn import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentLearnBinding import com.example.englishwordsapp.extensions.findTopNavController import com.example.englishwordsapp.ui.main.learn.quiz.QuizFragment import com.example.englishwordsapp.ui.main.learn.sentenceBuild.SentenceBuildFragment import com.example.englishwordsapp.ui.main.learn.speechRecognition.SpeechRecognitionFragment class LearnFragment : Fragment() { private var binding: FragmentLearnBinding? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = FragmentLearnBinding.inflate(layoutInflater) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding?.btQuiz?.setOnClickListener { showDifficultyLevelDialog(QuizFragment(), R.id.quizFragment) } binding?.btVocabularyTranslation?.setOnClickListener { findNavController().navigate(R.id.action_learnFragment_to_translationWordsFragment) } binding?.btSpeechRecognition?.setOnClickListener { showDifficultyLevelDialog(SpeechRecognitionFragment(),R.id.speechRecognitionFragment2 ) } binding?.btSentenceBuild?.setOnClickListener { showDifficultyLevelDialog(SentenceBuildFragment(), R.id.sentenceBuildFragment) } } private fun showDifficultyLevelDialog(fragment: Fragment, fragmentID: Int){ val dialog = LevelSetDialogFragment() dialog.onLevelSelectedListener = object : LevelSetDialogFragment.OnLevelSelectedListener { override fun onLevelSelected(level: String) { startFragment(level, fragment, fragmentID) } } dialog.show(childFragmentManager, "DifficultyLevelDialog") } private fun startFragment( difficultyLevel: String, fragment: Fragment, fragmentID: Int ) { val bundle = Bundle() bundle.putString("difficultyLevel", difficultyLevel) findTopNavController().navigate(fragmentID, bundle) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/profile/ProfileFragment.kt
3397695698
package com.example.englishwordsapp.ui.main.profile import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.example.englishwordsapp.databinding.FragmentProfileBinding class ProfileFragment : Fragment() { private var binding: FragmentProfileBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { binding = FragmentProfileBinding.inflate(layoutInflater) return binding?.root } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/ui/main/MainFragment.kt
3064453446
package com.example.englishwordsapp.ui.main import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.NavigationUI import com.example.englishwordsapp.R import com.example.englishwordsapp.databinding.FragmentMainBinding import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainFragment : Fragment() { private var binding: FragmentMainBinding? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = FragmentMainBinding.inflate(layoutInflater, container, false) return binding?.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val navHost = childFragmentManager.findFragmentById(R.id.tabsContainer) as NavHostFragment val navController = navHost.navController binding?.bottomNav?.let { NavigationUI.setupWithNavController(it, navController) } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/adminPanel/Words.kt
1943851331
package com.example.englishwordsapp.adminPanel import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel object Words { val listOfWords = mutableListOf( SimpleWordsModel("Apple", "Alma", "[ˈæpl]", "noun", "beginner_level"), SimpleWordsModel("Car", "Avtomobil", "[kɑːr]", "noun", "beginner_level"), SimpleWordsModel("Cat", "Pişik", "[kæt]", "noun", "beginner_level"), SimpleWordsModel("Dog", "It", "[dɔg]", "noun", "beginner_level"), SimpleWordsModel("Table", "Masa", "[ˈteɪbəl]", "noun", "beginner_level"), SimpleWordsModel("Room", "Otaq", "[ruːm]", "noun", "beginner_level"), SimpleWordsModel("Door", "Qapı", "[dɔr]", "noun", "beginner_level"), SimpleWordsModel("Star", "Ulduz", "[stɑːr]", "noun", "beginner_level"), SimpleWordsModel("Sun", "Günəş", "[sʌn]", "noun", "beginner_level"), SimpleWordsModel("Pen", "Qələm", "[pɛn]", "noun", "beginner_level"), SimpleWordsModel("Book", "Kitab", "[bʊk]", "noun", "beginner_level"), SimpleWordsModel("Ice", "Buz", "[aɪs]", "noun", "beginner_level"), SimpleWordsModel("Mother", "Ana", "[ˈmʌðər]", "noun", "beginner_level"), SimpleWordsModel("Father", "Ata", "[ˈfɑːðər]", "noun", "beginner_level"), SimpleWordsModel("Brother", "Qardaş", "[ˈbrʌðər]", "noun", "beginner_level"), SimpleWordsModel("Phone", "Telefon", "[foʊn]", "noun", "beginner_level"), SimpleWordsModel("Bus", "Avtobus", "[bʌs]", "noun", "beginner_level"), SimpleWordsModel("School", "Məktəb", "[skuːl]", "noun", "beginner_level"), SimpleWordsModel("City", "Şəhər", "[ˈsɪti]", "noun", "beginner_level"), SimpleWordsModel("Cheese", "Pendir", "[ʧiz]", "noun", "beginner_level") ) }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/adminPanel/AddingSimpleWordsModel.kt
370054323
package com.example.englishwordsapp.adminPanel import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase class AddingSimpleWordsModel { fun addWords(){ val db = Firebase.firestore val finalList = Words.listOfWords for(i in finalList){ val wordData = hashMapOf( "level" to i.level, "partOfSpeech" to i.partOfSpeech, "transcription" to i.transcription, "translationToAze" to i.translationToAze, "word" to i.word ) // db.collection("wordsForVocabulary") // .add(wordData) // .addOnSuccessListener { documentReference -> // Log.d("Musa","Error mesage :$documentReference") // } // .addOnFailureListener { e -> // Log.d("Musa","Error mesage :$e") // } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/App.kt
3097181054
package com.example.englishwordsapp import android.app.Application import com.google.firebase.FirebaseApp import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class App: Application() { override fun onCreate() { super.onCreate() FirebaseApp.initializeApp(this) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/extensions/FragmentExtensions.kt
1817074485
package com.example.englishwordsapp.extensions import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.findNavController import com.example.englishwordsapp.R fun Fragment.findTopNavController(): NavController { val topLevelHost = requireActivity().supportFragmentManager.findFragmentById(R.id.fragmentContainerInActivity) as NavHostFragment? return topLevelHost?.navController ?: findNavController() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/datasource/QuizRetrofitDatasource.kt
50127342
package com.example.englishwordsapp.data.datasource import com.example.englishwordsapp.data.model.QuizQuestionsResponse import com.example.englishwordsapp.data.model.core.ResultWrapper class QuizRetrofitDatasource: QuizDatasource { override suspend fun getQuestions(difficultyLevel: String): ResultWrapper<List<QuizQuestionsResponse>> { TODO("Not yet implemented") } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/datasource/QuizFirebaseDatasource.kt
270580238
package com.example.englishwordsapp.data.datasource import com.example.englishwordsapp.data.model.QuizQuestionsResponse import com.example.englishwordsapp.data.model.core.ResultWrapper import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import javax.inject.Inject class QuizFirebaseDatasource @Inject constructor( private val db: FirebaseFirestore ): QuizDatasource { override suspend fun getQuestions(difficultyLevel: String): ResultWrapper<List<QuizQuestionsResponse>> { val docRef = db.collection("wordsForQuiz") .document(difficultyLevel) .collection("questionsModel") val result = kotlin.runCatching { Tasks.await(docRef.get()) } val data = result.getOrNull()?.toObjects(QuizQuestionsResponse::class.java).orEmpty() return ResultWrapper.Success(data) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/datasource/QuizDatasource.kt
2421280820
package com.example.englishwordsapp.data.datasource import com.example.englishwordsapp.data.model.QuizQuestionsResponse import com.example.englishwordsapp.data.model.core.ResultWrapper interface QuizDatasource { suspend fun getQuestions(difficultyLevel: String): ResultWrapper<List<QuizQuestionsResponse>> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/roomDatabase/Entity.kt
2650949431
package com.example.englishwordsapp.data.roomDatabase import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey @Entity( tableName = "Table_for_words" ) class Entity( @PrimaryKey(autoGenerate = true) val id: Int?, @ColumnInfo val wordInEnglish: String?, @ColumnInfo val wordInRussian: String?, @ColumnInfo val wordTranscription: String?, @ColumnInfo val pronunciation: String?, ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/roomDatabase/DaoForRoom.kt
1253618808
package com.example.englishwordsapp.data.roomDatabase import androidx.room.Dao @Dao interface DaoForRoom { // @Insert // fun insertWord(item: Entity) // // @Query("SELECT * FROM Table_for_words") // fun getAllWords(): List<Entity> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/roomDatabase/DataBase.kt
3778092818
package com.example.englishwordsapp.data.roomDatabase import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase @Database( entities = [Entity::class], version = 1 ) abstract class DataBase: RoomDatabase(){ abstract fun getDao(): DaoForRoom companion object{ fun getDb(context: Context): DataBase { return Room.databaseBuilder( context.applicationContext, DataBase::class.java, "my.DB" ).build() } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/di/FirebaseModule.kt
392582164
package com.example.englishwordsapp.data.di import com.example.englishwordsapp.data.datasource.QuizDatasource import com.example.englishwordsapp.data.datasource.QuizFirebaseDatasource import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent @Module @InstallIn (SingletonComponent::class) object FirebaseModule { @Provides fun provideFirestore(): FirebaseFirestore{ return Firebase.firestore } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/di/DataSourceModule.kt
1868777248
package com.example.englishwordsapp.data.di import com.example.englishwordsapp.data.datasource.QuizDatasource import com.example.englishwordsapp.data.datasource.QuizFirebaseDatasource import com.google.firebase.firestore.FirebaseFirestore import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent @Module @InstallIn (SingletonComponent::class) object DataSourceModule { @Provides fun provideQuizDatasource(firebaseFirestore: FirebaseFirestore): QuizDatasource{ return QuizFirebaseDatasource(firebaseFirestore) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/di/RepositoryModule.kt
2651887629
package com.example.englishwordsapp.data.di import com.example.englishwordsapp.data.datasource.QuizDatasource import com.example.englishwordsapp.data.repositories.QuizRepository import com.example.englishwordsapp.data.repositories.QuizRepositoryImpl import com.example.englishwordsapp.data.repositories.SentenceBuildRepository import com.example.englishwordsapp.data.repositories.SentenceBuildRepositoryImpl import com.example.englishwordsapp.data.repositories.SpeechRecognitionRepository import com.example.englishwordsapp.data.repositories.SpeechRecognitionRepositoryImpl import com.example.englishwordsapp.data.repositories.VocabularyRepository import com.example.englishwordsapp.data.repositories.VocabularyRepositoryImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent @Module @InstallIn(SingletonComponent::class) object RepositoryModule { @Provides fun provideQuizRepository(quizDatasource: QuizDatasource): QuizRepository{ return QuizRepositoryImpl(quizDatasource) } @Provides fun provideSentenceBuildRepository(): SentenceBuildRepository{ return SentenceBuildRepositoryImpl() } @Provides fun provideSpeechRecognitionRepository(): SpeechRecognitionRepository{ return SpeechRecognitionRepositoryImpl() } @Provides fun provideVocabularyRepository(): VocabularyRepository{ return VocabularyRepositoryImpl() } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/QuizRepositoryImpl.kt
1128349902
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.datasource.QuizDatasource import com.example.englishwordsapp.data.model.QuizQuestionsResponse import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.quiz.QuizQuestionsModel import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import kotlinx.coroutines.flow.flow import javax.inject.Inject class QuizRepositoryImpl @Inject constructor( private val quizDatasource: QuizDatasource ): QuizRepository { override suspend fun getQuestionList(difficultyLevel: String) = flow<ResultWrapper<List<QuizQuestionsModel>>?> { when(val result = quizDatasource.getQuestions(difficultyLevel)){ is ResultWrapper.Success ->{ val mappedList = result.data.map { QuizQuestionsModel( question = it.question.orEmpty(), correctAnswer = it.correctAnswer.orEmpty(), answers = it.answers.orEmpty() ) } emit(ResultWrapper.Success(mappedList)) } is ResultWrapper.Error ->{ } } } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/SentenceBuildRepository.kt
2739720401
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.sentenceBuild.SentenceModel import kotlinx.coroutines.flow.Flow interface SentenceBuildRepository { suspend fun getSentencesList(wordsLevel: String): Flow<ResultWrapper<List<SentenceModel>>?> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/SpeechRecognitionRepositoryImpl.kt
1306291168
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.model.SimpleWordsResponse import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import kotlinx.coroutines.flow.flow import javax.inject.Inject class SpeechRecognitionRepositoryImpl @Inject constructor(): SpeechRecognitionRepository { override suspend fun getWordsList(difficultyLevel: String) = flow<ResultWrapper<List<SimpleWordsModel>>?> { val db = Firebase.firestore val docRef = db.collection("wordsForVocabulary") .whereEqualTo("level", difficultyLevel) val result = kotlin.runCatching { Tasks.await(docRef.get()) } val data = result.getOrNull()?.toObjects(SimpleWordsResponse::class.java) val mappedList = data?.map { SimpleWordsModel( word = it.word.orEmpty(), translationToAze = it.translationToAze.orEmpty(), transcription = it.transcription.orEmpty(), partOfSpeech = it.partOfSpeech.orEmpty(), level = it.level.orEmpty() ) }.orEmpty() emit(ResultWrapper.Success(mappedList)) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/VocabularyRepositoryImpl.kt
2545187791
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.SimpleWordsResponse import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import kotlinx.coroutines.flow.flow import javax.inject.Inject class VocabularyRepositoryImpl @Inject constructor(): VocabularyRepository { override suspend fun getWordsList(difficultyLevel: String) = flow<ResultWrapper<List<SimpleWordsModel>>?> { val db = Firebase.firestore val docRef = db.collection("wordsForVocabulary") val result = kotlin.runCatching { Tasks.await(docRef.get()) } val data = result.getOrNull()?.toObjects(SimpleWordsResponse::class.java) val mappedList = data?.map { SimpleWordsModel( word = it.word.orEmpty(), translationToAze = it.translationToAze.orEmpty(), transcription = it.transcription.orEmpty(), partOfSpeech = it.partOfSpeech.orEmpty(), level = it.level.orEmpty() ) }.orEmpty() emit(ResultWrapper.Success(mappedList)) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/SentenceBuildRepositoryImpl.kt
2972900417
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.data.model.SentenceResponseModel import com.example.englishwordsapp.ui.main.learn.sentenceBuild.SentenceModel import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import kotlinx.coroutines.flow.flow import javax.inject.Inject class SentenceBuildRepositoryImpl @Inject constructor(): SentenceBuildRepository { override suspend fun getSentencesList(wordsLevel: String) = flow<ResultWrapper<List<SentenceModel>>?> { val db = Firebase.firestore val docRef = db.collection("sentences") .document(wordsLevel) .collection("sentence_model") val result = kotlin.runCatching { Tasks.await(docRef.get()) } val data = result.getOrNull()?.toObjects(SentenceResponseModel::class.java) val mappedList = data?.map { SentenceModel( question = it.question.orEmpty(), answerWordsList = it.answerWordsList.orEmpty() ) }.orEmpty() emit(ResultWrapper.Success(mappedList)) } }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/VocabularyRepository.kt
3301435180
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import kotlinx.coroutines.flow.Flow interface VocabularyRepository { suspend fun getWordsList(difficultyLevel: String): Flow<ResultWrapper<List<SimpleWordsModel>>?> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/SpeechRecognitionRepository.kt
3591714356
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.SimpleWordsModel import kotlinx.coroutines.flow.Flow interface SpeechRecognitionRepository { suspend fun getWordsList(difficultyLevel: String): Flow<ResultWrapper<List<SimpleWordsModel>>?> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/repositories/QuizRepository.kt
783533714
package com.example.englishwordsapp.data.repositories import com.example.englishwordsapp.data.model.core.ResultWrapper import com.example.englishwordsapp.ui.main.learn.quiz.QuizQuestionsModel import kotlinx.coroutines.flow.Flow interface QuizRepository { suspend fun getQuestionList(difficultyLevel: String): Flow<ResultWrapper<List<QuizQuestionsModel>>?> }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/model/SimpleWordsResponse.kt
2378376949
package com.example.englishwordsapp.data.model class SimpleWordsResponse( val word: String? = null, val translationToAze: String? = null, val transcription: String? = null, val partOfSpeech: String? = null, val level: String? = null, ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/model/core/ResultWrapper.kt
1307639793
package com.example.englishwordsapp.data.model.core sealed class ResultWrapper <out T> { data class Success <T>(val data: T): ResultWrapper<T>() data class Error (val error: String?): ResultWrapper<Nothing>() }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/model/QuizQuestionsResponse.kt
2999170477
package com.example.englishwordsapp.data.model class QuizQuestionsResponse( val question: String? = null, val correctAnswer: String? = null, val answers: List<String>? = null, ) { }
LearnEnglishApp_AZE/app/src/main/java/com/example/englishwordsapp/data/model/SentenceResponseModel.kt
2513495280
package com.example.englishwordsapp.data.model class SentenceResponseModel( val question: String? = null, val answerWordsList: List<String>? = null ) { }
PexelApp/app/src/androidTest/java/ir/mirdar/pexelmovieapp/ExampleInstrumentedTest.kt
2219440176
package ir.mirdar.pexelmovieapp import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("ir.mirdar.pexelmovieapp", appContext.packageName) } }
PexelApp/app/src/test/java/ir/mirdar/pexelmovieapp/ExampleUnitTest.kt
1156386395
package ir.mirdar.pexelmovieapp import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/di/SingletonModule.kt
3736113975
package ir.mirdar.pexelmovieapp.di import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import io.realm.kotlin.Realm import io.realm.kotlin.RealmConfiguration import ir.mirdar.pexelmovieapp.data.local.model.RealmSource import ir.mirdar.pexelmovieapp.data.local.model.RealmPhoto import ir.mirdar.pexelmovieapp.data.local.model.RealmCurated import ir.mirdar.pexelmovieapp.data.remote.ApiService import ir.mirdar.pexelmovieapp.data.remote.RequestInterceptor import ir.mirdar.pexelmovieapp.presentation.common.Utils import okhttp3.Interceptor import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object SingletonModule { @Provides @Singleton fun provideRequestInterceptor(): Interceptor = RequestInterceptor() @Provides @Singleton fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor { val httpLoggingInterceptor = HttpLoggingInterceptor() httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY return httpLoggingInterceptor } @Provides @Singleton fun provideOkHttpClient( httpLoggingInterceptor: HttpLoggingInterceptor, requestInterceptor: RequestInterceptor ): OkHttpClient = OkHttpClient.Builder() .addInterceptor(requestInterceptor) .addInterceptor(httpLoggingInterceptor) .build() @Provides @Singleton fun provideRetrofitBuilder(okHttpClient: OkHttpClient): Retrofit = Retrofit.Builder() .baseUrl(Utils.BASE_URL) .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .build() @Provides @Singleton fun provideApiService(retrofit: Retrofit) = retrofit.create(ApiService::class.java) @Provides @Singleton fun provideRealmDatabase(): Realm { val config = RealmConfiguration.create( schema = setOf( RealmCurated::class, RealmPhoto::class, RealmSource::class ) ) return Realm.open(config) } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/di/ViewModelModule.kt
2322059311
package ir.mirdar.pexelmovieapp.di import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.components.ViewModelComponent import dagger.hilt.android.scopes.ViewModelScoped import io.realm.kotlin.Realm import ir.mirdar.pexelmovieapp.data.local.LocalRepositoryImpl import ir.mirdar.pexelmovieapp.data.remote.ApiService import ir.mirdar.pexelmovieapp.data.remote.RemoteRepositoryImpl import ir.mirdar.pexelmovieapp.domain.repositories.LocalRepository import ir.mirdar.pexelmovieapp.domain.repositories.RemoteRepository @Module @InstallIn(ViewModelComponent::class) object ViewModelModule { @Provides @ViewModelScoped fun provideRemoteRepository(apiService: ApiService): RemoteRepository = RemoteRepositoryImpl(apiService) @Provides @ViewModelScoped fun provideLocalRepository(realm: Realm) : LocalRepository = LocalRepositoryImpl(realm) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/PexelApplication.kt
1813914904
package ir.mirdar.pexelmovieapp import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class PexelApplication : Application() { }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/local/model/RealmSource.kt
220803828
package ir.mirdar.pexelmovieapp.data.local.model import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.PrimaryKey import ir.mirdar.pexelmovieapp.domain.models.SourceModel import org.mongodb.kbson.ObjectId open class RealmSource : RealmObject { @PrimaryKey var id: ObjectId = ObjectId() var original: String? = null var large2x: String? = null var medium: String? = null var small: String? = null var portrait: String? = null var landscape: String? = null var tiny: String? = null } fun RealmSource.toModel(): SourceModel = SourceModel( original ?: "", large2x ?: "", medium ?: "", small ?: "", portrait ?: "", landscape ?: "", tiny ?: "", )
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/local/model/RealmPhoto.kt
3269198986
package ir.mirdar.pexelmovieapp.data.local.model import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.PrimaryKey import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import org.mongodb.kbson.ObjectId open class RealmPhoto : RealmObject { @PrimaryKey var id: ObjectId = ObjectId() var photoId: Long? = null var width: Long? = null var height: Long? = null var url: String? = null var photographer: String? = null var photographer_url: String? = null var photographer_id: Long? = null var avg_color: String? = null var alt: String? = null var liked: Boolean? = null var src: RealmSource? = null } fun RealmPhoto.toModel(): PhotoModel { return PhotoModel( photoId ?: 0, width ?: 0, height ?: 0, url ?: "", photographer ?: "", photographer_url ?: "", photographer_id ?: 0, avg_color ?: "", alt ?: "", liked ?: false, src?.toModel()!!, ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/local/model/RealmCurated.kt
508755194
package ir.mirdar.pexelmovieapp.data.local.model import io.realm.kotlin.ext.realmListOf import io.realm.kotlin.types.RealmList import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.PrimaryKey import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import org.mongodb.kbson.ObjectId open class RealmCurated: RealmObject { @PrimaryKey var id: ObjectId = ObjectId() var page: Int? = null var photos: RealmList<RealmPhoto> = realmListOf() } fun List<RealmPhoto>.toModel(): List<PhotoModel> = this.map { it.toModel() } fun RealmCurated.toModel(): CuratedModel { return CuratedModel( page = page ?: 0, photos = photos.toModel() ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/local/LocalRepositoryImpl.kt
3359271525
package ir.mirdar.pexelmovieapp.data.local import io.realm.kotlin.Realm import ir.mirdar.pexelmovieapp.data.local.model.RealmCurated import ir.mirdar.pexelmovieapp.data.local.model.RealmPhoto import ir.mirdar.pexelmovieapp.data.local.model.toModel import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import ir.mirdar.pexelmovieapp.domain.models.toEntity import ir.mirdar.pexelmovieapp.domain.repositories.LocalRepository import javax.inject.Inject class LocalRepositoryImpl @Inject constructor( private val realm: Realm ) : LocalRepository { override fun insertUpcomingModel(curatedModel: CuratedModel) { realm.writeBlocking { copyToRealm(curatedModel.toEntity()) } } override fun readImageDetail(photoId: Long) : PhotoModel? { val realmPhoto = realm.query(RealmPhoto::class, "photoId == $photoId").first().find() return realmPhoto?.toModel() } override fun readResultModels(page: Int) : CuratedModel? { val realmUpcomingModel = realm.query(RealmCurated::class, "page == $page").first().find() return realmUpcomingModel?.toModel() } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/common/Result.kt
3779868543
package ir.mirdar.pexelmovieapp.data.common /** * Created by Rim Gazzah on 8/28/20. **/ sealed class Result<out T> { data class Success<out T>(val data: T) : Result<T>() data class Error(val exception: CallErrors) : Result<Nothing>() data object Loading : Result<Nothing>() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/common/NetworkExtensions.kt
1324090807
package ir.mirdar.pexelmovieapp.data.common import ir.mirdar.pexelmovieapp.presentation.common.Utils import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.retryWhen import java.io.IOException fun <T : Any> Flow<Result<T>>.applyCommonSideEffects() = retryWhen { cause, attempt -> when { (cause is IOException && attempt < Utils.MAX_RETRIES) -> { delay(Utils.getBackoffDelay(attempt)) true } else -> { false } } }.onStart { emit(Result.Loading) }.catch { emit(Result.Error(CallErrors.ErrorException(it))) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/common/CallErrors.kt
649758870
package ir.mirdar.pexelmovieapp.data.common /** * Created by Rim Gazzah on 8/28/20. **/ sealed class CallErrors { data object ErrorEmptyData : CallErrors() data object ErrorServer: CallErrors() data class ErrorException(val throwable: Throwable) : CallErrors() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/RemoteRepositoryImpl.kt
1330888066
package ir.mirdar.pexelmovieapp.data.remote import ir.mirdar.pexelmovieapp.data.common.CallErrors import ir.mirdar.pexelmovieapp.data.common.Result import ir.mirdar.pexelmovieapp.data.common.applyCommonSideEffects import ir.mirdar.pexelmovieapp.data.remote.model.toModel import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.repositories.RemoteRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject class RemoteRepositoryImpl @Inject constructor (private val apiService: ApiService) : RemoteRepository { override fun getUpcomingList(page: Int): Flow<Result<CuratedModel>> = flow { apiService.getUpcomingList(page).run { if (this.isSuccessful) { if (this.body() == null) { emit(Result.Error(CallErrors.ErrorEmptyData)) } else { emit(Result.Success(this.body()!!.toModel())) } } else { emit(Result.Error(CallErrors.ErrorServer)) } } }.applyCommonSideEffects() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/RequestInterceptor.kt
307827356
package ir.mirdar.pexelmovieapp.data.remote import ir.mirdar.pexelmovieapp.presentation.common.Utils.API_KEY import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response import javax.inject.Inject class RequestInterceptor @Inject constructor() : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request() val newRequest : Request try { newRequest = request.newBuilder() .addHeader("Authorization", API_KEY) .build() } catch (e: Exception) { e.printStackTrace() return chain.proceed(request) } return chain.proceed(newRequest) } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/model/Photo.kt
3255721043
package ir.mirdar.pexelmovieapp.data.remote.model import ir.mirdar.pexelmovieapp.domain.models.PhotoModel data class Photo( val id: Long, val width: Long, val height: Long, val url: String, val photographer: String, val photographer_url: String, val photographer_id: Long, val avg_color: String, val alt: String, val liked: Boolean, val src: Source ) fun Photo.toModel(): PhotoModel { return PhotoModel( id, width, height, url, photographer, photographer_url, photographer_id, avg_color, alt, liked, src.toModel(), ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/model/Source.kt
4142219943
package ir.mirdar.pexelmovieapp.data.remote.model import ir.mirdar.pexelmovieapp.domain.models.SourceModel data class Source( val original: String, val large2x: String, val medium: String, val small: String, val portrait: String, val landscape: String, val tiny: String ) fun Source.toModel(): SourceModel { return SourceModel( original, large2x, medium, small, portrait, landscape, tiny ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/model/Curated.kt
2609835645
package ir.mirdar.pexelmovieapp.data.remote.model import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.models.PhotoModel data class Curated( val page: Int, val photos: List<Photo>, ) fun List<Photo>.toModel(): List<PhotoModel> { return this.map { it.toModel() } } fun Curated.toModel(): CuratedModel { return CuratedModel( page, photos.toModel() ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/data/remote/ApiService.kt
2554409350
package ir.mirdar.pexelmovieapp.data.remote import ir.mirdar.pexelmovieapp.data.remote.model.Curated import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Query interface ApiService { @GET("curated") suspend fun getUpcomingList( @Query("page") page: Int ) : Response<Curated> }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/GetUpcomingList.kt
2951093915
package ir.mirdar.pexelmovieapp.domain import ir.mirdar.pexelmovieapp.data.common.Result import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.repositories.LocalRepository import ir.mirdar.pexelmovieapp.domain.repositories.RemoteRepository import ir.mirdar.pexelmovieapp.presentation.common.Utils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.flow import kotlinx.coroutines.withContext import javax.inject.Inject class GetUpcomingList @Inject constructor(private val remoteRepository: RemoteRepository, private val localRepository: LocalRepository) { suspend operator fun invoke(page: Int) = withContext(Dispatchers.IO) { flow<Result<CuratedModel>> { remoteRepository.getUpcomingList(page).collect { response -> when (response) { is Result.Success -> { Utils.END_OF_PAGE = response.data.photos.isEmpty() Utils.IS_LOADING = false localRepository.insertUpcomingModel(response.data) val localResult = localRepository.readResultModels(page) localResult?.let { emit(Result.Success(it)) } } is Result.Error -> { val localResult = localRepository.readResultModels(page) Utils.IS_LOADING = false localResult?.let { emit(Result.Success(it)) } } is Result.Loading -> { Utils.IS_LOADING = true } } } } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/repositories/RemoteRepository.kt
1499928375
package ir.mirdar.pexelmovieapp.domain.repositories import ir.mirdar.pexelmovieapp.data.common.Result import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import kotlinx.coroutines.flow.Flow interface RemoteRepository { fun getUpcomingList(page : Int) : Flow<Result<CuratedModel>> }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/repositories/LocalRepository.kt
2741770448
package ir.mirdar.pexelmovieapp.domain.repositories import ir.mirdar.pexelmovieapp.domain.models.CuratedModel import ir.mirdar.pexelmovieapp.domain.models.PhotoModel interface LocalRepository { fun insertUpcomingModel(upcomingModel: CuratedModel) fun readResultModels(page : Int): CuratedModel? fun readImageDetail(photoId: Long): PhotoModel? }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/models/PhotoModel.kt
2681909715
package ir.mirdar.pexelmovieapp.domain.models import ir.mirdar.pexelmovieapp.data.local.model.RealmPhoto data class PhotoModel( val id : Long, val width : Long, val height : Long, val url : String, val photographer : String, val photographer_url : String, val photographer_id : Long, val avg_color : String, val alt : String, val liked : Boolean, val src : SourceModel ) fun PhotoModel.toEntity(): RealmPhoto { return RealmPhoto().also { it.photoId = id it.width = width it.height = height it.url = url it.photographer = photographer it.photographer_url = photographer_url it.photographer_id = photographer_id it.avg_color = avg_color it.alt = alt it.liked = liked it.src = src.toEntity() } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/models/CuratedModel.kt
3064399497
package ir.mirdar.pexelmovieapp.domain.models import io.realm.kotlin.ext.toRealmList import io.realm.kotlin.types.RealmList import ir.mirdar.pexelmovieapp.data.local.model.RealmCurated import ir.mirdar.pexelmovieapp.data.local.model.RealmPhoto data class CuratedModel( val page: Int, val photos: List<PhotoModel>, ) fun List<PhotoModel>.toEntity(): RealmList<RealmPhoto> { return this.map { it.toEntity() }.toRealmList() } fun CuratedModel.toEntity(): RealmCurated { return RealmCurated().also { it.page = page it.photos = photos.toEntity() } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/models/SourceModel.kt
2787350177
package ir.mirdar.pexelmovieapp.domain.models import ir.mirdar.pexelmovieapp.data.local.model.RealmSource data class SourceModel( val original : String, val large2x : String, val medium : String, val small : String, val portrait : String, val landscape : String, val tiny : String ) fun SourceModel.toEntity(): RealmSource { return RealmSource().also { it.original = original it.large2x = large2x it.medium = medium it.small = small it.portrait = portrait it.landscape = landscape it.tiny = tiny } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/domain/GetImageDetail.kt
2332354169
package ir.mirdar.pexelmovieapp.domain import ir.mirdar.pexelmovieapp.data.common.Result import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import ir.mirdar.pexelmovieapp.domain.repositories.LocalRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.flow import kotlinx.coroutines.withContext import javax.inject.Inject class GetImageDetail @Inject constructor( private val localRepository: LocalRepository ) { suspend operator fun invoke(photoId : Long) = withContext(Dispatchers.IO) { flow { emit(Result.Loading) val photoModel = localRepository.readImageDetail(photoId) emit(Result.Success(photoModel)) } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/AppNavHost.kt
4276945042
package ir.mirdar.pexelmovieapp.presentation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.navArgument import ir.mirdar.pexelmovieapp.presentation.discovery.DiscoveryScreen import ir.mirdar.pexelmovieapp.presentation.detail.ImageDetailScreen import ir.mirdar.pexelmovieapp.presentation.screens.SplashScreen @Composable fun AppNavHost( modifier: Modifier = Modifier, navController: NavHostController, startDestination: String = NavigationItem.Splash.route ) { NavHost( modifier = modifier, navController = navController, startDestination = startDestination ) { composable(NavigationItem.Splash.route) { SplashScreen(navController) } composable(NavigationItem.Discovery.route) { DiscoveryScreen(navController) } composable( "detail/{photoId}", arguments = listOf(navArgument("photoId") { type = NavType.LongType }) ) { backStack -> val photoId = backStack.arguments?.getLong("photoId") ?: 0 ImageDetailScreen(navController, photoId) } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/AppNavigation.kt
2886522971
package ir.mirdar.pexelmovieapp.presentation enum class Screen { DISCOVERY, SPLASH } sealed class NavigationItem(val route: String) { data object Discovery : NavigationItem(Screen.DISCOVERY.name) data object Splash : NavigationItem(Screen.SPLASH.name) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/MainActivity.kt
3397591793
package ir.mirdar.pexelmovieapp.presentation import android.os.Bundle import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.ui.Modifier import androidx.navigation.compose.rememberNavController import dagger.hilt.android.AndroidEntryPoint import ir.mirdar.pexelmovieapp.presentation.common.BaseActivity import ir.mirdar.pexelmovieapp.presentation.discovery.HomeAction import ir.mirdar.pexelmovieapp.presentation.discovery.HomeIntent import ir.mirdar.pexelmovieapp.presentation.discovery.HomeState import ir.mirdar.pexelmovieapp.presentation.theme.PexelTheme @AndroidEntryPoint class MainActivity : BaseActivity<HomeIntent, HomeAction, HomeState>() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { val navController = rememberNavController() PexelTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { AppNavHost( navController = navController, startDestination = NavigationItem.Splash.route ) } } } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/discovery/CuratedViewModel.kt
927251866
package ir.mirdar.pexelmovieapp.presentation.discovery import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import ir.mirdar.pexelmovieapp.domain.GetUpcomingList import ir.mirdar.pexelmovieapp.presentation.common.BaseViewModel import ir.mirdar.pexelmovieapp.presentation.discovery.HomeAction import ir.mirdar.pexelmovieapp.presentation.discovery.HomeIntent import ir.mirdar.pexelmovieapp.presentation.discovery.HomeState import ir.mirdar.pexelmovieapp.presentation.common.reduce import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class CuratedViewModel @Inject constructor( private val getUpcomingList: GetUpcomingList ) : BaseViewModel<HomeIntent, HomeAction, HomeState>() { var currentPage = 0 private val mState : MutableStateFlow<HomeState> = MutableStateFlow(HomeState.Loading) override val state: StateFlow<HomeState> get() = mState.asStateFlow() init { dispatchIntent(HomeIntent.LoadUpcomingList(1)) } override fun intentToAction(intent: HomeIntent): HomeAction { return when (intent) { is HomeIntent.LoadUpcomingList -> { currentPage = intent.page HomeAction.LoadList(intent.page) } } } override fun handleAction(action: HomeAction) { when(action) { is HomeAction.LoadList -> { fetchUpcomingList(action.page) } } } private fun fetchUpcomingList(page: Int) { viewModelScope.launch { getUpcomingList(page = page).collect { mState.value = it.reduce() } } } } data class Su( val int : Int )
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/discovery/HomeState.kt
1973531017
package ir.mirdar.pexelmovieapp.presentation.discovery import ir.mirdar.pexelmovieapp.data.common.CallErrors import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import ir.mirdar.pexelmovieapp.presentation.common.ViewState sealed class HomeState : ViewState { data object Loading : HomeState() data class ResultAllUpcomingList(val data : List<PhotoModel>): HomeState() data class Exception(val callErrors: CallErrors) : HomeState() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/discovery/CuratedListScreen.kt
1366182036
package ir.mirdar.pexelmovieapp.presentation.discovery import android.app.Activity import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Card import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.TextUnitType import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import coil.compose.AsyncImage import coil.request.ImageRequest import ir.mirdar.pexelmovieapp.R import ir.mirdar.pexelmovieapp.domain.models.PhotoModel import ir.mirdar.pexelmovieapp.domain.models.SourceModel import ir.mirdar.pexelmovieapp.presentation.common.Utils val sampleModel = PhotoModel( id = 1234, width = 4000, height = 6000, url = "", photographer = "Mohamamd mirdar", photographer_url = "", photographer_id = 12345, avg_color = "", alt = "", liked = true, src = SourceModel( original = "", large2x = "", medium = "", small = "", portrait = "", landscape = "", tiny = "" ) ) @OptIn(ExperimentalMaterial3Api::class) @Composable fun DiscoveryScreen( navController: NavController, viewModel: CuratedViewModel = hiltViewModel() ) { val state = viewModel.state.collectAsState() val lazyMovieItem = remember { state } val upcomingList = remember { mutableStateListOf<PhotoModel>() } val listStat = rememberLazyGridState() Scaffold( topBar = { CenterAlignedTopAppBar( title = { Text( text = "Discover", fontWeight = FontWeight.Bold, color = Color.Red ) }, actions = { IconButton(onClick = { /*TODO*/ }) { Icon( painter = painterResource(id = R.drawable.pexel), contentDescription = "pexel logo", tint = Color.Unspecified, modifier = Modifier .width(35.dp) .height(35.dp) ) } }, ) } ) { if (lazyMovieItem.value is HomeState.Exception) { } LazyVerticalGrid( state = listStat, columns = GridCells.Fixed(3), modifier = Modifier.padding(it) ) { if (lazyMovieItem.value is HomeState.ResultAllUpcomingList) { val result = lazyMovieItem.value as HomeState.ResultAllUpcomingList upcomingList.addAll(result.data) items(upcomingList.size) { index -> if (index >= upcomingList.size - 1 && !Utils.IS_LOADING && !Utils.END_OF_PAGE) { viewModel.dispatchIntent(HomeIntent.LoadUpcomingList(viewModel.currentPage + 1)) } MovieItem( photoModel = upcomingList[index], onClick = { navController.navigate("detail/$it") }) } } item { if (lazyMovieItem.value is HomeState.Loading) { Row( modifier = Modifier .fillMaxWidth() .padding(8.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center ) { CircularProgressIndicator() } } } } } val activity = (LocalContext.current as Activity) BackHandler { activity.finish() } } @OptIn(ExperimentalMaterial3Api::class) @Composable @Preview fun MovieItem(photoModel: PhotoModel = sampleModel, onClick: (photoId: Long) -> Unit = {}) { Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { Card( modifier = Modifier .wrapContentWidth() .wrapContentHeight() .padding(4.dp) .background(color = Color(0xFFEBF7FE)), shape = RoundedCornerShape(size = 12.dp), onClick = { onClick(photoModel.id) } ) { AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(photoModel.src.medium) .crossfade(true) .build(), contentDescription = "Movie image", modifier = Modifier .width(119.dp) .height(154.dp), contentScale = ContentScale.Crop ) } Text( text = photoModel.photographer, color = Color.Black, fontSize = TextUnit(12f, TextUnitType.Sp), fontWeight = FontWeight.Bold, modifier = Modifier.padding(19.dp), maxLines = 1 ) } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/discovery/HomeIntent.kt
961798525
package ir.mirdar.pexelmovieapp.presentation.discovery import ir.mirdar.pexelmovieapp.presentation.common.ViewIntent sealed class HomeIntent : ViewIntent { data class LoadUpcomingList(val page: Int) : HomeIntent() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/discovery/HomeAction.kt
1451230531
package ir.mirdar.pexelmovieapp.presentation.discovery import ir.mirdar.pexelmovieapp.presentation.common.ViewAction sealed class HomeAction : ViewAction { data class LoadList(val page: Int) : HomeAction() }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/screens/AvailableScreen.kt
2920534077
import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import ir.mirdar.pexelmovieapp.R @Composable @Preview fun AvailableScreen() { Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, modifier = Modifier.fillMaxSize() ) { Image( painter = painterResource(id = R.drawable.pexel), contentDescription = "Large logo", modifier = Modifier .width(88.dp) .height(88.dp) ) IndeterminateCircularIndicator() } } @Composable fun IndeterminateCircularIndicator() { var loading by remember { mutableStateOf(true) } if (!loading) return CircularProgressIndicator( modifier = Modifier .width(32.dp) .padding(top = 50.dp), color = Color.Green, ) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/screens/UnAvailableScreen.kt
1787535293
import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.TextUnitType import androidx.compose.ui.unit.dp import ir.mirdar.pexelmovieapp.R @Composable @Preview fun UnAvailableScreen() { Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, modifier = Modifier.fillMaxSize() ) { Image( painter = painterResource(id = R.drawable.glitch_logo), contentDescription = "glitch logo", modifier = Modifier.size(96.dp) ) Spacer(modifier = Modifier.height(16.dp)) Text( text = "Connection glitch", fontWeight = FontWeight.Bold, fontSize = TextUnit(16f, TextUnitType.Sp), color = Color.White ) Text( text = "Seems like there's an internet\n" + "connection problem.", textAlign = TextAlign.Center, color = MaterialTheme.colorScheme.onSurfaceVariant ) Spacer(modifier = Modifier.height(24.dp)) Button(onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.onSurfaceVariant)) { Text(text = "Retry") } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/screens/SplashScreen.kt
2618116472
package ir.mirdar.pexelmovieapp.presentation.screens import AvailableScreen import UnAvailableScreen import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.getValue import androidx.compose.runtime.produceState import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import ir.mirdar.pexelmovieapp.presentation.NavigationItem import ir.mirdar.pexelmovieapp.presentation.helper.ConnectionState import ir.mirdar.pexelmovieapp.presentation.helper.currentConnectivityStatus import ir.mirdar.pexelmovieapp.presentation.helper.observeConnectivityAsFlow @Composable fun SplashScreen( navController: NavController ) { val connection by connectivityStatus() val isConnected = connection === ConnectionState.Available if (isConnected) { navController.navigate(NavigationItem.Discovery.route) } Scaffold { if (isConnected) { AvailableScreen() } else { UnAvailableScreen() } } } @Composable fun connectivityStatus(): State<ConnectionState> { val context = LocalContext.current return produceState(initialValue = context.currentConnectivityStatus) { context.observeConnectivityAsFlow().collect { value = it } } }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/common/ViewAction.kt
4127238931
package ir.mirdar.pexelmovieapp.presentation.common /** * Created by Rim Gazzah on 8/26/20. **/ interface ViewAction
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/common/Utils.kt
1622711926
package ir.mirdar.pexelmovieapp.presentation.common object Utils { const val API_KEY = "Ex0Hq63A52ZkeqvXc28ryNBNFW6LveesRxtPhIkY0aXRTv4bEQtS40h5" const val BASE_URL = "https://api.pexels.com/v1/" const val IMAGE_BASE_URL = "https://api.pexels.com/v1/photos/" const val MAX_RETRIES = 1L private const val INITIAL_BACKOFF = 2000L var IS_LOADING = false var END_OF_PAGE: Boolean = false fun getBackoffDelay(attempt: Long) = INITIAL_BACKOFF * (attempt + 1) }
PexelApp/app/src/main/java/ir/mirdar/pexelmovieapp/presentation/common/BaseViewModel.kt
229700810
package ir.mirdar.pexelmovieapp.presentation.common import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch /** * Created by Rim Gazzah on 8/20/20. **/ abstract class BaseViewModel<INTENT : ViewIntent, ACTION : ViewAction, STATE : ViewState> : ViewModel(), IModel<STATE, INTENT> { fun launchOnUI(block: suspend CoroutineScope.() -> Unit) { viewModelScope.launch { block() } } final override fun dispatchIntent(intent: INTENT) { handleAction(intentToAction(intent)) } abstract fun intentToAction(intent: INTENT): ACTION abstract fun handleAction(action: ACTION) }