Skip to content

Commit 5487969

Browse files
committed
release:
- App 용량 최적화 - Guest 사용자 추가 - UI 추가
1 parent 4d3d627 commit 5487969

17 files changed

Lines changed: 525 additions & 49 deletions

app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ android {
1818
applicationId "com.seok.gfd"
1919
minSdkVersion 26
2020
targetSdkVersion 28
21-
versionCode 9
22-
versionName "2.17.8"
21+
versionCode 10
22+
versionName "3.20.12"
2323
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2424
}
2525
buildTypes {
@@ -150,5 +150,4 @@ dependencies {
150150
// Tab Layout
151151
implementation 'com.ogaclejapan.smarttablayout:library:2.0.0@aar'
152152
implementation 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar'
153-
154153
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.seok.gfd.adapter
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.graphics.Color
6+
import android.view.Gravity
7+
import android.view.LayoutInflater
8+
import android.view.View
9+
import android.view.ViewGroup
10+
import android.widget.LinearLayout
11+
import android.widget.TextView
12+
import androidx.gridlayout.widget.GridLayout
13+
import androidx.recyclerview.widget.RecyclerView
14+
import com.seok.gfd.R
15+
import com.seok.gfd.utils.Contribution
16+
import org.jetbrains.anko.backgroundColor
17+
import org.jetbrains.anko.margin
18+
import java.time.LocalDate
19+
import java.time.Month
20+
21+
class ContributionsAdapter(list: ArrayList<Contribution>, context: Context) :
22+
RecyclerView.Adapter<ContributionsAdapter.MyViewHolder>() {
23+
var list = list
24+
var context: Context = context
25+
26+
override fun getItemCount() = list.size
27+
28+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
29+
val v = LayoutInflater.from(parent.context)
30+
.inflate(R.layout.contributions_layout, parent, false)
31+
return MyViewHolder(v)
32+
}
33+
34+
35+
@SuppressLint("SetTextI18n")
36+
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
37+
val contribution = list[position]
38+
val formatYear =
39+
String.format("%s: %d Contributions", contribution.year, contribution.total)
40+
holder.yearContribution.text = formatYear
41+
42+
var monthFlag = ""
43+
val size = contribution.list!!.size
44+
var lineLayout = LinearLayout(this.context)
45+
lineLayout.orientation = LinearLayout.VERTICAL
46+
val params = LinearLayout.LayoutParams(35, 35)
47+
params.margin = 4
48+
params.gravity = Gravity.CENTER
49+
for (index in 0 until size) {
50+
var tempLayout = LinearLayout(this.context)
51+
if (index % 7 == 0) {
52+
val monthDataStr = getDayStartCount(LocalDate.parse(contribution.list!![index].date).month)
53+
lineLayout = LinearLayout(this.context)
54+
lineLayout.orientation = LinearLayout.VERTICAL
55+
tempLayout.backgroundColor = Color.WHITE
56+
tempLayout.layoutParams = params
57+
if(monthFlag != monthDataStr){
58+
val month = TextView(this.context)
59+
month.textSize = 7f
60+
month.text = monthDataStr
61+
tempLayout.addView(month)
62+
monthFlag = monthDataStr
63+
}
64+
lineLayout.addView(tempLayout)
65+
tempLayout = LinearLayout(this.context)
66+
tempLayout.backgroundColor = Color.parseColor(contribution.list!![index].color)
67+
tempLayout.layoutParams = params
68+
lineLayout.addView(tempLayout)
69+
} else {
70+
tempLayout.backgroundColor = Color.parseColor(contribution.list!![index].color)
71+
tempLayout.layoutParams = params
72+
lineLayout.addView(tempLayout)
73+
}
74+
if (index % 7 == 0) {
75+
holder.contributionCanvas.addView(lineLayout)
76+
}
77+
if (index == size) {
78+
holder.contributionCanvas.addView(lineLayout)
79+
}
80+
}
81+
}
82+
83+
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
84+
var yearContribution: TextView = itemView.findViewById(R.id.guest_year_contribution)
85+
var contributionCanvas: GridLayout = itemView.findViewById(R.id.canvas)
86+
}
87+
88+
private fun getDayStartCount(dayOfMonth: Month): String = when (dayOfMonth) {
89+
Month.JANUARY -> "Jan"
90+
Month.FEBRUARY -> "Feb"
91+
Month.MARCH -> "Mar"
92+
Month.APRIL -> "Apr"
93+
Month.MAY -> "May"
94+
Month.JUNE -> "Jun"
95+
Month.JULY -> "Jul"
96+
Month.AUGUST-> "Aug"
97+
Month.SEPTEMBER-> "Sep"
98+
Month.OCTOBER -> "Oct"
99+
Month.NOVEMBER-> "Nov"
100+
Month.DECEMBER -> "Dec"
101+
else -> "X"
102+
}
103+
}
104+

app/src/main/java/com/seok/gfd/retrofit/RetrofitClient.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.seok.gfd.BuildConfig
55
import com.seok.gfd.retrofit.service.UserService
66
import com.seok.gfd.retrofit.service.CommitService
77
import com.seok.gfd.retrofit.service.GithubApiService
8-
import com.seok.gfd.retrofit.service.GithubCommitService
8+
import com.seok.gfd.retrofit.service.GithubContributionService
99
import retrofit2.Retrofit
1010
import retrofit2.converter.gson.GsonConverterFactory
1111

@@ -43,13 +43,13 @@ class RetrofitClient {
4343
.build()
4444
return retrofit.create(CommitService::class.java)
4545
}
46-
fun githubCommitService(): GithubCommitService{
46+
fun githubContributionService(): GithubContributionService{
4747
val gson = GsonBuilder().setLenient().create()
4848
retrofit = Retrofit.Builder()
4949
.baseUrl("https://github-contributions-api.now.sh/v1/")
5050
.addConverterFactory(GsonConverterFactory.create(gson))
5151
.build()
52-
return retrofit.create(GithubCommitService::class.java)
52+
return retrofit.create(GithubContributionService::class.java)
5353
}
5454
}
5555
}

app/src/main/java/com/seok/gfd/retrofit/domain/resopnse/CommitsResponseDto.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ class CommitsResponseDto {
4040
var color : String = ""
4141
var intensity : Int = 0
4242
}
43-
44-
4543
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.seok.gfd.retrofit.domain.resopnse
2+
3+
import lombok.AllArgsConstructor
4+
import lombok.Getter
5+
import lombok.NoArgsConstructor
6+
import lombok.Setter
7+
8+
@Getter
9+
@Setter
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
class NestedContributionsResponseDto {
13+
14+
var years: HashMap<Int, Years>? = null
15+
16+
var contributions : Contributions? = null
17+
18+
inner class Years{
19+
var year: String? = null
20+
var total : Int? = 0
21+
var range: Range? = null
22+
23+
inner class Range{
24+
var start: String = ""
25+
var end: String = ""
26+
}
27+
}
28+
29+
inner class Contributions{
30+
var year: String? = null
31+
var total : Int? = 0
32+
var range: Range? = null
33+
var contributions : HashMap<Int, HashMap<Int, HashMap<Int, Contribution>>>? = null
34+
35+
inner class Range{
36+
var start: String = ""
37+
var end: String = ""
38+
}
39+
40+
inner class Contribution{
41+
var date : String = ""
42+
var count : Int = 0
43+
var color : String = ""
44+
var intensity : Int = 0
45+
}
46+
}
47+
}

app/src/main/java/com/seok/gfd/retrofit/service/GithubCommitService.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.seok.gfd.retrofit.service
2+
3+
import com.seok.gfd.retrofit.domain.resopnse.CommitsResponseDto
4+
import com.seok.gfd.retrofit.domain.resopnse.NestedContributionsResponseDto
5+
import retrofit2.Call
6+
import retrofit2.http.GET
7+
import retrofit2.http.Path
8+
import retrofit2.http.Query
9+
10+
interface GithubContributionService {
11+
@GET("{userId}")
12+
fun getContributions(@Path("userId") userId: String): Call<CommitsResponseDto>
13+
14+
@GET("{userId}")
15+
fun getNestedContributions(
16+
@Path("userId") userId: String,
17+
@Query("format") format: String
18+
): Call<NestedContributionsResponseDto>
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.seok.gfd.utils
2+
3+
import lombok.AllArgsConstructor
4+
import lombok.Getter
5+
import lombok.NoArgsConstructor
6+
import lombok.Setter
7+
8+
@Getter
9+
@Setter
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
class Contribution {
13+
var year : String? = null
14+
var total : Int? = 0
15+
var list : ArrayList<ContributionInfo>? = ArrayList()
16+
17+
class ContributionInfo(date : String, count: Int, color : String, intensity: Int){
18+
var date : String = date
19+
var count : Int = count
20+
var color : String = color
21+
var intensity : Int = intensity
22+
}
23+
}

app/src/main/java/com/seok/gfd/viewmodel/GithubCommitDataViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class GithubCommitDataViewModel: ViewModel() {
6767

6868
// 깃허브 사용자 커밋 데이터 가져오기
6969
fun getCommitsInfo(userId : String){
70-
val getCommitsService = RetrofitClient.githubCommitService()
71-
val getCommitsCall = getCommitsService.getContribution(userId)
70+
val getCommitsService = RetrofitClient.githubContributionService()
71+
val getCommitsCall = getCommitsService.getContributions(userId)
7272
getCommitsCall.enqueue(object : retrofit2.Callback<CommitsResponseDto> {
7373
@SuppressLint("NewApi")
7474
override fun onResponse(call: Call<CommitsResponseDto>, response: Response<CommitsResponseDto>) {

app/src/main/java/com/seok/gfd/viewmodel/GithubContributionViewModel.kt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,56 @@ import androidx.lifecycle.MutableLiveData
66
import androidx.lifecycle.ViewModel
77
import com.seok.gfd.retrofit.RetrofitClient
88
import com.seok.gfd.retrofit.domain.resopnse.CommitsResponseDto
9+
import com.seok.gfd.retrofit.domain.resopnse.NestedContributionsResponseDto
910
import retrofit2.Call
1011
import retrofit2.Response
1112

1213
class GithubContributionViewModel : ViewModel() {
13-
private val _commits = MutableLiveData<CommitsResponseDto>()
14+
private val _contributions = MutableLiveData<CommitsResponseDto>()
15+
private val _nestedContributions = MutableLiveData<NestedContributionsResponseDto>()
1416

15-
val commits: LiveData<CommitsResponseDto>
16-
get() = _commits
17+
val contributions: LiveData<CommitsResponseDto>
18+
get() = _contributions
19+
val nestedContributions: LiveData<NestedContributionsResponseDto>
20+
get() = _nestedContributions
1721

1822

19-
fun getContributionData(userId: String) {
20-
val getContributionService = RetrofitClient.githubCommitService()
21-
val getContributionCall = getContributionService.getContribution(userId)
23+
fun getContributions(userId: String) {
24+
val getContributionService = RetrofitClient.githubContributionService()
25+
val getContributionCall = getContributionService.getContributions(userId)
2226
getContributionCall.enqueue(object : retrofit2.Callback<CommitsResponseDto> {
2327

24-
override fun onResponse(call: Call<CommitsResponseDto>, response: Response<CommitsResponseDto>) {
25-
_commits.value = response.body()
28+
override fun onResponse(
29+
call: Call<CommitsResponseDto>,
30+
response: Response<CommitsResponseDto>
31+
) {
32+
_contributions.value = response.body()
2633
}
2734

2835
override fun onFailure(call: Call<CommitsResponseDto>, t: Throwable) {
2936
Log.e(this.javaClass.simpleName, t.message.toString())
3037
}
38+
})
39+
}
40+
41+
fun getNestedContributions(userId: String) {
42+
val nestedContributionService = RetrofitClient.githubContributionService()
43+
val nestedContributionCall =
44+
nestedContributionService.getNestedContributions(userId, "nested")
45+
nestedContributionCall.enqueue(object : retrofit2.Callback<NestedContributionsResponseDto> {
46+
47+
override fun onResponse(
48+
call: Call<NestedContributionsResponseDto>,
49+
response: Response<NestedContributionsResponseDto>
50+
) {
51+
val t = response.body()
52+
t
53+
}
3154

55+
override fun onFailure(call: Call<NestedContributionsResponseDto>, t: Throwable) {
56+
Log.e(this.javaClass.simpleName, t.message.toString())
57+
}
3258
})
3359
}
60+
3461
}

0 commit comments

Comments
 (0)