-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
myung jun Hyun
committed
Nov 19, 2019
1 parent
845f2a9
commit 636bf2d
Showing
13 changed files
with
184 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
package com.mashup | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.mashup.app.notices.NoticesActivity | ||
import com.mashup.repository.NoticesRepository | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.schedulers.Schedulers | ||
import org.koin.android.ext.android.inject | ||
|
||
class SplashActivity : AppCompatActivity() { | ||
private val noticesRepository: NoticesRepository by inject() | ||
private val compositeDisposable = CompositeDisposable() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_splash) | ||
Handler().postDelayed({ | ||
startActivity(Intent(this, NoticesActivity::class.java)) | ||
finish() | ||
},2000) | ||
|
||
compositeDisposable.add( | ||
noticesRepository | ||
.getNoticeList() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe({ | ||
startActivity(Intent(this, NoticesActivity::class.java)) | ||
finish() | ||
}, { | ||
it.printStackTrace() | ||
})) | ||
} | ||
|
||
override fun onDestroy() { | ||
compositeDisposable.clear() | ||
super.onDestroy() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mashup.di | ||
|
||
import com.mashup.api.notice.NoticeService | ||
import com.mashup.api.user.UserService | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
|
||
val ApiModule = module { | ||
single<NoticeService>(createdAtStart = false) { get<Retrofit>().create(NoticeService::class.java) } | ||
single<UserService>(createdAtStart = false) { get<Retrofit>().create(UserService::class.java) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mashup.di | ||
|
||
import com.mashup.repository.DefaultNoticesRepository | ||
import com.mashup.repository.NoticesRepository | ||
import com.mashup.repository.source.remote.RepositoriesRemoteDataSource | ||
import org.koin.dsl.module | ||
|
||
val ApplicationModule = module { | ||
single { RepositoriesRemoteDataSource(get()) } | ||
single { DefaultNoticesRepository(get()) as NoticesRepository } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.mashup.di | ||
|
||
import com.google.gson.GsonBuilder | ||
import com.mashup.BuildConfig | ||
import okhttp3.Cache | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.koin.android.ext.koin.androidApplication | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
|
||
private const val BASE_URL = BuildConfig.BASE_URL | ||
private const val TIMEOUT_CONNECT = 15L | ||
|
||
val NetworkModule = module { | ||
single { Cache(androidApplication().cacheDir, 10L * 1024 * 1024) } | ||
|
||
single { | ||
OkHttpClient.Builder().apply { | ||
cache(get()) | ||
connectTimeout(TIMEOUT_CONNECT, TimeUnit.SECONDS) | ||
retryOnConnectionFailure(true) | ||
addInterceptor(HttpLoggingInterceptor().apply { | ||
if (BuildConfig.DEBUG) { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
}) | ||
}.build() | ||
} | ||
|
||
single { GsonBuilder().create() } | ||
|
||
single { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create(get())) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.client(get()) | ||
.build() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/mashup/repository/DefaultNoticesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.mashup.repository | ||
|
||
import com.mashup.model.Notice | ||
import com.mashup.repository.source.remote.RepositoriesRemoteDataSource | ||
import io.reactivex.Flowable | ||
|
||
class DefaultNoticesRepository( | ||
private val noticesRemoteDataSource: RepositoriesRemoteDataSource | ||
) : NoticesRepository { | ||
private var cachedNotices = emptyList<Notice>() | ||
private var mCacheIsDirty = false | ||
|
||
override fun getNoticeList(): Flowable<List<Notice>> { | ||
|
||
if (cachedNotices.isNotEmpty() && !mCacheIsDirty) { | ||
return Flowable.fromArray(cachedNotices) | ||
} | ||
|
||
return noticesRemoteDataSource | ||
.getNoticeList() | ||
.flatMap { notices -> | ||
Flowable.fromArray(notices).doOnNext { | ||
cachedNotices = notices | ||
} | ||
} | ||
.doOnComplete({ mCacheIsDirty = false }) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mashup.repository | ||
|
||
import com.mashup.model.Notice | ||
import io.reactivex.Flowable | ||
|
||
interface NoticesRepository { | ||
|
||
fun getNoticeList(): Flowable<List<Notice>> | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/mashup/repository/source/remote/NoticesRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mashup.repository.source.remote | ||
|
||
import com.mashup.api.notice.NoticeService | ||
import com.mashup.model.Notice | ||
import io.reactivex.Flowable | ||
import io.reactivex.schedulers.Schedulers | ||
|
||
class RepositoriesRemoteDataSource internal constructor( | ||
private val noticeService: NoticeService | ||
) { | ||
fun getNoticeList(): Flowable<List<Notice>> = | ||
noticeService.getNoticeList().subscribeOn(Schedulers.io()) | ||
} |