Skip to content

Commit

Permalink
unnecessary files removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Shock@5678 committed Aug 15, 2024
1 parent ae0b936 commit 09e3724
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 1,260 deletions.
4 changes: 3 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.VIBRATE"/>


<application
android:label="Beacon"
android:icon="@mipmap/launcher_icon"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true">

<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyC72TkXzQTsnbGdZy5ldeX64y0mofn_iUs"/>

Expand Down
54 changes: 12 additions & 42 deletions android/app/src/main/kotlin/com/example/beacon/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,21 @@
package com.example.beacon

import android.app.PictureInPictureParams
import android.os.Build
import android.util.Rational
import android.content.res.Configuration
import androidx.annotation.NonNull
import cl.puntito.simple_pip_mode.PipCallbackHelper
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
private val CHANNEL = "com.example.beacon/pip"
private var shouldEnterPipMode = false
private var callbackHelper = PipCallbackHelper()

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
when (call.method) {
"switchPIPMode"->{
shouldEnterPipMode = true
result.success(null)
}
"enablePIPMode" -> {
shouldEnterPipMode = true
result.success(null)
}
"disablePIPMode" -> {
shouldEnterPipMode = false
result.success(null)
}
else -> result.notImplemented()
}
}
}
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
callbackHelper.configureFlutterEngine(flutterEngine)
}

override fun onUserLeaveHint() {
super.onUserLeaveHint()
if (shouldEnterPipMode) {
enterPIPMode()
}
}

private fun enterPIPMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val aspectRatio = Rational(16, 9)
val pipParams = PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio)
.build()
enterPictureInPictureMode(pipParams)
}
}
override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) {
super.onPictureInPictureModeChanged(active, newConfig)
callbackHelper.onPictureInPictureModeChanged(active)
}
}
14 changes: 7 additions & 7 deletions lib/config/pip_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'package:flutter/services.dart';
class PIPMode {
static const platform = MethodChannel("com.example.beacon/pip");

static Future<void> enterPIPMode() async {
try {
await platform.invokeMethod('enablePIPMode');
} on PlatformException catch (e) {
print("Failed to enter PIP mode: '${e.message}'.");
}
}
// static Future<void> enterPIPMode() async {
// try {
// await platform.invokeMethod('enablePIPMode');
// } on PlatformException catch (e) {
// print("Failed to enter PIP mode: '${e.message}'.");
// }
// }

static Future<void> disablePIPMode() async {
try {
Expand Down
29 changes: 0 additions & 29 deletions lib/core/queries/beacon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,6 @@ deleteBeacon(id: "$id")
''';
}

String createGeofence(
String beaconId, String lat, String lon, double radius) {
return '''
mutation{
createGeofence(id: "$beaconId", location: {lat: "$lat", lon:"$lon"}, radius: $radius){
radius
center{
lat
lon
}
}
}
''';
}

String updateBeaconLocation(String? id, String lat, String lon) {
return '''
Expand Down Expand Up @@ -263,13 +249,6 @@ deleteBeacon(id: "$id")
lon
}
}
geofence{
center{
lat
lon
}
radius
}
landmarks{
_id
title
Expand Down Expand Up @@ -476,14 +455,6 @@ deleteBeacon(id: "$id")
}
}
geofence{
radius
center{
lat
lon
}
}
landmark{
_id
title
Expand Down
174 changes: 2 additions & 172 deletions lib/data/datasource/remote/remote_hike_api.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:beacon/core/queries/beacon.dart';
import 'package:beacon/core/resources/data_state.dart';
import 'package:beacon/data/models/beacon/beacon_model.dart';
import 'package:beacon/data/models/geofence/geofence_model.dart';
import 'package:beacon/data/models/landmark/landmark_model.dart';
import 'package:beacon/data/models/location/location_model.dart';
import 'package:beacon/data/models/subscriptions/beacon_locations_model/beacon_locations_model.dart';
Expand All @@ -14,7 +12,6 @@ import 'package:beacon/domain/entities/user/user_entity.dart';
import 'package:beacon/locator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:http/http.dart' as http;

class RemoteHikeApi {
late GraphQLClient _authClient;
Expand All @@ -36,8 +33,6 @@ class RemoteHikeApi {
final result = await _authClient.mutate(MutationOptions(
document: gql(beaconQueries.fetchBeaconDetail(beaconId))));

log(result.toString());

if (result.isConcrete && result.data != null) {
final beaconJson = result.data!['beacon'];

Expand All @@ -64,130 +59,9 @@ class RemoteHikeApi {
return DataFailed(encounteredExceptionOrError(result.exception!));
}

Future<DataState<GeofenceModel>> createGeofence(
String beaconId, LatLng latlng, double radius) async {
bool isConnected = await utils.checkInternetConnectivity();
if (!isConnected) {}

final result = await _authClient.mutate(MutationOptions(
document: gql(beaconQueries.createGeofence(beaconId,
latlng.latitude.toString(), latlng.longitude.toString(), radius))));

;
if (result.isConcrete && result.data != null) {
final beaconJson = result.data!['createGeofence'];
try {
var geofence = GeofenceModel.fromJson(beaconJson);
return DataSuccess(geofence);
} catch (e) {
log(e.toString());
}
}
return DataFailed(encounteredExceptionOrError(result.exception!));
}

Stream<DataState<LocationModel>> beaconLocationSubscription(
String? beaconId) async* {
bool isConnected = await utils.checkInternetConnectivity();
if (!isConnected) {
yield DataFailed("No internet connection");
return;
}

final subscriptionOptions = SubscriptionOptions(
document: beaconQueries.beaconLocationSubGql,
variables: {
'id': beaconId,
},
);

final authClient = await graphqlConfig.graphQlClient();

final resultStream = authClient.subscribe(subscriptionOptions);

await for (final result in resultStream) {
if (result.isConcrete &&
result.data != null &&
result.data!['beaconLocation'] != null) {
final locationJson = result.data!['beaconLocation'];
final location = LocationModel.fromJson(locationJson);
yield DataSuccess(location);
} else if (result.hasException) {
yield DataFailed(encounteredExceptionOrError(result.exception!));
}
}
}

Stream<DataState<UserModel>> beaconJoinedSubscription(
String beaconId) async* {
bool isConnected = await utils.checkInternetConnectivity();
if (!isConnected) {
yield DataFailed("No internet connection");
return;
}

final subscriptionOptions = SubscriptionOptions(
document: beaconQueries.beaconJoinedSubGql,
variables: {
'id': beaconId,
},
);

final authClient = await graphqlConfig.graphQlClient();

final resultStream = await authClient.subscribe(subscriptionOptions);

await for (var result in resultStream) {
if (result.isConcrete &&
result.data != null &&
result.data!['beaconJoined'] != null) {
final newMember = UserModel.fromJson(result.data!['beaconJoined']);
yield DataSuccess(newMember);
}
yield DataFailed(encounteredExceptionOrError(result.exception!));
}
}

Stream<DataState<dynamic>> beaconUpdateSubscription(String beaconId) async* {
final isConnected = await utils.checkInternetConnectivity();

if (!isConnected) {
yield DataFailed('No internet connection');
return;
}

final subscriptionOptions = SubscriptionOptions(
document: beaconQueries.beaconUpdateSubGql,
variables: {'id': beaconId});

final resultStream =
await _subscriptionClient.subscribe(subscriptionOptions);

await for (var result in resultStream) {
if (result.isConcrete &&
result.data != null &&
result.data!['updateBeacon'] != null) {
Map<String, dynamic> beaconJson =
result.data!['updateBeacon'] as Map<String, dynamic>;

if (beaconJson['user'] != null) {
UserModel newUser = UserModel.fromJson(beaconJson['user']);

yield DataSuccess(newUser);
// return user
}
if (beaconJson['landmark'] != null) {
LandMarkModel newLandmark =
LandMarkModel.fromJson(beaconJson['landmark']);

yield DataSuccess(newLandmark);
// return landmark
}
} else {
yield DataFailed(encounteredExceptionOrError(result.exception!));
}
}
}


Future<DataState<UserEntity>> changeUserLocation(
String beaconId, LatLng latlng) async {
Expand Down Expand Up @@ -288,24 +162,7 @@ class RemoteHikeApi {
}
}

Future<DataState<bool>> addRoute(String id, LatLng latlng) async {
bool isConnected = await utils.checkInternetConnectivity();

if (!isConnected) {
return DataFailed('No internet connection');
}

final result = await _authClient.mutate(
MutationOptions(document: gql(beaconQueries.addRoute(id, latlng))));

if (result.isConcrete &&
result.data != null &&
result.data!['addRoute'] != null) {
return DataSuccess(result.data!['addRoute']);
} else {
return DataSuccess(false);
}
}

Future<DataState<UserEntity>> sos(String id) async {
bool isConnected = await utils.checkInternetConnectivity();
Expand All @@ -326,34 +183,7 @@ class RemoteHikeApi {
}
}

Future<DataState<List<LatLng>>> getRoute(List<LatLng> latlng) async {
bool isConnected = await utils.checkInternetConnectivity();

if (!isConnected) {
return DataFailed('No internet connection');
}

List<List<double>> coordinates = [];

for (var coord in latlng) {
coordinates.add([coord.latitude, coord.longitude]);
}

final response = await http.post(
Uri.parse(
'https://api.openrouteservice.org/v2/directions/foot-hiking/gpx'),
headers: {
"Authorization":
"5b3ce3597851110001cf6248873a3b4f20c445c98808378287166ec0",
"Content-Type": "application/json"
},
body: jsonEncode({"coordinates": coordinates}));

if (response.statusCode == 200) {
return DataSuccess([]);
}
return DataSuccess([]);
}


String encounteredExceptionOrError(OperationException exception) {
if (exception.linkException != null) {
Expand Down
Loading

0 comments on commit 09e3724

Please sign in to comment.