Skip to content

Commit

Permalink
experimental: introduce core module.
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanLiou committed Aug 15, 2021
1 parent 9203d19 commit bced9a1
Show file tree
Hide file tree
Showing 51 changed files with 325 additions and 121 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ext {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":core")
implementation project(":anchor-bottom-sheet-behavior")
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
// FIXME:: map 3.1.0 use volley 1.1.0 which is not available on mavenCentral and google
Expand All @@ -130,7 +131,6 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.fragment:fragment-ktx:1.3.6"
implementation "com.google.android.gms:play-services-location:${gms_version}"

// HTTP Client
implementation "com.squareup.retrofit2:retrofit:${retrofit_version}"
Expand Down
4 changes: 0 additions & 4 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# public *;
#}

-keep class tw.com.louis383.coffeefinder.model.entity.** { *; }
-keep class tw.com.louis383.coffeefinder.model.domain.** { *; }
-keep interface tw.com.louis383.coffeefinder.model.data.api.CoffeeTripService { *; }

# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tw.com.louis383.coffeefinder

import androidx.fragment.app.Fragment
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

/**
* Created by louis383 on 2017/2/26.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import androidx.lifecycle.Lifecycle
import com.google.android.libraries.maps.model.LatLng
import dagger.hilt.android.AndroidEntryPoint
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.model.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.uimodel.CoffeeShopUiModel
import tw.com.louis383.coffeefinder.uimodel.getUiModel
import tw.com.louis383.coffeefinder.utils.FragmentArgumentDelegate
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import dagger.Reusable
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import tw.com.louis383.coffeefinder.model.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.model.PermissionChecker
import tw.com.louis383.coffeefinder.model.UserLocationListener
import tw.com.louis383.coffeefinder.core.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.core.PermissionChecker
import tw.com.louis383.coffeefinder.core.UserLocationListener
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import tw.com.louis383.coffeefinder.BuildConfig
import tw.com.louis383.coffeefinder.model.ConnectivityChecker
import tw.com.louis383.coffeefinder.model.data.api.CoffeeTripService
import tw.com.louis383.coffeefinder.core.ConnectivityChecker
import tw.com.louis383.coffeefinder.core.data.api.CoffeeTripService
import java.util.concurrent.TimeUnit
import javax.inject.Qualifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import tw.com.louis383.coffeefinder.model.domain.repository.CoffeeShopRepository
import tw.com.louis383.coffeefinder.model.domain.repository.CoffeeShopRepositoryImpl
import tw.com.louis383.coffeefinder.core.domain.repository.CoffeeShopRepository
import tw.com.louis383.coffeefinder.core.domain.repository.CoffeeShopRepositoryImpl

@InstallIn(SingletonComponent::class)
@Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tw.com.louis383.coffeefinder.list

import tw.com.louis383.coffeefinder.BaseView
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

interface CoffeeShopListView : BaseView {
fun setLoadingProgressBarVisibility(visible: Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tw.com.louis383.coffeefinder.list

import android.location.Location
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

/**
* Created by louis383 on 2017/3/8.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dagger.hilt.android.AndroidEntryPoint
import tw.com.louis383.coffeefinder.BaseFragment
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.R.layout
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.utils.FragmentArgumentDelegate
import tw.com.louis383.coffeefinder.utils.RecyclerViewDividerHelper
import tw.com.louis383.coffeefinder.view.CoffeeListAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tw.com.louis383.coffeefinder.list
import android.location.Location
import dagger.hilt.android.scopes.FragmentScoped
import tw.com.louis383.coffeefinder.BasePresenter
import tw.com.louis383.coffeefinder.model.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.CurrentLocationCarrier
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import javax.inject.Inject

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior
import dagger.hilt.android.AndroidEntryPoint
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.adapter.ViewPagerAdapter
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.details.DetailsFragment
import tw.com.louis383.coffeefinder.details.DetailsItemClickListener
import tw.com.louis383.coffeefinder.list.ListFragment
import tw.com.louis383.coffeefinder.maps.MapsClickHandler
import tw.com.louis383.coffeefinder.maps.MapsFragment
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.uimodel.getUiModel
import tw.com.louis383.coffeefinder.utils.Utils
import tw.com.louis383.coffeefinder.utils.bindView
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import tw.com.louis383.coffeefinder.BasePresenter
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.model.ConnectivityChecker
import tw.com.louis383.coffeefinder.model.UserLocationListener
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.model.domain.usecase.GetCoffeeShopsUseCase
import tw.com.louis383.coffeefinder.core.ConnectivityChecker
import tw.com.louis383.coffeefinder.core.UserLocationListener
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.usecase.GetCoffeeShopsUseCase
import tw.com.louis383.coffeefinder.uimodel.getUiModel
import tw.com.louis383.coffeefinder.utils.ifNotNull
import tw.com.louis383.coffeefinder.utils.toLatLng
import java.util.*
Expand Down Expand Up @@ -162,7 +163,7 @@ class MainPresenter @Inject constructor(
ifNotNull(currentLocation, lastTappedCoffeeShop) { currentLocation: Location, lastTappedCoffeeShop: CoffeeShop ->
val urlString = String.format(
Locale.getDefault(), "http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f&mode=w",
lastTappedCoffeeShop.location.latitude, lastTappedCoffeeShop.location.longitude,
lastTappedCoffeeShop.mapLocation.latitude, lastTappedCoffeeShop.mapLocation.longitude,
currentLocation.latitude, currentLocation.longitude
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.google.android.gms.common.api.ResolvableApiException
import com.google.android.libraries.maps.model.LatLng
import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior
import tw.com.louis383.coffeefinder.BaseView
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

interface MainView : BaseView {
fun isApplicationInstalled(packageName: String): Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tw.com.louis383.coffeefinder.maps

import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

/**
* Created by louis383 on 2017/3/7.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.google.android.libraries.maps.model.MarkerOptions
import dagger.hilt.android.AndroidEntryPoint
import tw.com.louis383.coffeefinder.BaseFragment
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.utils.ifNotNull
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import com.google.android.libraries.maps.model.Marker
import dagger.hilt.android.scopes.FragmentScoped
import tw.com.louis383.coffeefinder.BasePresenter
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.utils.toLatLng
import javax.inject.Inject

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ class MapsPresenter @Inject constructor() : BasePresenter<MapsView>(), GoogleMap
for (coffeeShop in coffeeShops) {
val distance = coffeeShop.distance.toString()
normalMarker?.run {
val generatedMarker = view?.addMakers(coffeeShop.location, coffeeShop.name, distance, coffeeShop, this)
val generatedMarker = view?.addMakers(coffeeShop.mapLocation.toLatLng(), coffeeShop.name, distance, coffeeShop, this)
generatedMarker?.let {
markerMap[coffeeShop.id] = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.google.android.libraries.maps.model.BitmapDescriptor
import com.google.android.libraries.maps.model.LatLng
import com.google.android.libraries.maps.model.Marker
import tw.com.louis383.coffeefinder.BaseView
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop

interface MapsView : BaseView {
fun checkLocationPermission(): Boolean
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import android.net.Uri
import android.text.TextUtils
import com.google.android.libraries.maps.model.LatLng
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.utils.toMapLocation

/**
* Created by louis383 on 2017/1/24.
*/

fun CoffeeShop.getUiModel(): CoffeeShopUiModel {
return CoffeeShopUiModel(this)
}

class CoffeeShopUiModel(private val coffeeShop: CoffeeShop) {
companion object {
private const val CAFE_NOMAD_PATH = "https://cafenomad.tw/shop/"
Expand Down Expand Up @@ -43,7 +49,7 @@ class CoffeeShopUiModel(private val coffeeShop: CoffeeShop) {
get() = coffeeShop.address

fun getDistancesFromLocation(latLng: LatLng): String {
val distance: Int = coffeeShop.calculateDistanceFromLocation(latLng)
val distance: Int = coffeeShop.calculateDistanceFromLocation(latLng.toMapLocation())
return distance.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.location.Location
import android.view.View
import androidx.annotation.IdRes
import com.google.android.libraries.maps.model.LatLng
import tw.com.louis383.coffeefinder.core.domain.model.MapLocation

fun <T: View> Activity.bindView(@IdRes resId: Int): Lazy<T> = lazy {
findViewById<T>(resId)
Expand All @@ -20,3 +21,11 @@ fun Location.toLatLng(): LatLng {
return LatLng(latitude, longitude)
}

fun MapLocation.toLatLng(): LatLng {
return LatLng(latitude, longitude)
}

fun LatLng.toMapLocation(): MapLocation {
return MapLocation(latitude, longitude)
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.libraries.maps.model.LatLng
import tw.com.louis383.coffeefinder.R
import tw.com.louis383.coffeefinder.core.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.list.ListAdapterHandler
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop
import tw.com.louis383.coffeefinder.uimodel.getUiModel

/**
* Created by louis383 on 2017/2/26.
Expand Down
1 change: 1 addition & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
66 changes: 66 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'kotlinx-serialization'
id 'dagger.hilt.android.plugin'
}

android {
compileSdk compile_sdk_version

defaultConfig {
minSdk min_sdk_version
targetSdk target_sdk_version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
}
}

ext {
retrofit_version = '2.9.0'
coroutines_version = '1.5.1'
}

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
// Kotlin
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutines_version}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${coroutines_version}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:${coroutines_version}"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"

// GMS
implementation "com.google.android.gms:play-services-location:${gms_version}"

// HTTP Client
implementation "com.squareup.retrofit2:retrofit:${retrofit_version}"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'

// Dependency Injection
implementation "com.google.dagger:hilt-android:$dagger_version"
kapt "com.google.dagger:hilt-compiler:$dagger_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Loading

0 comments on commit bced9a1

Please sign in to comment.