fix: wrong timezone used when saving page on android
This commit is contained in:
@ -17,7 +17,8 @@ import java.util.*
|
|||||||
suspend fun Networker.deleteSavedItem(itemID: String): Boolean {
|
suspend fun Networker.deleteSavedItem(itemID: String): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val input = SetBookmarkArticleInput(itemID, false)
|
val input = SetBookmarkArticleInput(itemID, false)
|
||||||
val result = authenticatedApolloClient().mutation(SetBookmarkArticleMutation(input)).execute()
|
val result =
|
||||||
|
authenticatedApolloClient().mutation(SetBookmarkArticleMutation(input)).execute()
|
||||||
result.data?.setBookmarkArticle?.onSetBookmarkArticleSuccess?.bookmarkedArticle?.id != null
|
result.data?.setBookmarkArticle?.onSetBookmarkArticleSuccess?.bookmarkedArticle?.id != null
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
false
|
false
|
||||||
@ -32,7 +33,10 @@ suspend fun Networker.unarchiveSavedItem(itemID: String): Boolean {
|
|||||||
return updateArchiveStatusSavedItem(itemID, false)
|
return updateArchiveStatusSavedItem(itemID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun Networker.updateArchiveStatusSavedItem(itemID: String, setAsArchived: Boolean): Boolean {
|
suspend fun Networker.updateArchiveStatusSavedItem(
|
||||||
|
itemID: String,
|
||||||
|
setAsArchived: Boolean
|
||||||
|
): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val input = ArchiveLinkInput(setAsArchived, itemID)
|
val input = ArchiveLinkInput(setAsArchived, itemID)
|
||||||
val result = authenticatedApolloClient().mutation(SetLinkArchivedMutation(input)).execute()
|
val result = authenticatedApolloClient().mutation(SetLinkArchivedMutation(input)).execute()
|
||||||
@ -42,10 +46,15 @@ suspend fun Networker.updateArchiveStatusSavedItem(itemID: String, setAsArchived
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun Networker.saveUrl(url: Uri): Boolean {
|
suspend fun Networker.saveUrl(url: Uri, timeZone: String): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val clientRequestId = UUID.randomUUID().toString()
|
val clientRequestId = UUID.randomUUID().toString()
|
||||||
val input = SaveUrlInput(url = url.toString(), clientRequestId = clientRequestId, source = "android")
|
val input = SaveUrlInput(
|
||||||
|
url = url.toString(),
|
||||||
|
clientRequestId = clientRequestId,
|
||||||
|
source = "android",
|
||||||
|
timeZone = timeZone
|
||||||
|
)
|
||||||
val result = authenticatedApolloClient().mutation(SaveUrlMutation(input)).execute()
|
val result = authenticatedApolloClient().mutation(SaveUrlMutation(input)).execute()
|
||||||
result.data?.saveUrl?.onSaveSuccess?.url != null
|
result.data?.saveUrl?.onSaveSuccess?.url != null
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
|
|||||||
@ -45,6 +45,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
// Not sure why we need this class, but directly opening SaveSheetActivity
|
// Not sure why we need this class, but directly opening SaveSheetActivity
|
||||||
// causes the app to crash.
|
// causes the app to crash.
|
||||||
@ -52,19 +53,22 @@ class SaveSheetActivity : SaveSheetActivityBase() {}
|
|||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@OptIn(ExperimentalMaterialApi::class)
|
@OptIn(ExperimentalMaterialApi::class)
|
||||||
abstract class SaveSheetActivityBase: AppCompatActivity() {
|
abstract class SaveSheetActivityBase : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val viewModel: SaveViewModel by viewModels()
|
val viewModel: SaveViewModel by viewModels()
|
||||||
var extractedText: String? = null
|
var extractedText: String? = null
|
||||||
|
|
||||||
|
// get timezone from device
|
||||||
|
val timezone = TimeZone.getDefault().id
|
||||||
|
|
||||||
when (intent?.action) {
|
when (intent?.action) {
|
||||||
Intent.ACTION_SEND -> {
|
Intent.ACTION_SEND -> {
|
||||||
if (intent.type?.startsWith("text/plain") == true) {
|
if (intent.type?.startsWith("text/plain") == true) {
|
||||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||||
extractedText = it
|
extractedText = it
|
||||||
viewModel.saveURL(it)
|
viewModel.saveURL(it, timezone)
|
||||||
Log.d(ContentValues.TAG, "Extracted text: $extractedText")
|
Log.d(ContentValues.TAG, "Extracted text: $extractedText")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,6 +78,7 @@ abstract class SaveSheetActivityBase: AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Handle other intents, such as being started from the home screen
|
// Handle other intents, such as being started from the home screen
|
||||||
}
|
}
|
||||||
@ -110,8 +115,11 @@ abstract class SaveSheetActivityBase: AppCompatActivity() {
|
|||||||
.clip(RoundedCornerShape(topEnd = 5.dp, topStart = 5.dp)),
|
.clip(RoundedCornerShape(topEnd = 5.dp, topStart = 5.dp)),
|
||||||
containerColor = MaterialTheme.colors.background,
|
containerColor = MaterialTheme.colors.background,
|
||||||
actions = {
|
actions = {
|
||||||
Spacer(modifier = Modifier.width(25.dp))
|
Spacer(modifier = Modifier.width(25.dp))
|
||||||
Text(message, style = androidx.compose.material3.MaterialTheme.typography.titleMedium)
|
Text(
|
||||||
|
message,
|
||||||
|
style = androidx.compose.material3.MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -181,7 +189,7 @@ abstract class SaveSheetActivityBase: AppCompatActivity() {
|
|||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
if (withResults) setResult(RESULT_OK)
|
if (withResults) setResult(RESULT_OK)
|
||||||
result?.let { intent = it}
|
result?.let { intent = it }
|
||||||
modalBottomSheetState.hide() // will trigger the LaunchedEffect
|
modalBottomSheetState.hide() // will trigger the LaunchedEffect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,9 +199,11 @@ abstract class SaveSheetActivityBase: AppCompatActivity() {
|
|||||||
viewModel: SaveViewModel,
|
viewModel: SaveViewModel,
|
||||||
modalBottomSheetState: ModalBottomSheetState
|
modalBottomSheetState: ModalBottomSheetState
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier
|
Box(
|
||||||
.height(300.dp)
|
modifier = Modifier
|
||||||
.background(Color.White)) {
|
.height(300.dp)
|
||||||
|
.background(Color.White)
|
||||||
|
) {
|
||||||
SaveContent(viewModel, modalBottomSheetState, modifier = Modifier.fillMaxSize())
|
SaveContent(viewModel, modalBottomSheetState, modifier = Modifier.fillMaxSize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user