public UserDetailsDialog (VBUser clickedUser, int teamId, VBEvent _event, UserDetailsType type) {
			this.clickedUser = clickedUser;
			this.teamId = teamId;
			this.user = VBUser.GetUserFromPreferences();
			this._event = _event;
			this.type = type;
		}
		/**Loads all events for the given user.
		 **/
		public async Task<List<VBEvent>> loadEvents(VBUser user, EventType eventType) {
			DB_Communicator db = DB_Communicator.getInstance();
			List<VBEvent> listEvents = new List<VBEvent>();
			JsonValue json;
			string alternativeMessage = "";

			if(eventType == EventType.Past) {
				json = await db.SelectPastEventsForUser(user.idUser, null);
				alternativeMessage = "Error while loading past events!";
			} else {
				json = await db.SelectUpcomingEventsForUser(user.idUser, null);
				alternativeMessage = "Error while loading upcoming events!";
			}

			if(db.wasSuccesful(json)) {
				listEvents = db.createEventFromResponse(json);
			} else {
				this.toastJson(mainActivity, json, ToastLength.Long, alternativeMessage);
			}

			return listEvents;
		}
		public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			user = VBUser.GetUserFromPreferences();

			View view = inflater.Inflate(Resource.Layout.EventDetails, container, false);

			string eventState = (getLoggedInUser(user.idUser, listUser) != null) 
								? "(" + getLoggedInUser(user.idUser, listUser).getEventState() + ")" : "";

			view.FindViewById<TextView>(Resource.Id.eventTitle).Text = _event.name;
			view.FindViewById<TextView>(Resource.Id.eventState).Text = eventState;
			view.FindViewById<TextView>(Resource.Id.eventLocation).Text = _event.location;
			view.FindViewById<TextView>(Resource.Id.eventTime).Text = _event.convertDateForLayout(_event);

			if(_event.description != null && !_event.description.Equals("")) {
				view.FindViewById<LinearLayout>(Resource.Id.eventDetailsEventDescriptionLine).Visibility = ViewStates.Visible;
				view.FindViewById<TextView>(Resource.Id.eventDetailsEventDescriptionValue).Text = _event.description.Replace("\\n", "\n");
			}

			ImageView btnInvite = this.Activity.FindViewById<ImageView>(Resource.Id.btnAddInToolbar);
			ImageView btnEdit = this.Activity.FindViewById<ImageView>(Resource.Id.btnEditInToolbar);
			ImageView btnDelete = this.Activity.FindViewById<ImageView>(Resource.Id.btnDeleteInToolbar);

			if(!this.isEditable(_event.startDate, _event.endDate)) {
				btnInvite.Visibility = ViewStates.Gone;
				btnEdit.Visibility = ViewStates.Gone;
				btnDelete.Visibility = ViewStates.Gone;

				view.FindViewById<Button>(Resource.Id.btnEventAbsagen).Visibility = ViewStates.Gone;
				view.FindViewById<Button>(Resource.Id.btnEventZusagen).Visibility = ViewStates.Gone;
			} else {
				if(DB_Communicator.getInstance().isAtLeast(user.getUserType(), UserType.Coremember)) {
					btnInvite.Visibility = ViewStates.Visible;
					btnEdit.Visibility = ViewStates.Visible;
					btnDelete.Visibility = ViewStates.Visible;
				}
			}

			//zusagen
			initalizeLinearLayout(view.FindViewById<LinearLayout>(Resource.Id.EventDetails_ListUser_Zugesagt), listUser,
				DB_Communicator.State.Accepted, view.FindViewById<TextView>(Resource.Id.EventDetails_Count_Zugesagt), inflater);
			//absagen
			initalizeLinearLayout(view.FindViewById<LinearLayout>(Resource.Id.EventDetails_ListUser_Abgesagt), listUser,
				DB_Communicator.State.Denied, view.FindViewById<TextView>(Resource.Id.EventDetails_Count_Abgesagt), inflater);
			//eingeladen
			initalizeLinearLayout(view.FindViewById<LinearLayout>(Resource.Id.EventDetails_ListUser_Eingeladen), listUser,
				DB_Communicator.State.Invited, view.FindViewById<TextView>(Resource.Id.EventDetails_Count_Eingeladen), inflater);

			#region buttons
			btnAccept = view.FindViewById<Button>(Resource.Id.btnEventZusagen);
			btnAccept.SetOnClickListener(new EventDetailsClickListener(EventDetailsClickListener.ON_ANSWER_INVITE, this, "G"));

			btnDenie = view.FindViewById<Button>(Resource.Id.btnEventAbsagen);
			btnDenie.SetOnClickListener(new EventDetailsClickListener(EventDetailsClickListener.ON_ANSWER_INVITE, this, "D"));

			if(getEventStateOfLoggedInUser().Equals(VBUser.ACCEPTED)) {
				btnAccept.Enabled = false;
				btnDenie.Enabled = true;
			}
			if(getEventStateOfLoggedInUser().Equals(VBUser.DENIED)) {
				btnAccept.Enabled = true;
				btnDenie.Enabled = false;
			}
			#endregion

			#region toolbar
			btnInvite.SetOnClickListener(new EventDetailsClickListener(EventDetailsClickListener.ON_INVITE, this));

			btnEdit.SetOnClickListener(new EventDetailsClickListener(EventDetailsClickListener.ON_EDIT, this));

			btnDelete.SetOnClickListener(new EventDetailsClickListener(EventDetailsClickListener.ON_DELETE, this));
			#endregion

			return view;
		}
		public EventDetailsClickListener(string source, EventDetailsFragment edf, VBUser clickedUser) {
			this.source = source;
			this.edf = edf;
			this._event = edf._event;
			this.clickedUser = clickedUser;
		}
			public TeamDetailsClickListener(string source, TeamDetailsFragment t) {
				this.source = source;
				this.t = t;
				this.user = VBUser.GetUserFromPreferences();
			}
			private async void handleRequest(string answer) {
				DB_Communicator db = DB_Communicator.getInstance();
				string response = await db.handleUserTypeRequest(r, answer);
				JsonValue json = JsonValue.Parse(response);
				ViewController.getInstance().toastJson(null, json, ToastLength.Long, "handleRequest");

				//refresh the user
				VBUser user = new VBUser(json["data"]["User"]); //always returns the current user
				user.StoreUserInPreferences(ViewController.getInstance().mainActivity, user);

				//refresh the view
				t.teamrole = user.getTeamroleForTeam(r.teamId);
				List<VBRequest> listRequests = db.createReqeuestList(JsonValue.Parse(await db.loadUserTypeRequest(r.teamId)));
				this.t.listRequests = listRequests;
				TeamDetailsFragment tdf = ViewController.getInstance().mainActivity.FindFragmentByTag(ViewController.TEAM_DETAILS_FRAGMENT) as TeamDetailsFragment;
				tdf.listRequests = listRequests;
				ViewController.getInstance().refreshFragment(TeamDetailsFragment.PROFILE);
			}
		public UserDetailsDialog (VBUser clickedUser, int teamId, UserDetailsType type) 
			: this(clickedUser, teamId, null, type) {}
		private VBUser createUserFromJson(JsonValue json, string password) {
			VBUser vbuser = new VBUser(json);
			vbuser.password = password;

			return vbuser;
		}
Exemplo n.º 9
0
		public static VBUser GetUserFromPreferences() {
			ISharedPreferences prefs = VBUser.context.GetSharedPreferences("userinformation", FileCreationMode.Private);
			VBUser vbuser =  new VBUser(prefs.GetInt("idUser", 0),
				prefs.GetString("name", ""),
				prefs.GetString("email", ""),
				prefs.GetString("state", ""),
				prefs.GetString("password", ""),
				prefs.GetString("userType", ""));

			if(prefs.Contains("idUser")) {
				for(int i = 0; i < count; i++) {
					VBTeamrole teamRole = new VBTeamrole(prefs.GetInt("teamId"+i, 0), prefs.GetString("userType"+i, ""), prefs.GetString("role"+i, ""), 
						prefs.GetInt("number"+i, 0),prefs.GetString("position"+i, ""));
					vbuser.listTeamRole.Add(teamRole);
				}


				return vbuser;
			} else {
				return null;
			}
		}
Exemplo n.º 10
0
		public void StoreUserInPreferences(Context context, VBUser user) {
			VBUser.context = context;
			ISharedPreferences prefs = context.GetSharedPreferences("userinformation", FileCreationMode.Private);
			ISharedPreferencesEditor editor = prefs.Edit();
			editor.PutInt("idUser", user.idUser);
			editor.PutString("name", user.name);
			editor.PutString("email", user.email);
			editor.PutString("state", user.state);
			if(user.password != null && !user.password.Equals(""))
				editor.PutString("password", user.password);
			editor.PutString("userType", user.getUserType().ToString().Substring(0,1));
			for(int i = 0; i < listTeamRole.Count; i++) {
				editor.PutInt("teamId"+i, user.listTeamRole[i].teamId);
				editor.PutString("role"+i, user.listTeamRole[i].role);
				editor.PutInt("number"+i, user.listTeamRole[i].number);
				editor.PutString("position"+i, user.listTeamRole[i].position);
				editor.PutString("userType"+i, user.listTeamRole[i].getUserType().ToString().Substring(0,1));
			}
			count = listTeamRole.Count;
			editor.Commit();
		}