From d8be70a465be1ff71de643437c09d81565a0b380 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Mon, 8 Jan 2024 23:26:46 +0100 Subject: [PATCH] chore(deps): update plugin ktlint to v12 (#357) --- .editorconfig | 9 ++++- app/src/main/java/app/pachli/AboutActivity.kt | 2 +- .../java/app/pachli/AccountsInListFragment.kt | 2 +- app/src/main/java/app/pachli/BaseActivity.kt | 2 +- .../java/app/pachli/BottomSheetActivity.kt | 4 +- .../java/app/pachli/EditProfileActivity.kt | 5 ++- app/src/main/java/app/pachli/ListsActivity.kt | 5 ++- app/src/main/java/app/pachli/MainActivity.kt | 2 +- .../main/java/app/pachli/PachliApplication.kt | 4 +- .../java/app/pachli/StatusListActivity.kt | 2 +- .../java/app/pachli/TabPreferenceActivity.kt | 4 +- .../main/java/app/pachli/ViewMediaActivity.kt | 2 +- .../java/app/pachli/appstore/CacheUpdater.kt | 2 +- .../java/app/pachli/appstore/EventsHub.kt | 4 +- .../components/account/AccountViewModel.kt | 19 +++++++--- .../account/list/ListsForAccountViewModel.kt | 2 +- .../account/media/AccountMediaFragment.kt | 2 +- .../accountlist/AccountListFragment.kt | 6 +-- .../announcements/AnnouncementAdapter.kt | 8 +++- .../announcements/AnnouncementsViewModel.kt | 2 +- .../components/compose/ComposeActivity.kt | 37 +++++++++++++------ .../components/compose/ComposeViewModel.kt | 12 ++++-- .../components/compose/ImageDownsizer.kt | 8 ++-- .../components/compose/MediaUploader.kt | 26 ++++++------- .../compose/dialog/AddPollDialog.kt | 3 +- .../compose/view/ComposeScheduleView.kt | 2 +- .../components/compose/view/TootButton.kt | 5 ++- .../conversation/ConversationsFragment.kt | 6 +-- .../conversation/ConversationsViewModel.kt | 8 ++-- .../pachli/components/drafts/DraftHelper.kt | 12 +++--- .../components/drafts/DraftsActivity.kt | 2 +- .../components/drafts/DraftsViewModel.kt | 2 +- .../components/filters/EditFilterActivity.kt | 10 +++-- .../components/filters/EditFilterViewModel.kt | 2 +- .../components/filters/FiltersViewModel.kt | 8 +++- .../followedtags/FollowedTagsActivity.kt | 2 +- .../followedtags/FollowedTagsViewModel.kt | 4 +- .../instanceinfo/InstanceInfoRepository.kt | 12 ++++-- .../fragment/InstanceListFragment.kt | 6 +-- .../pachli/components/login/LoginActivity.kt | 4 +- .../components/login/LoginWebViewViewModel.kt | 4 +- .../notifications/NotificationFetcher.kt | 4 +- .../notifications/NotificationHelper.kt | 2 +- .../notifications/NotificationsFragment.kt | 3 +- .../NotificationsPagingSource.kt | 2 +- .../notifications/NotificationsRepository.kt | 2 +- .../notifications/NotificationsViewModel.kt | 5 ++- .../preference/AccountPreferencesFragment.kt | 2 +- .../preference/PreferencesActivity.kt | 2 +- .../components/report/ReportViewModel.kt | 6 +-- .../fragments/ReportStatusesFragment.kt | 2 +- .../scheduled/ScheduledStatusActivity.kt | 2 +- .../scheduled/ScheduledStatusViewModel.kt | 2 +- .../components/search/SearchViewModel.kt | 4 +- .../fragments/SearchAccountsFragment.kt | 2 +- .../search/fragments/SearchFragment.kt | 2 +- .../fragments/SearchStatusesFragment.kt | 2 +- .../timeline/CachedTimelineRepository.kt | 6 +-- .../components/timeline/FiltersRepository.kt | 2 +- .../timeline/NetworkTimelineRepository.kt | 2 +- .../components/timeline/TimelineFragment.kt | 7 +++- .../components/timeline/util/TimelineUtils.kt | 2 +- .../viewmodel/CachedTimelineRemoteMediator.kt | 2 +- .../viewmodel/CachedTimelineViewModel.kt | 2 +- .../viewmodel/NetworkTimelinePagingSource.kt | 2 +- .../NetworkTimelineRemoteMediator.kt | 2 +- .../viewmodel/NetworkTimelineViewModel.kt | 2 +- .../timeline/viewmodel/PageCache.kt | 6 +-- .../timeline/viewmodel/TimelineViewModel.kt | 3 +- .../viewmodel/TrendingLinksViewModel.kt | 4 +- .../viewmodel/TrendingTagsViewModel.kt | 11 ++++-- .../viewthread/ViewThreadViewModel.kt | 10 +++-- .../viewthread/edits/ViewEditsFragment.kt | 2 +- .../viewthread/edits/ViewEditsViewModel.kt | 2 +- .../main/java/app/pachli/db/DraftsAlert.kt | 4 +- .../java/app/pachli/fragment/SFragment.kt | 2 +- .../app/pachli/fragment/ViewVideoFragment.kt | 2 +- .../app/pachli/network/ProgressRequestBody.kt | 4 +- .../network/ServerCapabilitiesRepository.kt | 6 +-- ...NotificationBlockStateBroadcastReceiver.kt | 2 +- .../receiver/SendStatusBroadcastReceiver.kt | 2 +- .../receiver/UnifiedPushBroadcastReceiver.kt | 2 +- .../app/pachli/service/SendStatusService.kt | 13 ++++--- .../settings/AccountPreferenceDataStore.kt | 2 +- .../java/app/pachli/settings/SettingsDSL.kt | 5 ++- .../java/app/pachli/usecase/TimelineCases.kt | 4 +- .../util/CombinedLoadStatesExtensions.kt | 6 +-- .../main/java/app/pachli/util/CryptoUtil.kt | 6 +-- .../java/app/pachli/util/CustomEmojiHelper.kt | 8 +++- .../java/app/pachli/util/FlowExtensions.kt | 4 +- .../main/java/app/pachli/util/LinkHelper.kt | 2 +- .../main/java/app/pachli/util/LocaleUtils.kt | 2 +- .../main/java/app/pachli/util/MediaUtils.kt | 2 +- app/src/main/java/app/pachli/util/Resource.kt | 4 +- .../main/java/app/pachli/util/SpanUtils.kt | 3 +- .../util/StatusDisplayOptionsRepository.kt | 12 ++++-- .../app/pachli/util/ThrowableExtensions.kt | 2 +- .../app/pachli/view/ClickableSpanTextView.kt | 2 +- .../java/app/pachli/view/SliderPreference.kt | 28 +++++++------- .../app/pachli/viewdata/StatusViewData.kt | 8 +++- .../viewmodel/AccountsInListViewModel.kt | 2 +- .../pachli/viewmodel/EditProfileViewModel.kt | 4 +- .../app/pachli/viewmodel/ListsViewModel.kt | 16 +++++--- .../app/pachli/worker/PruneCacheWorker.kt | 2 +- .../java/app/pachli/worker/WorkerFactory.kt | 2 +- .../app/pachli/BottomSheetActivityTest.kt | 2 +- app/src/test/java/app/pachli/FilterV1Test.kt | 4 +- .../test/java/app/pachli/MainActivityTest.kt | 6 +-- .../components/compose/ComposeActivityTest.kt | 8 ++-- .../CachedTimelineRemoteMediatorTest.kt | 2 +- .../CachedTimelineViewModelTestBase.kt | 6 +-- .../NetworkTimelineViewModelTestBase.kt | 6 +-- .../viewthread/ViewThreadViewModelTest.kt | 8 ++-- .../app/pachli/di/FakeMastodonApiModule.kt | 2 +- .../java/app/pachli/di/FakeNetworkModule.kt | 4 +- .../app/pachli/usecase/TimelineCasesTest.kt | 2 +- .../app/pachli/util/FlowExtensionsTest.kt | 4 +- .../StatusDisplayOptionsRepositoryTest.kt | 6 +-- .../pachli/lint/checks/IntentDetectorTest.kt | 1 + gradle/libs.versions.toml | 2 +- .../kotlin/app/pachli/mklanguages/Main.kt | 8 ++-- .../pachli/mklanguages/ValuesParserTest.kt | 2 +- 122 files changed, 356 insertions(+), 254 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2fe7f0b70..9f545e498 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,14 +7,21 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -# Disable wildcard imports [*.{java,kt}] +ktlint_code_style = android_studio + +ij_kotlin_imports_layout = * + +# Disable wildcard imports ij_kotlin_name_count_to_use_star_import = 999 ij_kotlin_name_count_to_use_star_import_for_members = 999 ij_java_class_count_to_use_import_on_demand = 999 + # Require trailing comma ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true +max_line_length = off + [*.{yml,yaml}] indent_size = 2 diff --git a/app/src/main/java/app/pachli/AboutActivity.kt b/app/src/main/java/app/pachli/AboutActivity.kt index 7e3152dfe..2c81426cf 100644 --- a/app/src/main/java/app/pachli/AboutActivity.kt +++ b/app/src/main/java/app/pachli/AboutActivity.kt @@ -22,8 +22,8 @@ import app.pachli.util.NoUnderlineURLSpan import app.pachli.util.hide import app.pachli.util.show import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.launch @AndroidEntryPoint class AboutActivity : BottomSheetActivity() { diff --git a/app/src/main/java/app/pachli/AccountsInListFragment.kt b/app/src/main/java/app/pachli/AccountsInListFragment.kt index e1dc58f77..d0048a67b 100644 --- a/app/src/main/java/app/pachli/AccountsInListFragment.kt +++ b/app/src/main/java/app/pachli/AccountsInListFragment.kt @@ -45,8 +45,8 @@ import app.pachli.util.viewBinding import app.pachli.viewmodel.AccountsInListViewModel import app.pachli.viewmodel.State import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.launch private typealias AccountInfo = Pair diff --git a/app/src/main/java/app/pachli/BaseActivity.kt b/app/src/main/java/app/pachli/BaseActivity.kt index eae2f5c79..6deb88017 100644 --- a/app/src/main/java/app/pachli/BaseActivity.kt +++ b/app/src/main/java/app/pachli/BaseActivity.kt @@ -51,8 +51,8 @@ import dagger.hilt.InstallIn import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.EntryPointAccessors.fromApplication import dagger.hilt.components.SingletonComponent -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber @AndroidEntryPoint abstract class BaseActivity : AppCompatActivity() { diff --git a/app/src/main/java/app/pachli/BottomSheetActivity.kt b/app/src/main/java/app/pachli/BottomSheetActivity.kt index fc9d38b96..d67e06cfe 100644 --- a/app/src/main/java/app/pachli/BottomSheetActivity.kt +++ b/app/src/main/java/app/pachli/BottomSheetActivity.kt @@ -30,8 +30,8 @@ import app.pachli.util.looksLikeMastodonUrl import app.pachli.util.openLink import at.connyduck.calladapter.networkresult.fold import com.google.android.material.bottomsheet.BottomSheetBehavior -import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.launch /** this is the base class for all activities that open links * links are checked against the api if they are mastodon links so they can be opened in Tusky @@ -97,7 +97,7 @@ abstract class BottomSheetActivity : BaseActivity() { onEndSearch(url) performUrlFallbackAction(url, lookupFallbackBehavior) } - },) + }) } } diff --git a/app/src/main/java/app/pachli/EditProfileActivity.kt b/app/src/main/java/app/pachli/EditProfileActivity.kt index 54923cc5c..82bd4adf6 100644 --- a/app/src/main/java/app/pachli/EditProfileActivity.kt +++ b/app/src/main/java/app/pachli/EditProfileActivity.kt @@ -124,7 +124,10 @@ class EditProfileActivity : BaseActivity() { binding.fieldList.layoutManager = LinearLayoutManager(this) binding.fieldList.adapter = accountFieldEditAdapter - val plusDrawable = IconicsDrawable(this, GoogleMaterial.Icon.gmd_add).apply { sizeDp = 12; colorInt = Color.WHITE } + val plusDrawable = IconicsDrawable(this, GoogleMaterial.Icon.gmd_add).apply { + sizeDp = 12 + colorInt = Color.WHITE + } binding.addFieldButton.setCompoundDrawablesRelativeWithIntrinsicBounds(plusDrawable, null, null, null) diff --git a/app/src/main/java/app/pachli/ListsActivity.kt b/app/src/main/java/app/pachli/ListsActivity.kt index 14879e191..f04e72832 100644 --- a/app/src/main/java/app/pachli/ListsActivity.kt +++ b/app/src/main/java/app/pachli/ListsActivity.kt @@ -237,7 +237,10 @@ class ListsActivity : BaseActivity() { .apply { val iconColor = MaterialColors.getColor(nameTextView, android.R.attr.textColorTertiary) val context = nameTextView.context - val icon = IconicsDrawable(context, GoogleMaterial.Icon.gmd_list).apply { sizeDp = 20; colorInt = iconColor } + val icon = IconicsDrawable(context, GoogleMaterial.Icon.gmd_list).apply { + sizeDp = 20 + colorInt = iconColor + } nameTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null) } diff --git a/app/src/main/java/app/pachli/MainActivity.kt b/app/src/main/java/app/pachli/MainActivity.kt index 16390e368..e258b43c0 100644 --- a/app/src/main/java/app/pachli/MainActivity.kt +++ b/app/src/main/java/app/pachli/MainActivity.kt @@ -153,9 +153,9 @@ import com.mikepenz.materialdrawer.widget.AccountHeaderView import dagger.hilt.android.AndroidEntryPoint import de.c1710.filemojicompat_ui.helpers.EMOJI_PREFERENCE import io.reactivex.rxjava3.schedulers.Schedulers +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { diff --git a/app/src/main/java/app/pachli/PachliApplication.kt b/app/src/main/java/app/pachli/PachliApplication.kt index e0093bfde..67d389172 100644 --- a/app/src/main/java/app/pachli/PachliApplication.kt +++ b/app/src/main/java/app/pachli/PachliApplication.kt @@ -40,11 +40,11 @@ import de.c1710.filemojicompat_defaults.DefaultEmojiPackList import de.c1710.filemojicompat_ui.helpers.EmojiPackHelper import de.c1710.filemojicompat_ui.helpers.EmojiPreference import io.reactivex.rxjava3.plugins.RxJavaPlugins -import org.conscrypt.Conscrypt -import timber.log.Timber import java.security.Security import java.util.concurrent.TimeUnit import javax.inject.Inject +import org.conscrypt.Conscrypt +import timber.log.Timber @HiltAndroidApp class PachliApplication : Application() { diff --git a/app/src/main/java/app/pachli/StatusListActivity.kt b/app/src/main/java/app/pachli/StatusListActivity.kt index 828b1f356..95d560e08 100644 --- a/app/src/main/java/app/pachli/StatusListActivity.kt +++ b/app/src/main/java/app/pachli/StatusListActivity.kt @@ -41,10 +41,10 @@ import com.google.android.material.appbar.AppBarLayout import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.launch import retrofit2.HttpException import timber.log.Timber -import javax.inject.Inject /** * Show a list of statuses of a particular type; containing a particular hashtag, diff --git a/app/src/main/java/app/pachli/TabPreferenceActivity.kt b/app/src/main/java/app/pachli/TabPreferenceActivity.kt index a4b9e081d..5d280f879 100644 --- a/app/src/main/java/app/pachli/TabPreferenceActivity.kt +++ b/app/src/main/java/app/pachli/TabPreferenceActivity.kt @@ -60,14 +60,14 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.material.transition.MaterialArcMotion import com.google.android.material.transition.MaterialContainerTransform import dagger.hilt.android.AndroidEntryPoint +import java.util.regex.Pattern +import javax.inject.Inject import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.delay import kotlinx.coroutines.launch import timber.log.Timber -import java.util.regex.Pattern -import javax.inject.Inject @AndroidEntryPoint class TabPreferenceActivity : BaseActivity(), ItemInteractionListener { diff --git a/app/src/main/java/app/pachli/ViewMediaActivity.kt b/app/src/main/java/app/pachli/ViewMediaActivity.kt index 990a56f0b..9a35b1f5a 100644 --- a/app/src/main/java/app/pachli/ViewMediaActivity.kt +++ b/app/src/main/java/app/pachli/ViewMediaActivity.kt @@ -63,12 +63,12 @@ import dagger.hilt.android.AndroidEntryPoint import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.schedulers.Schedulers -import timber.log.Timber import java.io.File import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException import java.util.Locale +import timber.log.Timber typealias ToolbarVisibilityListener = (isVisible: Boolean) -> Unit diff --git a/app/src/main/java/app/pachli/appstore/CacheUpdater.kt b/app/src/main/java/app/pachli/appstore/CacheUpdater.kt index 1e68b41b2..d463b2195 100644 --- a/app/src/main/java/app/pachli/appstore/CacheUpdater.kt +++ b/app/src/main/java/app/pachli/appstore/CacheUpdater.kt @@ -3,12 +3,12 @@ package app.pachli.appstore import app.pachli.core.accounts.AccountManager import app.pachli.core.database.dao.TimelineDao import com.google.gson.Gson +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.launch -import javax.inject.Inject class CacheUpdater @Inject constructor( eventHub: EventHub, diff --git a/app/src/main/java/app/pachli/appstore/EventsHub.kt b/app/src/main/java/app/pachli/appstore/EventsHub.kt index 991ec8c93..f3f27256d 100644 --- a/app/src/main/java/app/pachli/appstore/EventsHub.kt +++ b/app/src/main/java/app/pachli/appstore/EventsHub.kt @@ -1,9 +1,9 @@ package app.pachli.appstore -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableSharedFlow import javax.inject.Inject import javax.inject.Singleton +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableSharedFlow interface Event diff --git a/app/src/main/java/app/pachli/components/account/AccountViewModel.kt b/app/src/main/java/app/pachli/components/account/AccountViewModel.kt index a3c5c33ee..cc91ed06c 100644 --- a/app/src/main/java/app/pachli/components/account/AccountViewModel.kt +++ b/app/src/main/java/app/pachli/components/account/AccountViewModel.kt @@ -20,11 +20,11 @@ import app.pachli.util.Success import app.pachli.util.getDomain import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class AccountViewModel @Inject constructor( @@ -137,8 +137,8 @@ class AccountViewModel @Inject constructor( fun changeSubscribingState() { val relationship = relationshipData.value?.data - if (relationship?.notifying == true || /* Mastodon 3.3.0rc1 */ - relationship?.subscribing == true /* Pleroma */ + if (relationship?.notifying == true || // Mastodon 3.3.0rc1 + relationship?.subscribing == true // Pleroma ) { changeRelationship(RelationShipAction.UNSUBSCRIBE) } else { @@ -156,7 +156,7 @@ class AccountViewModel @Inject constructor( } }, { e -> Timber.e("Error muting $instance", e) - },) + }) } } @@ -169,7 +169,7 @@ class AccountViewModel @Inject constructor( } }, { e -> Timber.e("Error unmuting $instance", e) - },) + }) } } @@ -317,6 +317,13 @@ class AccountViewModel @Inject constructor( } enum class RelationShipAction { - FOLLOW, UNFOLLOW, BLOCK, UNBLOCK, MUTE, UNMUTE, SUBSCRIBE, UNSUBSCRIBE + FOLLOW, + UNFOLLOW, + BLOCK, + UNBLOCK, + MUTE, + UNMUTE, + SUBSCRIBE, + UNSUBSCRIBE, } } diff --git a/app/src/main/java/app/pachli/components/account/list/ListsForAccountViewModel.kt b/app/src/main/java/app/pachli/components/account/list/ListsForAccountViewModel.kt index a41208f7d..5fe1f5316 100644 --- a/app/src/main/java/app/pachli/components/account/list/ListsForAccountViewModel.kt +++ b/app/src/main/java/app/pachli/components/account/list/ListsForAccountViewModel.kt @@ -25,6 +25,7 @@ import at.connyduck.calladapter.networkresult.onFailure import at.connyduck.calladapter.networkresult.onSuccess import at.connyduck.calladapter.networkresult.runCatching import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -32,7 +33,6 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch -import javax.inject.Inject data class AccountListState( val list: MastoList, diff --git a/app/src/main/java/app/pachli/components/account/media/AccountMediaFragment.kt b/app/src/main/java/app/pachli/components/account/media/AccountMediaFragment.kt index e3b1c46d2..cdc046b95 100644 --- a/app/src/main/java/app/pachli/components/account/media/AccountMediaFragment.kt +++ b/app/src/main/java/app/pachli/components/account/media/AccountMediaFragment.kt @@ -50,9 +50,9 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import javax.inject.Inject /** * Fragment with multiple columns of media previews for the specified account. diff --git a/app/src/main/java/app/pachli/components/accountlist/AccountListFragment.kt b/app/src/main/java/app/pachli/components/accountlist/AccountListFragment.kt index 1fb2a7f1f..6b8312698 100644 --- a/app/src/main/java/app/pachli/components/accountlist/AccountListFragment.kt +++ b/app/src/main/java/app/pachli/components/accountlist/AccountListFragment.kt @@ -64,11 +64,11 @@ import com.google.android.material.color.MaterialColors import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import java.io.IOException +import javax.inject.Inject import kotlinx.coroutines.launch import retrofit2.Response import timber.log.Timber -import java.io.IOException -import javax.inject.Inject @AndroidEntryPoint class AccountListFragment : @@ -228,7 +228,7 @@ class AccountListFragment : onBlockSuccess(block, id, position) }, { onBlockFailure(block, id, it) - },) + }) } } diff --git a/app/src/main/java/app/pachli/components/announcements/AnnouncementAdapter.kt b/app/src/main/java/app/pachli/components/announcements/AnnouncementAdapter.kt index 738b09de7..4817a78fb 100644 --- a/app/src/main/java/app/pachli/components/announcements/AnnouncementAdapter.kt +++ b/app/src/main/java/app/pachli/components/announcements/AnnouncementAdapter.kt @@ -130,7 +130,13 @@ class AnnouncementAdapter( spanBuilder.setSpan(span, 0, 1, 0) Glide.with(this) .asDrawable() - .load(if (animateEmojis) { reaction.url } else { reaction.staticUrl }) + .load( + if (animateEmojis) { + reaction.url + } else { + reaction.staticUrl + }, + ) .into(span.getTarget(animateEmojis)) this.text = spanBuilder } diff --git a/app/src/main/java/app/pachli/components/announcements/AnnouncementsViewModel.kt b/app/src/main/java/app/pachli/components/announcements/AnnouncementsViewModel.kt index 80c3b0b65..61ae25f11 100644 --- a/app/src/main/java/app/pachli/components/announcements/AnnouncementsViewModel.kt +++ b/app/src/main/java/app/pachli/components/announcements/AnnouncementsViewModel.kt @@ -32,9 +32,9 @@ import app.pachli.util.Resource import app.pachli.util.Success import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class AnnouncementsViewModel @Inject constructor( diff --git a/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt b/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt index dd7881001..d13580c93 100644 --- a/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt +++ b/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt @@ -111,17 +111,17 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch -import timber.log.Timber import java.io.File import java.io.IOException import java.text.DecimalFormat import java.util.Locale import kotlin.math.max import kotlin.math.min +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.launch +import timber.log.Timber /** * Compose a status, either by creating one from scratch, or by editing an existing @@ -186,7 +186,8 @@ class ComposeActivity : uriNew, size, itemOld.description, - null, // Intentionally reset focus when cropping + // Intentionally reset focus when cropping + null, itemOld, ) } @@ -515,13 +516,22 @@ class ComposeActivity : val textColor = MaterialColors.getColor(binding.root, android.R.attr.textColorTertiary) - val cameraIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).apply { colorInt = textColor; sizeDp = 18 } + val cameraIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).apply { + colorInt = textColor + sizeDp = 18 + } binding.actionPhotoTake.setCompoundDrawablesRelativeWithIntrinsicBounds(cameraIcon, null, null, null) - val imageIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).apply { colorInt = textColor; sizeDp = 18 } + val imageIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).apply { + colorInt = textColor + sizeDp = 18 + } binding.actionPhotoPick.setCompoundDrawablesRelativeWithIntrinsicBounds(imageIcon, null, null, null) - val pollIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_poll).apply { colorInt = textColor; sizeDp = 18 } + val pollIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_poll).apply { + colorInt = textColor + sizeDp = 18 + } binding.addPollTextActionTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(pollIcon, null, null, null) binding.actionPhotoTake.visible(Intent(MediaStore.ACTION_IMAGE_CAPTURE).resolveActivity(packageManager) != null) @@ -1274,10 +1284,15 @@ class ComposeActivity : val state: State, ) { enum class Type { - IMAGE, VIDEO, AUDIO; + IMAGE, + VIDEO, + AUDIO, } enum class State { - UPLOADING, UNPROCESSED, PROCESSED, PUBLISHED + UPLOADING, + UNPROCESSED, + PROCESSED, + PUBLISHED, } } diff --git a/app/src/main/java/app/pachli/components/compose/ComposeViewModel.kt b/app/src/main/java/app/pachli/components/compose/ComposeViewModel.kt index d05a6bdf6..2eb86ba29 100644 --- a/app/src/main/java/app/pachli/components/compose/ComposeViewModel.kt +++ b/app/src/main/java/app/pachli/components/compose/ComposeViewModel.kt @@ -40,6 +40,7 @@ import app.pachli.service.ServiceClient import app.pachli.service.StatusToSend import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow @@ -53,7 +54,6 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber -import javax.inject.Inject @HiltViewModel class ComposeViewModel @Inject constructor( @@ -168,7 +168,11 @@ class ComposeViewModel @Inject constructor( item.copy( id = event.mediaId, uploadPercent = -1, - state = if (event.processed) { QueuedMedia.State.PROCESSED } else { QueuedMedia.State.UNPROCESSED }, + state = if (event.processed) { + QueuedMedia.State.PROCESSED + } else { + QueuedMedia.State.UNPROCESSED + }, ) is UploadEvent.ErrorEvent -> { media.update { mediaList -> mediaList.filter { it.localId != mediaItem.localId } } @@ -383,7 +387,7 @@ class ComposeViewModel @Inject constructor( }, { e -> Timber.e("Autocomplete search for $token failed.", e) emptyList() - },) + }) } '#' -> { return api.searchSync(query = token, type = SearchType.Hashtag.apiParameter, limit = 10) @@ -392,7 +396,7 @@ class ComposeViewModel @Inject constructor( }, { e -> Timber.e("Autocomplete search for $token failed.", e) emptyList() - },) + }) } ':' -> { val emojiList = emoji.replayCache.firstOrNull() ?: return emptyList() diff --git a/app/src/main/java/app/pachli/components/compose/ImageDownsizer.kt b/app/src/main/java/app/pachli/components/compose/ImageDownsizer.kt index 65b178bc9..a4c2a6bd4 100644 --- a/app/src/main/java/app/pachli/components/compose/ImageDownsizer.kt +++ b/app/src/main/java/app/pachli/components/compose/ImageDownsizer.kt @@ -52,10 +52,10 @@ fun downsizeImage( // Get EXIF data, for orientation info. val orientation = getImageOrientation(uri, contentResolver) /* Unfortunately, there isn't a determined worst case compression ratio for image - * formats. So, the only way to tell if they're too big is to compress them and - * test, and keep trying at smaller sizes. The initial estimate should be good for - * many cases, so it should only iterate once, but the loop is used to be absolutely - * sure it gets downsized to below the limit. */ + * formats. So, the only way to tell if they're too big is to compress them and + * test, and keep trying at smaller sizes. The initial estimate should be good for + * many cases, so it should only iterate once, but the loop is used to be absolutely + * sure it gets downsized to below the limit. */ var scaledImageSize = 1024 do { val outputStream = try { diff --git a/app/src/main/java/app/pachli/components/compose/MediaUploader.kt b/app/src/main/java/app/pachli/components/compose/MediaUploader.kt index 0e54a73ea..9f7398514 100644 --- a/app/src/main/java/app/pachli/components/compose/MediaUploader.kt +++ b/app/src/main/java/app/pachli/components/compose/MediaUploader.kt @@ -38,6 +38,13 @@ import app.pachli.util.getImageSquarePixels import app.pachli.util.getMediaSize import app.pachli.util.getServerErrorMessage import dagger.hilt.android.qualifiers.ApplicationContext +import java.io.File +import java.io.FileInputStream +import java.io.FileOutputStream +import java.io.IOException +import java.util.Date +import javax.inject.Inject +import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -56,13 +63,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import retrofit2.HttpException import timber.log.Timber -import java.io.File -import java.io.FileInputStream -import java.io.FileOutputStream -import java.io.IOException -import java.util.Date -import javax.inject.Inject -import javax.inject.Singleton sealed interface FinalUploadEvent @@ -85,9 +85,9 @@ fun createNewImageFile(context: Context, suffix: String = ".jpg"): File { val imageFileName = "Pachli_${randomId}_" val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) return File.createTempFile( - imageFileName, /* prefix */ - suffix, /* suffix */ - storageDir, /* directory */ + imageFileName, + suffix, + storageDir, ) } @@ -259,9 +259,9 @@ class MediaUploader @Inject constructor( // .m4a files. See https://github.com/tuskyapp/Tusky/issues/3189 for details. // Sniff the content of the file to determine the actual type. if (mimeType != null && ( - mimeType.startsWith("audio/", ignoreCase = true) || - mimeType.startsWith("video/", ignoreCase = true) - ) + mimeType.startsWith("audio/", ignoreCase = true) || + mimeType.startsWith("video/", ignoreCase = true) + ) ) { val retriever = MediaMetadataRetriever() retriever.setDataSource(context, media.uri) diff --git a/app/src/main/java/app/pachli/components/compose/dialog/AddPollDialog.kt b/app/src/main/java/app/pachli/components/compose/dialog/AddPollDialog.kt index 15f8dc191..65c05ddbc 100644 --- a/app/src/main/java/app/pachli/components/compose/dialog/AddPollDialog.kt +++ b/app/src/main/java/app/pachli/components/compose/dialog/AddPollDialog.kt @@ -25,6 +25,8 @@ import app.pachli.R import app.pachli.core.network.model.NewPoll import app.pachli.databinding.DialogAddPollBinding +const val DAY_SECONDS = 60 * 60 * 24 + fun showAddPollDialog( context: Context, poll: NewPoll?, @@ -74,7 +76,6 @@ fun showAddPollDialog( } } - val DAY_SECONDS = 60 * 60 * 24 val desiredDuration = poll?.expiresIn ?: DAY_SECONDS val pollDurationId = durations.indexOfLast { it <= desiredDuration diff --git a/app/src/main/java/app/pachli/components/compose/view/ComposeScheduleView.kt b/app/src/main/java/app/pachli/components/compose/view/ComposeScheduleView.kt index 4877d38ae..86b1023b0 100644 --- a/app/src/main/java/app/pachli/components/compose/view/ComposeScheduleView.kt +++ b/app/src/main/java/app/pachli/components/compose/view/ComposeScheduleView.kt @@ -225,7 +225,7 @@ class ComposeScheduleView } companion object { - var MINIMUM_SCHEDULED_SECONDS = 330 // Minimum is 5 minutes, pad 30 seconds for posting + const val MINIMUM_SCHEDULED_SECONDS = 330 // Minimum is 5 minutes, pad 30 seconds for posting fun calendar(): Calendar = Calendar.getInstance(TimeZone.getDefault()) } } diff --git a/app/src/main/java/app/pachli/components/compose/view/TootButton.kt b/app/src/main/java/app/pachli/components/compose/view/TootButton.kt index 013299fe6..0de8aae37 100644 --- a/app/src/main/java/app/pachli/components/compose/view/TootButton.kt +++ b/app/src/main/java/app/pachli/components/compose/view/TootButton.kt @@ -62,7 +62,10 @@ class TootButton Status.Visibility.DIRECT, -> { setText(R.string.action_send) - IconicsDrawable(context, GoogleMaterial.Icon.gmd_lock).apply { sizeDp = 18; colorInt = Color.WHITE } + IconicsDrawable(context, GoogleMaterial.Icon.gmd_lock).apply { + sizeDp = 18 + colorInt = Color.WHITE + } } else -> { null diff --git a/app/src/main/java/app/pachli/components/conversation/ConversationsFragment.kt b/app/src/main/java/app/pachli/components/conversation/ConversationsFragment.kt index 612471eea..324fd595a 100644 --- a/app/src/main/java/app/pachli/components/conversation/ConversationsFragment.kt +++ b/app/src/main/java/app/pachli/components/conversation/ConversationsFragment.kt @@ -61,13 +61,13 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject +import kotlin.time.DurationUnit +import kotlin.time.toDuration import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.launch -import javax.inject.Inject -import kotlin.time.DurationUnit -import kotlin.time.toDuration @AndroidEntryPoint class ConversationsFragment : diff --git a/app/src/main/java/app/pachli/components/conversation/ConversationsViewModel.kt b/app/src/main/java/app/pachli/components/conversation/ConversationsViewModel.kt index 8b130aeba..e56e3efe6 100644 --- a/app/src/main/java/app/pachli/components/conversation/ConversationsViewModel.kt +++ b/app/src/main/java/app/pachli/components/conversation/ConversationsViewModel.kt @@ -32,10 +32,10 @@ import app.pachli.usecase.TimelineCases import app.pachli.util.EmptyPagingSource import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class ConversationsViewModel @Inject constructor( @@ -81,7 +81,7 @@ class ConversationsViewModel @Inject constructor( saveConversationToDb(newConversation) }, { e -> Timber.w("failed to favourite status", e) - },) + }) } } @@ -96,7 +96,7 @@ class ConversationsViewModel @Inject constructor( saveConversationToDb(newConversation) }, { e -> Timber.w("failed to bookmark status", e) - },) + }) } } @@ -112,7 +112,7 @@ class ConversationsViewModel @Inject constructor( saveConversationToDb(newConversation) }, { e -> Timber.w("failed to vote in poll", e) - },) + }) } } diff --git a/app/src/main/java/app/pachli/components/drafts/DraftHelper.kt b/app/src/main/java/app/pachli/components/drafts/DraftHelper.kt index 713bc11e6..6bff0ee23 100644 --- a/app/src/main/java/app/pachli/components/drafts/DraftHelper.kt +++ b/app/src/main/java/app/pachli/components/drafts/DraftHelper.kt @@ -30,6 +30,12 @@ import app.pachli.core.network.model.NewPoll import app.pachli.core.network.model.Status import app.pachli.util.copyToFile import dagger.hilt.android.qualifiers.ApplicationContext +import java.io.File +import java.io.IOException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale +import javax.inject.Inject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.OkHttpClient @@ -37,12 +43,6 @@ import okhttp3.Request import okio.buffer import okio.sink import timber.log.Timber -import java.io.File -import java.io.IOException -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale -import javax.inject.Inject class DraftHelper @Inject constructor( @ApplicationContext val context: Context, diff --git a/app/src/main/java/app/pachli/components/drafts/DraftsActivity.kt b/app/src/main/java/app/pachli/components/drafts/DraftsActivity.kt index ff28ae210..22b12a62f 100644 --- a/app/src/main/java/app/pachli/components/drafts/DraftsActivity.kt +++ b/app/src/main/java/app/pachli/components/drafts/DraftsActivity.kt @@ -37,11 +37,11 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import retrofit2.HttpException import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class DraftsActivity : BaseActivity(), DraftActionListener { diff --git a/app/src/main/java/app/pachli/components/drafts/DraftsViewModel.kt b/app/src/main/java/app/pachli/components/drafts/DraftsViewModel.kt index f11e20add..a4b4e850d 100644 --- a/app/src/main/java/app/pachli/components/drafts/DraftsViewModel.kt +++ b/app/src/main/java/app/pachli/components/drafts/DraftsViewModel.kt @@ -28,8 +28,8 @@ import app.pachli.core.network.model.Status import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.NetworkResult import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.launch @HiltViewModel class DraftsViewModel @Inject constructor( diff --git a/app/src/main/java/app/pachli/components/filters/EditFilterActivity.kt b/app/src/main/java/app/pachli/components/filters/EditFilterActivity.kt index 1a7493bbd..55d42345b 100644 --- a/app/src/main/java/app/pachli/components/filters/EditFilterActivity.kt +++ b/app/src/main/java/app/pachli/components/filters/EditFilterActivity.kt @@ -27,10 +27,10 @@ import com.google.android.material.chip.Chip import com.google.android.material.snackbar.Snackbar import com.google.android.material.switchmaterial.SwitchMaterial import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch -import retrofit2.HttpException import java.util.Date import javax.inject.Inject +import kotlinx.coroutines.launch +import retrofit2.HttpException /** * Edit a single server-side filter. @@ -302,7 +302,11 @@ class EditFilterActivity : BaseActivity() { // but create/edit take a number of seconds (relative to the time the operation is posted) fun getSecondsForDurationIndex(index: Int, context: Context?, default: Date? = null): Int? { return when (index) { - -1 -> if (default == null) { default } else { ((default.time - System.currentTimeMillis()) / 1000).toInt() } + -1 -> if (default == null) { + default + } else { + ((default.time - System.currentTimeMillis()) / 1000).toInt() + } 0 -> null else -> context?.resources?.getIntArray(R.array.filter_duration_values)?.get(index) } diff --git a/app/src/main/java/app/pachli/components/filters/EditFilterViewModel.kt b/app/src/main/java/app/pachli/components/filters/EditFilterViewModel.kt index 681986e4d..04b1750e9 100644 --- a/app/src/main/java/app/pachli/components/filters/EditFilterViewModel.kt +++ b/app/src/main/java/app/pachli/components/filters/EditFilterViewModel.kt @@ -10,10 +10,10 @@ import app.pachli.core.network.model.FilterKeyword import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.withContext import retrofit2.HttpException -import javax.inject.Inject @HiltViewModel class EditFilterViewModel @Inject constructor(val api: MastodonApi, val eventHub: EventHub) : ViewModel() { diff --git a/app/src/main/java/app/pachli/components/filters/FiltersViewModel.kt b/app/src/main/java/app/pachli/components/filters/FiltersViewModel.kt index b10f567d2..e6ea4ea93 100644 --- a/app/src/main/java/app/pachli/components/filters/FiltersViewModel.kt +++ b/app/src/main/java/app/pachli/components/filters/FiltersViewModel.kt @@ -10,11 +10,11 @@ import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import retrofit2.HttpException -import javax.inject.Inject @HiltViewModel class FiltersViewModel @Inject constructor( @@ -23,7 +23,11 @@ class FiltersViewModel @Inject constructor( ) : ViewModel() { enum class LoadingState { - INITIAL, LOADING, LOADED, ERROR_NETWORK, ERROR_OTHER + INITIAL, + LOADING, + LOADED, + ERROR_NETWORK, + ERROR_OTHER, } data class State(val filters: List, val loadingState: LoadingState) diff --git a/app/src/main/java/app/pachli/components/followedtags/FollowedTagsActivity.kt b/app/src/main/java/app/pachli/components/followedtags/FollowedTagsActivity.kt index 0ab3b82d7..a472a4906 100644 --- a/app/src/main/java/app/pachli/components/followedtags/FollowedTagsActivity.kt +++ b/app/src/main/java/app/pachli/components/followedtags/FollowedTagsActivity.kt @@ -27,10 +27,10 @@ import at.connyduck.calladapter.networkresult.fold import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class FollowedTagsActivity : diff --git a/app/src/main/java/app/pachli/components/followedtags/FollowedTagsViewModel.kt b/app/src/main/java/app/pachli/components/followedtags/FollowedTagsViewModel.kt index 6167b395b..6e703f6e1 100644 --- a/app/src/main/java/app/pachli/components/followedtags/FollowedTagsViewModel.kt +++ b/app/src/main/java/app/pachli/components/followedtags/FollowedTagsViewModel.kt @@ -12,8 +12,8 @@ import app.pachli.core.network.model.HashTag import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber @HiltViewModel class FollowedTagsViewModel @Inject constructor( @@ -43,6 +43,6 @@ class FollowedTagsViewModel @Inject constructor( }, { e -> Timber.e("Autocomplete search for $token failed.", e) emptyList() - },) + }) } } diff --git a/app/src/main/java/app/pachli/components/instanceinfo/InstanceInfoRepository.kt b/app/src/main/java/app/pachli/components/instanceinfo/InstanceInfoRepository.kt index 73215e7ed..fbcfbf8c1 100644 --- a/app/src/main/java/app/pachli/components/instanceinfo/InstanceInfoRepository.kt +++ b/app/src/main/java/app/pachli/components/instanceinfo/InstanceInfoRepository.kt @@ -25,10 +25,10 @@ import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import at.connyduck.calladapter.networkresult.getOrElse import at.connyduck.calladapter.networkresult.onSuccess +import javax.inject.Inject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber -import javax.inject.Inject class InstanceInfoRepository @Inject constructor( private val api: MastodonApi, @@ -77,12 +77,18 @@ class InstanceInfoRepository @Inject constructor( maxFieldNameLength = instance.pleroma?.metadata?.fieldLimits?.nameLength, maxFieldValueLength = instance.pleroma?.metadata?.fieldLimits?.valueLength, ) - try { instanceDao.upsert(instanceEntity) } catch (_: Exception) { } + try { + instanceDao.upsert(instanceEntity) + } catch (_: Exception) { } instanceEntity }, { throwable -> Timber.w("failed to instance, falling back to cache and default values", throwable) - try { instanceDao.getInstanceInfo(instanceName) } catch (_: Exception) { null } + try { + instanceDao.getInstanceInfo(instanceName) + } catch (_: Exception) { + null + } }, ).let { instanceInfo: InstanceInfoEntity? -> InstanceInfo( diff --git a/app/src/main/java/app/pachli/components/instancemute/fragment/InstanceListFragment.kt b/app/src/main/java/app/pachli/components/instancemute/fragment/InstanceListFragment.kt index 9e44fb4e4..634db3ff2 100644 --- a/app/src/main/java/app/pachli/components/instancemute/fragment/InstanceListFragment.kt +++ b/app/src/main/java/app/pachli/components/instancemute/fragment/InstanceListFragment.kt @@ -20,9 +20,9 @@ import at.connyduck.calladapter.networkresult.fold import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class InstanceListFragment : @@ -71,7 +71,7 @@ class InstanceListFragment : adapter.addItem(instance) }, { e -> Timber.e("Error muting domain $instance", e) - },) + }) } else { api.unblockDomain(instance).fold({ adapter.removeItem(position) @@ -82,7 +82,7 @@ class InstanceListFragment : .show() }, { e -> Timber.e("Error unmuting domain $instance", e) - },) + }) } } } diff --git a/app/src/main/java/app/pachli/components/login/LoginActivity.kt b/app/src/main/java/app/pachli/components/login/LoginActivity.kt index 13c893c08..cc8ec51f1 100644 --- a/app/src/main/java/app/pachli/components/login/LoginActivity.kt +++ b/app/src/main/java/app/pachli/components/login/LoginActivity.kt @@ -44,10 +44,10 @@ import app.pachli.util.viewBinding import at.connyduck.calladapter.networkresult.fold import com.bumptech.glide.Glide import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.launch import okhttp3.HttpUrl import timber.log.Timber -import javax.inject.Inject /** * Main login page, the first thing that users see. @@ -333,7 +333,7 @@ class LoginActivity : BaseActivity() { binding.domainTextInputLayout.error = getString(R.string.error_loading_account_details) Timber.e(getString(R.string.error_loading_account_details), e) - },) + }) } private fun setLoading(loadingState: Boolean) { diff --git a/app/src/main/java/app/pachli/components/login/LoginWebViewViewModel.kt b/app/src/main/java/app/pachli/components/login/LoginWebViewViewModel.kt index d05984ed9..639e55367 100644 --- a/app/src/main/java/app/pachli/components/login/LoginWebViewViewModel.kt +++ b/app/src/main/java/app/pachli/components/login/LoginWebViewViewModel.kt @@ -21,10 +21,10 @@ import androidx.lifecycle.viewModelScope import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class LoginWebViewViewModel @Inject constructor( @@ -43,7 +43,7 @@ class LoginWebViewViewModel @Inject constructor( instanceRules.value = instance.rules?.map { rule -> rule.text }.orEmpty() }, { throwable -> Timber.w("failed to load instance info", throwable) - },) + }) } } } diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationFetcher.kt b/app/src/main/java/app/pachli/components/notifications/NotificationFetcher.kt index f17e11a75..28afa8dec 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationFetcher.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationFetcher.kt @@ -28,11 +28,11 @@ import app.pachli.core.network.model.Marker import app.pachli.core.network.model.Notification import app.pachli.core.network.retrofit.MastodonApi import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.delay -import timber.log.Timber import javax.inject.Inject import kotlin.math.min import kotlin.time.Duration.Companion.milliseconds +import kotlinx.coroutines.delay +import timber.log.Timber /** * Fetch Mastodon notifications and show Android notifications, with summaries, for them. diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationHelper.kt b/app/src/main/java/app/pachli/components/notifications/NotificationHelper.kt index d797a65f2..f76aa6e23 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationHelper.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationHelper.kt @@ -57,9 +57,9 @@ import app.pachli.viewdata.calculatePercent import app.pachli.worker.NotificationWorker import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.RoundedCorners -import timber.log.Timber import java.util.concurrent.ExecutionException import java.util.concurrent.TimeUnit +import timber.log.Timber /** ID of notification shown when fetching notifications */ const val NOTIFICATION_ID_FETCH_NOTIFICATION = 0 diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt index 5774e1967..741e5fc6c 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt @@ -324,7 +324,8 @@ class NotificationsFragment : when (it) { is UiSuccess.Block, is UiSuccess.Mute, is UiSuccess.MuteConversation -> adapter.refresh() - else -> { /* nothing to do */ + else -> { + /* nothing to do */ } } } diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsPagingSource.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsPagingSource.kt index a842efb26..a4bd16ae1 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationsPagingSource.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsPagingSource.kt @@ -25,12 +25,12 @@ import app.pachli.core.network.model.Links import app.pachli.core.network.model.Notification import app.pachli.core.network.retrofit.MastodonApi import com.google.gson.Gson +import javax.inject.Inject import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import okhttp3.Headers import retrofit2.Response import timber.log.Timber -import javax.inject.Inject private val INVALID = LoadResult.Invalid() diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsRepository.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsRepository.kt index 8bd117d06..337fbadd1 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationsRepository.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsRepository.kt @@ -26,13 +26,13 @@ import app.pachli.core.common.di.ApplicationScope import app.pachli.core.network.model.Notification import app.pachli.core.network.retrofit.MastodonApi import com.google.gson.Gson +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow import okhttp3.ResponseBody import retrofit2.Response import timber.log.Timber -import javax.inject.Inject class NotificationsRepository @Inject constructor( private val mastodonApi: MastodonApi, diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsViewModel.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsViewModel.kt index 4774103a1..aa5d08f5a 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationsViewModel.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsViewModel.kt @@ -49,6 +49,8 @@ import app.pachli.viewdata.NotificationViewData import app.pachli.viewdata.StatusViewData import at.connyduck.calladapter.networkresult.getOrThrow import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow @@ -72,8 +74,6 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import retrofit2.HttpException import timber.log.Timber -import javax.inject.Inject -import kotlin.time.Duration.Companion.milliseconds data class UiState( /** Filtered notification types */ @@ -333,6 +333,7 @@ class NotificationsViewModel @Inject constructor( // message, as it will be confusing to the user. val uiSuccess = MutableSharedFlow() + @Suppress("ktlint:standard:property-naming") /** Channel for error results */ // Errors are sent to a channel to ensure that any errors that occur *before* there are any // subscribers are retained. If this was a SharedFlow any errors would be dropped, and if it diff --git a/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt b/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt index fd81905c6..bb50c082e 100644 --- a/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt +++ b/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt @@ -55,11 +55,11 @@ import com.google.android.material.snackbar.Snackbar import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import retrofit2.Call import retrofit2.Callback import retrofit2.Response import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class AccountPreferencesFragment : PreferenceFragmentCompat() { diff --git a/app/src/main/java/app/pachli/components/preference/PreferencesActivity.kt b/app/src/main/java/app/pachli/components/preference/PreferencesActivity.kt index bfdf2db99..59dc6e8b1 100644 --- a/app/src/main/java/app/pachli/components/preference/PreferencesActivity.kt +++ b/app/src/main/java/app/pachli/components/preference/PreferencesActivity.kt @@ -36,10 +36,10 @@ import app.pachli.core.preferences.PrefKeys.APP_THEME import app.pachli.databinding.ActivityPreferencesBinding import app.pachli.util.setAppNightMode import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject /** * Show specific preferences. diff --git a/app/src/main/java/app/pachli/components/report/ReportViewModel.kt b/app/src/main/java/app/pachli/components/report/ReportViewModel.kt index d344049bc..3a6bdb8a0 100644 --- a/app/src/main/java/app/pachli/components/report/ReportViewModel.kt +++ b/app/src/main/java/app/pachli/components/report/ReportViewModel.kt @@ -40,12 +40,12 @@ import app.pachli.util.Success import app.pachli.viewdata.StatusViewData import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch -import javax.inject.Inject @HiltViewModel class ReportViewModel @Inject constructor( @@ -195,7 +195,7 @@ class ReportViewModel @Inject constructor( } }, { t -> blockStateMutable.value = Error(false, t.message) - },) + }) } blockStateMutable.value = Loading() } @@ -208,7 +208,7 @@ class ReportViewModel @Inject constructor( reportingStateMutable.value = Success(true) }, { error -> reportingStateMutable.value = Error(cause = error) - },) + }) } } diff --git a/app/src/main/java/app/pachli/components/report/fragments/ReportStatusesFragment.kt b/app/src/main/java/app/pachli/components/report/fragments/ReportStatusesFragment.kt index a0bfd98e9..1c3992b8b 100644 --- a/app/src/main/java/app/pachli/components/report/fragments/ReportStatusesFragment.kt +++ b/app/src/main/java/app/pachli/components/report/fragments/ReportStatusesFragment.kt @@ -55,9 +55,9 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import javax.inject.Inject @AndroidEntryPoint class ReportStatusesFragment : diff --git a/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusActivity.kt b/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusActivity.kt index a03fac186..31df1afe3 100644 --- a/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusActivity.kt +++ b/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusActivity.kt @@ -44,9 +44,9 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import javax.inject.Inject @AndroidEntryPoint class ScheduledStatusActivity : diff --git a/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusViewModel.kt b/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusViewModel.kt index 03f85ccec..da958e86a 100644 --- a/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusViewModel.kt +++ b/app/src/main/java/app/pachli/components/scheduled/ScheduledStatusViewModel.kt @@ -26,9 +26,9 @@ import app.pachli.core.network.model.ScheduledStatus import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class ScheduledStatusViewModel @Inject constructor( diff --git a/app/src/main/java/app/pachli/components/search/SearchViewModel.kt b/app/src/main/java/app/pachli/components/search/SearchViewModel.kt index f9b6630e3..84a7ad07c 100644 --- a/app/src/main/java/app/pachli/components/search/SearchViewModel.kt +++ b/app/src/main/java/app/pachli/components/search/SearchViewModel.kt @@ -33,11 +33,11 @@ import at.connyduck.calladapter.networkresult.NetworkResult import at.connyduck.calladapter.networkresult.fold import at.connyduck.calladapter.networkresult.onFailure import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @HiltViewModel class SearchViewModel @Inject constructor( @@ -127,7 +127,7 @@ class SearchViewModel @Inject constructor( ) }, { t -> Timber.d("Failed to reblog status ${statusViewData.id}", t) - },) + }) } } diff --git a/app/src/main/java/app/pachli/components/search/fragments/SearchAccountsFragment.kt b/app/src/main/java/app/pachli/components/search/fragments/SearchAccountsFragment.kt index 251d4d723..007d412de 100644 --- a/app/src/main/java/app/pachli/components/search/fragments/SearchAccountsFragment.kt +++ b/app/src/main/java/app/pachli/components/search/fragments/SearchAccountsFragment.kt @@ -26,8 +26,8 @@ import app.pachli.core.preferences.PrefKeys import app.pachli.core.preferences.SharedPreferencesRepository import com.google.android.material.divider.MaterialDividerItemDecoration import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.Flow import javax.inject.Inject +import kotlinx.coroutines.flow.Flow @AndroidEntryPoint class SearchAccountsFragment : SearchFragment() { diff --git a/app/src/main/java/app/pachli/components/search/fragments/SearchFragment.kt b/app/src/main/java/app/pachli/components/search/fragments/SearchFragment.kt index 0a1252a38..5927da36e 100644 --- a/app/src/main/java/app/pachli/components/search/fragments/SearchFragment.kt +++ b/app/src/main/java/app/pachli/components/search/fragments/SearchFragment.kt @@ -32,10 +32,10 @@ import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import javax.inject.Inject abstract class SearchFragment : Fragment(R.layout.fragment_search), diff --git a/app/src/main/java/app/pachli/components/search/fragments/SearchStatusesFragment.kt b/app/src/main/java/app/pachli/components/search/fragments/SearchStatusesFragment.kt index 5e613aaa2..f5ead6be8 100644 --- a/app/src/main/java/app/pachli/components/search/fragments/SearchStatusesFragment.kt +++ b/app/src/main/java/app/pachli/components/search/fragments/SearchStatusesFragment.kt @@ -58,10 +58,10 @@ import at.connyduck.calladapter.networkresult.fold import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class SearchStatusesFragment : SearchFragment(), StatusActionListener { diff --git a/app/src/main/java/app/pachli/components/timeline/CachedTimelineRepository.kt b/app/src/main/java/app/pachli/components/timeline/CachedTimelineRepository.kt index 68c675868..bdb218177 100644 --- a/app/src/main/java/app/pachli/components/timeline/CachedTimelineRepository.kt +++ b/app/src/main/java/app/pachli/components/timeline/CachedTimelineRepository.kt @@ -41,14 +41,14 @@ import app.pachli.viewdata.StatusViewData import at.connyduck.calladapter.networkresult.NetworkResult import at.connyduck.calladapter.networkresult.fold import com.google.gson.Gson +import javax.inject.Inject +import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton // TODO: This is very similar to NetworkTimelineRepository. They could be merged (and the use // of the cache be made a parameter to getStatusStream), except that they return Pagers of @@ -213,7 +213,7 @@ class CachedTimelineRepository @Inject constructor( }, { // Reset the translation state saveStatusViewData(statusViewData) - },) + }) return translation } diff --git a/app/src/main/java/app/pachli/components/timeline/FiltersRepository.kt b/app/src/main/java/app/pachli/components/timeline/FiltersRepository.kt index 9d9c24d8c..fe2484358 100644 --- a/app/src/main/java/app/pachli/components/timeline/FiltersRepository.kt +++ b/app/src/main/java/app/pachli/components/timeline/FiltersRepository.kt @@ -22,9 +22,9 @@ import app.pachli.core.network.model.FilterV1 import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import at.connyduck.calladapter.networkresult.getOrThrow -import retrofit2.HttpException import javax.inject.Inject import javax.inject.Singleton +import retrofit2.HttpException sealed interface FilterKind { /** API v1 filter, filtering happens client side */ diff --git a/app/src/main/java/app/pachli/components/timeline/NetworkTimelineRepository.kt b/app/src/main/java/app/pachli/components/timeline/NetworkTimelineRepository.kt index d7290294b..60eac0b1f 100644 --- a/app/src/main/java/app/pachli/components/timeline/NetworkTimelineRepository.kt +++ b/app/src/main/java/app/pachli/components/timeline/NetworkTimelineRepository.kt @@ -31,10 +31,10 @@ import app.pachli.core.network.model.Status import app.pachli.core.network.model.TimelineKind import app.pachli.core.network.retrofit.MastodonApi import app.pachli.util.getDomain +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import timber.log.Timber -import javax.inject.Inject // Things that make this more difficult than it should be: // diff --git a/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt b/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt index f12e71686..e26bb3a4d 100644 --- a/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt +++ b/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt @@ -82,6 +82,7 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collectLatest @@ -91,7 +92,6 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import timber.log.Timber -import kotlin.time.Duration.Companion.seconds @AndroidEntryPoint class TimelineFragment : @@ -212,7 +212,10 @@ class TimelineFragment : */ // TODO: Copied from NotificationsFragment val updateTimestampFlow = flow { - while (true) { delay(60.seconds); emit(Unit) } + while (true) { + delay(60.seconds) + emit(Unit) + } }.onEach { adapter.notifyItemRangeChanged(0, adapter.itemCount, listOf(StatusBaseViewHolder.Key.KEY_CREATED)) } diff --git a/app/src/main/java/app/pachli/components/timeline/util/TimelineUtils.kt b/app/src/main/java/app/pachli/components/timeline/util/TimelineUtils.kt index fe57e9a86..a51bf971f 100644 --- a/app/src/main/java/app/pachli/components/timeline/util/TimelineUtils.kt +++ b/app/src/main/java/app/pachli/components/timeline/util/TimelineUtils.kt @@ -1,7 +1,7 @@ package app.pachli.components.timeline.util -import retrofit2.HttpException import java.io.IOException +import retrofit2.HttpException fun Throwable.isExpected() = this is IOException || this is HttpException diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineRemoteMediator.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineRemoteMediator.kt index 8e44728c9..5c2548f65 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineRemoteMediator.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineRemoteMediator.kt @@ -37,13 +37,13 @@ import app.pachli.core.network.model.Links import app.pachli.core.network.model.Status import app.pachli.core.network.retrofit.MastodonApi import com.google.gson.Gson +import java.io.IOException import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import okhttp3.Headers import retrofit2.HttpException import retrofit2.Response import timber.log.Timber -import java.io.IOException @OptIn(ExperimentalPagingApi::class) class CachedTimelineRemoteMediator( diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineViewModel.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineViewModel.kt index e93618012..2bb3ac95c 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineViewModel.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/CachedTimelineViewModel.kt @@ -39,13 +39,13 @@ import app.pachli.util.StatusDisplayOptionsRepository import app.pachli.viewdata.StatusViewData import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject /** * TimelineViewModel that caches all statuses in a local database diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelinePagingSource.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelinePagingSource.kt index 2e448c5a6..5713d6c76 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelinePagingSource.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelinePagingSource.kt @@ -21,8 +21,8 @@ import androidx.paging.PagingSource import androidx.paging.PagingSource.LoadResult import androidx.paging.PagingState import app.pachli.core.network.model.Status -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber private val INVALID = LoadResult.Invalid() diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineRemoteMediator.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineRemoteMediator.kt index 56105adc1..3389a000e 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineRemoteMediator.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineRemoteMediator.kt @@ -27,11 +27,11 @@ import app.pachli.core.accounts.AccountManager import app.pachli.core.network.model.Status import app.pachli.core.network.model.TimelineKind import app.pachli.core.network.retrofit.MastodonApi +import java.io.IOException import kotlinx.coroutines.CoroutineScope import retrofit2.HttpException import retrofit2.Response import timber.log.Timber -import java.io.IOException /** Remote mediator for accessing timelines that are not backed by the database. */ @OptIn(ExperimentalPagingApi::class) diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineViewModel.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineViewModel.kt index d279d9ac0..dbc82dd5f 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineViewModel.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/NetworkTimelineViewModel.kt @@ -38,13 +38,13 @@ import app.pachli.usecase.TimelineCases import app.pachli.util.StatusDisplayOptionsRepository import app.pachli.viewdata.StatusViewData import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject /** * TimelineViewModel that caches all statuses in an in-memory list diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/PageCache.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/PageCache.kt index 8d5c1ff2c..8a4dbabed 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/PageCache.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/PageCache.kt @@ -21,12 +21,12 @@ import app.pachli.BuildConfig import app.pachli.core.common.string.isLessThan import app.pachli.core.network.model.Links import app.pachli.core.network.model.Status -import retrofit2.HttpException -import retrofit2.Response -import timber.log.Timber import java.util.TreeMap import kotlin.Result.Companion.failure import kotlin.Result.Companion.success +import retrofit2.HttpException +import retrofit2.Response +import timber.log.Timber /** A page of data from the Mastodon API */ data class Page( diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt index ef3da69a5..9536f306f 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt @@ -57,6 +57,7 @@ import app.pachli.util.StatusDisplayOptionsRepository import app.pachli.util.throttleFirst import app.pachli.viewdata.StatusViewData import at.connyduck.calladapter.networkresult.getOrThrow +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow @@ -75,7 +76,6 @@ import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import timber.log.Timber -import kotlin.time.Duration.Companion.milliseconds data class UiState( /** True if the FAB should be shown while scrolling */ @@ -287,6 +287,7 @@ abstract class TimelineViewModel( // message, as it will be confusing to the user. val uiSuccess = MutableSharedFlow() + @Suppress("ktlint:standard:property-naming") /** Channel for error results */ // Errors are sent to a channel to ensure that any errors that occur *before* there are any // subscribers are retained. If this was a SharedFlow any errors would be dropped, and if it diff --git a/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingLinksViewModel.kt b/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingLinksViewModel.kt index 199ebc502..544c85bcf 100644 --- a/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingLinksViewModel.kt +++ b/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingLinksViewModel.kt @@ -26,6 +26,8 @@ import app.pachli.util.StatusDisplayOptionsRepository import app.pachli.util.throttleFirst import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -34,8 +36,6 @@ import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch -import javax.inject.Inject -import kotlin.time.Duration.Companion.milliseconds sealed interface UiAction diff --git a/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingTagsViewModel.kt b/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingTagsViewModel.kt index 81b29eda4..21dac6cf8 100644 --- a/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingTagsViewModel.kt +++ b/app/src/main/java/app/pachli/components/trending/viewmodel/TrendingTagsViewModel.kt @@ -28,14 +28,14 @@ import app.pachli.core.network.retrofit.MastodonApi import app.pachli.viewdata.TrendingViewData import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import java.io.IOException +import javax.inject.Inject import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.launch import timber.log.Timber -import java.io.IOException -import javax.inject.Inject @HiltViewModel class TrendingTagsViewModel @Inject constructor( @@ -43,7 +43,12 @@ class TrendingTagsViewModel @Inject constructor( private val eventHub: EventHub, ) : ViewModel() { enum class LoadingState { - INITIAL, LOADING, REFRESHING, LOADED, ERROR_NETWORK, ERROR_OTHER + INITIAL, + LOADING, + REFRESHING, + LOADED, + ERROR_NETWORK, + ERROR_OTHER, } data class TrendingTagsUiState( diff --git a/app/src/main/java/app/pachli/components/viewthread/ViewThreadViewModel.kt b/app/src/main/java/app/pachli/components/viewthread/ViewThreadViewModel.kt index 16ca675c9..15e668911 100644 --- a/app/src/main/java/app/pachli/components/viewthread/ViewThreadViewModel.kt +++ b/app/src/main/java/app/pachli/components/viewthread/ViewThreadViewModel.kt @@ -49,6 +49,7 @@ import at.connyduck.calladapter.networkresult.getOrElse import at.connyduck.calladapter.networkresult.getOrThrow import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.Job import kotlinx.coroutines.async import kotlinx.coroutines.channels.BufferOverflow @@ -59,7 +60,6 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import retrofit2.HttpException import timber.log.Timber -import javax.inject.Inject @HiltViewModel class ViewThreadViewModel @Inject constructor( @@ -235,7 +235,7 @@ class ViewThreadViewModel @Inject constructor( detailedStatusPosition = 0, revealButton = RevealButtonState.NO_BUTTON, ) - },) + }) } } @@ -473,7 +473,7 @@ class ViewThreadViewModel @Inject constructor( if (it is HttpException && it.code() == 403) return@fold _errors.emit(it) - },) + }) } } @@ -643,5 +643,7 @@ sealed interface ThreadUiState { } enum class RevealButtonState { - NO_BUTTON, REVEAL, HIDE + NO_BUTTON, + REVEAL, + HIDE, } diff --git a/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsFragment.kt b/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsFragment.kt index 72788c5d6..924d65cb0 100644 --- a/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsFragment.kt +++ b/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsFragment.kt @@ -50,9 +50,9 @@ import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject @AndroidEntryPoint class ViewEditsFragment : diff --git a/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsViewModel.kt b/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsViewModel.kt index 788143e4c..6043e4b84 100644 --- a/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsViewModel.kt +++ b/app/src/main/java/app/pachli/components/viewthread/edits/ViewEditsViewModel.kt @@ -25,6 +25,7 @@ import app.pachli.core.network.model.StatusEdit import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.getOrElse import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -44,7 +45,6 @@ import org.pageseeder.diffx.token.impl.SpaceToken import org.pageseeder.diffx.xml.NamespaceSet import org.pageseeder.xmlwriter.XML.NamespaceAware import org.pageseeder.xmlwriter.XMLStringWriter -import javax.inject.Inject @HiltViewModel class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : ViewModel() { diff --git a/app/src/main/java/app/pachli/db/DraftsAlert.kt b/app/src/main/java/app/pachli/db/DraftsAlert.kt index c78c61318..09df65a0a 100644 --- a/app/src/main/java/app/pachli/db/DraftsAlert.kt +++ b/app/src/main/java/app/pachli/db/DraftsAlert.kt @@ -26,10 +26,10 @@ import app.pachli.R import app.pachli.core.accounts.AccountManager import app.pachli.core.database.dao.DraftDao import app.pachli.core.navigation.DraftsActivityIntent -import kotlinx.coroutines.launch -import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton +import kotlinx.coroutines.launch +import timber.log.Timber /** * This class manages an alert popup when a post has failed and been saved to drafts. diff --git a/app/src/main/java/app/pachli/fragment/SFragment.kt b/app/src/main/java/app/pachli/fragment/SFragment.kt index 9e1b5ae0b..7d1648461 100644 --- a/app/src/main/java/app/pachli/fragment/SFragment.kt +++ b/app/src/main/java/app/pachli/fragment/SFragment.kt @@ -66,9 +66,9 @@ import at.connyduck.calladapter.networkresult.fold import at.connyduck.calladapter.networkresult.onFailure import com.google.android.material.snackbar.Snackbar import io.github.z4kn4fein.semver.constraints.toConstraint +import javax.inject.Inject import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject /* Note from Andrew on Jan. 22, 2017: This class is a design problem for me, so I left it with an * awkward name. TimelineFragment and NotificationFragment have significant overlap but the nature diff --git a/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt b/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt index 5b43a7d36..f37bd10c7 100644 --- a/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt +++ b/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt @@ -59,9 +59,9 @@ import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint -import okhttp3.OkHttpClient import javax.inject.Inject import kotlin.math.abs +import okhttp3.OkHttpClient /** * Plays a video, showing media description if available. diff --git a/app/src/main/java/app/pachli/network/ProgressRequestBody.kt b/app/src/main/java/app/pachli/network/ProgressRequestBody.kt index f9f4c210e..e42fd4e57 100644 --- a/app/src/main/java/app/pachli/network/ProgressRequestBody.kt +++ b/app/src/main/java/app/pachli/network/ProgressRequestBody.kt @@ -17,11 +17,11 @@ package app.pachli.network +import java.io.IOException +import java.io.InputStream import okhttp3.MediaType import okhttp3.RequestBody import okio.BufferedSink -import java.io.IOException -import java.io.InputStream class ProgressRequestBody( private val content: InputStream, diff --git a/app/src/main/java/app/pachli/network/ServerCapabilitiesRepository.kt b/app/src/main/java/app/pachli/network/ServerCapabilitiesRepository.kt index 61c898e3f..89fb21338 100644 --- a/app/src/main/java/app/pachli/network/ServerCapabilitiesRepository.kt +++ b/app/src/main/java/app/pachli/network/ServerCapabilitiesRepository.kt @@ -23,12 +23,12 @@ import app.pachli.core.network.ServerCapabilities import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.fold import com.github.michaelbull.result.getOr +import javax.inject.Inject +import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import javax.inject.Inject -import javax.inject.Singleton @Singleton class ServerCapabilitiesRepository @Inject constructor( @@ -58,7 +58,7 @@ class ServerCapabilitiesRepository @Inject constructor( { mastodonApi.getInstanceV1().fold({ instance -> ServerCapabilities.from(instance).getOr { null } - }, { null },) + }, { null }) }, ) ?: ServerCapabilities() } diff --git a/app/src/main/java/app/pachli/receiver/NotificationBlockStateBroadcastReceiver.kt b/app/src/main/java/app/pachli/receiver/NotificationBlockStateBroadcastReceiver.kt index e8f6a372b..d190b52dc 100644 --- a/app/src/main/java/app/pachli/receiver/NotificationBlockStateBroadcastReceiver.kt +++ b/app/src/main/java/app/pachli/receiver/NotificationBlockStateBroadcastReceiver.kt @@ -27,10 +27,10 @@ import app.pachli.components.notifications.updateUnifiedPushSubscription import app.pachli.core.accounts.AccountManager import app.pachli.core.network.retrofit.MastodonApi import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import javax.inject.Inject @DelicateCoroutinesApi @AndroidEntryPoint diff --git a/app/src/main/java/app/pachli/receiver/SendStatusBroadcastReceiver.kt b/app/src/main/java/app/pachli/receiver/SendStatusBroadcastReceiver.kt index e0c1c5f27..0c0313c55 100644 --- a/app/src/main/java/app/pachli/receiver/SendStatusBroadcastReceiver.kt +++ b/app/src/main/java/app/pachli/receiver/SendStatusBroadcastReceiver.kt @@ -43,8 +43,8 @@ import app.pachli.core.network.model.Status import app.pachli.service.SendStatusService import app.pachli.service.StatusToSend import dagger.hilt.android.AndroidEntryPoint -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber @AndroidEntryPoint class SendStatusBroadcastReceiver : BroadcastReceiver() { diff --git a/app/src/main/java/app/pachli/receiver/UnifiedPushBroadcastReceiver.kt b/app/src/main/java/app/pachli/receiver/UnifiedPushBroadcastReceiver.kt index e0bada521..e8c8f3704 100644 --- a/app/src/main/java/app/pachli/receiver/UnifiedPushBroadcastReceiver.kt +++ b/app/src/main/java/app/pachli/receiver/UnifiedPushBroadcastReceiver.kt @@ -25,12 +25,12 @@ import app.pachli.core.accounts.AccountManager import app.pachli.core.network.retrofit.MastodonApi import app.pachli.worker.NotificationWorker import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import org.unifiedpush.android.connector.MessagingReceiver import timber.log.Timber -import javax.inject.Inject @DelicateCoroutinesApi @AndroidEntryPoint diff --git a/app/src/main/java/app/pachli/service/SendStatusService.kt b/app/src/main/java/app/pachli/service/SendStatusService.kt index 2bcaabbcf..86e9cd3ce 100644 --- a/app/src/main/java/app/pachli/service/SendStatusService.kt +++ b/app/src/main/java/app/pachli/service/SendStatusService.kt @@ -38,6 +38,9 @@ import app.pachli.core.network.retrofit.MastodonApi import app.pachli.util.unsafeLazy import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.AndroidEntryPoint +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.TimeUnit +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -48,9 +51,6 @@ import kotlinx.coroutines.runBlocking import kotlinx.parcelize.Parcelize import retrofit2.HttpException import timber.log.Timber -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.TimeUnit -import javax.inject.Inject @AndroidEntryPoint class SendStatusService : Service() { @@ -194,7 +194,7 @@ class SendStatusService : Service() { failOrRetry(throwable, statusId) return@launch - },) + }) } } } @@ -260,7 +260,7 @@ class SendStatusService : Service() { }, { throwable -> Timber.w("failed sending status", throwable) failOrRetry(throwable, statusId) - },) + }) stopSelfWhenDone() } } @@ -480,7 +480,8 @@ data class StatusToSend( @Parcelize data class MediaToSend( val localId: Int, - val id: String?, // null if media is not yet completely uploaded + // null if media is not yet completely uploaded + val id: String?, val uri: String, val description: String?, val focus: Attachment.Focus?, diff --git a/app/src/main/java/app/pachli/settings/AccountPreferenceDataStore.kt b/app/src/main/java/app/pachli/settings/AccountPreferenceDataStore.kt index 714f617f5..87581c64f 100644 --- a/app/src/main/java/app/pachli/settings/AccountPreferenceDataStore.kt +++ b/app/src/main/java/app/pachli/settings/AccountPreferenceDataStore.kt @@ -5,10 +5,10 @@ import app.pachli.core.accounts.AccountManager import app.pachli.core.common.di.ApplicationScope import app.pachli.core.database.model.AccountEntity import app.pachli.core.preferences.PrefKeys +import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch -import javax.inject.Inject class AccountPreferenceDataStore @Inject constructor( private val accountManager: AccountManager, diff --git a/app/src/main/java/app/pachli/settings/SettingsDSL.kt b/app/src/main/java/app/pachli/settings/SettingsDSL.kt index 0064fe3b5..5ea8c073a 100644 --- a/app/src/main/java/app/pachli/settings/SettingsDSL.kt +++ b/app/src/main/java/app/pachli/settings/SettingsDSL.kt @@ -35,7 +35,10 @@ inline fun PreferenceParent.listPreference(builder: ListPreference.() -> Unit): return pref } -inline fun PreferenceParent.emojiPreference(activity: A, builder: EmojiPickerPreference.() -> Unit): EmojiPickerPreference +inline fun PreferenceParent.emojiPreference( + activity: A, + builder: EmojiPickerPreference.() -> Unit, +): EmojiPickerPreference where A : Context, A : ActivityResultRegistryOwner, A : LifecycleOwner { val pref = EmojiPickerPreference.get(activity) builder(pref) diff --git a/app/src/main/java/app/pachli/usecase/TimelineCases.kt b/app/src/main/java/app/pachli/usecase/TimelineCases.kt index 65c5c433a..dd54a0be7 100644 --- a/app/src/main/java/app/pachli/usecase/TimelineCases.kt +++ b/app/src/main/java/app/pachli/usecase/TimelineCases.kt @@ -39,8 +39,8 @@ import at.connyduck.calladapter.networkresult.NetworkResult import at.connyduck.calladapter.networkresult.fold import at.connyduck.calladapter.networkresult.onFailure import at.connyduck.calladapter.networkresult.onSuccess -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber class TimelineCases @Inject constructor( private val mastodonApi: MastodonApi, @@ -123,7 +123,7 @@ class TimelineCases @Inject constructor( }, { e -> Timber.w("Failed to change pin state", e) NetworkResult.failure(TimelineError(e.getServerErrorMessage())) - },) + }) } suspend fun voteInPoll(statusId: String, pollId: String, choices: List): NetworkResult { diff --git a/app/src/main/java/app/pachli/util/CombinedLoadStatesExtensions.kt b/app/src/main/java/app/pachli/util/CombinedLoadStatesExtensions.kt index 8aa7cb8f3..cfe0b57a0 100644 --- a/app/src/main/java/app/pachli/util/CombinedLoadStatesExtensions.kt +++ b/app/src/main/java/app/pachli/util/CombinedLoadStatesExtensions.kt @@ -121,8 +121,6 @@ enum class UserRefreshState { /** A refresh or prepend operation was [LoadState.Error] */ ERROR, - - ; } /** @@ -185,7 +183,9 @@ fun Flow.asRefreshState(): Flow { refresh = when (loadState.refresh) { is LoadState.Loading -> if (refresh == UserRefreshState.WAITING) UserRefreshState.ACTIVE else refresh is LoadState.NotLoading -> if (refresh == UserRefreshState.ACTIVE) UserRefreshState.COMPLETE else refresh - else -> { throw IllegalStateException("can't happen, LoadState.Error is already handled") } + else -> { + throw IllegalStateException("can't happen, LoadState.Error is already handled") + } } // Prepend can only transition to active if there is an active or complete refresh diff --git a/app/src/main/java/app/pachli/util/CryptoUtil.kt b/app/src/main/java/app/pachli/util/CryptoUtil.kt index c2e87aeca..a179fb59e 100644 --- a/app/src/main/java/app/pachli/util/CryptoUtil.kt +++ b/app/src/main/java/app/pachli/util/CryptoUtil.kt @@ -17,13 +17,13 @@ package app.pachli.util import android.util.Base64 +import java.security.KeyPairGenerator +import java.security.SecureRandom +import java.security.Security import org.bouncycastle.jce.ECNamedCurveTable import org.bouncycastle.jce.interfaces.ECPrivateKey import org.bouncycastle.jce.interfaces.ECPublicKey import org.bouncycastle.jce.provider.BouncyCastleProvider -import java.security.KeyPairGenerator -import java.security.SecureRandom -import java.security.Security object CryptoUtil { const val CURVE_PRIME256_V1 = "prime256v1" diff --git a/app/src/main/java/app/pachli/util/CustomEmojiHelper.kt b/app/src/main/java/app/pachli/util/CustomEmojiHelper.kt index e4eb006c2..8003009b4 100644 --- a/app/src/main/java/app/pachli/util/CustomEmojiHelper.kt +++ b/app/src/main/java/app/pachli/util/CustomEmojiHelper.kt @@ -55,7 +55,13 @@ fun CharSequence.emojify(emojis: List?, view: View, animate: Boolean): Ch builder.setSpan(span, matcher.start(), matcher.end(), 0) Glide.with(view) .asDrawable() - .load(if (animate) { url } else { staticUrl }) + .load( + if (animate) { + url + } else { + staticUrl + }, + ) .into(span.getTarget(animate)) } } diff --git a/app/src/main/java/app/pachli/util/FlowExtensions.kt b/app/src/main/java/app/pachli/util/FlowExtensions.kt index 9ee8d1083..a887f0435 100644 --- a/app/src/main/java/app/pachli/util/FlowExtensions.kt +++ b/app/src/main/java/app/pachli/util/FlowExtensions.kt @@ -17,11 +17,11 @@ package app.pachli.util -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow import kotlin.time.Duration import kotlin.time.TimeMark import kotlin.time.TimeSource +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow /** * Returns a flow that mirrors the original flow, but filters out values that occur within diff --git a/app/src/main/java/app/pachli/util/LinkHelper.kt b/app/src/main/java/app/pachli/util/LinkHelper.kt index d87e4ab69..98c1b29fd 100644 --- a/app/src/main/java/app/pachli/util/LinkHelper.kt +++ b/app/src/main/java/app/pachli/util/LinkHelper.kt @@ -48,10 +48,10 @@ import com.mikepenz.iconics.IconicsSize import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.color import com.mikepenz.iconics.utils.size -import timber.log.Timber import java.lang.ref.WeakReference import java.net.URI import java.net.URISyntaxException +import timber.log.Timber fun getDomain(urlString: String?): String { val host = urlString?.toUri()?.host ?: return "" diff --git a/app/src/main/java/app/pachli/util/LocaleUtils.kt b/app/src/main/java/app/pachli/util/LocaleUtils.kt index d1a6bb421..95c933ae7 100644 --- a/app/src/main/java/app/pachli/util/LocaleUtils.kt +++ b/app/src/main/java/app/pachli/util/LocaleUtils.kt @@ -19,8 +19,8 @@ package app.pachli.util import androidx.appcompat.app.AppCompatDelegate import androidx.core.os.LocaleListCompat import app.pachli.core.database.model.AccountEntity -import timber.log.Timber import java.util.Locale +import timber.log.Timber private const val TAG: String = "LocaleUtils" diff --git a/app/src/main/java/app/pachli/util/MediaUtils.kt b/app/src/main/java/app/pachli/util/MediaUtils.kt index fc2a2d73f..ccc65545c 100644 --- a/app/src/main/java/app/pachli/util/MediaUtils.kt +++ b/app/src/main/java/app/pachli/util/MediaUtils.kt @@ -24,7 +24,6 @@ import android.graphics.Matrix import android.net.Uri import android.provider.OpenableColumns import androidx.exifinterface.media.ExifInterface -import timber.log.Timber import java.io.File import java.io.FileNotFoundException import java.io.IOException @@ -32,6 +31,7 @@ import java.text.SimpleDateFormat import java.util.Calendar import java.util.Date import java.util.Locale +import timber.log.Timber /** * Helper methods for obtaining and resizing media files diff --git a/app/src/main/java/app/pachli/util/Resource.kt b/app/src/main/java/app/pachli/util/Resource.kt index effa33d1d..c38b3abdc 100644 --- a/app/src/main/java/app/pachli/util/Resource.kt +++ b/app/src/main/java/app/pachli/util/Resource.kt @@ -4,9 +4,9 @@ sealed interface Resource { val data: T? } -class Loading (override val data: T? = null) : Resource +class Loading(override val data: T? = null) : Resource -class Success (override val data: T? = null) : Resource +class Success(override val data: T? = null) : Resource class Error( override val data: T? = null, diff --git a/app/src/main/java/app/pachli/util/SpanUtils.kt b/app/src/main/java/app/pachli/util/SpanUtils.kt index 9e3e9e3bc..1c7b523ca 100644 --- a/app/src/main/java/app/pachli/util/SpanUtils.kt +++ b/app/src/main/java/app/pachli/util/SpanUtils.kt @@ -43,7 +43,8 @@ private val finders = mapOf( FoundMatchType.HTTP_URL to PatternFinder(':', HTTP_URL_REGEX, 5, Character::isWhitespace), FoundMatchType.HTTPS_URL to PatternFinder(':', HTTPS_URL_REGEX, 6, Character::isWhitespace), FoundMatchType.TAG to PatternFinder('#', TAG_REGEX, 1, ::isValidForTagPrefix), - FoundMatchType.MENTION to PatternFinder('@', MENTION_REGEX, 1, Character::isWhitespace), // TODO: We also need a proper validator for mentions + // TODO: We also need a proper validator for mentions + FoundMatchType.MENTION to PatternFinder('@', MENTION_REGEX, 1, Character::isWhitespace), ) private enum class FoundMatchType { diff --git a/app/src/main/java/app/pachli/util/StatusDisplayOptionsRepository.kt b/app/src/main/java/app/pachli/util/StatusDisplayOptionsRepository.kt index 44b6399ea..1baa192ad 100644 --- a/app/src/main/java/app/pachli/util/StatusDisplayOptionsRepository.kt +++ b/app/src/main/java/app/pachli/util/StatusDisplayOptionsRepository.kt @@ -28,6 +28,8 @@ import app.pachli.core.preferences.SharedPreferencesRepository import app.pachli.network.ServerCapabilitiesRepository import app.pachli.settings.AccountPreferenceDataStore import io.github.z4kn4fein.semver.constraints.toConstraint +import javax.inject.Inject +import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -35,8 +37,6 @@ import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton /** * Repository for [StatusDisplayOptions], exposed through the [flow] property. @@ -125,7 +125,9 @@ class StatusDisplayOptionsRepository @Inject constructor( PrefKeys.SHOW_STATS_INLINE -> prev.copy( showStatsInline = sharedPreferencesRepository.getBoolean(key, default.showStatsInline), ) - else -> { prev } + else -> { + prev + } } } } @@ -146,7 +148,9 @@ class StatusDisplayOptionsRepository @Inject constructor( PrefKeys.MEDIA_PREVIEW_ENABLED -> prev.copy(mediaPreviewEnabled = value) PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA -> prev.copy(showSensitiveMedia = value) PrefKeys.ALWAYS_OPEN_SPOILER -> prev.copy(openSpoiler = value) - else -> { prev } + else -> { + prev + } } } } diff --git a/app/src/main/java/app/pachli/util/ThrowableExtensions.kt b/app/src/main/java/app/pachli/util/ThrowableExtensions.kt index 1bcf58c5e..e299e01bd 100644 --- a/app/src/main/java/app/pachli/util/ThrowableExtensions.kt +++ b/app/src/main/java/app/pachli/util/ThrowableExtensions.kt @@ -2,10 +2,10 @@ package app.pachli.util import android.content.Context import app.pachli.R +import java.io.IOException import org.json.JSONException import org.json.JSONObject import retrofit2.HttpException -import java.io.IOException /** * checks if this throwable indicates an error causes by a 4xx/5xx server response and diff --git a/app/src/main/java/app/pachli/view/ClickableSpanTextView.kt b/app/src/main/java/app/pachli/view/ClickableSpanTextView.kt index c0ab5a3d3..d7d3383a4 100644 --- a/app/src/main/java/app/pachli/view/ClickableSpanTextView.kt +++ b/app/src/main/java/app/pachli/view/ClickableSpanTextView.kt @@ -38,10 +38,10 @@ import androidx.appcompat.widget.AppCompatTextView import androidx.core.view.doOnLayout import app.pachli.BuildConfig import app.pachli.R -import timber.log.Timber import java.lang.Float.max import java.lang.Float.min import kotlin.math.abs +import timber.log.Timber /** * Displays text to the user with optional [ClickableSpan]s. Extends the touchable area of the spans diff --git a/app/src/main/java/app/pachli/view/SliderPreference.kt b/app/src/main/java/app/pachli/view/SliderPreference.kt index 1513a815c..eabf11291 100644 --- a/app/src/main/java/app/pachli/view/SliderPreference.kt +++ b/app/src/main/java/app/pachli/view/SliderPreference.kt @@ -62,7 +62,7 @@ class SliderPreference @JvmOverloads constructor( * @see Slider.getValue * @see Slider.setValue */ - var value: Float = defaultValue + var value: Float = DEFAULT_VALUE get() = _value set(v) { val clamped = max(max(v, valueFrom), min(v, valueTo)) @@ -85,7 +85,7 @@ class SliderPreference @JvmOverloads constructor( * Format string to be applied to values before setting the summary. For more control set * [SliderPreference.formatter] */ - var format: String = defaultFormat + var format: String = DEFAULT_FORMAT /** * Function that will be used to format the summary. The default formatter formats using the @@ -115,11 +115,11 @@ class SliderPreference @JvmOverloads constructor( val a = context.obtainStyledAttributes(attrs, R.styleable.SliderPreference, defStyleAttr, defStyleRes) - value = a.getFloat(R.styleable.SliderPreference_android_value, defaultValue) - valueFrom = a.getFloat(R.styleable.SliderPreference_android_valueFrom, defaultValueFrom) - valueTo = a.getFloat(R.styleable.SliderPreference_android_valueTo, defaultValueTo) - stepSize = a.getFloat(R.styleable.SliderPreference_android_stepSize, defaultStepSize) - format = a.getString(R.styleable.SliderPreference_format) ?: defaultFormat + value = a.getFloat(R.styleable.SliderPreference_android_value, DEFAULT_VALUE) + valueFrom = a.getFloat(R.styleable.SliderPreference_android_valueFrom, DEFAULT_VALUE_FROM) + valueTo = a.getFloat(R.styleable.SliderPreference_android_valueTo, DEFAULT_VALUE_TO) + stepSize = a.getFloat(R.styleable.SliderPreference_android_stepSize, DEFAULT_STEP_SIZE) + format = a.getString(R.styleable.SliderPreference_format) ?: DEFAULT_FORMAT val decrementIconResource = a.getResourceId(R.styleable.SliderPreference_iconStart, -1) if (decrementIconResource != -1) { @@ -135,11 +135,11 @@ class SliderPreference @JvmOverloads constructor( } override fun onGetDefaultValue(a: TypedArray, i: Int): Any { - return a.getFloat(i, defaultValue) + return a.getFloat(i, DEFAULT_VALUE) } override fun onSetInitialValue(defaultValue: Any?) { - value = getPersistedFloat((defaultValue ?: Companion.defaultValue) as Float) + value = getPersistedFloat((defaultValue ?: Companion.DEFAULT_VALUE) as Float) } override fun onBindViewHolder(holder: PreferenceViewHolder) { @@ -195,10 +195,10 @@ class SliderPreference @JvmOverloads constructor( } companion object { - private const val defaultValueFrom = 0F - private const val defaultValueTo = 1F - private const val defaultValue = 0.5F - private const val defaultStepSize = 0.1F - private const val defaultFormat = "%3.1f" + private const val DEFAULT_VALUE_FROM = 0F + private const val DEFAULT_VALUE_TO = 1F + private const val DEFAULT_VALUE = 0.5F + private const val DEFAULT_STEP_SIZE = 0.1F + private const val DEFAULT_FORMAT = "%3.1f" } } diff --git a/app/src/main/java/app/pachli/viewdata/StatusViewData.kt b/app/src/main/java/app/pachli/viewdata/StatusViewData.kt index b71ec7a53..6970b8252 100644 --- a/app/src/main/java/app/pachli/viewdata/StatusViewData.kt +++ b/app/src/main/java/app/pachli/viewdata/StatusViewData.kt @@ -66,12 +66,12 @@ data class StatusViewData( */ val isDetailed: Boolean = false, - /** Whether this status should be filtered, and if so, how */ // TODO: This means that null checks are required elsewhere in the code to deal with // the possibility that this might not be NONE, but that status.filtered is null or // empty (e.g., StatusBaseViewHolder.setupFilterPlaceholder()). It would be better // if the Filter.Action class subtypes carried the FilterResult information with them, // and it's impossible to construct them with an empty list. + /** Whether this status should be filtered, and if so, how */ var filterAction: Filter.Action = Filter.Action.NONE, /** True if the translated content should be shown (if it exists) */ @@ -90,12 +90,15 @@ data class StatusViewData( private val _content: Spanned + @Suppress("ktlint:standard:property-naming") private val _translatedContent: Spanned val content: Spanned get() = if (translationState == TranslationState.SHOW_TRANSLATION) _translatedContent else _content private val _spoilerText: String + + @Suppress("ktlint:standard:property-naming") private val _translatedSpoilerText: String /** The content warning, may be the empty string */ @@ -251,7 +254,8 @@ data class StatusViewData( isExpanded = conversationStatusEntity.expanded, isShowingContent = conversationStatusEntity.showingHiddenContent, isCollapsed = conversationStatusEntity.collapsed, - translationState = TranslationState.SHOW_ORIGINAL, // TODO: Include this in conversationStatusEntity + // TODO: Include translationState in conversationStatusEntity + translationState = TranslationState.SHOW_ORIGINAL, ) fun from( diff --git a/app/src/main/java/app/pachli/viewmodel/AccountsInListViewModel.kt b/app/src/main/java/app/pachli/viewmodel/AccountsInListViewModel.kt index 9a0f46029..fd36db6d2 100644 --- a/app/src/main/java/app/pachli/viewmodel/AccountsInListViewModel.kt +++ b/app/src/main/java/app/pachli/viewmodel/AccountsInListViewModel.kt @@ -26,11 +26,11 @@ import app.pachli.util.Either.Right import app.pachli.util.withoutFirstWhich import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import timber.log.Timber -import javax.inject.Inject data class State(val accounts: Either>, val searchResult: List?) diff --git a/app/src/main/java/app/pachli/viewmodel/EditProfileViewModel.kt b/app/src/main/java/app/pachli/viewmodel/EditProfileViewModel.kt index 0eba36735..c2593f9f6 100644 --- a/app/src/main/java/app/pachli/viewmodel/EditProfileViewModel.kt +++ b/app/src/main/java/app/pachli/viewmodel/EditProfileViewModel.kt @@ -37,6 +37,8 @@ import app.pachli.util.Success import app.pachli.util.getServerErrorMessage import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import java.io.File +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asFlow @@ -46,8 +48,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody -import java.io.File -import javax.inject.Inject private const val HEADER_FILE_NAME = "header.png" private const val AVATAR_FILE_NAME = "avatar.png" diff --git a/app/src/main/java/app/pachli/viewmodel/ListsViewModel.kt b/app/src/main/java/app/pachli/viewmodel/ListsViewModel.kt index ade1253a8..f66be20a6 100644 --- a/app/src/main/java/app/pachli/viewmodel/ListsViewModel.kt +++ b/app/src/main/java/app/pachli/viewmodel/ListsViewModel.kt @@ -24,23 +24,29 @@ import app.pachli.util.replacedFirstWhich import app.pachli.util.withoutFirstWhich import at.connyduck.calladapter.networkresult.fold import dagger.hilt.android.lifecycle.HiltViewModel +import java.io.IOException +import java.net.ConnectException +import javax.inject.Inject import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch -import java.io.IOException -import java.net.ConnectException -import javax.inject.Inject @HiltViewModel internal class ListsViewModel @Inject constructor(private val api: MastodonApi) : ViewModel() { enum class LoadingState { - INITIAL, LOADING, LOADED, ERROR_NETWORK, ERROR_OTHER + INITIAL, + LOADING, + LOADED, + ERROR_NETWORK, + ERROR_OTHER, } enum class Event { - CREATE_ERROR, DELETE_ERROR, UPDATE_ERROR + CREATE_ERROR, + DELETE_ERROR, + UPDATE_ERROR, } data class State(val lists: List, val loadingState: LoadingState) diff --git a/app/src/main/java/app/pachli/worker/PruneCacheWorker.kt b/app/src/main/java/app/pachli/worker/PruneCacheWorker.kt index 085bc8a01..c87879ecc 100644 --- a/app/src/main/java/app/pachli/worker/PruneCacheWorker.kt +++ b/app/src/main/java/app/pachli/worker/PruneCacheWorker.kt @@ -28,8 +28,8 @@ import app.pachli.components.notifications.NOTIFICATION_ID_PRUNE_CACHE import app.pachli.components.notifications.createWorkerNotification import app.pachli.core.accounts.AccountManager import app.pachli.core.database.dao.TimelineDao -import timber.log.Timber import javax.inject.Inject +import timber.log.Timber /** Prune the database cache of old statuses. */ class PruneCacheWorker( diff --git a/app/src/main/java/app/pachli/worker/WorkerFactory.kt b/app/src/main/java/app/pachli/worker/WorkerFactory.kt index 374829d59..f3b5813b2 100644 --- a/app/src/main/java/app/pachli/worker/WorkerFactory.kt +++ b/app/src/main/java/app/pachli/worker/WorkerFactory.kt @@ -21,10 +21,10 @@ import android.content.Context import androidx.work.ListenableWorker import androidx.work.WorkerFactory import androidx.work.WorkerParameters -import timber.log.Timber import javax.inject.Inject import javax.inject.Provider import javax.inject.Singleton +import timber.log.Timber /** * Workers implement this and are added to the map in [app.pachli.di.WorkerModule] diff --git a/app/src/test/java/app/pachli/BottomSheetActivityTest.kt b/app/src/test/java/app/pachli/BottomSheetActivityTest.kt index 844b1d656..5755b4380 100644 --- a/app/src/test/java/app/pachli/BottomSheetActivityTest.kt +++ b/app/src/test/java/app/pachli/BottomSheetActivityTest.kt @@ -24,6 +24,7 @@ import app.pachli.core.network.model.TimelineAccount import app.pachli.core.network.retrofit.MastodonApi import app.pachli.core.testing.rules.MainCoroutineRule import at.connyduck.calladapter.networkresult.NetworkResult +import java.util.Date import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.advanceUntilIdle @@ -38,7 +39,6 @@ import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.Mockito.eq import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock -import java.util.Date @OptIn(ExperimentalCoroutinesApi::class) class BottomSheetActivityTest { diff --git a/app/src/test/java/app/pachli/FilterV1Test.kt b/app/src/test/java/app/pachli/FilterV1Test.kt index 3c3914ee5..1db651600 100644 --- a/app/src/test/java/app/pachli/FilterV1Test.kt +++ b/app/src/test/java/app/pachli/FilterV1Test.kt @@ -26,13 +26,13 @@ import app.pachli.core.network.model.Poll import app.pachli.core.network.model.PollOption import app.pachli.core.network.model.Status import app.pachli.network.FilterModel +import java.time.Instant +import java.util.Date import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock -import java.time.Instant -import java.util.Date @RunWith(AndroidJUnit4::class) class FilterV1Test { diff --git a/app/src/test/java/app/pachli/MainActivityTest.kt b/app/src/test/java/app/pachli/MainActivityTest.kt index 4b1564091..01a3adee2 100644 --- a/app/src/test/java/app/pachli/MainActivityTest.kt +++ b/app/src/test/java/app/pachli/MainActivityTest.kt @@ -45,6 +45,9 @@ import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.CustomTestApplication import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.time.Instant +import java.util.Date +import javax.inject.Inject import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Before @@ -59,9 +62,6 @@ import org.mockito.kotlin.stub import org.robolectric.Shadows.shadowOf import org.robolectric.android.util.concurrent.BackgroundExecutor.runInBackground import org.robolectric.annotation.Config -import java.time.Instant -import java.util.Date -import javax.inject.Inject open class PachliHiltApplication : PachliApplication() diff --git a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt index f485e7831..2237a8ebf 100644 --- a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt +++ b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt @@ -36,6 +36,10 @@ import at.connyduck.calladapter.networkresult.NetworkResult import dagger.hilt.android.testing.CustomTestApplication import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.time.Instant +import java.util.Date +import java.util.Locale +import javax.inject.Inject import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -49,10 +53,6 @@ import org.mockito.kotlin.reset import org.mockito.kotlin.stub import org.robolectric.annotation.Config import org.robolectric.fakes.RoboMenuItem -import java.time.Instant -import java.util.Date -import java.util.Locale -import javax.inject.Inject open class PachliHiltApplication : PachliApplication() diff --git a/app/src/test/java/app/pachli/components/timeline/CachedTimelineRemoteMediatorTest.kt b/app/src/test/java/app/pachli/components/timeline/CachedTimelineRemoteMediatorTest.kt index 3d9a02518..186400903 100644 --- a/app/src/test/java/app/pachli/components/timeline/CachedTimelineRemoteMediatorTest.kt +++ b/app/src/test/java/app/pachli/components/timeline/CachedTimelineRemoteMediatorTest.kt @@ -22,6 +22,7 @@ import app.pachli.core.database.model.RemoteKeyKind import app.pachli.core.database.model.TimelineStatusWithAccount import com.google.common.truth.Truth.assertThat import com.google.gson.Gson +import java.io.IOException import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest @@ -39,7 +40,6 @@ import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import retrofit2.HttpException import retrofit2.Response -import java.io.IOException @RunWith(AndroidJUnit4::class) class CachedTimelineRemoteMediatorTest { diff --git a/app/src/test/java/app/pachli/components/timeline/CachedTimelineViewModelTestBase.kt b/app/src/test/java/app/pachli/components/timeline/CachedTimelineViewModelTestBase.kt index ca88d56c4..9c4619a0b 100644 --- a/app/src/test/java/app/pachli/components/timeline/CachedTimelineViewModelTestBase.kt +++ b/app/src/test/java/app/pachli/components/timeline/CachedTimelineViewModelTestBase.kt @@ -38,6 +38,9 @@ import com.google.gson.Gson import dagger.hilt.android.testing.CustomTestApplication import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.time.Instant +import java.util.Date +import javax.inject.Inject import kotlinx.coroutines.test.TestScope import okhttp3.ResponseBody import okhttp3.ResponseBody.Companion.toResponseBody @@ -51,9 +54,6 @@ import org.mockito.kotlin.stub import org.robolectric.annotation.Config import retrofit2.HttpException import retrofit2.Response -import java.time.Instant -import java.util.Date -import javax.inject.Inject open class PachliHiltApplication : PachliApplication() diff --git a/app/src/test/java/app/pachli/components/timeline/NetworkTimelineViewModelTestBase.kt b/app/src/test/java/app/pachli/components/timeline/NetworkTimelineViewModelTestBase.kt index bf8298092..30030af72 100644 --- a/app/src/test/java/app/pachli/components/timeline/NetworkTimelineViewModelTestBase.kt +++ b/app/src/test/java/app/pachli/components/timeline/NetworkTimelineViewModelTestBase.kt @@ -35,6 +35,9 @@ import app.pachli.util.StatusDisplayOptionsRepository import at.connyduck.calladapter.networkresult.NetworkResult import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.time.Instant +import java.util.Date +import javax.inject.Inject import kotlinx.coroutines.test.TestScope import okhttp3.ResponseBody import okhttp3.ResponseBody.Companion.toResponseBody @@ -48,9 +51,6 @@ import org.mockito.kotlin.stub import org.robolectric.annotation.Config import retrofit2.HttpException import retrofit2.Response -import java.time.Instant -import java.util.Date -import javax.inject.Inject @HiltAndroidTest @Config(application = HiltTestApplication_Application::class) diff --git a/app/src/test/java/app/pachli/components/viewthread/ViewThreadViewModelTest.kt b/app/src/test/java/app/pachli/components/viewthread/ViewThreadViewModelTest.kt index 42384c883..66e20388a 100644 --- a/app/src/test/java/app/pachli/components/viewthread/ViewThreadViewModelTest.kt +++ b/app/src/test/java/app/pachli/components/viewthread/ViewThreadViewModelTest.kt @@ -30,6 +30,10 @@ import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.CustomTestApplication import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.io.IOException +import java.time.Instant +import java.util.Date +import javax.inject.Inject import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.TestScope @@ -44,10 +48,6 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.reset import org.mockito.kotlin.stub import org.robolectric.annotation.Config -import java.io.IOException -import java.time.Instant -import java.util.Date -import javax.inject.Inject open class PachliHiltApplication : PachliApplication() diff --git a/app/src/test/java/app/pachli/di/FakeMastodonApiModule.kt b/app/src/test/java/app/pachli/di/FakeMastodonApiModule.kt index 0d1372073..e2ff72e46 100644 --- a/app/src/test/java/app/pachli/di/FakeMastodonApiModule.kt +++ b/app/src/test/java/app/pachli/di/FakeMastodonApiModule.kt @@ -23,8 +23,8 @@ import dagger.Module import dagger.Provides import dagger.hilt.components.SingletonComponent import dagger.hilt.testing.TestInstallIn -import org.mockito.kotlin.mock import javax.inject.Singleton +import org.mockito.kotlin.mock /** * Provides an empty mock. Use like: diff --git a/app/src/test/java/app/pachli/di/FakeNetworkModule.kt b/app/src/test/java/app/pachli/di/FakeNetworkModule.kt index 8e4d34b36..103035645 100644 --- a/app/src/test/java/app/pachli/di/FakeNetworkModule.kt +++ b/app/src/test/java/app/pachli/di/FakeNetworkModule.kt @@ -26,10 +26,10 @@ import dagger.Module import dagger.Provides import dagger.hilt.components.SingletonComponent import dagger.hilt.testing.TestInstallIn -import okhttp3.OkHttpClient -import org.mockito.kotlin.mock import java.util.Date import javax.inject.Singleton +import okhttp3.OkHttpClient +import org.mockito.kotlin.mock @TestInstallIn( components = [SingletonComponent::class], diff --git a/app/src/test/java/app/pachli/usecase/TimelineCasesTest.kt b/app/src/test/java/app/pachli/usecase/TimelineCasesTest.kt index 6a339a4e5..7c373b7d2 100644 --- a/app/src/test/java/app/pachli/usecase/TimelineCasesTest.kt +++ b/app/src/test/java/app/pachli/usecase/TimelineCasesTest.kt @@ -8,6 +8,7 @@ import app.pachli.components.timeline.CachedTimelineRepository import app.pachli.core.network.model.Status import app.pachli.core.network.retrofit.MastodonApi import at.connyduck.calladapter.networkresult.NetworkResult +import java.util.Date import kotlinx.coroutines.runBlocking import okhttp3.ResponseBody.Companion.toResponseBody import org.junit.Assert.assertEquals @@ -19,7 +20,6 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.stub import retrofit2.HttpException import retrofit2.Response -import java.util.Date @RunWith(AndroidJUnit4::class) class TimelineCasesTest { diff --git a/app/src/test/java/app/pachli/util/FlowExtensionsTest.kt b/app/src/test/java/app/pachli/util/FlowExtensionsTest.kt index 4631bcfa6..01b3a9679 100644 --- a/app/src/test/java/app/pachli/util/FlowExtensionsTest.kt +++ b/app/src/test/java/app/pachli/util/FlowExtensionsTest.kt @@ -19,14 +19,14 @@ package app.pachli.util import app.cash.turbine.test import com.google.common.truth.Truth.assertThat +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.ExperimentalTime import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.flow.flow import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Test -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.ExperimentalTime @OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class) class FlowExtensionsTest { diff --git a/app/src/test/java/app/pachli/util/StatusDisplayOptionsRepositoryTest.kt b/app/src/test/java/app/pachli/util/StatusDisplayOptionsRepositoryTest.kt index ebadfefdf..43b71fb8a 100644 --- a/app/src/test/java/app/pachli/util/StatusDisplayOptionsRepositoryTest.kt +++ b/app/src/test/java/app/pachli/util/StatusDisplayOptionsRepositoryTest.kt @@ -34,6 +34,9 @@ import com.google.common.truth.Truth.assertThat import dagger.hilt.android.testing.CustomTestApplication import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import java.time.Instant +import java.util.Date +import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.advanceUntilIdle @@ -43,9 +46,6 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.annotation.Config -import java.time.Instant -import java.util.Date -import javax.inject.Inject open class PachliHiltApplication : PachliApplication() diff --git a/checks/src/test/java/app/pachli/lint/checks/IntentDetectorTest.kt b/checks/src/test/java/app/pachli/lint/checks/IntentDetectorTest.kt index 6d73e9007..d1d230a2d 100644 --- a/checks/src/test/java/app/pachli/lint/checks/IntentDetectorTest.kt +++ b/checks/src/test/java/app/pachli/lint/checks/IntentDetectorTest.kt @@ -21,6 +21,7 @@ import com.android.tools.lint.checks.infrastructure.LintDetectorTest import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue +@Suppress("ktlint:standard:function-naming") class IntentDetectorTest : LintDetectorTest() { override fun getDetector(): Detector = IntentDetector() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 074dd7dd1..db0c130e2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -77,7 +77,7 @@ hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } -ktlint = "org.jlleitschuh.gradle.ktlint:11.6.1" +ktlint = "org.jlleitschuh.gradle.ktlint:12.0.3" room = { id = "androidx.room", version.ref = "androidx-room" } quadrant = { id = "com.gaelmarhic.quadrant", version.ref = "quadrant" } diff --git a/tools/mklanguages/src/main/kotlin/app/pachli/mklanguages/Main.kt b/tools/mklanguages/src/main/kotlin/app/pachli/mklanguages/Main.kt index 2924648f4..fd6675bb3 100644 --- a/tools/mklanguages/src/main/kotlin/app/pachli/mklanguages/Main.kt +++ b/tools/mklanguages/src/main/kotlin/app/pachli/mklanguages/Main.kt @@ -151,8 +151,8 @@ class App : CliktCommand(help = """Update languages in donottranslate.xml""") { // `language_entries` and `language_values` arrays with fresh data. val tmpFile = createTempFile().toFile() val w = tmpFile.printWriter() - val donottranslate_xml = resourcePath / "values" / "donottranslate.xml" - donottranslate_xml.toFile().useLines { lines -> + val donottranslateXml = resourcePath / "values" / "donottranslate.xml" + donottranslateXml.toFile().useLines { lines -> var inLanguageEntries = false var inLanguageValues = false @@ -199,8 +199,8 @@ class App : CliktCommand(help = """Update languages in donottranslate.xml""") { // Close, then replace donotranslate.xml w.close() - Files.move(tmpFile.toPath(), donottranslate_xml, StandardCopyOption.REPLACE_EXISTING) - log.info { "replaced ${donottranslate_xml.toAbsolutePath()}" } + Files.move(tmpFile.toPath(), donottranslateXml, StandardCopyOption.REPLACE_EXISTING) + log.info { "replaced ${donottranslateXml.toAbsolutePath()}" } } } diff --git a/tools/mklanguages/src/test/kotlin/app/pachli/mklanguages/ValuesParserTest.kt b/tools/mklanguages/src/test/kotlin/app/pachli/mklanguages/ValuesParserTest.kt index d048642de..38228235a 100644 --- a/tools/mklanguages/src/test/kotlin/app/pachli/mklanguages/ValuesParserTest.kt +++ b/tools/mklanguages/src/test/kotlin/app/pachli/mklanguages/ValuesParserTest.kt @@ -18,13 +18,13 @@ package app.pachli.mklanguages import com.github.h0tk3y.betterParse.grammar.parseToEnd +import java.util.stream.Stream import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Nested import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import java.util.stream.Stream @Execution(ExecutionMode.CONCURRENT) internal class ValuesParserTest {