-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d3a586
commit 4d84231
Showing
17 changed files
with
244 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/fossasia/openevent/general/event/subtopic/EventSubTopic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/fossasia/openevent/general/event/subtopic/EventSubTopicDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/fossasia/openevent/general/event/subtopic/EventSubTopicIdConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 6 additions & 9 deletions
15
app/src/main/java/org/fossasia/openevent/general/event/topic/EventTopicIdConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.