version updates

This commit is contained in:
Gergely Hegedus 2022-04-21 12:36:39 +03:00
parent 12e6f01d29
commit b256cb9bf2
28 changed files with 302 additions and 234 deletions

View file

@ -39,10 +39,10 @@ class SharedPreferencesManagerImpl private constructor(private val sharedPrefere
override fun getValue(thisRef: SharedPreferencesManagerImpl, property: KProperty<*>): Flow<Set<String>> =
callbackFlow {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ ->
offer(thisRef.getValues())
trySend(thisRef.getValues())
}
thisRef.sharedPreferences.registerOnSharedPreferenceChangeListener(listener)
offer(thisRef.getValues())
trySend(thisRef.getValues())
awaitClose {
thisRef.sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener)

View file

@ -5,6 +5,6 @@ import org.fnives.tiktokdownloader.data.network.parsing.response.VideoResponse
class VideoResponseConverter : ParsingExceptionThrowingConverter<VideoResponse>() {
override fun convertSafely(value: ResponseBody): VideoResponse? =
VideoResponse(value.contentType(), value.byteStream())
override fun convertSafely(responseBody: ResponseBody): VideoResponse? =
VideoResponse(responseBody.contentType(), responseBody.byteStream())
}

View file

@ -1,7 +1,7 @@
package org.fnives.tiktokdownloader.data.usecase
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
@ -16,6 +16,7 @@ import org.fnives.tiktokdownloader.data.model.VideoInPending
import org.fnives.tiktokdownloader.data.model.VideoInProgress
import org.fnives.tiktokdownloader.data.model.VideoState
@OptIn(FlowPreview::class)
class StateOfVideosObservableUseCase(
videoInProgressLocalSource: VideoInProgressLocalSource,
videoInPendingLocalSource: VideoInPendingLocalSource,

View file

@ -2,6 +2,7 @@ package org.fnives.tiktokdownloader.data.usecase
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@ -30,6 +31,7 @@ import org.fnives.tiktokdownloader.data.network.exceptions.CaptchaRequiredExcept
import org.fnives.tiktokdownloader.data.network.exceptions.NetworkException
import org.fnives.tiktokdownloader.data.network.exceptions.ParsingException
@OptIn(FlowPreview::class)
class VideoDownloadingProcessorUseCase(
private val tikTokDownloadRemoteSource: TikTokDownloadRemoteSource,
private val videoInProgressLocalSource: VideoInProgressLocalSource,

View file

@ -15,6 +15,7 @@ class ViewModelFactory(
private val viewModelModule: ViewModelModule,
) : AbstractSavedStateViewModelFactory(savedStateRegistryOwner, defaultArgs) {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T {
val viewModel = when (modelClass) {
MainViewModel::class.java -> viewModelModule.mainViewModel(handle)

View file

@ -6,7 +6,6 @@ import android.os.Bundle
import android.view.MenuItem
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.OvershootInterpolator
import androidx.activity.viewModels
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout
@ -43,28 +42,28 @@ class MainActivity : AppCompatActivity() {
animateFabClicked(downloadFab)
viewModel.onFetchDownloadClicked()
}
viewModel.refreshActionVisibility.observe(this, {
viewModel.refreshActionVisibility.observe(this) {
animateFabVisibility(downloadFab, it == true)
})
viewModel.errorMessage.observe(this, {
}
viewModel.errorMessage.observe(this) {
val stringRes = it?.item?.stringRes ?: return@observe
Snackbar.make(snackBarAnchor, stringRes, Snackbar.LENGTH_SHORT).show()
})
}
}
private fun setupBottomNavigationView(bottomNavigationView: BottomNavigationView, savedInstanceState: Bundle?) {
bottomNavigationView.setOnNavigationItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedListener { item ->
bottomNavigationView.setOnItemSelectedListener { item ->
val fragment = when (item.itemId) {
R.id.help_menu_item -> HelpFragment.newInstance()
R.id.queue_menu_item -> QueueFragment.newInstance()
else -> return@OnNavigationItemSelectedListener false
else -> return@setOnItemSelectedListener false
}
item.toScreen()?.let(viewModel::onScreenSelected)
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_holder, fragment)
.commit()
return@OnNavigationItemSelectedListener true
})
return@setOnItemSelectedListener true
}
if (savedInstanceState == null) {
bottomNavigationView.selectedItemId = R.id.queue_menu_item
}

View file

@ -75,7 +75,7 @@ class QueueService : Service() {
.setSmallIcon(R.drawable.ic_download)
.setContentIntent(buildMainPendingIntent(this))
.setAutoCancel(true)
.setNotificationSilent()
.setSilent(true)
.build()
NotificationState.Finish -> {
stopSelf()