diff --git a/app/build.gradle b/app/build.gradle index 276d4b5..b5dd956 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,4 +54,6 @@ dependencies { + + apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e968882..a31424b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + @@ -40,15 +40,20 @@ + + + + + + + - - @@ -56,7 +61,6 @@ - @@ -64,7 +68,6 @@ - @@ -72,7 +75,6 @@ - @@ -80,7 +82,6 @@ - @@ -89,7 +90,6 @@ - @@ -113,9 +113,14 @@ android:label="@string/title_activity_maps"> + + \ No newline at end of file diff --git a/app/src/main/java/com/example/eforezan/kuevents/Event.java b/app/src/main/java/com/example/eforezan/kuevents/Event.java index 712e85f..21e62f8 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/Event.java +++ b/app/src/main/java/com/example/eforezan/kuevents/Event.java @@ -15,9 +15,10 @@ public class Event { private double Latitude; private double Longitude; - public Event(){ - } + public Event(){} + + public Event(String title, String desc, String image, String start_date, String end_date, String start_time, String end_time, double Latitude, double Longitude) { this.title = title; @@ -29,7 +30,6 @@ public Event(String title, String desc, String image, String start_date, String this.end_time = end_time; this.Latitude = Latitude; this.Longitude = Longitude; - } public String getTitle() { @@ -40,6 +40,10 @@ public void setTitle(String title) { this.title = title; } + public String getDesc() {return desc;} + + public void setDesc(String desc) {this.desc = desc;} + public String getImage() { return image; } diff --git a/app/src/main/java/com/example/eforezan/kuevents/HomePage.java b/app/src/main/java/com/example/eforezan/kuevents/HomePage.java index 9baa361..77e8358 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/HomePage.java +++ b/app/src/main/java/com/example/eforezan/kuevents/HomePage.java @@ -2,10 +2,16 @@ import android.content.Context; import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.design.widget.NavigationView; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -24,7 +30,7 @@ import com.google.firebase.database.ValueEventListener; import com.squareup.picasso.Picasso; -public class HomePage extends AppCompatActivity { +public class HomePage extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { private RecyclerView mEventList; @@ -47,6 +53,19 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_page); + Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar ); + setSupportActionBar( toolbar ); + + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + ActionBarDrawerToggle toggle; + toggle = new ActionBarDrawerToggle( + this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + drawer.addDrawerListener(toggle); + toggle.syncState(); + + NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); + navigationView.setNavigationItemSelectedListener(this); + mAuth = FirebaseAuth.getInstance(); mCurrentUser = mAuth.getCurrentUser(); if(mCurrentUser == null){ @@ -106,7 +125,7 @@ public void onClick(View view) { @Override public void onClick(View view) { mProcessGoing = true; - mDatabase.addValueEventListener(new ValueEventListener() { + mDatabase.child( "Events" ).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (mProcessGoing){ @@ -141,6 +160,36 @@ public void onCancelled(DatabaseError databaseError) { } + + @Override + public void onBackPressed() { + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + if (drawer.isDrawerOpen( GravityCompat.START)) { + drawer.closeDrawer(GravityCompat.START); + } else { + super.onBackPressed(); + } + } + + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + int id = item.getItemId(); + + if (id == R.id.profile) { + // setFragment(new profile()); + } + else if (id == R.id.events) { + //startActivity( new Intent(MainActivity.this, HomePage.class ) ); + } + else if (id == R.id.location) { + Intent i = new Intent(HomePage.this, MapsActivity.class); + startActivity(i); + } + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + drawer.closeDrawer(GravityCompat.START); + return true; + } + public static class EventViewHolder extends RecyclerView.ViewHolder{ View mView; @@ -270,4 +319,6 @@ public void onCancelled(DatabaseError databaseError) { return super.onOptionsItemSelected(item); } + + } diff --git a/app/src/main/java/com/example/eforezan/kuevents/MainActivity.java b/app/src/main/java/com/example/eforezan/kuevents/MainActivity.java index 935a51b..2aa70e6 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/MainActivity.java +++ b/app/src/main/java/com/example/eforezan/kuevents/MainActivity.java @@ -1,5 +1,6 @@ package com.example.eforezan.kuevents; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.NavigationView; @@ -9,19 +10,45 @@ import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; +import com.firebase.ui.database.FirebaseRecyclerAdapter; import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ValueEventListener; +import com.squareup.picasso.Picasso; public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { + + + private RecyclerView mEventList; + + + private DatabaseReference mDatabase; + private DatabaseReference mDatabaseUsers; + private DatabaseReference sDatabase; + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + private FirebaseUser mCurrentUser; + + private boolean mProcessGoing = false; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -38,7 +65,25 @@ protected void onCreate(Bundle savedInstanceState) { NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); - sDatabase = FirebaseDatabase.getInstance().getReference().child("Users"); + mAuth = FirebaseAuth.getInstance(); + mCurrentUser = mAuth.getCurrentUser(); + if(mCurrentUser == null){ + Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class); + loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(loginIntent); + } + + mDatabase = FirebaseDatabase.getInstance().getReference().child("Events"); + mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); + + mDatabase.keepSynced(true); + mDatabaseUsers.keepSynced(true); + + mEventList = (RecyclerView) findViewById(R.id.event_list); + mEventList.setHasFixedSize(true); + mEventList.setLayoutManager(new LinearLayoutManager(this)); + + } @Override @@ -51,10 +96,149 @@ public void onBackPressed() { } } + @Override + protected void onStart() { + super.onStart(); + + TextView going = (TextView) findViewById(R.id.going_status); + + FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter( + Event.class, + R.layout.event_row, + HomePage.EventViewHolder.class, + mDatabase + ) { + @Override + protected void populateViewHolder(HomePage.EventViewHolder viewHolder, Event model, int position) { + + final String post_key = getRef(position).getKey(); + + viewHolder.setTitle(model.getTitle()); + viewHolder.setImage(getApplicationContext(), model.getImage()); + viewHolder.setStart_Date(model.getStart_date()); + viewHolder.setgoingbtn(post_key); + //viewHolder.setLatitude(model.getLatitude()); + //viewHolder.setLongitude(model.getLongitude()); + // This is used in second.java + viewHolder.mView.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + //Toast.makeText(HomePage.this, post_key, Toast.LENGTH_LONG).show(); + Intent singleEventIntent = new Intent(MainActivity.this, second.class); + singleEventIntent.putExtra("event_id", post_key); + startActivity(singleEventIntent); + } + }); + + viewHolder.mGoingbtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mProcessGoing = true; + mDatabase.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (mProcessGoing){ + if (dataSnapshot.child(post_key).child("Attendee").hasChild(mAuth.getCurrentUser().getUid())){ + mDatabase.child(post_key).child("Attendee").child(mAuth.getCurrentUser().getUid()).removeValue(); + mProcessGoing = false; + + + }else{ + mDatabase.child(post_key).child("Attendee").child(mAuth.getCurrentUser().getUid()).setValue("Random"); + mProcessGoing = false; + } + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + } + }); + + + } + //}; + //} + }; + mEventList.setAdapter(firebaseRecyclerAdapter); + + + } + + public static class EventViewHolder extends RecyclerView.ViewHolder{ + + View mView; + ImageButton mGoingbtn; + DatabaseReference mDatabase; + FirebaseAuth mAuth; + TextView going; + + public EventViewHolder(View itemView) { + super(itemView); + mView = itemView; + mGoingbtn = (ImageButton) mView.findViewById(R.id.going_btn); + mDatabase = FirebaseDatabase.getInstance().getReference().child("Events"); + mAuth = FirebaseAuth.getInstance(); + mDatabase.keepSynced(true); + going = mView.findViewById(R.id.going_status); + + } + + public void setgoingbtn(final String post_key){ + mDatabase.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (dataSnapshot.child(post_key).child("Attendee").hasChild(mAuth.getCurrentUser().getUid())){ + mGoingbtn.setImageResource(R.mipmap.ic_bookmark_black_24dp); + going.setText("Going"); + + }else{ + mGoingbtn.setImageResource(R.drawable.ic_bookmark_border_black_24dp); + going.setText("Are you going?"); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + } + + public void setTitle(String title){ + TextView post_title = (TextView) mView.findViewById(R.id.post_title); + post_title.setText(title); + + } + + + + + public void setImage(Context ctx, String image){ + ImageView post_image = (ImageView) mView.findViewById(R.id.post_image); + Picasso.with(ctx).load(image).into(post_image); + + } + + public void setStart_Date(String start_date){ + TextView post_date=(TextView) mView.findViewById(R.id.post_date); + post_date.setText(start_date); + } + + + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu, menu); + getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @@ -92,11 +276,11 @@ public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.profile) { - setFragment(new profile()); + // setFragment(new profile()); } else if (id == R.id.events) { - startActivity( new Intent(MainActivity.this, HomePage.class ) ); + //startActivity( new Intent(MainActivity.this, HomePage.class ) ); } else if (id == R.id.location) { @@ -115,8 +299,8 @@ else if (id == R.id.location) { public void setFragment(Fragment fragment){ if(fragment!=null){ FragmentTransaction ft= getSupportFragmentManager().beginTransaction(); - ft.replace(R.id.content_main,fragment); - ft.commit(); + ft.replace(R.id.event_list,fragment).commit(); + } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); diff --git a/app/src/main/java/com/example/eforezan/kuevents/PostActivity.java b/app/src/main/java/com/example/eforezan/kuevents/PostActivity.java index d42c8dd..f521909 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/PostActivity.java +++ b/app/src/main/java/com/example/eforezan/kuevents/PostActivity.java @@ -108,6 +108,7 @@ public void onClick(View view) { mDateSetListener, year, month, day); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + dialog.getDatePicker().setMinDate( System.currentTimeMillis()-1000 ); dialog.show(); } }); @@ -137,6 +138,7 @@ public void onClick(View view) { kDateSetListener, year, month, day); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + dialog.getDatePicker().setMinDate( System.currentTimeMillis()-1000 ); dialog.show(); } }); @@ -237,6 +239,8 @@ private void startPosting(){ final String starttime_value = mStartTime.getText().toString().trim(); final String endtime_value= mEndTime.getText().toString().trim(); + + if (!TextUtils.isEmpty(title_value) && !TextUtils.isEmpty(desc_value) && mimageUri!=null){ mProgress.show(); StorageReference filepath = mStorage.child("Event Images").child(mimageUri.getLastPathSegment()); @@ -258,8 +262,9 @@ public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + mProgress.dismiss(); - startActivity(new Intent(PostActivity.this, HomePage.class)); + startActivity(new Intent(PostActivity.this, navigation.class)); } }); } diff --git a/app/src/main/java/com/example/eforezan/kuevents/ProfileActivity.java b/app/src/main/java/com/example/eforezan/kuevents/ProfileActivity.java index 2b8545b..73da83a 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/ProfileActivity.java +++ b/app/src/main/java/com/example/eforezan/kuevents/ProfileActivity.java @@ -87,7 +87,7 @@ public void onClick(View view) { next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startActivity(new Intent(ProfileActivity.this, HomePage.class)); + startActivity(new Intent(ProfileActivity.this, navigation.class)); } }); diff --git a/app/src/main/java/com/example/eforezan/kuevents/display_data.java b/app/src/main/java/com/example/eforezan/kuevents/display_data.java index 46658da..18bcbf5 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/display_data.java +++ b/app/src/main/java/com/example/eforezan/kuevents/display_data.java @@ -27,10 +27,16 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_data); - mDatabase = FirebaseDatabase.getInstance().getReference().child("Attendee"); + + + final String mPost_key = getIntent().getExtras().getString("event_id"); + + mDatabase = FirebaseDatabase.getInstance().getReference().child( "Events" ).child( mPost_key ).child( "Attendee" ); mUserList = (ListView) findViewById(R.id.user_list); + + final ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, mUsernames); mUserList.setAdapter(arrayAdapter); diff --git a/app/src/main/java/com/example/eforezan/kuevents/location.java b/app/src/main/java/com/example/eforezan/kuevents/location.java new file mode 100644 index 0000000..48f8740 --- /dev/null +++ b/app/src/main/java/com/example/eforezan/kuevents/location.java @@ -0,0 +1,82 @@ +package com.example.eforezan.kuevents; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.Marker; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ValueEventListener; + + + +public class location extends Fragment implements OnMapReadyCallback { + + private DatabaseReference mDatabase; + Marker marker; + + private GoogleMap mMap; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_location, container, false); + super.onCreate(savedInstanceState); + + // Obtain the SupportMapFragment and get notified when the map is ready to be used. + SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager() + .findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + mDatabase = FirebaseDatabase.getInstance().getReference().child("Events"); + // Obtain the SupportMapFragment and get notified when the map is ready to be used. + mapFragment.getMapAsync( this ); + mDatabase.push().setValue(marker); + return view; + } + + + @Override + public void onMapReady( GoogleMap googleMap) { + mMap = googleMap; + googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); + + mDatabase.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + for (DataSnapshot child : dataSnapshot.getChildren()) { + + String lat = child.child("Latitude").getValue().toString(); + String longi = child.child("Longitude").getValue().toString(); + String title = child.child( "title" ).getValue().toString(); + + double location_left = Double.parseDouble(lat); + double location_right = Double.parseDouble(longi); + LatLng cod = new LatLng(location_left, location_right); + mMap.addMarker(new MarkerOptions().position(cod).title(title)); + float zoomLevel = 16.0f; //This goes up to 21 + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cod, zoomLevel)); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + + } + + +} diff --git a/app/src/main/java/com/example/eforezan/kuevents/navigation.java b/app/src/main/java/com/example/eforezan/kuevents/navigation.java new file mode 100644 index 0000000..3c7d151 --- /dev/null +++ b/app/src/main/java/com/example/eforezan/kuevents/navigation.java @@ -0,0 +1,347 @@ +package com.example.eforezan.kuevents; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.support.design.widget.NavigationView; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.firebase.ui.database.FirebaseRecyclerAdapter; +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.auth.UserInfo; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ValueEventListener; +import com.squareup.picasso.Picasso; + +import org.w3c.dom.Text; + +public class navigation extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { + + private RecyclerView mEventList; + + + private DatabaseReference mDatabase; + private DatabaseReference mDatabaseUsers; + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + private FirebaseUser mCurrentUser; + private DatabaseReference databaseReference; + private FirebaseUser firebaseUser; + + private DatabaseReference uDatabase; + + + + private boolean mProcessGoing = false; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate( savedInstanceState ); + setContentView( R.layout.activity_navigation ); + Toolbar toolbar = (Toolbar) findViewById( R.id.toolbar ); + setSupportActionBar( toolbar ); + + + DrawerLayout drawer = (DrawerLayout) findViewById( R.id.drawer_layout ); + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close ); + drawer.addDrawerListener( toggle ); + toggle.syncState(); + + NavigationView navigationView = (NavigationView) findViewById( R.id.nav_view ); + navigationView.setNavigationItemSelectedListener( this ); + + mAuth = FirebaseAuth.getInstance(); + mCurrentUser = mAuth.getCurrentUser(); + if (mCurrentUser == null) { + Intent loginIntent = new Intent( navigation.this, LoginActivity.class ); + loginIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); + startActivity( loginIntent ); + } + + + mDatabase = FirebaseDatabase.getInstance().getReference().child( "Events" ); + mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child( "Users" ); + + firebaseUser = mAuth.getCurrentUser(); + + + mDatabase.keepSynced( true ); + mDatabaseUsers.keepSynced( true ); + + mEventList = (RecyclerView) findViewById( R.id.event_list ); + mEventList.setHasFixedSize( true ); + mEventList.setLayoutManager( new LinearLayoutManager( this ) ); + + mAuth = FirebaseAuth.getInstance(); + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + if (firebaseAuth.getCurrentUser() == null) { + startActivity( new Intent( navigation.this, LoginActivity.class ) ); + } + } + }; + + final TextView mName = (TextView) navigationView.getHeaderView( 0 ).findViewById( R.id.headername ); + final ImageView mPic = (ImageView) navigationView.getHeaderView( 0 ).findViewById( R.id.headerimageView ); + + databaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child(firebaseUser.getUid()); + + databaseReference.addListenerForSingleValueEvent(new ValueEventListener() { + + + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + mName.setText(dataSnapshot.child("name").getValue().toString()); + + String link =dataSnapshot.child("image").getValue().toString(); + Picasso.with(getBaseContext()).load(link).into(mPic); + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + + + + + + }); + + + + + } + + + @Override + public void onBackPressed() { + DrawerLayout drawer = (DrawerLayout) findViewById( R.id.drawer_layout ); + if (drawer.isDrawerOpen( GravityCompat.START )) { + drawer.closeDrawer( GravityCompat.START ); + } else { + super.onBackPressed(); + } + } + + @Override + protected void onStart() { + super.onStart(); + + TextView going = (TextView) findViewById(R.id.going_status); + + FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter( + Event.class, + R.layout.event_row, + HomePage.EventViewHolder.class, + mDatabase + ) { + @Override + protected void populateViewHolder(HomePage.EventViewHolder viewHolder, Event model, int position) { + + final String post_key = getRef(position).getKey(); + + viewHolder.setTitle(model.getTitle()); + viewHolder.setImage(getApplicationContext(), model.getImage()); + viewHolder.setStart_Date(model.getStart_date()); + viewHolder.setgoingbtn(post_key); + //viewHolder.setLatitude(model.getLatitude()); + //viewHolder.setLongitude(model.getLongitude()); + // This is used in second.java + viewHolder.mView.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + //Toast.makeText(HomePage.this, post_key, Toast.LENGTH_LONG).show(); + Intent singleEventIntent = new Intent(navigation.this, second.class); + singleEventIntent.putExtra("event_id", post_key); + startActivity(singleEventIntent); + } + }); + + viewHolder.mGoingbtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mProcessGoing = true; + mDatabase.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + if (mProcessGoing){ + if (dataSnapshot.child(post_key).child("Attendee").hasChild(mAuth.getCurrentUser().getUid())){ + mDatabase.child(post_key).child("Attendee").child(mAuth.getCurrentUser().getUid()).removeValue(); + mDatabaseUsers.child(mAuth.getCurrentUser().getUid()).child( "GoingEvents" ).child(post_key).removeValue(); + mProcessGoing = false; + + + }else{ + + + + String uid = (String) mAuth.getCurrentUser().getUid().toString(); + + uDatabase = FirebaseDatabase.getInstance().getReference().child("Users"); + + uDatabase.child(uid).addValueEventListener( new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + + String name = (String) dataSnapshot.child("name").getValue(); + + mDatabase.child(post_key).child("Attendee").child(mAuth.getCurrentUser().getUid()).setValue(name); + mDatabaseUsers.child( mAuth.getCurrentUser().getUid()).child( "GoingEvents" ).child( post_key ).setValue( dataSnapshot.child(post_key).child( "title" ).getValue() ); + mProcessGoing = false; + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + } ); + + //mDatabase.child(post_key).child("Attendee").child(mAuth.getCurrentUser().getUid()).setValue(uid); + //mDatabaseUsers.child( mAuth.getCurrentUser().getUid()).child( "GoingEvents" ).child( post_key ).setValue( dataSnapshot.child(post_key).child( "title" ).getValue() ); + //mProcessGoing = false; + } + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + } + }); + + + } + //}; + //} + }; + mEventList.setAdapter(firebaseRecyclerAdapter); + + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate( R.menu.main_menu, menu ); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case R.id.action_logout: + + FirebaseAuth.getInstance().signOut(); + finish(); + startActivity(new Intent(this, LoginActivity.class)); + + break; + + case R.id.action_add: + + String uid = mCurrentUser.getUid().toString().trim(); + + mDatabaseUsers.child(uid).addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + + String role = (String) dataSnapshot.child("role").getValue(); + + if (role.equals("Admin")){ + Toast.makeText(navigation.this, "You are admin", Toast.LENGTH_LONG).show(); + startActivity(new Intent(navigation.this, PostActivity.class)); + + } + + if (role.equals("Normal")) + { + View b = findViewById(R.id.action_add); + b.setVisibility(View.GONE); + } + + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + + + // Toast.makeText(HomePage.this, uid, Toast.LENGTH_LONG).show(); + + + + + + break; + + case R.id.map_button: + startActivity( new Intent( navigation.this, MapsActivity.class ) ); + } + + + return super.onOptionsItemSelected( item ); + } + + @SuppressWarnings("StatementWithEmptyBody") + @Override + public boolean onNavigationItemSelected(MenuItem item) { + // Handle navigation view item clicks here. + int id = item.getItemId(); + + if (id == R.id.profile) { + setFragment( new profile() ); + } else if (id == R.id.events) { + startActivity( new Intent( navigation.this, navigation.class ) ); + + } else if (id == R.id.location) { + setFragment( new location() ); + } + DrawerLayout drawer = (DrawerLayout) findViewById( R.id.drawer_layout ); + drawer.closeDrawer( GravityCompat.START ); + return true; + } + + public void setFragment(Fragment fragment){ + if(fragment!=null){ + FragmentTransaction ft= getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.layout_layout,fragment).commit(); + + } + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + drawer.closeDrawer(GravityCompat.START); + } +} diff --git a/app/src/main/java/com/example/eforezan/kuevents/profile.java b/app/src/main/java/com/example/eforezan/kuevents/profile.java index 30da5d8..f968ab0 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/profile.java +++ b/app/src/main/java/com/example/eforezan/kuevents/profile.java @@ -43,7 +43,6 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, private void setupViewPager(ViewPager viewPager){ sliderAdapter adapter = new sliderAdapter(getChildFragmentManager()); adapter.addFragment(new tab1(), "Profile"); - adapter.addFragment(new tab2(), "Events posts"); adapter.addFragment(new tab3(), "Attended"); viewPager.setAdapter(adapter); } diff --git a/app/src/main/java/com/example/eforezan/kuevents/second.java b/app/src/main/java/com/example/eforezan/kuevents/second.java index c14cc11..2341911 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/second.java +++ b/app/src/main/java/com/example/eforezan/kuevents/second.java @@ -28,7 +28,7 @@ public class second extends AppCompatActivity { - //private String mPost_key = null; + String event_title; private DatabaseReference mDatabase; @@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) { mDatabase = FirebaseDatabase.getInstance().getReference().child("Events"); - String mPost_key = getIntent().getExtras().getString("event_id"); + final String mPost_key = getIntent().getExtras().getString("event_id"); mEventSingleImage = (ImageView) findViewById(R.id.image_event); mEventSingleTitle = (TextView) findViewById(R.id.title_view); @@ -62,6 +62,8 @@ protected void onCreate(Bundle savedInstanceState) { //Toast.makeText(second.this, mPost_key, Toast.LENGTH_LONG).show(); + //button_sbm = (Button) findViewById(R.id.button); + button_showdb = (Button) findViewById(R.id.button_showdb); @@ -73,11 +75,36 @@ public void onDataChange(DataSnapshot dataSnapshot) { String event_desc = (String) dataSnapshot.child("desc").getValue(); String event_image = (String) dataSnapshot.child("image").getValue(); + final String post_key= (String) dataSnapshot.getKey(); + + // final String post_key= mDatabase.child("title").push().getKey(); + + //added + //final String post_key = (String) dataSnapshot.getChildren().iterator().next().getKey(); + + //String uid = mDatabase.child("Events").push().getKey(); + //Log.i("uid", uid); + + + mEventSingleTitle.setText(event_title); mEventSingleDesc.setText(event_desc); Picasso.with(second.this).load(event_image).into(mEventSingleImage); + button_showdb.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view2) { + + // Toast.makeText(second.this, post_key, Toast.LENGTH_SHORT).show(); + Intent intent2 = new Intent(second.this, display_data.class); + intent2.putExtra("event_id", post_key); + startActivity(intent2); + } + }); + + + } @@ -92,13 +119,24 @@ public void onCancelled(DatabaseError databaseError) { //radio_b = (RadioButton) findViewById(selected_id); - button_sbm = (Button) findViewById(R.id.button); - button_showdb = (Button) findViewById(R.id.button_showdb); - mDatabase = FirebaseDatabase.getInstance().getReference().child("Attendee"); + + + /*button_showdb.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view2) { + + Toast.makeText(second.this, event_title, Toast.LENGTH_SHORT).show(); + //Intent intent2 = new Intent(second.this, display_data.this); + //intent2.putExtra("event_id", post_key); + //startActivity(intent2); + } + }); + */ + // AddData(); - showdb(); + //showdb(); @@ -144,16 +182,7 @@ public void onComplete(@NonNull Task task) { - public void showdb(){ - button_showdb.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view2) { - Intent intent2 = new Intent("com.example.eforezan.kuevents.display_data"); - startActivity(intent2); - } - }); - } diff --git a/app/src/main/java/com/example/eforezan/kuevents/splash.java b/app/src/main/java/com/example/eforezan/kuevents/splash.java new file mode 100755 index 0000000..63a3920 --- /dev/null +++ b/app/src/main/java/com/example/eforezan/kuevents/splash.java @@ -0,0 +1,50 @@ +package com.example.eforezan.kuevents; + +import android.content.Intent; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.Menu; +import android.view.MenuItem; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.ImageView; +import android.widget.TextView; + +public class splash extends AppCompatActivity { + private TextView tv; + private ImageView iv; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_splash); + + tv = (TextView) findViewById(R.id.tv); + iv = (ImageView) findViewById(R.id.iv); + Animation myanim = AnimationUtils.loadAnimation(this, R.anim.mytransistion); + tv.startAnimation(myanim); + iv.startAnimation(myanim); + final Intent i = new Intent(this, LoginActivity.class); + Thread timer = new Thread() { + public void run() { + try { + sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + startActivity(i); + finish(); + } + + } + }; + timer.start(); + + } +} + diff --git a/app/src/main/java/com/example/eforezan/kuevents/tab3.java b/app/src/main/java/com/example/eforezan/kuevents/tab3.java index 1865452..f739ae1 100644 --- a/app/src/main/java/com/example/eforezan/kuevents/tab3.java +++ b/app/src/main/java/com/example/eforezan/kuevents/tab3.java @@ -3,19 +3,84 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.ChildEventListener; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; + +import java.util.ArrayList; public class tab3 extends Fragment{ private static final String TAG ="Attended"; + private DatabaseReference mDatabase; + private FirebaseAuth mAuth; + private ListView mEventList; + private ArrayList mEventnames = new ArrayList<>(); @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_tab3,container,false); - return view; + View view = inflater.inflate( R.layout.fragment_tab3, container, false ); + + + mAuth = FirebaseAuth.getInstance(); + + mDatabase = FirebaseDatabase.getInstance().getReference().child( "Users" ).child( mAuth.getCurrentUser().getUid() ).child( "GoingEvents" ); + mEventList =(ListView) view.findViewById( R.id.attended_list ); + + + + final ArrayAdapter arrayAdapter = new ArrayAdapter( getContext(), android.R.layout.simple_expandable_list_item_1, mEventnames ); + mEventList.setAdapter( arrayAdapter ); + + mDatabase.addChildEventListener( new ChildEventListener() { + @Override + public void onChildAdded(DataSnapshot dataSnapshot, String s) { + String value = dataSnapshot.getValue().toString(); + arrayAdapter.add( value); + + Toast.makeText(getContext(),"Attended list",Toast.LENGTH_LONG ).show(); + + } + + @Override + public void onChildChanged(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onChildRemoved(DataSnapshot dataSnapshot) { + + } + + @Override + public void onChildMoved(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + } ); + + + return super.onCreateView(inflater, container, savedInstanceState); + } + + + } \ No newline at end of file diff --git a/app/src/main/res/anim/mytransistion.xml b/app/src/main/res/anim/mytransistion.xml new file mode 100755 index 0000000..9a78f9f --- /dev/null +++ b/app/src/main/res/anim/mytransistion.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_camera.xml b/app/src/main/res/drawable-v21/ic_menu_camera.xml new file mode 100644 index 0000000..0d9ea10 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_camera.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_gallery.xml b/app/src/main/res/drawable-v21/ic_menu_gallery.xml new file mode 100644 index 0000000..f6872c4 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_manage.xml b/app/src/main/res/drawable-v21/ic_menu_manage.xml new file mode 100644 index 0000000..c1be60b --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_manage.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/ic_menu_send.xml b/app/src/main/res/drawable-v21/ic_menu_send.xml new file mode 100644 index 0000000..00c668c --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_send.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_share.xml b/app/src/main/res/drawable-v21/ic_menu_share.xml new file mode 100644 index 0000000..a28fb9e --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_share.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_slideshow.xml b/app/src/main/res/drawable-v21/ic_menu_slideshow.xml new file mode 100644 index 0000000..209aa64 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_slideshow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/logo32.png b/app/src/main/res/drawable/logo32.png new file mode 100755 index 0000000..9cdb9a1 Binary files /dev/null and b/app/src/main/res/drawable/logo32.png differ diff --git a/app/src/main/res/layout/activity_home_page.xml b/app/src/main/res/layout/activity_home_page.xml index e1dd8a5..233c6b2 100644 --- a/app/src/main/res/layout/activity_home_page.xml +++ b/app/src/main/res/layout/activity_home_page.xml @@ -1,15 +1,60 @@ - + android:fitsSystemWindows="true" + tools:openDrawer="start"> - - + android:layout_gravity="start" + android:fitsSystemWindows="true" + app:headerLayout="@layout/nav_header_main" + app:menu="@menu/activity_main_drawer" /> + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 620b1cf..8b0d4b3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -23,4 +23,7 @@ app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /> + + + diff --git a/app/src/main/res/layout/activity_navigation.xml b/app/src/main/res/layout/activity_navigation.xml new file mode 100644 index 0000000..9ff6a66 --- /dev/null +++ b/app/src/main/res/layout/activity_navigation.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_second.xml b/app/src/main/res/layout/activity_second.xml index e272184..139093d 100644 --- a/app/src/main/res/layout/activity_second.xml +++ b/app/src/main/res/layout/activity_second.xml @@ -7,17 +7,6 @@ tools:context="com.example.eforezan.kuevents.second"> -