Skip to content

Instantly share code, notes, and snippets.

@enyciaa
enyciaa / file.kt
Created May 13, 2020 16:22
Medium - single activity architecture - part 3 of modern android series - 10
interface Navigator {
fun goToDetailsFromMain(githubRepoEntity: GithubRepoEntity)
fun goToUrl(url: String)
}
@enyciaa
enyciaa / file.kt
Created May 13, 2020 16:22
Medium - single activity architecture - part 3 of modern android series - 11
@SingleActivity
class NavigatorImpl @Inject constructor(
private val androidPlaygroundActivity: AndroidPlaygroundActivity
): Navigator {
override fun goToDetailsFromMain(githubRepo: GithubRepoEntity) {
val action = MainFragmentDirections.actionMainFragmentToDetailsFragment(githubRepo)
androidPlaygroundActivity.findNavController(R.id.nav_host_fragment).navigate(action)
}
@enyciaa
enyciaa / file.kt
Created May 13, 2020 16:23
Medium - single activity architecture - part 3 of modern android series - 12
fun repoClicked(githubRepoEntity: GithubRepoEntity) {
navigator.goToDetails(githubRepoEntity)
}
fun onGoToRepositoryClicked() {
navigator.goToUrl(githubRepoEntity.url)
}
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:26
Medium - single activity architecture - part 3 of modern android series - 1
class AndroidPlaygroundActivity : DaggerAppCompatActivity()
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:27
Medium - single activity architecture - part 3 of modern android series - 2
abstract class BaseFragment : DaggerFragment() {
// Code emitted for brevity
}
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:28
Medium - single activity architecture - part 3 of modern android series - 3
class DetailsFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val githubRepoEntity = arguments?.getParcelable<GithubRepoEntity>(REPOSITORY_KEY)
githubRepoEntity?.let { detailsViewModel.initData(it) }
}
override fun onCreateView(
inflater: LayoutInflater,
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:28
Medium - single activity architecture - part 3 of modern android series - 4
class MainFragment : BaseFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_main, container, false)
}
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:29
Medium - single activity architecture - part 3 of modern android series - 5
Toast.makeText(requireContext(), it.error, Toast.LENGTH_LONG).show()
@enyciaa
enyciaa / file.kt
Last active May 13, 2020 16:30
Medium - single activity architecture - part 3 of modern android series - 6
fun Fragment.requireAppCompatActivity(): AppCompatActivity {
return requireActivity() as? AppCompatActivity
?: throw IllegalStateException("Activity this fragment is attached to does not extend AppCompatActivity")
}
requireAppCompatActivity().supportActionBar?.title = it.toolbarTitle
@enyciaa
enyciaa / file.xml
Last active May 13, 2020 16:31
Medium - single activity architecture - part 3 of modern android series - 7
<activity android:name=".ui.AndroidPlaygroundActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>