Added tranlators
This commit is contained in:
parent
c2bc78e7ea
commit
369411ffc6
10 changed files with 147 additions and 22 deletions
|
@ -25,29 +25,28 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.adapter.ContributorAdapter
|
||||
import code.name.monkey.retromusic.model.Contributor
|
||||
import code.name.monkey.retromusic.mvp.presenter.AboutPresenter
|
||||
import code.name.monkey.retromusic.mvp.presenter.AboutView
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialdialogs.LayoutMode
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.list.listItems
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import kotlinx.android.synthetic.main.activity_about.*
|
||||
import kotlinx.android.synthetic.main.card_credit.*
|
||||
import kotlinx.android.synthetic.main.card_other.*
|
||||
import kotlinx.android.synthetic.main.card_retro_info.*
|
||||
import kotlinx.android.synthetic.main.card_social.*
|
||||
import java.io.IOException
|
||||
import java.nio.charset.StandardCharsets
|
||||
import javax.inject.Inject
|
||||
|
||||
class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
||||
class AboutActivity : AbsBaseActivity(), View.OnClickListener, AboutView {
|
||||
|
||||
private val assetJsonData: String?
|
||||
/*private val assetJsonData: String?
|
||||
get() {
|
||||
val json: String
|
||||
try {
|
||||
val inputStream = assets.open("contributors.json")
|
||||
val inputStream = assets.open("data/contributors.json")
|
||||
val size = inputStream.available()
|
||||
val buffer = ByteArray(size)
|
||||
inputStream.read(buffer)
|
||||
|
@ -60,6 +59,9 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
|||
|
||||
return json
|
||||
}
|
||||
*/
|
||||
@Inject
|
||||
lateinit var aboutPresenter: AboutPresenter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
|
@ -69,13 +71,27 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
|||
setNavigationbarColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
|
||||
App.musicComponent.inject(this)
|
||||
aboutPresenter.attachView(this)
|
||||
|
||||
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
|
||||
toolbar.setBackgroundColor(toolbarColor)
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
version.setSummary(getAppVersion())
|
||||
setUpView()
|
||||
loadContributors()
|
||||
//loadContributors()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
aboutPresenter.loadContributors()
|
||||
aboutPresenter.loadTranslators()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
aboutPresenter.detachView()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
@ -159,15 +175,14 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
|||
.setText(String.format(getString(R.string.app_share), packageName)).startChooser()
|
||||
}
|
||||
|
||||
private fun loadContributors() {
|
||||
val type = object : TypeToken<List<Contributor>>() {
|
||||
|
||||
}.type
|
||||
val contributors = Gson().fromJson<List<Contributor>>(assetJsonData, type)
|
||||
|
||||
val contributorAdapter = ContributorAdapter(contributors)
|
||||
override fun showContributors(contributor: List<Contributor>) {
|
||||
val contributorAdapter = ContributorAdapter(contributor)
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
recyclerView.itemAnimator = DefaultItemAnimator()
|
||||
recyclerView.adapter = contributorAdapter
|
||||
}
|
||||
|
||||
override fun translators(contributor: List<Contributor>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,6 @@ interface MusicComponent {
|
|||
fun inject(searchActivity: SearchActivity)
|
||||
|
||||
fun inject(bannerHomeFragment: BannerHomeFragment)
|
||||
|
||||
fun inject(aboutActivity: AboutActivity)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package code.name.monkey.retromusic.dagger.module
|
|||
|
||||
import android.content.Context
|
||||
import code.name.monkey.retromusic.mvp.presenter.*
|
||||
import code.name.monkey.retromusic.mvp.presenter.AboutPresenter.AboutPresenterImpl
|
||||
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter.AlbumDetailsPresenterImpl
|
||||
import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter.AlbumsPresenterImpl
|
||||
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter.ArtistDetailsPresenterImpl
|
||||
|
@ -98,4 +99,9 @@ class PresenterModule {
|
|||
fun providesSongPresenter(presenter: SongPresenterImpl): SongPresenter {
|
||||
return presenter
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesAboutPresenter(presenter: AboutPresenterImpl): AboutPresenter {
|
||||
return presenter
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package code.name.monkey.retromusic.data
|
||||
|
||||
import code.name.monkey.retromusic.model.Contributor
|
||||
import com.google.gson.GsonBuilder
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.http.GET
|
||||
|
||||
private const val BASE_URL = "https://github.com/h4h13/RetroMusicPlayer/blob/dev/data/"
|
||||
|
||||
interface RetroDataService {
|
||||
|
||||
@GET("translators.json")
|
||||
suspend fun getContributors(): List<Contributor>
|
||||
|
||||
@GET("translators.json")
|
||||
suspend fun getTranslators(): List<Contributor>
|
||||
|
||||
companion object {
|
||||
val retoService = Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().create()))
|
||||
.build()
|
||||
.create(RetroDataService::class.java)
|
||||
}
|
||||
}
|
|
@ -37,8 +37,7 @@ interface DeezerApiService {
|
|||
|
||||
fun createDefaultOkHttpClient(
|
||||
context: Context
|
||||
): OkHttpClient.Builder =
|
||||
OkHttpClient.Builder()
|
||||
): OkHttpClient.Builder = OkHttpClient.Builder()
|
||||
.cache(createDefaultCache(context))
|
||||
.addInterceptor(createCacheControlInterceptor())
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
import code.name.monkey.retromusic.Result.Error
|
||||
import code.name.monkey.retromusic.Result.Success
|
||||
import code.name.monkey.retromusic.model.Contributor
|
||||
import code.name.monkey.retromusic.mvp.Presenter
|
||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||
import kotlinx.coroutines.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
interface AboutView {
|
||||
fun showContributors(contributor: List<Contributor>)
|
||||
fun translators(contributor: List<Contributor>)
|
||||
|
||||
}
|
||||
|
||||
interface AboutPresenter : Presenter<AboutView> {
|
||||
fun loadContributors()
|
||||
fun loadTranslators()
|
||||
class AboutPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<AboutView>(), AboutPresenter, CoroutineScope {
|
||||
|
||||
override fun loadContributors() {
|
||||
launch {
|
||||
when (val result = repository.contributors()) {
|
||||
is Success -> withContext(Dispatchers.Main) {
|
||||
view.showContributors(
|
||||
result.data
|
||||
)
|
||||
}
|
||||
is Error -> withContext(Dispatchers.Main) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadTranslators() {
|
||||
launch {
|
||||
when (val result = repository.translators()) {
|
||||
is Success -> withContext(Dispatchers.Main) {
|
||||
view.translators(
|
||||
result.data
|
||||
)
|
||||
}
|
||||
is Error -> withContext(Dispatchers.Main) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var job: Job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.IO + job
|
||||
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ import code.name.monkey.retromusic.Result
|
|||
import code.name.monkey.retromusic.Result.Error
|
||||
import code.name.monkey.retromusic.Result.Success
|
||||
import code.name.monkey.retromusic.adapter.HomeAdapter
|
||||
import code.name.monkey.retromusic.data.RetroDataService
|
||||
import code.name.monkey.retromusic.loaders.*
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||
|
@ -283,6 +284,22 @@ class RepositoryImpl @Inject constructor(private val context: Context) : Reposit
|
|||
Error(Throwable("Error loading artist"))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun contributors(): Result<List<Contributor>> {
|
||||
return try {
|
||||
Success(RetroDataService.retoService.getContributors())
|
||||
} catch (e: Exception) {
|
||||
Error(Throwable(e))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun translators(): Result<List<Contributor>> {
|
||||
return try {
|
||||
Success(RetroDataService.retoService.getTranslators())
|
||||
} catch (e: Exception) {
|
||||
Error(Throwable(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T : Any> safeApiCall(call: suspend () -> Result<T>, errorMessage: String): Result<T> =
|
||||
|
|
|
@ -58,4 +58,8 @@ interface Repository {
|
|||
suspend fun albumInfo(artist: String, album: String): Result<LastFmAlbum>
|
||||
|
||||
suspend fun artistById(artistId: Int): Result<Artist>
|
||||
|
||||
suspend fun contributors(): Result<List<Contributor>>
|
||||
|
||||
suspend fun translators(): Result<List<Contributor>>
|
||||
}
|
|
@ -24,13 +24,12 @@ object LastFmClient {
|
|||
}
|
||||
|
||||
init {
|
||||
val retrofit = Retrofit.Builder()
|
||||
lastFMService = Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.callFactory(createDefaultOkHttpClientBuilder().build())
|
||||
.addConverterFactory(GsonConverterFactory.create(Gson()))
|
||||
.build()
|
||||
|
||||
lastFMService = retrofit.create(LastFMService::class.java)
|
||||
.create(LastFMService::class.java)
|
||||
}
|
||||
|
||||
private fun createDefaultOkHttpClientBuilder(): OkHttpClient.Builder {
|
||||
|
|
Loading…
Reference in a new issue