forked from github/wulkanowy-mirror
Add creators list (#636)
This commit is contained in:

committed by
Rafał Borcz

parent
ad3bb3a522
commit
4640d114f6
@ -2,6 +2,7 @@ package io.github.wulkanowy.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.AssetManager
|
||||
import android.content.res.Resources
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
@ -58,6 +59,10 @@ internal class RepositoryModule {
|
||||
@Provides
|
||||
fun provideResources(context: Context): Resources = context.resources
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideAssets(context: Context): AssetManager = context.assets
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideSharedPref(context: Context): SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
@ -0,0 +1,3 @@
|
||||
package io.github.wulkanowy.data.pojos
|
||||
|
||||
class AppCreator(val displayName: String, val githubUsername: String)
|
@ -0,0 +1,20 @@
|
||||
package io.github.wulkanowy.data.repositories.appcreator
|
||||
|
||||
import android.content.res.AssetManager
|
||||
import com.google.gson.Gson
|
||||
import io.github.wulkanowy.data.pojos.AppCreator
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AppCreatorRepository @Inject constructor(private val assets: AssetManager) {
|
||||
fun getAppCreators(): Single<List<AppCreator>> {
|
||||
return Single.fromCallable<List<AppCreator>> {
|
||||
Gson().fromJson(
|
||||
assets.open("creators.json").bufferedReader().use { it.readText() },
|
||||
Array<AppCreator>::class.java
|
||||
).toList()
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.about.creator.CreatorFragment
|
||||
import io.github.wulkanowy.ui.modules.about.license.LicenseFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
@ -42,6 +43,11 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView {
|
||||
Triple(getString(R.string.about_version), "${appInfo.versionName} (${appInfo.versionCode})", getCompatDrawable(R.drawable.ic_all_about))
|
||||
}
|
||||
|
||||
override val creatorsRes: Triple<String, String, Drawable?>?
|
||||
get() = context?.run {
|
||||
Triple(getString(R.string.about_creator), getString(R.string.about_creator_summary), getCompatDrawable(R.drawable.ic_about_creator))
|
||||
}
|
||||
|
||||
override val feedbackRes: Triple<String, String, Drawable?>?
|
||||
get() = context?.run {
|
||||
Triple(getString(R.string.about_feedback), getString(R.string.about_feedback_summary), getCompatDrawable(R.drawable.ic_about_feedback))
|
||||
@ -143,6 +149,10 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView {
|
||||
(activity as? MainActivity)?.pushView(LicenseFragment.newInstance())
|
||||
}
|
||||
|
||||
override fun openCreators() {
|
||||
(activity as? MainActivity)?.pushView(CreatorFragment.newInstance())
|
||||
}
|
||||
|
||||
override fun openPrivacyPolicy() {
|
||||
context?.openInternetBrowser("https://wulkanowy.github.io/polityka-prywatnosci.html", ::showMessage)
|
||||
}
|
||||
|
@ -52,6 +52,11 @@ class AboutPresenter @Inject constructor(
|
||||
openLicenses()
|
||||
analytics.logEvent("about_open", "name" to "licenses")
|
||||
}
|
||||
creatorsRes?.first -> {
|
||||
Timber.i("Opening creators view")
|
||||
openCreators()
|
||||
analytics.logEvent("about_open", "name" to "creators")
|
||||
}
|
||||
privacyRes?.first -> {
|
||||
Timber.i("Opening privacy page ")
|
||||
openPrivacyPolicy()
|
||||
@ -65,6 +70,7 @@ class AboutPresenter @Inject constructor(
|
||||
view?.run {
|
||||
updateData(AboutScrollableHeader(), listOfNotNull(
|
||||
versionRes?.let { (title, summary, image) -> AboutItem(title, summary, image) },
|
||||
creatorsRes?.let { (title, summary, image) -> AboutItem(title, summary, image) },
|
||||
feedbackRes?.let { (title, summary, image) -> AboutItem(title, summary, image) },
|
||||
faqRes?.let { (title, summary, image) -> AboutItem(title, summary, image) },
|
||||
discordRes?.let { (title, summary, image) -> AboutItem(title, summary, image) },
|
||||
|
@ -7,6 +7,8 @@ interface AboutView : BaseView {
|
||||
|
||||
val versionRes: Triple<String, String, Drawable?>?
|
||||
|
||||
val creatorsRes: Triple<String, String, Drawable?>?
|
||||
|
||||
val feedbackRes: Triple<String, String, Drawable?>?
|
||||
|
||||
val faqRes: Triple<String, String, Drawable?>?
|
||||
@ -33,5 +35,7 @@ interface AboutView : BaseView {
|
||||
|
||||
fun openLicenses()
|
||||
|
||||
fun openCreators()
|
||||
|
||||
fun openPrivacyPolicy()
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
package io.github.wulkanowy.ui.modules.about.creator
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.ViewGroup
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.common.FlexibleItemDecoration
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.setOnItemClickListener
|
||||
import kotlinx.android.synthetic.main.fragment_creator.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class CreatorFragment : BaseFragment(), CreatorView, MainView.TitledView {
|
||||
|
||||
@Inject
|
||||
lateinit var presenter: CreatorPresenter
|
||||
|
||||
@Inject
|
||||
lateinit var creatorsAdapter: FlexibleAdapter<AbstractFlexibleItem<*>>
|
||||
|
||||
override val titleStringId get() = R.string.creators_title
|
||||
|
||||
companion object {
|
||||
fun newInstance() = CreatorFragment()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_creator, container, false)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
presenter.onAttachView(this)
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
with(creatorRecycler) {
|
||||
layoutManager = SmoothScrollLinearLayoutManager(context)
|
||||
adapter = creatorsAdapter
|
||||
addItemDecoration(FlexibleItemDecoration(context)
|
||||
.withDefaultDivider()
|
||||
.withDrawDividerOnLastItem(false))
|
||||
}
|
||||
creatorsAdapter.setOnItemClickListener(presenter::onItemSelected)
|
||||
creatorSeeMore.setOnClickListener { presenter.onSeeMoreClick() }
|
||||
}
|
||||
|
||||
override fun updateData(data: List<CreatorItem>) {
|
||||
creatorsAdapter.updateDataSet(data)
|
||||
}
|
||||
|
||||
override fun openUserGithubPage(username: String) {
|
||||
context?.openInternetBrowser("https://github.com/${username}", ::showMessage)
|
||||
}
|
||||
|
||||
override fun openGithubContributorsPage() {
|
||||
context?.openInternetBrowser("https://github.com/wulkanowy/wulkanowy/graphs/contributors", ::showMessage)
|
||||
}
|
||||
|
||||
override fun showProgress(show: Boolean) {
|
||||
creatorProgress.visibility = if (show) VISIBLE else GONE
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
presenter.onDetachView()
|
||||
super.onDestroyView()
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package io.github.wulkanowy.ui.modules.about.creator
|
||||
|
||||
import android.view.View
|
||||
import coil.api.load
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.pojos.AppCreator
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.item_creator.*
|
||||
|
||||
class CreatorItem(val creator: AppCreator) : AbstractFlexibleItem<CreatorItem.ViewHolder>() {
|
||||
|
||||
override fun getLayoutRes() = R.layout.item_creator
|
||||
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>) = ViewHolder(view, adapter)
|
||||
|
||||
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>) {
|
||||
with(holder) {
|
||||
creatorItemName.text = creator.displayName
|
||||
|
||||
creatorItemAvatar.load("https://github.com/${creator.githubUsername}.png") {
|
||||
transformations(RoundedCornersTransformation(8f))
|
||||
crossfade(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as CreatorItem
|
||||
|
||||
if (creator != other.creator) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode() = creator.hashCode()
|
||||
|
||||
class ViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>) : FlexibleViewHolder(view, adapter),
|
||||
LayoutContainer {
|
||||
|
||||
override val containerView: View? get() = contentView
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package io.github.wulkanowy.ui.modules.about.creator
|
||||
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.data.pojos.AppCreator
|
||||
import io.github.wulkanowy.data.repositories.appcreator.AppCreatorRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
class CreatorPresenter @Inject constructor(
|
||||
schedulers: SchedulersProvider,
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository,
|
||||
private val appCreatorRepository: AppCreatorRepository
|
||||
) : BasePresenter<CreatorView>(errorHandler, studentRepository, schedulers) {
|
||||
|
||||
override fun onAttachView(view: CreatorView) {
|
||||
super.onAttachView(view)
|
||||
view.initView()
|
||||
loadData()
|
||||
}
|
||||
|
||||
fun onItemSelected(item: AbstractFlexibleItem<*>) {
|
||||
if (item !is CreatorItem) return
|
||||
view?.openUserGithubPage(item.creator.githubUsername)
|
||||
}
|
||||
|
||||
fun onSeeMoreClick() {
|
||||
view?.openGithubContributorsPage()
|
||||
}
|
||||
|
||||
private fun loadData() {
|
||||
disposable.add(appCreatorRepository.getAppCreators()
|
||||
.map { it.map { creator -> CreatorItem(creator) } }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doFinally { view?.showProgress(false) }
|
||||
.subscribe({ view?.run { updateData(it) } }, { errorHandler.dispatch(it) }))
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.github.wulkanowy.ui.modules.about.creator
|
||||
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
|
||||
interface CreatorView : BaseView {
|
||||
|
||||
fun initView()
|
||||
|
||||
fun updateData(data: List<CreatorItem>)
|
||||
|
||||
fun openUserGithubPage(username: String)
|
||||
|
||||
fun openGithubContributorsPage()
|
||||
|
||||
fun showProgress(show: Boolean)
|
||||
}
|
@ -8,6 +8,7 @@ import dagger.android.ContributesAndroidInjector
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.di.scopes.PerFragment
|
||||
import io.github.wulkanowy.ui.modules.about.AboutFragment
|
||||
import io.github.wulkanowy.ui.modules.about.creator.CreatorFragment
|
||||
import io.github.wulkanowy.ui.modules.about.license.LicenseFragment
|
||||
import io.github.wulkanowy.ui.modules.about.license.LicenseModule
|
||||
import io.github.wulkanowy.ui.modules.account.AccountDialog
|
||||
@ -121,6 +122,10 @@ abstract class MainModule {
|
||||
@ContributesAndroidInjector(modules = [LicenseModule::class])
|
||||
abstract fun bindLicenseFragment(): LicenseFragment
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindCreatorsFragment(): CreatorFragment
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector(modules = [SchoolAndTeachersModule::class])
|
||||
abstract fun bindSchoolAndTeachersFragment(): SchoolAndTeachersFragment
|
||||
|
Reference in New Issue
Block a user