From 83f9638aafce780e55c3cb8a8642a2cbf71be66f Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Tue, 16 Jul 2019 19:26:55 +0200 Subject: [PATCH] fix some lint warnings and Kotlin style issues (#1390) --- .../com/keylesspalace/tusky/AccountActivity.kt | 3 ++- .../conversation/ConversationAdapter.kt | 2 +- .../conversation/ConversationsFragment.kt | 6 ------ .../preference/ProxyPreferencesFragment.kt | 3 ++- .../receiver/SendStatusBroadcastReceiver.kt | 3 +-- .../util/ListStatusAccessibilityDelegate.kt | 4 ++-- .../com/keylesspalace/tusky/util/SpanUtils.kt | 3 ++- .../main/res/layout/activity_instance_list.xml | 18 ------------------ app/src/main/res/menu/report_toolbar.xml | 10 ---------- 9 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/res/layout/activity_instance_list.xml delete mode 100644 app/src/main/res/menu/report_toolbar.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index 53da95820..e2aa4ce6a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -58,6 +58,7 @@ import kotlinx.android.synthetic.main.activity_account.* import kotlinx.android.synthetic.main.view_account_moved.* import java.text.NumberFormat import javax.inject.Inject +import kotlin.math.abs class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInjector, LinkListener { @@ -272,7 +273,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountAvatarImageView.visible(scaledAvatarSize > 0) - var transparencyPercent = Math.abs(verticalOffset) / titleVisibleHeight.toFloat() + var transparencyPercent = abs(verticalOffset) / titleVisibleHeight.toFloat() if (transparencyPercent > 1) transparencyPercent = 1f window.statusBarColor = argbEvaluator.evaluate(transparencyPercent, statusBarColorTransparent, statusBarColorOpaque) as Int diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationAdapter.kt index 151b6741c..0b412029c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationAdapter.kt @@ -41,7 +41,7 @@ class ConversationAdapter(private val useAbsoluteTime: Boolean, override fun onChanged(position: Int, count: Int, payload: Any?) { notifyItemRangeChanged(position, count, payload) } - }, AsyncDifferConfig.Builder(CONVERSATION_COMPARATOR).build()) + }, AsyncDifferConfig.Builder(CONVERSATION_COMPARATOR).build()) fun submitList(list: PagedList) { differ.submitList(list) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt index 3c465910a..7799688ec 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt @@ -18,11 +18,9 @@ package com.keylesspalace.tusky.components.conversation import android.content.Intent import android.os.Bundle import android.preference.PreferenceManager -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.lifecycle.Lifecycle import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import androidx.paging.PagedList @@ -36,15 +34,11 @@ import com.keylesspalace.tusky.db.AppDatabase import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.ViewModelFactory import com.keylesspalace.tusky.fragment.SFragment -import com.keylesspalace.tusky.fragment.SearchFragment import com.keylesspalace.tusky.interfaces.ReselectableFragment import com.keylesspalace.tusky.interfaces.StatusActionListener import com.keylesspalace.tusky.util.NetworkState import com.keylesspalace.tusky.util.ThemeUtils import com.keylesspalace.tusky.util.hide -import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider -import com.uber.autodispose.autoDisposable -import io.reactivex.android.schedulers.AndroidSchedulers import kotlinx.android.synthetic.main.fragment_timeline.* import javax.inject.Inject diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/ProxyPreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/ProxyPreferencesFragment.kt index ede9749f7..a4efff2d7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/ProxyPreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/ProxyPreferencesFragment.kt @@ -20,6 +20,7 @@ import android.os.Bundle import androidx.preference.EditTextPreference import androidx.preference.PreferenceFragmentCompat import com.keylesspalace.tusky.R +import kotlin.system.exitProcess class ProxyPreferencesFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { @@ -50,7 +51,7 @@ class ProxyPreferencesFragment : PreferenceFragmentCompat(), SharedPreferences.O if (pendingRestart) { pendingRestart = false - System.exit(0) + exitProcess(0) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt b/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt index 9eea04d37..6942f4989 100644 --- a/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt +++ b/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt @@ -30,7 +30,6 @@ import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.service.SendTootService import com.keylesspalace.tusky.util.NotificationHelper import dagger.android.AndroidInjection -import java.util.* import javax.inject.Inject private const val TAG = "SendStatusBR" @@ -128,7 +127,7 @@ class SendStatusBroadcastReceiver : BroadcastReceiver() { .inReplyToId(citedStatusId) .replyVisibility(visibility) .contentWarning(spoiler) - .mentionedUsernames(Arrays.asList(*mentions)) + .mentionedUsernames(mentions.toList()) .replyingStatusAuthor(localAuthorId) .replyingStatusContent(citedText) .build(context) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt b/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt index 34010b7a8..ddd9b29cd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt @@ -159,7 +159,7 @@ class ListStatusAccessibilityDelegate( val textLinks = links.map { item -> item.link } AlertDialog.Builder(host.context) .setTitle(R.string.title_links_dialog) - .setAdapter(ArrayAdapter( + .setAdapter(ArrayAdapter( host.context, android.R.layout.simple_list_item_1, textLinks) @@ -188,7 +188,7 @@ class ListStatusAccessibilityDelegate( val tags = getHashtags(status).map { it.subSequence(1, it.length) }.toList() AlertDialog.Builder(host.context) .setTitle(R.string.title_hashtags_dialog) - .setAdapter(ArrayAdapter(host.context, + .setAdapter(ArrayAdapter(host.context, android.R.layout.simple_list_item_1, tags) ) { _, which -> statusActionListener.onViewTag(tags[which].toString()) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt b/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt index ec5040383..e1be27d8a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt @@ -6,6 +6,7 @@ import android.text.style.CharacterStyle import android.text.style.ForegroundColorSpan import android.text.style.URLSpan import java.util.regex.Pattern +import kotlin.math.max /** * @see @@ -68,7 +69,7 @@ private fun findPattern(string: String, fromIndex: Int): FindCharsResult { && ((i - fromIndex) < finder.searchPrefixWidth || Character.isWhitespace(string.codePointAt(i - finder.searchPrefixWidth)))) { result.matchType = matchType - result.start = Math.max(0, i - finder.searchPrefixWidth) + result.start = max(0, i - finder.searchPrefixWidth) findEndOfPattern(string, result, finder.pattern) if (result.start + finder.searchPrefixWidth <= i + 1 && // The found result is actually triggered by the correct search character result.end >= result.start) { // ...and we actually found a valid result diff --git a/app/src/main/res/layout/activity_instance_list.xml b/app/src/main/res/layout/activity_instance_list.xml deleted file mode 100644 index c8ca4a0a9..000000000 --- a/app/src/main/res/layout/activity_instance_list.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/report_toolbar.xml b/app/src/main/res/menu/report_toolbar.xml deleted file mode 100644 index d3b3ee8fe..000000000 --- a/app/src/main/res/menu/report_toolbar.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file