Skip to content

Commit

Permalink
Make export button work
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Jul 2, 2024
1 parent 9b4ea75 commit 98ce203
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.jocmp.capy.Account
import com.jocmp.capyreader.transfers.OPMLExporter
import org.koin.compose.koinInject

@Composable
fun OPMLExportButton() {
fun OPMLExportButton(
onClick: () -> Unit,
) {
Column {
Button(
onClick = {},
onClick = onClick,
colors = ButtonDefaults.buttonColors(
containerColor = colorScheme.secondary,
contentColor = colorScheme.onSecondary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val settingsModule = module {
account = get(),
accountManager = get(),
refreshScheduler = get(),
appPreferences = get()
appPreferences = get(),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.jocmp.capyreader.ui.settings

import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import com.jocmp.capyreader.transfers.OPMLExporter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel

@Composable
Expand All @@ -9,12 +14,22 @@ fun SettingsScreen(
onRemoveAccount: () -> Unit,
onNavigateBack: () -> Unit,
) {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()

val exportOPML = {
coroutineScope.launch(Dispatchers.IO) {
OPMLExporter(context = context).export(viewModel.account)
}
}

SettingsView(
refreshInterval = viewModel.refreshInterval,
updateRefreshInterval = viewModel::updateRefreshInterval,
accountName = viewModel.accountName,
onNavigateBack = { onNavigateBack() },
accountSource = viewModel.accountSource,
onRequestExport = { exportOPML() },
onRequestRemoveAccount = {
viewModel.removeAccount()
onRemoveAccount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fun SettingsView(
updateRefreshInterval: (interval: RefreshInterval) -> Unit,
onNavigateBack: () -> Unit,
onRequestRemoveAccount: () -> Unit,
onRequestExport: () -> Unit,
accountSource: Source,
accountName: String
) {
Expand Down Expand Up @@ -115,7 +116,9 @@ fun SettingsView(
}

Section(title = stringResource(R.string.settings_section_export)) {
OPMLExportButton()
OPMLExportButton(
onClick = onRequestExport,
)
}

Section(title = "Privacy") {
Expand Down Expand Up @@ -226,6 +229,7 @@ fun AccountSettingsViewPreview() {
updateRefreshInterval = {},
onRequestRemoveAccount = {},
onNavigateBack = {},
onRequestExport = {},
accountSource = Source.FEEDBIN,
accountName = "[email protected]"
)
Expand All @@ -248,6 +252,7 @@ fun AccountSettingsView_LocalPreview() {
updateRefreshInterval = {},
onRequestRemoveAccount = {},
onNavigateBack = {},
onRequestExport = {},
accountSource = Source.LOCAL,
accountName = ""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.jocmp.capyreader.ui.settings

import android.app.Application
import android.content.Context
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.jocmp.capy.Account
import com.jocmp.capy.AccountManager
import com.jocmp.capy.accounts.Source
import com.jocmp.capyreader.common.AppPreferences
import com.jocmp.capyreader.refresher.RefreshInterval
import com.jocmp.capyreader.refresher.RefreshScheduler
import com.jocmp.capyreader.transfers.OPMLExporter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class SettingsViewModel(
private val accountManager: AccountManager,
private val refreshScheduler: RefreshScheduler,
private val account: Account,
val account: Account,
private val appPreferences: AppPreferences,
) : ViewModel() {
private val _refreshInterval = mutableStateOf(refreshScheduler.refreshInterval)
Expand Down

0 comments on commit 98ce203

Please sign in to comment.