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

feat: add hashtags to event cards #1595

Merged
merged 2 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 38 additions & 10 deletions app/schemas/org.fossasia.openevent.general.OpenEventDatabase/2.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "29d454b1b501a8b9b411acc8476eab7c",
"version": 3,
"identityHash": "1badd5e17f181e602314a4244c04cf56",
"entities": [
{
"tableName": "Event",
"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`))",
"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`))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -305,7 +305,19 @@
{
"fieldPath": "eventTopic",
"columnName": "eventTopic",
"affinity": "INTEGER",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "eventType",
"columnName": "eventType",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "eventSubTopic",
"columnName": "eventSubTopic",
"affinity": "TEXT",
"notNull": false
}
],
Expand All @@ -323,6 +335,22 @@
"eventTopic"
],
"createSql": "CREATE INDEX `index_Event_eventTopic` ON `${TABLE_NAME}` (`eventTopic`)"
},
{
"name": "index_Event_eventType",
"unique": false,
"columnNames": [
"eventType"
],
"createSql": "CREATE INDEX `index_Event_eventType` ON `${TABLE_NAME}` (`eventType`)"
},
{
"name": "index_Event_eventSubTopic",
"unique": false,
"columnNames": [
"eventSubTopic"
],
"createSql": "CREATE INDEX `index_Event_eventSubTopic` ON `${TABLE_NAME}` (`eventSubTopic`)"
}
],
"foreignKeys": []
Expand Down Expand Up @@ -777,25 +805,25 @@
},
{
"tableName": "EventTopic",
"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 )",
"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 )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
"notNull": true
},
{
"fieldPath": "slug",
"columnName": "slug",
"affinity": "TEXT",
"notNull": false
"notNull": true
},
{
"fieldPath": "event",
Expand Down Expand Up @@ -1261,7 +1289,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"29d454b1b501a8b9b411acc8476eab7c\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"1badd5e17f181e602314a4244c04cf56\")"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import org.fossasia.openevent.general.auth.UserDao
import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventDao
import org.fossasia.openevent.general.event.EventIdConverter
import org.fossasia.openevent.general.event.subtopic.EventSubTopicConverter
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.topic.EventTopicIdConverter
import org.fossasia.openevent.general.event.topic.EventTopicConverter
import org.fossasia.openevent.general.event.topic.EventTopicsDao
import org.fossasia.openevent.general.event.types.EventTypeConverter
import org.fossasia.openevent.general.order.Order
import org.fossasia.openevent.general.order.OrderDao
import org.fossasia.openevent.general.social.SocialLink
Expand All @@ -29,8 +31,9 @@ import org.fossasia.openevent.general.ticket.TicketDao
import org.fossasia.openevent.general.ticket.TicketIdConverter

@Database(entities = [Event::class, User::class, SocialLink::class, Ticket::class, Attendee::class,
EventTopic::class, Order::class, CustomForm::class, Speaker::class, SpeakerWithEvent::class], version = 2)
@TypeConverters(EventIdConverter::class, EventTopicIdConverter::class, TicketIdConverter::class,
EventTopic::class, Order::class, CustomForm::class, Speaker::class, SpeakerWithEvent::class], version = 3)
@TypeConverters(EventIdConverter::class, EventTopicConverter::class, EventTypeConverter::class,
EventSubTopicConverter::class, TicketIdConverter::class,
AttendeeIdConverter::class, ListAttendeeIdConverter::class)
abstract class OpenEventDatabase : RoomDatabase() {

Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/org/fossasia/openevent/general/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.facebook.stetho.okhttp3.StethoInterceptor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.jasminb.jsonapi.ResourceConverter
import com.github.jasminb.jsonapi.SerializationFeature
import com.github.jasminb.jsonapi.retrofit.JSONAPIConverterFactory
import okhttp3.Interceptor
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -44,6 +46,7 @@ import org.fossasia.openevent.general.event.feedback.Feedback
import org.fossasia.openevent.general.event.feedback.FeedbackApi
import org.fossasia.openevent.general.event.location.EventLocation
import org.fossasia.openevent.general.event.location.EventLocationApi
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.topic.EventTopicApi
import org.fossasia.openevent.general.event.types.EventType
Expand Down Expand Up @@ -214,16 +217,20 @@ val networkModule = module {
single {
val baseUrl = BuildConfig.DEFAULT_BASE_URL
val objectMapper: ObjectMapper = get()
val onlineApiResourceConverter = ResourceConverter(
objectMapper, Event::class.java, User::class.java,
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
CustomForm::class.java, EventLocation::class.java, EventType::class.java,
EventSubTopic::class.java, Feedback::class.java, Speaker::class.java)

onlineApiResourceConverter.enableSerializationOption(SerializationFeature.INCLUDE_RELATIONSHIP_ATTRIBUTES)

Retrofit.Builder()
.client(get())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JSONAPIConverterFactory(objectMapper, Event::class.java, User::class.java,
SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java,
EventTopic::class.java, Attendee::class.java, TicketId::class.java, Order::class.java,
AttendeeId::class.java, Charge::class.java, Paypal::class.java, ConfirmOrder::class.java,
CustomForm::class.java, EventLocation::class.java, EventType::class.java,
Feedback::class.java, Speaker::class.java))
.addConverterFactory(JSONAPIConverterFactory(onlineApiResourceConverter))
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.baseUrl(baseUrl)
.build()
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/org/fossasia/openevent/general/event/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.github.jasminb.jsonapi.LongIdHandler
import com.github.jasminb.jsonapi.annotations.Id
import com.github.jasminb.jsonapi.annotations.Relationship
import com.github.jasminb.jsonapi.annotations.Type
import org.fossasia.openevent.general.event.subtopic.EventSubTopic
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.types.EventType

@Type("event")
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
Expand Down Expand Up @@ -68,6 +70,13 @@ data class Event(
val isMapShown: Boolean = false,
var favorite: Boolean = false,
@ColumnInfo(index = true)
@Relationship("event-topic")
var eventTopic: EventTopic? = null
@Relationship("event-topic", resolve = true)
var eventTopic: EventTopic? = null,
@ColumnInfo(index = true)
@Relationship("event-type", resolve = true)
var eventType: EventType? = null,
@ColumnInfo(index = true)
@Relationship("event-sub-topic", resolve = true)
var eventSubTopic: EventSubTopic? = null

)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface EventApi {
@GET("events?include=event-topic")
fun getEvents(): Single<List<Event>>

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

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class EventDetailsFragment : Fragment() {
if (event.eventTopic != null || !event.locationName.isNullOrBlank() ||
!event.searchableLocationName.isNullOrBlank()) {
similarEventsContainer.isVisible = true
eventTopicId = event.eventTopic?.id
eventTopicId = event.eventTopic?.id ?: 0
eventLocation =
if (event.searchableLocationName.isNullOrBlank()) event.locationName
else event.searchableLocationName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.fossasia.openevent.general.event

import android.content.res.ColorStateList
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_card_events.view.chipTags
import kotlinx.android.synthetic.main.item_card_events.view.date
import kotlinx.android.synthetic.main.item_card_events.view.eventImage
import kotlinx.android.synthetic.main.item_card_events.view.eventName
Expand Down Expand Up @@ -57,6 +61,19 @@ class EventViewHolder(override val containerView: View) : RecyclerView.ViewHolde

setFabBackground(event.favorite)

event.eventType.let {
if (it != null)
addchips(it.name)
}
event.eventTopic.let {
if (it != null)
addchips(it.name)
}
event.eventSubTopic.let {
if (it != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for explicit null checks?
Using ?.let would work?

addchips(it.name)
}

event.originalImageUrl?.let { url ->
Picasso.get()
.load(url)
Expand Down Expand Up @@ -87,6 +104,18 @@ class EventViewHolder(override val containerView: View) : RecyclerView.ViewHolde
}
}

private fun addchips(name: String) {
val chip = Chip(containerView.context)
chip.text = name
chip.isCheckable = false
chip.chipStartPadding = 0f
chip.chipEndPadding = 0f
chip.chipStrokeWidth = 2f
chip.chipStrokeColor =
ColorStateList.valueOf(ContextCompat.getColor(containerView.context, R.color.colorPrimary))
containerView.chipTags.addView(chip)
}

private fun setFabBackground(isFavorite: Boolean) {
if (isFavorite) {
containerView.favoriteFab.setImageResource(R.drawable.ic_baseline_favorite)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.fossasia.openevent.general.event.subtopic

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import com.github.jasminb.jsonapi.LongIdHandler
import com.github.jasminb.jsonapi.annotations.Id
import com.github.jasminb.jsonapi.annotations.Relationship
import com.github.jasminb.jsonapi.annotations.Type
import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventId

@Type("event-sub-topic")
@Entity(foreignKeys = [(ForeignKey(entity = Event::class, parentColumns = ["id"],
childColumns = ["event"], onDelete = ForeignKey.CASCADE))])
data class EventSubTopic(
@Id(LongIdHandler::class)
@PrimaryKey
val id: Long,
val name: String,
val slug: String,
@ColumnInfo(index = true)
@Relationship("event")
var event: EventId? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.fossasia.openevent.general.event.subtopic

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper

class EventSubTopicConverter {
aggarwalpulkit596 marked this conversation as resolved.
Show resolved Hide resolved

@TypeConverter
fun toEventSubTopic(json: String): EventSubTopic? {
return ObjectMapper().readerFor(EventSubTopic::class.java).readValue<EventSubTopic>(json)
}

@TypeConverter
fun toJson(eventSubTopic: EventSubTopic?) = ObjectMapper().writeValueAsString(eventSubTopic)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import org.fossasia.openevent.general.event.EventId
data class EventTopic(
@Id(LongIdHandler::class)
@PrimaryKey
val id: Long?,
val name: String?,
val slug: String?,
val id: Long,
val name: String,
val slug: String,
@ColumnInfo(index = true)
@Relationship("event")
var event: EventId? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.fossasia.openevent.general.event.topic

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper

class EventTopicConverter {
@TypeConverter
fun toEventTopic(json: String): EventTopic? {
return ObjectMapper().readerFor(EventTopic::class.java).readValue<EventTopic>(json)
}

@TypeConverter
fun toJson(eventTopic: EventTopic?) = ObjectMapper().writeValueAsString(eventTopic)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.fossasia.openevent.general.event.types

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.github.jasminb.jsonapi.LongIdHandler
import com.github.jasminb.jsonapi.annotations.Id
import com.github.jasminb.jsonapi.annotations.Relationship
import com.github.jasminb.jsonapi.annotations.Type
import org.fossasia.openevent.general.event.EventId

@Type("event-type")
@Entity
Expand All @@ -13,5 +16,8 @@ data class EventType(
@PrimaryKey
val id: Long,
val name: String,
val slug: String
val slug: String,
@ColumnInfo(index = true)
@Relationship("event")
var event: EventId? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.fossasia.openevent.general.event.types

import androidx.room.TypeConverter
import com.fasterxml.jackson.databind.ObjectMapper

class EventTypeConverter {
@TypeConverter
fun toEventType(json: String): EventType? {
return ObjectMapper().readerFor(EventType::class.java).readValue<EventType>(json)
}

@TypeConverter
fun toJson(eventType: EventType?) = ObjectMapper().writeValueAsString(eventType)
}
Loading