diff --git a/analytics/build.gradle b/analytics/build.gradle index bb08a7c316..7f20b2b222 100644 --- a/analytics/build.gradle +++ b/analytics/build.gradle @@ -13,6 +13,16 @@ android { buildConfigField "boolean", "SEND_EVENTS", getProperty('config.enableAnalyticsForDebugBuilds') } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.analytics' } diff --git a/app/build.gradle b/app/build.gradle index 5dd2141dd6..892517a255 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -118,15 +118,6 @@ android { } } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = '1.8' - } - composeOptions { kotlinCompilerExtensionVersion libs.versions.composeKotlinCompilerVersion.get() } @@ -136,6 +127,15 @@ android { compose true } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + splits { // Configures multiple APKs based on ABI. abi { @@ -151,16 +151,6 @@ android { namespace 'com.anytypeio.anytype' } -kotlin { - jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } -} - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of(11)) -} - dependencies { implementation project(':domain') diff --git a/clipboard/build.gradle b/clipboard/build.gradle index acacc6b054..6c65773ae5 100644 --- a/clipboard/build.gradle +++ b/clipboard/build.gradle @@ -15,6 +15,16 @@ android { buildConfigField ANYTYPE_CLIPBOARD_LABEL_TYPE, ANYTYPE_CLIPBOARD_LABEL, ANYTYPE_CLIPBOARD_LABEL_VALUE } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.clipboard' } diff --git a/core-ui/build.gradle b/core-ui/build.gradle index 3293f6148a..42a3dabf84 100644 --- a/core-ui/build.gradle +++ b/core-ui/build.gradle @@ -18,6 +18,16 @@ android { viewBinding true compose true } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.core_ui' } diff --git a/core-utils/build.gradle b/core-utils/build.gradle index e4485412a4..286231529a 100644 --- a/core-utils/build.gradle +++ b/core-utils/build.gradle @@ -12,6 +12,16 @@ android { buildFeatures { viewBinding true } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.core_utils' } diff --git a/crash-reporting/build.gradle b/crash-reporting/build.gradle index afa4ebe919..4612f46144 100644 --- a/crash-reporting/build.gradle +++ b/crash-reporting/build.gradle @@ -17,6 +17,16 @@ android { } includeDependenciesReport = true } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.crash_reporting' } diff --git a/device/build.gradle b/device/build.gradle index d4f8290b3e..68a7c164de 100644 --- a/device/build.gradle +++ b/device/build.gradle @@ -23,5 +23,14 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.device' } \ No newline at end of file diff --git a/domain/src/test/java/com/anytypeio/anytype/domain/misc/GetObjectTypeTest.kt b/domain/src/test/java/com/anytypeio/anytype/domain/misc/GetObjectTypeTest.kt index 776e5d65a4..eca8a172fb 100644 --- a/domain/src/test/java/com/anytypeio/anytype/domain/misc/GetObjectTypeTest.kt +++ b/domain/src/test/java/com/anytypeio/anytype/domain/misc/GetObjectTypeTest.kt @@ -211,9 +211,9 @@ class GetObjectTypeTest { } private fun stubGetObjectTypes(types: List) { - usecase.stub { + repo.stub { onBlocking { - repo.searchObjects( + searchObjects( filters = emptyList(), keys = listOf(Relations.ID), sorts = emptyList(), diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f8aff73859..90b6435269 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,24 +1,27 @@ [versions] middlewareVersion = "v0.30.0-rc5" -kotlinVersion = '1.7.10' +kotlinVersion = '1.8.22' androidxCoreVersion = "1.12.0" androidxComposeVersion = '1.5.0' -composeKotlinCompilerVersion = '1.3.1' -composeMaterial3Version = '1.1.1' +composeKotlinCompilerVersion = '1.4.8' +composeMaterial3Version = '1.1.2' composeMaterialVersion = '1.5.0' composeConstraintLayoutVersion = '1.0.1' -activityComposeVersion = '1.7.2' +dokkaVersion = '1.8.20' + +activityComposeVersion = '1.8.1' composeReorderableVersion = '0.9.6' accompanistVersion = "0.30.0" appcompatVersion = '1.6.1' +androidXAnnotationVersion = '1.7.0' fragmentVersion = "1.6.2" exoplayerVersion = "2.19.1" wireVersion = "4.5.2" glideVersion = "4.14.2" -mockitoKotlinVersion = "4.1.0" +mockitoKotlinVersion = "5.1.0" junitVersion = '4.13.2' androidJunitVersion = "1.1.4" runnerVersion = "1.5.0" @@ -84,7 +87,7 @@ composeReorderable = { module = "org.burnoutcrew.composereorderable:reorderable" composeConstraintLayout = { module = "androidx.constraintlayout:constraintlayout-compose", version.ref = "composeConstraintLayoutVersion" } kotlinxSerializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.4.1" } appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompatVersion" } -androidAnnotations = { module = "androidx.annotation:annotation", version.ref = "appcompatVersion" } +androidAnnotations = { module = "androidx.annotation:annotation", version.ref = "androidXAnnotationVersion" } design = { module = "com.google.android.material:material", version = "1.7.0" } fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentVersion" } fragmentTesting = { module = "androidx.fragment:fragment-testing", version.ref = "fragmentVersion" } @@ -162,12 +165,12 @@ appUpdater = { module = "com.github.PLPsiSoft:AndroidAppUpdater", version = "991 [bundles] [plugins] -application = { id = "com.android.application", version = "8.1.4" } -library = { id = "com.android.library", version = "8.1.4" } +application = { id = "com.android.application", version = "8.2.0" } +library = { id = "com.android.library", version = "8.2.0" } kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" } -dokka = { id = "org.jetbrains.dokka", version.ref = "kotlinVersion" } +dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaVersion" } kserialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinVersion" } wire = { id = "com.squareup.wire", version = "4.4.3" } -firebaseDistribution = { id = "com.google.firebase.appdistribution", version = "3.1.1" } +firebaseDistribution = { id = "com.google.firebase.appdistribution", version = "4.0.1" } kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlinVersion" } -gms = { id = "com.google.gms.google-services", version = "4.3.15" } \ No newline at end of file +gms = { id = "com.google.gms.google-services", version = "4.4.0" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3a02907943..4466424467 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Dec 14 17:20:55 CET 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/library-emojifier/build.gradle b/library-emojifier/build.gradle index 659c8dc9d9..b7be8550e0 100644 --- a/library-emojifier/build.gradle +++ b/library-emojifier/build.gradle @@ -16,5 +16,14 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } + namespace 'com.anytypeio.anytype.emojifier' } \ No newline at end of file diff --git a/library-page-icon-picker-widget/build.gradle b/library-page-icon-picker-widget/build.gradle index 719d89be42..45db7e1b12 100644 --- a/library-page-icon-picker-widget/build.gradle +++ b/library-page-icon-picker-widget/build.gradle @@ -7,6 +7,14 @@ android { buildFeatures { viewBinding true } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.library_page_icon_picker_widget' } diff --git a/library-syntax-highlighter/build.gradle b/library-syntax-highlighter/build.gradle index b1801aa8ef..8820c03dca 100644 --- a/library-syntax-highlighter/build.gradle +++ b/library-syntax-highlighter/build.gradle @@ -20,5 +20,13 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.library_syntax_highlighter' } \ No newline at end of file diff --git a/localization/build.gradle b/localization/build.gradle index 28219f6d35..cd89750b7d 100644 --- a/localization/build.gradle +++ b/localization/build.gradle @@ -9,5 +9,13 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.localization' } \ No newline at end of file diff --git a/middleware/build.gradle b/middleware/build.gradle index 87ac892d65..521dfc018a 100644 --- a/middleware/build.gradle +++ b/middleware/build.gradle @@ -26,5 +26,13 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.middleware' } \ No newline at end of file diff --git a/persistence/build.gradle b/persistence/build.gradle index 4333cf0522..3ed3b120e1 100644 --- a/persistence/build.gradle +++ b/persistence/build.gradle @@ -34,5 +34,12 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.persistence' } \ No newline at end of file diff --git a/presentation/build.gradle b/presentation/build.gradle index 2b70f05e17..0ca7502261 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -20,6 +20,14 @@ android { buildConfigField "boolean", "ENABLE_VIEWS_MENU", "true" buildConfigField("String", "STAGING_NETWORK_ID", networkConfigProps.getProperty('staging_network_id', 'null')) } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.presentation' } @@ -49,7 +57,6 @@ dependencies { testImplementation libs.junit testImplementation libs.kotlinTest testImplementation libs.mockitoKotlin - testImplementation "net.bytebuddy:byte-buddy:1.12.20" testImplementation libs.coroutineTesting testImplementation libs.liveDataTesting testImplementation libs.archCoreTesting diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt index a6e1c4d2d3..2bcf03c121 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt @@ -2,16 +2,13 @@ package com.anytypeio.anytype.presentation.editor.editor import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.domain.editor.Editor import com.anytypeio.anytype.presentation.editor.editor.model.BlockView -import kotlinx.coroutines.channels.ConflatedBroadcastChannel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asFlow import timber.log.Timber /** @@ -50,17 +47,6 @@ interface Store { override fun cancel() {} } - open class Conflated(default: T) : Store { - - private val channel = ConflatedBroadcastChannel(default) - private val stream = channel.asFlow() - - override fun stream(): Flow = stream - override fun current(): T = channel.value - override suspend fun update(t: T) = channel.send(t) - override fun cancel() = channel.cancel() - } - class Focus : State(Editor.Focus.empty()) { override suspend fun update(t: Editor.Focus) { Timber.d("Update focus in store: $t") @@ -68,7 +54,6 @@ interface Store { } } - class Context : Conflated("") class Screen : State>(emptyList()) class Details : State(Block.Details()) { @@ -78,7 +63,6 @@ interface Store { } class Relations : State>(emptyList()) - class ObjectTypes : State>(emptyList()) class ObjectRestrictions : State>(emptyList()) class TextSelection : State(Editor.TextSelection.empty()) class RelationLinks : State>(emptyList()) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/ObjectTypeTemplatesContainer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/ObjectTypeTemplatesContainer.kt index 834ae8a5c4..79bf8d85e3 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/ObjectTypeTemplatesContainer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/ObjectTypeTemplatesContainer.kt @@ -14,8 +14,7 @@ import com.anytypeio.anytype.domain.workspace.SpaceManager import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow -sealed interface ObjectTypeTemplatesContainer { - +interface ObjectTypeTemplatesContainer { suspend fun subscribeToTemplates(type: Id, subId: String): Flow> suspend fun unsubscribeFromTemplates(subId: Id) } diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt index f1670a369c..2fb6230671 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt @@ -346,6 +346,8 @@ open class EditorPresentationTestSetup { @Mock lateinit var fileLimitsEventChannel: FileLimitsEventChannel + + @Mock lateinit var interceptFileLimitEvents: InterceptFileLimitEvents @Mock @@ -428,7 +430,6 @@ open class EditorPresentationTestSetup { moveTableRow, moveTableColumn, setTableRowHeader ) - interceptFileLimitEvents = InterceptFileLimitEvents(fileLimitsEventChannel, dispatchers) return EditorViewModel( openPage = openPage, closePage = closePage, diff --git a/protocol/build.gradle b/protocol/build.gradle index 69d1df09a7..22389b890c 100644 --- a/protocol/build.gradle +++ b/protocol/build.gradle @@ -14,5 +14,12 @@ wire { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.protocol' } \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index d10b1412c3..1aa0c5a2d3 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,14 +1,13 @@ plugins { id "com.android.application" id "kotlin-android" - id "kotlin-android-extensions" id "kotlin-kapt" id 'com.google.gms.google-services' } android { compileSdkVersion 34 - buildToolsVersion "32.0.0" + buildToolsVersion "34.0.0" defaultConfig { applicationId "com.anytypeio.anytype.sample" @@ -31,12 +30,12 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 + kotlin { + jvmToolchain(17) } buildFeatures { diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 664862658b..4fe4e15d2f 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -27,11 +27,6 @@ - - - diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/DisabledAnimationActivity.kt b/sample/src/main/java/com/anytypeio/anytype/sample/DisabledAnimationActivity.kt deleted file mode 100644 index 892750881e..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/DisabledAnimationActivity.kt +++ /dev/null @@ -1,266 +0,0 @@ -package com.anytypeio.anytype.sample - -import android.content.Context -import android.graphics.Color -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.inputmethod.InputMethodManager -import android.widget.EditText -import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.anytypeio.anytype.core_utils.ext.imm -import com.anytypeio.anytype.core_utils.ui.ViewType -import com.anytypeio.anytype.sample.adapter.AbstractAdapter -import com.anytypeio.anytype.sample.adapter.AbstractHolder -import kotlinx.android.synthetic.main.activity_disabled_animation.* -import kotlinx.android.synthetic.main.item_editable.view.* -import timber.log.Timber - -class DisabledAnimationActivity : AppCompatActivity(R.layout.activity_disabled_animation) { - - private val start: List - get() = mutableListOf( - Mock( - id = 0, - text = "TITLE", - type = 0, - isFocused = false - ), - Mock( - id = 0, - text = "BULLETED", - type = 0, - isFocused = true - ), - Mock( - id = 1, - text = "PARAGRAPH 2", - type = 0, - isFocused = false - ) - ) - - private val end: List - get() = listOf( - Mock( - id = 0, - text = "TITLE", - type = 0, - isFocused = false - ), - Mock( - id = 0, - text = "PARAGRAPH", - type = 1, - isFocused = true - ), - Mock( - id = 1, - text = "PARAGRAPH 2", - type = 0, - isFocused = false - ) - ) - - private val mockAdapter = MockAdapter( - items = start.toMutableList() - ) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - recycler.apply { - layoutManager = CustomLinearLayoutManager(context) - adapter = mockAdapter - itemAnimator = null - } - startButton.setOnClickListener { - Timber.d("Start button clicked") - mockAdapter.update( - update = end - ) - } - - endButton.setOnClickListener { - Timber.d("End button clicked") - mockAdapter.update( - update = start - ) - } - } - - class MockAdapter(val items: MutableList) : AbstractAdapter(items) { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AbstractHolder { - return when (viewType) { - 0 -> { - val inflater = LayoutInflater.from(parent.context) - val view = inflater.inflate(R.layout.item_editable, parent, false) - MockHolder(view) - } - 1 -> { - val inflater = LayoutInflater.from(parent.context) - val view = inflater.inflate(R.layout.item_editable, parent, false) - MockHolder2(view) - } - else -> throw IllegalStateException() - } - } - - override fun getItemViewType(position: Int): Int { - return items[position].getViewType() - } - - override fun update(update: List) { - val old = ArrayList(items) - val cb = Differ(old = old, new = update) - val result = DiffUtil.calculateDiff(cb) - items.clear() - items.addAll(update) - result.dispatchUpdatesTo(this) - } - } - - class MockHolder(view: View) : AbstractHolder(view) { - - override fun bind(item: Mock) { - Timber.d("Binding item: $item") - itemView.input.setText(item.text) - if (item.isFocused) - focus() - else - itemView.input.clearFocus() - } - - private fun focus() { - itemView.input.apply { - post { - if (!hasFocus()) { - if (requestFocus()) { - context.imm().showSoftInput(this, InputMethodManager.SHOW_FORCED) - } else { - Timber.d("Couldn't gain focus") - } - } else - Timber.d("Already had focus") - } - } - } - } - - class MockHolder2(view: View) : AbstractHolder(view) { - - override fun bind(item: Mock) { - Timber.d("Binding item: $item") - itemView.input.setText(item.text) - itemView.input.setTextColor(Color.GREEN) - if (item.isFocused) focus() - } - - private fun focus() { - itemView.input.apply { - post { - Timber.d("Focusing!") - if (!hasFocus()) { - if (requestFocus()) { - context.imm().showSoftInput(this, InputMethodManager.SHOW_FORCED) - } else { - Timber.d("Couldn't gain focus") - } - } else - Timber.d("Already had focus") - } - } - } - } - - data class Mock( - val id: Int, - val text: String, - val isFocused: Boolean, - val type: Int - ) : ViewType { - override fun getViewType(): Int = type - } - - class Differ( - private val old: List, - private val new: List - ) : DiffUtil.Callback() { - - override fun getOldListSize(): Int = old.size - override fun getNewListSize(): Int = new.size - - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - val oldItem = old[oldItemPosition] - val newItem = new[newItemPosition] - Timber.d("areItemsTheSame for: $oldItem \n and \n $newItem") - return oldItem.id == newItem.id - } - - override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - val oldItem = old[oldItemPosition] - val newItem = new[newItemPosition] - Timber.d("areContentsTheSame for: $oldItem \n and \n $newItem") - return oldItem == newItem - } - } - - class CustomLinearLayoutManager( - context: Context, - //focus: View - ) : LinearLayoutManager(context) { - - override fun onInterceptFocusSearch(focused: View, direction: Int): View? { - Timber.d("OnInterceptFocusSearch view with text: ${(focused as EditText).text}") - when (direction) { - View.FOCUS_UP -> { - Timber.d("OnInterceptFocusSearch direction: FOCUS_UP") - } - View.FOCUS_DOWN -> { - Timber.d("OnInterceptFocusSearch direction: FOCUS_DOWN") - } - } - //return super.onInterceptFocusSearch(focused, direction) - - //val v = getChildAt(2)?.findViewById(R.id.input) - - //v?.requestFocus() - - //Timber.d("At position 2 there is a view with text: ${(v as EditText).text}") - - return null - } - - override fun removeView(child: View?) { - Timber.d("On remove view") - super.removeView(child) - } - - override fun detachView(child: View) { - Timber.d("On detach view") - super.detachView(child) - } - - override fun onFocusSearchFailed( - focused: View, - focusDirection: Int, - recycler: RecyclerView.Recycler, - state: RecyclerView.State - ): View? { - Timber.d("onFocusSearchFailed for view with text: ${(focused as EditText).text}") - when (focusDirection) { - View.FOCUS_UP -> { - Timber.d("onFocusSearchFailed direction: FOCUS_UP") - } - View.FOCUS_DOWN -> { - Timber.d("onFocusSearchFailed direction: FOCUS_DOWN") - } - } - return super.onFocusSearchFailed(focused, focusDirection, recycler, state) - } - } -} diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/LongClickActivity.kt b/sample/src/main/java/com/anytypeio/anytype/sample/LongClickActivity.kt deleted file mode 100644 index 6144221f64..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/LongClickActivity.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.anytypeio.anytype.sample - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.lifecycleScope -import kotlinx.android.synthetic.main.activity_long_clicked.* -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import timber.log.Timber - -/** - * Emulate long click on text block, with following - * Selection and Focus events - * - */ -class LongClickActivity: AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_long_clicked) - - textInputWidget.enableEditMode() - textInputWidget.setText("Hi, Konstantin") - - textInputWidget.setOnClickListener { - Timber.d("Single clicked!") - } - - textInputWidget.setOnLongClickListener { - Timber.d("Long clicked!") - lifecycleScope.launch { - delay(500) - Timber.d("Enabling read mode") - textInputWidget.enableReadMode() - } - true - } - - textInputWidget.selectionWatcher = {intRange: IntRange -> - Timber.d("Selection changed : $intRange") - } - - textInputWidget.setOnFocusChangeListener { v, hasFocus -> - Timber.d("Focus changed:$hasFocus") - } - - button.setOnClickListener { - textInputWidget.enableEditMode() - } - } -} \ No newline at end of file diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/MainActivity.kt b/sample/src/main/java/com/anytypeio/anytype/sample/MainActivity.kt deleted file mode 100644 index 77b1a50122..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/MainActivity.kt +++ /dev/null @@ -1,90 +0,0 @@ -package com.anytypeio.anytype.sample - -import android.os.Bundle -import android.text.Annotation -import android.text.Spannable -import android.text.SpannableString -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.android.synthetic.main.item_test.view.* - -class MainActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - val annotation = Annotation("key", "rounded") - val list = mutableListOf() - - val range = IntRange(0, 50) - range.forEach { - - var t = "I am block number $it" - val spannable = SpannableString(t) - if (it == 10) { - spannable.setSpan(annotation, 0, t.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE) - list.add(Item(text = spannable)) - } else { - list.add(Item(text = spannable)) - } - } - - with(recyclerView) { - layoutManager = LinearLayoutManager(this@MainActivity) - addItemDecoration( - DividerItemDecoration( - this@MainActivity, - DividerItemDecoration.VERTICAL - ) - ) - adapter = MarkupAdapter(list) { pos: Int -> - (this.adapter as MarkupAdapter).setData( - Item(SpannableString("I am block number $pos")), - pos - ) - - } - } - - } - - class MarkupAdapter(private val data: MutableList, private val listener: (Int) -> Unit) : - RecyclerView.Adapter() { - - fun setData(item: Item, position: Int) { - data[position] = item - notifyItemChanged(position) - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MarkupViewHolder { - val view = - LayoutInflater.from(parent.context).inflate(R.layout.item_test, parent, false) - return MarkupViewHolder(view) - } - - override fun getItemCount(): Int = data.size - - override fun onBindViewHolder(holder: MarkupViewHolder, position: Int) { - holder.bind(data[position].text, listener) - } - - class MarkupViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - - fun bind(text: SpannableString, listener: (Int) -> Unit) { - itemView.item.text = text - itemView.setOnClickListener { - listener.invoke(adapterPosition) - } - } - } - } -} - -data class Item(val text: SpannableString) diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/ScrollAndMove.kt b/sample/src/main/java/com/anytypeio/anytype/sample/ScrollAndMove.kt deleted file mode 100644 index 694e3cddd7..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/ScrollAndMove.kt +++ /dev/null @@ -1,406 +0,0 @@ -package com.anytypeio.anytype.sample - -import android.content.Context -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Point -import android.graphics.Rect -import android.graphics.drawable.Drawable -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.WindowManager -import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.anytypeio.anytype.core_utils.ext.toast -import kotlinx.android.synthetic.main.activity_scroll_and_move.* -import kotlinx.android.synthetic.main.item_scroll_and_move.view.* -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.consumeAsFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.mapLatest -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.launch -import timber.log.Timber - -class ScrollAndMove : AppCompatActivity() { - - private val decoration = object : RecyclerView.ItemDecoration() { - - var divider: Drawable? = null - - override fun getItemOffsets( - outRect: Rect, - view: View, - parent: RecyclerView, - state: RecyclerView.State - ) { - parent.adapter?.itemCount?.let { count -> - if (count == 1) { - outRect.bottom = screenHeight - outRect.top = screenHeight - } else { - if (parent.getChildAdapterPosition(view) == count - 1) { - outRect.bottom = screenHeight - } else if (parent.getChildAdapterPosition(view) == 0) { - outRect.top = screenHeight - } - } - } - } - - override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { - //c.save() - - Timber.d("child count: ${parent.childCount}") - - for (i in 0 until parent.childCount) { - - Timber.d("idx: $i") - - val child = parent.getChildAt(i) - - val pos = parent.getChildAdapterPosition(child) - - Timber.d("onDrawOver position: $pos") - - var targeted = false - var ratio: Float = 0.0f - - (parent.adapter as? Adapter)?.let { adapter -> - val item = adapter.models[pos] - targeted = item.isTargeted - ratio = item.ratio - } - - if (!targeted) continue - - Timber.d("onDrawOver ratio: $ratio") - - if (ratio in END_RANGE) { - Timber.d("Drawing bottom decoration for: $pos") - - val left = 0 - val right = parent.width - val top = child.bottom - val bottom = child.bottom + divider!!.intrinsicHeight - - - divider?.setBounds(left, top, right, bottom) - divider?.draw(c) - } else if (ratio in START_RANGE) { - Timber.d("Drawing bottom decoration for: $pos") - - val left = 0 - val right = parent.width - val top = child.top - val bottom = child.top + divider!!.intrinsicHeight - - divider?.setBounds(left, top, right, bottom) - divider?.draw(c) - } - } - - //c.restore() - } - } - - private val channel = Channel() - - init { - channel - .consumeAsFlow() - .onEach { Timber.d("event!") } - .mapLatest { - calculate() - } - .onEach { Timber.d("done") } - .launchIn(lifecycleScope) - } - - val screenHeight: Int - get() { - val wm = (getSystemService(Context.WINDOW_SERVICE) as WindowManager) - val display = wm.defaultDisplay - val p = Point() - display.getSize(p) - return p.y / 2 - } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_scroll_and_move) - setup() - } - - fun toggleDecoration() { - if (recycler.itemDecorationCount > 0) { - recycler.removeItemDecoration(decoration) - } else { - recycler.addItemDecoration(decoration) - } - } - - - fun setup() { - - toogleDecoration.setOnClickListener { - toggleDecoration() - } - - apply.setOnClickListener { - move() - } - - val text = getString(R.string.placeholder_text) - - val models = mutableListOf().apply { - repeat(MODEL_COUNT) { count -> - add( - Model( - text = "$count. $text", - isSelected = count in 0..1 - ) - ) - } - } - - decoration.divider = getDrawable(R.drawable.scroll_and_move_divider) - - recycler.apply { - - addItemDecoration(decoration) - - layoutManager = LinearLayoutManager(context) - - adapter = Adapter( - models = models - ) - - addOnScrollListener( - object : RecyclerView.OnScrollListener() { - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - super.onScrolled(recyclerView, dx, dy) - //Timber.d("On scrolled dy: $dy") - //Timber.d("Current scroll y: ${recycler.scrollY}") - } - - override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - super.onScrollStateChanged(recyclerView, newState) - if (newState == RecyclerView.SCROLL_STATE_IDLE) { - lifecycleScope.launch { - channel.send(Unit) - } - } - //return - - // Timber.d("Vertical scroll: ${recycler.computeVerticalScrollOffset()}") - } - } - ) - } - } - - fun move() { - - val adapter = (recycler.adapter as Adapter) - val models = adapter.models - val target = models.firstOrNull { it.isTargeted } - - check(models.count { it.isTargeted } == 1) { "merde!" } - - if (target != null) { - when (target.ratio) { - in START_RANGE -> { - // top - val result = mutableListOf() - val selected = models.filter { it.isSelected } - models.forEach { model -> - if (!model.isSelected) { - if (!model.isTargeted) - result.add(model) - if (model.isTargeted) { - result.addAll(selected) - result.add( - model.copy( - isTargeted = false, - ratio = 0.0f - ) - ) - } - } - } - adapter.update(result) - } - in MIDDLE_RANDE -> { - // inside - val update = - models.filter { !it.isSelected }.map { it.copy(isTargeted = false) } - adapter.update(update) - } - in END_RANGE -> { - // bottom - val result = mutableListOf() - val selected = models.filter { it.isSelected } - models.forEach { model -> - if (!model.isSelected) { - if (!model.isTargeted) - result.add(model) - if (model.isTargeted) { - result.add( - model.copy( - isTargeted = false, - ratio = 0.0f - ) - ) - result.addAll(selected) - } - } - } - adapter.update(result) - } - } - } - - toast("well done!") - } - - fun calculate() { - - val lm = recycler.layoutManager as LinearLayoutManager - - recycler.findChildViewUnder(0f, screenHeight.toFloat())?.let { view -> - - Timber.d("Found view: $view") - - val first = lm.findFirstVisibleItemPosition() - val last = lm.findLastVisibleItemPosition() - - val position = recycler.getChildAdapterPosition(view) - - val center = screenHeight.toFloat() - - val top = view.top - val height = view.height - - val ratio: Float - - if (center < top) { - Timber.d("top of the view is below center") - val delta = top - center - ratio = delta / height - Timber.d("Ration = $ratio") - } else { - Timber.d("top ($top) of the view is above center ($center)") - val delta = center - top - ratio = delta / height - Timber.d("Ration = $ratio") - } - - Timber.d("Target position: $position") - Timber.d("First visible item position: $first") - Timber.d("Last visible item position: $last") - - (recycler.adapter as Adapter).let { - val update = it.models.mapIndexed { index, model -> - model.copy( - isTargeted = index == position, - ratio = ratio - ) - } - it.update(update) - } - } - - } - - companion object { - const val MODEL_COUNT = 20 - val START_RANGE = 0.0..0.2 - val MIDDLE_RANDE = 0.2..0.8 - val END_RANGE = 0.8..1.0 - } -} - -data class Model( - val text: String, - val isTargeted: Boolean = false, - val isSelected: Boolean = false, - val ratio: Float = 0.0f -) - -class Adapter(var models: List) : RecyclerView.Adapter() { - - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): ViewHolder = ViewHolder( - view = LayoutInflater.from(parent.context).inflate( - R.layout.item_scroll_and_move, - parent, - false - ) - ) - - override fun getItemCount(): Int = models.size - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.bind(models[position]) - } - - fun update(update: List) { - this.models = update - notifyDataSetChanged() - Timber.d("Updated data set: $update") - } - - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - - private val top = itemView.topDivider - private val bottom = itemView.bottomDivider - private val paragraph = itemView.paragraph - - fun bind(model: Model) { - - if (model.isTargeted) { - when (model.ratio) { - in START_RANGE -> { - itemView.setBackgroundColor(Color.WHITE) - } - in MIDDLE_RANDE -> { - itemView.setBackgroundColor(Color.parseColor("#FFB522")) - } - in END_RANGE -> { - itemView.setBackgroundColor(Color.WHITE) - } - } - Timber.d("Binding selected model: $model") - } else { - itemView.setBackgroundColor(Color.WHITE) - //bottom.invisible() - //top.invisible() - Timber.d("Binding simple model") - } - - if (model.isSelected) { - paragraph.setTextColor( - Color.parseColor("#3E58EB") - ) - } else { - paragraph.setTextColor( - Color.parseColor("#2C2B27") - ) - } - - paragraph.text = model.text - itemView.isSelected = false - } - } - - companion object { - val START_RANGE = 0.0..0.2 - val MIDDLE_RANDE = 0.2..0.8 - val END_RANGE = 0.8..1.0 - } -} \ No newline at end of file diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageActivity.kt b/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageActivity.kt deleted file mode 100644 index b21557702c..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageActivity.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.anytypeio.anytype.sample.search - -import androidx.appcompat.app.AppCompatActivity -import androidx.core.widget.doOnTextChanged -import androidx.recyclerview.widget.LinearLayoutManager -import com.anytypeio.anytype.sample.R -import kotlinx.android.synthetic.main.activity_search_on_page.* - -class SearchOnPageActivity : AppCompatActivity(R.layout.activity_search_on_page) { - - private val items = mutableListOf().apply { - repeat(10) { - add( - SearchOnPageAdapter.Item( - id = it, - txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." - ) - ) - } - } - - private val mockAdapter = SearchOnPageAdapter( - items = items - ) - - override fun onStart() { - super.onStart() - recycler.apply { - layoutManager = LinearLayoutManager(context) - adapter = mockAdapter - } - search.doOnTextChanged { text, start, before, count -> - - } - } -} \ No newline at end of file diff --git a/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageAdapter.kt b/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageAdapter.kt deleted file mode 100644 index 88b28317b8..0000000000 --- a/sample/src/main/java/com/anytypeio/anytype/sample/search/SearchOnPageAdapter.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.anytypeio.anytype.sample.search - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import com.anytypeio.anytype.sample.R -import com.anytypeio.anytype.sample.adapter.AbstractAdapter -import com.anytypeio.anytype.sample.adapter.AbstractHolder -import kotlinx.android.synthetic.main.item_editable.view.* - -class SearchOnPageAdapter( - private var items: List -) : AbstractAdapter(items) { - - override fun update(update: List) { - this.items = update - notifyDataSetChanged() - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AbstractHolder { - val inflater = LayoutInflater.from(parent.context) - val view = inflater.inflate(R.layout.item_editable, parent, false) - return ItemViewHolder(view) - } - - data class Item( - val id: Int, - val txt: String - ) - - class ItemViewHolder(view: View) : AbstractHolder(view) { - override fun bind(item: Item) { - itemView.input.setText(item.txt) - } - } -} \ No newline at end of file diff --git a/test/android-utils/build.gradle b/test/android-utils/build.gradle index 776e8c1f30..204fa81d36 100644 --- a/test/android-utils/build.gradle +++ b/test/android-utils/build.gradle @@ -15,5 +15,12 @@ dependencies { } android { + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.test_utils' } \ No newline at end of file diff --git a/ui-settings/build.gradle b/ui-settings/build.gradle index d99a1fa901..8b74674ba6 100644 --- a/ui-settings/build.gradle +++ b/ui-settings/build.gradle @@ -14,6 +14,14 @@ android { composeOptions { kotlinCompilerExtensionVersion libs.versions.composeKotlinCompilerVersion.get() } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlin { + jvmToolchain(17) + } namespace 'com.anytypeio.anytype.ui_settings' }