Skip to content

Instantly share code, notes, and snippets.

View princessdharmy's full-sized avatar
👩‍💻
I learn how to be better everyday...

Damilola Omoyiwola princessdharmy

👩‍💻
I learn how to be better everyday...
View GitHub Profile
class CompetitionsFragment : BaseFragment() {
override fun onAttach(context: Context) {
super.onAttach(context)
// Inject dagger here
DaggerCompetitionComponent.factory().create(coreComponent()).inject(this)
}
}
@Module
interface CompetitionsViewModelModule {
@Binds
@Fragment
fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory
@Binds
@IntoMap
@ViewModelKey(CompetitionsViewModel::class)
@Component(dependencies = [CoreComponent::class],
modules = [CompetitionsViewModelModule::class]
)
@Fragment
interface CompetitionComponent {
@Component.Factory
interface Factory {
fun create(component: CoreComponent): CompetitionComponent
}
class MainApplication: Application() {
private val coreComponent: CoreComponent by lazy {
DaggerCoreComponent.factory().create(this)
}
companion object {
@JvmStatic
fun coreComponent(context: Context) =
(context.applicationContext as MainApplication).coreComponent
@Module
abstract class CoreModule {
@Binds
@Singleton
abstract fun bindApplication(application: MainApplication): Application
}
@Singleton
@Component(modules = [CoreModule::class, DataModule::class, DatabaseModule::class])
interface CoreComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance context: Context): CoreComponent
}
val competitionsRepository: CompetitionsRepository
class BottomSheetAdapter (
private var squadList: List<Player>
): RecyclerView.Adapter<BottomSheetAdapter.ViewHolder>() {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
val view = LayoutInflater.from(p0.context).inflate(R.layout.team_line_names, p0, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
class BottomSheetFragment : BottomSheetDialogFragment() {
companion object {
fun newInstance(players: PlayerResponse) = BottomSheetFragment().apply {
arguments = Bundle().apply {
putString("name", players.name)
putString("url", players.crestUrl)
putParcelableArrayList("players", ArrayList(players.squad))
}
}
class CompetitionDetailsActivity : DaggerAppCompatActivity(), TeamFragment.OnFragmentInteractionListener {
private var bottomSheetFragment: BottomSheetFragment? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_competition_details)
}
override fun sendTeam(playerResponse: PlayerResponse) {
class TeamFragment : DaggerFragment() {
private var listener: OnFragmentInteractionListener? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.team_fragment, container, false)
val view = binding.root