From eaa66e167cb86acbb3e9ae4de8c9ad302e0b6300 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Wed, 6 Jul 2016 22:41:47 +0300 Subject: [PATCH] added features - added user location to map - added titles to fragments - added logout option --- .../sagi/thesocialnotework/GmapFragment.java | 19 +++++++++++--- .../sagi/thesocialnotework/LoginActivity.java | 1 - .../sagi/thesocialnotework/MainActivity.java | 26 ++++++++++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index 34966f0..082e0bb 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -1,10 +1,12 @@ package com.android_app.matan.ara.sagi.thesocialnotework; import android.content.Context; +import android.content.pm.PackageManager; import android.location.Location; import android.net.Uri; import android.os.Bundle; //import android.app.Fragment; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; @@ -72,7 +74,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } - mainActivity = (MainActivity)getActivity(); + mainActivity = (MainActivity) getActivity(); gpsUtils = mainActivity.getGPSUtils(); @@ -108,11 +110,22 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { mMap = googleMap; - VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" +mainActivity.getUserId() , getNotesSuccessListener, mainActivity.genericErrorListener); + VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener); LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude()); mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!")); - mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + } + mMap.setMyLocationEnabled(true); + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 12)); } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java index ad816fb..bb0879a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java @@ -3,7 +3,6 @@ package com.android_app.matan.ara.sagi.thesocialnotework; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.Editable; diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index dfdc2d2..caa84a1 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -2,6 +2,8 @@ package com.android_app.matan.ara.sagi.thesocialnotework; import android.app.ProgressDialog; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; @@ -38,6 +40,7 @@ public class MainActivity extends AppCompatActivity public static ProgressDialog progress; private GmapFragment gmapFragment; private PersonalFragment personalFragment; + private Toolbar toolbar; public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; @@ -45,7 +48,8 @@ public class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar.setTitle("Personal Notes"); setSupportActionBar(toolbar); gmapFragment = new GmapFragment(); personalFragment = new PersonalFragment(); @@ -119,13 +123,13 @@ public class MainActivity extends AppCompatActivity int id = item.getItemId(); if (id == R.id.nav_explore) { - // Handle the camera action + toolbar.setTitle("Explore"); + setSupportActionBar(toolbar); } else if (id == R.id.nav_map) { -// + Log.d(TAG,"Before going to map"); -// gmapFragment.("note_list", (ArrayList) listOfNotes); -// gmapFragment.put("user_lat", gpsUtils.getLatitude()); -// gmapFragment.putExtra("user_lng", gpsUtils.getLongitude()); + toolbar.setTitle("Map"); + setSupportActionBar(toolbar); ft.replace(R.id.fragment_container, gmapFragment); ft.commit(); } else if (id == R.id.nav_personal) { @@ -134,9 +138,17 @@ public class MainActivity extends AppCompatActivity ft.replace(R.id.fragment_container, personalFragment); ft.commit(); } else if (id == R.id.nav_settings) { - + toolbar.setTitle("Settings"); + setSupportActionBar(toolbar); } else if (id == R.id.nav_logout) { + SharedPreferences sharedPref = this.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPref.edit(); + editor.remove("UserId"); + editor.commit(); + Intent loginActivity = new Intent(MainActivity.this, LoginActivity.class); + startActivity(loginActivity); + finish(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);