Skip to content

Commit

Permalink
feat: add hashtags to event cards
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarwalpulkit596 committed Apr 16, 2019
1 parent 3d3a586 commit 4d84231
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ 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.EventSubTopic
import org.fossasia.openevent.general.event.subtopic.EventSubTopicDao
import org.fossasia.openevent.general.event.subtopic.EventSubTopicIdConverter
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.topic.EventTopicIdConverter
import org.fossasia.openevent.general.event.topic.EventTopicsDao
import org.fossasia.openevent.general.event.types.EventType
import org.fossasia.openevent.general.event.types.EventTypeIdConverter
import org.fossasia.openevent.general.event.types.EventTypesDao
import org.fossasia.openevent.general.order.Order
import org.fossasia.openevent.general.order.OrderDao
import org.fossasia.openevent.general.social.SocialLink
Expand All @@ -25,8 +31,10 @@ 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], version = 2)
@TypeConverters(EventIdConverter::class, EventTopicIdConverter::class, TicketIdConverter::class,
EventTopic::class, EventSubTopic::class, EventType::class,
Order::class, CustomForm::class], version = 3)
@TypeConverters(EventIdConverter::class, EventTopicIdConverter::class, EventTypeIdConverter::class,
EventSubTopicIdConverter::class, TicketIdConverter::class,
AttendeeIdConverter::class, ListAttendeeIdConverter::class)
abstract class OpenEventDatabase : RoomDatabase() {

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

abstract fun eventTopicsDao(): EventTopicsDao

abstract fun eventTypesDao(): EventTypesDao

abstract fun eventSubTopicDao(): EventSubTopicDao

abstract fun orderDao(): OrderDao
}
30 changes: 24 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 @@ -42,6 +44,7 @@ import org.fossasia.openevent.general.event.EventsListAdapter
import org.fossasia.openevent.general.event.EventsViewModel
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 @@ -136,7 +139,7 @@ val apiModule = module {
factory { AuthHolder(get()) }
factory { AuthService(get(), get(), get()) }

factory { EventService(get(), get(), get(), get(), get(), get()) }
factory { EventService(get(), get(), get(), get(), get(), get(), get(), get()) }
factory { TicketService(get(), get()) }
factory { SocialLinksService(get(), get()) }
factory { AttendeeService(get(), get(), get()) }
Expand Down Expand Up @@ -196,15 +199,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)

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))
.addConverterFactory(JSONAPIConverterFactory(onlineApiResourceConverter))
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.baseUrl(baseUrl)
.build()
Expand Down Expand Up @@ -254,6 +262,16 @@ val databaseModule = module {
val database: OpenEventDatabase = get()
database.orderDao()
}

factory {
val database: OpenEventDatabase = get()
database.eventTypesDao()
}

factory {
val database: OpenEventDatabase = get()
database.eventSubTopicDao()
}
}

val fragmentsModule = module {
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 @@ -258,7 +258,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
Expand Up @@ -5,12 +5,14 @@ import io.reactivex.Flowable
import io.reactivex.Single
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.subtopic.EventSubTopicDao
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.topic.EventTopicApi
import org.fossasia.openevent.general.event.topic.EventTopicsDao
import org.fossasia.openevent.general.event.types.EventType
import org.fossasia.openevent.general.event.types.EventTypesApi

import org.fossasia.openevent.general.event.types.EventTypesDao
import java.util.Locale.filter

class EventService(
Expand All @@ -19,6 +21,8 @@ class EventService(
private val eventTopicApi: EventTopicApi,
private val eventTopicsDao: EventTopicsDao,
private val eventTypesApi: EventTypesApi,
private val eventTypesDao: EventTypesDao,
private val eventSubTopicDao: EventSubTopicDao,
private val eventLocationApi: EventLocationApi
) {

Expand Down Expand Up @@ -51,6 +55,20 @@ class EventService(
.toList()
}

private fun getEventSubTopicList(eventsList: List<Event>): List<EventSubTopic?> {
return eventsList
.filter { it.eventSubTopic != null }
.map { it.eventSubTopic }
.toList()
}

private fun getEventTypeList(eventsList: List<Event>): List<EventType?> {
return eventsList
.filter { it.eventType != null }
.map { it.eventType }
.toList()
}

fun getEventTopics(): Flowable<List<EventTopic>> {
return eventTopicsDao.getAllEventTopics()
}
Expand All @@ -76,6 +94,8 @@ class EventService(
return eventApi.searchEvents("name", locationName).flatMap { apiList ->
val eventIds = apiList.map { it.id }.toList()
eventTopicsDao.insertEventTopics(getEventTopicList(apiList))
eventTypesDao.insertEventTypes(getEventTypeList(apiList))
eventSubTopicDao.insertEventSubTopics(getEventSubTopicList(apiList))
eventDao.getFavoriteEventWithinIds(eventIds).flatMap { favIds ->
updateFavorites(apiList, favIds)
}
Expand All @@ -97,6 +117,10 @@ class EventService(
return eventApi.getEventFromApi(id)
}

fun getEventTypeFromid(id: Long): EventType {
return eventTypesDao.getEventType(id)
}

fun getEventsUnderUser(eventId: String): Single<List<Event>> {
return eventApi.eventsUnderUser(eventId)
}
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)
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,23 @@
package org.fossasia.openevent.general.event.subtopic

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.reactivex.Flowable

@Dao
interface EventSubTopicDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertEventSubTopics(eventSubTopic: List<EventSubTopic?>)

@Query("SELECT * from EventSubTopic")
fun getAllEventSubTopic(): Flowable<List<EventSubTopic>>

@Query("SELECT * from EventSubTopic WHERE id = :id")
fun getEventSubTopic(id: Long): EventSubTopic

@Query("DELETE FROM EventSubTopic")
fun deleteAll()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.fossasia.openevent.general.event.subtopic

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class EventSubTopicIdConverter {
@TypeConverter
fun toEventSubTopic(json: String): EventSubTopic? {
val type = object : TypeToken<EventSubTopic>() {}.type
return Gson().fromJson(json, type)
}

@TypeConverter
fun toJson(eventSubTopic: EventSubTopic?) = Gson().toJson(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
@@ -1,20 +1,17 @@
package org.fossasia.openevent.general.event.topic

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class EventTopicIdConverter {

@TypeConverter
fun fromEventTopic(eventTopic: EventTopic?): Long? {
return eventTopic?.id ?: -1
fun toEventSubTopic(json: String): EventTopic? {
val type = object : TypeToken<EventTopic>() {}.type
return Gson().fromJson(json, type)
}

@TypeConverter
fun toEventTopic(id: Long?): EventTopic {
return if (id == null) {
EventTopic(-1, "", "")
} else {
EventTopic(id, "", "")
}
}
fun toJson(eventSubTopic: EventTopic?) = Gson().toJson(eventSubTopic)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface EventTopicsDao {
@Query("SELECT * from EventTopic")
fun getAllEventTopics(): Flowable<List<EventTopic>>

@Query("SELECT * from EventTopic WHERE id = :id")
fun getEventTopic(id: Long): EventTopic

@Query("DELETE FROM EventTopic")
fun deleteAll()
}
Loading

0 comments on commit 4d84231

Please sign in to comment.