Skip to content

Commit

Permalink
⚡️ :: Main_Setting
Browse files Browse the repository at this point in the history
main setting
  • Loading branch information
bhindor committed Jan 30, 2023
1 parent c341edd commit daeceb5
Show file tree
Hide file tree
Showing 24 changed files with 479 additions and 36 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath(Google.HILT_ANDROID_PLUGIN)
}
}

plugins {
id(Plugin.application).version(Version.ANDROID).apply(false)
id(Plugin.library).version(Version.ANDROID).apply(false)
Expand Down
50 changes: 28 additions & 22 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
object Versions {

// AndroidX
const val APP_COMPAT = "1.4.1"
const val MATERIAL = "1.5.0"
const val CONSTRAINT_LAYOUT = "2.1.3"

// KTX
const val CORE = "1.7.0"

// TEST
const val JUNIT = "1.1.3"

// Android Test
const val ESPRESSO_CORE = "3.4.0"
object Kotlin {
const val COROUTINES_CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Version.KOTLINX_COROUTINES}"
const val COROUTINES_ANDROID = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Version.KOTLINX_COROUTINES}"
}

object Libraries {

object AndroidX {
const val APP_COMPAT = "androidx.appcompat:appcompat:${Versions.APP_COMPAT}"
const val MATERIAL = "com.google.android.material:material:${Versions.MATERIAL}"
const val CONSTRAINT_LAYOUT = "androidx.constraintlayout:constraintlayout:${Versions.CONSTRAINT_LAYOUT}"
const val APP_COMPAT = "androidx.appcompat:appcompat:${Version.APP_COMPAT}"
const val MATERIAL = "com.google.android.material:material:${Version.MATERIAL}"
const val CONSTRAINT_LAYOUT = "androidx.constraintlayout:constraintlayout:${Version.CONSTRAINT_LAYOUT}"

const val NAVIGATION = "androidx.navigation:navigation-fragment-ktx:${Version.NAVIGATION}"
const val NAVIGATION_UI_KTX = "androidx.navigation:navigation-ui-ktx:${Version.NAVIGATION}"

const val RUNTIME = "androidx.lifecycle:lifecycle-runtime-ktx:${Version.RUNTIME}"
const val VIEWMODEL = "androidx.lifecycle:lifecycle-viewmodel:${Version.VIEWMODEL}"
const val VIEWMODEL_KTX = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Version.VIEWMODEL}"
const val FRAGMENT_KTX = "androidx.fragment:fragment-ktx:${Version.FRAGMENT}"

const val ROOM_RUNTIME = "androidx.room:room-runtime:${Version.ROOM}"
const val ROOM_KTX = "androidx.room:room-ktx:${Version.ROOM}"
const val ROOM_COMPILER = "androidx.room:room-compiler:${Version.ROOM}"
}

object KTX {
const val CORE = "androidx.core:core-ktx:${Versions.CORE}"
const val CORE = "androidx.core:core-ktx:${Version.CORE}"
}

object Test {
const val JUNIT = "androidx.test.ext:junit:${Versions.JUNIT}"
const val JUNIT = "androidx.test.ext:junit:${Version.JUNIT}"
}

object AndroidTest {
const val ESPRESSO_CORE = "androidx.test.espresso:espresso-core:${Versions.ESPRESSO_CORE}"
const val ESPRESSO_CORE = "androidx.test.espresso:espresso-core:${Version.ESPRESSO_CORE}"
}

}

object Google {
const val HILT_ANDROID = "com.google.dagger:hilt-android:${Version.HILT}"
const val HILT_ANDROID_COMPILER = "com.google.dagger:hilt-android-compiler:${Version.HILT}"
const val HILT_ANDROID_PLUGIN = "com.google.dagger:hilt-android-gradle-plugin:${Version.HILT}"
const val MATERIAL = "com.google.android.material:material:${Version.MATERIAL}"
}
8 changes: 7 additions & 1 deletion buildSrc/src/main/java/Plugin.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
object Plugin {
const val application = "com.android.application"
const val kotlin = "kotlin-android"
const val library = "com.android.library"

const val kotlin = "kotlin-android"
const val kotlinKapt = "kotlin-kapt"
const val kotlinParcelize = "kotlin-parcelize"
const val daggerPlugin = "dagger.hilt.android.plugin"

const val jetbrains = "org.jetbrains.kotlin.android"
const val jetbrainsJvm = "org.jetbrains.kotlin.jvm"

}
25 changes: 25 additions & 0 deletions buildSrc/src/main/java/Version.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
object Version {
// const val ANDROID = "8.0.0-alpha11"
// const val JETBRAINS = "1.8.0"
const val KOTLINX_COROUTINES = "1.6.0"
// AndroidX
const val APP_COMPAT = "1.4.1"
const val MATERIAL = "1.5.0"
const val CONSTRAINT_LAYOUT = "2.1.3"

// KTX
const val CORE = "1.7.0"

// TEST
const val JUNIT = "1.1.3"

// Android Test
const val ESPRESSO_CORE = "3.4.0"

const val ANDROID = "7.4.0"
const val JETBRAINS = "1.7.21"

const val NAVIGATION = "2.4.2"

const val FRAGMENT = "1.5.5"

const val ROOM = "2.4.3"
const val RUNTIME = "2.5.1"
const val VIEWMODEL = "2.5.1"

const val HILT = "2.44"
}
29 changes: 29 additions & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
id(Plugin.application)
id(Plugin.kotlin)
id(Plugin.kotlinKapt)
id(Plugin.kotlinParcelize)
id(Plugin.daggerPlugin)
}

android {
Expand All @@ -27,6 +30,9 @@ android {
sourceCompatibility = AppConfig.javaVersion
targetCompatibility = AppConfig.javaVersion
}
buildFeatures {
dataBinding = true
}
kotlinOptions {
jvmTarget = AppConfig.jvmTarget
}
Expand All @@ -48,6 +54,29 @@ dependencies {
// AndroidTest
androidTestImplementation(Libraries.AndroidTest.ESPRESSO_CORE)

// navigation
implementation(Libraries.AndroidX.NAVIGATION)
implementation(Libraries.AndroidX.NAVIGATION_UI_KTX)

// coroutine
implementation(Kotlin.COROUTINES_ANDROID)
implementation(Kotlin.COROUTINES_CORE)

// room
implementation(Libraries.AndroidX.ROOM_RUNTIME)
kapt(Libraries.AndroidX.ROOM_COMPILER)
implementation(Libraries.AndroidX.ROOM_KTX)

implementation(Libraries.AndroidX.RUNTIME)

implementation(Libraries.AndroidX.VIEWMODEL)
implementation(Libraries.AndroidX.VIEWMODEL_KTX)
implementation(Libraries.AndroidX.FRAGMENT_KTX)

// hilt
implementation(Google.HILT_ANDROID)
kapt(Google.HILT_ANDROID_COMPILER)

implementation(project(AppConfig.domain))
implementation(project(AppConfig.data))
}
4 changes: 4 additions & 0 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".utils.DasarangApplication"
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
Expand Down
35 changes: 35 additions & 0 deletions presentation/src/main/java/co/dasa/dasarang/base/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package co.dasa.dasarang.base

import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import co.dasa.dasarang.BR

abstract class BaseActivity<B : ViewDataBinding, VM : BaseViewModel>(
@LayoutRes private val layoutRes: Int
) : AppCompatActivity() {

protected lateinit var binding: B
protected abstract val viewModel: VM

protected abstract fun start()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
prepareDataBinding()
start()
}

private fun prepareDataBinding() {
binding = DataBindingUtil.setContentView(this, layoutRes)
binding.setVariable(BR.vm, viewModel)
binding.lifecycleOwner = this
binding.executePendingBindings()
}

override fun onDestroy() {
super.onDestroy()
if (::binding.isInitialized) binding.unbind()
}
}
50 changes: 50 additions & 0 deletions presentation/src/main/java/co/dasa/dasarang/base/BaseFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package co.dasa.dasarang.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import co.dasa.dasarang.features.main.activity.MainActivity
import co.dasa.dasarang.BR

abstract class BaseFragment<B : ViewDataBinding, VM : BaseViewModel>(
@LayoutRes private val layoutRes: Int
) : Fragment() {

protected lateinit var binding: B
protected abstract val viewModel: VM
protected open val hasBottomNavigation: Boolean = false

protected abstract fun start()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
prepareDataBinding()
(activity as? MainActivity)?.setNavVisible(hasBottomNavigation)
start()
}

private fun prepareDataBinding() {
binding.setVariable(BR.vm, viewModel)
binding.lifecycleOwner = this
binding.executePendingBindings()
}

override fun onDestroy() {
super.onDestroy()
if (::binding.isInitialized) binding.unbind()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package co.dasa.dasarang.base

import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView

abstract class BaseListAdapter<T, B : ViewDataBinding>(
@LayoutRes private val itemLayoutRes: Int,
diffUtil: DiffUtil.ItemCallback<T>
) : ListAdapter<T, BaseListAdapter<T, B>.BaseViewHolder>(diffUtil) {

abstract fun action(item: T, binding: B)

inner class BaseViewHolder(private val binding: B) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: T) {
action(item, binding)
}
}

override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
return holder.bind(getItem(position))
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package co.dasa.dasarang.extensions

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

fun LifecycleOwner.repeatOnStarted(block: suspend CoroutineScope.() -> Unit) = lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED, block)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@ package co.dasa.dasarang.features.main.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import co.dasa.dasarang.R
import co.dasa.dasarang.base.BaseActivity
import co.dasa.dasarang.databinding.ActivityMainBinding
import co.dasa.dasarang.features.main.viewmodel.MainViewModel
import dagger.hilt.android.AndroidEntryPoint

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(R.layout.activity_main) {

override val viewModel: MainViewModel by viewModels()
private lateinit var navController: NavController

override fun start() {
setNavigation()
}

private fun setNavigation() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fcv_main) as NavHostFragment
navController = navHostFragment.navController
binding.bnvMain.setupWithNavController(navController)
}

fun setNavVisible(demand: Boolean) {
binding.bnvMain.visibility = if (demand) View.VISIBLE else View.GONE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package co.dasa.dasarang.features.plaza.fragment

import android.widget.Toast
import androidx.fragment.app.viewModels
import co.dasa.dasarang.R
import co.dasa.dasarang.base.BaseFragment
import co.dasa.dasarang.databinding.FragmentPlazaBinding
import co.dasa.dasarang.extensions.repeatOnStarted
import co.dasa.dasarang.features.plaza.viewmodel.PlazaViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class PlazaFragment : BaseFragment<FragmentPlazaBinding, PlazaViewModel>(R.layout.fragment_plaza) {

override val viewModel: PlazaViewModel by viewModels()
override val hasBottomNavigation: Boolean = true

override fun start() {
repeatOnStarted {
viewModel.eventFlow.collect { event -> handleEvent(event) }
}
}

private fun handleEvent(event: PlazaViewModel.Event) {
when (event) {
is PlazaViewModel.Event.ShowToast -> Toast.makeText(requireContext(), event.text, Toast.LENGTH_SHORT).show()
}
}
}
Loading

0 comments on commit daeceb5

Please sign in to comment.