Initial commit
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
99
app/build.gradle.kts
Normal file
@ -0,0 +1,99 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
@Suppress("DSL_SCOPE_VIOLATION")
|
||||
plugins {
|
||||
id(libs.plugins.android.application.get().pluginId)
|
||||
id(libs.plugins.kotlin.android.get().pluginId)
|
||||
id(libs.plugins.kotlin.kapt.get().pluginId)
|
||||
id(libs.plugins.kotlin.parcelize.get().pluginId)
|
||||
}
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
applicationId = "ru.myitschool.lab23"
|
||||
versionCode = 1
|
||||
versionName = "0.0.1"
|
||||
|
||||
targetSdk = 33
|
||||
minSdk = 27
|
||||
compileSdk = 33
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
lint {
|
||||
warningsAsErrors = true
|
||||
ignoreWarnings = false
|
||||
abortOnError = true
|
||||
checkAllWarnings = true
|
||||
lintConfig = file("lint.xml")
|
||||
lint {
|
||||
disable.addAll(
|
||||
listOf(
|
||||
"InvalidPackage",
|
||||
"UnusedIds",
|
||||
"GradleDependency",
|
||||
"UnusedResources",
|
||||
"UnknownNullness",
|
||||
"SyntheticAccessor",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
val lintTask = tasks["lint${name.capitalize()}"]
|
||||
assembleProvider.get().dependsOn.add(lintTask)
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
}
|
||||
namespace = "ru.myitschool.lab23"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(libs.android.material)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.androidx.lifecycle.livedata.ktx)
|
||||
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.koin.core)
|
||||
implementation(libs.koin.android)
|
||||
implementation(libs.androidx.constraintlayout)
|
||||
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.androidx.navigation.fragment)
|
||||
implementation(libs.androidx.navigation.ui)
|
||||
|
||||
// Networking
|
||||
implementation(libs.retrofit.core)
|
||||
implementation(libs.retrofit.kotlin.serialization)
|
||||
implementation(libs.retrofit.converter.gson)
|
||||
implementation(libs.retrofit.converter.jackson)
|
||||
implementation(libs.retrofit.converter.moshi)
|
||||
implementation(libs.retrofit.converter.protobuf)
|
||||
implementation(libs.okhttp.logging)
|
||||
implementation(libs.volley)
|
||||
|
||||
implementation(libs.kotlinx.coroutines.android)
|
||||
|
||||
debugImplementation(libs.leakcanary)
|
||||
|
||||
androidTestImplementation(libs.truth)
|
||||
androidTestImplementation(libs.kakao)
|
||||
androidTestImplementation(libs.androidx.test.uiautomator)
|
||||
androidTestImplementation(libs.androidx.test.ext)
|
||||
androidTestImplementation(libs.androidx.test.runner)
|
||||
androidTestImplementation(libs.androidx.test.rules)
|
||||
androidTestImplementation(libs.androidx.test.espresso.core)
|
||||
androidTestImplementation(libs.androidx.test.espresso.intents)
|
||||
androidTestImplementation(libs.androidx.navigation.testing)
|
||||
androidTestImplementation(libs.androidx.test.ext)
|
||||
androidTestImplementation(libs.androidx.test.rules)
|
||||
androidTestImplementation(libs.androidx.test.espresso.accessibility)
|
||||
androidTestImplementation(libs.kotlinx.coroutines.test)
|
||||
androidTestImplementation(kotlin("test"))
|
||||
testImplementation(libs.androidx.test.ext)
|
||||
}
|
44
app/lint.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
<issue id="UnusedAttribute" severity="error">
|
||||
<ignore regexp="importantForAutofill"/>
|
||||
<ignore regexp="autofillHints"/>
|
||||
</issue>
|
||||
<issue id="InvalidPackage">
|
||||
<ignore path="**/freemarker-2.*.*.jar" />
|
||||
<ignore path="**/nnio-0.2.jar"/>
|
||||
<ignore path="**/bcpkix-jdk15on-1.69.jar" />
|
||||
</issue>
|
||||
|
||||
<issue id="UnusedResources" severity="error">
|
||||
<ignore regexp="store_short_desc|store_full_desc|store_short_dev_desc|store_full_dev_desc" />
|
||||
</issue>
|
||||
|
||||
<issue id="UnusedResources">
|
||||
<ignore path="**/values-**/strings.xml" />
|
||||
<ignore path="**/values/setup.xml" />
|
||||
</issue>
|
||||
|
||||
<issue id="Typos">
|
||||
<ignore path="**/values-**/strings.xml" />
|
||||
<ignore path="**/values/setup.xml" />
|
||||
</issue>
|
||||
|
||||
<issue id="RestrictedApi" severity="error">
|
||||
<ignore path="build" />
|
||||
</issue>
|
||||
|
||||
<issue id="NewApi" severity="error">
|
||||
<ignore path="build" />
|
||||
</issue>
|
||||
|
||||
<issue id="ObsoleteLintCustomCheck" severity="warning">
|
||||
<ignore path="**/fragment-1.2.5/**/lint.jar" />
|
||||
<ignore path="**/work-runtime-2.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-butterknife-runtime-10.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-dagger-lint-aar-2.**.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-annotation-experimental-1.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-firebase-installations**/**/lint.jar" />
|
||||
<ignore path="**/appcompat-1.**/**/lint.jar" />
|
||||
</issue>
|
||||
</lint>
|
21
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,12 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.MethodSorters
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@MediumTest
|
||||
class RateServiceTest
|
27
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ru.myitschool.lab23">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Lab">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
59
app/src/main/java/ru/myitschool/lab23/MainActivity.kt
Normal file
@ -0,0 +1,59 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
lateinit var viewModel: MainViewModel
|
||||
lateinit var textRate: TextView
|
||||
lateinit var textTargetRate: EditText
|
||||
lateinit var rootView: View
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
initViewModel()
|
||||
initView()
|
||||
}
|
||||
|
||||
fun initViewModel() {
|
||||
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
|
||||
|
||||
viewModel.usdRate.observe(this) {
|
||||
textRate.text = it
|
||||
}
|
||||
|
||||
viewModel.onCreate()
|
||||
}
|
||||
|
||||
fun initView() {
|
||||
textRate = findViewById(R.id.textUsdRubRate)
|
||||
textTargetRate = findViewById(R.id.textTargetRate)
|
||||
rootView = findViewById(R.id.rootView)
|
||||
|
||||
findViewById<Button>(R.id.btnRefresh).setOnClickListener {
|
||||
viewModel.onRefreshClicked()
|
||||
}
|
||||
|
||||
findViewById<Button>(R.id.btnSubscribeToRate).setOnClickListener {
|
||||
val targetRate = textTargetRate.text.toString()
|
||||
val startRate = viewModel.usdRate.value
|
||||
|
||||
if (targetRate.isNotEmpty() && startRate?.isNotEmpty() == true) {
|
||||
RateCheckService.stopService(this)
|
||||
RateCheckService.startService(this, startRate, targetRate)
|
||||
} else if (targetRate.isEmpty()) {
|
||||
Snackbar.make(rootView, R.string.target_rate_empty, Snackbar.LENGTH_SHORT).show()
|
||||
} else if (startRate.isNullOrEmpty()) {
|
||||
Snackbar.make(rootView, R.string.current_rate_empty, Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
app/src/main/java/ru/myitschool/lab23/MainViewModel.kt
Normal file
@ -0,0 +1,33 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
val usdRate = MutableLiveData<String>()
|
||||
val rateCheckInteractor = RateCheckInteractor()
|
||||
|
||||
fun onCreate() {
|
||||
refreshRate()
|
||||
}
|
||||
|
||||
fun onRefreshClicked() {
|
||||
refreshRate()
|
||||
}
|
||||
|
||||
private fun refreshRate() {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
val rate = rateCheckInteractor.requestRate()
|
||||
// Log.d(TAG, "usdRate = $rate")
|
||||
usdRate.value = rate
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "MainViewModel"
|
||||
const val USD_RATE_URL = "https://www.freeforexapi.com/api/live?pairs=USDRUB"
|
||||
}
|
||||
}
|
41
app/src/main/java/ru/myitschool/lab23/NetworkClient.kt
Normal file
@ -0,0 +1,41 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import android.util.Log
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
|
||||
class NetworkClient {
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.addInterceptor(
|
||||
HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
},
|
||||
)
|
||||
.build()
|
||||
|
||||
fun request(url: String): String? {
|
||||
LatestUrl.latestUrl = url
|
||||
LatestUrl.attempts += 1
|
||||
val requestBuilder = Request.Builder()
|
||||
.url(url)
|
||||
.build()
|
||||
|
||||
try {
|
||||
val response = client.newCall(requestBuilder).execute()
|
||||
if (response.isSuccessful) {
|
||||
return response.body?.string()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("NetworkClient", "error during network call", e)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
object LatestUrl {
|
||||
var latestUrl = "Default"
|
||||
var attempts = 0
|
||||
}
|
||||
}
|
33
app/src/main/java/ru/myitschool/lab23/RateCheckInteractor.kt
Normal file
@ -0,0 +1,33 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
|
||||
class RateCheckInteractor {
|
||||
val networkClient = NetworkClient()
|
||||
|
||||
suspend fun requestRate(): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val result = networkClient.request(MainViewModel.USD_RATE_URL)
|
||||
if (!result.isNullOrEmpty()) {
|
||||
parseRate(result)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseRate(jsonString: String): String {
|
||||
try {
|
||||
return JSONObject(jsonString)
|
||||
.getJSONObject("rates")
|
||||
.getJSONObject("USDRUB")
|
||||
.getString("rate")
|
||||
} catch (e: Exception) {
|
||||
Log.e("RateCheckInteractor", "", e)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
81
app/src/main/java/ru/myitschool/lab23/RateCheckService.kt
Normal file
@ -0,0 +1,81 @@
|
||||
package ru.myitschool.lab23
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.math.BigDecimal
|
||||
|
||||
class RateCheckService : Service() {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
var rateCheckAttempt = 0
|
||||
lateinit var startRate: BigDecimal
|
||||
lateinit var targetRate: BigDecimal
|
||||
val rateCheckInteractor = RateCheckInteractor()
|
||||
|
||||
val rateCheckRunnable: Runnable = Runnable {
|
||||
rateCheckAttempt++
|
||||
|
||||
if (rateCheckAttempt > RATE_CHECK_ATTEMPTS_MAX) {
|
||||
}
|
||||
|
||||
requestAndCheckRate()
|
||||
}
|
||||
|
||||
private fun requestAndCheckRate() {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
val rate = rateCheckInteractor.requestRate()
|
||||
val rateBigDecimal = BigDecimal(rate)
|
||||
if ((startRate >= targetRate && rateBigDecimal <= targetRate) ||
|
||||
(startRate < targetRate && rateBigDecimal >= targetRate)
|
||||
) {
|
||||
stopSelf()
|
||||
} else {
|
||||
handler.postDelayed(rateCheckRunnable, RATE_CHECK_INTERVAL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(p0: Intent?): IBinder? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
startRate = BigDecimal(intent?.getStringExtra(ARG_START_RATE))
|
||||
targetRate = BigDecimal(intent?.getStringExtra(ARG_TARGET_RATE))
|
||||
|
||||
handler.post(rateCheckRunnable)
|
||||
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
handler.removeCallbacks(rateCheckRunnable)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "RateCheckService"
|
||||
const val RATE_CHECK_INTERVAL = 4000L
|
||||
const val RATE_CHECK_ATTEMPTS_MAX = 10
|
||||
|
||||
const val ARG_START_RATE = "ARG_START_RATE"
|
||||
const val ARG_TARGET_RATE = "ARG_TARGET_RATE"
|
||||
|
||||
fun startService(context: Context, startRate: String, targetRate: String) {
|
||||
context.startService(
|
||||
Intent(context, RateCheckService::class.java).apply {
|
||||
putExtra(ARG_START_RATE, startRate)
|
||||
putExtra(ARG_TARGET_RATE, targetRate)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun stopService(context: Context) {
|
||||
context.stopService(Intent(context, RateCheckService::class.java))
|
||||
}
|
||||
}
|
||||
}
|
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3E91FF"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
30
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
78
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/rootView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/labelUsdRubRate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/usd_rate"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textUsdRubRate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="@string/current_rate_empty"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/labelUsdRubRate"
|
||||
app:layout_constraintTop_toTopOf="@id/labelUsdRubRate" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRefresh"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/refresh_rate"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/labelUsdRubRate" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/labelTargetRate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/target_rate"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
app:layout_constraintBottom_toBottomOf="@id/textTargetRate"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/textTargetRate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="center"
|
||||
android:hint="@string/sample_rate"
|
||||
android:inputType="numberDecimal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/labelTargetRate"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnRefresh"
|
||||
android:importantForAutofill="no" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSubscribeToRate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/subscribe"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/textTargetRate" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 7.6 KiB |
10
app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="blue_200">#3E91FF</color>
|
||||
<color name="blue_500">#0381FE</color>
|
||||
<color name="blue_700">#0072DE</color>
|
||||
<color name="teal_200">#3E91FF</color>
|
||||
<color name="teal_700">#3E91FF</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
11
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
<string name="app_name">Get Rate</string>
|
||||
<string name="refresh_rate">refresh</string>
|
||||
<string name="usd_rate">Current rate:</string>
|
||||
<string name="target_rate_empty">Target rate is empty</string>
|
||||
<string name="current_rate_empty">Current rate is empty</string>
|
||||
<string name="subscribe">subscribe</string>
|
||||
<string name="target_rate">Target rate</string>
|
||||
<string name="limit_reached">Maximum number of requests reached</string>
|
||||
<string name="sample_rate">75.12</string>
|
||||
</resources>
|
22
app/src/main/res/values/themes.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Lab" parent="Theme.Material3.DayNight">
|
||||
<!-- Primary color -->
|
||||
<item name="colorPrimary">@color/blue_500</item>
|
||||
<item name="colorPrimaryVariant">@color/blue_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary color -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Floating Action Button Container -->
|
||||
<item name="colorPrimaryContainer">@color/blue_500</item>
|
||||
<!--ActionBar -->
|
||||
<item name="colorSurface">@color/blue_700</item>
|
||||
<item name="colorOnSurface">@color/white</item>
|
||||
|
||||
<item name="android:navigationBarColor">@color/blue_200</item>
|
||||
<item name="android:windowLightNavigationBar">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
17
app/src/test/java/ru/myitschool/lab23/ExampleUnitTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ru.myitschool.lab23;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|