Skip to content

Commit

Permalink
[MERGE/#3] pull request #5 from GO-SOPT-ANDROID/seminar2
Browse files Browse the repository at this point in the history
2주차 세미나 과제
  • Loading branch information
b1urrrr authored Apr 29, 2023
2 parents cf01bbd + 970a675 commit 0ac4ec9
Show file tree
Hide file tree
Showing 52 changed files with 2,214 additions and 129 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ develop/view 브랜치에서 새로운 feature 브랜치(seminar1, week1, featur
## Summary
| Week | Topic | Link |
| :--: | :---: | :--: |
| 1 | Activity Life Cycle | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/seminar1/summary/Activity%20Life%20Cycle.md) |
| | EditText inputType | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/seminar1/summary/EditText%20inputType.md) |
| | Task & Back Stack | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/seminar1/summary/Task%20%26%20Back%20Stack.md) |
| 1 | Activity Lifecycle | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/develop/summary/Activity%20Lifeycle.md) |
| | EditText inputType | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/develop/summary/EditText%20inputType.md) |
| | Task & Back Stack | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/develop/summary/Task%20%26%20Back%20Stack.md) |
| 2 | Fragment Lifecycle | [🔗](https://github.com/GO-SOPT-ANDROID/chaeyeon-jeon/blob/develop/summary/Fragment%20Lifecycle.md) |
<br>

<!--
Expand Down
15 changes: 8 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'kotlin-parcelize'
id 'dagger.hilt.android.plugin'
id 'org.jlleitschuh.gradle.ktlint' version '10.3.0'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10'
}

android {
Expand Down Expand Up @@ -52,8 +53,8 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"

// ktx
implementation "androidx.activity:activity-ktx:1.7.0"
implementation "androidx.fragment:fragment-ktx:1.5.6"
implementation "androidx.activity:activity-ktx:1.7.1"
implementation "androidx.fragment:fragment-ktx:1.5.7"

// recyclerview
implementation "androidx.recyclerview:recyclerview:1.3.0"
Expand All @@ -69,18 +70,18 @@ dependencies {

// coil
implementation "io.coil-kt:coil:2.2.2"

// json
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"

// serialization
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0"

// timber
implementation "com.jakewharton.timber:timber:5.0.1"

// shared preference
implementation "androidx.security:security-crypto-ktx:1.1.0-alpha05"
implementation "androidx.security:security-crypto-ktx:1.1.0-alpha06"

implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.core:core-ktx:1.10.0"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "com.google.android.material:material:1.8.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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=".GoSoptApplication"
android:allowBackup="true"
Expand Down
1,034 changes: 1,034 additions & 0 deletions app/src/main/assets/fake_repo_list.json

Large diffs are not rendered by default.

194 changes: 194 additions & 0 deletions app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package org.android.go.sopt.data.entity

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.android.go.sopt.domain.model.Repo

@Serializable
data class MockRepoDto(
@SerialName("allow_forking")
val allowForking: Boolean,
@SerialName("archive_url")
val archiveUrl: String,
val archived: Boolean,
@SerialName("assignees_url")
val assigneesUrl: String,
@SerialName("blobs_url")
val blobsUrl: String,
@SerialName("branches_url")
val branchesUrl: String,
@SerialName("clone_url")
val cloneUrl: String,
@SerialName("collaborators_url")
val collaboratorsUrl: String,
@SerialName("comments_url")
val commentsUrl: String,
@SerialName("commits_url")
val commitsUrl: String,
@SerialName("compare_url")
val compareUrl: String,
@SerialName("contents_url")
val contentsUrl: String,
@SerialName("contributors_url")
val contributorsUrl: String,
@SerialName("created_at")
val createdAt: String,
@SerialName("default_branch")
val defaultBranch: String,
@SerialName("deployments_url")
val deploymentsUrl: String,
val description: String,
val disabled: Boolean,
@SerialName("downloads_url")
val downloadsUrl: String,
@SerialName("events_url")
val eventsUrl: String,
val fork: Boolean,
val forks: Int,
@SerialName("forks_count")
val forksCount: Int,
@SerialName("forks_url")
val forksUrl: String,
@SerialName("full_name")
val fullName: String,
@SerialName("git_commits_url")
val gitCommitsUrl: String,
@SerialName("git_refs_url")
val gitRefsUrl: String,
@SerialName("git_tags_url")
val gitTagsUrl: String,
@SerialName("git_url")
val gitUrl: String,
@SerialName("has_discussions")
val hasDiscussions: Boolean,
@SerialName("has_downloads")
val hasDownloads: Boolean,
@SerialName("has_issues")
val hasIssues: Boolean,
@SerialName("has_pages")
val hasPages: Boolean,
@SerialName("has_projects")
val hasProjects: Boolean,
@SerialName("has_wiki")
val hasWiki: Boolean,
val homepage: String,
@SerialName("hooks_url")
val hooksUrl: String,
@SerialName("html_url")
val htmlUrl: String,
val id: Int,
@SerialName("is_template")
val isTemplate: Boolean,
@SerialName("issue_comment_url")
val issueCommentUrl: String,
@SerialName("issue_events_url")
val issueEventsUrl: String,
@SerialName("issues_url")
val issuesUrl: String,
@SerialName("keys_url")
val keysUrl: String,
@SerialName("labels_url")
val labelsUrl: String,
val language: String?,
@SerialName("languages_url")
val languagesUrl: String,
val license: String?,
@SerialName("merges_url")
val mergesUrl: String,
@SerialName("milestones_url")
val milestonesUrl: String,
@SerialName("mirror_url")
val mirrorUrl: String?,
val name: String,
@SerialName("node_id")
val nodeId: String,
@SerialName("notifications_url")
val notificationsUrl: String,
@SerialName("open_issues")
val openIssues: Int,
@SerialName("open_issues_count")
val openIssuesCount: Int,
val owner: Owner,
@SerialName("private")
val isPrivate: Boolean,
@SerialName("pulls_url")
val pullsUrl: String,
@SerialName("pushed_at")
val pushedAt: String,
@SerialName("releases_url")
val releasesUrl: String,
val size: Int,
@SerialName("ssh_url")
val sshUrl: String,
@SerialName("stargazers_count")
val stargazersCount: Int,
@SerialName("stargazers_url")
val stargazersUrl: String,
@SerialName("statuses_url")
val statusesUrl: String,
@SerialName("subscribers_url")
val subscribersUrl: String,
@SerialName("subscription_url")
val subscriptionUrl: String,
@SerialName("svn_url")
val svnUrl: String,
@SerialName("tags_url")
val tagsUrl: String,
@SerialName("teams_url")
val teamsUrl: String,
val topics: List<String>,
@SerialName("trees_url")
val treesUrl: String,
@SerialName("updated_at")
val updatedAt: String,
val url: String,
val visibility: String,
val watchers: Int,
@SerialName("watchers_count")
val watchersCount: Int,
@SerialName("web_commit_signoff_required")
val webCommitSignoffRequired: Boolean,
) {
@Serializable
data class Owner(
@SerialName("avatar_url")
val avatarUrl: String,
@SerialName("events_url")
val eventsUrl: String,
@SerialName("followers_url")
val followersUrl: String,
@SerialName("following_url")
val followingUrl: String,
@SerialName("gists_url")
val gistsUrl: String,
@SerialName("gravatar_id")
val gravatarId: String,
@SerialName("html_url")
val htmlUrl: String,
val id: Int,
val login: String,
@SerialName("node_id")
val nodeId: String,
@SerialName("organizations_url")
val organizationsUrl: String,
@SerialName("received_events_url")
val receivedEventsUrl: String,
@SerialName("repos_url")
val reposUrl: String,
@SerialName("site_admin")
val siteAdmin: Boolean,
@SerialName("starred_url")
val starredUrl: String,
@SerialName("subscriptions_url")
val subscriptionsUrl: String,
val type: String,
val url: String,
)

fun toRepo() = Repo(
id = id,
image = owner.avatarUrl,
name = name,
owner = owner.login,
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.android.go.sopt.data.repository

import org.android.go.sopt.data.entity.User
import org.android.go.sopt.data.source.LocalPrefDataSource
import org.android.go.sopt.domain.AuthRepository
import org.android.go.sopt.domain.model.User
import org.android.go.sopt.domain.repository.AuthRepository
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.android.go.sopt.data.repository

import org.android.go.sopt.data.source.RepoDataSource
import org.android.go.sopt.domain.model.Repo
import org.android.go.sopt.domain.repository.RepoRepository
import javax.inject.Inject

class RepoRepositoryImpl @Inject constructor(
private val repoDataSource: RepoDataSource,
) : RepoRepository {
override suspend fun getRepoList(): Result<List<Repo>> = runCatching {
repoDataSource.getRepoList().map { repo -> repo.toRepo() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.SharedPreferences
import androidx.core.content.edit
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import org.android.go.sopt.data.entity.User
import org.android.go.sopt.domain.model.User
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -31,10 +31,7 @@ class LocalPrefDataSource @Inject constructor(
}

fun clearLocalPref() {
with(prefs.edit()) {
clear()
commit()
}
prefs.edit { clear() }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.android.go.sopt.data.source

import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.android.go.sopt.data.entity.MockRepoDto
import org.android.go.sopt.util.AssetLoader
import javax.inject.Inject

class RepoDataSource @Inject constructor(
private val assetLoader: AssetLoader,
) {
fun getRepoList(): Array<MockRepoDto> {
return assetLoader.getJsonString(FILE_FAKE_REPO_LIST)?.let { jsonString ->
Json.decodeFromString<Array<MockRepoDto>>(jsonString)
} ?: emptyArray()
}

companion object {
private const val FILE_FAKE_REPO_LIST = "fake_repo_list.json"
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/android/go/sopt/di/AssetLoaderModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.android.go.sopt.di

import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.android.go.sopt.util.AssetLoader
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AssetLoaderModule {
@Provides
@Singleton
fun providesAssetLoader(@ApplicationContext context: Context): AssetLoader =
AssetLoader(context)
}
12 changes: 10 additions & 2 deletions app/src/main/java/org/android/go/sopt/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.android.go.sopt.data.repository.AuthRepositoryImpl
import org.android.go.sopt.domain.AuthRepository
import org.android.go.sopt.data.repository.RepoRepositoryImpl
import org.android.go.sopt.domain.repository.AuthRepository
import org.android.go.sopt.domain.repository.RepoRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
@Singleton
abstract fun providesAuthRepository(
abstract fun bindsAuthRepository(
authRepositoryImpl: AuthRepositoryImpl,
): AuthRepository

@Binds
@Singleton
abstract fun bindsRepoRepository(
repoRepositoryImpl: RepoRepositoryImpl,
): RepoRepository
}
8 changes: 8 additions & 0 deletions app/src/main/java/org/android/go/sopt/domain/model/Repo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.android.go.sopt.domain.model

data class Repo(
val id: Int,
val image: String,
val name: String,
val owner: String,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.android.go.sopt.data.entity
package org.android.go.sopt.domain.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.android.go.sopt.domain
package org.android.go.sopt.domain.repository

import org.android.go.sopt.data.entity.User
import org.android.go.sopt.domain.model.User

interface AuthRepository {
fun setAutoLogin(isAutoLogin: Boolean)
Expand Down
Loading

0 comments on commit 0ac4ec9

Please sign in to comment.