version bumps

This commit is contained in:
Gergely Hegedus 2025-05-13 14:48:37 +03:00
parent 603915d379
commit e8afb551ee
14 changed files with 143 additions and 79 deletions

View file

@ -1,7 +1,7 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "kotlin-kapt"
// id "kotlin-kapt"
}
try {
apply from: 'signing.config.gradle'
@ -14,12 +14,12 @@ try {
}
android {
compileSdkVersion 31
compileSdk 35
defaultConfig {
applicationId "org.fnives.tiktokdownloader"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 35
versionCode 2
versionName "1.3.1"
@ -43,21 +43,18 @@ android {
}
release {
signingConfig signingConfigs.release
debuggable true
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
buildFeatures.buildConfig = true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
}
lintOptions {
abortOnError true
jvmTarget = "17"
}
testOptions.unitTests {
@ -71,53 +68,57 @@ android {
}
}
}
}
tasks.configureEach { task ->
if (task.taskIdentity.type.toString() == "class org.jetbrains.kotlin.gradle.tasks.KotlinCompile") {
task.kotlinOptions {
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
namespace 'org.fnives.tiktokdownloader'
lint {
abortOnError true
}
}
//tasks.configureEach { task ->
// if (task.taskIdentity.type.toString() == "class org.jetbrains.kotlin.gradle.tasks.KotlinCompile") {
// task.kotlinOptions {
// freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
// }
// }
//}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
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.core:core-ktx:1.16.0"
implementation "androidx.appcompat:appcompat:1.7.0"
implementation "androidx.activity:activity-ktx:1.10.1"
implementation "androidx.fragment:fragment-ktx:1.8.6"
implementation "com.google.android.material:material:1.12.0"
implementation "androidx.constraintlayout:constraintlayout:2.2.1"
// Coroutines
def coroutine_version = "1.6.0"
def coroutine_version = "1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.fragment:fragment-ktx:1.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.0"
implementation "androidx.fragment:fragment-ktx:1.8.6"
def glide_version = "4.11.0"
def glide_version = "4.15.1"
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
// kapt "com.github.bumptech.glide:compiler:$glide_version"
def okhttp_version = "4.9.3"
def okhttp_version = "4.12.0"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:11.0.1'
def junit_version = "5.7.0"
def junit_version = "5.8.2"
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
testImplementation 'com.jraska.livedata:testing-ktx:1.2.0'
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
testImplementation "commons-io:commons-io:2.8.0"
testImplementation "commons-io:commons-io:2.13.0"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutine_version"
testImplementation "androidx.arch.core:core-testing:2.1.0"
testImplementation "androidx.arch.core:core-testing:2.2.0"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation "androidx.test.ext:junit:1.2.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
}

View file

@ -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>

View file

@ -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,

View file

@ -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 })

View file

@ -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
}
}

View file

@ -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 {

View file

@ -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"

View 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>

View file

@ -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()
// }
// )
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.6.20"
ext.kotlin_version = '2.1.21'
repositories {
mavenCentral()
google()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:8.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View file

@ -18,4 +18,7 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

View file

@ -1,6 +1,6 @@
#Thu Jan 27 21:44:07 EET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME