├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── style.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── drawable-xxhdpi │ │ │ │ └── konata.png │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── drawable │ │ │ │ ├── bg_3c404f_r10.xml │ │ │ │ ├── ic_baseline_star_24.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── item_sample.xml │ │ │ │ └── activity_main.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── pluu │ │ │ │ └── sample │ │ │ │ └── codeforreadability │ │ │ │ ├── data │ │ │ │ ├── LogResult.kt │ │ │ │ ├── SampleApi.kt │ │ │ │ └── SampleRepository.kt │ │ │ │ ├── model │ │ │ │ └── SampleItem.kt │ │ │ │ ├── utils │ │ │ │ └── DimensExtension.kt │ │ │ │ ├── SampleApp.kt │ │ │ │ ├── presentation │ │ │ │ ├── SampleItemDecoration.kt │ │ │ │ ├── SampleAdapter.kt │ │ │ │ ├── SampleViewHolder.kt │ │ │ │ └── MainActivity.kt │ │ │ │ └── provider │ │ │ │ └── RetrofitProvider.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── pluu │ │ │ └── sample │ │ │ └── codeforreadability │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── pluu │ │ └── sample │ │ └── codeforreadability │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── arts └── preview.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── settings.gradle ├── gradle.properties ├── gradlew.bat ├── .gitignore └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /arts/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/arts/preview.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CodeForReadabilitySample 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/konata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/drawable-xxhdpi/konata.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pluu/CodeForReadabilitySample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/data/LogResult.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.data 2 | 3 | data class LogResult( 4 | val login: String, 5 | val age: String = "999", 6 | val contribute: List 7 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/data/SampleApi.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.data 2 | 3 | import retrofit2.http.GET 4 | 5 | interface SampleApi { 6 | @GET("/users/google") 7 | suspend fun sendLog(): LogResult 8 | } -------------------------------------------------------------------------------- /app/src/main/res/values/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_3c404f_r10.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Apr 23 21:31:43 KST 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Sample] Code for Readability 2 | 3 | ### 구현해야하는 스펙 4 | 5 | 1. 랜덤으로 생성된 텍스트/색상을 표시하는 리스트를 만든다 6 | 2. 항목 선택시, 해당 항목에 `⭑` 표시가 되어야한다 7 | 3. 마지막으로 선택된 항목이 존재하는 경우에는 아래 조건을 대응해야한다 8 | 1. 초기화 후 새로운 항목 노출시에도 마지막 선택된 값과 동일한 경우 `2번` 조건을 대응해야한다. 9 | 10 | ------ 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/data/SampleRepository.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.data 2 | 3 | import kotlinx.coroutines.flow.flow 4 | 5 | class SampleRepository( 6 | private val sampleApi: SampleApi 7 | ) : SampleApi by sampleApi { 8 | fun sendLogFlow() = flow { 9 | emit(sampleApi.sendLog()) 10 | } 11 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/model/SampleItem.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.model 2 | 3 | import androidx.core.graphics.ColorUtils 4 | 5 | data class SampleItem( 6 | val text: String, 7 | val bgColor: Int 8 | ) { 9 | fun isDarkBg(): Boolean { 10 | return ColorUtils.calculateLuminance(bgColor) < 0.5 11 | } 12 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/utils/DimensExtension.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.utils 2 | 3 | import android.content.res.Resources 4 | import kotlin.math.roundToInt 5 | 6 | val Int.dp: Int 7 | get() = (this * Resources.getSystem().displayMetrics.density).roundToInt() 8 | 9 | val Float.dp: Int 10 | get() = (this * Resources.getSystem().displayMetrics.density).roundToInt() -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | rootProject.name = "CodeForReadabilitySample" 16 | include ':app' 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/SampleApp.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability 2 | 3 | import android.app.Application 4 | import logcat.AndroidLogcatLogger 5 | import logcat.LogPriority 6 | 7 | class SampleApp : Application() { 8 | override fun onCreate() { 9 | super.onCreate() 10 | AndroidLogcatLogger.installOnDebuggableApp(this, minPriority = LogPriority.VERBOSE) 11 | } 12 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_star_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/test/java/com/pluu/sample/codeforreadability/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Test 5 | 6 | /** 7 | * Example local unit test, which will execute on the development machine (host). 8 | * 9 | * See [testing documentation](http://d.android.com/tools/testing). 10 | */ 11 | class ExampleUnitTest { 12 | @Test 13 | fun addition_isCorrect() { 14 | assertEquals(4, 2 + 2) 15 | } 16 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | #4285F4 11 | #DB4437 12 | #F4B400 13 | #0F9D58 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/presentation/SampleItemDecoration.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.presentation 2 | 3 | import android.graphics.Rect 4 | import android.view.View 5 | import androidx.recyclerview.widget.RecyclerView 6 | 7 | class SampleItemDecoration( 8 | private val offset: Int 9 | ) : RecyclerView.ItemDecoration() { 10 | override fun getItemOffsets( 11 | outRect: Rect, 12 | view: View, 13 | parent: RecyclerView, 14 | state: RecyclerView.State 15 | ) { 16 | super.getItemOffsets(outRect, view, parent, state) 17 | outRect.set(offset, offset.div(2), offset, offset.div(2)) 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/provider/RetrofitProvider.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.provider 2 | 3 | import com.pluu.sample.codeforreadability.data.SampleApi 4 | import com.pluu.sample.codeforreadability.data.SampleRepository 5 | import retrofit2.Retrofit 6 | import retrofit2.converter.gson.GsonConverterFactory 7 | 8 | private fun provideRetrofit(): Retrofit = Retrofit.Builder() 9 | .baseUrl("https://api.github.com/") 10 | .addConverterFactory(GsonConverterFactory.create()) 11 | .build() 12 | 13 | fun provideRepository(): SampleRepository = SampleRepository(provideApi()) 14 | 15 | private fun provideApi(): SampleApi = provideRetrofit() 16 | .create(SampleApi::class.java) 17 | 18 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/pluu/sample/codeforreadability/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4 4 | import androidx.test.platform.app.InstrumentationRegistry 5 | import org.junit.Assert.assertEquals 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | /** 10 | * Instrumented test, which will execute on an Android device. 11 | * 12 | * See [testing documentation](http://d.android.com/tools/testing). 13 | */ 14 | @RunWith(AndroidJUnit4::class) 15 | class ExampleInstrumentedTest { 16 | @Test 17 | fun useAppContext() { 18 | // Context of the app under test. 19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 20 | assertEquals("com.pluu.sample.codeforreadability", appContext.packageName) 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /app/src/main/java/com/pluu/sample/codeforreadability/presentation/SampleAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.pluu.sample.codeforreadability.presentation 2 | 3 | import android.view.ViewGroup 4 | import androidx.recyclerview.widget.RecyclerView 5 | import com.pluu.sample.codeforreadability.model.SampleItem 6 | 7 | class SampleAdapter( 8 | private val onDuplicate: (SampleItem) -> Unit, 9 | private val onFavorite: (String) -> Unit 10 | ) : RecyclerView.Adapter() { 11 | 12 | private var list = mutableListOf() 13 | 14 | private var favoriteText: String? = null 15 | 16 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SampleViewHolder { 17 | return SampleViewHolder.create(parent, onFavorite) 18 | } 19 | 20 | override fun onBindViewHolder(holder: SampleViewHolder, position: Int) { 21 | holder.onBind(list[position], favoriteText.orEmpty()) 22 | } 23 | 24 | override fun getItemCount(): Int = list.size 25 | 26 | fun addItem(item: SampleItem) { 27 | val isNoneItem = list.none { it.text == item.text } 28 | if (isNoneItem) { 29 | list.add(item) 30 | list.sortBy { it.text } 31 | notifyDataSetChanged() 32 | } else { 33 | onDuplicate(item) 34 | } 35 | } 36 | 37 | fun updateFavorite(text: String) { 38 | this.favoriteText = text 39 | } 40 | 41 | fun reset() { 42 | list.clear() 43 | notifyDataSetChanged() 44 | } 45 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sample.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |