From 57813ac0a7e18f4c54f216a3078b686a335064f3 Mon Sep 17 00:00:00 2001 From: Harun Wangereka Date: Thu, 16 Jan 2020 15:43:19 +0300 Subject: [PATCH] fix: Removed unused room packages and classes. This addresses #52 --- .../droidconke19/database/AppDatabase.kt | 43 ---------- .../database/converters/Converter.kt | 78 ------------------- .../droidconke19/database/dao/SessionsDao.kt | 33 -------- .../database/dao/StarredSessionDao.kt | 24 ------ .../database/entities/StarredSessionEntity.kt | 30 ------- .../com/android254/droidconke19/di/modules.kt | 9 +-- .../repository/ReserveSeatRepo.kt | 4 +- .../repository/SessionDataRepo.kt | 6 +- .../droidconke19/repository/SessionsRepo.kt | 3 +- .../repository/WifiDetailsRepo.kt | 4 +- 10 files changed, 8 insertions(+), 226 deletions(-) delete mode 100644 app/src/main/java/com/android254/droidconke19/database/AppDatabase.kt delete mode 100644 app/src/main/java/com/android254/droidconke19/database/converters/Converter.kt delete mode 100644 app/src/main/java/com/android254/droidconke19/database/dao/SessionsDao.kt delete mode 100644 app/src/main/java/com/android254/droidconke19/database/dao/StarredSessionDao.kt delete mode 100644 app/src/main/java/com/android254/droidconke19/database/entities/StarredSessionEntity.kt diff --git a/app/src/main/java/com/android254/droidconke19/database/AppDatabase.kt b/app/src/main/java/com/android254/droidconke19/database/AppDatabase.kt deleted file mode 100644 index 92f8990..0000000 --- a/app/src/main/java/com/android254/droidconke19/database/AppDatabase.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.android254.droidconke19.database - -import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import androidx.room.TypeConverters -import com.android254.droidconke19.database.converters.Converter -import com.android254.droidconke19.database.dao.SessionsDao -import com.android254.droidconke19.database.dao.StarredSessionDao -import com.android254.droidconke19.models.SessionsModel -import com.android254.droidconke19.models.StarredSessionModel - - -@Database(entities = [StarredSessionModel::class, SessionsModel::class], version = 10, exportSchema = false) -@TypeConverters(Converter::class) -abstract class AppDatabase : RoomDatabase() { - - //dao - abstract fun sessionsDao(): SessionsDao - - abstract fun starredSessionDao(): StarredSessionDao - - companion object { - //Singleton - @Volatile - private var INSTANCE: AppDatabase? = null - - fun getDatabase(context: Context): AppDatabase? { - when (INSTANCE) { - null -> INSTANCE = Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, "droidconKE_db") - .fallbackToDestructiveMigration() - .build() - } - return INSTANCE - } - - fun destroyInstance() { - INSTANCE = null - } - } - -} diff --git a/app/src/main/java/com/android254/droidconke19/database/converters/Converter.kt b/app/src/main/java/com/android254/droidconke19/database/converters/Converter.kt deleted file mode 100644 index 7a8cb5f..0000000 --- a/app/src/main/java/com/android254/droidconke19/database/converters/Converter.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.android254.droidconke19.database.converters - -import androidx.room.TypeConverter -import com.android254.droidconke19.models.Level -import com.android254.droidconke19.models.SpeakersModel -import com.android254.droidconke19.models.Stage -import com.android254.droidconke19.models.Type -import com.android254.droidconke19.utils.enumToInt -import com.android254.droidconke19.utils.toEnum -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.util.* -import kotlin.collections.ArrayList - -class Converter { - @TypeConverter - fun fromString(value: String): ArrayList? { - val listType = object : TypeToken>() { - - }.type - return Gson().fromJson>(value, listType) - } - - @TypeConverter - fun fromArrayList(list: ArrayList): String { - val gson = Gson() - return gson.toJson(list) - } - - @TypeConverter - fun listFromString(value: String): ArrayList? { - val listType = object : TypeToken>() { - - }.type - return Gson().fromJson>(value, listType) - } - - @TypeConverter - fun listFromArrayList(list: ArrayList): String { - val gson = Gson() - return gson.toJson(list) - } - - @TypeConverter - fun typeEnumToInt(type : Type) = type.enumToInt() - - @TypeConverter - fun intEnumToType(value : Int) = value.toEnum() - - @TypeConverter - fun levelEnumToInt(level : Level) = level.enumToInt() - - @TypeConverter - fun intEnumToLevel(value : Int) = value.toEnum() - - @TypeConverter - fun stageEnumToInt(stage : Stage) = stage.enumToInt() - - @TypeConverter - fun intEnumToStage(value : Int) = value.toEnum() - - @TypeConverter - fun speakerFromString(value: String): ArrayList? { - val listType = object : TypeToken>() { - - }.type - return Gson().fromJson>(value, listType) - } - - @TypeConverter - fun speakerFromArrayList(list: ArrayList): String { - val gson = Gson() - return gson.toJson(list) - } - - - -} diff --git a/app/src/main/java/com/android254/droidconke19/database/dao/SessionsDao.kt b/app/src/main/java/com/android254/droidconke19/database/dao/SessionsDao.kt deleted file mode 100644 index 9af06a1..0000000 --- a/app/src/main/java/com/android254/droidconke19/database/dao/SessionsDao.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.android254.droidconke19.database.dao - -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy.REPLACE -import androidx.room.Query -import com.android254.droidconke19.models.SessionsModel - -@Dao -interface SessionsDao { - - @Insert(onConflict = REPLACE) - suspend fun saveSession(sessionsModelList: List) - - @Query("SELECT * FROM sessionsList WHERE day_number =:dayNumber") - suspend fun getDayOneSessions(dayNumber: String): List - - @Query("SELECT * FROM sessionsList WHERE day_number =:dayNumber") - suspend fun getDayTwoSessions(dayNumber: String): List - - @Query("SELECT * FROM sessionsList WHERE day_number =:dayNumber AND id =:sessionId") - suspend fun getSessionDetails(dayNumber: String, sessionId: Int): SessionsModel - - @Query("UPDATE sessionsList SET starred = :isStarred WHERE id LIKE :sessionId AND day_number LIKE :dayNumber") - suspend fun starSession(sessionId: Int, isStarred: String, dayNumber: String) - - @Query("SELECT count(*) FROM sessionsList WHERE id=:sessionId AND day_number =:dayNumber") - suspend fun isSessionStarred(sessionId: Int, dayNumber: String): Int - - @Query("UPDATE sessionsList SET starred = :isStarred WHERE id LIKE :sessionId AND day_number LIKE :dayNumber") - suspend fun unStarSession(sessionId: Int, isStarred: String, dayNumber: String) - -} diff --git a/app/src/main/java/com/android254/droidconke19/database/dao/StarredSessionDao.kt b/app/src/main/java/com/android254/droidconke19/database/dao/StarredSessionDao.kt deleted file mode 100644 index 60a9851..0000000 --- a/app/src/main/java/com/android254/droidconke19/database/dao/StarredSessionDao.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.android254.droidconke19.database.dao - -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy.REPLACE -import androidx.room.Query -import com.android254.droidconke19.models.StarredSessionModel - -@Dao -interface StarredSessionDao { - - @Query("SELECT * FROM starredSessions") - suspend fun starredSessions(): List - - @Insert(onConflict = REPLACE) - fun starSession(starredSessionModel: StarredSessionModel) - - @Query("UPDATE starredSessions SET isStarred=:starred WHERE documentId =:documentId") - fun unStarSession(starred: Boolean, documentId: String) - - @Query("SELECT isStarred FROM starredSessions WHERE documentId LIKE :documentId ") - fun isSessionStarred(documentId: String): Boolean - -} diff --git a/app/src/main/java/com/android254/droidconke19/database/entities/StarredSessionEntity.kt b/app/src/main/java/com/android254/droidconke19/database/entities/StarredSessionEntity.kt deleted file mode 100644 index 6631a33..0000000 --- a/app/src/main/java/com/android254/droidconke19/database/entities/StarredSessionEntity.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.android254.droidconke19.database.entities - -import androidx.room.Entity -import androidx.room.PrimaryKey -import java.util.* - -@Entity(tableName = "starredSessions") -data class StarredSessionEntity ( - @PrimaryKey - var id: Int = 0, - var speaker_id: ArrayList? = null, - var room_id: Int = 0, - var main_tag: String? = null, - var room: String? = null, - var speakers: String? = null, - var starred: Boolean = false, - var time: String? = null, - var title: String? = null, - var topic: String? = null, - var url: String? = null, - var duration: String? = null, - var description: String? = null, - var session_color: String? = null, - var topic_id: Int = 0, - var type_id: Int = 0, - var type: String? = null, - var documentId: String? = null, - var timestamp: String? = null, - var day_number: String? = null -) diff --git a/app/src/main/java/com/android254/droidconke19/di/modules.kt b/app/src/main/java/com/android254/droidconke19/di/modules.kt index a7a530a..b64a14f 100644 --- a/app/src/main/java/com/android254/droidconke19/di/modules.kt +++ b/app/src/main/java/com/android254/droidconke19/di/modules.kt @@ -1,8 +1,6 @@ package com.android254.droidconke19.di import android.content.Context -import androidx.room.Room -import com.android254.droidconke19.database.AppDatabase import com.android254.droidconke19.firebase.FirebaseRemoteConfigFactory import com.android254.droidconke19.repository.* import com.android254.droidconke19.utils.SharedPref @@ -12,7 +10,6 @@ import com.google.firebase.database.FirebaseDatabase import com.google.firebase.firestore.ktx.firestore import com.google.firebase.ktx.Firebase import com.google.firebase.messaging.FirebaseMessaging -import com.google.firebase.remoteconfig.FirebaseRemoteConfig import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module @@ -44,8 +41,8 @@ val appModule = module { val dataModule = module { // Repos single { AboutDetailsRepoImpl(get()) } - single { SessionsRepoImpl(get(), get()) } - single { SessionDataRepoImpl(get(), get()) } + single { SessionsRepoImpl(get()) } + single { SessionDataRepoImpl(get()) } single { SpeakersRepoImpl(get()) } single { RoomRepoImpl(get()) } single { SessionFeedbackRepoImpl(get()) } @@ -57,6 +54,4 @@ val dataModule = module { single { ReserveSeatRepoImpl(get()) } single { WifiDetailsRepoImpl(get()) } - // Database - single { Room.databaseBuilder(get(), AppDatabase::class.java, "droidconKE_db").fallbackToDestructiveMigration().build() } } \ No newline at end of file diff --git a/app/src/main/java/com/android254/droidconke19/repository/ReserveSeatRepo.kt b/app/src/main/java/com/android254/droidconke19/repository/ReserveSeatRepo.kt index 4081e65..58999e3 100644 --- a/app/src/main/java/com/android254/droidconke19/repository/ReserveSeatRepo.kt +++ b/app/src/main/java/com/android254/droidconke19/repository/ReserveSeatRepo.kt @@ -1,11 +1,11 @@ package com.android254.droidconke19.repository +import com.android254.droidconke19.datastates.FirebaseResult +import com.android254.droidconke19.datastates.runCatching import com.android254.droidconke19.models.ReserveSeatModel import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.FirebaseFirestoreException import kotlinx.coroutines.tasks.await -import com.android254.droidconke19.datastates.FirebaseResult -import com.android254.droidconke19.datastates.runCatching interface ReserveSeatRepo { suspend fun reserveSeat(reserveSeatModel: ReserveSeatModel): FirebaseResult diff --git a/app/src/main/java/com/android254/droidconke19/repository/SessionDataRepo.kt b/app/src/main/java/com/android254/droidconke19/repository/SessionDataRepo.kt index ff0b99e..f74dfa8 100644 --- a/app/src/main/java/com/android254/droidconke19/repository/SessionDataRepo.kt +++ b/app/src/main/java/com/android254/droidconke19/repository/SessionDataRepo.kt @@ -1,7 +1,5 @@ package com.android254.droidconke19.repository -import com.android254.droidconke19.database.AppDatabase -import com.android254.droidconke19.database.dao.SessionsDao import com.android254.droidconke19.datastates.FirebaseResult import com.android254.droidconke19.datastates.runCatching import com.android254.droidconke19.models.SessionsModel @@ -21,9 +19,7 @@ interface SessionDataRepo { suspend fun clearStarredSessions(userId: String) } -class SessionDataRepoImpl(db: AppDatabase, private val firestore: FirebaseFirestore) : SessionDataRepo { - private val sessionsDao: SessionsDao = db.sessionsDao() - +class SessionDataRepoImpl(private val firestore: FirebaseFirestore) : SessionDataRepo { private val starredSessionCollection = "starred_sessions" override suspend fun getSessionData(dayNumber: String, sessionId: Int): FirebaseResult = diff --git a/app/src/main/java/com/android254/droidconke19/repository/SessionsRepo.kt b/app/src/main/java/com/android254/droidconke19/repository/SessionsRepo.kt index a6b4776..c1c27b7 100644 --- a/app/src/main/java/com/android254/droidconke19/repository/SessionsRepo.kt +++ b/app/src/main/java/com/android254/droidconke19/repository/SessionsRepo.kt @@ -1,6 +1,5 @@ package com.android254.droidconke19.repository -import com.android254.droidconke19.database.AppDatabase import com.android254.droidconke19.datastates.FirebaseResult import com.android254.droidconke19.datastates.runCatching import com.android254.droidconke19.models.SessionsModel @@ -14,7 +13,7 @@ interface SessionsRepo { suspend fun getSessions(sessionDay: String): FirebaseResult> } -class SessionsRepoImpl(db: AppDatabase, private val firestore: FirebaseFirestore) : SessionsRepo { +class SessionsRepoImpl(private val firestore: FirebaseFirestore) : SessionsRepo { override suspend fun getSessions(sessionDay: String): FirebaseResult> = runCatching { diff --git a/app/src/main/java/com/android254/droidconke19/repository/WifiDetailsRepo.kt b/app/src/main/java/com/android254/droidconke19/repository/WifiDetailsRepo.kt index afb4d5e..2c4271f 100644 --- a/app/src/main/java/com/android254/droidconke19/repository/WifiDetailsRepo.kt +++ b/app/src/main/java/com/android254/droidconke19/repository/WifiDetailsRepo.kt @@ -1,10 +1,10 @@ package com.android254.droidconke19.repository import com.android254.droidconke19.datastates.FirebaseResult -import com.android254.droidconke19.models.WifiDetailsModel -import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.android254.droidconke19.datastates.runCatching +import com.android254.droidconke19.models.WifiDetailsModel import com.android254.droidconke19.models.utils.WifiDetailsModelFactory +import com.google.firebase.remoteconfig.FirebaseRemoteConfig import kotlinx.coroutines.tasks.await interface WifiDetailsRepo {