Commit dbd0dd0a authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Lint cleanup

parent 267e7372
......@@ -24,6 +24,6 @@ abstract class AndroidSingleton<T> {
return newSingleton
}
abstract protected fun createInstance(context: Context): T
protected abstract fun createInstance(context: Context): T
}
\ No newline at end of file
......@@ -24,8 +24,8 @@ import at.bitfire.dav4jvm.UrlUtils
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.*
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.*
import at.bitfire.davdroid.model.Collection
import at.bitfire.davdroid.model.*
import at.bitfire.davdroid.settings.AccountSettings
import at.bitfire.davdroid.ui.DebugInfoActivity
import at.bitfire.davdroid.ui.NotificationUtils
......@@ -299,7 +299,7 @@ class DavService: IntentService("DavService") {
val itHomeSets = homeSets.iterator()
while (itHomeSets.hasNext()) {
val (homeSetUrl, homeSet) = itHomeSets.next()
Logger.log.fine("Listing home set ${homeSetUrl}")
Logger.log.fine("Listing home set $homeSetUrl")
try {
DavResource(httpClient, homeSetUrl).propfind(1, *DAV_COLLECTION_PROPERTIES) { response, relation ->
......
......@@ -45,7 +45,7 @@ object DavUtils {
fun lastSegmentOfUrl(url: HttpUrl): String {
// the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy
val segments = LinkedList<String>(url.pathSegments)
val segments = LinkedList(url.pathSegments)
segments.reverse()
return segments.firstOrNull { it.isNotEmpty() } ?: "/"
......
......@@ -27,7 +27,7 @@ class ForegroundService : Service() {
fun startIfEnabled(context: Context) {
if (isEnabled(context)) {
val serviceIntent = Intent(ForegroundService.ACTION_FOREGROUND, null, context, ForegroundService::class.java)
val serviceIntent = Intent(ACTION_FOREGROUND, null, context, ForegroundService::class.java)
if (Build.VERSION.SDK_INT >= 26)
context.startForegroundService(serviceIntent)
else
......
......@@ -171,11 +171,11 @@ class HttpClient private constructor(
}
fun build(): HttpClient {
val trustManager = certManager ?: {
val trustManager = certManager ?: run {
val factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
factory.init(null as KeyStore?)
factory.trustManagers.first() as X509TrustManager
}()
}
val hostnameVerifier = certManager?.hostnameVerifier(OkHostnameVerifier)
?: OkHostnameVerifier
......
......@@ -63,7 +63,7 @@ object PermissionUtils {
/**
* Whether this app declares the given permission (regardless of whether it has been granted or not).
*
* @param permisssion permission to check
* @param permission permission to check
*
* @return *true* if this app declares [permission] in the manifest; *false* otherwise
*/
......
......@@ -203,7 +203,7 @@ abstract class AppDatabase: RoomDatabase() {
val cols = cursor.columnCount
// print rows
while (cursor.moveToNext()) {
val values = Array<String?>(cols) { idx -> cursor.getStringOrNull(idx) }
val values = Array(cols) { idx -> cursor.getStringOrNull(idx) }
table.addLine(*values)
}
writer.append(table.toString())
......
......@@ -3,7 +3,6 @@ package at.bitfire.davdroid.model
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Update
import java.util.*
interface SyncableDao<T: IdEntity> {
......
......@@ -14,7 +14,6 @@ import android.os.RemoteException
import android.provider.ContactsContract
import android.provider.ContactsContract.CommonDataKinds.GroupMembership
import android.provider.ContactsContract.RawContacts.Data
import androidx.annotation.RequiresApi
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.UnknownProperties
......
......@@ -8,7 +8,6 @@
package at.bitfire.davdroid.resource
import android.content.ContentProviderOperation
import android.content.ContentUris
import android.content.ContentValues
import android.net.Uri
......
......@@ -153,8 +153,7 @@ class AccountSettings(
}
// repair calendar sync
settings.getSavedCalendarsSyncInterval()?.let { strInterval ->
val shouldBe = strInterval.toLong()
settings.getSavedCalendarsSyncInterval()?.let { shouldBe ->
val current = settings.getSyncInterval(CalendarContract.AUTHORITY)
if (current != shouldBe) {
Logger.log.warning("${account.name}: ${CalendarContract.AUTHORITY} sync interval should be $shouldBe but is $current -> setting to $current")
......@@ -164,8 +163,7 @@ class AccountSettings(
if (taskAuthority != null)
// repair calendar sync
settings.getSavedTasksSyncInterval()?.let { strInterval ->
val shouldBe = strInterval.toLong()
settings.getSavedTasksSyncInterval()?.let { shouldBe ->
val current = settings.getSyncInterval(taskAuthority)
if (current != shouldBe) {
Logger.log.warning("${account.name}: $taskAuthority sync interval should be $shouldBe but is $current -> setting to $current")
......@@ -249,7 +247,7 @@ class AccountSettings(
Logger.log.fine("Disabling automatic sync of $account/$authority")
ContentResolver.setSyncAutomatically(account, authority, false)
/* return */ ContentResolver.getSyncAutomatically(account, authority) == false
/* return */ !ContentResolver.getSyncAutomatically(account, authority)
}
} else {
{
......@@ -263,7 +261,7 @@ class AccountSettings(
}
// try up to 10 times with 100 ms pause
var success: Boolean = false
var success = false
for (idxTry in 0 until 10) {
success = setInterval()
if (success)
......
......@@ -124,7 +124,7 @@ class AboutActivity: AppCompatActivity() {
private val binding get() = _binding!!
val model by viewModels<TextFileModel>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = AboutBinding.inflate(inflater, container, false)
return binding.root
}
......@@ -268,9 +268,9 @@ class AboutActivity: AppCompatActivity() {
// sort translations by localized language name
val collator = Collator.getInstance()
result.sortWith({
o1, o2 -> collator.compare(o1.language, o2.language)
})
result.sortWith { o1, o2 ->
collator.compare(o1.language, o2.language)
}
postValue(result)
}
......
......@@ -240,9 +240,9 @@ class AccountListFragment: Fragment() {
val sortedAccounts = accountManager
.getAccountsByType(context.getString(R.string.account_type))
.sortedArrayWith({ a, b ->
.sortedArrayWith { a, b ->
collator.compare(a.name, b.name)
})
}
val accountsWithInfo = sortedAccounts.map { account ->
AccountInfo(account, DavUtils.accountSyncStatus(context, syncAuthorities, account))
}
......
......@@ -148,7 +148,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
class Model(app: Application): AndroidViewModel(app), SyncStatusObserver {
private var syncStatusObserver: Any? = null
val showSyncDisabled = MutableLiveData<Boolean>(false)
val showSyncDisabled = MutableLiveData(false)
init {
syncStatusObserver = ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this)
......
......@@ -184,7 +184,7 @@ class DebugInfoActivity: AppCompatActivity() {
val remoteResource = MutableLiveData<String>()
val debugInfo = MutableLiveData<File>()
val zipProgress = MutableLiveData<Boolean>(false)
val zipProgress = MutableLiveData(false)
val zipFile = MutableLiveData<File>()
// private storage, not readable by others
......@@ -232,7 +232,7 @@ class DebugInfoActivity: AppCompatActivity() {
remoteResource.postValue(remote)
generateDebugInfo(
extras?.getParcelable<Account>(EXTRA_ACCOUNT),
extras?.getParcelable(EXTRA_ACCOUNT),
extras?.getString(EXTRA_AUTHORITY),
throwable,
local,
......@@ -241,7 +241,7 @@ class DebugInfoActivity: AppCompatActivity() {
}
}
fun generateDebugInfo(syncAccount: Account?, syncAuthority: String?, cause: Throwable?, localResource: String?, remoteResource: String?) {
private fun generateDebugInfo(syncAccount: Account?, syncAuthority: String?, cause: Throwable?, localResource: String?, remoteResource: String?) {
val debugInfoFile = File(debugInfoDir, FILE_DEBUG_INFO)
debugInfoFile.writer().buffered().use { writer ->
writer.append(ByteOrderMark.UTF_BOM)
......@@ -356,7 +356,7 @@ class DebugInfoActivity: AppCompatActivity() {
}
if (properties != null) {
writer .append(" - DNS: ")
.append(properties.dnsServers.map { it.hostAddress }.joinToString(", "))
.append(properties.dnsServers.joinToString(", ") { it.hostAddress })
if (Build.VERSION.SDK_INT >= 28 && properties.isPrivateDnsActive)
writer.append(" (private mode)")
writer.append('\n')
......
......@@ -19,8 +19,7 @@ class HomeSetAdapter(
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val data = getItem(position)!!
val v: View
v = convertView ?: LayoutInflater.from(context).inflate(R.layout.text_list_item, parent, false)
val v: View = convertView ?: LayoutInflater.from(context).inflate(R.layout.text_list_item, parent, false)
v.findViewById<TextView>(android.R.id.text1).apply {
text = data.displayName ?: DavUtils.lastSegmentOfUrl(data.url)
}
......
......@@ -31,7 +31,7 @@ class PermissionsFragment: Fragment() {
val model by viewModels<Model>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val binding = ActivityPermissionsBinding.inflate(inflater, container, false)
binding.lifecycleOwner = viewLifecycleOwner
binding.model = model
......
......@@ -249,7 +249,7 @@ class AccountActivity: AppCompatActivity() {
}
private val db = AppDatabase.getInstance(application)
val accountManager = AccountManager.get(application)
val accountManager = AccountManager.get(application)!!
val accountSettings by lazy { AccountSettings(getApplication(), account) }
val accountExists = MutableLiveData<Boolean>()
......
......@@ -15,7 +15,7 @@ class AddressBooksFragment: CollectionsFragment() {
inflater.inflate(R.menu.carddav_actions, menu)
override fun onPrepareOptionsMenu(menu: Menu) {
menu.findItem(R.id.create_address_book).setVisible(model.hasWriteableCollections.value ?: false)
menu.findItem(R.id.create_address_book).isVisible = model.hasWriteableCollections.value ?: false
super.onPrepareOptionsMenu(menu)
}
......
......@@ -17,7 +17,7 @@ class CalendarsFragment: CollectionsFragment() {
inflater.inflate(R.menu.caldav_actions, menu)
override fun onPrepareOptionsMenu(menu: Menu) {
menu.findItem(R.id.create_calendar).setVisible(model.hasWriteableCollections.value ?: false)
menu.findItem(R.id.create_calendar).isVisible = model.hasWriteableCollections.value ?: false
super.onPrepareOptionsMenu(menu)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment