#74 getFeedentries now returns a map with date as key and as value the entries for that day
This commit is contained in:
		
							parent
							
								
									3f6d416f39
								
							
						
					
					
						commit
						f3a8c93a3e
					
				
					 2 changed files with 8 additions and 2 deletions
				
			
		|  | @ -5,6 +5,6 @@ import kotlinx.coroutines.flow.Flow | |||
| 
 | ||||
| interface FeedDAO { | ||||
| 
 | ||||
|     fun getFeedEntries(): Flow<List<FeedEntry>> | ||||
|     fun getFeedEntries(): Flow<Map<String, List<FeedEntry>>> | ||||
| 
 | ||||
| } | ||||
|  | @ -1,5 +1,6 @@ | |||
| package be.ugent.sel.studeez.domain.implementation | ||||
| 
 | ||||
| import android.icu.text.DateFormat | ||||
| import be.ugent.sel.studeez.data.local.models.FeedEntry | ||||
| import be.ugent.sel.studeez.data.local.models.SessionReport | ||||
| import be.ugent.sel.studeez.data.local.models.task.Subject | ||||
|  | @ -17,16 +18,21 @@ class FirebaseFeedDAO @Inject constructor( | |||
|     private val subjectDAO: FireBaseSubjectDAO | ||||
| ) : FeedDAO { | ||||
| 
 | ||||
|     override fun getFeedEntries(): Flow<List<FeedEntry>> { | ||||
|     override fun getFeedEntries(): Flow<Map<String, List<FeedEntry>>> { | ||||
|         return sessionDAO.getSessions().map {sessionReports -> | ||||
|             sessionReports | ||||
|                 .map { sessionReport ->  sessionToFeedEntry(sessionReport) } | ||||
|                 .groupBy { it.taskId } | ||||
|                 .map { fuseFeedEntries(it.component2()) } | ||||
|                 .sortedByDescending { it.endTime } | ||||
|                 .groupBy { getFormattedTime(it) } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun getFormattedTime(entry: FeedEntry): String { | ||||
|         return DateFormat.getDateInstance().format(entry.endTime.toDate()) | ||||
|     } | ||||
| 
 | ||||
|     private fun fuseFeedEntries(entries: List<FeedEntry>): FeedEntry = | ||||
|         entries.fold(entries[0]) { accEntry, newEntry -> | ||||
|             accEntry.copy( | ||||
|  |  | |||
		Reference in a new issue
	
	 lbarraga
						lbarraga