diff --git a/.gitignore b/.gitignore index ccf832b..dad5d55 100644 --- a/.gitignore +++ b/.gitignore @@ -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. @@ -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 diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index ac216bc..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 526b4c2..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 55138b2..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 971e29b..b7f0dbd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" @@ -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' // добавлено @@ -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" @@ -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' } \ No newline at end of file diff --git a/app/src/main/java/com/daniilmaster/storageanimal/db/AnimalEntity.kt b/app/src/main/java/com/daniilmaster/storageanimal/db/AnimalEntity.kt index 4176df1..5e17089 100644 --- a/app/src/main/java/com/daniilmaster/storageanimal/db/AnimalEntity.kt +++ b/app/src/main/java/com/daniilmaster/storageanimal/db/AnimalEntity.kt @@ -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 \ No newline at end of file diff --git a/app/src/main/java/com/daniilmaster/storageanimal/db/AppDatabase.kt b/app/src/main/java/com/daniilmaster/storageanimal/db/AppDatabase.kt index 983ecf8..c0f4908 100644 --- a/app/src/main/java/com/daniilmaster/storageanimal/db/AppDatabase.kt +++ b/app/src/main/java/com/daniilmaster/storageanimal/db/AppDatabase.kt @@ -17,6 +17,7 @@ abstract class AppDatabase : RoomDatabase() { companion object { @Volatile private var INSTANCE: AppDatabase? = null + private val lock = Any() fun getDatabase(context: Context): AppDatabase { @@ -24,12 +25,12 @@ abstract class AppDatabase : RoomDatabase() { 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 diff --git a/app/src/main/java/com/daniilmaster/storageanimal/db/AppHelperDatabase.kt b/app/src/main/java/com/daniilmaster/storageanimal/db/AppHelperDatabase.kt index cab73c1..7d8dd90 100644 --- a/app/src/main/java/com/daniilmaster/storageanimal/db/AppHelperDatabase.kt +++ b/app/src/main/java/com/daniilmaster/storageanimal/db/AppHelperDatabase.kt @@ -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" @@ -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) } @@ -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) diff --git a/app/src/main/java/com/daniilmaster/storageanimal/ui/fragments/list/ListFragment.kt b/app/src/main/java/com/daniilmaster/storageanimal/ui/fragments/list/ListFragment.kt index 387dc48..960762e 100644 --- a/app/src/main/java/com/daniilmaster/storageanimal/ui/fragments/list/ListFragment.kt +++ b/app/src/main/java/com/daniilmaster/storageanimal/ui/fragments/list/ListFragment.kt @@ -94,9 +94,9 @@ class ListFragment : Fragment(), OnDeleteFragment { // Обновление строения viewModel.allAnimals() - viewModel.animals.observe(viewLifecycleOwner, { listAnimals -> + viewModel.animals.observe(viewLifecycleOwner) { listAnimals -> adapter!!.setData(listAnimals) - }) + } } @@ -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)) { _, _ -> @@ -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)) { _, _ -> diff --git a/build.gradle b/build.gradle index 7b3dc1f..6c2a9ee 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d6a752b..9f54db4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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