Skip to content

Commit

Permalink
Small changes and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
siarhei-luskanau committed Oct 1, 2024
1 parent 0f2cdac commit 9b67f68
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ buildscript {
dependencies {
classpath(libs.android.gradle.plugin)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.androidx.navigation.safeArgsGradlePlugin)
}
}

plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.navigation.safeargs.kotlin).apply(false)
}

allprojects {
Expand Down
13 changes: 0 additions & 13 deletions buildSrc/build.gradle.kts

This file was deleted.

13 changes: 13 additions & 0 deletions convention-plugin-android-library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`kotlin-dsl`
}

repositories {
google()
mavenCentral()
}

dependencies {
implementation(libs.android.gradle.plugin)
implementation(libs.kotlin.gradle.plugin)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencyResolutionManagement {
versionCatalogs {
create("buildSrcLibs") {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion dialog-fragment/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
androidApplicationConvention
id("androidApplicationConvention")
}

android {
Expand Down
8 changes: 2 additions & 6 deletions dialog-fragment/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@drawable/ic_android"
android:label="DialogFragment"
android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar">

<activity
android:name="siarhei.luskanau.example.dialogfragment.AppActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FragmentWithId :
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = FragmentWithIdBinding.inflate(inflater, container, false)
): View = FragmentWithIdBinding.inflate(inflater, container, false)
.also { binding ->
binding.fragmentWithIdDialogButton.setOnClickListener {
AppDialogFragment.Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FragmentWithTag :
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = FragmentWithTagBinding.inflate(inflater, container, false)
): View = FragmentWithTagBinding.inflate(inflater, container, false)
.also { binding ->
binding.fragmentWithTagDialogButton.setOnClickListener {
AppDialogFragment.Builder(
Expand Down
4 changes: 1 addition & 3 deletions fileprovider-camera/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
androidApplicationConvention
id("androidApplicationConvention")
}

android {
Expand All @@ -8,7 +8,6 @@ android {
applicationId = "siarhei.luskanau.example.camera.app"
versionCode = 1
versionName = "1.0"
vectorDrawables.useSupportLibrary = true
}

buildTypes {
Expand All @@ -35,7 +34,6 @@ android {

dependencies {
implementation(project(":fileprovider-camera:camera"))

implementation(libs.android.material)
implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.fragment.ktx)
Expand Down
11 changes: 3 additions & 8 deletions fileprovider-camera/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@drawable/ic_android_24dp"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar">

<activity
android:name="siarhei.luskanau.example.camera.app.MainActivity"
android:exported="true"
android:label="@string/app_name">
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
2 changes: 1 addition & 1 deletion fileprovider-camera/camera/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
androidLibraryConvention
id("androidLibraryConvention")
}

android {
Expand Down
2 changes: 1 addition & 1 deletion fonts/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
androidApplicationConvention
id("androidApplicationConvention")
}

android {
Expand Down
6 changes: 2 additions & 4 deletions fonts/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:icon="@drawable/ic_android"
android:label="@string/app_name"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar">

<activity
android:name="siarhei.luskanau.example.fonts.AppActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package siarhei.luskanau.example.fonts

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import siarhei.luskanau.example.fonts.databinding.ActivityAppBinding

class AppActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

ActivityAppBinding.inflate(LayoutInflater.from(this))
.also { binding ->
setContentView(binding.root)
}
}
}
class AppActivity : AppCompatActivity(R.layout.activity_app)
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref
androidx-core = { module = "androidx.core:core", version.ref = "androidx-core" }
androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "androidx-fragment" }
androidx-navigation-fragment-ktx = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidx-navigation" }
androidx-navigation-safeArgsGradlePlugin = { module = "androidx.navigation:navigation-safe-args-gradle-plugin", version.ref = "androidx-navigation" }
androidx-navigation-ui-ktx = { module = "androidx.navigation:navigation-ui-ktx", version.ref = "androidx-navigation" }
androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "androidx-work" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -32,3 +31,4 @@ timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
navigation-safeargs-kotlin = { id = "androidx.navigation.safeargs.kotlin", version.ref = "androidx-navigation" }
4 changes: 2 additions & 2 deletions navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
androidApplicationConvention
id("androidx.navigation.safeargs.kotlin")
id("androidApplicationConvention")
alias(libs.plugins.navigation.safeargs.kotlin)
}

android {
Expand Down
6 changes: 2 additions & 4 deletions navigation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:icon="@drawable/ic_android"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">
android:theme="@style/AppTheme">

<activity
android:name="siarhei.luskanau.example.navigation.AppActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Feature1Fragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val binding = FragmentFeature1Binding.inflate(inflater, container, false)

return binding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Feature2DetailFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val binding = FragmentFeature2DetailBinding.inflate(inflater, container, false)

val args = Feature2DetailFragmentArgs.fromBundle(arguments ?: Bundle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Feature2ListFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val binding = FragmentFeature2ListBinding.inflate(inflater, container, false)

binding.feature2DetailListItem.setOnClickListener {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pluginManagement {
includeBuild("convention-plugin-android-library")
repositories {
google()
gradlePluginPortal()
Expand All @@ -10,7 +11,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}

Expand Down
4 changes: 2 additions & 2 deletions workmanager/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
androidApplicationConvention
id("androidx.navigation.safeargs.kotlin")
id("androidApplicationConvention")
alias(libs.plugins.navigation.safeargs.kotlin)
}

android {
Expand Down
7 changes: 2 additions & 5 deletions workmanager/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name="siarhei.luskanau.example.workmanager.AppApplication"
android:allowBackup="false"
android:icon="@drawable/ic_android"
android:label="WorkManager"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
tools:ignore="GoogleAppIndexingWarning">
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">

<activity
android:name="siarhei.luskanau.example.workmanager.AppActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class AppActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding =
ActivityAppBinding.inflate(LayoutInflater.from(this)).also { binding ->
setContentView(binding.root)
}
val binding = ActivityAppBinding.inflate(LayoutInflater.from(this))
.also { binding -> setContentView(binding.root) }

navController = Navigation.findNavController(this, R.id.navHostFragment)
appBarConfiguration = AppBarConfiguration(navController.graph, binding.drawerLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class BaseBeginCancelWorkFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val binding = FragmentBeginCancelWorkBinding.inflate(inflater, container, false)

binding.beginWorkButton.setOnClickListener { onBeginButtonPressed() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout.VERTICAL
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import kotlinx.coroutines.launch
import siarhei.luskanau.example.workmanager.databinding.FragmentWorkManagerMonitorBinding

class WorkManagerMonitorFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
val binding = FragmentWorkManagerMonitorBinding.inflate(inflater, container, false)

val adapter = WorkInfoAdapter()
Expand All @@ -30,9 +33,14 @@ class WorkManagerMonitorFragment : Fragment() {
)

val workManagerMonitorViewModel =
ViewModelProvider(this).get(WorkManagerMonitorViewModel::class.java)
workManagerMonitorViewModel.getWorkStatusListLiveData(requireContext())
.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
ViewModelProvider(this)[WorkManagerMonitorViewModel::class.java]
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
workManagerMonitorViewModel.getWorkStatusListFlow(binding.root.context).collect {
adapter.submitList(it)
}
}
}

return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package siarhei.luskanau.example.workmanager.monitor

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.work.WorkInfo
import androidx.work.WorkManager
import kotlinx.coroutines.flow.Flow

class WorkManagerMonitorViewModel : ViewModel() {
fun getWorkStatusListLiveData(context: Context): LiveData<List<WorkInfo>> =
WorkManager.getInstance(context).getWorkInfosByTagLiveData(WorkManagerConstants.TAG_ALL)
fun getWorkStatusListFlow(context: Context): Flow<List<WorkInfo>> =
WorkManager.getInstance(context).getWorkInfosByTagFlow(WorkManagerConstants.TAG_ALL)
}

0 comments on commit 9b67f68

Please sign in to comment.