Skip to content

Commit 0a2f916

Browse files
aggarwalpulkit596iamareebjamal
authored andcommitted
feat: add hashtags to event cards (#1595)
1 parent e1c4843 commit 0a2f916

File tree

15 files changed

+194
-49
lines changed

15 files changed

+194
-49
lines changed

app/schemas/org.fossasia.openevent.general.OpenEventDatabase/2.json

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"formatVersion": 1,
33
"database": {
4-
"version": 2,
5-
"identityHash": "29d454b1b501a8b9b411acc8476eab7c",
4+
"version": 3,
5+
"identityHash": "1badd5e17f181e602314a4244c04cf56",
66
"entities": [
77
{
88
"tableName": "Event",
9-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `identifier` TEXT NOT NULL, `startsAt` TEXT NOT NULL, `endsAt` TEXT NOT NULL, `timezone` TEXT NOT NULL, `privacy` TEXT NOT NULL, `paymentCountry` TEXT, `paypalEmail` TEXT, `thumbnailImageUrl` TEXT, `schedulePublishedOn` TEXT, `paymentCurrency` TEXT, `organizerDescription` TEXT, `originalImageUrl` TEXT, `onsiteDetails` TEXT, `organizerName` TEXT, `largeImageUrl` TEXT, `deletedAt` TEXT, `ticketUrl` TEXT, `locationName` TEXT, `codeOfConduct` TEXT, `state` TEXT, `searchableLocationName` TEXT, `description` TEXT, `pentabarfUrl` TEXT, `xcalUrl` TEXT, `logoUrl` TEXT, `externalEventUrl` TEXT, `iconImageUrl` TEXT, `icalUrl` TEXT, `createdAt` TEXT, `bankDetails` TEXT, `chequeDetails` TEXT, `isComplete` INTEGER NOT NULL, `latitude` REAL, `longitude` REAL, `refundPolicy` TEXT, `canPayByStripe` INTEGER NOT NULL, `canPayByCheque` INTEGER NOT NULL, `canPayByBank` INTEGER NOT NULL, `canPayByPaypal` INTEGER NOT NULL, `canPayOnsite` INTEGER NOT NULL, `isSponsorsEnabled` INTEGER NOT NULL, `hasOrganizerInfo` INTEGER NOT NULL, `isSessionsSpeakersEnabled` INTEGER NOT NULL, `isTicketingEnabled` INTEGER NOT NULL, `isTaxEnabled` INTEGER NOT NULL, `isMapShown` INTEGER NOT NULL, `favorite` INTEGER NOT NULL, `eventTopic` INTEGER, PRIMARY KEY(`id`))",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `identifier` TEXT NOT NULL, `startsAt` TEXT NOT NULL, `endsAt` TEXT NOT NULL, `timezone` TEXT NOT NULL, `privacy` TEXT NOT NULL, `paymentCountry` TEXT, `paypalEmail` TEXT, `thumbnailImageUrl` TEXT, `schedulePublishedOn` TEXT, `paymentCurrency` TEXT, `organizerDescription` TEXT, `originalImageUrl` TEXT, `onsiteDetails` TEXT, `organizerName` TEXT, `largeImageUrl` TEXT, `deletedAt` TEXT, `ticketUrl` TEXT, `locationName` TEXT, `codeOfConduct` TEXT, `state` TEXT, `searchableLocationName` TEXT, `description` TEXT, `pentabarfUrl` TEXT, `xcalUrl` TEXT, `logoUrl` TEXT, `externalEventUrl` TEXT, `iconImageUrl` TEXT, `icalUrl` TEXT, `createdAt` TEXT, `bankDetails` TEXT, `chequeDetails` TEXT, `isComplete` INTEGER NOT NULL, `latitude` REAL, `longitude` REAL, `refundPolicy` TEXT, `canPayByStripe` INTEGER NOT NULL, `canPayByCheque` INTEGER NOT NULL, `canPayByBank` INTEGER NOT NULL, `canPayByPaypal` INTEGER NOT NULL, `canPayOnsite` INTEGER NOT NULL, `isSponsorsEnabled` INTEGER NOT NULL, `hasOrganizerInfo` INTEGER NOT NULL, `isSessionsSpeakersEnabled` INTEGER NOT NULL, `isTicketingEnabled` INTEGER NOT NULL, `isTaxEnabled` INTEGER NOT NULL, `isMapShown` INTEGER NOT NULL, `favorite` INTEGER NOT NULL, `eventTopic` TEXT, `eventType` TEXT, `eventSubTopic` TEXT, PRIMARY KEY(`id`))",
1010
"fields": [
1111
{
1212
"fieldPath": "id",
@@ -305,7 +305,19 @@
305305
{
306306
"fieldPath": "eventTopic",
307307
"columnName": "eventTopic",
308-
"affinity": "INTEGER",
308+
"affinity": "TEXT",
309+
"notNull": false
310+
},
311+
{
312+
"fieldPath": "eventType",
313+
"columnName": "eventType",
314+
"affinity": "TEXT",
315+
"notNull": false
316+
},
317+
{
318+
"fieldPath": "eventSubTopic",
319+
"columnName": "eventSubTopic",
320+
"affinity": "TEXT",
309321
"notNull": false
310322
}
311323
],
@@ -323,6 +335,22 @@
323335
"eventTopic"
324336
],
325337
"createSql": "CREATE INDEX `index_Event_eventTopic` ON `${TABLE_NAME}` (`eventTopic`)"
338+
},
339+
{
340+
"name": "index_Event_eventType",
341+
"unique": false,
342+
"columnNames": [
343+
"eventType"
344+
],
345+
"createSql": "CREATE INDEX `index_Event_eventType` ON `${TABLE_NAME}` (`eventType`)"
346+
},
347+
{
348+
"name": "index_Event_eventSubTopic",
349+
"unique": false,
350+
"columnNames": [
351+
"eventSubTopic"
352+
],
353+
"createSql": "CREATE INDEX `index_Event_eventSubTopic` ON `${TABLE_NAME}` (`eventSubTopic`)"
326354
}
327355
],
328356
"foreignKeys": []
@@ -777,25 +805,25 @@
777805
},
778806
{
779807
"tableName": "EventTopic",
780-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `name` TEXT, `slug` TEXT, `event` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`event`) REFERENCES `Event`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
808+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `slug` TEXT NOT NULL, `event` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`event`) REFERENCES `Event`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
781809
"fields": [
782810
{
783811
"fieldPath": "id",
784812
"columnName": "id",
785813
"affinity": "INTEGER",
786-
"notNull": false
814+
"notNull": true
787815
},
788816
{
789817
"fieldPath": "name",
790818
"columnName": "name",
791819
"affinity": "TEXT",
792-
"notNull": false
820+
"notNull": true
793821
},
794822
{
795823
"fieldPath": "slug",
796824
"columnName": "slug",
797825
"affinity": "TEXT",
798-
"notNull": false
826+
"notNull": true
799827
},
800828
{
801829
"fieldPath": "event",
@@ -1261,7 +1289,7 @@
12611289
"views": [],
12621290
"setupQueries": [
12631291
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
1264-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"29d454b1b501a8b9b411acc8476eab7c\")"
1292+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"1badd5e17f181e602314a4244c04cf56\")"
12651293
]
12661294
}
1267-
}
1295+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ 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.EventSubTopicConverter
1617
import org.fossasia.openevent.general.event.topic.EventTopic
17-
import org.fossasia.openevent.general.event.topic.EventTopicIdConverter
18+
import org.fossasia.openevent.general.event.topic.EventTopicConverter
1819
import org.fossasia.openevent.general.event.topic.EventTopicsDao
20+
import org.fossasia.openevent.general.event.types.EventTypeConverter
1921
import org.fossasia.openevent.general.order.Order
2022
import org.fossasia.openevent.general.order.OrderDao
2123
import org.fossasia.openevent.general.social.SocialLink
@@ -29,8 +31,9 @@ import org.fossasia.openevent.general.ticket.TicketDao
2931
import org.fossasia.openevent.general.ticket.TicketIdConverter
3032

3133
@Database(entities = [Event::class, User::class, SocialLink::class, Ticket::class, Attendee::class,
32-
EventTopic::class, Order::class, CustomForm::class, Speaker::class, SpeakerWithEvent::class], version = 2)
33-
@TypeConverters(EventIdConverter::class, EventTopicIdConverter::class, TicketIdConverter::class,
34+
EventTopic::class, Order::class, CustomForm::class, Speaker::class, SpeakerWithEvent::class], version = 3)
35+
@TypeConverters(EventIdConverter::class, EventTopicConverter::class, EventTypeConverter::class,
36+
EventSubTopicConverter::class, TicketIdConverter::class,
3437
AttendeeIdConverter::class, ListAttendeeIdConverter::class)
3538
abstract class OpenEventDatabase : RoomDatabase() {
3639

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

Lines changed: 13 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
@@ -44,6 +46,7 @@ import org.fossasia.openevent.general.event.feedback.Feedback
4446
import org.fossasia.openevent.general.event.feedback.FeedbackApi
4547
import org.fossasia.openevent.general.event.location.EventLocation
4648
import org.fossasia.openevent.general.event.location.EventLocationApi
49+
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
4750
import org.fossasia.openevent.general.event.topic.EventTopic
4851
import org.fossasia.openevent.general.event.topic.EventTopicApi
4952
import org.fossasia.openevent.general.event.types.EventType
@@ -214,16 +217,20 @@ val networkModule = module {
214217
single {
215218
val baseUrl = BuildConfig.DEFAULT_BASE_URL
216219
val objectMapper: ObjectMapper = get()
220+
val onlineApiResourceConverter = ResourceConverter(
221+
objectMapper, Event::class.java, User::class.java,
222+
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
223+
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
224+
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
225+
CustomForm::class.java, EventLocation::class.java, EventType::class.java,
226+
EventSubTopic::class.java, Feedback::class.java, Speaker::class.java)
227+
228+
onlineApiResourceConverter.enableSerializationOption(SerializationFeature.INCLUDE_RELATIONSHIP_ATTRIBUTES)
217229

218230
Retrofit.Builder()
219231
.client(get())
220232
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
221-
.addConverterFactory(JSONAPIConverterFactory(objectMapper, Event::class.java, User::class.java,
222-
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
223-
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
224-
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
225-
CustomForm::class.java, EventLocation::class.java, EventType::class.java,
226-
Feedback::class.java, Speaker::class.java))
233+
.addConverterFactory(JSONAPIConverterFactory(onlineApiResourceConverter))
227234
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
228235
.baseUrl(baseUrl)
229236
.build()

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
@@ -290,7 +290,7 @@ class EventDetailsFragment : Fragment() {
290290
if (event.eventTopic != null || !event.locationName.isNullOrBlank() ||
291291
!event.searchableLocationName.isNullOrBlank()) {
292292
similarEventsContainer.isVisible = true
293-
eventTopicId = event.eventTopic?.id
293+
eventTopicId = event.eventTopic?.id ?: 0
294294
eventLocation =
295295
if (event.searchableLocationName.isNullOrBlank()) event.locationName
296296
else event.searchableLocationName

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.fossasia.openevent.general.event.subtopic
2+
3+
import androidx.room.TypeConverter
4+
import com.fasterxml.jackson.databind.ObjectMapper
5+
6+
class EventSubTopicConverter {
7+
8+
@TypeConverter
9+
fun toEventSubTopic(json: String): EventSubTopic? {
10+
return ObjectMapper().readerFor(EventSubTopic::class.java).readValue<EventSubTopic>(json)
11+
}
12+
13+
@TypeConverter
14+
fun toJson(eventSubTopic: EventSubTopic?) = ObjectMapper().writeValueAsString(eventSubTopic)
15+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import org.fossasia.openevent.general.event.EventId
1717
data class EventTopic(
1818
@Id(LongIdHandler::class)
1919
@PrimaryKey
20-
val id: Long?,
21-
val name: String?,
22-
val slug: String?,
20+
val id: Long,
21+
val name: String,
22+
val slug: String,
2323
@ColumnInfo(index = true)
2424
@Relationship("event")
2525
var event: EventId? = null
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.fossasia.openevent.general.event.topic
2+
3+
import androidx.room.TypeConverter
4+
import com.fasterxml.jackson.databind.ObjectMapper
5+
6+
class EventTopicConverter {
7+
@TypeConverter
8+
fun toEventTopic(json: String): EventTopic? {
9+
return ObjectMapper().readerFor(EventTopic::class.java).readValue<EventTopic>(json)
10+
}
11+
12+
@TypeConverter
13+
fun toJson(eventTopic: EventTopic?) = ObjectMapper().writeValueAsString(eventTopic)
14+
}

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

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.fossasia.openevent.general.event.types
22

3+
import androidx.room.ColumnInfo
34
import androidx.room.Entity
45
import androidx.room.PrimaryKey
56
import com.github.jasminb.jsonapi.LongIdHandler
67
import com.github.jasminb.jsonapi.annotations.Id
8+
import com.github.jasminb.jsonapi.annotations.Relationship
79
import com.github.jasminb.jsonapi.annotations.Type
10+
import org.fossasia.openevent.general.event.EventId
811

912
@Type("event-type")
1013
@Entity
@@ -13,5 +16,8 @@ data class EventType(
1316
@PrimaryKey
1417
val id: Long,
1518
val name: String,
16-
val slug: String
19+
val slug: String,
20+
@ColumnInfo(index = true)
21+
@Relationship("event")
22+
var event: EventId? = null
1723
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.fossasia.openevent.general.event.types
2+
3+
import androidx.room.TypeConverter
4+
import com.fasterxml.jackson.databind.ObjectMapper
5+
6+
class EventTypeConverter {
7+
@TypeConverter
8+
fun toEventType(json: String): EventType? {
9+
return ObjectMapper().readerFor(EventType::class.java).readValue<EventType>(json)
10+
}
11+
12+
@TypeConverter
13+
fun toJson(eventType: EventType?) = ObjectMapper().writeValueAsString(eventType)
14+
}

0 commit comments

Comments
 (0)