mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
access auth token in save activity
This commit is contained in:
parent
6c859430de
commit
aedfc33f5f
5 changed files with 47 additions and 7 deletions
|
|
@ -7,7 +7,9 @@ import androidx.datastore.preferences.core.edit
|
|||
import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package app.omnivore.omnivore
|
|||
|
||||
import android.content.ContentValues
|
||||
import android.util.Log
|
||||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.omnivore.omnivore.ui.theme.OmnivoreTheme
|
||||
import androidx.compose.runtime.getValue
|
||||
|
|
|
|||
|
|
@ -4,24 +4,38 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.omnivore.omnivore.ui.theme.OmnivoreTheme
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class SaveActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
var text: String? = null
|
||||
val viewModel: SaveViewModel by viewModels()
|
||||
var extractedText: String? = null
|
||||
val authToken = viewModel.getAuthToken()
|
||||
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SEND -> {
|
||||
if (intent.type?.startsWith("text/") == true) {
|
||||
if (intent.type?.startsWith("text/plain") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
text = it
|
||||
extractedText = it
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.type?.startsWith("text/html") == true) {
|
||||
intent.getStringExtra(Intent.EXTRA_HTML_TEXT)?.let {
|
||||
extractedText = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,9 +46,18 @@ class SaveActivity : ComponentActivity() {
|
|||
|
||||
setContent {
|
||||
OmnivoreTheme {
|
||||
// A surface container using the 'background' color from the theme
|
||||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
|
||||
Text(text = text ?: "no text extracted")
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colors.background)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Text(text = extractedText ?: "no text extracted")
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(text = authToken ?: "no auth token")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package app.omnivore.omnivore
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SaveViewModel @Inject constructor(
|
||||
private val datastoreRepo: DatastoreRepository
|
||||
): ViewModel() {
|
||||
fun getAuthToken(): String? = runBlocking {
|
||||
datastoreRepo.getString(DatastoreKeys.omnivoreAuthToken)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue