mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 13:08:46 +01:00
fix: share image as file (#1126)
This commit is contained in:
parent
d797e05954
commit
3debfe77c4
@ -11,9 +11,9 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.gallery.GalleryHelper
|
|||||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.gallery.download
|
import com.github.diegoberaldin.raccoonforlemmy.core.utils.gallery.download
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.imagepreload.ImagePreloadManager
|
import com.github.diegoberaldin.raccoonforlemmy.core.utils.imagepreload.ImagePreloadManager
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.share.ShareHelper
|
import com.github.diegoberaldin.raccoonforlemmy.core.utils.share.ShareHelper
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.IO
|
import kotlinx.coroutines.IO
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -44,7 +44,7 @@ class ZoomableImageViewModel(
|
|||||||
is NotificationCenterEvent.ShareImageModeSelected.ModeFile -> shareFile(event.url, event.source)
|
is NotificationCenterEvent.ShareImageModeSelected.ModeFile -> shareFile(event.url, event.source)
|
||||||
is NotificationCenterEvent.ShareImageModeSelected.ModeUrl -> shareUrl(event.url)
|
is NotificationCenterEvent.ShareImageModeSelected.ModeUrl -> shareUrl(event.url)
|
||||||
}
|
}
|
||||||
}.launchIn(this)
|
}.launchIn(CoroutineScope(Dispatchers.IO))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,16 +103,14 @@ class ZoomableImageViewModel(
|
|||||||
val idx = s.lastIndexOf(".").takeIf { it >= 0 } ?: s.length
|
val idx = s.lastIndexOf(".").takeIf { it >= 0 } ?: s.length
|
||||||
s.substring(idx).takeIf { it.isNotEmpty() } ?: ".jpeg"
|
s.substring(idx).takeIf { it.isNotEmpty() } ?: ".jpeg"
|
||||||
}
|
}
|
||||||
val path =
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
galleryHelper.saveToGallery(
|
val path = galleryHelper.saveToGallery(
|
||||||
bytes = bytes,
|
bytes = bytes,
|
||||||
name = "${epochMillis()}$extension",
|
name = "${epochMillis()}$extension",
|
||||||
additionalPathSegment = folder.takeIf { imageSourcePath },
|
additionalPathSegment = folder.takeIf { imageSourcePath },
|
||||||
)
|
)
|
||||||
}
|
|
||||||
// if done too early no image is found
|
withContext(Dispatchers.Main) {
|
||||||
delay(750)
|
|
||||||
updateState { it.copy(loading = false) }
|
updateState { it.copy(loading = false) }
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
@ -120,6 +118,8 @@ class ZoomableImageViewModel(
|
|||||||
} else {
|
} else {
|
||||||
emitEffect(ZoomableImageMviModel.Effect.ShareFailure)
|
emitEffect(ZoomableImageMviModel.Effect.ShareFailure)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
updateState { it.copy(loading = false) }
|
updateState { it.copy(loading = false) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user