Skip to content

Commit

Permalink
Added Splash screen to load data before seeing MainActivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvielCo committed May 24, 2020
1 parent fd3e9f5 commit 072e084
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 91 deletions.
40 changes: 27 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".map_profile.profile.WatchProfile"></activity>

<!-- MAIN ACTIVITY -->
<activity
android:name=".utilities.MainActivity"
<activity android:name=".utilities.SplashScreenActivity"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- App settings (User) -->
</activity>
<activity android:name=".map_profile.profile.WatchProfile" />

<activity android:name=".utilities.MainActivity"
android:launchMode="singleTop"/>


<!-- App settings -->
<activity
android:name=".settings.SettingsActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity" /> <!-- Login, Register, Reset/Change password -->
android:parentActivityName=".map_profile.maps.MapActivity" />

<!-- Login, Register, Reset/Change password -->
<activity
android:name=".emailpassword.LoginActivity"
android:launchMode="singleTop"
Expand All @@ -44,7 +52,9 @@
<activity
android:name=".emailpassword.ChangePassActivity"
android:launchMode="singleTop"
android:parentActivityName=".settings.SettingsActivity" /> <!-- Map -->
android:parentActivityName=".settings.SettingsActivity" />

<!-- Map -->
<activity
android:name=".map_profile.maps.MapActivity"
android:launchMode="singleTop"
Expand All @@ -53,28 +63,32 @@
<activity
android:name=".map_profile.maps.LocationsActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity" /> <!-- Bulletin Board -->
android:parentActivityName=".map_profile.maps.MapActivity" />

<!-- Bulletin Board -->
<activity
android:name=".bulletinboard.BulletinBoardActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity"
android:theme="@style/AppTheme" />
<activity
android:name=".bulletinboard.NoteDescriptionActivity"
android:launchMode="singleTop"
android:parentActivityName=".bulletinboard.BulletinBoardActivity" /> <!-- Profile -->

<!-- Profile -->
<activity
android:name=".map_profile.profile.ProfileActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity" /> <!-- Contacts -->
android:parentActivityName=".map_profile.maps.MapActivity" />

<!-- Contacts -->
<activity
android:name=".contacts.ContactActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity" />
<activity
android:name=".contacts.EditContactActivity"
android:launchMode="singleTop"
android:parentActivityName=".map_profile.maps.MapActivity" /> <!-- Rating -->
android:parentActivityName=".map_profile.maps.MapActivity" />

<!-- Rating -->
<activity
android:name=".RateUsActivity"
android:theme="@style/Theme.AppCompat.DayNight.Dialog.Alert" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.evan.parknbark.R;
import com.evan.parknbark.validation.EditTextValidator;
import com.google.android.material.textfield.TextInputLayout;
Expand All @@ -23,7 +21,6 @@

import java.text.DateFormat;
import java.util.Calendar;
import java.util.concurrent.atomic.AtomicBoolean;

import es.dmoral.toasty.Toasty;

Expand All @@ -33,10 +30,9 @@ public class NewNoteDialog extends DialogFragment {
private TextInputLayout textInputTitle;
private TextInputLayout textInputDescription;

public static NewNoteDialog display(FragmentManager fragmentManager) {
static void display(FragmentManager fragmentManager) {
NewNoteDialog exampleDialog = new NewNoteDialog();
exampleDialog.show(fragmentManager, TAG);
return exampleDialog;
}

@Override
Expand All @@ -54,7 +50,7 @@ public void onStart() {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.new_note_dialog, container, false);
View v = inflater.inflate(R.layout.dialog_new_note, container, false);
toolbar = v.findViewById(R.id.toolbar);
textInputDescription = v.findViewById(R.id.text_input_description);
textInputTitle = v.findViewById(R.id.text_input_title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NoteDescriptionDialog extends DialogFragment {
private static final String TAG = "NoteDescriptionDialog";
private Toolbar toolbar;

public static NoteDescriptionDialog display(FragmentManager fragmentManager) {
static NoteDescriptionDialog display(FragmentManager fragmentManager) {
NoteDescriptionDialog noteDescriptionDialog = new NoteDescriptionDialog();
noteDescriptionDialog.show(fragmentManager, TAG);

Expand All @@ -43,7 +43,7 @@ public void onStart() {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.note_description_dialog, container, false);
View v = inflater.inflate(R.layout.dialog_note_description, container, false);
toolbar = v.findViewById(R.id.toolbar);
textViewDate = v.findViewById(R.id.text_view_date_des);
textViewDescription = v.findViewById(R.id.text_view_description_des);
Expand Down
34 changes: 0 additions & 34 deletions app/src/main/java/com/evan/parknbark/maps/usersFragment.java

This file was deleted.

49 changes: 18 additions & 31 deletions app/src/main/java/com/evan/parknbark/utilities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,39 @@

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import com.evan.parknbark.R;
import com.evan.parknbark.emailpassword.*;
import com.evan.parknbark.google.GoogleAuthActivity;
import com.evan.parknbark.map_profile.maps.MapActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;

import javax.annotation.Nullable;

public class MainActivity extends BaseActivity implements View.OnClickListener {
GoogleAuthActivity gaa;
@Nullable private String currentUserPermission;

@Override
public void onCreate(Bundle savedInstanceState) {
loadLocale(this);
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);

findViewById(R.id.button_sign_in_main).setOnClickListener(this);
findViewById(R.id.button_sign_up_main).setOnClickListener(this);
//findViewById(R.id.button_google_sign_in).setOnClickListener(this);

gaa = new GoogleAuthActivity();
Bundle bundle = getIntent().getExtras();
currentUserPermission = bundle.getString("current_user_permission", null);

updateUI(mAuth.getCurrentUser());
}

private void updateUI(FirebaseUser firebaseUser) {
if (firebaseUser != null) {
DocumentReference docRef = db.collection("users").document(mAuth.getCurrentUser().getUid());
docRef.get().addOnCompleteListener(this, new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
User user = task.getResult().toObject(User.class);
startActivity(new Intent(MainActivity.this, MapActivity.class)
.putExtra("current_user_permission", user.getPermission()));
}
}
});

}
if (firebaseUser != null && currentUserPermission != null)
startActivity(new Intent(MainActivity.this, MapActivity.class)
.putExtra("current_user_permission", currentUserPermission));
}

@Override
Expand All @@ -62,17 +47,19 @@ public void onClick(View v) {
case R.id.button_sign_up_main:
startActivity(new Intent(this, RegisterActivity.class));
break;
// case R.id.button_google_sign_in:
// GoogleSignInAccount googleAccount = gaa.signInWithGoogle();
// if (googleAccount != null)
// updateUI(mAuth.getCurrentUser());
// break;

}
}

@Override
public void onBackPressed() {
finish();
}

/*@Override
public void taskResults(User user) {
if (user != null) {
this.user = user;
updateUI(mAuth.getCurrentUser());
}
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.evan.parknbark.utilities;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.evan.parknbark.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;

import gr.net.maroulis.library.EasySplashScreen;

public class SplashScreenActivity extends BaseActivity {

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Create a bundle to pass to the next activity
Bundle bundle = new Bundle();

db = FirebaseFirestore.getInstance();
mAuth = FirebaseAuth.getInstance();
FirebaseUser firebaseUser = mAuth.getCurrentUser();
if (firebaseUser != null) {
DocumentReference docRef = db.collection("users").document(firebaseUser.getUid());
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
User user = task.getResult().toObject(User.class);
//if user is logged in, put the permission into bundle
//else, do nothing
bundle.putString("current_user_permission", user.getPermission());
}
}
});
}


EasySplashScreen config = new EasySplashScreen(this)
.withFullScreen()
.withTargetActivity(MainActivity.class) //go to main activity
.withBundleExtras(bundle) //send bundle, either user logged in or nah
.withBackgroundColor(Color.parseColor("#e1f5fe"))
.withHeaderText("Welcome to")
.withLogo(R.mipmap.app_logo1_foreground); //TODO: adjust logo dimensions

View easySplashScreen = config.create();
setContentView(easySplashScreen);
}
}
3 changes: 0 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingStart="30dp"
android:paddingTop="30dp"
android:paddingEnd="30dp"
android:background="@color/colorAppBackground"
tools:context="com.evan.parknbark.utilities.MainActivity">

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions app/src/main/res/menu/drawer_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
android:checkableBehavior="none">
<item
android:id="@+id/nav_profile"
android:icon="@drawable/ic_editcontact"
android:title="@string/edit_my_profile" />
android:icon="@drawable/ic_editcontact" />
<item
android:id="@+id/nav_watch_profile"
android:title="@string/my_profile"
Expand Down

0 comments on commit 072e084

Please sign in to comment.