Skip to content

Commit 97c037b

Browse files
feat: add hashtags to event cards
1 parent 3d3a586 commit 97c037b

19 files changed

+257
-40
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ dependencies {
118118
testImplementation "androidx.room:room-testing:${roomVersion}"
119119
implementation 'androidx.preference:preference:1.1.0-alpha01'
120120
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
121+
implementation "com.google.code.gson:gson:2.8.5"
121122

122123
// KTX
123124
implementation "androidx.core:core-ktx:$ktx_version"

app/src/main/java/org/fossasia/openevent/general/OpenEventDatabase.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import org.fossasia.openevent.general.auth.UserDao
1313
import org.fossasia.openevent.general.event.Event
1414
import org.fossasia.openevent.general.event.EventDao
1515
import org.fossasia.openevent.general.event.EventIdConverter
16+
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
17+
import org.fossasia.openevent.general.event.subtopic.EventSubTopicConverter
18+
import org.fossasia.openevent.general.event.subtopic.EventSubTopicDao
1619
import org.fossasia.openevent.general.event.topic.EventTopic
17-
import org.fossasia.openevent.general.event.topic.EventTopicIdConverter
20+
import org.fossasia.openevent.general.event.topic.EventTopicConverter
1821
import org.fossasia.openevent.general.event.topic.EventTopicsDao
22+
import org.fossasia.openevent.general.event.types.EventType
23+
import org.fossasia.openevent.general.event.types.EventTypeConverter
24+
import org.fossasia.openevent.general.event.types.EventTypesDao
1925
import org.fossasia.openevent.general.order.Order
2026
import org.fossasia.openevent.general.order.OrderDao
2127
import org.fossasia.openevent.general.social.SocialLink
@@ -25,8 +31,10 @@ import org.fossasia.openevent.general.ticket.TicketDao
2531
import org.fossasia.openevent.general.ticket.TicketIdConverter
2632

2733
@Database(entities = [Event::class, User::class, SocialLink::class, Ticket::class, Attendee::class,
28-
EventTopic::class, Order::class, CustomForm::class], version = 2)
29-
@TypeConverters(EventIdConverter::class, EventTopicIdConverter::class, TicketIdConverter::class,
34+
EventTopic::class, EventSubTopic::class, EventType::class,
35+
Order::class, CustomForm::class], version = 3)
36+
@TypeConverters(EventIdConverter::class, EventTopicConverter::class, EventTypeConverter::class,
37+
EventSubTopicConverter::class, TicketIdConverter::class,
3038
AttendeeIdConverter::class, ListAttendeeIdConverter::class)
3139
abstract class OpenEventDatabase : RoomDatabase() {
3240

@@ -42,5 +50,9 @@ abstract class OpenEventDatabase : RoomDatabase() {
4250

4351
abstract fun eventTopicsDao(): EventTopicsDao
4452

53+
abstract fun eventTypesDao(): EventTypesDao
54+
55+
abstract fun eventSubTopicDao(): EventSubTopicDao
56+
4557
abstract fun orderDao(): OrderDao
4658
}

app/src/main/java/org/fossasia/openevent/general/di/Modules.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.facebook.stetho.okhttp3.StethoInterceptor
55
import com.fasterxml.jackson.databind.DeserializationFeature
66
import com.fasterxml.jackson.databind.ObjectMapper
77
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
8+
import com.github.jasminb.jsonapi.ResourceConverter
9+
import com.github.jasminb.jsonapi.SerializationFeature
810
import com.github.jasminb.jsonapi.retrofit.JSONAPIConverterFactory
911
import okhttp3.Interceptor
1012
import okhttp3.OkHttpClient
@@ -42,6 +44,7 @@ import org.fossasia.openevent.general.event.EventsListAdapter
4244
import org.fossasia.openevent.general.event.EventsViewModel
4345
import org.fossasia.openevent.general.event.location.EventLocation
4446
import org.fossasia.openevent.general.event.location.EventLocationApi
47+
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
4548
import org.fossasia.openevent.general.event.topic.EventTopic
4649
import org.fossasia.openevent.general.event.topic.EventTopicApi
4750
import org.fossasia.openevent.general.event.types.EventType
@@ -136,7 +139,7 @@ val apiModule = module {
136139
factory { AuthHolder(get()) }
137140
factory { AuthService(get(), get(), get()) }
138141

139-
factory { EventService(get(), get(), get(), get(), get(), get()) }
142+
factory { EventService(get(), get(), get(), get(), get(), get(), get(), get()) }
140143
factory { TicketService(get(), get()) }
141144
factory { SocialLinksService(get(), get()) }
142145
factory { AttendeeService(get(), get(), get()) }
@@ -196,15 +199,20 @@ val networkModule = module {
196199
single {
197200
val baseUrl = BuildConfig.DEFAULT_BASE_URL
198201
val objectMapper: ObjectMapper = get()
202+
val onlineApiResourceConverter = ResourceConverter(
203+
objectMapper, Event::class.java, User::class.java,
204+
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
205+
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
206+
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
207+
CustomForm::class.java, EventLocation::class.java, EventType::class.java,
208+
EventSubTopic::class.java)
209+
210+
onlineApiResourceConverter.enableSerializationOption(SerializationFeature.INCLUDE_RELATIONSHIP_ATTRIBUTES)
199211

200212
Retrofit.Builder()
201213
.client(get())
202214
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
203-
.addConverterFactory(JSONAPIConverterFactory(objectMapper, Event::class.java, User::class.java,
204-
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
205-
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
206-
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
207-
CustomForm::class.java, EventLocation::class.java, EventType::class.java))
215+
.addConverterFactory(JSONAPIConverterFactory(onlineApiResourceConverter))
208216
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
209217
.baseUrl(baseUrl)
210218
.build()
@@ -254,6 +262,16 @@ val databaseModule = module {
254262
val database: OpenEventDatabase = get()
255263
database.orderDao()
256264
}
265+
266+
factory {
267+
val database: OpenEventDatabase = get()
268+
database.eventTypesDao()
269+
}
270+
271+
factory {
272+
val database: OpenEventDatabase = get()
273+
database.eventSubTopicDao()
274+
}
257275
}
258276

259277
val fragmentsModule = module {

app/src/main/java/org/fossasia/openevent/general/event/Event.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import com.github.jasminb.jsonapi.LongIdHandler
99
import com.github.jasminb.jsonapi.annotations.Id
1010
import com.github.jasminb.jsonapi.annotations.Relationship
1111
import com.github.jasminb.jsonapi.annotations.Type
12+
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
1213
import org.fossasia.openevent.general.event.topic.EventTopic
14+
import org.fossasia.openevent.general.event.types.EventType
1315

1416
@Type("event")
1517
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
@@ -68,6 +70,13 @@ data class Event(
6870
val isMapShown: Boolean = false,
6971
var favorite: Boolean = false,
7072
@ColumnInfo(index = true)
71-
@Relationship("event-topic")
72-
var eventTopic: EventTopic? = null
73+
@Relationship("event-topic", resolve = true)
74+
var eventTopic: EventTopic? = null,
75+
@ColumnInfo(index = true)
76+
@Relationship("event-type", resolve = true)
77+
var eventType: EventType? = null,
78+
@ColumnInfo(index = true)
79+
@Relationship("event-sub-topic", resolve = true)
80+
var eventSubTopic: EventSubTopic? = null
81+
7382
)

app/src/main/java/org/fossasia/openevent/general/event/EventApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface EventApi {
1010
@GET("events?include=event-topic")
1111
fun getEvents(): Single<List<Event>>
1212

13-
@GET("events?include=event-topic")
13+
@GET("events?include=event-sub-topic,event-topic,event-type")
1414
fun searchEvents(@Query("sort") sort: String, @Query("filter") eventName: String): Single<List<Event>>
1515

1616
@GET

app/src/main/java/org/fossasia/openevent/general/event/EventDetailsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class EventDetailsFragment : Fragment() {
258258
if (event.eventTopic != null || !event.locationName.isNullOrBlank() ||
259259
!event.searchableLocationName.isNullOrBlank()) {
260260
similarEventsContainer.isVisible = true
261-
eventTopicId = event.eventTopic?.id
261+
eventTopicId = event.eventTopic?.id ?: 0
262262
eventLocation =
263263
if (event.searchableLocationName.isNullOrBlank()) event.locationName
264264
else event.searchableLocationName

app/src/main/java/org/fossasia/openevent/general/event/EventService.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import io.reactivex.Flowable
55
import io.reactivex.Single
66
import org.fossasia.openevent.general.event.location.EventLocation
77
import org.fossasia.openevent.general.event.location.EventLocationApi
8+
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
9+
import org.fossasia.openevent.general.event.subtopic.EventSubTopicDao
810
import org.fossasia.openevent.general.event.topic.EventTopic
911
import org.fossasia.openevent.general.event.topic.EventTopicApi
1012
import org.fossasia.openevent.general.event.topic.EventTopicsDao
1113
import org.fossasia.openevent.general.event.types.EventType
1214
import org.fossasia.openevent.general.event.types.EventTypesApi
13-
15+
import org.fossasia.openevent.general.event.types.EventTypesDao
1416
import java.util.Locale.filter
1517

1618
class EventService(
@@ -19,6 +21,8 @@ class EventService(
1921
private val eventTopicApi: EventTopicApi,
2022
private val eventTopicsDao: EventTopicsDao,
2123
private val eventTypesApi: EventTypesApi,
24+
private val eventTypesDao: EventTypesDao,
25+
private val eventSubTopicDao: EventSubTopicDao,
2226
private val eventLocationApi: EventLocationApi
2327
) {
2428

@@ -51,6 +55,20 @@ class EventService(
5155
.toList()
5256
}
5357

58+
private fun getEventSubTopicList(eventsList: List<Event>): List<EventSubTopic?> {
59+
return eventsList
60+
.filter { it.eventSubTopic != null }
61+
.map { it.eventSubTopic }
62+
.toList()
63+
}
64+
65+
private fun getEventTypeList(eventsList: List<Event>): List<EventType?> {
66+
return eventsList
67+
.filter { it.eventType != null }
68+
.map { it.eventType }
69+
.toList()
70+
}
71+
5472
fun getEventTopics(): Flowable<List<EventTopic>> {
5573
return eventTopicsDao.getAllEventTopics()
5674
}
@@ -76,6 +94,8 @@ class EventService(
7694
return eventApi.searchEvents("name", locationName).flatMap { apiList ->
7795
val eventIds = apiList.map { it.id }.toList()
7896
eventTopicsDao.insertEventTopics(getEventTopicList(apiList))
97+
eventTypesDao.insertEventTypes(getEventTypeList(apiList))
98+
eventSubTopicDao.insertEventSubTopics(getEventSubTopicList(apiList))
7999
eventDao.getFavoriteEventWithinIds(eventIds).flatMap { favIds ->
80100
updateFavorites(apiList, favIds)
81101
}
@@ -97,6 +117,10 @@ class EventService(
97117
return eventApi.getEventFromApi(id)
98118
}
99119

120+
fun getEventTypeFromid(id: Long): EventType {
121+
return eventTypesDao.getEventType(id)
122+
}
123+
100124
fun getEventsUnderUser(eventId: String): Single<List<Event>> {
101125
return eventApi.eventsUnderUser(eventId)
102126
}

app/src/main/java/org/fossasia/openevent/general/event/EventViewHolder.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.fossasia.openevent.general.event
22

3+
import android.content.res.ColorStateList
34
import android.view.View
5+
import androidx.core.content.ContextCompat
46
import androidx.recyclerview.widget.RecyclerView
7+
import com.google.android.material.chip.Chip
58
import com.squareup.picasso.Callback
69
import com.squareup.picasso.Picasso
710
import kotlinx.android.extensions.LayoutContainer
11+
import kotlinx.android.synthetic.main.item_card_events.view.chipTags
812
import kotlinx.android.synthetic.main.item_card_events.view.date
913
import kotlinx.android.synthetic.main.item_card_events.view.eventImage
1014
import kotlinx.android.synthetic.main.item_card_events.view.eventName
@@ -57,6 +61,19 @@ class EventViewHolder(override val containerView: View) : RecyclerView.ViewHolde
5761

5862
setFabBackground(event.favorite)
5963

64+
event.eventType.let {
65+
if (it != null)
66+
addchips(it.name)
67+
}
68+
event.eventTopic.let {
69+
if (it != null)
70+
addchips(it.name)
71+
}
72+
event.eventSubTopic.let {
73+
if (it != null)
74+
addchips(it.name)
75+
}
76+
6077
event.originalImageUrl?.let { url ->
6178
Picasso.get()
6279
.load(url)
@@ -87,6 +104,18 @@ class EventViewHolder(override val containerView: View) : RecyclerView.ViewHolde
87104
}
88105
}
89106

107+
private fun addchips(name: String) {
108+
val chip = Chip(containerView.context)
109+
chip.text = name
110+
chip.isCheckable = false
111+
chip.chipStartPadding = 0f
112+
chip.chipEndPadding = 0f
113+
chip.chipStrokeWidth = 2f
114+
chip.chipStrokeColor =
115+
ColorStateList.valueOf(ContextCompat.getColor(containerView.context, R.color.colorPrimary))
116+
containerView.chipTags.addView(chip)
117+
}
118+
90119
private fun setFabBackground(isFavorite: Boolean) {
91120
if (isFavorite) {
92121
containerView.favoriteFab.setImageResource(R.drawable.ic_baseline_favorite)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.fossasia.openevent.general.event.subtopic
2+
3+
import androidx.room.ColumnInfo
4+
import androidx.room.Entity
5+
import androidx.room.ForeignKey
6+
import androidx.room.PrimaryKey
7+
import com.github.jasminb.jsonapi.LongIdHandler
8+
import com.github.jasminb.jsonapi.annotations.Id
9+
import com.github.jasminb.jsonapi.annotations.Relationship
10+
import com.github.jasminb.jsonapi.annotations.Type
11+
import org.fossasia.openevent.general.event.Event
12+
import org.fossasia.openevent.general.event.EventId
13+
14+
@Type("event-sub-topic")
15+
@Entity(foreignKeys = [(ForeignKey(entity = Event::class, parentColumns = ["id"],
16+
childColumns = ["event"], onDelete = ForeignKey.CASCADE))])
17+
data class EventSubTopic(
18+
@Id(LongIdHandler::class)
19+
@PrimaryKey
20+
val id: Long,
21+
val name: String,
22+
val slug: String,
23+
@ColumnInfo(index = true)
24+
@Relationship("event")
25+
var event: EventId? = null
26+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.fossasia.openevent.general.event.subtopic
2+
3+
import androidx.room.TypeConverter
4+
import com.google.gson.Gson
5+
import com.google.gson.reflect.TypeToken
6+
7+
class EventSubTopicConverter {
8+
@TypeConverter
9+
fun toEventSubTopic(json: String): EventSubTopic? {
10+
val type = object : TypeToken<EventSubTopic>() {}.type
11+
return Gson().fromJson(json, type)
12+
}
13+
14+
@TypeConverter
15+
fun toJson(eventSubTopic: EventSubTopic?) = Gson().toJson(eventSubTopic)
16+
}

0 commit comments

Comments
 (0)