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

SF-1 MyFriends 구현 #1

Open
wants to merge 35 commits into
base: feature/SF-1-MyFriends
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b09f37f
build.gradle 라이브러리 추가
ddaeyeonkim Jul 12, 2020
2eea69d
친구정보 화면 추가
ddaeyeonkim Jul 12, 2020
ca8aee1
Friends 화면 디자인
ddaeyeonkim Jul 12, 2020
4860376
friendActivity 작성
ddaeyeonkim Jul 12, 2020
fd6e379
FriendApi 추가
ddaeyeonkim Jul 12, 2020
13a76f6
RemoteFriendDataSource 추가
ddaeyeonkim Jul 12, 2020
757ed7d
RetrofitService 추가
ddaeyeonkim Jul 12, 2020
5b7ee24
FriendApp 추가
ddaeyeonkim Jul 12, 2020
c101013
인터넷 권한 추가
ddaeyeonkim Jul 12, 2020
def3ac4
FriendViewModel Factory 추가
ddaeyeonkim Jul 12, 2020
4c6a70a
url 에러 수정
ddaeyeonkim Jul 12, 2020
750a104
MyGlideModule 추가
ddaeyeonkim Jul 12, 2020
7cd87a5
ImageViewExt 추가
ddaeyeonkim Jul 12, 2020
fcfdd38
FriendItem 에 데이터바인딩 적용
ddaeyeonkim Jul 12, 2020
ca2737f
Event 추가
ddaeyeonkim Jul 12, 2020
5ef29f9
Friend 모델 Parcelable 구현
ddaeyeonkim Jul 12, 2020
4189633
FriendDetailActivity 추가
ddaeyeonkim Jul 12, 2020
11d23b7
FriendDetailActivity 이동 함수 구현
ddaeyeonkim Jul 12, 2020
4af0f8e
구글맵 추가
ddaeyeonkim Jul 12, 2020
4574b6e
Coordinates 필드 타입 수정
ddaeyeonkim Jul 12, 2020
afb04f4
FriendDetailActivity 에 구글맵 api 연동하여 좌표 표시
ddaeyeonkim Jul 12, 2020
d9c04db
EndlessRecyclerViewScrollListener 추가
ddaeyeonkim Jul 12, 2020
5c9f843
페이징 처리 추가
ddaeyeonkim Jul 12, 2020
3f82961
뒤로 가기 두번 눌러서 앱 종료 기능 추가
ddaeyeonkim Jul 12, 2020
ae5c865
FriendInfoView 전화번호, 이메일 클릭리스너 추가
ddaeyeonkim Jul 12, 2020
c2368d9
FriendDetailActivity 에 클릭 이벤트 추가
ddaeyeonkim Jul 12, 2020
88a794c
해상도가 너무 낮아서 large 로 변경
ddaeyeonkim Jul 12, 2020
f3b33b6
FriendMapper 에서 country 필드를 nat 필드로 매핑
ddaeyeonkim Jul 12, 2020
2232acf
TextViewExt 추가
ddaeyeonkim Jul 12, 2020
6e6bb32
view_friend_info 데이터바인딩 어댑터 적용
ddaeyeonkim Jul 12, 2020
ad61793
리프레시 버그 수정
ddaeyeonkim Jul 12, 2020
e04c26c
Friend 를 ui 모델로 이동
ddaeyeonkim Jul 12, 2020
9f2d221
data 레이어에 FriendData 모델 추가
ddaeyeonkim Jul 12, 2020
73d3d13
item_friend 마진, 리플 추가
ddaeyeonkim Jul 12, 2020
cd0d185
activity_friend_detail 구글맵 marginTop 추가
ddaeyeonkim Jul 12, 2020
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
46 changes: 44 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"

defaultConfig {
applicationId "com.studyfork.sfoide"
Expand All @@ -14,6 +14,8 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
}

buildTypes {
Expand All @@ -22,16 +24,56 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "1.8"
}

dataBinding {
enabled = true
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'

implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

// test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

// networking
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'

// log
implementation 'com.jakewharton.timber:timber:4.7.1'

// image
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'

// google map
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
}
12 changes: 11 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.studyfork.sfoide">

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

<application
android:name=".FriendApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>

<activity android:name=".ui.friend.FriendActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity android:name=".ui.friend.detail.FriendDetailActivity" />
</application>

</manifest>
15 changes: 15 additions & 0 deletions app/src/main/java/com/studyfork/sfoide/FriendApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.studyfork.sfoide

import android.app.Application
import timber.log.Timber

class FriendApp : Application() {

override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
11 changes: 0 additions & 11 deletions app/src/main/java/com/studyfork/sfoide/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.studyfork.sfoide.data.datasource

import com.studyfork.sfoide.data.mapper.toEntity
import com.studyfork.sfoide.data.model.FriendData
import com.studyfork.sfoide.data.remote.api.FriendApi
import com.studyfork.sfoide.data.remote.datasource.RemoteFriendDataSource
import com.studyfork.sfoide.data.remote.response.FriendsResponse
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class RemoteFriendDataSourceImpl(
private val friendApi: FriendApi
) : RemoteFriendDataSource {

override fun getFriends(
pageNumber: Int,
itemCount: Int,
onSuccess: (friends: List<FriendData>) -> Unit,
onError: (error: Throwable) -> Unit
) {
friendApi.getFriends(
page = pageNumber,
results = itemCount
)
.enqueue(object : Callback<FriendsResponse?> {
override fun onFailure(call: Call<FriendsResponse?>, t: Throwable) {
onError(t)
}

override fun onResponse(
call: Call<FriendsResponse?>,
response: Response<FriendsResponse?>
) {
if (response.isSuccessful) {
val friends =
response.body()?.results?.map { FriendResponse -> FriendResponse.toEntity() }
?: emptyList()
onSuccess(friends)
} else {
onError(Throwable("network error"))
}
}
})
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/studyfork/sfoide/data/mapper/FriendMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.studyfork.sfoide.data.mapper

import com.studyfork.sfoide.data.model.CoordinatesData
import com.studyfork.sfoide.data.model.FriendData
import com.studyfork.sfoide.data.remote.response.FriendsResponse

fun FriendsResponse.Result.toEntity(): FriendData {
return FriendData(
id = this.login?.uuid ?: "",
thumbnail = this.picture?.large ?: "",
name = this.name.toString(),
age = this.dob?.age ?: 0,
gender = this.gender ?: "",
country = this.nat ?: "",
email = this.email ?: "",
telephone = this.phone ?: "",
mobilePhone = this.cell ?: "",
coordinatesData = CoordinatesData(
latitude = this.location?.coordinates?.latitude?.toDouble() ?: 0.0,
longitude = this.location?.coordinates?.longitude?.toDouble() ?: 0.0
)
)
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/studyfork/sfoide/data/model/FriendData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.studyfork.sfoide.data.model

data class FriendData(
val id: String,
val thumbnail: String,
val name: String,
val age: Int,
val gender: String,
val country: String,
val email: String,
val telephone: String,
val mobilePhone: String,
val coordinatesData: CoordinatesData
)

class CoordinatesData(
val latitude: Double,
val longitude: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.studyfork.sfoide.data.remote

import com.studyfork.sfoide.BuildConfig
import com.studyfork.sfoide.data.remote.api.FriendApi
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitService {

private val retrofit = Retrofit.Builder()
.baseUrl("https://randomuser.me/")
.client(createOkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build()

private fun createOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder().addInterceptor(createHttpLoggingInterceptor()).build()
}

private fun createHttpLoggingInterceptor(): HttpLoggingInterceptor {
return HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
}
}
}

val friendApi = retrofit.create(FriendApi::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.studyfork.sfoide.data.remote.api

import com.studyfork.sfoide.data.remote.response.FriendsResponse
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface FriendApi {

@GET("api/")
fun getFriends(
@Query("page") page: Int,
@Query("results") results: Int
): Call<FriendsResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.studyfork.sfoide.data.remote.datasource

import com.studyfork.sfoide.data.model.FriendData

interface RemoteFriendDataSource {

fun getFriends(
pageNumber: Int,
itemCount: Int,
onSuccess: (friends: List<FriendData>) -> Unit,
onError: (error: Throwable) -> Unit
)
}
Loading