public void SetRequest(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("requests");
            var req = dr.Child(nodeKey);

            if (dr != null)
            {
                if (obj != null)
                {
                    string objJsonString = JsonConvert.SerializeObject(obj);

                    Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                    HashMap dataHashMap = new HashMap();

                    Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                    dataHashMap = jsonObj.JavaCast <HashMap>();


                    req.SetValue(dataHashMap);
                }
                else
                {
                    req.Child("Status").SetValue("Canceled");
                }
            }
        }
Example #2
0
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
		
			SetContentView (Resource.Layout.main);
			var textView = FindViewById<TextView> (Resource.Id.textView);

			// create an object
			var account = new Account ("Xamarin", "Corporate");

			// create the serializer
			var gson = new GsonBuilder ()
				.SetPrettyPrinting ()
				.Create ();

			// serialize the object into json
			var json = gson.ToJson (account);

			// deserialize the json into the object
			var clazz = Java.Lang.Class.FromType (typeof(Account));
			var newAccount = (Account)gson.FromJson (json, clazz);

			textView.Text = string.Join (System.Environment.NewLine, new [] { 
				json, 
				"Name == 'Xamarin': " + (newAccount.Name == "Xamarin"), 
				"Type == 'Corporate': " + (newAccount.Type == "Corporate") 
			});
		}
Example #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.main);
            var textView = FindViewById <TextView> (Resource.Id.textView);

            // create an object
            var account = new Account("Xamarin", "Corporate");

            // create the serializer
            var gson = new GsonBuilder()
                       .SetPrettyPrinting()
                       .Create();

            // serialize the object into json
            var json = gson.ToJson(account);

            // deserialize the json into the object
            var clazz      = Java.Lang.Class.FromType(typeof(Account));
            var newAccount = (Account)gson.FromJson(json, clazz);

            textView.Text = string.Join(System.Environment.NewLine, new [] {
                json,
                "Name == 'Xamarin': " + (newAccount.Name == "Xamarin"),
                "Type == 'Corporate': " + (newAccount.Type == "Corporate")
            });
        }
        public void OnMapReady(MapboxMap mapboxMap)
        {
            this.mapboxMap     = mapboxMap;
            navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, "admin-3-4-boundaries-bg");
            Gson gson = new GsonBuilder().RegisterTypeAdapterFactory(DirectionsAdapterFactory.Create()).Create();
            var  json = loadJsonFromAsset(DIRECTIONS_RESPONSE);
            DirectionsResponse response = (DirectionsResponse)gson.FromJson(json, Class.FromType(typeof(DirectionsResponse)));

            navigationMapRoute.AddRoute(response.Routes()[0]);
            mapboxMap.SetOnMapLongClickListener(this);
            navigationMapRoute.SetOnRouteSelectionChangeListener(this);
        }
Example #5
0
        public string SetChildValueByAutoId(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson             gson        = new GsonBuilder().SetPrettyPrinting().Create();
                HashMap          dataHashMap = new HashMap();
                Java.Lang.Object jsonObj     = gson.FromJson(objJsonString, dataHashMap.Class);
                dataHashMap = jsonObj.JavaCast <HashMap>();
                DatabaseReference newChildRef = dr.Push();
                newChildRef.SetValue(dataHashMap);
                return(newChildRef.Key);
            }

            return(null);
        }
Example #6
0
        public void UpdateDriverLocation(string key, object v)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("drivers");

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(v);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                dr.Child(key).Child("Location").SetValue(dataHashMap);
            }
        }
Example #7
0
        public async Task <string> StartTrip(string key, object trip)
        {
            DatabaseReference tripref = FirebaseDatabase.Instance.GetReference("trips");

            DatabaseReference driverref = FirebaseDatabase.Instance.GetReference("drivers");

            DatabaseReference reqref = FirebaseDatabase.Instance.GetReference("requests").Child(key);

            string uid = await new AFirebaseAuthClass().GetCurrentUser();

            var Key = tripref.Push().Key;

            // update request
            // With key
            if (tripref != null)
            {
                string objJsonString = JsonConvert.SerializeObject(trip);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                tripref.Child(Key).SetValue(dataHashMap);

                tripref.Child(Key).Child("Key").SetValue(Key);

                reqref.Child("Key").SetValue(Key);

                reqref.Child("Status").SetValue("Accepted");

                driverref.Child(uid).Child("Trip").SetValue(Key);

                return(Key);
            }
            // start trip
            return(null);
        }
        public void SetBooking(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                var key = dr.Push().Key;

                dr.Child(key).SetValue(dataHashMap);
                dr.Child(key).Child("Key").SetValue(key);
            }
        }
        public void CreateProfile(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            string uid = mAuth.CurrentUser.Uid;

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                dr.Child(uid).SetValue(dataHashMap);
                dr.Child(uid).Child("Key").SetValue(uid);
            }
        }
Example #10
0
        public void SubmitFeedback(object feedback)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("feedbacks");

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(feedback);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                var Key = dr.Push().Key;

                var feedbackref = dr.Child(Key);

                feedbackref.SetValue(dataHashMap);
            }
        }