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
class CompetitionsFragment : BaseFragment() { | |
override fun onAttach(context: Context) { | |
super.onAttach(context) | |
// Inject dagger here | |
DaggerCompetitionComponent.factory().create(coreComponent()).inject(this) | |
} | |
} |
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
@Module | |
interface CompetitionsViewModelModule { | |
@Binds | |
@Fragment | |
fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory | |
@Binds | |
@IntoMap | |
@ViewModelKey(CompetitionsViewModel::class) |
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
@Component(dependencies = [CoreComponent::class], | |
modules = [CompetitionsViewModelModule::class] | |
) | |
@Fragment | |
interface CompetitionComponent { | |
@Component.Factory | |
interface Factory { | |
fun create(component: CoreComponent): CompetitionComponent | |
} |
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
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 |
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
@Module | |
abstract class CoreModule { | |
@Binds | |
@Singleton | |
abstract fun bindApplication(application: MainApplication): Application | |
} |
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
@Singleton | |
@Component(modules = [CoreModule::class, DataModule::class, DatabaseModule::class]) | |
interface CoreComponent { | |
@Component.Factory | |
interface Factory { | |
fun create(@BindsInstance context: Context): CoreComponent | |
} | |
val competitionsRepository: CompetitionsRepository |
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
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 { |
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
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)) | |
} | |
} |
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
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) { |
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
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 |