Skip to content

Commit

Permalink
🎨 Simplify structure of base Android classes
Browse files Browse the repository at this point in the history
The explicitly created constructors are replaced one constructor with
default value of parameter. The constructor has @jvmoverloads
annotation to maintain Java interoperability.
  • Loading branch information
smidf authored and vsouhrada committed Apr 1, 2020
1 parent 5f1224b commit b2b2183
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import kotlinx.coroutines.cancel
* @see[AppCompatActivity]
* @since 0.1.0
*/
abstract class BaseActivity : AppCompatActivity, CoroutineScope {
abstract class BaseActivity @JvmOverloads constructor(
@LayoutRes contentLayoutId: Int = 0
) : AppCompatActivity(contentLayoutId), CoroutineScope {

override val coroutineContext = Dispatchers.Main + SupervisorJob()

constructor(): super()

constructor(@LayoutRes contentLayoutId: Int): super(contentLayoutId)

override fun onDestroy() {
super.onDestroy()
coroutineContext.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import kotlinx.coroutines.cancel
* @see[Fragment]
* @since 0.1.0
*/
abstract class BaseFragment : Fragment, CoroutineScope {
abstract class BaseFragment @JvmOverloads constructor(
@LayoutRes contentLayoutId: Int = 0
) : Fragment(contentLayoutId), CoroutineScope {

override val coroutineContext = Dispatchers.Main + SupervisorJob()

constructor(): super()

constructor(@LayoutRes contentLayoutId: Int): super(contentLayoutId)

override fun onDestroy() {
super.onDestroy()
coroutineContext.cancel()
Expand Down

0 comments on commit b2b2183

Please sign in to comment.