Skip to content

Commit

Permalink
Apply ktlint and add to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kyori19 committed Nov 11, 2022
1 parent 004a9b4 commit c7a91fb
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 111 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:

- run: |
chmod +x ./gradlew
./gradlew :ktlintCheck
./gradlew :app:testBlueDebugUnitTest
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import androidx.activity.viewModels
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.widget.PopupMenu
Expand Down Expand Up @@ -621,11 +621,11 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
}

binding.mainDrawer.addItems(
secondaryDrawerItem {
nameText = "Yuito (by kyori19)"
isEnabled = false
textColor = ColorStateList.valueOf(ThemeUtils.getColor(this@MainActivity, R.attr.colorInfo))
}
secondaryDrawerItem {
nameText = "Yuito (by kyori19)"
isEnabled = false
textColor = ColorStateList.valueOf(ThemeUtils.getColor(this@MainActivity, R.attr.colorInfo))
}
)
}

Expand Down Expand Up @@ -732,8 +732,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
}
R.id.tabEditList -> {
AccountsInListFragment.newInstance(
tabs[i].arguments.getOrNull(0).orEmpty(),
tabs[i].arguments.getOrNull(1).orEmpty()
tabs[i].arguments.getOrNull(0).orEmpty(),
tabs[i].arguments.getOrNull(1).orEmpty()
).show(supportFragmentManager, null)
}
R.id.tabToggleStreaming -> {
Expand All @@ -750,18 +750,20 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
it.tabPreferences = tabs
accountManager.saveAccount(it)
}
.subscribeOn(Schedulers.io())
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
.subscribe()
.subscribeOn(Schedulers.io())
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
.subscribe()
}
}
}
R.id.tabToggleNotificationsFilter -> {
if (fragment is NotificationsFragment) {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
prefs.edit().putBoolean("showNotificationsFilter",
!prefs.getBoolean("showNotificationsFilter", true))
.apply()
prefs.edit().putBoolean(
"showNotificationsFilter",
!prefs.getBoolean("showNotificationsFilter", true)
)
.apply()
eventHub.dispatch(PreferenceChangedEvent("showNotificationsFilter"))
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/keylesspalace/tusky/StatusListActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import android.view.Menu
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.Lifecycle
import autodispose2.androidx.lifecycle.autoDispose
import com.keylesspalace.tusky.appstore.EventHub
import androidx.lifecycle.lifecycleScope
import at.connyduck.calladapter.networkresult.fold
import autodispose2.androidx.lifecycle.autoDispose
import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.components.timeline.TimelineFragment
import com.keylesspalace.tusky.components.timeline.viewmodel.TimelineViewModel.Kind
import com.keylesspalace.tusky.databinding.ActivityStatuslistBinding
import com.keylesspalace.tusky.di.ViewModelFactory
import com.keylesspalace.tusky.util.viewBinding
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import kotlinx.coroutines.launch
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import kotlinx.coroutines.launch
import net.accelf.yuito.QuickTootViewModel
import javax.inject.Inject

Expand All @@ -50,7 +50,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
@Inject
lateinit var viewModelFactory: ViewModelFactory

private val quickTootViewModel: QuickTootViewModel by viewModels{ viewModelFactory }
private val quickTootViewModel: QuickTootViewModel by viewModels { viewModelFactory }

private val binding: ActivityStatuslistBinding by viewBinding(ActivityStatuslistBinding::inflate)
private lateinit var kind: Kind
Expand Down Expand Up @@ -95,9 +95,9 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
binding.viewQuickToot.attachViewModel(quickTootViewModel, this)

eventHub.events
.observeOn(AndroidSchedulers.mainThread())
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
.subscribe(binding.viewQuickToot::handleEvent)
.observeOn(AndroidSchedulers.mainThread())
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
.subscribe(binding.viewQuickToot::handleEvent)
binding.floatingBtn.setOnClickListener(binding.viewQuickToot::onFABClicked)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,16 @@ class ComposeActivity :
binding.checkboxUseDefaultText.isChecked = preferences.getBoolean(PREF_USE_DEFAULT_TAG, false)
binding.checkboxUseDefaultText.setOnCheckedChangeListener { _, isChecked ->
preferences.edit()
.putBoolean(PREF_USE_DEFAULT_TAG, isChecked)
.apply()
.putBoolean(PREF_USE_DEFAULT_TAG, isChecked)
.apply()
eventHub.dispatch(PreferenceChangedEvent(PREF_USE_DEFAULT_TAG))
}

binding.editTextDefaultText.setText(preferences.getString(PREF_DEFAULT_TAG, ""))
binding.editTextDefaultText.doAfterTextChanged {
preferences.edit()
.putString(PREF_DEFAULT_TAG, it.toString())
.apply()
.putString(PREF_DEFAULT_TAG, it.toString())
.apply()
eventHub.dispatch(PreferenceChangedEvent(PREF_DEFAULT_TAG))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.updateAndGet
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
Expand Down Expand Up @@ -71,14 +80,18 @@ class ComposeViewModel @Inject constructor(
private var hasScheduledTimeChanged: Boolean = false

private val useCache = MutableStateFlow(true)
val instanceInfo = useCache.map { when (it) {
true -> instanceInfoRepo.getCachedInstanceInfo()
false -> instanceInfoRepo.getInstanceInfo()
} }.shareIn(viewModelScope, SharingStarted.Eagerly, 1)
val emoji = useCache.map { when (it) {
true -> instanceInfoRepo.getCachedEmojis()
false -> instanceInfoRepo.getEmojis()
} }.shareIn(viewModelScope, SharingStarted.Eagerly, 1)
val instanceInfo = useCache.map {
when (it) {
true -> instanceInfoRepo.getCachedInstanceInfo()
false -> instanceInfoRepo.getInstanceInfo()
}
}.shareIn(viewModelScope, SharingStarted.Eagerly, 1)
val emoji = useCache.map {
when (it) {
true -> instanceInfoRepo.getCachedEmojis()
false -> instanceInfoRepo.getEmojis()
}
}.shareIn(viewModelScope, SharingStarted.Eagerly, 1)

val markMediaAsSensitive: MutableStateFlow<Boolean> =
MutableStateFlow(accountManager.activeAccount?.defaultMediaSensitivity ?: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,17 @@ class PreferencesFragment : PreferenceFragmentCompat(), Injectable {
setTitle(R.string.pref_title_stacktrace_send)
setOnPreferenceClickListener {
activity?.let { activity ->
val intent = ComposeActivity.startIntent(activity, ComposeOptions(
val intent = ComposeActivity.startIntent(
activity,
ComposeOptions(
content = "@[email protected] $stackTrace".substring(0, 400),
contentWarning = "Yuito StackTrace"
))
)
)
activity.startActivity(intent)
prefs.edit()
.remove(PrefKeys.STACK_TRACE)
.apply()
.remove(PrefKeys.STACK_TRACE)
.apply()
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.keylesspalace.tusky.network.NotestockApi
import com.keylesspalace.tusky.viewdata.StatusViewData

class SearchNotestockPagingSourceFactory(
private val notestockApi: NotestockApi,
private val initialItems: List<StatusViewData.Concrete>? = null,
private val parser: (SearchResult) -> List<StatusViewData.Concrete>
private val notestockApi: NotestockApi,
private val initialItems: List<StatusViewData.Concrete>? = null,
private val parser: (SearchResult) -> List<StatusViewData.Concrete>
) : () -> SearchNotestockPagingSource {

private var searchRequest: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ class SearchPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(acti
}

override fun getItemCount() = 4

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class SearchNotestockFragment : SearchFragment<StatusViewData.Concrete>(), Statu
return SearchStatusesAdapter(statusDisplayOptions, this)
}


override fun onContentHiddenChange(isShowing: Boolean, position: Int) {
searchAdapter.peek(position)?.let {
viewModel.contentHiddenNotestockChange(it, isShowing)
Expand Down Expand Up @@ -133,9 +132,7 @@ class SearchNotestockFragment : SearchFragment<StatusViewData.Concrete>(), Statu
Attachment.Type.UNKNOWN -> {
}
}

}

}

override fun onViewThread(position: Int) {
Expand Down Expand Up @@ -491,11 +488,9 @@ class SearchNotestockFragment : SearchFragment<StatusViewData.Concrete>(), Statu
Log.w("SearchStatusesFragment", "error deleting status", error)
Toast.makeText(context, R.string.error_generic, Toast.LENGTH_SHORT).show()
})

}
.setNegativeButton(android.R.string.cancel, null)
.show()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class SearchStatusesFragment : SearchFragment<StatusViewData.Concrete>(), Status
}

val intent = ComposeActivity.startIntent(
requireContext(),
requireContext(),
ComposeOptions(
quoteId = status.actionableId,
quoteStatusAuthor = actionableStatus.account.localUsername,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,14 @@ class NetworkTimelineViewModel @Inject constructor(
statusData.add(0, StatusViewData.Placeholder(status.id, isLoading = false))
isFirstOfStreaming = false
} else {
statusData.add(0, status.toViewData(
isShowingContent = activeAccount.alwaysShowSensitiveMedia,
isExpanded = activeAccount.alwaysOpenSpoiler,
isCollapsed = true,
))
statusData.add(
0,
status.toViewData(
isShowingContent = activeAccount.alwaysShowSensitiveMedia,
isExpanded = activeAccount.alwaysOpenSpoiler,
isCollapsed = true,
)
)
}

currentSource?.invalidate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ abstract class TimelineViewModel(
protected fun shouldFilterStatus(statusViewData: StatusViewData): Boolean {
val status = statusViewData.asStatusOrNull()?.status ?: return false
return status.inReplyToId != null && filterRemoveReplies ||
status.reblog != null && filterRemoveReblogs ||
filterModel.shouldFilterStatus(status.actionableStatus)
status.reblog != null && filterRemoveReblogs ||
filterModel.shouldFilterStatus(status.actionableStatus)
}

private fun onPreferenceChanged(key: String) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/keylesspalace/tusky/db/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Converters @Inject constructor (
// List name may include ":"
return tabData?.joinToString(";") {
(if (it.enableStreaming) { it.id + STREAMING } else { it.id }) + ":" +
it.arguments.joinToString(":") { s -> URLEncoder.encode(s, "UTF-8") }
it.arguments.joinToString(":") { s -> URLEncoder.encode(s, "UTF-8") }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ abstract class FragmentBuildersModule {

@ContributesAndroidInjector
abstract fun searchNotestockFragment(): SearchNotestockFragment

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class NetworkModule {
@Singleton
fun providesNotestockApi(
okHttpClient: OkHttpClient,
gson: Gson
gson: Gson
): NotestockApi {
val retrofit = Retrofit.Builder().baseUrl("https://notestock.osa-p.net")
.client(okHttpClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ abstract class ViewModelModule {
@ViewModelKey(QuickTootViewModel::class)
internal abstract fun quickTootViewModel(viewModel: QuickTootViewModel): ViewModel

//Add more ViewModels here
// Add more ViewModels here
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ interface NotestockApi {

@GET("api/v1/search.json")
fun searchObservable(
@Query("q") q: String,
@Query("max_dt") maxDt: String? = null
@Query("q") q: String,
@Query("max_dt") maxDt: String? = null
): Single<SearchResult>

}
6 changes: 3 additions & 3 deletions app/src/main/java/net/accelf/yuito/QuickTootView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import kotlinx.coroutines.launch
import kotlin.properties.Delegates

class QuickTootView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : ConstraintLayout(context, attrs, defStyleAttr) {

private val binding = ViewQuickTootBinding.inflate(LayoutInflater.from(context), this, true)
Expand Down
Loading

0 comments on commit c7a91fb

Please sign in to comment.