Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase target sdk, support dark theme #2

Merged
merged 13 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 26 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

def keystorePropertiesFile = rootProject.file("keystore.properties")
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 {
Expand All @@ -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'
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avs.sea.battle">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:appCategory="game"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/avs/sea/battle/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ResolveInfo
import android.content.res.Configuration
import android.graphics.Color
import android.net.Uri
import java.util.*

Expand Down Expand Up @@ -44,4 +46,9 @@ fun openMarket(showAppsList: Boolean): Intent {
Uri.parse("market://details?id=$NAMESPACE")
}
return Intent(Intent.ACTION_VIEW, uri)
}

fun isDarkThemeOn(context: Context): Boolean {
return context.resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
}
28 changes: 21 additions & 7 deletions app/src/main/java/com/avs/sea/battle/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ class MainActivity : AppCompatActivity(), PopupMenu.OnMenuItemClickListener {
return { v: View, event: MotionEvent ->
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()
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/avs/sea/battle/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/avs/sea/battle/views/ComputerSquareView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading
Loading