Skip to content

Commit

Permalink
Update project (Gradle version) and fix not null
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilkofficial committed Jul 27, 2022
1 parent 61d18a7 commit d58ae27
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 118 deletions.
18 changes: 1 addition & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
/.idea/

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
Expand Down Expand Up @@ -88,12 +78,6 @@ lint/tmp/
*.hprof
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
Expand Down
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

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

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

32 changes: 0 additions & 32 deletions .idea/misc.xml

This file was deleted.

28 changes: 14 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ plugins {
}

android {
compileSdk 30
compileSdk 31

defaultConfig {
applicationId "com.daniilmaster.storageanimal"
minSdk 21
targetSdk 30
targetSdk 31
versionCode 3
versionName "1.2.4"

Expand Down Expand Up @@ -42,10 +42,10 @@ android {

dependencies {
// Main
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' // добавлено

Expand All @@ -55,9 +55,9 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

// Version
def navigation = "2.3.5"
def room = "2.3.0"
def coroutines = "1.5.1"
def navigation = '2.5.0'
def room = '2.4.2'
def coroutines = '1.6.4'

// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:$navigation"
Expand All @@ -71,18 +71,18 @@ dependencies {

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation 'androidx.lifecycle:lifecycle-common-java8:2.5.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0'

// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30"
implementation 'org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.5.30'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10'
implementation 'org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.7.10'
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"

// DataBinding
kapt "com.android.databinding:compiler:3.2.0-alpha10"

implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.preference:preference-ktx:1.2.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
import org.jetbrains.annotations.NotNull

@Parcelize
@Entity(tableName = "animal_table")
data class AnimalEntity(
@PrimaryKey(autoGenerate = true)
val id: Int,
@NotNull val id: Int = 0,
// имя, год, порода
val name: String,
val age: Int,
val breed: String
@NotNull val name: String = "",
@NotNull val age: Int = 1,
@NotNull val breed: String = ""
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ abstract class AppDatabase : RoomDatabase() {
companion object {
@Volatile
private var INSTANCE: AppDatabase? = null
private val lock = Any()

fun getDatabase(context: Context): AppDatabase {

val temp = INSTANCE
if (temp != null) {
return temp
}
synchronized(true) {
synchronized(lock) {
val instance =
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"app_database"
"app_database_animal"
).build()

INSTANCE = instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppHelperDatabase(context: Context) :

// Имена (константы)
companion object {
private const val DATABASE_NAME = "app_database"
private const val DATABASE_NAME = "app_database_animal"
private const val DATABASE_VERSION = 1

private const val TABLE_NAME = "animal_table"
Expand All @@ -38,10 +38,10 @@ class AppHelperDatabase(context: Context) :
val createQuery = ("CREATE TABLE "
+ TABLE_NAME
+ "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_NAME + " TEXT,"
+ KEY_AGE + " INTEGER, "
+ KEY_BREED + " TEXT"
+ KEY_ID + " INTEGER PRIMARY KEY NOT NULL,"
+ KEY_NAME + " TEXT NOT NULL,"
+ KEY_AGE + " INTEGER NOT NULL,"
+ KEY_BREED + " TEXT NOT NULL"
+ ")")
db?.execSQL(createQuery)
}
Expand Down Expand Up @@ -119,10 +119,10 @@ class AppHelperDatabase(context: Context) :
if (cursor.moveToFirst()) { // от первого курсора
do {
// получаем данные из курсора
id = cursor.getInt(cursor.getColumnIndex(KEY_ID))
name = cursor.getString(cursor.getColumnIndex(KEY_NAME))
age = cursor.getInt(cursor.getColumnIndex(KEY_AGE))
breed = cursor.getString(cursor.getColumnIndex(KEY_BREED))
id = cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ID))
name = cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME))
age = cursor.getInt(cursor.getColumnIndexOrThrow(KEY_AGE))
breed = cursor.getString(cursor.getColumnIndexOrThrow(KEY_BREED))

val animal = AnimalEntity(id, name, age, breed) // сохраняем в модель
list.add(animal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class ListFragment : Fragment(), OnDeleteFragment {

// Обновление строения
viewModel.allAnimals()
viewModel.animals.observe(viewLifecycleOwner, { listAnimals ->
viewModel.animals.observe(viewLifecycleOwner) { listAnimals ->
adapter!!.setData(listAnimals)
})
}

}

Expand All @@ -115,9 +115,9 @@ class ListFragment : Fragment(), OnDeleteFragment {
showToast(getString(R.string.toast_delete_success) + animalEntity.name)

viewModel.allAnimals()
viewModel.animals.observe(viewLifecycleOwner, { listAnimals ->
viewModel.animals.observe(viewLifecycleOwner) { listAnimals ->
adapter!!.setData(listAnimals)
})
}

}
builder.setNegativeButton(getString(R.string.no)) { _, _ ->
Expand All @@ -138,9 +138,9 @@ class ListFragment : Fragment(), OnDeleteFragment {
showToast(R.string.toast_delete_all_success)

viewModel.allAnimals()
viewModel.animals.observe(viewLifecycleOwner, { listAnimals ->
viewModel.animals.observe(viewLifecycleOwner) { listAnimals ->
adapter!!.setData(listAnimals)
})
}

}
builder.setNegativeButton(getString(R.string.no)) { _, _ ->
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"

// поддержка Navigation
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha07"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Aug 19 19:43:42 MSK 2021
#Mon Jul 25 01:36:46 MSK 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit d58ae27

Please sign in to comment.