This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
suspend fun getUserDataChanges(id : String?) : Flow<Resource<User>> = withContext(ioDispatcher) { | |
callbackFlow { | |
if (id == null) { | |
offer(Resource.Error(Exception("Id must not be null"))) | |
return@callbackFlow | |
} | |
// 1- Create query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val subscription = cloudDBZone.subscribeSnapshot(query, CloudDBZoneQuery.CloudDBZoneQueryPolicy.POLICY_QUERY_FROM_CLOUD_PRIOR, | |
object : OnSnapshotListener<User> { | |
override fun onSnapshot(snapShot: CloudDBZoneSnapshot<User>?, error: AGConnectCloudDBException?) { | |
// do something | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
suspend fun getUserData(id : String?) : Flow<Resource<User>> = withContext(ioDispatcher) { | |
callbackFlow { | |
if (id == null) { | |
offer(Resource.Error(Exception("Id must not be null"))) | |
return@callbackFlow | |
} | |
// 1- Create query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomInfoViewAdapter constructor(context : Context) : HuaweiMap.InfoWindowAdapter { | |
private var mWindow: View? = null | |
init { | |
mWindow = LayoutInflater.from(context).inflate(R.layout.custom_info_window_layout, null) | |
} | |
override fun getInfoWindow(marker: Marker?): View? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:padding="4dp" | |
android:background="@android:color/white"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Initialize dummy markers | |
*/ | |
private fun initMarkers() { | |
val markerDataList = createMarkerList() | |
markerDataList.forEachIndexed { index, markerOptions -> | |
val marker = hMap?.addMarker(markerOptions) | |
marker?.setMarkerAnchor(0.5f, 1f) // Set marker anchor point | |
marker?.tag = "$index Extra Info" // Set extra data with tag. This data can be a custom class | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), OnMapReadyCallback { | |
private var hMap: HuaweiMap? = null | |
companion object { | |
private const val MAPVIEW_BUNDLE_KEY = "MapViewBundleKey" | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Take photo from camera and save it to public gallery | |
// Before Q and After Q implementations | |
// Answer riginally taken from this SO answer | |
// https://stackoverflow.com/a/59482148/5695091 | |
private val REQUEST_TAKE_PHOTO = 101 | |
private val REQUEST_PICK_PHOTO = 102 | |
private var photoURI : Uri? = null | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
if (requestCode == REQUEST_CHECK_SETTINGS) { | |
when (resultCode) { | |
Activity.RESULT_OK -> { | |
LogUtils.d("User confirm to access location") | |
} | |
Activity.RESULT_CANCELED -> { | |
LogUtils.d("User denied to access location") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { | |
Log.i(TAG, "sdk < 28 Q"); | |
if (ActivityCompat.checkSelfPermission(this, | |
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED | |
|| ActivityCompat.checkSelfPermission(this, | |
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
String[] strings = | |
{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; | |
ActivityCompat.requestPermissions(this, strings, 1); | |
} |
NewerOlder