Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1184c86
commit f656011
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
core_presentation/src/main/java/com/raqun/core/presentation/base/BaseFragment.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.raqun.core.presentation.base | ||
|
||
import android.os.Bundle | ||
import android.view.* | ||
import android.widget.Toast | ||
import androidx.annotation.LayoutRes | ||
import androidx.annotation.MenuRes | ||
import androidx.annotation.StringRes | ||
import androidx.fragment.app.Fragment | ||
import com.raqun.core.presentation.Constants | ||
|
||
abstract class BaseFragment : Fragment(), BaseView { | ||
|
||
@LayoutRes | ||
protected abstract fun getLayoutRes(): Int | ||
|
||
@MenuRes | ||
open val menuRes = Constants.NO_RES | ||
|
||
@StringRes | ||
open val titleRes = Constants.NO_RES | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setHasOptionsMenu(menuRes != Constants.NO_RES) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { | ||
super.onCreateOptionsMenu(menu, inflater) | ||
if (menuRes != Constants.NO_RES) { | ||
inflater?.inflate(menuRes, menu) | ||
} | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(getLayoutRes(), null, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initView() | ||
} | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
if (titleRes != Constants.NO_RES) { | ||
setActivityTitle(getString(titleRes)) | ||
} | ||
} | ||
|
||
override fun onError(e: Error) { | ||
Toast.makeText(context, "Unknown error has been occurred!", Toast.LENGTH_LONG).show() | ||
} | ||
|
||
protected fun setActivityTitle(title: String) { | ||
if (activity is BaseActivity) { | ||
(activity as BaseActivity).setScreenTitle(title) | ||
} | ||
} | ||
|
||
fun getApplication() = activity?.application | ||
|
||
fun getApplicationContext() = getApplication()?.applicationContext | ||
|
||
open fun initView() { | ||
// can be overridden | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
core_presentation/src/main/java/com/raqun/core/presentation/base/BaseInjectionActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.raqun.core.presentation.base | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import dagger.android.AndroidInjection | ||
import dagger.android.AndroidInjector | ||
import dagger.android.DispatchingAndroidInjector | ||
import dagger.android.support.HasSupportFragmentInjector | ||
import javax.inject.Inject | ||
|
||
abstract class BaseInjectionActivity : BaseActivity(), HasSupportFragmentInjector { | ||
|
||
@Inject | ||
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> | ||
|
||
override fun supportFragmentInjector(): AndroidInjector<Fragment> = dispatchingAndroidInjector | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
AndroidInjection.inject(this) | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
open fun onInject() { | ||
// empty for override | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core_presentation/src/main/java/com/raqun/core/presentation/base/BaseView.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.raqun.core.presentation.base | ||
|
||
interface BaseView { | ||
fun onError(e: Error) | ||
} |
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