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: View social links in event details #105

Merged
merged 19 commits into from
Jun 14, 2018
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation "com.android.support:customtabs:27.1.1"
implementation 'com.android.support:exifinterface:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.koin:koin-android:$koin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "d72b474ff1822b41be54debe93211e73",
"identityHash": "4adfbfcd9397a9c7a151ff89ad65972b",
"entities": [
{
"tableName": "Event",
Expand Down Expand Up @@ -439,11 +439,70 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "SocialLink",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `link` TEXT NOT NULL, `name` 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": true
},
{
"fieldPath": "link",
"columnName": "link",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "event",
"columnName": "event",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_SocialLink_event",
"unique": false,
"columnNames": [
"event"
],
"createSql": "CREATE INDEX `index_SocialLink_event` ON `${TABLE_NAME}` (`event`)"
}
],
"foreignKeys": [
{
"table": "Event",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"event"
],
"referencedColumns": [
"id"
]
}
]
}
],
"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, \"d72b474ff1822b41be54debe93211e73\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"4adfbfcd9397a9c7a151ff89ad65972b\")"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package org.fossasia.openevent.general

import android.arch.persistence.room.Database
import android.arch.persistence.room.RoomDatabase
import android.arch.persistence.room.TypeConverters
import org.fossasia.openevent.general.auth.User
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.social.SocialLink
import org.fossasia.openevent.general.social.SocialLinksDao

@Database(entities = [Event::class, User::class], version = 1)
@Database(entities = [Event::class, User::class, SocialLink::class], version = 1)
@TypeConverters(EventIdConverter::class)
abstract class OpenEventDatabase : RoomDatabase() {

abstract fun eventDao(): EventDao

abstract fun userDao(): UserDao

abstract fun socialLinksDao(): SocialLinksDao
}
14 changes: 13 additions & 1 deletion app/src/main/java/org/fossasia/openevent/general/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.fossasia.openevent.general.auth.*
import org.fossasia.openevent.general.data.Preference
import org.fossasia.openevent.general.event.*
import org.fossasia.openevent.general.search.SearchViewModel
import org.fossasia.openevent.general.social.*
import org.fossasia.openevent.general.ticket.*
import org.koin.android.architecture.ext.viewModel
import org.koin.android.ext.koin.androidApplication
Expand Down Expand Up @@ -40,12 +41,17 @@ val apiModule = applicationContext {
val retrofit: Retrofit = get()
retrofit.create(TicketApi::class.java)
}
bean {
val retrofit: Retrofit = get()
retrofit.create(SocialLinkApi::class.java)
}

factory { AuthHolder(get()) }
factory { AuthService(get(), get(), get()) }

factory { EventService(get(), get()) }
factory { TicketService(get()) }
factory { SocialLinksService(get(), get()) }
}

val viewModelModule = applicationContext {
Expand All @@ -56,6 +62,7 @@ val viewModelModule = applicationContext {
viewModel { EventDetailsViewModel(get()) }
viewModel { SearchViewModel(get()) }
viewModel { TicketsViewModel(get()) }
viewModel { SocialLinksViewModel(get()) }
}

val networkModule = applicationContext {
Expand Down Expand Up @@ -89,7 +96,7 @@ val networkModule = applicationContext {
Retrofit.Builder()
.client(get())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JSONAPIConverterFactory(objectMapper, Event::class.java, User::class.java, SignUp::class.java, Ticket::class.java))
.addConverterFactory(JSONAPIConverterFactory(objectMapper, Event::class.java, User::class.java, SignUp::class.java, Ticket::class.java, SocialLink::class.java, EventId::class.java))
Copy link
Member

Choose a reason for hiding this comment

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

@iamareebjamal why is eventid class here would it be needed?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.baseUrl(baseUrl)
.build()
Expand All @@ -115,4 +122,9 @@ val databaseModule = applicationContext {
val database: OpenEventDatabase = get()
database.userDao()
}

factory {
val database: OpenEventDatabase = get()
database.socialLinksDao()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.content_event.view.*
import org.fossasia.openevent.general.MainActivity
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.social.SocialLinksFragment
import org.fossasia.openevent.general.ticket.TicketsFragment
import org.fossasia.openevent.general.utils.nullToEmpty
import org.koin.android.architecture.ext.viewModel
Expand Down Expand Up @@ -46,6 +47,7 @@ class EventDetailsFragment : Fragment() {
eventShare = it
}
loadTicketFragment()
loadSocialLinksFragment()
Timber.d("Fetched events of id %d", eventId)
})

Expand Down Expand Up @@ -167,6 +169,16 @@ class EventDetailsFragment : Fragment() {
transaction.add(R.id.frameContainer, ticketFragment).commit()
}

private fun loadSocialLinksFragment(){
//Initialise SocialLinks Fragment
val socialLinksFragemnt = SocialLinksFragment()
val bundle = Bundle()
bundle.putLong("EVENT_ID", eventId)
socialLinksFragemnt.arguments = bundle
val transaction = childFragmentManager.beginTransaction()
transaction.add(R.id.frameContainerSocial, socialLinksFragemnt).commit()
}

private fun startMap(event: Event) {
// start map intent
val mapUrl = eventViewModel.loadMapUrl(event)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/fossasia/openevent/general/event/EventId.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.fossasia.openevent.general.event

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

@Type("event")
data class EventId(
@Id(LongIdHandler::class)
val id: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.fossasia.openevent.general.event

import android.arch.persistence.room.TypeConverter

class EventIdConverter {

@TypeConverter
fun fromEventId(eventId: EventId): Long{
return eventId.id
}

@TypeConverter
fun toEventId(id: Long): EventId{
return EventId(id)
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package org.fossasia.openevent.general.social

import android.arch.persistence.room.*
import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Entity
import android.arch.persistence.room.ForeignKey
import android.arch.persistence.room.ForeignKey.CASCADE
import android.arch.persistence.room.PrimaryKey
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import com.fasterxml.jackson.databind.annotation.JsonNaming
import com.github.jasminb.jsonapi.IntegerIdHandler
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("social-link")
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
@Entity(foreignKeys = [(ForeignKey(entity = Event::class, parentColumns = ["id"], childColumns = ["event"], onDelete = CASCADE))])
data class SocialLink(
@Id(IntegerIdHandler::class)
@PrimaryKey
val id: Int,
val link: String,
val name: String,
@ColumnInfo(index = true)
@Relationship("event")
val event: Event
var event: EventId? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import retrofit2.http.Path

interface SocialLinkApi {

@GET("events/{id}/social-links")
@GET("events/{id}/social-links?include=event&fields[event]=id&page[size]=0")
fun getSocialLinks(@Path("id") id: Long): Flowable<List<SocialLink>>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.fossasia.openevent.general.social

import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy
import android.arch.persistence.room.Query
import io.reactivex.Flowable

@Dao
interface SocialLinksDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertSocialLinks(socialLinks: List<SocialLink>)

@Query("DELETE FROM SocialLink")
fun deleteAll()

@Query("SELECT * from SocialLink WHERE event = :eventId")
fun getAllSocialLinks(eventId: Long): Flowable<List<SocialLink>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.fossasia.openevent.general.social

import android.arch.lifecycle.Observer
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import kotlinx.android.synthetic.main.fragment_social_links.view.*
import org.fossasia.openevent.general.R
import org.koin.android.architecture.ext.viewModel
import timber.log.Timber

class SocialLinksFragment : Fragment() {
private val socialLinksRecyclerAdapter: SocialLinksRecyclerAdapter = SocialLinksRecyclerAdapter()
private val socialLinksViewModel by viewModel<SocialLinksViewModel>()
private lateinit var rootView: View
private var id: Long = -1
private val EVENT_ID: String = "EVENT_ID"
private lateinit var linearLayoutManager: LinearLayoutManager

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val bundle = this.arguments
if (bundle != null) {
id = bundle.getLong(EVENT_ID, -1)
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
rootView = inflater.inflate(R.layout.fragment_social_links, container, false)

rootView.progressBarSocial.isIndeterminate = true

linearLayoutManager = LinearLayoutManager(context)
linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
rootView.socialLinksRecycler.layoutManager = linearLayoutManager

rootView.socialLinksRecycler.adapter = socialLinksRecyclerAdapter
rootView.socialLinksRecycler.isNestedScrollingEnabled = false

socialLinksViewModel.socialLinks.observe(this, Observer {
it?.let {
socialLinksRecyclerAdapter.addAll(it)
}
socialLinksRecyclerAdapter.notifyDataSetChanged()
Timber.d("Fetched social-links of size %s", socialLinksRecyclerAdapter.itemCount)
})

socialLinksViewModel.error.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
})

socialLinksViewModel.progress.observe(this, Observer {
it?.let { showProgressBar(it) }
})

socialLinksViewModel.loadSocialLinks(id)

return rootView
}

private fun showProgressBar(show: Boolean) {
rootView.progressBarSocial.isIndeterminate = show
rootView.progressBarSocial.visibility = if (show) View.VISIBLE else View.GONE
}
}
Loading