Skip to content

Commit cade325

Browse files
Gabi Scardine SilvaGabi Scardine Silva
authored andcommitted
Convert Contest
1 parent 25fecce commit cade325

File tree

6 files changed

+162
-224
lines changed

6 files changed

+162
-224
lines changed

app/src/main/java/io/intrepid/contest/models/Contest.java

Lines changed: 0 additions & 169 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package io.intrepid.contest.models
2+
3+
import android.os.Parcel
4+
import com.google.gson.annotations.SerializedName
5+
import timber.log.Timber
6+
import java.util.*
7+
8+
open class Contest {
9+
@SerializedName("id")
10+
var id: UUID? = null
11+
var creatorId: UUID? = null
12+
@SerializedName("created_at")
13+
var creationDate: Date? = null
14+
@SerializedName("updated_at")
15+
var lastUpdatedDate: Date? = null
16+
@SerializedName("ended_at")
17+
var endedDate: Date? = null
18+
set(value) {
19+
this.endedDate = endedDate
20+
}
21+
var title: String? = null
22+
var description: String? = null
23+
@SerializedName("scoring_categories")
24+
var categories: List<Category>? = null
25+
var entries: List<Entry>? = null
26+
var submissionsClosedAt: Date? = null
27+
var participationType: ParticipationType? = null
28+
29+
init {
30+
id = UUID.randomUUID()
31+
categories = ArrayList<Category>()
32+
}
33+
34+
override fun toString(): String {
35+
return title + "/n" +
36+
description + "/n" +
37+
id + "/n" +
38+
creatorId + " " + creationDate +
39+
" /n size of categories was " + categories!!.size +
40+
"categories " + categories +
41+
" /n Last updated " + lastUpdatedDate +
42+
" /n Ended Data " + endedDate
43+
}
44+
45+
class Builder {
46+
var categories: List<Category> = ArrayList()
47+
var title: String? = null
48+
var description: String? = null
49+
internal var contestId: UUID? = null
50+
internal var creatorId: UUID? = null
51+
internal var creationDate: Date? = null
52+
internal var lastUpdatedDate: Date? = null
53+
internal var endedDate: Date? = null
54+
55+
constructor() : this(UUID(UUID_MIN_LIMIT.toLong(), UUID_MAX_LIMIT.toLong())) {}
56+
57+
internal constructor(creatorId: UUID) {
58+
this.creatorId = creatorId
59+
this.contestId = UUID(UUID_MIN_LIMIT.toLong(), UUID_MAX_LIMIT.toLong())
60+
}
61+
62+
protected constructor(`in`: Parcel) {
63+
title = `in`.readString()
64+
description = `in`.readString()
65+
}
66+
67+
fun setTitle(title: String): Builder {
68+
this.title = title
69+
return this
70+
}
71+
72+
fun setDescription(description: String): Builder {
73+
this.description = description
74+
return this
75+
}
76+
77+
fun build(): Contest {
78+
if (creationDate == null) {
79+
creationDate = Date()
80+
}
81+
if (lastUpdatedDate == null) {
82+
lastUpdatedDate = Date()
83+
}
84+
Timber.d(this.toString())
85+
val contest = Contest()
86+
contest.id = this.contestId
87+
contest.creatorId = this.creatorId
88+
contest.lastUpdatedDate = Date()
89+
contest.creationDate = this.creationDate
90+
contest.endedDate = this.endedDate
91+
contest.title = this.title
92+
contest.description = this.description
93+
contest.categories = this.categories
94+
return contest
95+
}
96+
97+
companion object {
98+
internal val UUID_MIN_LIMIT = 0
99+
internal val UUID_MAX_LIMIT = Integer.MAX_VALUE
100+
}
101+
}
102+
}

app/src/main/java/io/intrepid/contest/screens/contestcreation/reviewcontest/ReviewContestFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public ReviewContestPresenter createPresenter(PresenterConfiguration configurati
5555

5656
@Override
5757
public void displayReviewPageContent(Contest.Builder contestBuilder) {
58-
titleButton.setText(contestBuilder.title);
59-
descriptionButton.setText(contestBuilder.description);
58+
titleButton.setText(contestBuilder.getTitle());
59+
descriptionButton.setText(contestBuilder.getDescription());
6060
categoryAdapter.setCategories(contestBuilder.getCategories());
6161
}
6262

app/src/test/java/io/intrepid/contest/screens/contestcreation/NewContestPresenterTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class NewContestPresenterTest : BasePresenterTest<NewContestPresenter>() {
104104

105105
@Test
106106
fun onEditContestCaegoryShouldTriggerViewToUpdateCategory() {
107-
`when`(mockContestBuilder.getCategories()).thenReturn(categories)
107+
`when`(mockContestBuilder.categories).thenReturn(categories)
108108
presenter.onContestEditEntered(0, "New Name", "New Description")
109109
verify<View>(mockView).showUpdatedCategories()
110110
}

0 commit comments

Comments
 (0)