- Analytics Repository interface to implemented in app project
- Commons utils and extention
- Support MVVM pattern with BaseViewModel
- Network Configuration
- WebViewActivity used/ call this directly to show webview
- BaseActivity and BaseFragment
Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.mncinnovation:mnc-android-code-standard-core:0.1.3'
}
or Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.mncinnovation</groupId>
<artifactId>mnc-android-code-standard-core</artifactId>
<version>0.1.3</version>
</dependency>
- BaseActivity
class MainActivity : BaseActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) showToolbarBack(false) showToolbarTitle(false) } }
- BaseViewModel
- Handle Result from com.mncgroup.core.network.Result (To Handle result from any data model)
- Common live event, like _isLoading, showErrorDialog, navigateToLogin and more.
class LoginViewModel constructor( private val authRepository: AuthRepository, userRepository: UserRepository ) : BaseViewModel() { val userData: LiveData<List<UserModel>> = userRepository.getUserLiveData() @OptIn(DelicateCoroutinesApi::class) fun authLogin(email: String, password: String) { _isLoading.value = true GlobalScope.launch(Dispatchers.Main) { val result = authRepository.requestLogin(LoginRequest(email, password)) result.handle { //handle result ok _isLoading.value = false } } } }
- WebViewActivity, an activity class to show webview. You can use
WebViewActivitydirectly from your project.
val headers: MutableMap<String, String> = mutableMapOf() headers["token"] = "5454wvybw9y9" startActivity( Intent(this@MainActivity, WebViewActivity::class.java) .apply { putExtra(EXTRA_TITLE, "Webview") putExtra(EXTRA_HEADERS, headers.toMap() as Serializable) data = Uri.parse("https://cloud.google.com/speech-to-text/docs/libraries") } )
- Load Image
Easy load image by accessing ImageView extensions. image view extension
ivImage.load("https://img.shields.io/github/v/release/mncinnovation/mnc-android-code-standard-core.svg?label=latest")- Snackbar
btnShowSnackbar.setOnClickListener {
showSnackbar(it, "Ini snackbar") {
Toast.makeText(this@MainActivity, "closed snackbar", Toast.LENGTH_SHORT).show()
}
}- Intens
There is an Intents object that contain functions that return Intent Intents
btnOpenLocationSetting.setOnClickListener {
startActivity(Intents.createOpenLocationSettings())
}- AppCompatAlert
Show appCompatAlert or with action, or with input action. showAppCompatAlert Options
btnShowAppCompatAlertAction.setOnClickListener {
showAppCompatAlert("This is a message") {
Toast.makeText(this@MainActivity, "Test", Toast.LENGTH_SHORT).show()
}
}- Date Picker and Date utils
btnShowDatePicker.setOnClickListener {
showDatePickerAction(null, null) { day, month, year ->
Toast.makeText(
this@MainActivity, "selected date is " + day +
" / " + month +
" / " + year, Toast.LENGTH_SHORT
).show()
}.show()
}Calendar extensions
Calendar.getDate()Calendar.getMonth()Calendar.getFullYear()Calendar.getHours(),Calendar.getMinutes(),Calendar.getSeconds(),Calendar.getMilliseconds()DateFormat.parseIndonesianCalendar(dateString: String): Calendar
Date Format with indonesian Locale variable Date Format
- Permissions
Check any permissions and request permissions.
private fun checkPermissionOrOpenCamera() { when (checkPermissionsAll( listOf( Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE ) )) { PermissionResult.Granted -> openFileChooser() PermissionResult.DialogNeeded, PermissionResult.NeedRequest -> { requestPermissions( RC_CAMERA, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE ) } } }
- Internet Util
This is an object to help app check internet connection. First need to init in application class.
class AppNameApplication : Application() { override fun onCreate() { super.onCreate() //init internet util InternetUtil.init(this) } }
And to use it call runIfConnectedOrResultException and place call of function API at the body like this sample.
interface AuthRepository { suspend fun requestLogin(request: LoginRequest): Result<LoginResponse> } class AuthRepositoryImpl(private val authApi: AuthApi, private val userRepository: UserRepository) : AuthRepository { @OptIn(ExperimentalCoroutinesApi::class) override suspend fun requestLogin(request: LoginRequest): Result<LoginResponse> { return runIfConnectedOrResultException { authApi.loginUser(request).awaitResult() { userRepository.updateUser(this.user) this } } } }
- View Extensions
Common functions for view configurations.
View.hideKeyboard()andView.showKeyboard()View.toBitmap()Boolean?.toVisibleOrGone()Boolean?.toVisibleOrInvisible()Context.dip(value: Int)
- Arguments
Start an Activity for given class T and allow to work on intent with "run" lambda function
<T : Fragment> T.withSerializable(vararg arguments: Pair<String, Serializable>)<T : Fragment> T.withParcelable(vararg arguments: Pair<String, Parcelable>): T
Retrieve property from intent
<T : Any> AppCompatActivity.argument(key: String) : T<T : Any> AppCompatActivity.argument(key: String, defaultValue: T? = null) : T<T : Any> AppCompatActivity.argumentNotNull(key: String, defaultValue: T) : T<T : Any> Fragment.argument(key: String) : T<T : Any> Fragment.argument(key: String, defaultValue: T? = null) : T<T : Any> Fragment.argumentNotNull(key: String, defaultValue: T) : T
- ConfigUtils
Configuration for resources locale
Context.updateResourcesLocale(locale: Locale): ContextContext.updateResourcesLocaleLegacy(locale: Locale): ContextContext.updateBaseContextLocale(locale: Locale): ContextContext.updateResourcesLocale(body: Configuration.() -> Unit): ContextContext.updateBaseContextLocaleWithoutChange(locale: Locale): Context
Copyright 2021 MNC Innovation Center
Proprietary license