diff --git a/.idea/appInsightsSettings.xml b/.idea/appInsightsSettings.xml new file mode 100644 index 0000000..4aea96f --- /dev/null +++ b/.idea/appInsightsSettings.xml @@ -0,0 +1,46 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index c00d563..411d2c6 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,23 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ce86a83..0897082 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,16 +4,15 @@ diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 1ea0cd8..1180ed2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - - + diff --git a/app/build.gradle b/app/build.gradle index af84cd7..b6f58cb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,8 +2,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - apply plugin: 'kotlin-kapt' def keystorePropertiesFile = rootProject.file("keystore.properties") @@ -11,16 +9,16 @@ def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { - compileSdkVersion 32 - buildToolsVersion '30.0.3' + compileSdk 34 + buildToolsVersion = '30.0.3' defaultConfig { applicationId "com.avs.sea.battle" minSdkVersion 19 - targetSdkVersion 32 - versionCode 8 - versionName "8" + targetSdkVersion 34 + versionCode 9 + versionName "9" vectorDrawables.useSupportLibrary = true - resConfigs "en", "uk", "ru" + resourceConfigurations += ['en', 'uk', 'ru'] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } signingConfigs { @@ -41,27 +39,39 @@ android { dataBinding { enabled = true } + buildFeatures { + viewBinding = true + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = '17' + } + namespace 'com.avs.sea.battle' } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.core:core-ktx:1.12.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.google.android.material:material:1.11.0' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' testImplementation "org.mockito:mockito-core:3.3.0" - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0" - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1" + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2" kapt "com.android.databinding:compiler:3.1.4" implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test:rules:1.5.0' implementation 'com.google.android.play:core:1.10.3' implementation 'com.google.android.play:core-ktx:1.8.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4983ed6..ac8935a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,12 +1,12 @@ - + when (event.action) { MotionEvent.ACTION_DOWN -> { - v.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent)) - setTextColor(v, R.color.colorPrimary) + v.setBackgroundColor(ContextCompat.getColor(this, R.color.greySelected)) } + MotionEvent.ACTION_UP -> { v.background = ContextCompat.getDrawable(this, R.drawable.square_background) - setTextColor(v, R.color.colorPrimaryDark) v.performClick() } } @@ -139,30 +138,45 @@ class MainActivity : AppCompatActivity(), PopupMenu.OnMenuItemClickListener { override fun onMenuItemClick(item: MenuItem): Boolean { return when (item.itemId) { R.id.share -> { - startActivity(Intent.createChooser(getShareIntent(this), - resources.getString(R.string.share_text))) + startActivity( + Intent.createChooser( + getShareIntent(this), + resources.getString(R.string.share_text) + ) + ) true } + R.id.rate -> { val call = { startActivity(openMarket(false)) } openActivity(call, R.string.cannot_open_market_error_text) true } + R.id.write_to_author -> { - val call = { startActivity(openGmail(this, RECIPIENTS, - resources.getString(R.string.app_name))) } + val call = { + startActivity( + openGmail( + this, RECIPIENTS, + resources.getString(R.string.app_name) + ) + ) + } openActivity(call, R.string.cannot_send_email_error_text) true } + R.id.more_apps -> { val call = { startActivity(openMarket(true)) } openActivity(call, R.string.cannot_open_market_error_text) true } + R.id.privacy_policy -> { startActivity(Intent(this, PrivacyPolicyActivity::class.java)) true } + else -> false } } diff --git a/app/src/main/java/com/avs/sea/battle/main/MainViewModel.kt b/app/src/main/java/com/avs/sea/battle/main/MainViewModel.kt index c486f0f..e398ca3 100644 --- a/app/src/main/java/com/avs/sea/battle/main/MainViewModel.kt +++ b/app/src/main/java/com/avs/sea/battle/main/MainViewModel.kt @@ -131,7 +131,7 @@ class MainViewModel : ViewModel() { shotManager.handleShot(isShipHit) if (isShipHit) { viewModelScope.launch { - delay(SECOND_IN_MILLIS + SECOND_IN_MILLIS / 2) + delay(SECOND_IN_MILLIS) _computerSuccessfulShots.value = personBattleField.getCrossesCoordinates() if (personBattleField.isGameOver()) { endGame(false) @@ -142,7 +142,7 @@ class MainViewModel : ViewModel() { } } else { viewModelScope.launch { - delay(SECOND_IN_MILLIS + SECOND_IN_MILLIS / 2) + delay(SECOND_IN_MILLIS) _computerFailShots.value = personBattleField.getDotsCoordinates() activePlayer = Player.PERSON checkCurrentPlayer() diff --git a/app/src/main/java/com/avs/sea/battle/views/ComputerSquareView.kt b/app/src/main/java/com/avs/sea/battle/views/ComputerSquareView.kt index 0fd3110..1c273ef 100644 --- a/app/src/main/java/com/avs/sea/battle/views/ComputerSquareView.kt +++ b/app/src/main/java/com/avs/sea/battle/views/ComputerSquareView.kt @@ -40,25 +40,25 @@ class ComputerSquareView : SquareView { setOnTouchListener(OnTouchListener(getCustomOnTouchListener())) } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { super.onDraw(canvas) if (shipsCoordinates.isNotEmpty()) { for (ship in shipsCoordinates) { - canvas?.drawSquare(ship.y, ship.x, paintShipSquare) + canvas.drawSquare(ship.y, ship.x, paintShipSquare) } } if (dotsCoordinates.isNotEmpty()) { for (coordinate in dotsCoordinates) { - canvas?.drawDot(coordinate) + canvas.drawDot(coordinate) } } if (crossesCoordinates.isNotEmpty()) { for (cross in crossesCoordinates) { - canvas?.drawCross(cross.y, cross.x) + canvas.drawCross(cross.y, cross.x) } } if (selectedSquare != null) { - canvas?.drawSquare(selectedSquare!!.x, selectedSquare!!.y, paintSelected) + canvas.drawSquare(selectedSquare!!.x, selectedSquare!!.y, paintSelected) } } diff --git a/app/src/main/java/com/avs/sea/battle/views/PersonSquareView.kt b/app/src/main/java/com/avs/sea/battle/views/PersonSquareView.kt index 2057878..c04e8ed 100644 --- a/app/src/main/java/com/avs/sea/battle/views/PersonSquareView.kt +++ b/app/src/main/java/com/avs/sea/battle/views/PersonSquareView.kt @@ -30,21 +30,21 @@ class PersonSquareView : SquareView { crossesCoordinates = arrayListOf() } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { super.onDraw(canvas) if (shipsCoordinates.isNotEmpty()) { for (ship in shipsCoordinates) { - canvas?.drawSquare(ship.y, ship.x, paintShipSquare) + canvas.drawSquare(ship.y, ship.x, paintShipSquare) } } if (dotsCoordinates.isNotEmpty()) { for (coordinate in dotsCoordinates) { - canvas?.drawDot(coordinate) + canvas.drawDot(coordinate) } } if (crossesCoordinates.isNotEmpty()) { for (cross in crossesCoordinates) { - canvas?.drawCross(cross.y, cross.x) + canvas.drawCross(cross.y, cross.x) } } } diff --git a/app/src/main/java/com/avs/sea/battle/views/SquareView.kt b/app/src/main/java/com/avs/sea/battle/views/SquareView.kt index 944e57a..fa811f9 100644 --- a/app/src/main/java/com/avs/sea/battle/views/SquareView.kt +++ b/app/src/main/java/com/avs/sea/battle/views/SquareView.kt @@ -1,11 +1,14 @@ package com.avs.sea.battle.views import android.content.Context +import android.content.res.Configuration +import android.content.res.Configuration.UI_MODE_NIGHT_YES import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.graphics.Path import android.util.AttributeSet +import android.util.Log import android.util.TypedValue import android.view.View import androidx.core.content.ContextCompat @@ -13,6 +16,7 @@ import com.avs.sea.battle.R import com.avs.sea.battle.SQUARES_COUNT import com.avs.sea.battle.battle_field.Coordinate import com.avs.sea.battle.battle_field.CoordinateF +import com.avs.sea.battle.isDarkThemeOn import com.avs.sea.battle.main.MainViewModel abstract class SquareView : View { @@ -42,7 +46,7 @@ abstract class SquareView : View { private fun init(context: Context) { circleRadius = getFloatValue(context) paint = Paint() - paint.color = Color.BLACK + paint.color = if (isDarkThemeOn(context)) Color.WHITE else Color.BLACK paint.strokeWidth = lineWidth paintShipSquare = Paint() paintShipSquare.color = ContextCompat.getColor(context, R.color.greyTransparent) @@ -65,15 +69,19 @@ abstract class SquareView : View { screenWidth = MeasureSpec.getSize(widthMeasureSpec).toFloat() } - override fun onDraw(canvas: Canvas?) { - paint.color = Color.BLACK - paint.strokeWidth = lineWidth - canvas?.let { + override fun onDraw(canvas: Canvas) { + canvas.let { drawHorizontalLines(it) drawVerticalLines(it) } } + private fun getColor(): Int { + return if (resources.configuration.uiMode and + Configuration.UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES + ) Color.WHITE else Color.BLACK + } + private fun drawHorizontalLines(canvas: Canvas) { paint.strokeWidth = lineWidth for (i in 1..SQUARES_COUNT) { diff --git a/app/src/main/res/drawable/square_background.xml b/app/src/main/res/drawable/square_background.xml index db08dc7..2b094d5 100644 --- a/app/src/main/res/drawable/square_background.xml +++ b/app/src/main/res/drawable/square_background.xml @@ -1,8 +1,8 @@ - + + android:color="?attr/colorAccent"> \ No newline at end of file diff --git a/app/src/main/res/layout-land-v21/activity_main.xml b/app/src/main/res/layout-land-v21/activity_main.xml index c8d8007..51d1344 100644 --- a/app/src/main/res/layout-land-v21/activity_main.xml +++ b/app/src/main/res/layout-land-v21/activity_main.xml @@ -13,7 +13,6 @@ @@ -42,7 +41,6 @@ android:paddingEnd="@dimen/dimen_10dp" android:singleLine="true" android:text="@string/status_welcome_text" - android:textColor="@color/colorAccent" android:textSize="@dimen/text_size_16sp" app:layout_constraintEnd_toEndOf="@+id/viewComputer" app:layout_constraintStart_toStartOf="@+id/viewPerson" @@ -143,7 +141,7 @@ style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:indeterminateTint="@color/colorAccent" + android:indeterminateTint="?attr/colorAccent" android:indeterminateTintMode="src_in" android:visibility="invisible" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index b70358a..56e9be4 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -13,7 +13,6 @@ @@ -42,7 +41,6 @@ android:paddingEnd="@dimen/dimen_10dp" android:singleLine="true" android:text="@string/status_welcome_text" - android:textColor="@color/colorAccent" android:textSize="@dimen/text_size_16sp" app:layout_constraintEnd_toEndOf="@+id/viewComputer" app:layout_constraintStart_toStartOf="@+id/viewPerson" diff --git a/app/src/main/res/layout-v21/activity_main.xml b/app/src/main/res/layout-v21/activity_main.xml index 1b7f1fe..79876e1 100644 --- a/app/src/main/res/layout-v21/activity_main.xml +++ b/app/src/main/res/layout-v21/activity_main.xml @@ -13,7 +13,6 @@ @@ -42,7 +41,6 @@ android:paddingEnd="@dimen/dimen_10dp" android:singleLine="false" android:text="@string/status_welcome_text" - android:textColor="@color/colorAccent" android:textSize="@dimen/text_size_16sp" android:layout_marginStart="@dimen/dimen_4dp" android:layout_marginEnd="@dimen/dimen_4dp" @@ -148,7 +146,7 @@ style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:indeterminateTint="@color/colorAccent" + android:indeterminateTint="?attr/colorAccent" android:indeterminateTintMode="src_in" android:visibility="invisible" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a1b6ad9..4db1cf6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,7 +13,6 @@ @@ -45,7 +44,6 @@ android:maxLines="2" android:layout_marginStart="@dimen/dimen_4dp" android:layout_marginEnd="@dimen/dimen_4dp" - android:textColor="@color/colorAccent" android:textSize="@dimen/text_size_16sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c226642..a51be69 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,6 +3,6 @@ #FFFFFF #808080 #000000 - #33808080 - #7C808080 + #99C1C0C0 + #99808080 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 502ba70..5dba393 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,14 +1,15 @@ - - diff --git a/build.gradle b/build.gradle index e50e635..0659ab7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.7.0' + ext.kotlin_version = '1.9.0' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.1' + classpath 'com.android.tools.build:gradle:8.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index 23339e0..95b9377 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,3 +19,6 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=true +android.nonFinalResIds=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 701b567..1fb451e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip