mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-21 18:55:12 +00:00
feature/home-screen (
Future functionality) create home-screen data domain and init presentation and ui
This commit is contained in:
parent
3e91ec6a74
commit
3fb29c57b5
28 changed files with 468 additions and 1 deletions
1
feature-home/.gitignore
vendored
Normal file
1
feature-home/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
67
feature-home/build.gradle
Normal file
67
feature-home/build.gradle
Normal file
|
@ -0,0 +1,67 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'kotlin-android'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.2.5'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
||||
implementation 'com.google.android.material:material:1.3.0-alpha03'
|
||||
|
||||
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
|
||||
implementation"com.squareup.moshi:moshi-kotlin:1.11.0"
|
||||
implementation "com.squareup.moshi:moshi-kotlin-codegen:1.11.0"
|
||||
implementation "com.squareup.moshi:moshi-adapters:1.11.0"
|
||||
|
||||
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
|
||||
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
|
||||
|
||||
implementation "org.koin:koin-android:2.2.1"
|
||||
implementation "org.koin:koin-android-viewmodel:2.2.1"
|
||||
implementation "org.koin:koin-android-ext:2.2.1"
|
||||
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.vanced.manager.feature.home
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.vanced.manager.feature.home.test", appContext.packageName)
|
||||
}
|
||||
}
|
1
feature-home/src/main/AndroidManifest.xml
Normal file
1
feature-home/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1 @@
|
|||
<manifest package="com.vanced.manager.feature.home" />
|
|
@ -0,0 +1,14 @@
|
|||
package com.vanced.manager.feature.home.data.api
|
||||
|
||||
import com.vanced.manager.feature.home.data.dto.VancedAppsDto
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface GetAppInformationApi {
|
||||
|
||||
companion object {
|
||||
const val URL = "/api/v1/latest.json"
|
||||
}
|
||||
|
||||
@GET(URL)
|
||||
suspend fun getAppInformation(): VancedAppsDto
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.vanced.manager.feature.home.data.datasource
|
||||
|
||||
import com.vanced.manager.feature.home.data.api.GetAppInformationApi
|
||||
import com.vanced.manager.feature.home.data.dto.toEntity
|
||||
import com.vanced.manager.feature.home.domain.entity.VancedApps
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
interface AppInformationDataSource {
|
||||
|
||||
suspend fun getAppInformation(): VancedApps
|
||||
}
|
||||
|
||||
class AppInformationDataSourceImpl(
|
||||
private val api: GetAppInformationApi
|
||||
) : AppInformationDataSource {
|
||||
|
||||
override suspend fun getAppInformation(): VancedApps =
|
||||
withContext(Dispatchers.IO) {
|
||||
api.getAppInformation().toEntity()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.vanced.manager.feature.home.data.dto
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.vanced.manager.feature.home.domain.entity.MicroG
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class MicroGDto(
|
||||
@Json(name = "version") val version: String,
|
||||
@Json(name = "versionCode") val versionCode: Long,
|
||||
@Json(name = "url") val baseUrl: String,
|
||||
@Json(name = "changelog") val changeLog: String
|
||||
)
|
||||
|
||||
fun MicroGDto.toEntity() =
|
||||
MicroG(version, versionCode, baseUrl, changeLog)
|
||||
|
||||
fun MicroG.toDto() =
|
||||
MicroGDto(version, versionCode, baseUrl, changeLog)
|
|
@ -0,0 +1,30 @@
|
|||
package com.vanced.manager.feature.home.data.dto
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.vanced.manager.feature.home.domain.entity.VancedApps
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class VancedAppsDto(
|
||||
@Json(name = "manager") val vancedManager: VancedManagerDto,
|
||||
@Json(name = "vanced") val youTubeVanced: YouTubeVancedDto,
|
||||
@Json(name = "music") val youTubeMusicVanced: YouTubeMusicVancedDto,
|
||||
@Json(name = "microg") val microG: MicroGDto
|
||||
)
|
||||
|
||||
|
||||
fun VancedAppsDto.toEntity() =
|
||||
VancedApps(
|
||||
vancedManager = vancedManager.toEntity(),
|
||||
youTubeVanced = youTubeVanced.toEntity(),
|
||||
youTubeMusicVanced = youTubeMusicVanced.toEntity(),
|
||||
microG = microG.toEntity()
|
||||
)
|
||||
|
||||
fun VancedApps.toDto() =
|
||||
VancedAppsDto(
|
||||
vancedManager = vancedManager.toDto(),
|
||||
youTubeVanced = youTubeVanced.toDto(),
|
||||
youTubeMusicVanced = youTubeMusicVanced.toDto(),
|
||||
microG = microG.toDto()
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
package com.vanced.manager.feature.home.data.dto
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.vanced.manager.feature.home.domain.entity.VancedManager
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class VancedManagerDto(
|
||||
@Json(name = "version") val version: String,
|
||||
@Json(name = "versionCode") val versionCode: Long,
|
||||
@Json(name = "url") val baseUrl: String,
|
||||
@Json(name = "changelog") val changeLog: String
|
||||
)
|
||||
|
||||
fun VancedManagerDto.toEntity() =
|
||||
VancedManager(version, versionCode, baseUrl, changeLog)
|
||||
|
||||
fun VancedManager.toDto() =
|
||||
VancedManagerDto(version, versionCode, baseUrl, changeLog)
|
|
@ -0,0 +1,19 @@
|
|||
package com.vanced.manager.feature.home.data.dto
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.vanced.manager.feature.home.domain.entity.YouTubeMusicVanced
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class YouTubeMusicVancedDto(
|
||||
@Json(name = "version") val version: String,
|
||||
@Json(name = "versionCode") val versionCode: Long,
|
||||
@Json(name = "url") val baseUrl: String,
|
||||
@Json(name = "changelog") val changeLog: String
|
||||
)
|
||||
|
||||
fun YouTubeMusicVancedDto.toEntity() =
|
||||
YouTubeMusicVanced(version, versionCode, baseUrl, changeLog)
|
||||
|
||||
fun YouTubeMusicVanced.toDto() =
|
||||
YouTubeMusicVancedDto(version, versionCode, baseUrl, changeLog)
|
|
@ -0,0 +1,22 @@
|
|||
package com.vanced.manager.feature.home.data.dto
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.vanced.manager.feature.home.domain.entity.YouTubeVanced
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class YouTubeVancedDto(
|
||||
@Json(name = "version") val version: String,
|
||||
@Json(name = "versionCode") val versionCode: Long,
|
||||
@Json(name = "url") val baseUrl: String,
|
||||
@Json(name = "changelog") val changeLog: String,
|
||||
@Json(name = "themes") val themes: List<String>,
|
||||
@Json(name = "langs") val langs: List<String>
|
||||
)
|
||||
|
||||
|
||||
fun YouTubeVancedDto.toEntity() =
|
||||
YouTubeVanced(version, versionCode, baseUrl, changeLog, themes, langs)
|
||||
|
||||
fun YouTubeVanced.toDto() =
|
||||
YouTubeVancedDto(version, versionCode, baseUrl, changeLog, themes, langs)
|
|
@ -0,0 +1,25 @@
|
|||
package com.vanced.manager.feature.home.data.repository
|
||||
|
||||
import com.vanced.manager.feature.home.data.datasource.AppInformationDataSource
|
||||
import com.vanced.manager.feature.home.domain.entity.*
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class AppInformationRepositoryImpl(
|
||||
private val dataSource: AppInformationDataSource
|
||||
) : AppInformationRepository {
|
||||
|
||||
override suspend fun getAppInformation(): VancedApps =
|
||||
dataSource.getAppInformation()
|
||||
|
||||
override suspend fun getMicroGInformation(): MicroG =
|
||||
dataSource.getAppInformation().microG
|
||||
|
||||
override suspend fun getVancedManagerInformation(): VancedManager =
|
||||
dataSource.getAppInformation().vancedManager
|
||||
|
||||
override suspend fun getYouTubeMusicVancedInformation(): YouTubeMusicVanced =
|
||||
dataSource.getAppInformation().youTubeMusicVanced
|
||||
|
||||
override suspend fun getYouTubeVancedInformation(): YouTubeVanced =
|
||||
dataSource.getAppInformation().youTubeVanced
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.vanced.manager.feature.home.di
|
||||
|
||||
import com.vanced.manager.feature.home.data.api.GetAppInformationApi
|
||||
import com.vanced.manager.feature.home.data.datasource.AppInformationDataSource
|
||||
import com.vanced.manager.feature.home.data.datasource.AppInformationDataSourceImpl
|
||||
import com.vanced.manager.feature.home.data.repository.AppInformationRepositoryImpl
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
import com.vanced.manager.feature.home.domain.usecase.*
|
||||
import com.vanced.manager.feature.home.presentation.HomeViewModel
|
||||
import org.koin.android.viewmodel.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
internal val retrofitModule = module {
|
||||
single<GetAppInformationApi?> { null }
|
||||
}
|
||||
|
||||
internal val dataSourceModule = module {
|
||||
single<AppInformationDataSource> { AppInformationDataSourceImpl(api = get()) }
|
||||
}
|
||||
|
||||
internal val repositoryModule = module {
|
||||
single<AppInformationRepository> { AppInformationRepositoryImpl(dataSource = get()) }
|
||||
}
|
||||
|
||||
internal val useCaseModule = module {
|
||||
single { GetAppInformationUseCase(repository = get()) }
|
||||
|
||||
single { GetMicroGInformationUseCase(repository = get()) }
|
||||
single { GetVancedManagerInformationUseCase(repository = get()) }
|
||||
single { GetYouTubeMusicVancedInformationUseCase(repository = get()) }
|
||||
single { GetYouTubeVancedInformationUseCase(repository = get()) }
|
||||
}
|
||||
|
||||
internal val viewModelModule = module {
|
||||
viewModel {
|
||||
HomeViewModel(
|
||||
getAppInformationUseCase = get(),
|
||||
getMicroGInformationUseCase = get(),
|
||||
getVancedManagerInformationUseCase = get(),
|
||||
getYouTubeVancedInformationUseCase = get(),
|
||||
getYouTubeMusicVancedInformationUseCase = get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val FeatureHomeModules = listOf(
|
||||
retrofitModule,
|
||||
dataSourceModule,
|
||||
repositoryModule,
|
||||
useCaseModule,
|
||||
viewModelModule
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
package com.vanced.manager.feature.home.domain.entity
|
||||
|
||||
data class MicroG(
|
||||
val version: String,
|
||||
val versionCode: Long,
|
||||
val baseUrl: String,
|
||||
val changeLog: String
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
package com.vanced.manager.feature.home.domain.entity
|
||||
|
||||
data class VancedApps(
|
||||
val vancedManager: VancedManager,
|
||||
val youTubeVanced: YouTubeVanced,
|
||||
val youTubeMusicVanced: YouTubeMusicVanced,
|
||||
val microG: MicroG
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
package com.vanced.manager.feature.home.domain.entity
|
||||
|
||||
data class VancedManager(
|
||||
val version: String,
|
||||
val versionCode: Long,
|
||||
val baseUrl: String,
|
||||
val changeLog: String
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
package com.vanced.manager.feature.home.domain.entity
|
||||
|
||||
data class YouTubeMusicVanced(
|
||||
val version: String,
|
||||
val versionCode: Long,
|
||||
val baseUrl: String,
|
||||
val changeLog: String
|
||||
)
|
|
@ -0,0 +1,10 @@
|
|||
package com.vanced.manager.feature.home.domain.entity
|
||||
|
||||
data class YouTubeVanced(
|
||||
val version: String,
|
||||
val versionCode: Long,
|
||||
val baseUrl: String,
|
||||
val changeLog: String,
|
||||
val themes: List<String>,
|
||||
val langs: List<String>
|
||||
)
|
|
@ -0,0 +1,16 @@
|
|||
package com.vanced.manager.feature.home.domain.repository
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.*
|
||||
|
||||
interface AppInformationRepository {
|
||||
|
||||
suspend fun getAppInformation(): VancedApps
|
||||
|
||||
suspend fun getMicroGInformation(): MicroG
|
||||
|
||||
suspend fun getVancedManagerInformation(): VancedManager
|
||||
|
||||
suspend fun getYouTubeMusicVancedInformation(): YouTubeMusicVanced
|
||||
|
||||
suspend fun getYouTubeVancedInformation(): YouTubeVanced
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.domain.usecase
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.VancedApps
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class GetAppInformationUseCase(
|
||||
private val repository: AppInformationRepository
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): VancedApps =
|
||||
repository.getAppInformation()
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.domain.usecase
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.MicroG
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class GetMicroGInformationUseCase(
|
||||
private val repository: AppInformationRepository
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): MicroG =
|
||||
repository.getMicroGInformation()
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.domain.usecase
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.VancedManager
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class GetVancedManagerInformationUseCase(
|
||||
private val repository: AppInformationRepository
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): VancedManager =
|
||||
repository.getVancedManagerInformation()
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.domain.usecase
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.YouTubeMusicVanced
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class GetYouTubeMusicVancedInformationUseCase(
|
||||
private val repository: AppInformationRepository
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): YouTubeMusicVanced =
|
||||
repository.getYouTubeMusicVancedInformation()
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.domain.usecase
|
||||
|
||||
import com.vanced.manager.feature.home.domain.entity.YouTubeVanced
|
||||
import com.vanced.manager.feature.home.domain.repository.AppInformationRepository
|
||||
|
||||
class GetYouTubeVancedInformationUseCase(
|
||||
private val repository: AppInformationRepository
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): YouTubeVanced =
|
||||
repository.getYouTubeVancedInformation()
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.vanced.manager.feature.home.presentation
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.vanced.manager.feature.home.domain.usecase.*
|
||||
|
||||
class HomeViewModel(
|
||||
private val getAppInformationUseCase: GetAppInformationUseCase,
|
||||
private val getMicroGInformationUseCase: GetMicroGInformationUseCase,
|
||||
private val getVancedManagerInformationUseCase: GetVancedManagerInformationUseCase,
|
||||
private val getYouTubeVancedInformationUseCase: GetYouTubeVancedInformationUseCase,
|
||||
private val getYouTubeMusicVancedInformationUseCase: GetYouTubeMusicVancedInformationUseCase
|
||||
) : ViewModel()
|
|
@ -0,0 +1,5 @@
|
|||
package com.vanced.manager.feature.home.ui
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
class HomeFragment : Fragment()
|
|
@ -0,0 +1,17 @@
|
|||
package com.vanced.manager.feature.home
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
rootProject.name='Vanced Manager'
|
||||
include ':app'
|
||||
|
||||
include ':core-ui'
|
||||
include ':core-ui'
|
||||
include ':feature-home'
|
Loading…
Reference in a new issue