-
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
232 changed files
with
12,383 additions
and
6,127 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
22 changes: 22 additions & 0 deletions
22
app/android/app/src/main/java/tech/oxymore/liane/AppPackage.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,22 @@ | ||
package tech.oxymore.liane | ||
|
||
import android.view.View | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ReactShadowNode | ||
import com.facebook.react.uimanager.ViewManager | ||
import tech.oxymore.liane.geolocation.BackgroundGeolocationModule | ||
import tech.oxymore.liane.splashscreen.SplashScreenModule | ||
|
||
class AppPackage : ReactPackage { | ||
|
||
override fun createViewManagers( | ||
reactContext: ReactApplicationContext | ||
): MutableList<ViewManager<View, ReactShadowNode<*>>> = mutableListOf() | ||
|
||
override fun createNativeModules( | ||
reactContext: ReactApplicationContext | ||
): MutableList<NativeModule> = listOf(BackgroundGeolocationModule(reactContext), SplashScreenModule(reactContext)).toMutableList() | ||
} | ||
|
44 changes: 0 additions & 44 deletions
44
app/android/app/src/main/java/tech/oxymore/liane/MainActivity.java
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
app/android/app/src/main/java/tech/oxymore/liane/MainActivity.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,106 @@ | ||
package tech.oxymore.liane | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.IntentSenderRequest | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import com.facebook.react.ReactActivityDelegate | ||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.concurrentReactEnabled | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled | ||
import com.facebook.react.defaults.DefaultReactActivityDelegate | ||
import com.google.android.gms.common.api.ApiException | ||
import com.google.android.gms.common.api.ResolvableApiException | ||
import com.google.android.gms.location.* | ||
import com.google.android.gms.tasks.Task | ||
import tech.oxymore.liane.geolocation.LocationRequestHandler | ||
import tech.oxymore.liane.geolocation.LogTag | ||
import tech.oxymore.liane.splashscreen.SplashScreenActivity | ||
|
||
class MainActivity : SplashScreenActivity(), LocationRequestHandler { | ||
lateinit var locationRequestLauncher : ActivityResultLauncher<IntentSenderRequest> | ||
var promise: Promise? = null | ||
/** | ||
* Required by react navigation to handle wake up | ||
*/ | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(null) | ||
locationRequestLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { r -> | ||
if (r.resultCode == Activity.RESULT_OK) { | ||
promise?.resolve(true) | ||
} else { | ||
promise?.reject("rejected") | ||
} | ||
promise = null | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Returns the name of the main component registered from JavaScript. This is used to schedule | ||
* rendering of the component. | ||
*/ | ||
override fun getMainComponentName(): String { | ||
return "liane" | ||
} | ||
|
||
/** | ||
* Returns the instance of the [ReactActivityDelegate]. Here we use a util class [ ] which allows you to easily enable Fabric and Concurrent React | ||
* (aka React 18) with two boolean flags. | ||
*/ | ||
override fun createReactActivityDelegate(): ReactActivityDelegate { | ||
return DefaultReactActivityDelegate( | ||
this, | ||
mainComponentName, // If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||
fabricEnabled, // fabricEnabled | ||
// If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). | ||
concurrentReactEnabled // concurrentRootEnabled | ||
) | ||
} | ||
|
||
override fun requestEnableLocation(promise: Promise) { | ||
if (this.promise != null) return | ||
val locationRequest: LocationRequest = LocationRequest.create() | ||
locationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY) | ||
val builder = LocationSettingsRequest.Builder() | ||
.addLocationRequest(locationRequest) | ||
|
||
val result: Task<LocationSettingsResponse> = | ||
LocationServices.getSettingsClient(this).checkLocationSettings(builder.build()) | ||
|
||
|
||
|
||
result.addOnCompleteListener { task -> | ||
try { | ||
val response = task.getResult(ApiException::class.java) | ||
// All location settings are satisfied. The client can initialize location | ||
// requests here. | ||
promise.resolve(true) | ||
} catch (exception: ApiException) { | ||
when (exception.statusCode) { | ||
LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> | ||
// Location settings are not satisfied. But could be fixed by showing the | ||
// user a dialog. | ||
try { | ||
val resolvable = exception as ResolvableApiException | ||
this.promise = promise | ||
locationRequestLauncher.launch(IntentSenderRequest.Builder(resolvable.resolution).build()) | ||
} catch (e: Exception) { | ||
Log.e(LogTag, e.message.toString()) | ||
promise.reject("rejected") | ||
} | ||
|
||
LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE -> {promise.reject("rejected")} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
app/android/app/src/main/java/tech/oxymore/liane/geolocation/Api.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,9 @@ | ||
package tech.oxymore.liane.geolocation | ||
|
||
|
||
data class PingConfig(val url: String, val token: String, val userId: String, val lianeId: String) | ||
data class GeolocationConfig(val defaultInterval: Long, val nearWayPointInterval: Long, val nearWayPointRadius: Int) | ||
|
||
|
||
|
||
|
51 changes: 51 additions & 0 deletions
51
app/android/app/src/main/java/tech/oxymore/liane/geolocation/BackgroundGeolocationModule.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,51 @@ | ||
package tech.oxymore.liane.geolocation | ||
|
||
import android.content.Intent | ||
import android.util.Log | ||
import com.facebook.react.bridge.* | ||
import tech.oxymore.liane.geolocation.Util.isMyServiceRunning | ||
|
||
public const val LogTag = "BackgroundGeoService" | ||
class BackgroundGeolocationModule (context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) { | ||
|
||
private lateinit var mServiceIntent: Intent | ||
override fun getName(): String { | ||
return "BackgroundGeolocationServiceModule"; | ||
} | ||
|
||
@ReactMethod | ||
fun enableLocation(promise: Promise) { | ||
if(currentActivity is LocationRequestHandler) (currentActivity as LocationRequestHandler).requestEnableLocation(promise) | ||
else promise.reject("unsupported") | ||
} | ||
|
||
|
||
@ReactMethod | ||
fun stopService(promise: Promise) { | ||
if (::mServiceIntent.isInitialized) { | ||
reactApplicationContext.stopService(mServiceIntent) | ||
promise.resolve(null) | ||
} | ||
promise.reject("no service running") | ||
} | ||
|
||
@ReactMethod | ||
fun isRunning(promise: Promise){ | ||
promise.resolve(isMyServiceRunning(LocationService::class.java, reactApplicationContext)) | ||
} | ||
|
||
@ReactMethod | ||
fun startService(config: ReadableMap, promise: Promise) { | ||
if (!isMyServiceRunning(LocationService::class.java, reactApplicationContext)) { | ||
mServiceIntent = Intent(reactApplicationContext, LocationService::class.java) | ||
mServiceIntent.putExtras(Arguments.toBundle(config)!!) | ||
|
||
reactApplicationContext.startService(mServiceIntent) | ||
Log.d(LogTag, "start service") | ||
promise.resolve(null) | ||
} else { | ||
Log.d(LogTag, "service was already started") | ||
promise.reject("service already started") | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/android/app/src/main/java/tech/oxymore/liane/geolocation/LocationRequestHandler.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,7 @@ | ||
package tech.oxymore.liane.geolocation | ||
|
||
import com.facebook.react.bridge.Promise | ||
|
||
interface LocationRequestHandler { | ||
fun requestEnableLocation(promise: Promise) | ||
} |
Oops, something went wrong.