Skip to content

[WIP] Use Spotless for Kotlin formatting #6420

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

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 1
ij_kotlin_wrap_first_method_in_call_chain = false
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_filename = disabled
ktlint_standard_package-name = disabled
ktlint_standard_annotation = disabled
1 change: 0 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
#!/bin/bash
echo "Running spotless check"
./gradlew spotlessApply
./gradlew formatKotlin
git add `git diff --name-only --cached`
exit 0
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [actionlint] reported by reviewdog 🐶
shellcheck reported issue in this script: SC2002:style:1:5: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead [shellcheck]

run: cat build/fladle/fladleResults/HtmlErrorReport.html | cut -d\` -f2 >> results.json

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # required due to setting Spotless ratchetFrom
submodules: recursive

- name: Set up JDK version
Expand All @@ -39,7 +40,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3

- name: Run Code Formatting Checks
run: ./gradlew code_format_checks
run: ./gradlew spotlessCheck

unit_tests:
name: Unit tests
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # required due to setting Spotless ratchetFrom
submodules: recursive

- name: Set up JDK version
Expand All @@ -30,7 +31,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3

- name: Run Code Formatting Checks
run: ./gradlew code_format_checks
run: ./gradlew spotlessCheck

unit_tests:
name: Unit tests
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ captures/

# Intellij
*.iml
.idea/
.idea/workspace.xml
.idea/*
!.idea/icon.svg
!.idea/copyright/
.idea/workspace.xml

# Keystore files
*.jks
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ If your PR is failing because of that, please make sure that you follow our [sty
You can also trigger an automatic code formatting of the code by executing:

```
./gradleW code_format_checks
./gradleW formatKotlin
./gradleW app:spotlessApply
```
4 changes: 2 additions & 2 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

### Code formatting

You can check the code formatting correctness by running `./gradleW code_format_checks`.
To adhere to codestyle, please run `./gradleW formatKotlin` and `./gradleW spotlessApply` to autoformat in order to fix any CI issues.
You can check the code formatting correctness by running `./gradleW spotlessCheck`.
To adhere to codestyle, please run `./gradleW spotlessApply` to autoformat and fix any CI issues.

If you want to do this automatically upon commit we recommend the existing [pre-commit hook](.githooks/pre-commit):
- Pull develop branch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:screenOrientation="portrait" />

<activity
android:name="com.duckduckgo.mobile.android.vpn.ui.report.DeviceShieldAppTrackersInfo"
android:name="com.duckduckgo.mobile.android.vpn.ui.privacyreport.DeviceShieldAppTrackersInfo"
android:exported="false"
android:label="@string/atp_ProfilingActivityTitle"
android:parentActivityName="com.duckduckgo.mobile.android.vpn.ui.tracker_activity.DeviceShieldTrackerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,25 @@ import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnRunningState.ENABLED
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnStopReason.REVOKED
import com.duckduckgo.mobile.android.vpn.ui.onboarding.VpnStore
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel.PrivacyReportView.TrackersBlocked
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel.PrivacyReportView.ViewState
import com.duckduckgo.mobile.android.vpn.ui.privacyreport.PrivacyReportViewModel
import com.duckduckgo.mobile.android.vpn.ui.privacyreport.PrivacyReportViewModel.PrivacyReportView.TrackersBlocked
import com.duckduckgo.mobile.android.vpn.ui.privacyreport.PrivacyReportViewModel.PrivacyReportView.ViewState
import com.duckduckgo.mobile.android.vpn.ui.tracker_activity.DeviceShieldTrackerActivity
import com.duckduckgo.newtabpage.api.NewTabPageSection
import com.duckduckgo.newtabpage.api.NewTabPageSectionPlugin
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject

@InjectWith(ViewScope::class)
class AppTrackingProtectionStateView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
) : FrameLayout(context, attrs, defStyle) {

override fun getTag(): String {
return "AppTP"
}
override fun getTag(): String = "AppTP"

@Inject
lateinit var deviceShieldPixels: DeviceShieldPixels
Expand All @@ -83,9 +80,10 @@ class AppTrackingProtectionStateView @JvmOverloads constructor(
AndroidSupportInjection.inject(this)
super.onAttachedToWindow()

conflatedJob += viewModel.viewStateFlow
.onEach { viewState -> renderViewState(viewState) }
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)
conflatedJob +=
viewModel.viewStateFlow
.onEach { viewState -> renderViewState(viewState) }
.launchIn(findViewTreeLifecycleOwner()?.lifecycleScope!!)

deviceShieldPixels.didShowNewTabSummary()

Expand Down Expand Up @@ -141,49 +139,56 @@ class AppTrackingProtectionStateView @JvmOverloads constructor(
val lastTrackingApp = trackerBlocked.latestApp
val otherApps = trackerBlocked.otherAppsSize

val textToStyle = if (trackersBlocked == 1) {
when (otherApps) {
0 -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeZeroOtherApps,
trackersBlocked,
lastTrackingApp,
)

1 -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeOneOtherApp,
trackersBlocked,
lastTrackingApp,
)

else -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeMoreOtherApps,
trackersBlocked,
lastTrackingApp,
otherApps,
)
val textToStyle =
if (trackersBlocked == 1) {
when (otherApps) {
0 ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeZeroOtherApps,
trackersBlocked,
lastTrackingApp,
)

1 ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeOneOtherApp,
trackersBlocked,
lastTrackingApp,
)

else ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOneTimeMoreOtherApps,
trackersBlocked,
lastTrackingApp,
otherApps,
)
}
} else {
when (otherApps) {
0 ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesZeroOtherApps,
trackersBlocked,
lastTrackingApp,
)

1 ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesOneOtherApp,
trackersBlocked,
lastTrackingApp,
)

else ->
resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesMoreOtherApps,
trackersBlocked,
lastTrackingApp,
otherApps,
)
}
}
} else {
when (otherApps) {
0 -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesZeroOtherApps,
trackersBlocked,
lastTrackingApp,
)

1 -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesOneOtherApp,
trackersBlocked,
lastTrackingApp,
)

else -> resources.getString(
R.string.atp_DailyLastCompanyBlockedHomeTabOtherTimesMoreOtherApps,
trackersBlocked,
lastTrackingApp,
otherApps,
)
}
}

binding.deviceShieldCtaHeader.text = HtmlCompat.fromHtml(textToStyle, HtmlCompat.FROM_HTML_MODE_LEGACY)
binding.deviceShieldCtaImage.setImageResource(R.drawable.ic_apptp_default)
Expand All @@ -202,9 +207,7 @@ class AppTrackingProtectionNewTabPageSectionPlugin @Inject constructor(
) : NewTabPageSectionPlugin {
override val name = NewTabPageSection.APP_TRACKING_PROTECTION.name

override fun getView(context: Context): View {
return AppTrackingProtectionStateView(context)
}
override fun getView(context: Context): View = AppTrackingProtectionStateView(context)

override suspend fun isUserEnabled(): Boolean {
if (vpnFeatureRemover.isFeatureRemoved()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 DuckDuckGo
* Copyright (c) 2025 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.duckduckgo.mobile.android.vpn.ui.report
package com.duckduckgo.mobile.android.vpn.ui.privacyreport

import android.content.Context
import android.content.Intent
Expand All @@ -29,7 +29,6 @@ import javax.inject.Inject

@InjectWith(ActivityScope::class)
class DeviceShieldAppTrackersInfo : DuckDuckGoActivity() {

@Inject
lateinit var deviceShieldPixels: DeviceShieldPixels

Expand All @@ -55,9 +54,6 @@ class DeviceShieldAppTrackersInfo : DuckDuckGoActivity() {
}

companion object {

internal fun intent(context: Context): Intent {
return Intent(context, DeviceShieldAppTrackersInfo::class.java)
}
internal fun intent(context: Context): Intent = Intent(context, DeviceShieldAppTrackersInfo::class.java)
}
}
Loading
Loading