Commit 6c0b555e authored by Ricki Hirner's avatar Ricki Hirner 🐑

lint

parent 89183820
Pipeline #122954063 passed with stages
in 13 minutes and 31 seconds
......@@ -27,6 +27,7 @@ import java.util.*
*/
object DavUtils {
@Suppress("FunctionName")
fun ARGBtoCalDAVColor(colorWithAlpha: Int): String {
val alpha = (colorWithAlpha shr 24) and 0xFF
val color = colorWithAlpha and 0xFFFFFF
......
......@@ -13,7 +13,6 @@ import android.os.Build
import android.security.KeyChain
import at.bitfire.cert4android.CustomCertManager
import at.bitfire.dav4jvm.BasicDigestAuthHandler
import at.bitfire.dav4jvm.Constants
import at.bitfire.dav4jvm.UrlUtils
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.Credentials
......
......@@ -32,7 +32,7 @@ object Logger : SharedPreferences.OnSharedPreferenceChangeListener {
private const val LOG_TO_FILE = "log_to_file"
val log = java.util.logging.Logger.getLogger("davx5")
val log: java.util.logging.Logger = java.util.logging.Logger.getLogger("davx5")
private lateinit var context: Context
private lateinit var preferences: SharedPreferences
......
......@@ -44,6 +44,7 @@ import java.util.logging.Level
*
* @throws InvalidAccountException on construction when the account doesn't exist (anymore)
*/
@Suppress("FunctionName")
class AccountSettings(
val context: Context,
val account: Account
......@@ -295,6 +296,7 @@ class AccountSettings(
provider.client.update(tasksUri, emptyETag, "${TaskContract.Tasks._DIRTY}=0 AND ${TaskContract.Tasks._DELETED}=0", null)
}
@SuppressLint("Recycle")
if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED)
context.contentResolver.acquireContentProviderClient(CalendarContract.AUTHORITY)?.let { provider ->
provider.update(AndroidCalendar.syncAdapterURI(CalendarContract.Calendars.CONTENT_URI, account),
......
......@@ -15,7 +15,6 @@ import java.lang.ref.WeakReference
import java.util.*
import java.util.logging.Level
@WorkerThread
class Settings(
appContext: Context
) {
......@@ -68,16 +67,22 @@ class Settings(
/*** OBSERVERS ***/
fun addOnChangeListener(observer: OnChangeListener) {
observers += WeakReference(observer)
synchronized(this) {
observers += WeakReference(observer)
}
}
fun removeOnChangeListener(observer: OnChangeListener) {
observers.removeAll { it.get() == null || it.get() == observer }
synchronized(this) {
observers.removeAll { it.get() == null || it.get() == observer }
}
}
fun onSettingsChanged() {
observers.mapNotNull { it.get() }.forEach {
it.onSettingsChanged()
synchronized(this) {
observers.mapNotNull { it.get() }.forEach {
it.onSettingsChanged()
}
}
}
......
......@@ -25,9 +25,9 @@ import androidx.core.content.ContextCompat
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.settings.AccountSettings
import at.bitfire.davdroid.ui.account.SettingsActivity
import at.bitfire.davdroid.ui.NotificationUtils
import at.bitfire.davdroid.ui.account.AccountActivity
import at.bitfire.davdroid.ui.account.SettingsActivity
import java.lang.ref.WeakReference
import java.util.*
import java.util.logging.Level
......
......@@ -22,7 +22,7 @@ import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.App
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.R
......@@ -108,8 +108,8 @@ class AboutActivity: AppCompatActivity() {
if (true /* open-source version */) {
warranty.setText(R.string.about_license_info_no_warranty)
val model = ViewModelProviders.of(this).get(LicenseModel::class.java)
model.htmlText.observe(this, Observer { spanned ->
val model = ViewModelProvider(this).get(LicenseModel::class.java)
model.htmlText.observe(viewLifecycleOwner, Observer { spanned ->
license_text.text = spanned
})
}
......
......@@ -32,7 +32,7 @@ import androidx.fragment.app.ListFragment
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.R
import at.bitfire.davdroid.ui.account.AccountActivity
import kotlinx.android.synthetic.main.account_list.*
......@@ -43,14 +43,14 @@ class AccountListFragment: ListFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
listAdapter = AccountListAdapter(requireActivity())
val model = ViewModelProviders.of(this).get(Model::class.java)
model.accounts.observe(this, Observer { accounts ->
val model = ViewModelProvider(this).get(Model::class.java)
model.accounts.observe(viewLifecycleOwner, Observer { accounts ->
val adapter = listAdapter as AccountListAdapter
adapter.clear()
adapter.addAll(*accounts)
})
model.networkAvailable.observe(this, Observer { networkAvailable ->
model.networkAvailable.observe(viewLifecycleOwner, Observer { networkAvailable ->
no_network_info.visibility = if (networkAvailable) View.GONE else View.VISIBLE
})
......
......@@ -20,7 +20,7 @@ import androidx.core.app.NavUtils
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.R
import at.bitfire.davdroid.databinding.ActivityCreateAddressBookBinding
import at.bitfire.davdroid.model.AppDatabase
......@@ -43,7 +43,7 @@ class CreateAddressBookActivity: AppCompatActivity() {
super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
model = ViewModelProviders.of(this).get(Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
(intent?.getParcelableExtra(EXTRA_ACCOUNT) as? Account)?.let {
model.initialize(it)
}
......
......@@ -24,7 +24,7 @@ import androidx.core.app.NavUtils
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.R
import at.bitfire.davdroid.databinding.ActivityCreateCalendarBinding
......@@ -53,7 +53,7 @@ class CreateCalendarActivity: AppCompatActivity(), ColorPickerDialogListener {
super.onCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
model = ViewModelProviders.of(this).get(Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
(intent?.getParcelableExtra(EXTRA_ACCOUNT) as? Account)?.let {
model.initialize(it)
}
......@@ -163,7 +163,7 @@ class CreateCalendarActivity: AppCompatActivity(), ColorPickerDialogListener {
context: Context
): ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, android.R.id.text1) {
val tz = TimeZone.getAvailableIDs()!!
val tz: Array<String> = TimeZone.getAvailableIDs()
override fun getFilter(): Filter {
return object: Filter() {
......
......@@ -56,7 +56,7 @@ class CreateCollectionFragment: DialogFragment() {
super.onCreate(savedInstanceState)
val args = arguments ?: throw IllegalArgumentException()
model = ViewModelProviders.of(this).get(Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
model.account = args.getParcelable(ARG_ACCOUNT) ?: throw IllegalArgumentException("ARG_ACCOUNT required")
model.serviceType = args.getString(ARG_SERVICE_TYPE) ?: throw java.lang.IllegalArgumentException("ARG_SERVICE_TYPE required")
......@@ -80,7 +80,7 @@ class CreateCollectionFragment: DialogFragment() {
requireActivity().finish()
else {
dismiss()
requireFragmentManager().beginTransaction()
parentFragmentManager.beginTransaction()
.add(ExceptionInfoFragment.newInstance(exception, model.account), null)
.commit()
}
......
......@@ -36,7 +36,7 @@ import androidx.core.content.pm.PackageInfoCompat
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.InvalidAccountException
......@@ -71,7 +71,7 @@ class DebugInfoActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
model = ViewModelProviders.of(this).get(ReportModel::class.java)
model = ViewModelProvider(this).get(ReportModel::class.java)
model.initialize(intent.extras)
val binding = DataBindingUtil.setContentView<ActivityDebugInfoBinding>(this, R.layout.activity_debug_info)
......
......@@ -45,10 +45,10 @@ class DeleteCollectionFragment: DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
model = ViewModelProviders.of(this).get(DeleteCollectionModel::class.java)
model = ViewModelProvider(this).get(DeleteCollectionModel::class.java)
model.initialize(
arguments!!.getParcelable(ARG_ACCOUNT)!!,
arguments!!.getLong(ARG_COLLECTION_ID)
requireArguments().getParcelable(ARG_ACCOUNT)!!,
requireArguments().getLong(ARG_COLLECTION_ID)
)
}
......@@ -62,9 +62,9 @@ class DeleteCollectionFragment: DialogFragment() {
binding.progress.visibility = View.VISIBLE
binding.controls.visibility = View.GONE
model.deleteCollection().observe(this, Observer { exception ->
model.deleteCollection().observe(viewLifecycleOwner, Observer { exception ->
if (exception != null)
requireFragmentManager().beginTransaction()
parentFragmentManager.beginTransaction()
.add(ExceptionInfoFragment.newInstance(exception, model.account), null)
.commit()
dismiss()
......
......@@ -64,7 +64,7 @@ class StartupDialogFragment: DialogFragment() {
}
// vendor-specific auto-start information
if (autostartManufacturers.contains(Build.MANUFACTURER.toLowerCase()) && settings.getBoolean(HINT_AUTOSTART_PERMISSIONS) != false)
if (autostartManufacturers.contains(Build.MANUFACTURER.toLowerCase(Locale.ROOT)) && settings.getBoolean(HINT_AUTOSTART_PERMISSIONS) != false)
dialogs.add(instantiate(Mode.AUTOSTART_PERMISSIONS))
// OpenTasks information
......@@ -92,7 +92,7 @@ class StartupDialogFragment: DialogFragment() {
val settings = Settings.getInstance(requireActivity())
val activity = requireActivity()
return when (Mode.valueOf(arguments!!.getString(ARGS_MODE)!!)) {
return when (Mode.valueOf(requireArguments().getString(ARGS_MODE)!!)) {
Mode.AUTOSTART_PERMISSIONS ->
MaterialAlertDialogBuilder(activity)
.setIcon(R.drawable.ic_error_dark)
......
......@@ -47,7 +47,7 @@ class AccountActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
model = ViewModelProviders.of(this).get(Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
(intent.getParcelableExtra(EXTRA_ACCOUNT) as? Account)?.let { account ->
model.initialize(account)
}
......
......@@ -17,7 +17,7 @@ import androidx.annotation.UiThread
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.databinding.CollectionPropertiesBinding
import at.bitfire.davdroid.model.AppDatabase
import at.bitfire.davdroid.model.Collection
......@@ -40,7 +40,7 @@ class CollectionInfoFragment: DialogFragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val model = ViewModelProviders.of(this).get(Model::class.java)
val model = ViewModelProvider(this).get(Model::class.java)
arguments?.getLong(ARGS_COLLECTION_ID)?.let { id ->
model.initialize(id)
}
......
......@@ -46,8 +46,8 @@ abstract class CollectionsFragment: Fragment(), SwipeRefreshLayout.OnRefreshList
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
accountModel = ViewModelProviders.of(requireActivity()).get(AccountActivity.Model::class.java)
model = ViewModelProviders.of(this).get(Model::class.java)
accountModel = ViewModelProvider(requireActivity()).get(AccountActivity.Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
model.initialize(
accountModel,
arguments?.getLong(EXTRA_SERVICE_ID) ?: throw IllegalArgumentException("EXTRA_SERVICE_ID required"),
......
......@@ -22,7 +22,7 @@ import androidx.fragment.app.DialogFragment
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.bitfire.davdroid.DavUtils
import at.bitfire.davdroid.R
import at.bitfire.davdroid.closeCompat
......@@ -55,7 +55,7 @@ class RenameAccountFragment: DialogFragment() {
@SuppressLint("Recycle")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val oldAccount: Account = arguments!!.getParcelable(ARG_ACCOUNT)!!
val oldAccount: Account = requireArguments().getParcelable(ARG_ACCOUNT)!!
val editText = EditText(requireActivity()).apply {
setText(oldAccount.name)
......@@ -66,7 +66,7 @@ class RenameAccountFragment: DialogFragment() {
layout.setPadding(8*density, 8*density, 8*density, 8*density)
layout.addView(editText)
val model = ViewModelProviders.of(this).get(Model::class.java)
val model = ViewModelProvider(this).get(Model::class.java)
model.finished.observe(this, Observer {
this@RenameAccountFragment.requireActivity().finish()
})
......
......@@ -79,9 +79,9 @@ class SettingsActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
settings = Settings.getInstance(requireActivity())
account = arguments!!.getParcelable(EXTRA_ACCOUNT)!!
account = requireArguments().getParcelable(EXTRA_ACCOUNT)!!
model = ViewModelProviders.of(this).get(Model::class.java)
model = ViewModelProvider(this).get(Model::class.java)
model.initialize(account)
initSettings()
......
......@@ -43,7 +43,7 @@ class WebcalFragment: CollectionsFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
webcalModel = ViewModelProviders.of(this).get(WebcalModel::class.java)
webcalModel = ViewModelProvider(this).get(WebcalModel::class.java)
webcalModel.calendarPermission.observe(this, Observer { granted ->
if (!granted)
requestPermissions(arrayOf(Manifest.permission.READ_CALENDAR), 0)
......
......@@ -46,8 +46,8 @@ class AccountDetailsFragment: Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loginModel = ViewModelProviders.of(requireActivity()).get(LoginModel::class.java)
model = ViewModelProviders.of(this).get(AccountDetailsModel::class.java)
loginModel = ViewModelProvider(requireActivity()).get(LoginModel::class.java)
model = ViewModelProvider(this).get(AccountDetailsModel::class.java)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
......@@ -90,7 +90,7 @@ class AccountDetailsFragment: Fragment() {
loginModel.credentials!!,
config,
GroupMethod.valueOf(groupMethodName)
).observe(this, Observer<Boolean> { success ->
).observe(viewLifecycleOwner, Observer<Boolean> { success ->
if (success)
requireActivity().finish()
else {
......
......@@ -43,7 +43,7 @@ class DavResourceFinder(
override fun toString() = wellKnownName
}
val log = Logger.getLogger("davdroid.DavResourceFinder")
val log: Logger = Logger.getLogger("davdroid.DavResourceFinder")
private val logBuffer = StringHandler()
init {
log.level = Level.FINEST
......
......@@ -33,23 +33,23 @@ class DetectConfigurationFragment: Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loginModel = ViewModelProviders.of(requireActivity()).get(LoginModel::class.java)
model = ViewModelProviders.of(this).get(DetectConfigurationModel::class.java)
loginModel = ViewModelProvider(requireActivity()).get(LoginModel::class.java)
model = ViewModelProvider(this).get(DetectConfigurationModel::class.java)
model.detectConfiguration(loginModel).observe(this, Observer<DavResourceFinder.Configuration> { result ->
// save result for next step
loginModel.configuration = result
// remove "Detecting configuration" fragment, it shouldn't come back
requireFragmentManager().popBackStack()
parentFragmentManager.popBackStack()
if (result.calDAV != null || result.cardDAV != null)
requireFragmentManager().beginTransaction()
parentFragmentManager.beginTransaction()
.replace(android.R.id.content, AccountDetailsFragment())
.addToBackStack(null)
.commit()
else
requireFragmentManager().beginTransaction()
parentFragmentManager.beginTransaction()
.add(NothingDetectedFragment(), null)
.commit()
})
......@@ -105,7 +105,7 @@ class DetectConfigurationFragment: Fragment() {
class NothingDetectedFragment: DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val model = ViewModelProviders.of(requireActivity()).get(LoginModel::class.java)
val model = ViewModelProvider(requireActivity()).get(LoginModel::class.java)
return MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.login_configuration_detection)
.setIcon(R.drawable.ic_error_dark)
......@@ -118,7 +118,7 @@ class DetectConfigurationFragment: Fragment() {
.setPositiveButton(android.R.string.ok) { _, _ ->
// just dismiss
}
.create()!!
.create()
}
}
......
Subproject commit aa9b9cfc32d9fdef8a3bf385f5cca8a9cd673fe1
Subproject commit e4a7866ef87f5d427722af97007ce8ae52b56b18
Subproject commit 9a7dabeb3898f2862c2d568416436a06cb3a855c
Subproject commit 7669dba7b87bc6643f09adb74a4f0cae4968eea1
Subproject commit 4e258cd0f4e3faf009ca5782303d547182c086ca
Subproject commit 2290ac6d002d05477b9419d71fd0d592fa756c7b
Markdown is supported
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