Skip to content

Commit e15cd46

Browse files
authored
Code tidy up
• update to latest libs • remove unused images • switch to kotlin short formats • clean up compiler warnings
1 parent 8ae0bda commit e15cd46

34 files changed

+47
-269
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ dependencies {
8787
implementation "com.android.support:appcompat-v7:$supportLibrary"
8888
implementation "com.android.support:design:$supportLibrary"
8989
implementation "com.android.support.constraint:constraint-layout:1.0.2"
90-
implementation "com.squareup.okhttp3:okhttp:3.9.0"
90+
implementation "com.squareup.okhttp3:okhttp:3.9.1"
9191
implementation "com.squareup.retrofit2:retrofit:$retrofit"
9292
implementation "com.squareup.retrofit2:converter-moshi:$retrofit"
9393
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
94-
implementation "io.reactivex.rxjava2:rxjava:2.1.6"
94+
implementation "io.reactivex.rxjava2:rxjava:2.1.7"
9595
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
9696
implementation "com.jakewharton.timber:timber:4.6.0"
9797
implementation "android.arch.lifecycle:extensions:$architectureComponents"

app/lint.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<lint>
3+
<issue id="IconColors">
4+
<ignore path="src/main/res/drawable*/privacy_icon_unknown.*" />
5+
</issue>
6+
<issue id="IconExpectedSize">
7+
<ignore path="src/main/res/drawable-*/privacy_icon_unknown.*" />
8+
</issue>
9+
</lint>

app/src/androidTest/java/com/duckduckgo/app/privacydashboard/PrivacyDashboardViewModelTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class PrivacyDashboardViewModelTest {
109109
assertEquals("10 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
110110
}
111111

112-
private fun getStringResource(id: Int): String {
113-
return InstrumentationRegistry.getTargetContext().getString(id)
114-
}
112+
private fun getStringResource(id: Int): String =
113+
InstrumentationRegistry.getTargetContext().getString(id)
115114
}

app/src/androidTest/java/com/duckduckgo/app/trackerdetection/AdBlockClientInstrumentationTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class AdBlockClientInstrumentationTest {
6666
assertFalse(testee.matches(nonTrackerUrl, documentUrl, resourceType))
6767
}
6868

69-
private fun data(): ByteArray {
70-
return javaClass.classLoader.getResource("binary/easylist_sample").readBytes()
71-
}
69+
private fun data(): ByteArray =
70+
javaClass.classLoader.getResource("binary/easylist_sample").readBytes()
7271
}

app/src/main/java/com/duckduckgo/app/browser/BrowserWebViewClient.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ class BrowserWebViewClient @Inject constructor(
9191
return false
9292
}
9393

94-
private fun WebView.elementClicked(): String? {
95-
return safeHitTestResult().extra
96-
}
94+
private fun WebView.elementClicked(): String? = safeHitTestResult().extra
9795

9896
/**
9997
* Access the webview hit test result from any thread; jumps onto the main thread to achieve this

app/src/main/java/com/duckduckgo/app/browser/omnibar/QueryUrlConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class QueryUrlConverter @Inject constructor(private val requestRewriter: DuckDuc
6464
}
6565

6666
override fun convertUri(input: String): String {
67-
var uri = Uri.parse(input).withScheme()
67+
val uri = Uri.parse(input).withScheme()
6868

6969
if (uri.host == baseUrl) {
7070
return requestRewriter.rewriteRequestWithCustomQueryParams(uri).toString()

app/src/main/java/com/duckduckgo/app/di/NetworkModule.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class NetworkModule {
4242

4343
@Provides
4444
@Singleton
45-
fun moshi(): Moshi {
46-
return Moshi.Builder().add(DisconnectJsonAdapter()).build()
47-
}
45+
fun moshi(): Moshi = Moshi.Builder().add(DisconnectJsonAdapter()).build()
4846

4947
@Provides
5048
@Singleton
@@ -58,7 +56,6 @@ class NetworkModule {
5856
}
5957

6058
@Provides
61-
fun trackerListService(retrofit: Retrofit): TrackerListService {
62-
return retrofit.create(TrackerListService::class.java)
63-
}
59+
fun trackerListService(retrofit: Retrofit): TrackerListService =
60+
retrofit.create(TrackerListService::class.java)
6461
}

app/src/main/java/com/duckduckgo/app/privacydashboard/PrivacyDashboardViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import com.duckduckgo.app.privacymonitor.HttpsStatus
2525
import com.duckduckgo.app.privacymonitor.PrivacyMonitor
2626
import javax.inject.Inject
2727

28-
29-
class PrivacyDashboardViewModel @Inject constructor(@SuppressLint("StaticFieldLeak") private val context: Context) : ViewModel() {
28+
@SuppressLint("StaticFieldLeak")
29+
class PrivacyDashboardViewModel @Inject constructor(private val context: Context) : ViewModel() {
3030

3131
data class ViewState(
3232
val domain: String,

app/src/main/java/com/duckduckgo/app/trackerdetection/AdBlockClient.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ import com.duckduckgo.app.trackerdetection.model.ResourceType
2121
import timber.log.Timber
2222

2323

24-
class AdBlockClient : Client {
24+
class AdBlockClient(override val name: ClientName) : Client {
2525

26-
override val name: ClientName
2726
private val nativeClientPointer: Long
2827
private var rawDataPointer: Long
2928
private var processedDataPointer: Long
3029

3130
init {
3231
System.loadLibrary("adblockclient-lib")
33-
}
34-
35-
constructor(name: ClientName) {
36-
this.name = name
3732
nativeClientPointer = createClient()
3833
rawDataPointer = 0
3934
processedDataPointer = 0
@@ -59,15 +54,12 @@ class AdBlockClient : Client {
5954

6055
private external fun loadProcessedData(clientPointer: Long, data: ByteArray): Long
6156

62-
fun getProcessedData(): ByteArray {
63-
return getProcessedData(nativeClientPointer)
64-
}
57+
fun getProcessedData(): ByteArray = getProcessedData(nativeClientPointer)
6558

6659
private external fun getProcessedData(clientPointer: Long): ByteArray
6760

68-
override fun matches(url: String, documentUrl: String, resourceType: ResourceType): Boolean {
69-
return matches(nativeClientPointer, url, documentUrl, resourceType.filterOption)
70-
}
61+
override fun matches(url: String, documentUrl: String, resourceType: ResourceType): Boolean =
62+
matches(nativeClientPointer, url, documentUrl, resourceType.filterOption)
7163

7264
private external fun matches(clientPointer: Long, url: String, documentUrl: String, filterOption: Int): Boolean
7365

app/src/main/java/com/duckduckgo/app/trackerdetection/DisconnectClient.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class DisconnectClient(override val name: Client.ClientName, private val tracker
2828
.any { sameOrSubdomain(url, it.url) }
2929
}
3030

31-
private fun bannedCategories(): List<String> {
32-
return listOf("Analytics", "Advertising", "Social")
33-
}
31+
private fun bannedCategories(): List<String> = listOf("Analytics", "Advertising", "Social")
3432

3533
}

0 commit comments

Comments
 (0)