Skip to content

Commit 1141ea2

Browse files
committed
Add view action
1 parent 4d49475 commit 1141ea2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

core/src/main/java/com/omega_r/libs/omegaintentbuilder/OmegaIntentBuilder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ object OmegaIntentBuilder {
4242
@JvmStatic
4343
fun share() = ShareIntentBuilder()
4444

45+
@JvmStatic
46+
fun view() = ViewIntentBuilder()
47+
4548
/**
4649
* @return ShareIntentBuilder for creating email Intent
4750
*/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.omega_r.libs.omegaintentbuilder.builders
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import java.lang.IllegalStateException
6+
7+
class ViewIntentBuilder: BaseUriBuilder() {
8+
9+
private var mimeType: String? = null
10+
11+
fun mimeType(mimeType: String): ViewIntentBuilder = also {
12+
this.mimeType = mimeType
13+
}
14+
15+
override fun createIntent(context: Context): Intent {
16+
val intent = Intent(Intent.ACTION_VIEW)
17+
val uriSet = getUriSet(context)
18+
if (uriSet.size == 1) intent.setDataAndType(uriSet.first(), mimeType)
19+
else throw IllegalStateException("Multiple uri not supported")
20+
return intent
21+
}
22+
23+
}

0 commit comments

Comments
 (0)