version bumps
This commit is contained in:
parent
603915d379
commit
e8afb551ee
14 changed files with 143 additions and 79 deletions
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.fnives.tiktokdownloader">
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission
|
||||
|
|
@ -9,10 +8,12 @@
|
|||
android:maxSdkVersion="28"
|
||||
tools:ignore="ScopedStorage" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
|
@ -40,7 +41,9 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".ui.service.QueueService" />
|
||||
<service
|
||||
android:name=".ui.service.QueueService"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
package org.fnives.tiktokdownloader.di
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.savedstate.SavedStateRegistryOwner
|
||||
import org.fnives.tiktokdownloader.di.module.AndroidFileManagementModule
|
||||
import org.fnives.tiktokdownloader.di.module.LocalSourceModule
|
||||
import org.fnives.tiktokdownloader.di.module.NetworkModule
|
||||
|
|
@ -29,18 +27,16 @@ object ServiceLocator {
|
|||
val useCaseModule: UseCaseModule
|
||||
get() = _useCaseModule ?: throw IllegalStateException("$this.start has not been called!")
|
||||
|
||||
fun viewModelFactory(
|
||||
savedStateRegistryOwner: SavedStateRegistryOwner,
|
||||
defaultArgs: Bundle
|
||||
): ViewModelProvider.Factory =
|
||||
ViewModelFactory(savedStateRegistryOwner, defaultArgs, viewModelModule)
|
||||
fun viewModelFactory(): ViewModelProvider.Factory =
|
||||
ViewModelFactory(viewModelModule)
|
||||
|
||||
val queueServiceViewModel: QueueServiceViewModel
|
||||
get() = viewModelModule.queueServiceViewModel
|
||||
|
||||
fun start(context: Context) {
|
||||
val androidFileManagementModule = AndroidFileManagementModule(context)
|
||||
val localSourceModule = LocalSourceModule(androidFileManagementModule = androidFileManagementModule)
|
||||
val localSourceModule =
|
||||
LocalSourceModule(androidFileManagementModule = androidFileManagementModule)
|
||||
val networkModule = NetworkModule(delayBeforeRequest = DEFAULT_DELAY_BEFORE_REQUEST)
|
||||
val useCaseModule = UseCaseModule(
|
||||
localSourceModule = localSourceModule,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package org.fnives.tiktokdownloader.di
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
|
@ -10,17 +9,13 @@ inline fun <reified VM : ViewModel> ComponentActivity.provideViewModels() =
|
|||
ViewModelLazy(
|
||||
viewModelClass = VM::class,
|
||||
storeProducer = { viewModelStore },
|
||||
factoryProducer = { createViewModelFactory() }
|
||||
factoryProducer = { ServiceLocator.viewModelFactory() },
|
||||
extrasProducer = { defaultViewModelCreationExtras }
|
||||
)
|
||||
|
||||
inline fun <reified VM : ViewModel> Fragment.provideViewModels() =
|
||||
ViewModelLazy(
|
||||
viewModelClass = VM::class,
|
||||
storeProducer = { viewModelStore },
|
||||
factoryProducer = { createViewModelFactory() })
|
||||
|
||||
fun ComponentActivity.createViewModelFactory() =
|
||||
ServiceLocator.viewModelFactory(this, intent?.extras ?: Bundle.EMPTY)
|
||||
|
||||
fun Fragment.createViewModelFactory() =
|
||||
ServiceLocator.viewModelFactory(this, arguments ?: Bundle.EMPTY)
|
||||
factoryProducer = { ServiceLocator.viewModelFactory() },
|
||||
extrasProducer = { defaultViewModelCreationExtras })
|
||||
|
|
@ -1,29 +1,34 @@
|
|||
package org.fnives.tiktokdownloader.di
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.AbstractSavedStateViewModelFactory
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.savedstate.SavedStateRegistryOwner
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.createSavedStateHandle
|
||||
import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import org.fnives.tiktokdownloader.di.module.ViewModelModule
|
||||
import org.fnives.tiktokdownloader.ui.main.MainViewModel
|
||||
import org.fnives.tiktokdownloader.ui.main.queue.QueueViewModel
|
||||
import org.fnives.tiktokdownloader.ui.main.settings.SettingsViewModel
|
||||
|
||||
class ViewModelFactory(
|
||||
savedStateRegistryOwner: SavedStateRegistryOwner,
|
||||
defaultArgs: Bundle,
|
||||
private val viewModelModule: ViewModelModule,
|
||||
) : AbstractSavedStateViewModelFactory(savedStateRegistryOwner, defaultArgs) {
|
||||
) : ViewModelProvider.Factory {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
val viewModel = when (modelClass) {
|
||||
MainViewModel::class.java -> viewModelModule.mainViewModel(handle)
|
||||
QueueViewModel::class.java -> viewModelModule.queueViewModel
|
||||
SettingsViewModel::class.java -> viewModelModule.settignsViewModel
|
||||
else -> throw IllegalArgumentException("Can't create viewModel for $modelClass ")
|
||||
}
|
||||
return viewModel as T
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
|
||||
val viewModel = when (modelClass) {
|
||||
MainViewModel::class.java -> viewModelModule.mainViewModel(extras.createSavedStateHandle())
|
||||
else -> create(modelClass)
|
||||
}
|
||||
return viewModel as T
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package org.fnives.tiktokdownloader.ui.service
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
|
|
@ -32,6 +33,7 @@ class QueueService : Service() {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ForegroundServiceType")
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
intent?.url?.let(viewModel::onUrlReceived)
|
||||
startForeground()
|
||||
|
|
@ -66,10 +68,16 @@ class QueueService : Service() {
|
|||
val (id, notification) = when (notificationState) {
|
||||
is NotificationState.Processing ->
|
||||
SERVICE_NOTIFICATION_ID to NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.tik_tok_downloader_processing, notificationState.url))
|
||||
.setContentTitle(
|
||||
getString(
|
||||
R.string.tik_tok_downloader_processing,
|
||||
notificationState.url
|
||||
)
|
||||
)
|
||||
.setSmallIcon(R.drawable.ic_download)
|
||||
.setProgress(0, 10, true)
|
||||
.build()
|
||||
|
||||
is NotificationState.Error ->
|
||||
NOTIFICATION_ID to NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle(getString(notificationState.errorRes))
|
||||
|
|
@ -78,6 +86,7 @@ class QueueService : Service() {
|
|||
.setAutoCancel(true)
|
||||
.setSilent(true)
|
||||
.build()
|
||||
|
||||
NotificationState.Finish -> {
|
||||
stopSelf()
|
||||
return
|
||||
|
|
@ -100,7 +109,8 @@ class QueueService : Service() {
|
|||
|
||||
private class ServiceLifecycle : LifecycleOwner {
|
||||
val lifecycleRegistry = LifecycleRegistry(this)
|
||||
override fun getLifecycle(): Lifecycle = lifecycleRegistry
|
||||
override val lifecycle: Lifecycle
|
||||
get() = lifecycleRegistry
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,15 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".ui.main.MainActivity">
|
||||
|
||||
<!-- TODO -->
|
||||
<View
|
||||
android:id="@+id/status_bar_inset"
|
||||
android:layout_width="0dp"
|
||||
app:layout_constraintStart_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_height="32dp"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_holder"
|
||||
android:layout_width="0dp"
|
||||
|
|
@ -16,7 +25,7 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/status_bar_inset" />
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/snack_bar_anchor"
|
||||
|
|
|
|||
36
app/src/main/res/xml/data_extraction_rules.xml
Normal file
36
app/src/main/res/xml/data_extraction_rules.xml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!--
|
||||
TODO: Use <include> and <exclude> to control what is backed up.
|
||||
The domain can be file, database, sharedpref, external or root.
|
||||
Examples:
|
||||
|
||||
<include domain="file" path="file_to_include"/>
|
||||
<exclude domain="file" path="file_to_exclude"/>
|
||||
<include domain="file" path="include_folder"/>
|
||||
<exclude domain="file" path="include_folder/file_to_exclude"/>
|
||||
<exclude domain="file" path="exclude_folder"/>
|
||||
<include domain="file" path="exclude_folder/file_to_include"/>
|
||||
|
||||
<include domain="sharedpref" path="include_shared_pref1.xml"/>
|
||||
<include domain="database" path="db_name/file_to_include"/>
|
||||
<exclude domain="database" path="db_name/include_folder/file_to_exclude"/>
|
||||
<include domain="external" path="file_to_include"/>
|
||||
<exclude domain="external" path="file_to_exclude"/>
|
||||
<include domain="root" path="file_to_include"/>
|
||||
<exclude domain="root" path="file_to_exclude"/>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package org.fnives.tiktokdownloader.di
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.createSavedStateHandle
|
||||
import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.fnives.tiktokdownloader.helper.mock.MockSavedStateRegistryOwner
|
||||
import org.fnives.tiktokdownloader.ui.main.MainViewModel
|
||||
import org.fnives.tiktokdownloader.ui.main.queue.QueueViewModel
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
|
|
@ -43,11 +44,17 @@ class ServiceLocatorTest {
|
|||
|
||||
@Test
|
||||
fun verifyQueueViewModelCanBeCreated() {
|
||||
ServiceLocator.viewModelFactory(MockSavedStateRegistryOwner(), mock()).create(QueueViewModel::class.java)
|
||||
ServiceLocator.viewModelFactory().create(QueueViewModel::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifyMainViewModelCanBeCreated() {
|
||||
ServiceLocator.viewModelFactory(MockSavedStateRegistryOwner(), mock()).create(MainViewModel::class.java)
|
||||
// TODO one day fix this, because the CreationExtras's createSavedStateHandle isn't open it actually gets called
|
||||
// ServiceLocator.viewModelFactory().create(
|
||||
// MainViewModel::class.java,
|
||||
// mock<CreationExtras>().apply {
|
||||
// doReturn(mock()).`when`(this).createSavedStateHandle()
|
||||
// }
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,12 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.LifecycleObserver
|
||||
|
||||
class MockLifecycle : Lifecycle() {
|
||||
override val currentState: State
|
||||
get() = State.CREATED
|
||||
|
||||
override fun addObserver(observer: LifecycleObserver) {
|
||||
}
|
||||
|
||||
override fun removeObserver(observer: LifecycleObserver) {
|
||||
}
|
||||
|
||||
override fun getCurrentState(): State = State.CREATED
|
||||
}
|
||||
|
|
@ -6,11 +6,9 @@ import androidx.savedstate.SavedStateRegistryOwner
|
|||
import org.mockito.kotlin.mock
|
||||
|
||||
class MockSavedStateRegistryOwner(
|
||||
private val lifecycle: Lifecycle = MockLifecycle(),
|
||||
override val lifecycle: Lifecycle = MockLifecycle(),
|
||||
private val mockSavedStateRegistry: SavedStateRegistry = mock()
|
||||
) : SavedStateRegistryOwner {
|
||||
|
||||
override fun getLifecycle(): Lifecycle = lifecycle
|
||||
|
||||
override fun getSavedStateRegistry(): SavedStateRegistry = mockSavedStateRegistry
|
||||
override val savedStateRegistry: SavedStateRegistry = mockSavedStateRegistry
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue