1
+ package fr.free.nrw.commons.LocationPicker
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import fr.free.nrw.commons.CameraPosition
6
+ import fr.free.nrw.commons.Media
7
+
8
+
9
+ /* *
10
+ * Helper class for starting the activity
11
+ */
12
+ object LocationPicker {
13
+
14
+ /* *
15
+ * Getting camera position from the intent using constants
16
+ *
17
+ * @param data intent
18
+ * @return CameraPosition
19
+ */
20
+ @JvmStatic
21
+ fun getCameraPosition (data : Intent ): CameraPosition ? {
22
+ return data.getParcelableExtra(LocationPickerConstants .MAP_CAMERA_POSITION )
23
+ }
24
+
25
+ class IntentBuilder
26
+ /* *
27
+ * Creates a new builder that creates an intent to launch the place picker activity.
28
+ */ () {
29
+
30
+ private val intent: Intent = Intent ()
31
+
32
+ /* *
33
+ * Gets and puts location in intent
34
+ * @param position CameraPosition
35
+ * @return LocationPicker.IntentBuilder
36
+ */
37
+ fun defaultLocation (position : CameraPosition ): IntentBuilder {
38
+ intent.putExtra(LocationPickerConstants .MAP_CAMERA_POSITION , position)
39
+ return this
40
+ }
41
+
42
+ /* *
43
+ * Gets and puts activity name in intent
44
+ * @param activity activity key
45
+ * @return LocationPicker.IntentBuilder
46
+ */
47
+ fun activityKey (activity : String ): IntentBuilder {
48
+ intent.putExtra(LocationPickerConstants .ACTIVITY_KEY , activity)
49
+ return this
50
+ }
51
+
52
+ /* *
53
+ * Gets and puts media in intent
54
+ * @param media Media
55
+ * @return LocationPicker.IntentBuilder
56
+ */
57
+ fun media (media : Media ): IntentBuilder {
58
+ intent.putExtra(LocationPickerConstants .MEDIA , media)
59
+ return this
60
+ }
61
+
62
+ /* *
63
+ * Gets and sets the activity
64
+ * @param activity Activity
65
+ * @return Intent
66
+ */
67
+ fun build (activity : Activity ): Intent {
68
+ intent.setClass(activity, LocationPickerActivity ::class .java)
69
+ return intent
70
+ }
71
+ }
72
+ }
0 commit comments