mirror of
https://github.com/melihaksoy/Android-Kotlin-Modulerized-CleanArchitecture.git
synced 2026-03-24 10:21:44 +01:00
WIP: feature/abstractions (#45)
* Abstraction layer backup * Removed DataEntity, was unnecessary for now * Separated network, persistence, entities and interaction, closes #29 * Renamed binding * Removed build files, example tests Removed build files, example tests * Fixed build files were not being ignored all around app * Updated CI ymls * Small changes * Fixed legacy repository package names * Fixed CQ findings * Updated Fastlane * Packaging changes and version upgrades * Removed core from interactors * Version bumps * Added new module graph
This commit is contained in:
31
data/persistence/build.gradle
Normal file
31
data/persistence/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
apply from: "$rootProject.projectDir/scripts/module.gradle"
|
||||
apply from: "$rootProject.projectDir/scripts/default_dependencies.gradle"
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = ["room.schemaLocation": "$rootProject.projectDir/reports/room".toString()]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation project(':data:definitions')
|
||||
|
||||
implementation libraries.moshiKotlin
|
||||
implementation libraries.coroutines
|
||||
implementation libraries.room
|
||||
|
||||
kapt annotationProcessors.roomCompiler
|
||||
|
||||
testImplementation testLibraries.coroutinesCore
|
||||
testImplementation testLibraries.coroutinesTest
|
||||
}
|
||||
0
data/persistence/consumer-rules.pro
Normal file
0
data/persistence/consumer-rules.pro
Normal file
21
data/persistence/proguard-rules.pro
vendored
Normal file
21
data/persistence/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
3
data/persistence/src/main/AndroidManifest.xml
Normal file
3
data/persistence/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.melih.persistence" />
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.melih.persistence
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.melih.definitions.entities.LaunchEntity
|
||||
import com.melih.persistence.converters.LocationConverter
|
||||
import com.melih.persistence.converters.MissionConverter
|
||||
import com.melih.persistence.converters.RocketConverter
|
||||
import com.melih.persistence.dao.LaunchesDao
|
||||
|
||||
const val DB_NAME = "LaunchesDB"
|
||||
|
||||
/**
|
||||
* DB that manages launches
|
||||
*/
|
||||
@Database(
|
||||
entities = [LaunchEntity::class],
|
||||
exportSchema = true,
|
||||
version = 1
|
||||
)
|
||||
@TypeConverters(
|
||||
LocationConverter::class,
|
||||
RocketConverter::class,
|
||||
MissionConverter::class
|
||||
)
|
||||
abstract class LaunchesDatabase : RoomDatabase() {
|
||||
|
||||
//region Companion
|
||||
|
||||
companion object {
|
||||
|
||||
private lateinit var instance: LaunchesDatabase
|
||||
|
||||
fun getInstance(ctx: Context): LaunchesDatabase {
|
||||
if (!::instance.isInitialized) {
|
||||
instance = Room.databaseBuilder(ctx, LaunchesDatabase::class.java, DB_NAME)
|
||||
.build()
|
||||
}
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Abstractions
|
||||
|
||||
abstract val launchesDao: LaunchesDao
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.melih.persistence.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
|
||||
/**
|
||||
* Base converter for reduced boilerplate code
|
||||
*/
|
||||
abstract class BaseConverter<T> {
|
||||
|
||||
//region Abstractions
|
||||
|
||||
abstract fun getAdapter(moshi: Moshi): JsonAdapter<T>
|
||||
//endregion
|
||||
|
||||
//region Properties
|
||||
|
||||
private val moshi = Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
//endregion
|
||||
|
||||
//region Functions
|
||||
|
||||
@TypeConverter
|
||||
fun convertFrom(item: T) =
|
||||
getAdapter(moshi).toJson(item)
|
||||
|
||||
@TypeConverter
|
||||
fun convertTo(string: String) =
|
||||
getAdapter(moshi).fromJson(string)
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.melih.persistence.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
|
||||
/**
|
||||
* Base converter for reduced boilerplate code
|
||||
*/
|
||||
abstract class BaseListConverter<T> {
|
||||
|
||||
//region Abstractions
|
||||
|
||||
abstract fun getAdapter(moshi: Moshi): JsonAdapter<List<T>>
|
||||
//endregion
|
||||
|
||||
//region Properties
|
||||
|
||||
private val moshi = Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
//endregion
|
||||
|
||||
//region Functions
|
||||
|
||||
@TypeConverter
|
||||
fun convertFrom(items: List<T>) =
|
||||
getAdapter(moshi).toJson(items)
|
||||
|
||||
@TypeConverter
|
||||
fun convertTo(string: String): List<T>? =
|
||||
getAdapter(moshi).fromJson(string)
|
||||
//endregion
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.melih.persistence.converters
|
||||
|
||||
import com.melih.definitions.entities.LocationEntity
|
||||
import com.melih.definitions.entities.LocationEntityJsonAdapter
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
/**
|
||||
* Converts [location][LocationEntity]
|
||||
*/
|
||||
class LocationConverter : BaseConverter<LocationEntity>() {
|
||||
|
||||
override fun getAdapter(moshi: Moshi): JsonAdapter<LocationEntity> =
|
||||
LocationEntityJsonAdapter(moshi)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.melih.persistence.converters
|
||||
|
||||
import com.melih.definitions.entities.MissionEntity
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
|
||||
/**
|
||||
* Converts [mission][MissionEntity]
|
||||
*/
|
||||
class MissionConverter : BaseListConverter<MissionEntity>() {
|
||||
|
||||
override fun getAdapter(moshi: Moshi): JsonAdapter<List<MissionEntity>> =
|
||||
moshi.adapter(
|
||||
Types.newParameterizedType(
|
||||
List::class.java,
|
||||
MissionEntity::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.melih.persistence.converters
|
||||
|
||||
import com.melih.definitions.entities.RocketEntity
|
||||
import com.melih.definitions.entities.RocketEntityJsonAdapter
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
/**
|
||||
* Converts [rocket][RocketEntity]
|
||||
*/
|
||||
class RocketConverter : BaseConverter<RocketEntity>() {
|
||||
|
||||
override fun getAdapter(moshi: Moshi): JsonAdapter<RocketEntity> =
|
||||
RocketEntityJsonAdapter(moshi)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.melih.persistence.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.melih.definitions.entities.LaunchEntity
|
||||
|
||||
/**
|
||||
* DAO for list of [launches][LaunchEntity]
|
||||
*/
|
||||
@Dao
|
||||
abstract class LaunchesDao {
|
||||
|
||||
//region Queries
|
||||
|
||||
@Query("SELECT * FROM Launches ORDER BY launchStartTime DESC LIMIT :count OFFSET :page*:count")
|
||||
abstract suspend fun getLaunches(count: Int, page: Int): List<LaunchEntity>
|
||||
|
||||
@Query("SELECT * FROM Launches WHERE id=:id LIMIT 1")
|
||||
abstract suspend fun getLaunchById(id: Long): LaunchEntity?
|
||||
|
||||
@Query("DELETE FROM Launches")
|
||||
abstract suspend fun nukeLaunches()
|
||||
//endregion
|
||||
|
||||
//region Insertion
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun saveLaunches(launches: List<LaunchEntity>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun saveLaunch(launch: LaunchEntity)
|
||||
//endregion
|
||||
}
|
||||
Reference in New Issue
Block a user