From 2b4b83a0d2d24c5b7ac1ba9b87e377d23a567daa Mon Sep 17 00:00:00 2001 From: Domagalski Date: Sat, 20 Oct 2018 11:54:41 +0200 Subject: [PATCH 01/11] we going back --- .idea/encodings.xml | 6 ++ .settings/org.eclipse.buildship.core.prefs | 2 + app/.classpath | 6 ++ .../org.eclipse.buildship.core.prefs | 2 + app/src/main/AndroidManifest.xml | 6 +- .../findmytutor/activity/MainActivity.java | 5 +- .../findmytutor/activity/SharingFragment.java | 76 +++++++++++++++++++ .../findmytutor/activity/StartupActivity.java | 7 +- 8 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .settings/org.eclipse.buildship.core.prefs create mode 100644 app/.classpath create mode 100644 app/.settings/org.eclipse.buildship.core.prefs create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..646dfea --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..e889521 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir= +eclipse.preferences.version=1 diff --git a/app/.classpath b/app/.classpath new file mode 100644 index 0000000..eb19361 --- /dev/null +++ b/app/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/.settings/org.eclipse.buildship.core.prefs b/app/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..b1886ad --- /dev/null +++ b/app/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e7eae35..128d662 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,9 +43,9 @@ - - - + { + ListPreference lp = (ListPreference) findPreference("key_status_value"); + updateListPreference(lp, newValue, "manual_statuses"); + return true; + }); + + /* Preference manualLocation = findPreference("key_sharing_enabled"); + manualLocation.setOnPreferenceChangeListener((preference, newValue) -> { + ListPreference lp = (ListPreference) findPreference("key_sharing_enabled"); + updateListPreference(lp, newValue, "sharing_enabled"); + return true; + });*/ + + Preference sharingLocation = findPreference("key_sharing_enabled"); + sharingLocation.setOnPreferenceChangeListener((preference, o) -> { + Log.e("change", "1"); + return false; + }); + } + + + protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){ + CharSequence [] entries = lp.getEntries(); + Set defaultEntries = new HashSet(Arrays.asList(entries)); + SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); + Set manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries); + manualStatusSet.add((String) newValue); + String [] manualStatusArr = manualStatusSet.toArray(new String[0]); + Arrays.sort(manualStatusArr); + setListPreferenceData(lp.getKey(),manualStatusArr); + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putStringSet(storageKey,manualStatusSet); + editor.commit(); + } + + protected ListPreference setListPreferenceData(String lp_name, String [] entries) { + ListPreference lp = (ListPreference) findPreference(lp_name); + lp.setEntries(entries); + CharSequence[] entryValues = new CharSequence [entries.length]; + + for (int i = 0; i < entries.length; i++){ + entryValues[i] = Integer.toString(i+1); + } + + lp.setDefaultValue("1"); + lp.setEntryValues(entryValues); + + return lp; + } +} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java index 04dfc8b..0833950 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java @@ -2,8 +2,9 @@ package com.uam.wmi.findmytutor.activity; import android.app.Activity; import android.content.Intent; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + import com.uam.wmi.findmytutor.utils.PrefUtils; @@ -14,7 +15,7 @@ public class StartupActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { if (PrefUtils.isLoggedIn(getApplicationContext())){ - Intent startupIntent = new Intent(this, MapActivity.class); + Intent startupIntent = new Intent(this, MainActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); finish(); @@ -30,7 +31,7 @@ public class StartupActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) { - Intent startupIntent = new Intent(this, MapActivity.class); + Intent startupIntent = new Intent(this, MainActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); } -- 2.20.1 From 091b714b18a1821a6bceae94038967982b47e56f Mon Sep 17 00:00:00 2001 From: Domagalski Date: Sat, 20 Oct 2018 18:09:28 +0200 Subject: [PATCH 02/11] working Markers with mixed adapter view and fragment layout --- app/src/main/AndroidManifest.xml | 3 +- .../findmytutor/activity/MainActivity.java | 205 ++++++++++++++++-- app/src/main/res/layout/activity_main.xml | 13 ++ 3 files changed, 205 insertions(+), 16 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 128d662..b5a061b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,7 +45,8 @@ android:label="@string/title_activity_sharing" /> + android:label="@string/title_activity_sharing" + android:launchMode="singleTop" /> coordsMap = new HashMap<>(); + + private CoordinateService coordinateService; + private CompositeDisposable disposable = new CompositeDisposable(); + // 4 search private ListView listView; @@ -65,16 +98,60 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); + final String authToken = sharedPref.getString("authToken",null); + coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); + + mHandler = new Handler(); Bundle extras = getIntent().getExtras(); Mapbox.getInstance(this, getString(R.string.access_token)); + + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + configureconfigureNavigationDrawer(); configureBottomNavigationView(); configureLogoutButton(); } + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() + .position(new LatLng(52.466782,16.927549))); + mStatusChecker.run(); + + mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { + @Override + public void onMapClick(@NonNull LatLng point) { + + // When the user clicks on the map, we want to animate the marker to that + // location. + ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", + new LatLngEvaluator(), marker.getPosition(), point); + markerAnimator.setDuration(2000); + markerAnimator.start(); + } + }); + } + + + Runnable mStatusChecker = new Runnable() { + @Override + public void run() { + try{ + fetchTopCoords(); + } finally { + mHandler.postDelayed(mStatusChecker, mInterval); + } + } + }; + private void configureconfigureNavigationDrawer() { listView = findViewById(R.id.list_item); Toolbar toolbar = findViewById(R.id.toolbar_main); @@ -282,18 +359,116 @@ public class MainActivity extends AppCompatActivity { } } - @Override - protected void onResume() { - super.onResume(); + private static class LatLngEvaluator implements TypeEvaluator { + // Method is used to interpolate the marker animation. + + private LatLng latLng = new LatLng(); + + @Override + public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { + latLng.setLatitude(startValue.getLatitude() + + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); + latLng.setLongitude(startValue.getLongitude() + + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); + return latLng; + } + } + + private void fetchTopCoords() { + disposable.add( +// coordinateService.getTopCoordinates() + coordinateService.getOnlineCoordinates() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver>() { + @Override + public void onSuccess(List coordsList) { + + + for (Coordinate element : coordsList) { + String id = element.getUserId(); + Coordinate cord = coordsMap.get(id); + + + Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); + Log.d("mapper", "b " + coordsMap.size()); + if (cord != null) { + if (!cord.getLongitude().equals(element.getLongitude()) + ) { + Log.d("mapper", " cos sie zienilo "); + Marker marker = mapboxMap.addMarker(new MarkerViewOptions() + .title(cord.getUserId()) + .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); + + ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", + new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); + markerAnimator.setDuration(2000); + markerAnimator.start(); + + coordsMap.replace(id,element); + } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ + Log.d("mapper", "update"); + Log.d("mapper", " "+cord.getTimeStamp()); + Log.d("mapper", " "+element.getTimeStamp()); + coordsMap.replace(id,element); + } + } else { + coordsMap.put(id,element); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); + } + } + } + + @Override + public void onError(Throwable e) { + Log.e("Error",e.toString()); + } + }) + ); + } @Override - protected void onPause() { + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); } protected void onDestroy() { super.onDestroy(); + mapView.onDestroy(); + mHandler.removeCallbacks(mStatusChecker); + disposable.dispose(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 807eab3..1b3c6cc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,7 @@ + + + + -- 2.20.1 From d60a3c413c1234415f1cf25f1c3291f49c20991c Mon Sep 17 00:00:00 2001 From: Domagalski Date: Mon, 22 Oct 2018 01:01:06 +0200 Subject: [PATCH 03/11] fragment with background --- .idea/misc.xml | 2 +- .../findmytutor/activity/MainActivity.java | 162 +++++++----------- .../findmytutor/activity/SharingFragment.java | 11 +- 3 files changed, 76 insertions(+), 99 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b0c7b20..dc44dda 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java index 7a24828..6926c8c 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java @@ -6,6 +6,7 @@ import android.app.FragmentTransaction; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.design.widget.BottomNavigationView; @@ -39,7 +40,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions; import android.util.Log; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.uam.wmi.findmytutor.ListViewAdapter; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; import com.uam.wmi.findmytutor.utils.PrefUtils; @@ -62,7 +62,7 @@ import io.reactivex.schedulers.Schedulers; public class MainActivity extends AppCompatActivity implements -OnMapReadyCallback { + OnMapReadyCallback { private BottomNavigationView mMainNav; private FrameLayout mMainFrame; @@ -88,11 +88,7 @@ OnMapReadyCallback { private CoordinateService coordinateService; private CompositeDisposable disposable = new CompositeDisposable(); - - // 4 search - private ListView listView; - private ArrayList stringArrayList; - private ListViewAdapter adapter; + private Runnable mStatusChecker; @Override protected void onCreate(Bundle savedInstanceState) { @@ -101,6 +97,17 @@ OnMapReadyCallback { final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); final String authToken = sharedPref.getString("authToken",null); + mStatusChecker = new Runnable() { + @Override + public void run() { + try{ + fetchTopCoords(); + } finally { + mHandler.postDelayed(mStatusChecker, mInterval); + } + } + }; + coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); mHandler = new Handler(); @@ -108,7 +115,7 @@ OnMapReadyCallback { Mapbox.getInstance(this, getString(R.string.access_token)); - + mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(this); @@ -141,28 +148,10 @@ OnMapReadyCallback { } - Runnable mStatusChecker = new Runnable() { - @Override - public void run() { - try{ - fetchTopCoords(); - } finally { - mHandler.postDelayed(mStatusChecker, mInterval); - } - } - }; - private void configureconfigureNavigationDrawer() { - listView = findViewById(R.id.list_item); Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); - setData(); - adapter = new ListViewAdapter(this, R.layout.item_listview, stringArrayList); - listView.setAdapter(adapter); - - listView.setOnItemClickListener((parent, view, position, id) -> Toast.makeText(MainActivity.this, (String)parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show()); - drawerLayout = findViewById(R.id.drawer_layout); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); @@ -175,7 +164,6 @@ OnMapReadyCallback { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } - } private void setFragment(Fragment fragment) { @@ -200,7 +188,7 @@ OnMapReadyCallback { profileFragment = new ProfileFragment(); // Default frag here - setFragment(mapFragment); +// setFragment(mapFragment); mMainNav.setSelectedItemId(R.id.nav_map); /* code below is resposible for changing colours of tabs in main tab menu */ @@ -209,13 +197,12 @@ OnMapReadyCallback { switch (item.getItemId()) { case R.id.nav_map: // setFragment(mapFragment); - setFragment(sharingFragment); return true; case R.id.nav_notif: setFragment(notificationFragment); return true; case R.id.nav_profile: - setFragment(profileFragment); + setFragment(sharingFragment); return true; default: return false; @@ -240,25 +227,6 @@ OnMapReadyCallback { }); } - // mock 4 search bar - private void setData() { - stringArrayList = new ArrayList<>(); - stringArrayList.add("Quynh Trang"); - stringArrayList.add("Hoang Bien"); - stringArrayList.add("Duc Tuan"); - stringArrayList.add("Dang Thanh"); - stringArrayList.add("Xuan Luu"); - stringArrayList.add("Phan Thanh"); - stringArrayList.add("Kim Kien"); - stringArrayList.add("Ngo Trang"); - stringArrayList.add("Thanh Ngan"); - stringArrayList.add("Nguyen Duong"); - stringArrayList.add("Quoc Cuong"); - stringArrayList.add("Tran Ha"); - stringArrayList.add("Vu Danh"); - stringArrayList.add("Minh Meo"); - } - @Override public boolean onCreateOptionsMenu( Menu menu) { getMenuInflater().inflate( R.menu.menu_main, menu); @@ -274,16 +242,16 @@ OnMapReadyCallback { @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { - adapter.filter(""); - listView.clearTextFilter(); +// adapter.filter(""); +// listView.clearTextFilter(); } else { - adapter.filter(newText); +// adapter.filter(newText); } + return true; } }); - return true; } @@ -376,58 +344,64 @@ OnMapReadyCallback { private void fetchTopCoords() { disposable.add( -// coordinateService.getTopCoordinates() + // coordinateService.getTopCoordinates() coordinateService.getOnlineCoordinates() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List coordsList) { + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver>() { + @Override + public void onSuccess(List coordsList) { - for (Coordinate element : coordsList) { - String id = element.getUserId(); - Coordinate cord = coordsMap.get(id); + for (Coordinate element : coordsList) { + String id = element.getUserId(); + Coordinate cord = coordsMap.get(id); - Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); - Log.d("mapper", "b " + coordsMap.size()); - if (cord != null) { - if (!cord.getLongitude().equals(element.getLongitude()) - ) { - Log.d("mapper", " cos sie zienilo "); - Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .title(cord.getUserId()) - .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); + Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); + Log.d("mapper", "b " + coordsMap.size()); + if (cord != null) { + if (!cord.getLongitude().equals(element.getLongitude()) + ) { + Log.d("mapper", " cos sie zienilo "); + Marker marker = mapboxMap.addMarker(new MarkerViewOptions() + .title(cord.getUserId()) + .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); - markerAnimator.setDuration(2000); - markerAnimator.start(); + ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", + new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); + markerAnimator.setDuration(2000); + markerAnimator.start(); - coordsMap.replace(id,element); - } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ - Log.d("mapper", "update"); - Log.d("mapper", " "+cord.getTimeStamp()); - Log.d("mapper", " "+element.getTimeStamp()); - coordsMap.replace(id,element); + coordsMap.replace(id,element); + } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ + Log.d("mapper", "update"); + Log.d("mapper", " "+cord.getTimeStamp()); + Log.d("mapper", " "+element.getTimeStamp()); + coordsMap.replace(id,element); + } + } else { + coordsMap.put(id,element); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); + } } - } else { - coordsMap.put(id,element); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); } - } - } - @Override - public void onError(Throwable e) { - Log.e("Error",e.toString()); - } - }) + @Override + public void onError(Throwable e) { + Log.e("Error",e.toString()); + } + }) ); } + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + @Override protected void onStart() { super.onStart(); @@ -464,12 +438,6 @@ OnMapReadyCallback { mHandler.removeCallbacks(mStatusChecker); disposable.dispose(); } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 639a0fb..65b22e8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -7,6 +7,9 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import com.uam.wmi.findmytutor.R; @@ -22,7 +25,6 @@ public class SharingFragment extends PreferenceFragment { public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_sharing); - Preference manualStatus = findPreference("key_manual_status"); manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { ListPreference lp = (ListPreference) findPreference("key_status_value"); @@ -44,6 +46,13 @@ public class SharingFragment extends PreferenceFragment { }); } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = super.onCreateView(inflater, container, savedInstanceState); + view.setBackgroundColor(getResources().getColor(android.R.color.white)); + + return view; + } protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){ CharSequence [] entries = lp.getEntries(); -- 2.20.1 From 5dab4eaf4bcfb2cecce0ffdf684fec663aab3dcd Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Thu, 25 Oct 2018 00:19:12 +0200 Subject: [PATCH 04/11] bottom navi with frags and activities --- .idea/misc.xml | 2 +- .../findmytutor/activity/BaseActivity.java | 42 ++++++++------ .../findmytutor/activity/SharingActivity.java | 2 +- .../findmytutor/activity/SharingFragment.java | 2 +- .../findmytutor/activity/StartupActivity.java | 4 +- app/src/main/res/layout/activity_map.xml | 11 +--- app/src/main/res/layout/base_activity.xml | 56 ++++++++++++------- .../main/res/{xml => layout}/pref_sharing.xml | 8 ++- 8 files changed, 72 insertions(+), 55 deletions(-) rename app/src/main/res/{xml => layout}/pref_sharing.xml (92%) diff --git a/.idea/misc.xml b/.idea/misc.xml index dc44dda..b0c7b20 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 4b0e776..8c0b5ba 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -1,5 +1,7 @@ package com.uam.wmi.findmytutor.activity; +import android.app.Fragment; +import android.app.FragmentTransaction; import android.content.Intent; import android.content.res.Configuration; import android.support.annotation.NonNull; @@ -39,6 +41,7 @@ public abstract class BaseActivity private ListView listView; private ArrayList stringArrayList; private ListViewAdapter adapter; + private SharingFragment sharingFragment; @Override @@ -48,6 +51,8 @@ public abstract class BaseActivity navigationView = findViewById(R.id.navigation); navigationView.setOnNavigationItemSelectedListener(this); + sharingFragment = new SharingFragment(); + } @@ -161,36 +166,37 @@ public abstract class BaseActivity overridePendingTransition(0,0); } + private void setFragment(Fragment fragment) { + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.activity_content, fragment); + fragmentTransaction.commit(); + } + + private void removeFragment(Fragment fragment) { + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.remove(fragment); + fragmentTransaction.commit(); + } + @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { navigationView.postDelayed(() -> { int itemId = item.getItemId(); if (itemId == R.id.nav_map) { - startActivity(new Intent(this, MapActivity.class)); + removeFragment(sharingFragment); + // startActivity(new Intent(this, MapActivity.class)); } else if (itemId == R.id.nav_profile) { - startActivity(new Intent(this, ProfileActivity.class)); + // startActivity(new Intent(this, ProfileActivity.class)); + setFragment(sharingFragment); + } else if (itemId == R.id.nav_notif) { startActivity(new Intent(this, NotificationsActivity.class)); } - finish(); + //finish(); }, 300); - return true; -// navigationView.postDelayed(() -> { -// int itemId = item.getItemId(); -// switch (itemId) { -// case R.id.nav_profile: -// startActivity(new Intent(this, ProfileActivity.class)); -// case R.id.nav_map: -// startActivity(new Intent(this, MapActivity.class)); -// case R.id.nav_notif: -// startActivity(new Intent(this, NotificationsActivity.class)); -// } -// -// finish(); -// }, 300); -// return true; + return true; } private void updateNavigationBarState() { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java index 30d5465..a989f0e 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingActivity.java @@ -36,7 +36,7 @@ public class SharingActivity extends AppCompatPreferenceActivity { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_sharing); + addPreferencesFromResource(R.layout.pref_sharing); Preference manualStatus = findPreference("key_manual_status"); manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 65b22e8..586fa13 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -24,7 +24,7 @@ public class SharingFragment extends PreferenceFragment { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_sharing); + addPreferencesFromResource(R.layout.pref_sharing); Preference manualStatus = findPreference("key_manual_status"); manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { ListPreference lp = (ListPreference) findPreference("key_status_value"); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java index 0833950..934b486 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java @@ -15,7 +15,7 @@ public class StartupActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { if (PrefUtils.isLoggedIn(getApplicationContext())){ - Intent startupIntent = new Intent(this, MainActivity.class); + Intent startupIntent = new Intent(this, MapActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); finish(); @@ -31,7 +31,7 @@ public class StartupActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) { - Intent startupIntent = new Intent(this, MainActivity.class); + Intent startupIntent = new Intent(this, MapActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); } diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 7af4e8e..c34a574 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -10,7 +10,7 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/base_activity.xml b/app/src/main/res/layout/base_activity.xml index 2edc8cc..044f938 100644 --- a/app/src/main/res/layout/base_activity.xml +++ b/app/src/main/res/layout/base_activity.xml @@ -5,30 +5,45 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> - - - - - /> - + android:layout_height="wrap_content"> + + + + + + + + + + + + + + - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_sharing.xml b/app/src/main/res/layout/pref_sharing.xml similarity index 92% rename from app/src/main/res/xml/pref_sharing.xml rename to app/src/main/res/layout/pref_sharing.xml index a06258b..4a75c7b 100644 --- a/app/src/main/res/xml/pref_sharing.xml +++ b/app/src/main/res/layout/pref_sharing.xml @@ -1,7 +1,10 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + tools:ignore="MissingDefaultResource" + android:layout_width="match_parent" + android:layout_height="match_parent"> - + + \ No newline at end of file -- 2.20.1 From b1af9f679860a706aab98a7d0c86257aae31ab97 Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Fri, 26 Oct 2018 20:41:36 +0200 Subject: [PATCH 05/11] code cleanup cont --- .../findmytutor/activity/BaseActivity.java | 4 +- .../findmytutor/activity/MainActivity.java | 40 -------- .../wmi/findmytutor/activity/MapFragment.java | 98 ------------------- .../activity/NotificationFragment.java | 31 ------ .../activity/NotificationsActivity.java | 95 ------------------ .../findmytutor/activity/ProfileFragment.java | 31 ------ .../res/layout/activity_notifications.xml | 20 ---- app/src/main/res/layout/fragment_profile.xml | 14 --- 8 files changed, 3 insertions(+), 330 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationFragment.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileFragment.java delete mode 100644 app/src/main/res/layout/fragment_profile.xml diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 8c0b5ba..db50b0d 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -185,13 +185,15 @@ public abstract class BaseActivity int itemId = item.getItemId(); if (itemId == R.id.nav_map) { removeFragment(sharingFragment); + // startActivity(new Intent(this, MapActivity.class)); } else if (itemId == R.id.nav_profile) { // startActivity(new Intent(this, ProfileActivity.class)); setFragment(sharingFragment); } else if (itemId == R.id.nav_notif) { - startActivity(new Intent(this, NotificationsActivity.class)); + //startActivity(new Intent(this, NotificationsActivity.class)); + setFragment(sharingFragment); } //finish(); }, 300); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java index 6926c8c..6aff006 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java @@ -67,10 +67,7 @@ public class MainActivity extends AppCompatActivity implements private BottomNavigationView mMainNav; private FrameLayout mMainFrame; private boolean isTutor; - private MapFragment mapFragment; private SharingFragment sharingFragment; - private NotificationFragment notificationFragment; - private ProfileFragment profileFragment;; private static final int REQUEST_PERMISSIONS = 100; boolean boolean_permission; @@ -121,7 +118,6 @@ public class MainActivity extends AppCompatActivity implements mapView.getMapAsync(this); configureconfigureNavigationDrawer(); - configureBottomNavigationView(); configureLogoutButton(); } @@ -172,43 +168,7 @@ public class MainActivity extends AppCompatActivity implements fragmentTransaction.commit(); } - private void configureBottomNavigationView(){ - mMainFrame = findViewById(R.id.main_frame); - mMainNav = findViewById(R.id.main_nav); - isTutor = PrefUtils.getIsTutor(getApplicationContext()); - - if (!isTutor) { - mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE); - } - - mapFragment = new MapFragment(); - sharingFragment = new SharingFragment(); - notificationFragment = new NotificationFragment(); - profileFragment = new ProfileFragment(); - - // Default frag here -// setFragment(mapFragment); - mMainNav.setSelectedItemId(R.id.nav_map); - - /* code below is resposible for changing colours of tabs in main tab menu */ - mMainNav.setOnNavigationItemSelectedListener(item -> { - - switch (item.getItemId()) { - case R.id.nav_map: -// setFragment(mapFragment); - return true; - case R.id.nav_notif: - setFragment(notificationFragment); - return true; - case R.id.nav_profile: - setFragment(sharingFragment); - return true; - default: - return false; - } - }); - } private void configureLogoutButton(){ // Logout button diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java deleted file mode 100644 index d8c1e36..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - - -import android.os.Bundle; -import android.app.Fragment; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.mapbox.mapboxsdk.maps.MapView; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.network.ApiClient; -import com.uam.wmi.findmytutor.service.CoordinateService; - -import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; - -/** - * A simple {@link Fragment} subclass. - */ -public class MapFragment extends Fragment { - private MapView mapView; - - - public MapFragment() { - // Required empty public constructor - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_map, container, false); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - mapView = (MapView) view.findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - CoordinateService service = ApiClient.getClient(getApplicationContext()) - .create(CoordinateService.class); - } - - @Override - public void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - public void onResume() { - super.onResume(); - mapView.onResume(); - - } - - @Override - public void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - public void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - mapView.onDestroy(); - } - -// @Override -// public void onDestroy() { -// super.onDestroy(); -// mapView.onDestroy(); -// } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - - -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationFragment.java deleted file mode 100644 index 431777b..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationFragment.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - - -import android.os.Bundle; -import android.app.Fragment; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.uam.wmi.findmytutor.R; - -/** - * A simple {@link Fragment} subclass. - */ -public class NotificationFragment extends Fragment { - - - public NotificationFragment() { - // Required empty public constructor - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_notification, container, false); - } - -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java index 30045ae..ceaca51 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java @@ -32,144 +32,49 @@ import io.reactivex.schedulers.Schedulers; public class NotificationsActivity extends BaseActivity { - private MapView mapView; - private CoordinateService coordinateService; - private CompositeDisposable disposable = new CompositeDisposable(); - private List coordinatesList = new ArrayList<>(); - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mapInit(savedInstanceState); - -// coordinateService = ApiClient.getClient(getApplicationContext()) -// .create(CoordinateService.class); - final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); - final String authToken = sharedPref.getString("authToken",null); - - coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); - - fetchTopCoords(); - } - - private void mapInit(Bundle savedInstanceState) { - // Mapbox access token is configured here. This needs to be called either in your application - // object or in the same activity which contains the mapview. - Mapbox.getInstance(this, getString(R.string.access_token)); - // This contains the MapView in XML and needs to be called after the access token is configured. - // setContentView(R.layout.activity_notifications); - - mapView = (MapView) findViewById(R.id.mapView2); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(MapboxMap mapboxMap) { - - final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .position(new LatLng(64.900932, -18.167040))); - - mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - - // When the user clicks on the map, we want to animate the marker to that - // location. - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), point); - markerAnimator.setDuration(2000); - markerAnimator.start(); - } - }); - - } - }); - - } - - private void fetchTopCoords() { - disposable.add( - coordinateService.getTopCoordinates() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List coordsList) { - - Log.d("mapTag", "co?"); - for (Coordinate element: - coordsList) { - Log.d("mapTag", element.getUserId()); - } - } - - @Override - public void onError(Throwable e) { - Log.e("Error",e.toString()); - } - }) - ); - } @Override protected void onStart() { super.onStart(); - mapView.onStart(); } @Override public void onResume() { super.onResume(); - mapView.onResume(); } @Override public void onPause() { super.onPause(); - mapView.onPause(); } @Override protected void onStop() { super.onStop(); - mapView.onStop(); } @Override public void onLowMemory() { super.onLowMemory(); - mapView.onLowMemory(); } @Override protected void onDestroy() { super.onDestroy(); - mapView.onDestroy(); - disposable.dispose(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); } - private static class LatLngEvaluator implements TypeEvaluator { - // Method is used to interpolate the marker animation. - private LatLng latLng = new LatLng(); - - @Override - public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { - latLng.setLatitude(startValue.getLatitude() - + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); - latLng.setLongitude(startValue.getLongitude() - + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); - return latLng; - } - } @Override protected int getContentViewId() { return R.layout.activity_notifications; } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileFragment.java deleted file mode 100644 index d994bfd..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileFragment.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - - -import android.os.Bundle; -import android.app.Fragment; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.uam.wmi.findmytutor.R; - -/** - * A simple {@link Fragment} subclass. - */ -public class ProfileFragment extends Fragment { - - - public ProfileFragment() { - // Required empty public constructor - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_profile, container, false); - } - -} diff --git a/app/src/main/res/layout/activity_notifications.xml b/app/src/main/res/layout/activity_notifications.xml index be82ea7..e07b34b 100644 --- a/app/src/main/res/layout/activity_notifications.xml +++ b/app/src/main/res/layout/activity_notifications.xml @@ -9,24 +9,4 @@ tools:context=".activity.NotificationsActivity"> - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml deleted file mode 100644 index f98dfe6..0000000 --- a/app/src/main/res/layout/fragment_profile.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file -- 2.20.1 From 2c81359665e7e4d3a87815c14b38d96fa25c658f Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Sun, 28 Oct 2018 19:58:15 +0100 Subject: [PATCH 06/11] rm unused activities and layouts --- .../activity/NotificationsActivity.java | 84 ------------------- .../findmytutor/activity/ProfileActivity.java | 14 ---- .../res/layout/activity_notifications.xml | 12 --- app/src/main/res/layout/activity_profile.xml | 17 ---- app/src/main/res/layout/fragment_map.xml | 22 ----- .../main/res/layout/fragment_notification.xml | 14 ---- .../main/res/{xml => layout}/pref_main.xml | 0 7 files changed, 163 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java delete mode 100644 app/src/main/res/layout/activity_notifications.xml delete mode 100644 app/src/main/res/layout/activity_profile.xml delete mode 100644 app/src/main/res/layout/fragment_map.xml delete mode 100644 app/src/main/res/layout/fragment_notification.xml rename app/src/main/res/{xml => layout}/pref_main.xml (100%) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java deleted file mode 100644 index ceaca51..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.animation.ObjectAnimator; -import android.animation.TypeEvaluator; -import android.animation.ValueAnimator; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.util.Log; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.model.Coordinate; -import com.uam.wmi.findmytutor.network.RetrofitClientInstance; -import com.uam.wmi.findmytutor.service.CoordinateService; - -import java.util.ArrayList; -import java.util.List; - -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableSingleObserver; -import io.reactivex.schedulers.Schedulers; - - -public class NotificationsActivity extends BaseActivity { - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - } - - @Override - protected void onStart() { - super.onStart(); - } - - @Override - public void onResume() { - super.onResume(); - } - - @Override - public void onPause() { - super.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - } - - - - @Override - protected int getContentViewId() { return R.layout.activity_notifications; } - - @Override - protected int getNavigationMenuItemId() { return R.id.nav_notif; } -} diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java deleted file mode 100644 index 5a3d92d..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/ProfileActivity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import com.uam.wmi.findmytutor.R; - -public class ProfileActivity extends BaseActivity { - - @Override - protected int getContentViewId() { return R.layout.activity_profile; } - - @Override - protected int getNavigationMenuItemId() { - return R.id.nav_profile; - } -} diff --git a/app/src/main/res/layout/activity_notifications.xml b/app/src/main/res/layout/activity_notifications.xml deleted file mode 100644 index e07b34b..0000000 --- a/app/src/main/res/layout/activity_notifications.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml deleted file mode 100644 index 49b6e9b..0000000 --- a/app/src/main/res/layout/activity_profile.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_map.xml b/app/src/main/res/layout/fragment_map.xml deleted file mode 100644 index 6a6d89f..0000000 --- a/app/src/main/res/layout/fragment_map.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notification.xml b/app/src/main/res/layout/fragment_notification.xml deleted file mode 100644 index 2cd9409..0000000 --- a/app/src/main/res/layout/fragment_notification.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/layout/pref_main.xml similarity index 100% rename from app/src/main/res/xml/pref_main.xml rename to app/src/main/res/layout/pref_main.xml -- 2.20.1 From d2405d36f6b621b8a962448fc0778699e5c3a7f3 Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Sun, 28 Oct 2018 21:56:40 +0100 Subject: [PATCH 07/11] finall clean up - ready to merge develop --- app/src/main/AndroidManifest.xml | 2 - .../findmytutor/activity/BaseActivity.java | 69 +++++++ .../wmi/findmytutor/activity/MapActivity.java | 189 +++++++++++++++++- .../activity/SettingsActivity.java | 2 +- app/src/main/res/layout/activity_map.xml | 11 +- 5 files changed, 259 insertions(+), 14 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b5a061b..6ec7431 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,9 +55,7 @@ android:enabled="true" /> - - diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index db50b0d..4492708 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -3,9 +3,13 @@ package com.uam.wmi.findmytutor.activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.os.Build; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; @@ -14,6 +18,7 @@ import android.os.Bundle; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -24,6 +29,8 @@ import android.widget.Toast; import com.uam.wmi.findmytutor.ListViewAdapter; import com.uam.wmi.findmytutor.R; +import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; +import com.uam.wmi.findmytutor.utils.PrefUtils; import java.util.ArrayList; @@ -43,6 +50,12 @@ public abstract class BaseActivity private ListViewAdapter adapter; private SharingFragment sharingFragment; + private static final int REQUEST_PERMISSIONS = 100; + boolean boolean_permission; + private boolean isTutor; + + + @Override protected void onCreate(Bundle savedInstanceState) { @@ -53,6 +66,10 @@ public abstract class BaseActivity navigationView.setOnNavigationItemSelectedListener(this); sharingFragment = new SharingFragment(); + isTutor = PrefUtils.getIsTutor(getApplicationContext()); + if (!isTutor) { + navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE); + } } @@ -111,6 +128,41 @@ public abstract class BaseActivity setUpNav(); actionBarDrawerToggle.syncState(); + Log.e("erororr", "guewa!" + isTutor); + +// if (isTutor && getContentViewId() == R.layout.activity_map) { + if (isTutor) { + Log.e("erororr", "taaaaaak!"); + fn_permission(); + } + } + + private void fn_permission() { + if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { + + if ((ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) { + + } else { + ActivityCompat.requestPermissions(BaseActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION + + }, + REQUEST_PERMISSIONS); + } + } else { + + if (isTutor) { + Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(intent); + } else { + startService(intent); + } + + } else { + Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show(); + } + } } @Override @@ -154,6 +206,21 @@ public abstract class BaseActivity return super.onOptionsItemSelected(item); } + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + switch (requestCode) { + case REQUEST_PERMISSIONS: { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + boolean_permission = true; + } else { + Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show(); + } + } + } + } + @Override protected void onStart() { super.onStart(); @@ -181,6 +248,8 @@ public abstract class BaseActivity @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { + + navigationView.postDelayed(() -> { int itemId = item.getItemId(); if (itemId == R.id.nav_map) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 67dfc45..4dced04 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -1,32 +1,199 @@ package com.uam.wmi.findmytutor.activity; +import android.animation.ObjectAnimator; +import android.animation.TypeEvaluator; +import android.animation.ValueAnimator; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.support.design.widget.FloatingActionButton; +import android.util.Log; import com.mapbox.mapboxsdk.Mapbox; +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.uam.wmi.findmytutor.R; +import com.uam.wmi.findmytutor.model.Coordinate; +import com.uam.wmi.findmytutor.network.RetrofitClientInstance; +import com.uam.wmi.findmytutor.service.CoordinateService; +import com.uam.wmi.findmytutor.utils.PrefUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.observers.DisposableSingleObserver; +import io.reactivex.schedulers.Schedulers; + + +public class MapActivity extends BaseActivity + implements OnMapReadyCallback { -public class MapActivity extends BaseActivity { - private MapView mapView; String tag = "LifeCycleEvents"; + + private MapView mapView; + private MapboxMap mapboxMap; + private int mInterval = 10000; + private Handler mHandler; + + private Map coordsMap = new HashMap<>(); + + private CoordinateService coordinateService; + private CompositeDisposable disposable = new CompositeDisposable(); + + private Runnable mStatusChecker; + + + + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Mapbox.getInstance(this, getString(R.string.access_token)); - mapView = findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); + configureLogoutButton(); - mapView.getMapAsync(new OnMapReadyCallback() { + final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); + final String authToken = sharedPref.getString("authToken",null); + + mStatusChecker = new Runnable() { @Override - public void onMapReady(MapboxMap mapboxMap) { - - // Customize map with markers, polylines, etc. - + public void run() { + try{ + fetchTopCoords(); + } finally { + mHandler.postDelayed(mStatusChecker, mInterval); + } } + }; + + coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJhM2MxMDU1YS1kZDM0LTQ5ZWItYTFkNS0xY2E5YTE2YzY0ODgiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiI4NTA0NDA5NS00NjBkLTQzZDgtYjMxMC0xYmNiNWMxNGExZjQiLCJleHAiOjE1NDMzNTAzMzQsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.xGyu6iBeq9xF0ufBd01jNzILLq1NeYa-5MeVOiPahD8"); + + mHandler = new Handler(); + Bundle extras = getIntent().getExtras(); + + Mapbox.getInstance(this, getString(R.string.access_token)); + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() + .position(new LatLng(52.466782,16.927549))); + mStatusChecker.run(); + + mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { + @Override + public void onMapClick(@NonNull LatLng point) { + + // When the user clicks on the map, we want to animate the marker to that + // location. + ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", + new LatLngEvaluator(), marker.getPosition(), point); + markerAnimator.setDuration(2000); + markerAnimator.start(); + } + }); + } + + private static class LatLngEvaluator implements TypeEvaluator { + // Method is used to interpolate the marker animation. + + private LatLng latLng = new LatLng(); + + @Override + public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { + latLng.setLatitude(startValue.getLatitude() + + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); + latLng.setLongitude(startValue.getLongitude() + + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); + return latLng; + } + } + + private void fetchTopCoords() { + disposable.add( + // coordinateService.getTopCoordinates() + coordinateService.getOnlineCoordinates() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableSingleObserver>() { + @Override + public void onSuccess(List coordsList) { + + + for (Coordinate element : coordsList) { + String id = element.getUserId(); + Coordinate cord = coordsMap.get(id); + + + Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); + Log.d("mapper", "b " + coordsMap.size()); + if (cord != null) { + if (!cord.getLongitude().equals(element.getLongitude()) + ) { + Log.d("mapper", " cos sie zienilo "); + Marker marker = mapboxMap.addMarker(new MarkerViewOptions() + .title(cord.getUserId()) + .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); + + ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", + new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); + markerAnimator.setDuration(2000); + markerAnimator.start(); + + coordsMap.replace(id,element); + } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ + Log.d("mapper", "update"); + Log.d("mapper", " "+cord.getTimeStamp()); + Log.d("mapper", " "+element.getTimeStamp()); + coordsMap.replace(id,element); + } + } else { + coordsMap.put(id,element); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); + } + } + } + + @Override + public void onError(Throwable e) { + Log.e("Error",e.toString()); + } + }) + ); + + } + + private void configureLogoutButton(){ + // Logout button + final FloatingActionButton button = findViewById(R.id.logoutButton); + + button.setOnClickListener(view -> { + PrefUtils.cleanUserLocalStorage(getApplicationContext()); + + Intent i = getBaseContext().getPackageManager() + .getLaunchIntentForPackage(getBaseContext().getPackageName()); + if (i != null) { + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + } + startActivity(i); + finish(); }); } @@ -67,6 +234,8 @@ public class MapActivity extends BaseActivity { protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); + mHandler.removeCallbacks(mStatusChecker); + disposable.dispose(); } @Override diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java index 13b75a1..c20fb4c 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java @@ -31,7 +31,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_main); + addPreferencesFromResource(R.layout.pref_main); //TODO add on change listeners for preferences diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index c34a574..282f395 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -18,5 +18,14 @@ mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8"> - + \ No newline at end of file -- 2.20.1 From 9aca72bdfee75ebd410af6ab7dfc8e178cf09c5c Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Tue, 30 Oct 2018 18:24:16 +0100 Subject: [PATCH 08/11] replace changed to put --- .../com/uam/wmi/findmytutor/activity/MapActivity.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index 4dced04..fac1dc4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -157,12 +157,14 @@ public class MapActivity extends BaseActivity markerAnimator.setDuration(2000); markerAnimator.start(); - coordsMap.replace(id,element); +// coordsMap.replace(id,element); + coordsMap.put(id,element); } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ Log.d("mapper", "update"); Log.d("mapper", " "+cord.getTimeStamp()); - Log.d("mapper", " "+element.getTimeStamp()); - coordsMap.replace(id,element); + Log.d("mapper", " " + element.getTimeStamp()); +// coordsMap.replace(id,element); + coordsMap.put(id,element); } } else { coordsMap.put(id,element); -- 2.20.1 From 2a79537fbee88f5662cb5b6fd670aefe45e7dc51 Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Tue, 30 Oct 2018 19:35:40 +0100 Subject: [PATCH 09/11] rdy to develop --- app/src/main/AndroidManifest.xml | 2 +- .../findmytutor/activity/MainActivity.java | 4 - .../wmi/findmytutor/activity/MapActivity.java | 74 +---- .../activity/NotificationsActivity.java | 266 ------------------ app/src/main/res/.DS_Store | Bin 0 -> 6148 bytes app/src/main/res/layout/activity_map.xml | 16 -- 6 files changed, 5 insertions(+), 357 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java create mode 100644 app/src/main/res/.DS_Store diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5719d1c..6ec7431 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,7 +18,7 @@ android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java index efc0517..6aff006 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java @@ -40,10 +40,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions; import android.util.Log; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.geometry.LatLng; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.maps.MapFragment; -import com.uam.wmi.findmytutor.ListViewAdapter; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; import com.uam.wmi.findmytutor.utils.PrefUtils; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index d33c9c6..8db8e41 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -10,14 +10,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; import android.util.Log; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.widget.Toast; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.annotations.Marker; @@ -44,15 +36,11 @@ import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; -public class MapActivity extends BaseActivity +public class MapActivity extends BaseActivity implements OnMapReadyCallback { -import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; -import com.uam.wmi.findmytutor.utils.PrefUtils; String tag = "LifeCycleEvents"; - private static final int REQUEST_PERMISSIONS = 100; - private boolean isTutor; private MapView mapView; @@ -169,13 +157,16 @@ import com.uam.wmi.findmytutor.utils.PrefUtils; markerAnimator.setDuration(2000); markerAnimator.start(); + // coordsMap.replace(id,element); + coordsMap.remove(id); coordsMap.put(id,element); } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ Log.d("mapper", "update"); Log.d("mapper", " "+cord.getTimeStamp()); Log.d("mapper", " " + element.getTimeStamp()); // coordsMap.replace(id,element); + coordsMap.remove(id); coordsMap.put(id,element); } } else { @@ -208,19 +199,7 @@ import com.uam.wmi.findmytutor.utils.PrefUtils; } startActivity(i); finish(); - isTutor = PrefUtils.getIsTutor(getApplicationContext()); - - if (isTutor) { - fn_permission(); - } - - mapView.getMapAsync(mapboxMap -> { - - // Customize map with markers, polylines, etc. - }); - // TODO remove logout button - configureLogoutButton(); } @@ -270,51 +249,6 @@ import com.uam.wmi.findmytutor.utils.PrefUtils; mapView.onSaveInstanceState(outState); } - private void configureLogoutButton(){ - // Logout button - final FloatingActionButton button = findViewById(R.id.logoutButton); - - button.setOnClickListener(view -> { - PrefUtils.cleanUserLocalStorage(getApplicationContext()); - - Intent i = getBaseContext().getPackageManager() - .getLaunchIntentForPackage(getBaseContext().getPackageName()); - if (i != null) { - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - } - startActivity(i); - finish(); - }); - } - - private void fn_permission() { - if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { - - if ((ActivityCompat.shouldShowRequestPermissionRationale(MapActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) { - - } else { - ActivityCompat.requestPermissions(MapActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION - - }, - REQUEST_PERMISSIONS); - } - } else { - - if (isTutor) { - Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - - } else { - Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show(); - } - } - } - @Override protected int getContentViewId() { return R.layout.activity_map; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java deleted file mode 100644 index 6af733e..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/NotificationsActivity.java +++ /dev/null @@ -1,266 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.animation.ObjectAnimator; -import android.animation.TypeEvaluator; -import android.animation.ValueAnimator; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.os.Handler; -import android.util.Log; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.model.Coordinate; -import com.uam.wmi.findmytutor.network.RetrofitClientInstance; -import com.uam.wmi.findmytutor.service.CoordinateService; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.annotations.NonNull; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableSingleObserver; -import io.reactivex.schedulers.Schedulers; - - -public class NotificationsActivity extends BaseActivity implements - OnMapReadyCallback { - - private int mInterval = 10000; - private Handler mHandler; - - private MapView mapView; - private MapboxMap mapboxMap; - private Map coordsMap = new HashMap<>(); - - private CoordinateService coordinateService; - private CompositeDisposable disposable = new CompositeDisposable(); - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // This contains the MapView in XML and needs to be called after the access token is configured. - setContentView(R.layout.activity_notifications); - - - // mapInit(savedInstanceState); - - // Mapbox access token is configured here. This needs to be called either in your application - // object or in the same activity which contains the mapview. - Mapbox.getInstance(this, getString(R.string.access_token)); - - - - mapView = findViewById(R.id.mapView2); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - - - final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); - final String authToken = sharedPref.getString("authToken",null); - - coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); - - mHandler = new Handler(); - -// fetchTopCoords(); - } - - @Override - public void onMapReady(MapboxMap map) { - mapboxMap = map; - final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .position(new LatLng(52.466782,16.927549))); - mStatusChecker.run(); - - mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - - // When the user clicks on the map, we want to animate the marker to that - // location. - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), point); - markerAnimator.setDuration(2000); - markerAnimator.start(); - } - }); - } - - - Runnable mStatusChecker = new Runnable() { - @Override - public void run() { - try{ - fetchTopCoords(); - } finally { - mHandler.postDelayed(mStatusChecker, mInterval); - } - } - }; -/* - private void mapInit(Bundle savedInstanceState) { - // Mapbox access token is configured here. This needs to be called either in your application - // object or in the same activity which contains the mapview. - Mapbox.getInstance(this, getString(R.string.access_token)); - // This contains the MapView in XML and needs to be called after the access token is configured. - // setContentView(R.layout.activity_notifications); - - mapView = (MapView) findViewById(R.id.mapView2); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(MapboxMap mapboxMap) { - - final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .position(new LatLng(52.466782,16.927549))); - - mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - - // When the user clicks on the map, we want to animate the marker to that - // location. - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), point); - markerAnimator.setDuration(2000); - markerAnimator.start(); - } - }); - - } - }); - - }*/ - - private void fetchTopCoords() { - disposable.add( -// coordinateService.getTopCoordinates() - coordinateService.getOnlineCoordinates() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List coordsList) { - - - for (Coordinate element : coordsList) { - String id = element.getUserId(); - Coordinate cord = coordsMap.get(id); - - - Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); - Log.d("mapper", "b " + coordsMap.size()); - if (cord != null) { - if (!cord.getLongitude().equals(element.getLongitude()) - ) { - Log.d("mapper", " cos sie zienilo "); - Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .title(cord.getUserId()) - .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); - - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); - markerAnimator.setDuration(2000); - markerAnimator.start(); - - coordsMap.replace(id,element); - } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ - Log.d("mapper", "update"); - Log.d("mapper", " "+cord.getTimeStamp()); - Log.d("mapper", " "+element.getTimeStamp()); - coordsMap.replace(id,element); - } - } else { - coordsMap.put(id,element); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); - } - } - } - - @Override - public void onError(Throwable e) { - Log.e("Error",e.toString()); - } - }) - ); - - } - - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - public void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - public void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - mHandler.removeCallbacks(mStatusChecker); - disposable.dispose(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - private static class LatLngEvaluator implements TypeEvaluator { - // Method is used to interpolate the marker animation. - - private LatLng latLng = new LatLng(); - - @Override - public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { - latLng.setLatitude(startValue.getLatitude() - + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); - latLng.setLongitude(startValue.getLongitude() - + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); - return latLng; - } - } - - @Override - protected int getContentViewId() { return R.layout.activity_notifications; } - - @Override - protected int getNavigationMenuItemId() { return R.id.nav_notif; } -} diff --git a/app/src/main/res/.DS_Store b/app/src/main/res/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e0e801dbbc5cc94c23e165015b8c4db8f870b1a0 GIT binary patch literal 6148 zcmeHK!A=4(5N!dm8)M{PqTYJ(#$gExCzB20!J7$24{BgH5ZPqi5?Ca-V)i@qkNg3D z$C*ZttRd|{)wDTLS(+v2X(SCdxaC*x7W zAKvI**zE<@zEmn&*nV&o_9pGp?x~6sKa6|BFX6Y>Vcb=dh8oA+k)G$mPx_GSIF4}I zrGqrBxYb%&9=p|9S*G>6Tb4)F+HB^Cy~E1MdFNsJls?a1UJbPz{z5G~7U%E=#?mey zTf;a~@jdwGIrCUTVt^PR2G*Yed-92`_1`M(kQg8ae#roy4-yp7vzQswM+Y=`eZ=ts zA_~~}mOzviJ&Tz^7y;oX70{$|`^4ZT9sJV9c@{H+CY^D;GR$LF=Jtic_3Gf4I-GIO zAhpB*F|f=)-gHY?|IdDY|1T#|j~E~Z)`|gMXttUS*pjWSE1SbwD?vM;C>WO+T%>@Z hOEJV^Dc%Rw0)B}Gpl2~N2p$l+2xuCpAqM`Gflpf - - Date: Tue, 30 Oct 2018 20:24:53 +0100 Subject: [PATCH 10/11] ds store deleted mainasctivity listview adapter --- .../uam/wmi/findmytutor/ListViewAdapter.java | 109 ----- .../findmytutor/activity/MainActivity.java | 403 ------------------ 2 files changed, 512 deletions(-) delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java delete mode 100644 app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java diff --git a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java b/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java deleted file mode 100644 index 8fd91a7..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/ListViewAdapter.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.uam.wmi.findmytutor; - -import android.app.Activity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import com.amulyakhare.textdrawable.TextDrawable; -import com.amulyakhare.textdrawable.util.ColorGenerator; - -import com.uam.wmi.findmytutor.activity.MainActivity; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -public class ListViewAdapter extends ArrayAdapter { - - - private MainActivity activity; - private List friendList; - private List searchList; - - public ListViewAdapter(MainActivity context, int resource, List objects) { - super(context, resource, objects); - this.activity = context; - this.friendList = objects; - this.searchList = new ArrayList<>(); - this.searchList.addAll(friendList); - } - - @Override - public int getCount() { - return friendList.size(); - } - - @Override - public String getItem(int position) { - return friendList.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ViewHolder holder; - LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - // If holder not exist then locate all view from UI file. - if (convertView == null) { - // inflate UI from XML file - convertView = inflater.inflate(R.layout.item_listview, parent, false); - // get all UI view - holder = new ViewHolder(convertView); - // set tag for holder - convertView.setTag(holder); - } else { - // if holder created, get tag from view - holder = (ViewHolder) convertView.getTag(); - } - - holder.friendName.setText(getItem(position)); - - //get first letter of each String item - String firstLetter = String.valueOf(getItem(position).charAt(0)); - - ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT - // generate random color - int color = generator.getColor(getItem(position)); - - TextDrawable drawable = TextDrawable.builder() - .buildRound(firstLetter, color); // radius in px - - holder.imageView.setImageDrawable(drawable); - - return convertView; - } - - // Filter method - public void filter(String charText) { - charText = charText.toLowerCase(Locale.getDefault()); - friendList.clear(); - if (charText.length() == 0) { - friendList.addAll(searchList); - } else { - for (String s : searchList) { - if (s.toLowerCase(Locale.getDefault()).contains(charText)) { - friendList.add(s); - } - } - } - notifyDataSetChanged(); - } - - private class ViewHolder { - private ImageView imageView; - private TextView friendName; - - public ViewHolder(View v) { - imageView = (ImageView) v.findViewById(R.id.image_view); - friendName = (TextView) v.findViewById(R.id.text); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java deleted file mode 100644 index 6aff006..0000000 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MainActivity.java +++ /dev/null @@ -1,403 +0,0 @@ -package com.uam.wmi.findmytutor.activity; - -import android.animation.TypeEvaluator; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.Configuration; -import android.graphics.Color; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.BottomNavigationView; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.widget.DrawerLayout; -import android.content.Context; -import android.content.SharedPreferences; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.SearchView; -import android.support.v7.widget.Toolbar; -import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; -import android.os.Handler; -import android.view.View; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.widget.FrameLayout; -import android.widget.ListView; -import android.widget.Toast; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import android.util.Log; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.uam.wmi.findmytutor.R; -import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; -import com.uam.wmi.findmytutor.utils.PrefUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.uam.wmi.findmytutor.model.Coordinate; -import com.uam.wmi.findmytutor.network.RetrofitClientInstance; -import com.uam.wmi.findmytutor.service.CoordinateService; - - -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.annotations.NonNull; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableSingleObserver; -import io.reactivex.schedulers.Schedulers; - - -public class MainActivity extends AppCompatActivity implements - OnMapReadyCallback { - - private BottomNavigationView mMainNav; - private FrameLayout mMainFrame; - private boolean isTutor; - private SharingFragment sharingFragment; - - private static final int REQUEST_PERMISSIONS = 100; - boolean boolean_permission; - - private DrawerLayout drawerLayout; - private ActionBarDrawerToggle actionBarDrawerToggle; - - private MapView mapView; - private MapboxMap mapboxMap; - private int mInterval = 10000; - private Handler mHandler; - - private Map coordsMap = new HashMap<>(); - - private CoordinateService coordinateService; - private CompositeDisposable disposable = new CompositeDisposable(); - - private Runnable mStatusChecker; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); - final String authToken = sharedPref.getString("authToken",null); - - mStatusChecker = new Runnable() { - @Override - public void run() { - try{ - fetchTopCoords(); - } finally { - mHandler.postDelayed(mStatusChecker, mInterval); - } - } - }; - - coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); - - mHandler = new Handler(); - Bundle extras = getIntent().getExtras(); - Mapbox.getInstance(this, getString(R.string.access_token)); - - - - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(this); - - configureconfigureNavigationDrawer(); - configureLogoutButton(); - - } - - @Override - public void onMapReady(MapboxMap map) { - mapboxMap = map; - final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .position(new LatLng(52.466782,16.927549))); - mStatusChecker.run(); - - mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - - // When the user clicks on the map, we want to animate the marker to that - // location. - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), point); - markerAnimator.setDuration(2000); - markerAnimator.start(); - } - }); - } - - - private void configureconfigureNavigationDrawer() { - Toolbar toolbar = findViewById(R.id.toolbar_main); - setSupportActionBar(toolbar); - - drawerLayout = findViewById(R.id.drawer_layout); - - actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawerLayout.addDrawerListener(actionBarDrawerToggle); - - ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(false); - - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); - } - } - - private void setFragment(Fragment fragment) { - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.main_frame, fragment); - fragmentTransaction.commit(); - } - - - - private void configureLogoutButton(){ - // Logout button - final FloatingActionButton button = findViewById(R.id.logoutButton); - - button.setOnClickListener(view -> { - PrefUtils.cleanUserLocalStorage(getApplicationContext()); - - Intent i = getBaseContext().getPackageManager() - .getLaunchIntentForPackage(getBaseContext().getPackageName()); - if (i != null) { - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - } - startActivity(i); - finish(); - }); - } - - @Override - public boolean onCreateOptionsMenu( Menu menu) { - getMenuInflater().inflate( R.menu.menu_main, menu); - - MenuItem myActionMenuItem = menu.findItem( R.id.action_search); - final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - return false; - } - - @Override - public boolean onQueryTextChange(String newText) { - if (TextUtils.isEmpty(newText)) { -// adapter.filter(""); -// listView.clearTextFilter(); - } else { -// adapter.filter(newText); - } - - return true; - } - }); - - return true; - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - - actionBarDrawerToggle.syncState(); - - if (isTutor) { - fn_permission(); - } - - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - actionBarDrawerToggle.onConfigurationChanged(newConfig); - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (actionBarDrawerToggle.onOptionsItemSelected(item)) { - return true; - } - return super.onOptionsItemSelected(item); - - } - - - private void fn_permission() { - if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { - - if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) { - - } else { - ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION - - }, - REQUEST_PERMISSIONS); - } - } else { - - if (isTutor) { - Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(intent); - } else { - startService(intent); - } - - } else { - Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show(); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - - switch (requestCode) { - case REQUEST_PERMISSIONS: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - boolean_permission = true; - } else { - Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show(); - } - } - } - } - - private static class LatLngEvaluator implements TypeEvaluator { - // Method is used to interpolate the marker animation. - - private LatLng latLng = new LatLng(); - - @Override - public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { - latLng.setLatitude(startValue.getLatitude() - + ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); - latLng.setLongitude(startValue.getLongitude() - + ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); - return latLng; - } - } - - private void fetchTopCoords() { - disposable.add( - // coordinateService.getTopCoordinates() - coordinateService.getOnlineCoordinates() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List coordsList) { - - - for (Coordinate element : coordsList) { - String id = element.getUserId(); - Coordinate cord = coordsMap.get(id); - - - Log.d("mapper", "a " + mapboxMap.getMarkerViewManager()); - Log.d("mapper", "b " + coordsMap.size()); - if (cord != null) { - if (!cord.getLongitude().equals(element.getLongitude()) - ) { - Log.d("mapper", " cos sie zienilo "); - Marker marker = mapboxMap.addMarker(new MarkerViewOptions() - .title(cord.getUserId()) - .position(new LatLng(cord.getLatitude(),cord.getLongitude()))); - - ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", - new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude())); - markerAnimator.setDuration(2000); - markerAnimator.start(); - - coordsMap.replace(id,element); - } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){ - Log.d("mapper", "update"); - Log.d("mapper", " "+cord.getTimeStamp()); - Log.d("mapper", " "+element.getTimeStamp()); - coordsMap.replace(id,element); - } - } else { - coordsMap.put(id,element); - mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); - } - } - } - - @Override - public void onError(Throwable e) { - Log.e("Error",e.toString()); - } - }) - ); - - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - public void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - public void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - mHandler.removeCallbacks(mStatusChecker); - disposable.dispose(); - } -} - - -- 2.20.1 From 2d9e041b6bede13be4e3e1c4f704ac66c58c4048 Mon Sep 17 00:00:00 2001 From: Adam Domagalski Date: Tue, 30 Oct 2018 20:25:16 +0100 Subject: [PATCH 11/11] clean up --- .DS_Store | Bin 6148 -> 0 bytes app/src/main/AndroidManifest.xml | 4 --- .../findmytutor/activity/BaseActivity.java | 26 ++---------------- app/src/main/res/.DS_Store | Bin 6148 -> 0 bytes 4 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 .DS_Store delete mode 100644 app/src/main/res/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 0d8080cbf6dc254973dab74f2064ab5348fa3552..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK-D=c86h6~k+pMc}g+l9HZUis3vIW~Mh_I~nqIbfIUZ}K56Wc(V2}#zaT~~7B zJE(8qqxb|qh!3FOnHeQXt#~D(b71D1pYxORB{P#DA~Bu@TSPq~a!?rCS5f^$c%I7z zSu!JCpkN>J$d9Fu9=o$*8L$le?F{hRZIMSQrTcMh{ocdO?XOBy5=P6P<*8ZapZqkA z@?tRfES6gBE6Xd6<8+%V`qi%FiROIDu`a({VZny^Z;NdpPX7cXxLdeRn<_4*Kr)U}v%D zIP15z?(ZL-o}JHMFW$V@Z$V&_QnG6BJA6RHr1xr)C9zD7F~Zu{$fqeq6jMNV=$JB4 z6`&V3$odG~Dp@z_C9D$YZqg~8p)TO3APEnf@WC?~dXe%QK_{+z6zdI-%a=zNZyUNd zs=9dYRK-du1Qv)HQr?L6rQuIwjCV^|5=>gONm@&IsTu+)eVh|s1$Z7R$aLzugR(B_yQ8U0eDHYcGX!;gt9%ne1D ztA}uvI*E}+TU!P!19b*ky4&OP|Ka8L|GJUwSq3Zv{}cnFy*Jq#BPDaTUPzA5S{LOI rg@yG>jmiX-IgV9>kKzp!C75%$0UQ}DHDUx}e*_c_wz3TTQ3k#Ng#Fb$ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ec7431..f29338f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,10 +43,6 @@ - stringArrayList; - private ListViewAdapter adapter; private SharingFragment sharingFragment; private static final int REQUEST_PERMISSIONS = 100; @@ -87,23 +84,6 @@ public abstract class BaseActivity toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } - private void setData() { - stringArrayList = new ArrayList<>(); - stringArrayList.add("Quynh Trang"); - stringArrayList.add("Hoang Bien"); - stringArrayList.add("Duc Tuan"); - stringArrayList.add("Dang Thanh"); - stringArrayList.add("Xuan Luu"); - stringArrayList.add("Phan Thanh"); - stringArrayList.add("Kim Kien"); - stringArrayList.add("Ngo Trang"); - stringArrayList.add("Thanh Ngan"); - stringArrayList.add("Nguyen Duong"); - stringArrayList.add("Quoc Cuong"); - stringArrayList.add("Tran Ha"); - stringArrayList.add("Vu Danh"); - stringArrayList.add("Minh Meo"); - } private void setUpNav() { @@ -186,10 +166,10 @@ public abstract class BaseActivity @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { - adapter.filter(""); - listView.clearTextFilter(); + //adapter.filter(""); + //listView.clearTextFilter(); } else { - adapter.filter(newText); + //adapter.filter(newText); } return true; } diff --git a/app/src/main/res/.DS_Store b/app/src/main/res/.DS_Store deleted file mode 100644 index e0e801dbbc5cc94c23e165015b8c4db8f870b1a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A=4(5N!dm8)M{PqTYJ(#$gExCzB20!J7$24{BgH5ZPqi5?Ca-V)i@qkNg3D z$C*ZttRd|{)wDTLS(+v2X(SCdxaC*x7W zAKvI**zE<@zEmn&*nV&o_9pGp?x~6sKa6|BFX6Y>Vcb=dh8oA+k)G$mPx_GSIF4}I zrGqrBxYb%&9=p|9S*G>6Tb4)F+HB^Cy~E1MdFNsJls?a1UJbPz{z5G~7U%E=#?mey zTf;a~@jdwGIrCUTVt^PR2G*Yed-92`_1`M(kQg8ae#roy4-yp7vzQswM+Y=`eZ=ts zA_~~}mOzviJ&Tz^7y;oX70{$|`^4ZT9sJV9c@{H+CY^D;GR$LF=Jtic_3Gf4I-GIO zAhpB*F|f=)-gHY?|IdDY|1T#|j~E~Z)`|gMXttUS*pjWSE1SbwD?vM;C>WO+T%>@Z hOEJV^Dc%Rw0)B}Gpl2~N2p$l+2xuCpAqM`Gflpf