-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
414 additions
and
210 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
package io.matchmore.sdk | ||
|
||
import android.content.Context | ||
import android.util.Base64 | ||
import org.json.JSONObject | ||
import java.nio.charset.Charset | ||
|
||
data class MatchMoreConfig @JvmOverloads constructor( | ||
data class MatchMoreConfig( | ||
var context: Context, | ||
val apiKey: String, | ||
val worldId: String, | ||
val serverProtocol: String? = null, | ||
val serverUrl: String? = null, | ||
val callbackInUIThread: Boolean = true, | ||
val debugLog: Boolean = false) { | ||
var debugLog: Boolean | ||
) { | ||
|
||
init { | ||
context = context.applicationContext | ||
} | ||
|
||
val worldId: String by lazy { | ||
val segments = apiKey.split(".") | ||
if (segments.size < 2) throw IllegalArgumentException("Invalid API Key.") | ||
val json = Base64.decode(segments[1], Base64.DEFAULT).toString(Charset.defaultCharset()) | ||
return@lazy JSONObject(json).getString("sub") | ||
} | ||
} |
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
sdk/src/main/java/io/matchmore/sdk/managers/DefaultLocationProvider.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.matchmore.sdk.managers | ||
|
||
import android.Manifest.permission.ACCESS_FINE_LOCATION | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.location.Criteria | ||
import android.location.Location | ||
import android.location.LocationListener | ||
import android.location.LocationManager | ||
import android.os.Bundle | ||
import android.support.v4.content.ContextCompat | ||
import io.matchmore.sdk.utils.mmLocation | ||
|
||
|
||
class DefaultLocationProvider(private val context: Context): MatchMoreLocationProvider { | ||
|
||
private var sender: LocationSender? = null | ||
|
||
private val listener: LocationListener = object : LocationListener { | ||
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {} | ||
|
||
override fun onProviderEnabled(provider: String?) {} | ||
|
||
override fun onProviderDisabled(provider: String?) {} | ||
|
||
override fun onLocationChanged(location: Location) { | ||
sender?.sendLocation(location.mmLocation) | ||
} | ||
} | ||
|
||
private val locationManager by lazy { | ||
context.getSystemService(Context.LOCATION_SERVICE) as LocationManager | ||
} | ||
|
||
private fun findProvider() = locationManager.getBestProvider(Criteria().apply { | ||
accuracy = Criteria.ACCURACY_FINE | ||
}, false) | ||
|
||
override fun startUpdatingLocation(sender: LocationSender) { | ||
if (ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { | ||
val provider = findProvider() | ||
?: throw IllegalStateException("Can't find location provider.") | ||
val location = locationManager.getLastKnownLocation(provider) | ||
if (location != null) sender.sendLocation(location.mmLocation) | ||
locationManager.requestLocationUpdates(provider, MIN_TIME, MIN_DISTANCE, listener) | ||
} else { | ||
throw SecurityException("You need to get ACCESS_FINE_LOCATION permission first. ") | ||
} | ||
} | ||
|
||
override fun stopUpdatingLocation() { | ||
locationManager.removeUpdates(listener) | ||
} | ||
|
||
companion object { | ||
private const val MIN_TIME = 10 * 1000L //10s | ||
private const val MIN_DISTANCE = 10f //10m | ||
} | ||
} |
This file contains 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
Oops, something went wrong.