Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Spotless and ktlint - Code style rule changes #1002

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/blueprints.yaml
Expand Up @@ -22,10 +22,10 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17

- uses: actions/cache@v2
with:
Expand Down
21 changes: 11 additions & 10 deletions app/build.gradle.kts
Expand Up @@ -17,7 +17,6 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kapt)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
}
Expand Down Expand Up @@ -78,25 +77,27 @@ android {

buildFeatures {
compose = true
buildConfig = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}

packagingOptions {
excludes += "META-INF/AL2.0"
excludes += "META-INF/LGPL2.1"
packaging {
jniLibs.excludes += "META-INF/AL2.0"
jniLibs.excludes += "META-INF/LGPL2.1"
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get()
}
namespace = "com.example.android.architecture.blueprints.todoapp"

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
Expand Down Expand Up @@ -128,7 +129,7 @@ dependencies {
// Hilt
implementation(libs.hilt.android.core)
implementation(libs.androidx.hilt.navigation.compose)
kapt(libs.hilt.compiler)
ksp(libs.hilt.compiler)

// Jetpack Compose
val composeBom = platform(libs.androidx.compose.bom)
Expand Down Expand Up @@ -166,7 +167,7 @@ dependencies {

// JVM tests - Hilt
testImplementation(libs.hilt.android.testing)
kaptTest(libs.hilt.compiler)
kspTest(libs.hilt.compiler)

// Dependencies for Android unit tests
androidTestImplementation(composeBom)
Expand Down Expand Up @@ -196,5 +197,5 @@ dependencies {

// AndroidX Test - Hilt testing
androidTestImplementation(libs.hilt.android.testing)
kaptAndroidTest(libs.hilt.compiler)
kspAndroidTest(libs.hilt.compiler)
}
Expand Up @@ -76,7 +76,7 @@ class AddEditTaskScreenTest {
viewModel = AddEditTaskViewModel(repository, SavedStateHandle()),
topBarTitle = R.string.add_task,
onTaskUpdate = { },
onBack = { },
onBack = { }
)
}
}
Expand Down
Expand Up @@ -45,14 +45,15 @@ class TaskDaoTest {
ToDoDatabase::class.java
).allowMainThreadQueries().build()
}

@Test
fun insertTaskAndGetById() = runTest {
// GIVEN - insert a task
val task = LocalTask(
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)
database.taskDao().upsert(task)

Expand All @@ -74,7 +75,7 @@ class TaskDaoTest {
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)
database.taskDao().upsert(task)

Expand Down Expand Up @@ -102,7 +103,7 @@ class TaskDaoTest {
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)
database.taskDao().upsert(task)

Expand All @@ -124,7 +125,7 @@ class TaskDaoTest {
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)

database.taskDao().upsert(originalTask)
Expand Down Expand Up @@ -175,7 +176,7 @@ class TaskDaoTest {
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)
database.taskDao().upsert(task)

Expand All @@ -195,7 +196,7 @@ class TaskDaoTest {
title = "title",
description = "description",
id = "id",
isCompleted = false,
isCompleted = false
)
)

Expand Down
Expand Up @@ -109,7 +109,7 @@ class TaskDetailScreenTest {
),
onEditTask = { /*TODO*/ },
onBack = { },
onDeleteTask = { },
onDeleteTask = { }
)
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/debug/AndroidManifest.xml
Expand Up @@ -14,8 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.architecture.blueprints.todoapp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -14,8 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.architecture.blueprints.todoapp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="false"
Expand Down
Expand Up @@ -65,7 +65,10 @@ fun TodoNavGraph(
composable(
TodoDestinations.TASKS_ROUTE,
arguments = listOf(
navArgument(USER_MESSAGE_ARG) { type = NavType.IntType; defaultValue = 0 }
navArgument(USER_MESSAGE_ARG) {
type = NavType.IntType
defaultValue = 0
}
)
) { entry ->
AppModalDrawer(drawerState, currentRoute, navActions) {
Expand All @@ -87,7 +90,10 @@ fun TodoNavGraph(
TodoDestinations.ADD_EDIT_TASK_ROUTE,
arguments = listOf(
navArgument(TITLE_ARG) { type = NavType.IntType },
navArgument(TASK_ID_ARG) { type = NavType.StringType; nullable = true },
navArgument(TASK_ID_ARG) {
type = NavType.StringType
nullable = true
}
)
) { entry ->
val taskId = entry.arguments?.getString(TASK_ID_ARG)
Expand Down
Expand Up @@ -46,14 +46,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.example.android.architecture.blueprints.todoapp.R
import com.example.android.architecture.blueprints.todoapp.util.AddEditTaskTopAppBar
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState

@OptIn(ExperimentalLifecycleComposeApi::class)
@Composable
fun AddEditTaskScreen(
@StringRes topBarTitle: Int,
Expand Down Expand Up @@ -116,7 +114,7 @@ private fun AddEditTaskContent(
// Show the loading spinner—`loading` is `true` in this code path
state = rememberSwipeRefreshState(true),
onRefresh = { /* DO NOTHING */ },
content = { },
content = { }
)
} else {
Column(
Expand Down
Expand Up @@ -114,7 +114,7 @@ class AddEditTaskViewModel @Inject constructor(
taskRepository.updateTask(
taskId,
title = uiState.value.title,
description = uiState.value.description,
description = uiState.value.description
)
_uiState.update {
it.copy(isTaskSaved = true)
Expand Down
Expand Up @@ -22,7 +22,6 @@ import com.example.android.architecture.blueprints.todoapp.di.ApplicationScope
import com.example.android.architecture.blueprints.todoapp.di.DefaultDispatcher
import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
Expand All @@ -40,12 +39,11 @@ import kotlinx.coroutines.withContext
* @param scope - The coroutine scope used for deferred jobs where the result isn't important, such
* as sending data to the network.
*/
@Singleton
class DefaultTaskRepository @Inject constructor(
private val networkDataSource: NetworkDataSource,
private val localDataSource: TaskDao,
@DefaultDispatcher private val dispatcher: CoroutineDispatcher,
@ApplicationScope private val scope: CoroutineScope,
@ApplicationScope private val scope: CoroutineScope
) : TaskRepository {

override suspend fun createTask(title: String, description: String): String {
Expand All @@ -57,7 +55,7 @@ class DefaultTaskRepository @Inject constructor(
val task = Task(
title = title,
description = description,
id = taskId,
id = taskId
)
localDataSource.upsert(task.toLocal())
saveTasksToNetwork()
Expand Down
Expand Up @@ -39,7 +39,7 @@ fun Task.toLocal() = LocalTask(
id = id,
title = title,
description = description,
isCompleted = isCompleted,
isCompleted = isCompleted
)

fun List<Task>.toLocal() = map(Task::toLocal)
Expand All @@ -49,7 +49,7 @@ fun LocalTask.toExternal() = Task(
id = id,
title = title,
description = description,
isCompleted = isCompleted,
isCompleted = isCompleted
)

// Note: JvmName is used to provide a unique name for each extension function with the same name.
Expand All @@ -63,7 +63,7 @@ fun NetworkTask.toLocal() = LocalTask(
id = id,
title = title,
description = shortDescription,
isCompleted = (status == TaskStatus.COMPLETE),
isCompleted = (status == TaskStatus.COMPLETE)
)

@JvmName("networkToLocal")
Expand All @@ -74,7 +74,11 @@ fun LocalTask.toNetwork() = NetworkTask(
id = id,
title = title,
shortDescription = description,
status = if (isCompleted) { TaskStatus.COMPLETE } else { TaskStatus.ACTIVE }
status = if (isCompleted) {
TaskStatus.COMPLETE
} else {
TaskStatus.ACTIVE
}
)

fun List<LocalTask>.toNetwork() = map(LocalTask::toNetwork)
Expand Down
Expand Up @@ -31,7 +31,7 @@ data class Task(
val title: String = "",
val description: String = "",
val isCompleted: Boolean = false,
val id: String,
val id: String
) {

val titleForList: String
Expand Down
Expand Up @@ -33,5 +33,5 @@ data class LocalTask(
@PrimaryKey val id: String,
var title: String,
var description: String,
var isCompleted: Boolean,
var isCompleted: Boolean
)
Expand Up @@ -54,7 +54,6 @@ object CoroutinesModule {
@Provides
@Singleton
@ApplicationScope
fun providesCoroutineScope(
@DefaultDispatcher dispatcher: CoroutineDispatcher
): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
fun providesCoroutineScope(@DefaultDispatcher dispatcher: CoroutineDispatcher): CoroutineScope =
CoroutineScope(SupervisorJob() + dispatcher)
}
Expand Up @@ -34,14 +34,12 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.example.android.architecture.blueprints.todoapp.R
import com.example.android.architecture.blueprints.todoapp.util.LoadingContent
import com.example.android.architecture.blueprints.todoapp.util.StatisticsTopAppBar
import com.google.accompanist.appcompattheme.AppCompatTheme

@OptIn(ExperimentalLifecycleComposeApi::class)
@Composable
fun StatisticsScreen(
openDrawer: () -> Unit,
Expand Down
Expand Up @@ -66,23 +66,22 @@ class StatisticsViewModel @Inject constructor(
}
}

private fun produceStatisticsUiState(taskLoad: Async<List<Task>>) =
when (taskLoad) {
Async.Loading -> {
StatisticsUiState(isLoading = true, isEmpty = true)
}
is Async.Error -> {
// TODO: Show error message?
StatisticsUiState(isEmpty = true, isLoading = false)
}
is Async.Success -> {
val stats = getActiveAndCompletedStats(taskLoad.data)
StatisticsUiState(
isEmpty = taskLoad.data.isEmpty(),
activeTasksPercent = stats.activeTasksPercent,
completedTasksPercent = stats.completedTasksPercent,
isLoading = false
)
}
private fun produceStatisticsUiState(taskLoad: Async<List<Task>>) = when (taskLoad) {
Async.Loading -> {
StatisticsUiState(isLoading = true, isEmpty = true)
}
is Async.Error -> {
// TODO: Show error message?
StatisticsUiState(isEmpty = true, isLoading = false)
}
is Async.Success -> {
val stats = getActiveAndCompletedStats(taskLoad.data)
StatisticsUiState(
isEmpty = taskLoad.data.isEmpty(),
activeTasksPercent = stats.activeTasksPercent,
completedTasksPercent = stats.completedTasksPercent,
isLoading = false
)
}
}
}
Expand Up @@ -22,7 +22,6 @@ import com.example.android.architecture.blueprints.todoapp.data.Task
* Function that does some trivial computation. Used to showcase unit tests.
*/
internal fun getActiveAndCompletedStats(tasks: List<Task>): StatsResult {

return if (tasks.isEmpty()) {
StatsResult(0f, 0f)
} else {
Expand Down