Skip to content

Commit

Permalink
Globals, Privacy Policy and God Mode Added
Browse files Browse the repository at this point in the history
-Globals class has all globals in one place.
-God can delete any entry from the app.
-Other code cleanup.
  • Loading branch information
divya21raj committed Sep 20, 2018
1 parent f73b099 commit 30bb97b
Show file tree
Hide file tree
Showing 23 changed files with 486 additions and 239 deletions.
27 changes: 25 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
plugins {}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

//noinspection GradleCompatible
apply plugin: 'com.android.application'

Expand All @@ -16,8 +31,8 @@ android {
applicationId 'garbagecollectors.com.unipool'
minSdkVersion 16
targetSdkVersion 27
versionCode 120
versionName "1.20"
versionCode 124
versionName "1.24"
resConfigs "en"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -29,6 +44,8 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Disable fabric build ID generation for debug builds
//ext.enableCrashlytics = false
debuggable true
}
}
Expand All @@ -55,11 +72,17 @@ dependencies {
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-config:16.0.0'

implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}

implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'

implementation 'com.google.code.gson:gson:2.8.2'

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:mediarouter-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyB8Ik3P9bFz_prcjauv0oGMM_4gQmK2U_I" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="8bde319aa83c03e6a94fbcb5548b9f2c14b4e503"
/>

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/logo_trans" />

Expand Down Expand Up @@ -72,7 +77,8 @@
</intent-filter>
</service>

<activity android:name=".activities.AboutActivity"></activity>
<activity android:name=".activities.AboutActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import garbagecollectors.com.unipool.R;
import garbagecollectors.com.unipool.activities.RequestActivity.RequestActivity;
import garbagecollectors.com.unipool.application.Constants;
import garbagecollectors.com.unipool.application.Globals;
import garbagecollectors.com.unipool.application.UtilityMethods;

import static garbagecollectors.com.unipool.activities.BaseActivity.currentUser;
Expand Down Expand Up @@ -117,6 +117,12 @@ private void dealWithSelectedMenuItem(MenuItem menuItem)
case R.id.nav_about:
break;

case R.id.nav_privacy:
// The code for opening a URL in a Browser in Android:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.PrivacyPolicyUrl)));
startActivity(browserIntent);
break;

case R.id.nav_logout:
BaseActivity.mAuth.signOut();
startActivity(new Intent(this, LoginActivity.class));
Expand Down Expand Up @@ -214,6 +220,6 @@ public void onBackPressed()
protected void onResume()
{
super.onResume();
Constants.OPEN_ACTIVITY = "ABOUT";
Globals.OPEN_ACTIVITY = "ABOUT";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
Expand All @@ -24,7 +25,6 @@
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseException;
Expand All @@ -41,9 +41,10 @@
import garbagecollectors.com.unipool.activities.RequestActivity.ReceivedRequestsFragment;
import garbagecollectors.com.unipool.activities.RequestActivity.RequestActivity;
import garbagecollectors.com.unipool.activities.RequestActivity.SentRequestsFragment;
import garbagecollectors.com.unipool.application.Constants;
import garbagecollectors.com.unipool.application.Globals;
import garbagecollectors.com.unipool.application.UtilityMethods;
import garbagecollectors.com.unipool.dialog.NewEntryDialog;
import garbagecollectors.com.unipool.firebase.FirebaseInteractions;
import garbagecollectors.com.unipool.models.GenLocation;
import garbagecollectors.com.unipool.models.Message;
import garbagecollectors.com.unipool.models.TripEntry;
Expand All @@ -63,7 +64,7 @@ public abstract class BaseActivity extends AppCompatActivity implements BottomNa

public static User finalCurrentUser;

protected static ArrayList<TripEntry> tripEntryList = SplashActivity.getTripEntryList();
public static ArrayList<TripEntry> tripEntryList = SplashActivity.getTripEntryList();
protected static HashMap<String, User> chatMap; //key = UserId

protected static HashMap<String, HashMap<String, Message>> messages = new HashMap<>(); //Key - PairUpID, Value- List of messages in that pairUp
Expand All @@ -80,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(getContentViewId());

Constants.init();
Globals.init();

mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
Expand All @@ -92,14 +93,14 @@ protected void onCreate(Bundle savedInstanceState)
actionBar.setDisplayHomeAsUpEnabled(true);
}

Constants.userDatabaseReference = FirebaseDatabase.getInstance().getReference(Constants.UNI + "users/" + finalCurrentUser.getUserId());
Constants.userMessageDatabaseReference = FirebaseDatabase.getInstance().getReference(Constants.UNI + "messages/" + finalCurrentUser.getUserId());
Globals.userDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "users/" + finalCurrentUser.getUserId());
Globals.userMessageDatabaseReference = FirebaseDatabase.getInstance().getReference(Globals.UNI + "messages/" + finalCurrentUser.getUserId());

startMessageListener();

getTripEntries();
FirebaseInteractions.addTripEntryChildListener(this);

getMegaEntries();
FirebaseInteractions.addMegaEntryChildListener(this);

getUserDetails();
}
Expand Down Expand Up @@ -131,7 +132,7 @@ protected void startMessageListener()

protected void getUserDetails()
{
Constants.userDatabaseReference.addValueEventListener(new ValueEventListener()
Globals.userDatabaseReference.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
Expand All @@ -143,7 +144,7 @@ public void onDataChange(DataSnapshot dataSnapshot)
if(dataSnapshot.getValue() != null)
{
finalCurrentUser = dataSnapshot.getValue(User.class);
UtilityMethods.populateChatMap(dataSnapshot);
UtilityMethods.populateChatMap(dataSnapshot.child("pairUps"));
ReceivedRequestsFragment.refreshRecycler();
SentRequestsFragment.refreshRecycler();
ChatFragment.refreshRecycler();
Expand All @@ -169,134 +170,24 @@ public void onCancelled(DatabaseError error)
bottomNavigationView.setOnNavigationItemSelectedListener(this);
}

protected void getTripEntries()
{
Constants.entryDatabaseReference.addChildEventListener(new ChildEventListener()
{
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s)
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);

HomeActivity.updateRecycleAdapter();
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s)
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);

HomeActivity.updateRecycleAdapter();
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot)
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
if (tripEntry != null)
{
UtilityMethods.removeFromList(tripEntryList, tripEntry.getEntry_id());
HomeActivity.updateRecycleAdapter();
}

}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s)
{
//IDK
}

@Override
public void onCancelled(DatabaseError databaseError)
{
// Failed to read value
Log.w("Hello", "Failed to read value.", databaseError.toException());
Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
}
});
}

protected void getMegaEntries()
{
Constants.megaEntryDatabaseReference.addChildEventListener(new ChildEventListener()
{
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s)
{
try
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);

HomeActivity.updateRecycleAdapter();
} catch (Exception e)
{
e.printStackTrace();
}
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s)
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);

HomeActivity.updateRecycleAdapter();
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot)
{
try
{
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
if (tripEntry != null)
{
UtilityMethods.removeFromList(tripEntryList, tripEntry.getEntry_id());
HomeActivity.updateRecycleAdapter();
}
} catch (Exception e)
{
e.printStackTrace();
}

}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s)
{
//IDK
}

@Override
public void onCancelled(DatabaseError databaseError)
{
// Failed to read value
Log.w("Hello", "Failed to read value.", databaseError.toException());
Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
}
});
}

@Override
protected void onStart()
{
super.onStart();
updateNavigationBarState();
finalCurrentUser.setOnline(true);
Constants.userDatabaseReference.child("isOnline").setValue("true");
Globals.userDatabaseReference.child("isOnline").setValue("true");
}

@Override
public void onBackPressed()
{
super.onBackPressed();
finalCurrentUser.setOnline(false);
Constants.userDatabaseReference.child("isOnline").setValue("false");
Constants.expiryDatabaseReference.child(finalCurrentUser.getUserId()).removeValue();
Globals.userDatabaseReference.child("isOnline").setValue("false");
Globals.expiryDatabaseReference.child(finalCurrentUser.getUserId()).removeValue();
}

@Override
Expand Down Expand Up @@ -398,6 +289,12 @@ protected void dealWithSelectedMenuItem(MenuItem menuItem)
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
overridePendingTransition(0, 0);
finish();
break;

case R.id.nav_privacy:
// The code for opening a URL in a Browser in Android:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.PrivacyPolicyUrl)));
startActivity(browserIntent);
break;

case R.id.nav_logout:
Expand All @@ -407,7 +304,7 @@ protected void dealWithSelectedMenuItem(MenuItem menuItem)
break;

case R.id.nav_home:
if(!Constants.OPEN_ACTIVITY.contains("HOME"))
if(!Globals.OPEN_ACTIVITY.contains("HOME"))
{
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
overridePendingTransition(0, 0);
Expand All @@ -416,7 +313,7 @@ protected void dealWithSelectedMenuItem(MenuItem menuItem)
break;

case R.id.nav_newEntry:
if(Constants.OPEN_ACTIVITY.contains("HOME"))
if(Globals.OPEN_ACTIVITY.contains("HOME"))
new NewEntryDialog().show(getFragmentManager(), "NewEntryDialog");
else
{
Expand All @@ -429,7 +326,7 @@ protected void dealWithSelectedMenuItem(MenuItem menuItem)
break;

case R.id.nav_requests:
if(!Constants.OPEN_ACTIVITY.contains("REQ"))
if(!Globals.OPEN_ACTIVITY.contains("REQ"))
{
startActivity(new Intent(getApplicationContext(), RequestActivity.class));
overridePendingTransition(0, 0);
Expand All @@ -438,7 +335,7 @@ protected void dealWithSelectedMenuItem(MenuItem menuItem)
break;

case R.id.nav_chat:
if(!Constants.OPEN_ACTIVITY.contains("CHAT"))
if(!Globals.OPEN_ACTIVITY.contains("CHAT"))
{
Intent chatIntent = new Intent(getApplicationContext(), RequestActivity.class);
chatIntent.putExtra("openingTab", 2);
Expand Down
Loading

0 comments on commit 30bb97b

Please sign in to comment.