Call directly instead of invoke when possible

pull/1274/head
mhmdanas 5 years ago committed by Alex Baker
parent 607935bda3
commit d318cf8b10

@ -27,7 +27,7 @@ class TranslationTests {
private fun forEachLocale(callback: (Resources) -> Unit) { private fun forEachLocale(callback: (Resources) -> Unit) {
val locales = Locale.getAvailableLocales() val locales = Locale.getAvailableLocales()
for (locale in locales) { for (locale in locales) {
callback.invoke(getResourcesForLocale(locale)) callback(getResourcesForLocale(locale))
} }
} }

@ -6,7 +6,7 @@ import org.tasks.time.DateTimeUtils
class Freeze { class Freeze {
fun thawAfter(run: () -> Unit) { fun thawAfter(run: () -> Unit) {
try { try {
run.invoke() run()
} finally { } finally {
thaw() thaw()
} }

@ -7,7 +7,7 @@ class SuspendFreeze {
suspend fun thawAfter(run: suspend () -> Unit) { suspend fun thawAfter(run: suspend () -> Unit) {
try { try {
run.invoke() run()
} finally { } finally {
thaw() thaw()
} }

@ -97,7 +97,7 @@ class NavigationDrawerAdapter @Inject constructor(
} }
} }
private fun onClickFilter(filter: FilterListItem?) = onClick.invoke(if (filter == selected) null else filter) private fun onClickFilter(filter: FilterListItem?) = onClick(if (filter == selected) null else filter)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val item = getItem(position) val item = getItem(position)

@ -72,7 +72,7 @@ class CriterionViewHolder(
} }
@OnClick(R.id.row) @OnClick(R.id.row)
fun onClick() = this.onClick.invoke(criterion.id) fun onClick() = onClick(criterion.id)
fun setMoving(moving: Boolean) { fun setMoving(moving: Boolean) {
if (moving) { if (moving) {

@ -30,7 +30,7 @@ class CustomFilterItemTouchHelper(
if (toPosition == 0) { if (toPosition == 0) {
return false return false
} }
onMove.invoke(src.adapterPosition, toPosition) onMove(src.adapterPosition, toPosition)
return true return true
} }
@ -60,10 +60,10 @@ class CustomFilterItemTouchHelper(
(viewHolder as CriterionViewHolder).setMoving(false) (viewHolder as CriterionViewHolder).setMoving(false)
onClear.invoke() onClear()
} }
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
onDelete.invoke(viewHolder.adapterPosition) onDelete(viewHolder.adapterPosition)
} }
} }

@ -82,7 +82,7 @@ class Upgrader @Inject constructor(
private fun run(from: Int, version: Int, runnable: suspend () -> Unit) { private fun run(from: Int, version: Int, runnable: suspend () -> Unit) {
if (from < version) { if (from < version) {
runBlocking { runBlocking {
runnable.invoke() runnable()
} }
preferences.setCurrentVersion(version) preferences.setCurrentVersion(version)
} }

@ -141,7 +141,7 @@ class SubtasksFilterUpdater @Inject constructor(
private suspend fun applyToDescendantsHelper(n: Node, visitor: suspend (Node) -> Unit) { private suspend fun applyToDescendantsHelper(n: Node, visitor: suspend (Node) -> Unit) {
val children = n.children val children = n.children
for (child in children) { for (child in children) {
visitor.invoke(child) visitor(child)
applyToDescendantsHelper(child, visitor) applyToDescendantsHelper(child, visitor)
} }
} }

@ -105,7 +105,7 @@ class SubtasksHelper @Inject constructor(
var i = 0 var i = 0
while (i < children.size) { while (i < children.size) {
val child = children[i] val child = children[i]
val key = helper.invoke(child.uuid) val key = helper(child.uuid)
val uuid = idMap[key] val uuid = idMap[key]
if (!isValidUuid(uuid!!)) { if (!isValidUuid(uuid!!)) {
children.removeAt(i) children.removeAt(i)

@ -107,7 +107,7 @@ class ListPicker : DialogFragment() {
.setSingleChoiceItems(filterAdapter,-1) { dialog: DialogInterface, which: Int -> .setSingleChoiceItems(filterAdapter,-1) { dialog: DialogInterface, which: Int ->
val item = filterAdapter.getItem(which) val item = filterAdapter.getItem(which)
if (item is GtasksFilter || item is CaldavFilter) { if (item is GtasksFilter || item is CaldavFilter) {
handler.invoke(item as Filter) handler(item as Filter)
} }
dialog.dismiss() dialog.dismiss()
} }

@ -102,7 +102,7 @@ abstract class TaskDao(private val database: Database) {
open suspend fun fetchTasks(callback: suspend (SubtaskInfo) -> List<String>, subtasks: SubtaskInfo): List<TaskContainer> = open suspend fun fetchTasks(callback: suspend (SubtaskInfo) -> List<String>, subtasks: SubtaskInfo): List<TaskContainer> =
database.withTransaction { database.withTransaction {
val start = if (BuildConfig.DEBUG) DateUtilities.now() else 0 val start = if (BuildConfig.DEBUG) DateUtilities.now() else 0
val queries = callback.invoke(subtasks) val queries = callback(subtasks)
val last = queries.size - 1 val last = queries.size - 1
for (i in 0 until last) { for (i in 0 until last) {
query(SimpleSQLiteQuery(queries[i])) query(SimpleSQLiteQuery(queries[i]))

@ -8,8 +8,8 @@ object SuspendDbUtils {
eachChunk(MAX_SQLITE_ARGS, action) eachChunk(MAX_SQLITE_ARGS, action)
suspend fun <T> Iterable<T>.eachChunk(size: Int, action: suspend (List<T>) -> Unit) = suspend fun <T> Iterable<T>.eachChunk(size: Int, action: suspend (List<T>) -> Unit) =
chunked(size).forEach { action.invoke(it) } chunked(size).forEach { action(it) }
suspend fun <T, R> Iterable<T>.chunkedMap(transform: suspend (List<T>) -> Iterable<R>): List<R> = suspend fun <T, R> Iterable<T>.chunkedMap(transform: suspend (List<T>) -> Iterable<R>): List<R> =
dbchunk().flatMap { transform.invoke(it) } dbchunk().flatMap { transform(it) }
} }

@ -203,7 +203,7 @@ class EteSyncClient {
var journalEntries: List<JournalEntryManager.Entry> var journalEntries: List<JournalEntryManager.Entry>
do { do {
journalEntries = journalEntryManager.list(crypto, calendar.ctag, MAX_FETCH) journalEntries = journalEntryManager.list(crypto, calendar.ctag, MAX_FETCH)
callback.invoke(journalEntries.map { callback(journalEntries.map {
Pair.create(it, SyncEntry.fromJournalEntry(crypto, it)) Pair.create(it, SyncEntry.fromJournalEntry(crypto, it))
}) })
} while (journalEntries.size >= MAX_FETCH) } while (journalEntries.size >= MAX_FETCH)

@ -69,8 +69,8 @@ class AlphanumComparator<T>(private val getTitle: (T) -> String?) : Comparator<T
} }
override fun compare(t1: T, t2: T): Int { override fun compare(t1: T, t2: T): Int {
val s1 = getTitle.invoke(t1) val s1 = getTitle(t1)
val s2 = getTitle.invoke(t2) val s2 = getTitle(t2)
if (s1 == null || s2 == null) { if (s1 == null || s2 == null) {
return 0 return 0
} }

@ -186,14 +186,14 @@ class CommentBarFragment : TaskEditControlFragment() {
options.add(getString(R.string.take_a_picture)) options.add(getString(R.string.take_a_picture))
} }
if (clearImageOption != null) { if (clearImageOption != null) {
runnables.add { clearImageOption.invoke() } runnables.add { clearImageOption() }
options.add(getString(R.string.actfm_picture_clear)) options.add(getString(R.string.actfm_picture_clear))
} }
if (runnables.size == 1) { if (runnables.size == 1) {
runnables[0].invoke() runnables[0]()
} else { } else {
val listener = DialogInterface.OnClickListener { d: DialogInterface, which: Int -> val listener = DialogInterface.OnClickListener { d: DialogInterface, which: Int ->
runnables[which].invoke() runnables[which]()
d.dismiss() d.dismiss()
} }

@ -78,7 +78,7 @@ class BackupWork @WorkerInject constructor(
const val DAYS_TO_KEEP_BACKUP = 7 const val DAYS_TO_KEEP_BACKUP = 7
val BACKUP_FILE_NAME_REGEX = Regex("auto\\.[-\\d]+\\.json") val BACKUP_FILE_NAME_REGEX = Regex("auto\\.[-\\d]+\\.json")
private val FILENAME_FILTER = { f: String -> f.matches(BACKUP_FILE_NAME_REGEX) } private val FILENAME_FILTER = { f: String -> f.matches(BACKUP_FILE_NAME_REGEX) }
val FILE_FILTER = FileFilter { f: File -> FILENAME_FILTER.invoke(f.name) } val FILE_FILTER = FileFilter { f: File -> FILENAME_FILTER(f.name) }
private val BY_LAST_MODIFIED = { f1: File, f2: File -> private val BY_LAST_MODIFIED = { f1: File, f2: File ->
BackupConstants.getTimestamp(f2).compareTo(BackupConstants.getTimestamp(f1)) BackupConstants.getTimestamp(f2).compareTo(BackupConstants.getTimestamp(f1))
} }
@ -89,7 +89,7 @@ class BackupWork @WorkerInject constructor(
private fun getDeleteList(fileArray: Array<DocumentFile>?) = private fun getDeleteList(fileArray: Array<DocumentFile>?) =
fileArray fileArray
?.filter { FILENAME_FILTER.invoke(it.name!!) } ?.filter { FILENAME_FILTER(it.name!!) }
?.sortedWith(DOCUMENT_FILE_COMPARATOR) ?.sortedWith(DOCUMENT_FILE_COMPARATOR)
?.drop(DAYS_TO_KEEP_BACKUP) ?.drop(DAYS_TO_KEEP_BACKUP)
?: emptyList() ?: emptyList()

@ -21,11 +21,11 @@ internal class Throttle constructor(
val sleep = throttle[oldest] - (currentTimeMillis() - periodMillis) val sleep = throttle[oldest] - (currentTimeMillis() - periodMillis)
if (sleep > 0) { if (sleep > 0) {
Timber.v("$tag: Throttled for ${sleep}ms") Timber.v("$tag: Throttled for ${sleep}ms")
sleeper.invoke(sleep) sleeper(sleep)
} }
try { try {
runBlocking { runBlocking {
runnable.invoke() runnable()
} }
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e) Timber.e(e)

@ -186,7 +186,7 @@ class Advanced : InjectingPreferenceFragment() {
} }
private fun performAction(message: Int, callable: suspend () -> Int) = lifecycleScope.launch { private fun performAction(message: Int, callable: suspend () -> Int) = lifecycleScope.launch {
toaster.longToastUnformatted(message, callable.invoke()) toaster.longToastUnformatted(message, callable())
} }
private fun resetPreferences() { private fun resetPreferences() {

@ -12,7 +12,7 @@ class Debouncer constructor(private val tag: String, private val block: suspend
delay(1000) delay(1000)
if (immediate || thisCount == count) { if (immediate || thisCount == count) {
block.invoke(immediate) block(immediate)
} else { } else {
Timber.v("debouncing $tag") Timber.v("debouncing $tag")
} }

@ -33,7 +33,7 @@ class TagPickerViewHolder internal constructor(
@OnClick(R.id.tag_row) @OnClick(R.id.tag_row)
fun onClickRow() { fun onClickRow() {
if (tagData!!.id == null) { if (tagData!!.id == null) {
callback.invoke(tagData!!, this) callback(tagData!!, this)
} else { } else {
checkBox.toggle() checkBox.toggle()
} }
@ -41,7 +41,7 @@ class TagPickerViewHolder internal constructor(
@OnCheckedChanged(R.id.checkbox) @OnCheckedChanged(R.id.checkbox)
fun onCheckedChanged() { fun onCheckedChanged() {
callback.invoke(tagData!!, this) callback(tagData!!, this)
} }
fun bind( fun bind(

@ -66,7 +66,7 @@ class HeaderViewHolder(
init { init {
header.setOnClickListener { header.setOnClickListener {
callback.invoke(sortGroup) callback(sortGroup)
} }
} }
} }

@ -18,7 +18,7 @@ open class ActionViewModel : ViewModel() {
errorObserver: (Throwable) -> Unit) { errorObserver: (Throwable) -> Unit) {
completed.observe(lifecycleOwner) { completed.observe(lifecycleOwner) {
lifecycleOwner.lifecycleScope.launch { lifecycleOwner.lifecycleScope.launch {
completeObserver.invoke(it) completeObserver(it)
} }
} }
error.observe(lifecycleOwner, errorObserver) error.observe(lifecycleOwner, errorObserver)
@ -28,7 +28,7 @@ open class ActionViewModel : ViewModel() {
if (!inProgress) { if (!inProgress) {
inProgress = true inProgress = true
try { try {
action.invoke() action()
completed.value = true completed.value = true
} catch (e: Exception) { } catch (e: Exception) {
error.value = e error.value = e

@ -17,7 +17,7 @@ abstract class CompletableViewModel<T> : ViewModel() {
errorObserver: (Throwable) -> Unit) { errorObserver: (Throwable) -> Unit) {
data.observe(lifecycleOwner) { data.observe(lifecycleOwner) {
lifecycleOwner.lifecycleScope.launch { lifecycleOwner.lifecycleScope.launch {
dataObserver.invoke(it) dataObserver(it)
} }
} }
error.observe(lifecycleOwner, errorObserver) error.observe(lifecycleOwner, errorObserver)
@ -27,7 +27,7 @@ abstract class CompletableViewModel<T> : ViewModel() {
if (!inProgress) { if (!inProgress) {
inProgress = true inProgress = true
try { try {
data.postValue(callable.invoke()) data.postValue(callable())
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e) Timber.e(e)
error.postValue(e) error.postValue(e)

@ -108,7 +108,7 @@ class LocationControlSet : TaskEditControlFragment() {
dialogBuilder dialogBuilder
.newDialog(location.displayName) .newDialog(location.displayName)
.setItems(items) { _, which: Int -> .setItems(items) { _, which: Int ->
options[which].second!!.invoke() options[which].second!!()
} }
.show() .show()
} }

Loading…
Cancel
Save