Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ ktlint_standard_function-expression-body = disabled

max_line_length = off

ktlint_function_naming_ignore_when_annotated_with = Composable

[*.{yml,yaml}]
indent_size = 2

Expand Down
46 changes: 46 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,50 @@ dependencies {
androidTestImplementation(libs.androidx.test.core.ktx)

lintChecks(projects.checks)

val composeBom = platform("androidx.compose:compose-bom:2025.08.00")
implementation(composeBom)
androidTestImplementation(composeBom)

// Choose one of the following:
// Material Design 3
implementation("androidx.compose.material3:material3")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
// or Material Design 2
// implementation("androidx.compose.material:material")
// or skip Material Design and build directly on top of foundational components
// implementation("androidx.compose.foundation:foundation")
// or only import the main APIs for the underlying toolkit systems,
// such as input and measurement/layout
// implementation("androidx.compose.ui:ui")

// Android Studio Preview support
implementation("androidx.compose.ui:ui-tooling-preview")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
debugImplementation("androidx.compose.ui:ui-tooling")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead

// UI Tests
androidTestImplementation("androidx.compose.ui:ui-test-junit4")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
debugImplementation("androidx.compose.ui:ui-test-manifest")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead

// Optional - Included automatically by material, only add when you need
// the icons but not the material library (e.g. when using Material3 or a
// custom design system based on Foundation)
// implementation("androidx.compose.material:material-icons-core")
// Optional - Add full set of material icons
// implementation("androidx.compose.material:material-icons-extended")
// Optional - Add window size utils
implementation("androidx.compose.material3.adaptive:adaptive")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead

// Optional - Integration with activities
implementation("androidx.activity:activity-compose:1.10.1")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
// Optional - Integration with ViewModels
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
// Optional - Integration with LiveData
// implementation("androidx.compose.runtime:runtime-livedata")
// Optional - Integration with RxJava
// implementation("androidx.compose.runtime:runtime-rxjava2")

implementation("androidx.constraintlayout:constraintlayout:2.2.1")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use the existing version catalog reference (libs.androidx.constraintlayout) instead
// To use constraintlayout in compose
implementation("androidx.constraintlayout:constraintlayout-compose:1.1.1")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
debugImplementation("androidx.compose.runtime:runtime-tracing")

Check failure

Code scanning / Android Lint

Use TOML Version Catalog Instead

Use version catalog instead
}
49 changes: 0 additions & 49 deletions app/src/google/kotlin/app/pachli/translation/HeadingAdapter.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,21 @@ import android.net.NetworkCapabilities
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.content.getSystemService
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import app.pachli.R
import app.pachli.core.common.extensions.viewBinding
import app.pachli.core.data.repository.Loadable
import app.pachli.core.designsystem.theme.AppTheme
import app.pachli.core.preferences.SharedPreferencesRepository
import app.pachli.core.ui.extensions.applyDefaultWindowInsets
import app.pachli.databinding.FragmentModelManagerBinding
import app.pachli.translation.ConfirmDeleteLanguageDialogFragment.Companion.newInstance
import app.pachli.translation.ConfirmDownloadLanguageDialogFragment.Companion.newInstance
import com.github.michaelbull.result.get
import com.google.mlkit.nl.translate.TranslateRemoteModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

/**
* Displays a list of downloaded and available translation models, and UI controls to
Expand All @@ -64,66 +57,25 @@ class TranslationModelManagerFragment : Fragment(R.layout.fragment_model_manager

private val connectivityManager by lazy { requireContext().getSystemService<ConnectivityManager>()!! }

/** Adapter for a list of translation models already downloaded. */
private val downloadedModelAdapter by lazy {
TranslationModelAdapter(
onDelete = ::confirmDeleteModel,
onDownload = ::confirmDownloadLanguage,
)
}

/** Adapter for a list of translation models that can be downloaded. */
private val remoteModelAdapter by lazy {
TranslationModelAdapter(
onDelete = ::confirmDeleteModel,
onDownload = ::confirmDownloadLanguage,
)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.recyclerView.applyDefaultWindowInsets()

with(binding.recyclerView) {
layoutManager = LinearLayoutManager(context)

adapter = ConcatAdapter(
HeadingAdapter(R.string.translation_model_manager_fragment_downloaded_heading),
downloadedModelAdapter,
HeadingAdapter(R.string.translation_model_manager_fragment_remote_heading),
remoteModelAdapter,
)
setHasFixedSize(true)
setAccessibilityDelegateCompat(
RemoteModelAccessibilityDelegate(
this,
::confirmDeleteModel,
::confirmDownloadLanguage,
),
)
}

bind()
}

private fun bind() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
launch {
// Split the list of models in two, depending on whether the model has
// been downloaded. Send each part to the correct adapter.
viewModel.flowViewData.collectLatest { models ->
val (loaded, remote) = models.partition { it.state.get() is Loadable.Loaded }
downloadedModelAdapter.submitList(loaded)
remoteModelAdapter.submitList(remote)
}
binding.composeView.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
AppTheme {
TranslationModelManagerScreen(
viewModel,
::confirmDeleteModel,
::confirmDownloadLanguage,
)
}
}
}
}

/**
* Downloads the [viewData.remoteModel.language][com.google.mlkit.nl.translate.TranslateRemoteModel.language].
* Downloads the [viewData.remoteModel.language][TranslateRemoteModel.language].
*
* If the user allows downloads with mobile data, or the user is connected to a Wi-Fi
* network, then the download proceeds immediately.
Expand Down
Loading
Loading