diff --git a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt index 2b637271..4cd9e69b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt @@ -266,6 +266,17 @@ class Navigator @Inject constructor( startActivityExternal(intent) } + fun shareFile(file: File) { + val data = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file) + val type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.name.split(".").last()) + val intent = Intent(Intent.ACTION_SEND) + .setType(type) + .putExtra(Intent.EXTRA_STREAM, data) + .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + + startActivityExternal(intent) + } + fun showNotificationSettings(threadId: Long = 0) { val intent = Intent(context, NotificationPrefsActivity::class.java) intent.putExtra("threadId", threadId) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryActivity.kt index 5edc8b82..f2c261b6 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryActivity.kt @@ -54,7 +54,7 @@ class GalleryActivity : QkActivity(), GalleryView { private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[GalleryViewModel::class.java] } override fun onCreate(savedInstanceState: Bundle?) { - delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES) + delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_YES AndroidInjection.inject(this) super.onCreate(savedInstanceState) setContentView(R.layout.gallery_activity) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt index 9d72c07d..d660d6ce 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/gallery/GalleryViewModel.kt @@ -20,6 +20,7 @@ package com.moez.QKSMS.feature.gallery import android.content.Context import com.moez.QKSMS.R +import com.moez.QKSMS.common.Navigator import com.moez.QKSMS.common.base.QkViewModel import com.moez.QKSMS.common.util.extensions.makeToast import com.moez.QKSMS.extensions.mapNotNull @@ -37,9 +38,10 @@ import javax.inject.Named class GalleryViewModel @Inject constructor( conversationRepo: ConversationRepository, - messageRepo: MessageRepository, @Named("partId") private val partId: Long, private val context: Context, + private val messageRepo: MessageRepository, + private val navigator: Navigator, private val saveImage: SaveImage, private val permissions: PermissionManager ) : QkViewModel(GalleryState()) { @@ -74,6 +76,14 @@ class GalleryViewModel @Inject constructor( .withLatestFrom(view.pageChanged()) { _, part -> part.id } .autoDisposable(view.scope()) .subscribe { partId -> saveImage.execute(partId) { context.makeToast(R.string.gallery_toast_saved) } } + + // Share image externally + view.optionsItemSelected() + .filter { itemId -> itemId == R.id.share } + .filter { permissions.hasStorage().also { if (!it) view.requestStoragePermission() } } + .withLatestFrom(view.pageChanged()) { _, part -> part.id } + .autoDisposable(view.scope()) + .subscribe { partId -> messageRepo.savePart(partId)?.let(navigator::shareFile) } } -} \ No newline at end of file +} diff --git a/presentation/src/main/res/menu/gallery.xml b/presentation/src/main/res/menu/gallery.xml index 00793241..9cd668b4 100644 --- a/presentation/src/main/res/menu/gallery.xml +++ b/presentation/src/main/res/menu/gallery.xml @@ -23,4 +23,8 @@ android:id="@+id/save" android:title="@string/menu_save" /> - \ No newline at end of file + + + diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 01be513b..27041d0c 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -39,6 +39,7 @@ Call Details Save to gallery + Share Open navigation drawer %d selected