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

과제3 예시답안 #68

Open
wants to merge 3 commits into
base: assignment2-finish
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions assignment-3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.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
1 change: 1 addition & 0 deletions assignment-3/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
65 changes: 65 additions & 0 deletions assignment-3/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
id("kotlin-parcelize")
}

android {
namespace = "com.jutak.assignment3"
compileSdk = 34

defaultConfig {
applicationId = "com.jutak.assignment3"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = 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"
}
buildFeatures {
viewBinding = true
}
}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

implementation("androidx.activity:activity-ktx:1.7.2")
implementation("androidx.recyclerview:recyclerview:1.3.1")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.2")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
implementation("com.squareup.moshi:moshi:1.14.0")
implementation("com.squareup.moshi:moshi-kotlin:1.14.0")

implementation("com.google.dagger:hilt-android:2.47")
kapt("com.google.dagger:hilt-android-compiler:2.47")
}
21 changes: 21 additions & 0 deletions assignment-3/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 com.jutak.assignment3

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("com.jutak.assignment3", appContext.packageName)
}
}
34 changes: 34 additions & 0 deletions assignment-3/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:name=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Assignment3"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".views.main.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".views.detail.DetailActivity"
android:exported="false"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jutak.assignment3

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jutak.assignment3.data.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class CheckWordListEditPermissionParam(
@Json(name = "password") val password: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jutak.assignment3.data.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class CheckWordListEditPermissionResult(
@Json(name = "valid") val valid: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jutak.assignment3.data.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class DeleteWordListParam(
@Json(name = "password") val password: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.SimpleWordList

typealias DeleteWordListResult = List<SimpleWordList>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.Word
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class GetWordListByIdResult(
@Json(name = "id") val id: Int,
@Json(name = "name") val name: String,
@Json(name = "owner") val owner: String,
@Json(name = "word_list") val wordList: List<Word>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.SimpleWordList

typealias GetWordListsResult = List<SimpleWordList>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jutak.assignment3.data.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class PostWordListParam(
@Json(name = "name") val name: String,
@Json(name = "owner") val owner: String,
@Json(name = "password") val password: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.SimpleWordList

typealias PostWordListResult = List<SimpleWordList>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.Word
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class PostWordToWordListParam(
@Json(name = "password") val password: String,
@Json(name = "word") val word: Word,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jutak.assignment3.data.dto

import com.jutak.assignment3.data.model.Word
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class PutWordToWordListResult(
@Json(name = "id") val id: Int,
@Json(name = "name") val name: String,
@Json(name = "owner") val owner: String,
@Json(name = "word_list") val wordList: List<Word>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jutak.assignment3.data.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class SimpleWordList(
@Json(name = "id") val id: Int,
@Json(name = "name") val name: String,
@Json(name = "owner") val owner: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.jutak.assignment3.data.model

import android.os.Parcelable
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import kotlinx.parcelize.Parcelize

@JsonClass(generateAdapter = true)
@Parcelize
data class Word(
@Json(name = "spell") val spell: String,
@Json(name = "meaning") val meaning: String,
@Json(name = "synonym") val synonym: String? = null,
@Json(name = "antonym") val antonym: String? = null,
@Json(name = "sentence") val sentence: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jutak.assignment3.data.model

import android.os.Parcelable
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import kotlinx.parcelize.Parcelize

@JsonClass(generateAdapter = true)
@Parcelize
data class WordList(
@Json(name = "id") val id: Int,
@Json(name = "name") val name: String,
@Json(name = "owner") val owner: String,
@Json(name = "password") val password: String? = null,
@Json(name = "word_list") val wordList: List<Word>,
) : Parcelable {
companion object {
val Default = WordList(0, "", "", null, emptyList())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jutak.assignment3.data.repository

import com.jutak.assignment3.data.model.SimpleWordList
import com.jutak.assignment3.data.model.Word
import com.jutak.assignment3.data.model.WordList

interface WordListRepository {
suspend fun getRemoteWordLists(): List<SimpleWordList>
suspend fun getRemoteWordListById(id: Int): WordList
suspend fun postNewWordList(name: String, owner: String, password: String): List<SimpleWordList>
suspend fun addWordToWordList(listId: Int, password: String, word: Word): WordList
suspend fun deleteRemoteWordList(id: Int, password: String)
suspend fun checkWordListEditPermission(id: Int, password: String): Boolean
}
Loading