-
Notifications
You must be signed in to change notification settings - Fork 556
feat: Show similar events based on event topic #198
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: Show similar events based on event topic #198
Conversation
| @@ -0,0 +1,11 @@ | |||
| package org.fossasia.openevent.general.similar | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What similar?
| fun getEventTopicOfEvent(eventId: Long): Flowable<EventTopic> | ||
| */ | ||
| @Query("UPDATE Event SET favorite = :favorite WHERE id = :eventId") | ||
| fun setFavorite(eventId: Long, favorite: Boolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ummm This is EventDao
| val similarEvents = MutableLiveData<List<Event>>() | ||
| val error = MutableLiveData<String>() | ||
|
|
||
| fun getSimilarEvents(id: Long) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A void getter!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change the function name 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PR 👍
| val view = LayoutInflater.from(parent.context).inflate(R.layout.item_card_events, parent, false) | ||
| return EventViewHolder(view) | ||
| val eventView: View | ||
| if (eventLayout.equals("similarEvents")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep similarEvents and events in some constant string and use reference here
| @GET("event-topics/{id}") | ||
| fun getEventTopic(@Path("id") id: Long): Single<EventTopic> | ||
|
|
||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you keeping commented code?
| .map { | ||
| eventTopicsDao.insertSimilarEvents(it) | ||
| } | ||
| .toFlowable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take this to the line above
| eventTopicsDao.insertEventTopic(it) | ||
| it | ||
| } | ||
| .toFlowable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| /* | ||
| @Insert(onConflict = OnConflictStrategy.REPLACE) | ||
| fun insertEventTopic(eventTopic: EventTopic) | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code?
| /* | ||
| @Query("DELETE FROM EventTopic") | ||
| fun deleteAllEventTopics() | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I might probably require these methods in future, will probably remove them for now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please remove this dont keep commented code in final version
| } | ||
|
|
||
| similarEventsRecyclerAdapter.setListener(recyclerViewClickListener) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line feed
| super.onCleared() | ||
| compositeDisposable.clear() | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
|
good work btw 👍 |
| val error = MutableLiveData<String>() | ||
|
|
||
| fun loadSimilarEvents(id: Long) { | ||
| if(id.toString() == "-1"){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a conversion to string ? You can compare that directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not working if I use id.equals(-1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why dont you do id == -1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id is of type long actually, so an error is cropping up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use id == -1
|
@iamareebjamal Could you please review this as I want to work on #207 after this |
| val favorite: Boolean = false, | ||
| @ColumnInfo(index = true) | ||
| @Relationship("event-topic") | ||
| var eventTopic: EventTopicId? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not load the entire event topic in one go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way you can even show the event topic's name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I will do that 👍
| rootView.endsOn.text = EventUtils.getFormattedDate(endsAt) | ||
|
|
||
| //Set event topic id | ||
| if(event.eventTopic != null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space around symbols
|
|
||
| //Set event topic id | ||
| if(event.eventTopic != null){ | ||
| eventTopicId = (event.eventTopic)?.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for parenthesis
| bundle.putLong(EVENT_ID, eventId) | ||
| eventTopicId?.let { bundle.putLong(EVENT_TOPIC_ID, it) } | ||
| similarEventsFragment.arguments = bundle | ||
| val transaction = childFragmentManager.beginTransaction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of storing transaction in a variable
| class EventTopicIdConverter { | ||
|
|
||
| @TypeConverter | ||
| fun fromEventTopicId(eventTopicId: EventTopicId?): Long?{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before {
| import org.fossasia.openevent.general.event.Event | ||
| import org.fossasia.openevent.general.event.EventDao | ||
|
|
||
| class EventTopicService(private val eventApi: EventTopicApi, private val eventTopicsDao: EventTopicsDao, private val eventDao: EventDao) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Property per line
| eventApi.getEventsUnderTopicId(id) | ||
| .toFlowable() | ||
| .map { | ||
| eventTopicsDao.insertSimilarEvents(it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different from event service's method?
| } | ||
| } | ||
|
|
||
| fun setFavorite(eventId: Long, favourite: Boolean): Completable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create unnecessary duplicate methods?
| fun deleteAllEvents() | ||
|
|
||
| @Query("SELECT * from Event WHERE eventTopic = :topicId") | ||
| fun getAllSimilarEvents(topicId: Long): Flowable<List<Event>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this in EventDao, you are selecting from the same table, so should remain in the same DAO
By this logic, we should have FavoriteDao as well
|
PR Updated 👍 |
| interface EventTopicApi { | ||
|
|
||
| @GET("event-topics/{id}/events") | ||
| @GET("event-topics/{id}/events?include=event-topic&fields[event-topic]=id&page[size]=0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to restrict the event topic field now
| @Query("DELETE FROM Event") | ||
| fun deleteAllEvents() | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't we require this in future to show users a list of event topics ?
| @Id(LongIdHandler::class) | ||
| val id: Long? = null, | ||
| val name: String? = null, | ||
| val slug: String? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a foreign key to event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually EventTopic is not being inserted into the database, so I thought that foriegn key is not needed. Is it wrong ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! Got it wrong 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to insert it into database as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PR 👍
| @PrimaryKey | ||
| val id: Long?, | ||
| val name: String?, | ||
| val slug: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no eventId to make foreign key of
|
@iamareebjamal Did all the changes requested 👍 |
| @Query("DELETE FROM Event") | ||
| fun deleteAllEvents() | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of this file
|
Removed EventTopicsDao for while 👍 |
|
|
||
| @Type("event-topic") | ||
| @JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class) | ||
| data class EventTopic( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had removed EventTopic as it was not needed that time. I added it again now 👍
| @@ -0,0 +1,25 @@ | |||
| package org.fossasia.openevent.general.similarEvents | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package name doesn't have camel case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to similar_events
| object EventUtils { | ||
|
|
||
| val SIMILAR_EVENTS: String = "similarEvents" | ||
| val EVENTS: String = "events" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are needed in EventsFragment and SimilarEventsFragment respectively. I have used the same adapter and ViewHolder for both the recycler views.
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| eventsRecyclerAdapter.setEventLayout(EventUtils.EVENTS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamareebjamal Here is one case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use them locally then, no need for these in EventUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the changes 👍
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| similarEventsRecyclerAdapter.setEventLayout(EventUtils.SIMILAR_EVENTS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is another case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Underscore is also not allowed, move the package in event package and rename to topic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed package name 👍
|
|
||
| class EventDetailsFragment : Fragment() { | ||
| val EVENT_ID = "EVENT_ID" | ||
| val EVENT_TOPIC_ID = "EVENT_TOPIC_ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private const val and above as well
| private var clickListener: RecyclerViewClickListener? = null | ||
| private var favoriteFabListener: FavoriteFabListener? = null | ||
| private var eventLayout: String? = null | ||
| val SIMILAR_EVENTS: String = "similarEvents" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private const val
| private val similarEventsViewModel by viewModel<SimilarEventsViewModel>() | ||
| private lateinit var rootView: View | ||
| private var EVENT_TOPIC_ID: String = "EVENT_TOPIC_ID" | ||
| val SIMILAR_EVENTS: String = "similarEvents" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use once
iamareebjamal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up PR to save the loaded event topic in DB
|
@dreadpool2 Squash your commits |
|
@iamareebjamal Thanks! I will do that 👍 |
|
@iamareebjamal Rebased my commits 👍 |
Fixes #123
