Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Axhaat committed Mar 23, 2023
0 parents commit 1738f42
Show file tree
Hide file tree
Showing 57 changed files with 1,317 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
.idea/gradle.xml
.idea/vcs.xml
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

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

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

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

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

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Derrick

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Todolist
Android Todolist simple app for leanring MVVM Architecture
You can simply check and know the techniques below

- Room
- MVVM Architecture
- Coroutines basic
- Defedency Injetion with Kodein-DI
- Live Data






1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
78 changes: 78 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}

android {
compileSdk 31

defaultConfig {
applicationId "jinyoung.dev.todolist"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}



buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}

}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

def room_version = '2.4.0'
def kodein_version = "6.4.0"
def lifecycle_version = "2.0.0"

// Room and Architectural Components
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation "androidx.room:room-ktx:2.2.1"
kapt "androidx.room:room-compiler:$room_version"



// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"

// New Material Design
implementation "com.google.android.material:material:1.0.0"

// ViewModel
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

// Kodein
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package jinyoung.dev.todolist

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("jinyoung.dev.mvvmsample", appContext.packageName)
}
}
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jinyoung.dev.todolist">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name="jinyoung.dev.todolist.TodoListApplication"
android:theme="@style/Theme.MVVMSample">
<activity
android:name="jinyoung.dev.todolist.ui.actionitem.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>
32 changes: 32 additions & 0 deletions app/src/main/java/jinyoung/dev/todolist/TodoListApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package jinyoung.dev.todolist

import android.app.Application
import jinyoung.dev.todolist.data.db.ActionDatabase
import jinyoung.dev.todolist.repositories.ActionRepository
import jinyoung.dev.todolist.ui.actionitem.ActionItemViewModelFactory

import org.kodein.di.Kodein
import org.kodein.di.KodeinAware
import org.kodein.di.android.x.androidXModule
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.provider
import org.kodein.di.generic.singleton

class TodoListApplication: Application(), KodeinAware {

override val kodein: Kodein = Kodein.lazy {
import(androidXModule(this@TodoListApplication))
bind() from singleton { ActionDatabase(instance()) }
bind() from singleton {
ActionRepository(
instance()
)
}
bind() from provider {
ActionItemViewModelFactory(
instance()
)
}
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/jinyoung/dev/todolist/data/db/ActionDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jinyoung.dev.todolist.data.db

import androidx.lifecycle.LiveData
import androidx.room.*
import jinyoung.dev.todolist.data.db.entities.ActionItem

@Dao
interface ActionDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsert(item: ActionItem)

@Delete
suspend fun delete(item: ActionItem)

@Query("SELECT * FROM action_items")
fun getAllActionItems(): LiveData<List<ActionItem>>

}
34 changes: 34 additions & 0 deletions app/src/main/java/jinyoung/dev/todolist/data/db/ActionDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package jinyoung.dev.todolist.data.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import jinyoung.dev.todolist.data.db.entities.ActionItem

@Database(
entities = [ActionItem::class],
version = 1
)
abstract class ActionDatabase: RoomDatabase() {

abstract fun getActionDao(): ActionDao

companion object {
@Volatile
private var instance: ActionDatabase? = null
private val LOCK = Any()

operator fun invoke(context: Context) = instance
?: synchronized(LOCK) {
instance
?: createDatabase(
context
).also { instance = it }
}

private fun createDatabase(context: Context) =
Room.databaseBuilder(context.applicationContext,
ActionDatabase::class.java, "ActionItemDB.db").build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jinyoung.dev.todolist.data.db.entities

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "action_items")
data class ActionItem(
@ColumnInfo(name = "item_name")
var name: String,
@ColumnInfo(name = "item_amount")
var amount: Int,

@ColumnInfo(name = "item_staus")
var status: Boolean
) {
@PrimaryKey(autoGenerate = true)
var id: Int? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jinyoung.dev.todolist.repositories

import jinyoung.dev.todolist.data.db.ActionDatabase
import jinyoung.dev.todolist.data.db.entities.ActionItem

class ActionRepository(
private val db: ActionDatabase
) {
suspend fun upsert(item: ActionItem) = db.getActionDao().upsert(item)

suspend fun delete(item: ActionItem) = db.getActionDao().delete(item)

fun getAllActionItems() = db.getActionDao().getAllActionItems()
}
Loading

0 comments on commit 1738f42

Please sign in to comment.