Skip to content

Commit

Permalink
popup window appears after login if user doesnt have profile
Browse files Browse the repository at this point in the history
  • Loading branch information
EmiliaZorin committed Jun 7, 2020
1 parent 2ecfc86 commit baa4f74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.evan.parknbark.map_profile.maps;

import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
Expand All @@ -21,6 +23,7 @@
import com.evan.parknbark.map_profile.MapProfileBottomSheetDialog;
import com.evan.parknbark.map_profile.profile.Profile;
import com.evan.parknbark.map_profile.profile.WatchProfile;
import com.evan.parknbark.settings.admin.UsersListActivity;
import com.evan.parknbark.utilities.BaseNavDrawerActivity;
import com.evan.parknbark.utilities.User;
import com.google.android.gms.location.FusedLocationProviderClient;
Expand Down Expand Up @@ -57,6 +60,8 @@ public class MapActivity extends BaseNavDrawerActivity implements OnMapReadyCall
private static final String PARK_CHECKIN = "parkcheckin";
private static final String CHECKIN_FIELD = "currentProfilesInPark";
private static final String PROFILES = "profiles";
private static final String POPUP_WINDOW_TITLE = "Set your profile!";
private static final String POPUP_WINDOW_BODY = "you must set your profile for further use.";
private static final double defaultLan = 31.249927;
private static final double defaultLon = 34.791930;
//permissions
Expand Down Expand Up @@ -94,8 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
currentUserPermission = currentUser.getPermission();

if (!currentUser.isBuiltProfile()) {
startActivityForResult(new Intent(MapActivity.this, WatchProfile.class),
REQUEST_PROFILE_BUILD);
displayPopupWindow();
}
}

Expand All @@ -116,9 +120,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_PROFILE_BUILD) {
if (resultCode != RESULT_OK) {
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(MapActivity.this, WatchProfile.class),
REQUEST_PROFILE_BUILD);
displayPopupWindow();
} else {
db.collection("users").document(mAuth.getCurrentUser().getUid())
.update("builtProfile", true);
Expand Down Expand Up @@ -369,6 +371,21 @@ public void checkIn(String title) {
db.collection(PARK_CHECKIN).document(title).update(CHECKIN_FIELD, FieldValue.arrayUnion(mAuth.getCurrentUser().getUid()));
setUserCheckinPark(title);
}

public void displayPopupWindow(){
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
if (which == DialogInterface.BUTTON_POSITIVE)
startActivityForResult(new Intent(MapActivity.this, WatchProfile.class),
REQUEST_PROFILE_BUILD);
dialog.dismiss();
};
new AlertDialog.Builder(MapActivity.this)
.setTitle(POPUP_WINDOW_TITLE)
.setMessage(POPUP_WINDOW_BODY)
.setPositiveButton("OK", dialogClickListener)
.setCancelable(false)
.show();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Picasso;

import java.util.Objects;

import es.dmoral.toasty.Toasty;

public class WatchProfile extends BaseActivity implements View.OnClickListener, Toolbar.OnMenuItemClickListener {
Expand Down Expand Up @@ -200,6 +202,7 @@ public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
showSuccessToast(R.string.profile_saved);
setResult(RESULT_OK);
user.setBuiltProfile(true);
hideProgressBar();
} else showErrorToast();
}
Expand All @@ -216,7 +219,7 @@ public void saveProfile(String dogNameInput, String dogBreedInput, String dogAge
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
user = task.getResult().toObject(User.class);
user = Objects.requireNonNull(task.getResult()).toObject(User.class);
if (mUploadTask != null && mUploadTask.isInProgress())
Toasty.info(getApplicationContext(), "Upload in progress", Toast.LENGTH_SHORT).show();
else if (isUploadedImage)
Expand Down Expand Up @@ -253,8 +256,13 @@ public boolean onMenuItemClick(MenuItem item) {
String name = mEditTextDogName.getText().toString();
String age = mEditTextDogAge.getText().toString();
String breed = mEditTextDogBreed.getText().toString();
if(name == "name")
name = "UNKNOWN";
else if(age == "age")
age="UNKNOWN";
else if(breed=="breed")
breed="UNKNOWN";
saveProfile(name, breed, age);
user.setBuiltProfile(true);
hiddenItem = false;
hideItemInsideToolbar();
mButtonUploadPic.setVisibility(View.INVISIBLE);
Expand Down

0 comments on commit baa4f74

Please sign in to comment.