Skip to content

Commit 9fc2922

Browse files
committed
Open url via navigation menu #3780
1 parent 75a9a28 commit 9fc2922

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/workflow/ApplicationWorkflow.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ enum class ApplicationWorkflow {
6565

6666
/** A workflow to launch delete draft questionnaires */
6767
DELETE_DRAFT_QUESTIONNAIRE,
68+
69+
/** A workflow that opens URL in external app (browser, email, etc.) */
70+
OPEN_URL,
6871
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M480,600Q497,600 508.5,588.5Q520,577 520,560Q520,543 508.5,531.5Q497,520 480,520Q463,520 451.5,531.5Q440,543 440,560Q440,577 451.5,588.5Q463,600 480,600ZM440,440L520,440L520,200L440,200L440,440ZM80,880L80,160Q80,127 103.5,103.5Q127,80 160,80L800,80Q833,80 856.5,103.5Q880,127 880,160L880,640Q880,673 856.5,696.5Q833,720 800,720L240,720L80,880ZM206,640L800,640Q800,640 800,640Q800,640 800,640L800,160Q800,160 800,160Q800,160 800,160L160,160Q160,160 160,160Q160,160 160,160L160,685L206,640ZM160,640L160,640L160,160Q160,160 160,160Q160,160 160,160L160,160Q160,160 160,160Q160,160 160,160L160,640Q160,640 160,640Q160,640 160,640Z"/>
10+
</vector>

android/quest/src/main/assets/configs/app/navigation_config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,28 @@
297297
}
298298
]
299299
},
300+
{
301+
"id": "feedback",
302+
"visible": true,
303+
"display": "Feedback",
304+
"menuIconConfig": {
305+
"type": "local",
306+
"reference": "ic_feedback"
307+
},
308+
"actions": [
309+
{
310+
"trigger": "ON_CLICK",
311+
"workflow": "OPEN_URL",
312+
"id": "openFeedback",
313+
"params": [
314+
{
315+
"key": "url",
316+
"value": "https://ona.io/home/"
317+
}
318+
]
319+
}
320+
]
321+
},
300322
{
301323
"id": "settings",
302324
"visible": true,

android/quest/src/main/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.widget.Toast
2626
import androidx.appcompat.app.AppCompatActivity
2727
import androidx.compose.runtime.snapshots.SnapshotStateMap
2828
import androidx.core.content.ContextCompat
29+
import androidx.core.net.toUri
2930
import androidx.core.os.bundleOf
3031
import androidx.navigation.NavController
3132
import androidx.navigation.NavOptions
@@ -245,6 +246,18 @@ fun ActionConfig.handleClickEvent(
245246
)
246247
navController.navigate(MainNavigationScreen.AlertDialogFragment.route, args)
247248
}
249+
ApplicationWorkflow.OPEN_URL -> {
250+
val url = interpolatedParams.find { it.key == "url" }?.value
251+
if (!url.isNullOrBlank()) {
252+
try {
253+
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
254+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
255+
ContextCompat.startActivity(navController.context, intent, null)
256+
} catch (e: Exception) {
257+
context?.showToast("Unable to open url ${e.message}", Toast.LENGTH_SHORT)
258+
}
259+
}
260+
}
248261
else -> return
249262
}
250263
}

0 commit comments

Comments
 (0)