Skip to content

Commit

Permalink
Fixed Fakerepos
Browse files Browse the repository at this point in the history
  • Loading branch information
khalid64927 committed Aug 20, 2023
1 parent b49e0bf commit d439a9d
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 93 deletions.
21 changes: 1 addition & 20 deletions GitHubRepos/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@ import com.dependencies.pln

plugins {
id("com.khalid.hamid.KhalidAndroidPlugin")
//id("com.google.devtools.ksp") version ("1.9.0-1.0.11")
}
pln("after plugin")

KPlugin {
pln("KPlugin Ext app...")
isLibraryModule = false
minSDK = 19
compileSDK = "33"
targetSDK = "33"
versionCode = 10
versionName = "1.1"
testRunner = "com.khalid.hamid.githubrepos.utilities.AppTestRunner"
lintBaseLineFilePath = "$rootDir/quality/lint-baseline.xml"
checkstylePath = "$rootDir/quality/checkstyle.xml"
}

allOpen.annotation("com.khalid.hamid.githubrepos.testing.OpenClass")
android {
pln("android block...")
namespace = "com.khalid.hamid.githubrepos"
defaultConfig {
applicationId = "com.khalid.hamid.githubrepos"
Expand Down Expand Up @@ -113,7 +97,4 @@ dependencies {
// Nav
implementation(Dependencies.NAV_RUNTIME_FRAGMENT_KTX)
debugImplementation(Dependencies.CHUCKER)
}

pln("script end")

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.khalid.hamid.githubrepos

import androidx.multidex.BuildConfig
import androidx.multidex.MultiDexApplication
import com.khalid.hamid.githubrepos.network.BaseRepository
import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.utilities.AppExecutors
import com.khalid.hamid.githubrepos.utilities.CrashReportingTree
import dagger.hilt.android.HiltAndroidApp
Expand All @@ -29,7 +29,7 @@ import javax.inject.Inject
class MercariApp : MultiDexApplication() {

@Inject
lateinit var baseRepository: BaseRepository
lateinit var baseDataSource: BaseDataSource

@Inject
lateinit var appExecutors: AppExecutors
Expand All @@ -40,6 +40,6 @@ class MercariApp : MultiDexApplication() {
} else {
Timber.plant(CrashReportingTree())
}
baseRepository.sync()
baseDataSource.sync()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package com.khalid.hamid.githubrepos.ui.timeline
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.khalid.hamid.githubrepos.core.BaseViewModel
import com.khalid.hamid.githubrepos.network.BaseRepository
import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductList
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ProductsTimelineViewModel @Inject constructor(
val baseRepository: BaseRepository
val baseDataSource: BaseDataSource
) : BaseViewModel() {

val productTimelineEventLiveData: LiveData<ProductsTimelineEvent>
Expand All @@ -37,7 +37,7 @@ class ProductsTimelineViewModel @Inject constructor(
launchAsyncAPI({
_productTimelineEventLiveData.value = FailedToFetchTimelineProducts(it.message)
}) {
val products = baseRepository.getProductForCategory(categoryId)
val products = baseDataSource.getProductForCategory(categoryId)
_productTimelineEventLiveData.value = ReceivedProductsEvent(products)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.khalid.hamid.githubrepos.ui.timeline
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.khalid.hamid.githubrepos.core.BaseViewModel
import com.khalid.hamid.githubrepos.network.BaseRepository
import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductCategoriesList
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductList
import com.khalid.hamid.githubrepos.utilities.Prefs
Expand All @@ -29,7 +29,7 @@ import javax.inject.Inject

@HiltViewModel
class TimelineViewModel @Inject constructor(
val baseRepository: BaseRepository,
val baseDataSource: BaseDataSource,
val perf: Prefs
) : BaseViewModel() {

Expand All @@ -45,7 +45,7 @@ class TimelineViewModel @Inject constructor(
launchAsyncAPI({
_mainTimelineEventLiveData.value = FailedToFetchProducts(it.message)
}) {
baseRepository.run {
baseDataSource.run {
Timber.d("launchAsyncAPI")
val categoriesResult = getProductCategories()
val categoryName = categoriesResult.firstOrNull()?.name ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class SafeClickListener(
}
}

@BindingAdapter("app:onSingleClick")
@BindingAdapter("onSingleClick")
fun View.setSafeOnClickListener(onSafeClick: (View) -> Unit) {
val safeClickListener = SafeClickListener {
onSafeClick(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun View.gone() {
visibility = View.GONE
}

@BindingAdapter("app:productImage")
@BindingAdapter("productImage")
fun PhotoView.loadSKUImage(imageURL: String?) {
Glide.with(context)
.load(imageURL)
Expand All @@ -48,17 +48,17 @@ fun PhotoView.loadSKUImage(imageURL: String?) {
.into(this)
}

@BindingAdapter("app:productStatus")
@BindingAdapter("productStatus")
fun ImageView.checkStatus(value: String) {
visibility = if (value == "sold_out") View.VISIBLE else View.GONE
}

@BindingAdapter("app:integerData")
@BindingAdapter("integerData")
fun TextView.setIntegerData(value: Int) {
text = value.toString()
}

@BindingAdapter("app:productPrice")
@BindingAdapter("productPrice")
fun TextView.setPrice(value: Int) {
val sb = StringBuilder()
sb.append("$ $value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ImageView
android:id="@+id/iv_outOfStock"
android:src="@drawable/badge_soldout"
app:productStatus="@{item.status}"
productStatus="@{item.status}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/sold_out" />
Expand Down Expand Up @@ -67,7 +67,7 @@
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/iv_like"
android:textSize="6pt"
app:integerData="@{item.numLikes}"
integerData="@{item.numLikes}"
app:layout_constraintBottom_toBottomOf="@+id/iv_like"
app:layout_constraintStart_toEndOf="@+id/iv_like"
app:layout_constraintTop_toTopOf="@+id/iv_like"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.khalid.hamid.githubrepos.di

import android.app.Application
import com.khalid.hamid.githubrepos.network.BaseRepository
import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.network.remote.FakeDataSource
import dagger.Module
import dagger.Provides
Expand All @@ -31,7 +31,7 @@ class RepositoryModule {

@Singleton
@Provides
fun provideRepository(context: Application): BaseRepository {
return BaseRepository(FakeDataSource(context))
fun provideRepository(context: Application): BaseDataSource {
return FakeDataSource(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,41 @@ import android.app.Application
import com.google.gson.Gson
import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.network.Result
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductCategoriesItem
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductsItem
import com.khalid.hamid.githubrepos.utilities.runSafe
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductCategoriesList
import com.khalid.hamid.githubrepos.ui.timeline.dto.ProductList
import com.khalid.hamid.githubrepos.utilities.extentions.runSafe
import javax.inject.Inject

class FakeDataSource @Inject constructor(val context: Application) : BaseDataSource {
val gson = Gson()

override var isSyncCompleted = false
override suspend fun fetchProductCategories(url: String): Result<ProductCategoriesList> {
return Result.Success(ProductCategoriesList())
}

override suspend fun fetchProductForCategory(url: String): Result<ProductList> {
return Result.Success(ProductList())
}

override suspend fun getProductCategories(): ProductCategoriesList {
return ProductCategoriesList()
}

override suspend fun getProductForCategory(categoryId: String): ProductList {
return ProductList()
}

override suspend fun getAllProducts(): ProductList {
return ProductList()
}

override fun sync() {
// no-op
}

override var isSyncing = false

private inline fun <reified T> parse(jsonPath: String): T? {
var response: T? = null
runSafe {
Expand All @@ -38,12 +65,4 @@ class FakeDataSource @Inject constructor(val context: Application) : BaseDataSou
}
return response
}

override suspend fun fetchProductCategories(url: String): Result<List<ProductCategoriesItem>> {
TODO("Not yet implemented")
}

override suspend fun fetchProductForCategory(url: String): Result<List<ProductsItem>> {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.khalid.hamid.githubrepos.di

import com.khalid.hamid.githubrepos.network.BaseDataSource
import com.khalid.hamid.githubrepos.network.BaseRepository
import com.khalid.hamid.githubrepos.network.local.LocalDataSource
import com.khalid.hamid.githubrepos.network.remote.RemoteDataSource
Expand All @@ -31,7 +32,7 @@ class RepositoryModule {

@Singleton
@Provides
fun provideRepository(remoteDataSource: RemoteDataSource, localDataSource: LocalDataSource): BaseRepository {
fun provideRepository(remoteDataSource: RemoteDataSource, localDataSource: LocalDataSource): BaseDataSource {
return BaseRepository(remoteDataSource, localDataSource)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ abstract class ProjectBuildTask: DefaultTask() {
}

@TaskAction
fun runTask(taskString: String){
logger.quiet("running task ", taskString)
when(taskString.lowercase()){
fun runAll(taskString: String){
logger.quiet("running task ")
taskString.checkTask()
}

private fun String.checkTask(){
when(this.lowercase()){
"spotless" -> runSpotless()
"sonar" -> runSonar()
"oss" -> runOSSScan()
Expand All @@ -48,11 +52,18 @@ abstract class ProjectBuildTask: DefaultTask() {
runtime.exec("./gradlew :app:spotlessApply")
}

private fun runLint() {
pln("runLint")
runtime.exec("./gradlew :app:lintProdDebug")
}

private fun runSonar() {
// TODO:
pln("runSonar")
runtime.exec("./gradlew jacocoTestReport --stacktrace")
}

private fun runDepUpdates() {
pln("runDepUpdates")
runtime.exec("./gradlew app:dependencyUpdates")
}

Expand Down

0 comments on commit d439a9d

Please sign in to comment.