@@ -21,6 +21,7 @@ import com.example.util.simpletimetracker.navigation.params.action.OpenSystemSet
21
21
import com.example.util.simpletimetracker.navigation.params.action.RequestPermissionParams
22
22
import com.example.util.simpletimetracker.navigation.params.action.SendEmailParams
23
23
import com.example.util.simpletimetracker.navigation.params.action.ShareFileParams
24
+ import timber.log.Timber
24
25
import javax.inject.Inject
25
26
26
27
class ActionResolverImpl @Inject constructor(
@@ -42,8 +43,8 @@ class ActionResolverImpl @Inject constructor(
42
43
when (data) {
43
44
is OpenMarketParams -> openMarket(activity, data)
44
45
is SendEmailParams -> sendEmail(activity, data)
45
- is CreateFileParams -> createFile(activity, data)
46
- is OpenFileParams -> openFile(activity, data)
46
+ is CreateFileParams -> createFile(data)
47
+ is OpenFileParams -> openFile(data)
47
48
is OpenSystemSettings -> openSystemSettings(activity, data)
48
49
is ShareFileParams -> shareFile(activity, data)
49
50
is RequestPermissionParams -> requestPermission(data)
@@ -96,27 +97,29 @@ class ActionResolverImpl @Inject constructor(
96
97
}
97
98
}
98
99
99
- private fun openFile (activity : Activity ? , data : OpenFileParams ) {
100
+ private fun openFile (data : OpenFileParams ) {
100
101
val intent = Intent (Intent .ACTION_OPEN_DOCUMENT )
101
102
.addCategory(Intent .CATEGORY_OPENABLE )
102
103
.setType(data.type)
103
104
104
- if (activity.checkIfIntentResolves(intent)) {
105
+ runCatching {
105
106
openFileResultLauncher?.launch(intent)
106
- } else {
107
+ }.onFailure {
108
+ Timber .e(it)
107
109
data.notHandledCallback()
108
110
}
109
111
}
110
112
111
- private fun createFile (activity : Activity ? , data : CreateFileParams ) {
113
+ private fun createFile (data : CreateFileParams ) {
112
114
val intent = Intent (Intent .ACTION_CREATE_DOCUMENT )
113
115
.addCategory(Intent .CATEGORY_OPENABLE )
114
116
.setType(data.type)
115
117
.putExtra(Intent .EXTRA_TITLE , data.fileName)
116
118
117
- if (activity.checkIfIntentResolves(intent)) {
119
+ runCatching {
118
120
createFileResultLauncher?.launch(intent)
119
- } else {
121
+ }.onFailure {
122
+ Timber .e(it)
120
123
data.notHandledCallback()
121
124
}
122
125
}
@@ -183,11 +186,6 @@ class ActionResolverImpl @Inject constructor(
183
186
}
184
187
}
185
188
186
- private fun Activity?.checkIfIntentResolves (intent : Intent ): Boolean {
187
- if (this == null ) return false
188
- return packageManager?.let (intent::resolveActivity) != null
189
- }
190
-
191
189
companion object {
192
190
private const val MARKET_INTENT = " market://details?id="
193
191
private const val MARKET_LINK = " http://play.google.com/store/apps/details?id="
0 commit comments