update dependencies, migrate code & cleanup (#12)
* update dependencies, migrate code & cleanup * migrate from Kotlin Android extensions to Kotlin Parcelize * fix import order
This commit is contained in:
parent
7c14af603e
commit
466dba6096
|
@ -1,16 +1,16 @@
|
|||
plugins {
|
||||
id("com.android.application")
|
||||
id("kotlin-android")
|
||||
id("kotlin-android-extensions")
|
||||
id("kotlin-kapt")
|
||||
id("kotlin-parcelize")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion(30)
|
||||
compileSdk = 31
|
||||
defaultConfig {
|
||||
applicationId = "at.connyduck.pixelcat"
|
||||
minSdkVersion(24)
|
||||
targetSdkVersion(30)
|
||||
minSdk = 24
|
||||
targetSdk = 31
|
||||
versionCode = 1
|
||||
versionName = "0.0 snapshot1"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
@ -29,19 +29,15 @@ android {
|
|||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
androidExtensions {
|
||||
features = setOf("parcelize")
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
exclude("LICENSE_OFL")
|
||||
exclude("LICENSE_UNICODE")
|
||||
exclude("okhttp3/internal/publicsuffix/NOTICE")
|
||||
exclude("DebugProbesKt.bin")
|
||||
resources.excludes.add("LICENSE_OFL")
|
||||
resources.excludes.add("LICENSE_UNICODE")
|
||||
resources.excludes.add("okhttp3/internal/publicsuffix/NOTICE")
|
||||
resources.excludes.add("DebugProbesKt.bin")
|
||||
}
|
||||
|
||||
sourceSets["main"].java.srcDir("src/main/kotlin")
|
||||
|
@ -60,37 +56,36 @@ tasks {
|
|||
|
||||
dependencies {
|
||||
|
||||
val lifecycleVersion = "2.3.0-alpha07"
|
||||
val lifecycleVersion = "2.4.0"
|
||||
val emojiCompatVersion = "1.2.0-alpha01"
|
||||
val roomVersion = "2.3.0-alpha03"
|
||||
val okHttpVersion = "4.8.1"
|
||||
val roomVersion = "2.4.1"
|
||||
val okHttpVersion = "4.9.3"
|
||||
val retrofitVersion = "2.9.0"
|
||||
val moshiVersion = "1.10.0"
|
||||
val daggerVersion = "2.28.3"
|
||||
val jUnitVersion = "5.7.0"
|
||||
val moshiVersion = "1.13.0"
|
||||
val daggerVersion = "2.40.5"
|
||||
val jUnitVersion = "5.8.2"
|
||||
|
||||
implementation(kotlin("stdlib-jdk7"))
|
||||
|
||||
implementation("androidx.core:core-ktx:1.5.0-alpha03")
|
||||
implementation("androidx.appcompat:appcompat:1.3.0-alpha02")
|
||||
implementation("androidx.activity:activity-ktx:1.2.0-alpha08")
|
||||
implementation("androidx.fragment:fragment-ktx:1.3.0-alpha08")
|
||||
implementation("com.google.android.material:material:1.3.0-alpha02")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.0.1")
|
||||
implementation("androidx.core:core-ktx:1.7.0")
|
||||
implementation("androidx.appcompat:appcompat:1.4.1")
|
||||
implementation("androidx.activity:activity-ktx:1.4.0")
|
||||
implementation("androidx.fragment:fragment-ktx:1.4.1")
|
||||
implementation("com.google.android.material:material:1.5.0")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
|
||||
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
|
||||
implementation("androidx.recyclerview:recyclerview:1.2.0-alpha05")
|
||||
implementation("androidx.annotation:annotation:1.1.0")
|
||||
implementation("androidx.recyclerview:recyclerview:1.2.1")
|
||||
implementation("androidx.annotation:annotation:1.3.0")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
|
||||
implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion")
|
||||
implementation("androidx.preference:preference:1.1.1")
|
||||
implementation("androidx.preference:preference-ktx:1.2.0")
|
||||
implementation("androidx.emoji:emoji-bundled:$emojiCompatVersion")
|
||||
implementation("androidx.emoji:emoji-appcompat:$emojiCompatVersion")
|
||||
implementation("androidx.paging:paging-runtime-ktx:3.0.0-alpha06")
|
||||
implementation("androidx.paging:paging-runtime-ktx:3.1.0")
|
||||
implementation("androidx.viewpager2:viewpager2:1.0.0")
|
||||
|
||||
implementation("androidx.room:room-ktx:$roomVersion")
|
||||
implementation("androidx.room:room-paging:$roomVersion")
|
||||
kapt("androidx.room:room-compiler:$roomVersion")
|
||||
|
||||
implementation("com.squareup.okhttp3:okhttp:$okHttpVersion")
|
||||
|
@ -103,17 +98,17 @@ dependencies {
|
|||
implementation("com.squareup.moshi:moshi-adapters:$moshiVersion")
|
||||
kapt("com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion")
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
|
||||
|
||||
implementation("com.fxn769:pix:1.4.4")
|
||||
implementation("com.fxn769:pix:1.5.6")
|
||||
|
||||
implementation("com.github.yalantis:ucrop:2.2.5")
|
||||
|
||||
implementation("me.relex:circleindicator:2.1.4")
|
||||
implementation("me.relex:circleindicator:2.1.6")
|
||||
|
||||
implementation("io.coil-kt:coil:1.0.0-rc3")
|
||||
|
||||
implementation("com.github.connyduck:sparkbutton:4.0.0")
|
||||
implementation("com.github.connyduck:sparkbutton:4.1.0")
|
||||
|
||||
implementation("com.google.dagger:dagger:$daggerVersion")
|
||||
kapt("com.google.dagger:dagger-compiler:$daggerVersion")
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
android:usesCleartextTraffic="false"
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
<!-- TODO order activities -->
|
||||
<activity android:name=".components.splash.SplashActivity">
|
||||
<activity android:name=".components.splash.SplashActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import at.connyduck.pixelcat.databinding.ActivityComposeBinding
|
|||
import at.connyduck.pixelcat.util.viewBinding
|
||||
import com.fxn.pix.Options
|
||||
import com.fxn.pix.Pix
|
||||
import com.fxn.utility.ImageQuality
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
@ -104,24 +103,23 @@ class ComposeActivity : BaseActivity(), OnImageActionClickListener {
|
|||
}
|
||||
|
||||
viewModel.imageLiveData.observe(
|
||||
this,
|
||||
{
|
||||
adapter.submitList(it)
|
||||
}
|
||||
)
|
||||
this
|
||||
) {
|
||||
adapter.submitList(it)
|
||||
}
|
||||
|
||||
viewModel.visibility.observe(
|
||||
this,
|
||||
{
|
||||
val visibilityString = when (it) {
|
||||
VISIBILITY.PUBLIC -> R.string.compose_visibility_public
|
||||
VISIBILITY.UNLISTED -> R.string.compose_visibility_unlisted
|
||||
VISIBILITY.FOLLOWERS_ONLY -> R.string.compose_visibility_followers_only
|
||||
}
|
||||
|
||||
binding.composeVisibilityButton.text = getString(R.string.compose_visibility, getString(visibilityString))
|
||||
this
|
||||
) {
|
||||
val visibilityString = when (it) {
|
||||
VISIBILITY.PUBLIC -> R.string.compose_visibility_public
|
||||
VISIBILITY.UNLISTED -> R.string.compose_visibility_unlisted
|
||||
VISIBILITY.FOLLOWERS_ONLY -> R.string.compose_visibility_followers_only
|
||||
}
|
||||
)
|
||||
|
||||
binding.composeVisibilityButton.text =
|
||||
getString(R.string.compose_visibility, getString(visibilityString))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
@ -141,7 +139,6 @@ class ComposeActivity : BaseActivity(), OnImageActionClickListener {
|
|||
override fun onAddImage() {
|
||||
val options = Options.init()
|
||||
.setRequestCode(REQUEST_CODE_PICK_MEDIA)
|
||||
.setImageQuality(ImageQuality.HIGH)
|
||||
.setScreenOrientation(Options.SCREEN_ORIENTATION_PORTRAIT)
|
||||
|
||||
Pix.start(this, options)
|
||||
|
|
|
@ -38,13 +38,13 @@ import at.connyduck.pixelcat.model.NewStatus
|
|||
import at.connyduck.pixelcat.network.FediverseApi
|
||||
import at.connyduck.pixelcat.network.calladapter.NetworkResponseError
|
||||
import dagger.android.DaggerService
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
|
|
|
@ -43,14 +43,9 @@ import at.connyduck.pixelcat.components.util.extension.visible
|
|||
import at.connyduck.pixelcat.dagger.ViewModelFactory
|
||||
import at.connyduck.pixelcat.databinding.ActivityLoginBinding
|
||||
import at.connyduck.pixelcat.util.viewBinding
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@FlowPreview
|
||||
@ExperimentalCoroutinesApi
|
||||
class LoginActivity : BaseActivity() {
|
||||
|
||||
@Inject
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package at.connyduck.pixelcat.components.login
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class LoginModel(
|
||||
|
|
|
@ -25,25 +25,21 @@ import at.connyduck.pixelcat.config.Config
|
|||
import at.connyduck.pixelcat.db.AccountManager
|
||||
import at.connyduck.pixelcat.db.entitity.AccountAuthData
|
||||
import at.connyduck.pixelcat.network.FediverseApi
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.HttpUrl
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
@FlowPreview
|
||||
@ExperimentalCoroutinesApi
|
||||
class LoginViewModel @Inject constructor(
|
||||
private val api: FediverseApi,
|
||||
private val accountManager: AccountManager
|
||||
) : ViewModel() {
|
||||
|
||||
private val loginState = ConflatedBroadcastChannel(LoginModel(state = LoginState.NO_ERROR))
|
||||
private val loginState = MutableStateFlow(LoginModel(state = LoginState.NO_ERROR))
|
||||
|
||||
fun observe() = loginState.asFlow()
|
||||
fun observe(): Flow<LoginModel> = loginState
|
||||
|
||||
fun startLogin(input: String) {
|
||||
viewModelScope.launch {
|
||||
|
@ -52,7 +48,7 @@ class LoginViewModel @Inject constructor(
|
|||
try {
|
||||
HttpUrl.Builder().host(domainInput).scheme("https").build()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
loginState.send(LoginModel(input, LoginState.INVALID_DOMAIN))
|
||||
loginState.value = LoginModel(input, LoginState.INVALID_DOMAIN)
|
||||
return@launch
|
||||
}
|
||||
|
||||
|
@ -61,11 +57,11 @@ class LoginViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
if (exceptionMatch) {
|
||||
loginState.send(LoginModel(input, LoginState.AUTH_ERROR))
|
||||
loginState.value = LoginModel(input, LoginState.AUTH_ERROR)
|
||||
return@launch
|
||||
}
|
||||
|
||||
loginState.send(LoginModel(input, LoginState.LOADING))
|
||||
loginState.value = LoginModel(input, LoginState.LOADING)
|
||||
|
||||
api.authenticateAppAsync(
|
||||
domain = domainInput,
|
||||
|
@ -75,10 +71,10 @@ class LoginViewModel @Inject constructor(
|
|||
scopes = Config.oAuthScopes
|
||||
).fold(
|
||||
{ appData ->
|
||||
loginState.send(LoginModel(input, LoginState.SUCCESS, domainInput, appData.clientId, appData.clientSecret))
|
||||
loginState.value = LoginModel(input, LoginState.SUCCESS, domainInput, appData.clientId, appData.clientSecret)
|
||||
},
|
||||
{
|
||||
loginState.send(LoginModel(input, LoginState.AUTH_ERROR))
|
||||
loginState.value = LoginModel(input, LoginState.AUTH_ERROR)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -107,19 +103,17 @@ class LoginViewModel @Inject constructor(
|
|||
clientSecret = loginModel.clientSecret
|
||||
)
|
||||
accountManager.addAccount(loginModel.domain, authData)
|
||||
loginState.send(loginState.value.copy(state = LoginState.SUCCESS_FINAL))
|
||||
loginState.value = loginState.value.copy(state = LoginState.SUCCESS_FINAL)
|
||||
},
|
||||
{
|
||||
loginState.send(loginState.value.copy(state = LoginState.AUTH_ERROR))
|
||||
loginState.value = loginState.value.copy(state = LoginState.AUTH_ERROR)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeError() {
|
||||
viewModelScope.launch {
|
||||
loginState.send(loginState.value.copy(state = LoginState.NO_ERROR))
|
||||
}
|
||||
loginState.value = loginState.value.copy(state = LoginState.NO_ERROR)
|
||||
}
|
||||
|
||||
private fun canonicalizeDomain(domain: String): String {
|
||||
|
@ -131,6 +125,6 @@ class LoginViewModel @Inject constructor(
|
|||
if (at != -1) {
|
||||
s = s.substring(at + 1)
|
||||
}
|
||||
return s.trim().toLowerCase(Locale.ROOT)
|
||||
return s.trim().lowercase(Locale.ROOT)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ import at.connyduck.pixelcat.databinding.ActivityMainBinding
|
|||
import at.connyduck.pixelcat.db.AccountManager
|
||||
import com.fxn.pix.Options
|
||||
import com.fxn.pix.Pix
|
||||
import com.fxn.utility.ImageQuality
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
|
@ -54,8 +53,8 @@ class MainActivity : BaseActivity() {
|
|||
private lateinit var mainFragmentAdapter: MainFragmentAdapter
|
||||
|
||||
private val onNavigationItemSelectedListener =
|
||||
BottomNavigationView.OnNavigationItemSelectedListener { item ->
|
||||
return@OnNavigationItemSelectedListener when (item.itemId) {
|
||||
NavigationBarView.OnItemSelectedListener { item ->
|
||||
return@OnItemSelectedListener when (item.itemId) {
|
||||
R.id.navigation_home -> {
|
||||
binding.mainViewPager.setCurrentItem(0, false)
|
||||
true
|
||||
|
@ -67,7 +66,6 @@ class MainActivity : BaseActivity() {
|
|||
R.id.navigation_compose -> {
|
||||
val options = Options.init()
|
||||
.setRequestCode(100)
|
||||
.setImageQuality(ImageQuality.HIGH)
|
||||
.setScreenOrientation(Options.SCREEN_ORIENTATION_PORTRAIT)
|
||||
|
||||
Pix.start(this, options)
|
||||
|
@ -102,7 +100,7 @@ class MainActivity : BaseActivity() {
|
|||
binding.mainViewPager.adapter = mainFragmentAdapter
|
||||
binding.mainViewPager.isUserInputEnabled = false
|
||||
|
||||
binding.navigation.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener)
|
||||
binding.navigation.setOnItemSelectedListener(onNavigationItemSelectedListener)
|
||||
|
||||
mainViewModel.whatever()
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.paging.ExperimentalPagingApi
|
||||
import androidx.paging.LoadState
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
|
@ -52,7 +51,6 @@ class NotificationsFragment :
|
|||
|
||||
private val binding by viewBinding(FragmentNotificationsBinding::bind)
|
||||
|
||||
@ExperimentalPagingApi
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
binding.notificationSwipeRefresh.setColorSchemeColors(
|
||||
|
|
|
@ -33,14 +33,13 @@ import kotlinx.coroutines.flow.asFlow
|
|||
import kotlinx.coroutines.flow.flatMapConcat
|
||||
import javax.inject.Inject
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class, FlowPreview::class)
|
||||
class NotificationsViewModel @Inject constructor(
|
||||
accountManager: AccountManager,
|
||||
private val db: AppDatabase,
|
||||
private val api: FediverseApi
|
||||
) : ViewModel() {
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
@ExperimentalPagingApi
|
||||
val notificationsFlow = accountManager::activeAccount.asFlow()
|
||||
.flatMapConcat { activeAccount ->
|
||||
Pager(
|
||||
|
|
|
@ -23,13 +23,13 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.paging.ExperimentalPagingApi
|
||||
import androidx.recyclerview.widget.ConcatAdapter
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import at.connyduck.pixelcat.R
|
||||
import at.connyduck.pixelcat.components.bottomsheet.accountselection.AccountSelectionBottomSheet
|
||||
import at.connyduck.pixelcat.components.bottomsheet.menu.MenuBottomSheet
|
||||
import at.connyduck.pixelcat.components.main.MainActivity
|
||||
import at.connyduck.pixelcat.components.util.Error
|
||||
import at.connyduck.pixelcat.components.util.Success
|
||||
import at.connyduck.pixelcat.components.util.extension.getDisplayWidthInPx
|
||||
import at.connyduck.pixelcat.dagger.ViewModelFactory
|
||||
|
@ -63,7 +63,6 @@ class ProfileFragment : DaggerFragment(R.layout.fragment_profile) {
|
|||
private val headerAdapter = ProfileHeaderAdapter()
|
||||
private lateinit var imageAdapter: ProfileImageAdapter
|
||||
|
||||
@ExperimentalPagingApi
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
if (activity is MainActivity) {
|
||||
|
@ -111,23 +110,22 @@ class ProfileFragment : DaggerFragment(R.layout.fragment_profile) {
|
|||
viewModel.setAccountInfo(arg(ACCOUNT_ID))
|
||||
|
||||
viewModel.profile.observe(
|
||||
viewLifecycleOwner,
|
||||
{
|
||||
when (it) {
|
||||
is Success -> onAccountChanged(it.data)
|
||||
is Error -> showError()
|
||||
}
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
when (it) {
|
||||
is Success -> onAccountChanged(it.data)
|
||||
is Error -> showError()
|
||||
else -> {}
|
||||
}
|
||||
)
|
||||
}
|
||||
viewModel.relationship.observe(
|
||||
viewLifecycleOwner,
|
||||
{
|
||||
when (it) {
|
||||
is Success -> onRelationshipChanged(it.data)
|
||||
is Error -> showError()
|
||||
}
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
when (it) {
|
||||
is Success -> onRelationshipChanged(it.data)
|
||||
is Error -> showError()
|
||||
}
|
||||
)
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.imageFlow.collectLatest { imageAdapter.submitData(it) }
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package at.connyduck.pixelcat.components.profile
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import at.connyduck.pixelcat.db.AccountManager
|
||||
import at.connyduck.pixelcat.model.Status
|
||||
import at.connyduck.pixelcat.network.FediverseApi
|
||||
|
@ -54,4 +55,6 @@ class ProfileImagePagingSource(
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun getRefreshKey(state: PagingState<String, Status>): String? = null
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import kotlinx.coroutines.FlowPreview
|
|||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@OptIn(FlowPreview::class, ExperimentalPagingApi::class)
|
||||
class ProfileViewModel @Inject constructor(
|
||||
private val api: FediverseApi,
|
||||
private val accountManager: AccountManager
|
||||
|
@ -45,8 +46,6 @@ class ProfileViewModel @Inject constructor(
|
|||
val profile = MutableLiveData<UiState<Account>>()
|
||||
val relationship = MutableLiveData<UiState<Relationship>>()
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
@ExperimentalPagingApi
|
||||
val imageFlow = Pager(
|
||||
config = PagingConfig(pageSize = 10, enablePlaceholders = false),
|
||||
pagingSourceFactory = { ProfileImagePagingSource(api, accountId, accountManager) }
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.paging.ExperimentalPagingApi
|
||||
import androidx.paging.LoadState
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
|
@ -49,7 +48,6 @@ class TimelineFragment : DaggerFragment(R.layout.fragment_timeline), TimeLineAct
|
|||
|
||||
private val binding by viewBinding(FragmentTimelineBinding::bind)
|
||||
|
||||
@ExperimentalPagingApi
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
binding.timelineSwipeRefresh.setColorSchemeColors(
|
||||
|
|
|
@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.flatMapConcat
|
|||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@OptIn(FlowPreview::class, ExperimentalPagingApi::class)
|
||||
class TimelineViewModel @Inject constructor(
|
||||
accountManager: AccountManager,
|
||||
private val db: AppDatabase,
|
||||
|
@ -42,8 +43,6 @@ class TimelineViewModel @Inject constructor(
|
|||
private val useCases: TimelineUseCases
|
||||
) : ViewModel() {
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
@ExperimentalPagingApi
|
||||
val statusFlow = accountManager::activeAccount.asFlow()
|
||||
.flatMapConcat { activeAccount ->
|
||||
Pager(
|
||||
|
|
|
@ -76,46 +76,44 @@ class DetailActivity : BaseActivity(), TimeLineActionListener {
|
|||
binding.detailRecyclerView.adapter = ConcatAdapter(statusAdapter, repliesAdapter)
|
||||
|
||||
viewModel.currentStatus.observe(
|
||||
this,
|
||||
{
|
||||
when (it) {
|
||||
is Success -> {
|
||||
binding.detailSwipeRefresh.show()
|
||||
binding.detailStatus.hide()
|
||||
binding.detailProgress.hide()
|
||||
binding.detailSwipeRefresh.isRefreshing = false
|
||||
binding.detailRecyclerView.show()
|
||||
statusAdapter.submitList(listOf(it.data))
|
||||
it.data?.let { status ->
|
||||
if (intent.getBooleanExtra(EXTRA_REPLY, false)) {
|
||||
intent.removeExtra(EXTRA_REPLY)
|
||||
onReply(status)
|
||||
}
|
||||
this
|
||||
) {
|
||||
when (it) {
|
||||
is Success -> {
|
||||
binding.detailSwipeRefresh.show()
|
||||
binding.detailStatus.hide()
|
||||
binding.detailProgress.hide()
|
||||
binding.detailSwipeRefresh.isRefreshing = false
|
||||
binding.detailRecyclerView.show()
|
||||
statusAdapter.submitList(listOf(it.data))
|
||||
it.data?.let { status ->
|
||||
if (intent.getBooleanExtra(EXTRA_REPLY, false)) {
|
||||
intent.removeExtra(EXTRA_REPLY)
|
||||
onReply(status)
|
||||
}
|
||||
}
|
||||
is Loading -> {
|
||||
binding.detailSwipeRefresh.hide()
|
||||
binding.detailStatus.hide()
|
||||
binding.detailProgress.show()
|
||||
}
|
||||
is Error -> {
|
||||
binding.detailSwipeRefresh.hide()
|
||||
binding.detailStatus.show()
|
||||
binding.detailProgress.hide()
|
||||
binding.detailStatus.showGeneralError()
|
||||
}
|
||||
}
|
||||
is Loading -> {
|
||||
binding.detailSwipeRefresh.hide()
|
||||
binding.detailStatus.hide()
|
||||
binding.detailProgress.show()
|
||||
}
|
||||
is Error -> {
|
||||
binding.detailSwipeRefresh.hide()
|
||||
binding.detailStatus.show()
|
||||
binding.detailProgress.hide()
|
||||
binding.detailStatus.showGeneralError()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.replies.observe(
|
||||
this,
|
||||
{
|
||||
if (it is Success) {
|
||||
repliesAdapter.submitList(it.data)
|
||||
}
|
||||
this
|
||||
) {
|
||||
if (it is Success) {
|
||||
repliesAdapter.submitList(it.data)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFavorite(status: StatusEntity) {
|
||||
|
|
|
@ -132,7 +132,7 @@ class DetailViewModel @Inject constructor(
|
|||
NewStatus(
|
||||
status = replyText,
|
||||
inReplyToId = statusToReply.actionableId,
|
||||
visibility = statusToReply.visibility.name.toLowerCase(Locale.ROOT),
|
||||
visibility = statusToReply.visibility.name.lowercase(Locale.ROOT),
|
||||
sensitive = statusToReply.sensitive,
|
||||
mediaIds = null
|
||||
)
|
||||
|
|
|
@ -27,6 +27,6 @@ import java.util.Locale
|
|||
* @return the mime type, or null if it couldn't be determined
|
||||
*/
|
||||
fun getMimeType(filePath: String): String? {
|
||||
val extension = filePath.split('.').lastOrNull()?.toLowerCase(Locale.ROOT) ?: return null
|
||||
val extension = filePath.split('.').lastOrNull()?.lowercase(Locale.ROOT) ?: return null
|
||||
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ data class Account(
|
|||
) {
|
||||
|
||||
val name: String
|
||||
get() = if (displayName.isEmpty()) {
|
||||
get() = displayName.ifEmpty {
|
||||
localUsername
|
||||
} else displayName
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
|
|
@ -32,17 +32,16 @@ class FragmentViewBindingDelegate<T : ViewBinding>(
|
|||
object : DefaultLifecycleObserver {
|
||||
override fun onCreate(owner: LifecycleOwner) {
|
||||
fragment.viewLifecycleOwnerLiveData.observe(
|
||||
fragment,
|
||||
{ t ->
|
||||
t?.lifecycle?.addObserver(
|
||||
object : DefaultLifecycleObserver {
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
binding = null
|
||||
}
|
||||
fragment
|
||||
) { t ->
|
||||
t?.lifecycle?.addObserver(
|
||||
object : DefaultLifecycleObserver {
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
binding = null
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -5,9 +5,9 @@ buildscript {
|
|||
gradlePluginPortal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:4.1.0")
|
||||
classpath(kotlin("gradle-plugin", version = "1.4.10"))
|
||||
classpath("org.jlleitschuh.gradle:ktlint-gradle:9.4.0")
|
||||
classpath("com.android.tools.build:gradle:7.1.0")
|
||||
classpath(kotlin("gradle-plugin", version = "1.6.10"))
|
||||
classpath("org.jlleitschuh.gradle:ktlint-gradle:10.2.1")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
Loading…
Reference in New Issue