diff --git a/.travis.yml b/.travis.yml index 0aa80c4..b1672a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,8 @@ android: before_install: - yes | sdkmanager "platforms;android-$ANDROID_API_LEVEL" + - sudo apt-get install jq + - wget -O ~/codacy-coverage-reporter-assembly-latest.jar $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r .assets[0].browser_download_url) # Emulator Management: Create, Start and Wait before_script: @@ -59,3 +61,5 @@ script: after_success: - bash <(curl -s https://codecov.io/bash) + - java -cp ~/codacy-coverage-reporter-assembly-latest.jar com.codacy.CodacyCoverageReporter -l Java -r ./app/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacocoTestDebugUnitTestReport.xml + diff --git a/README.md b/README.md index 3100f51..50650c7 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Download the beta from Google Play. ## What's the build status? -[![Build Status](https://travis-ci.org/Teester/Whats-Nearby.svg?branch=master)](https://travis-ci.org/Teester/Whats-Nearby) [![codecov](https://codecov.io/gh/Teester/Whats-Nearby/branch/master/graph/badge.svg)](https://codecov.io/gh/Teester/Whats-Nearby) +[![Build Status](https://travis-ci.org/Teester/Whats-Nearby.svg?branch=master)](https://travis-ci.org/Teester/Whats-Nearby) [![codecov](https://codecov.io/gh/Teester/Whats-Nearby/branch/master/graph/badge.svg)](https://codecov.io/gh/Teester/Whats-Nearby) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6635ff22c9b240f79c6472dfd66b594e)](https://www.codacy.com/app/Teester/Whats-Nearby?utm_source=github.com&utm_medium=referral&utm_content=Teester/Whats-Nearby&utm_campaign=Badge_Grade) ## What's done - Basic location determination and notification logic diff --git a/app/build.gradle b/app/build.gradle index 9ab8983..d10a347 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId 'com.teester.whatsnearby' minSdkVersion 21 targetSdkVersion 27 - versionCode 12 - versionName "0.12" + versionCode 13 + versionName "0.13" setProperty("archivesBaseName", "whatsnearby-$versionName") testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -34,13 +34,16 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:27.0.2' - implementation 'com.android.support:design:27.0.2' - implementation 'com.android.support:support-v4:27.0.2' + implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'com.android.support:design:27.1.0' + implementation 'com.android.support:support-v4:27.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'android.arch.lifecycle:extensions:1.1.0' implementation 'android.arch.persistence.room:runtime:1.0.0' @@ -57,6 +60,7 @@ dependencies { } androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + androidTestImplementation 'android.arch.core:core-testing:1.1.0' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.11.0' diff --git a/app/src/androidTest/java/com/teester/whatsnearby/DatabaseInstrumentedTest.java b/app/src/androidTest/java/com/teester/whatsnearby/DatabaseInstrumentedTest.java new file mode 100644 index 0000000..36ab972 --- /dev/null +++ b/app/src/androidTest/java/com/teester/whatsnearby/DatabaseInstrumentedTest.java @@ -0,0 +1,95 @@ +package com.teester.whatsnearby; + +import android.arch.core.executor.testing.InstantTaskExecutorRule; +import android.arch.persistence.room.Room; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import com.teester.whatsnearby.data.OsmObject; +import com.teester.whatsnearby.data.database.AppDatabase; +import com.teester.whatsnearby.data.database.VisitedLocation; +import com.teester.whatsnearby.data.database.VisitedLocationDao; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.List; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.assertTrue; + +@RunWith(AndroidJUnit4.class) +public class DatabaseInstrumentedTest { + + @Rule + public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); + + private AppDatabase mDatabase; + private VisitedLocationDao visitedLocationDao; + private OsmObject osmObject = new OsmObject(1, "", "1", "", 1, 1, 1); + private OsmObject osmObject2 = new OsmObject(2, "", "2", "", 1, 1, 1); + private OsmObject osmObject3 = new OsmObject(3, "", "3", "", 1, 1, 1); + private OsmObject osmObject4 = new OsmObject(4, "", "4", "", 1, 1, 1); + private OsmObject osmObject5 = new OsmObject(5, "", "5", "", 1, 1, 1); + + @Before + public void initDb() throws Exception { + mDatabase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), + AppDatabase.class) + .allowMainThreadQueries() + .build(); + + visitedLocationDao = mDatabase.visitedLocationDao(); + } + + @After + public void closeDb() throws Exception { + mDatabase.close(); + } + + @Test + public void onFetchingLocationsShouldGetEmptyListIfTableIsEmpty() throws InterruptedException { + List LocationList = visitedLocationDao.getAllVisitedLocations(); + assertTrue(LocationList.isEmpty()); + } + + @Test + public void onInsertingLocationsCheckIfRowCountIsCorrect() throws InterruptedException { + visitedLocationDao.insert(new VisitedLocation(osmObject)); + visitedLocationDao.insert(new VisitedLocation(osmObject2)); + visitedLocationDao.insert(new VisitedLocation(osmObject3)); + visitedLocationDao.insert(new VisitedLocation(osmObject4)); + visitedLocationDao.insert(new VisitedLocation(osmObject5)); + + assertEquals(5, visitedLocationDao.getAllVisitedLocations().size()); + } + + @Test + public void onUpdatingALocationCheckIfUpdateHappensCorrectly() throws InterruptedException { + VisitedLocation visitedLocation = new VisitedLocation(osmObject); + visitedLocationDao.insert(visitedLocation); + + visitedLocation = visitedLocationDao.findByOsmId(osmObject.getId()); + visitedLocation.setName("New Name"); + visitedLocationDao.update(visitedLocation); + + assertEquals(1, visitedLocationDao.getAllVisitedLocations().size()); + assertEquals("New Name", visitedLocationDao.findByOsmId(osmObject.getId()).getName()); + } + + @Test + public void onLocationDeletionCheckIfLocationIsDeletedFromTable() { + visitedLocationDao.insert(new VisitedLocation(osmObject)); + visitedLocationDao.insert(new VisitedLocation(osmObject2)); + visitedLocationDao.insert(new VisitedLocation(osmObject3)); + visitedLocationDao.insert(new VisitedLocation(osmObject4)); + visitedLocationDao.insert(new VisitedLocation(osmObject5)); + + visitedLocationDao.delete(visitedLocationDao.findByOsmId(osmObject2.getId())); + assertNull(visitedLocationDao.findByOsmId(osmObject2.getId())); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aa1b3c5..fbd46d7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + @@ -31,18 +32,22 @@ android:scheme="mapquestions"/> - + - + + + \ No newline at end of file diff --git a/app/src/main/java/com/teester/whatsnearby/BasePresenter.java b/app/src/main/java/com/teester/whatsnearby/BasePresenter.java deleted file mode 100644 index 32abaad..0000000 --- a/app/src/main/java/com/teester/whatsnearby/BasePresenter.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.teester.whatsnearby; - -public interface BasePresenter { - - void init(); - - void destroy(); - -} diff --git a/app/src/main/java/com/teester/whatsnearby/BaseView.java b/app/src/main/java/com/teester/whatsnearby/BaseView.java deleted file mode 100644 index 64aabe7..0000000 --- a/app/src/main/java/com/teester/whatsnearby/BaseView.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.teester.whatsnearby; - -public interface BaseView { - - void setPresenter(T presenter); -} diff --git a/app/src/main/java/com/teester/whatsnearby/Startup.java b/app/src/main/java/com/teester/whatsnearby/Startup.java index bad668e..5237e1f 100644 --- a/app/src/main/java/com/teester/whatsnearby/Startup.java +++ b/app/src/main/java/com/teester/whatsnearby/Startup.java @@ -1,17 +1,26 @@ package com.teester.whatsnearby; +import android.app.job.JobInfo; +import android.app.job.JobScheduler; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import com.teester.whatsnearby.data.location.LocationService; +import com.teester.whatsnearby.data.location.LocationJobService; public class Startup extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction() == Intent.ACTION_BOOT_COMPLETED) { - context.startService(new Intent(context, LocationService.class)); + + JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); + ComponentName jobService = new ComponentName(context.getPackageName(), LocationJobService.class.getName()); + JobInfo jobInfo = new JobInfo.Builder(1, jobService) + .setPeriodic(60000) + .build(); + jobScheduler.schedule(jobInfo); } } } diff --git a/app/src/main/java/com/teester/whatsnearby/Utilities.java b/app/src/main/java/com/teester/whatsnearby/Utilities.java index 968f7b1..a841bd1 100644 --- a/app/src/main/java/com/teester/whatsnearby/Utilities.java +++ b/app/src/main/java/com/teester/whatsnearby/Utilities.java @@ -35,22 +35,22 @@ public static Map> splitQuery(URI url) throws UnsupportedEn /** * Calculates the distance, in metres, between two points * - * @param lat1 - latitude of location 1 - * @param lon1 - longitude of location 1 - * @param lat2 - latitude of location 2 - * @param lon2 - longitude of location 2 + * @param latitude1 - latitude of location 1 + * @param longitude1 - longitude of location 1 + * @param latitude2 - latitude of location 2 + * @param longitude2 - longitude of location 2 * @return - distance between location 1 and 2 */ - public static float computeDistance(double lat1, double lon1, double lat2, double lon2) { + public static float computeDistance(double latitude1, double longitude1, double latitude2, double longitude2) { // Based on http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf // using the "Inverse Formula" (section 4) int MAXITERS = 20; // Convert lat/long to radians - lat1 *= Math.PI / 180.0; - lat2 *= Math.PI / 180.0; - lon1 *= Math.PI / 180.0; - lon2 *= Math.PI / 180.0; + double lat1 = latitude1 * (Math.PI / 180.0); + double lat2 = latitude2 * (Math.PI / 180.0); + double lon1 = longitude1 * (Math.PI / 180.0); + double lon2 = longitude2 * (Math.PI / 180.0); double a = 6378137.0; // WGS84 major axis double b = 6356752.3142; // WGS84 semi-major axis diff --git a/app/src/main/java/com/teester/whatsnearby/data/Answers.java b/app/src/main/java/com/teester/whatsnearby/data/Answers.java index 7c4274a..62741fc 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/Answers.java +++ b/app/src/main/java/com/teester/whatsnearby/data/Answers.java @@ -10,9 +10,6 @@ public class Answers { private static Answers INSTANCE; private static OsmObject osmObject; - private static int id; - private static String name; - private static String objectType; private static Map answerMap = new HashMap<>(); private static Map changesetTags; diff --git a/app/src/main/java/com/teester/whatsnearby/data/OsmObject.java b/app/src/main/java/com/teester/whatsnearby/data/OsmObject.java index 667e445..46f7a68 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/OsmObject.java +++ b/app/src/main/java/com/teester/whatsnearby/data/OsmObject.java @@ -1,5 +1,7 @@ package com.teester.whatsnearby.data; +import com.teester.whatsnearby.data.pois.PoiContract; + import java.util.HashMap; import java.util.Map; @@ -61,7 +63,7 @@ public String getTag(String key) { } public int getDrawable() { - OsmObjectType objectType = PoiTypes.getPoiType(this.type); + PoiContract objectType = PoiTypes.getPoiType(this.type); int drawable = objectType.getObjectIcon(); return drawable; } diff --git a/app/src/main/java/com/teester/whatsnearby/data/PoiTypes.java b/app/src/main/java/com/teester/whatsnearby/data/PoiTypes.java index 0be8730..a2c3cb3 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/PoiTypes.java +++ b/app/src/main/java/com/teester/whatsnearby/data/PoiTypes.java @@ -1,6 +1,46 @@ package com.teester.whatsnearby.data; -import com.teester.whatsnearby.R; +import com.teester.whatsnearby.data.pois.AmenityBank; +import com.teester.whatsnearby.data.pois.AmenityBar; +import com.teester.whatsnearby.data.pois.AmenityCafe; +import com.teester.whatsnearby.data.pois.AmenityCinema; +import com.teester.whatsnearby.data.pois.AmenityDentist; +import com.teester.whatsnearby.data.pois.AmenityDoctors; +import com.teester.whatsnearby.data.pois.AmenityFastFood; +import com.teester.whatsnearby.data.pois.AmenityFuel; +import com.teester.whatsnearby.data.pois.AmenityPharmacy; +import com.teester.whatsnearby.data.pois.AmenityPub; +import com.teester.whatsnearby.data.pois.AmenityRestaurant; +import com.teester.whatsnearby.data.pois.Poi; +import com.teester.whatsnearby.data.pois.PoiContract; +import com.teester.whatsnearby.data.pois.ShopAlcohol; +import com.teester.whatsnearby.data.pois.ShopBakery; +import com.teester.whatsnearby.data.pois.ShopBeauty; +import com.teester.whatsnearby.data.pois.ShopBicycle; +import com.teester.whatsnearby.data.pois.ShopButcher; +import com.teester.whatsnearby.data.pois.ShopCar; +import com.teester.whatsnearby.data.pois.ShopCarRepair; +import com.teester.whatsnearby.data.pois.ShopChemist; +import com.teester.whatsnearby.data.pois.ShopClothes; +import com.teester.whatsnearby.data.pois.ShopConvenience; +import com.teester.whatsnearby.data.pois.ShopCosmetics; +import com.teester.whatsnearby.data.pois.ShopDepartmentStore; +import com.teester.whatsnearby.data.pois.ShopDoItYourself; +import com.teester.whatsnearby.data.pois.ShopFlorist; +import com.teester.whatsnearby.data.pois.ShopFurniture; +import com.teester.whatsnearby.data.pois.ShopHairdresser; +import com.teester.whatsnearby.data.pois.ShopJewelry; +import com.teester.whatsnearby.data.pois.ShopLaundry; +import com.teester.whatsnearby.data.pois.ShopMobilePhone; +import com.teester.whatsnearby.data.pois.ShopOptician; +import com.teester.whatsnearby.data.pois.ShopPerfumery; +import com.teester.whatsnearby.data.pois.ShopPhoto; +import com.teester.whatsnearby.data.pois.ShopShoes; +import com.teester.whatsnearby.data.pois.ShopSports; +import com.teester.whatsnearby.data.pois.ShopStationary; +import com.teester.whatsnearby.data.pois.ShopSupermarket; +import com.teester.whatsnearby.data.pois.ShopVariety; +import com.teester.whatsnearby.data.pois.ShopVeterinary; import java.util.HashMap; import java.util.Map; @@ -12,92 +52,48 @@ public class PoiTypes { private static PoiTypes INSTANCE; - //Amenities - private OsmObjectType bank = new OsmObjectType("bank", "amenity", R.drawable.ic_bank, new String[]{"wheelchair"}); - private OsmObjectType bar = new OsmObjectType("bar", "amenity", R.drawable.ic_bar, new String[]{"wheelchair", "outdoor_seating", "wifi", "wifi_fee", "cash", "cheques", "credit_card", "debit_card", "contactless", "wheelchair_toilets"}); - private OsmObjectType cafe = new OsmObjectType("cafe", "amenity", R.drawable.ic_cafe, new String[]{"wheelchair", "outdoor_seating", "wifi", "wifi_fee", "cash", "cheques", "credit_card", "debit_card", "contactless", "wheelchair_toilets"}); - private OsmObjectType cinema = new OsmObjectType("cinema", "amenity", R.drawable.ic_cinema, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless", "wheelchair_toilets"}); - private OsmObjectType dentist = new OsmObjectType("dentist", "amenity", R.drawable.ic_dentist, new String[]{"wheelchair"}); - private OsmObjectType doctors = new OsmObjectType("doctors", "amenity", R.drawable.ic_doctors, new String[]{"wheelchair"}); - private OsmObjectType fast_food = new OsmObjectType("fast_food", "amenity", R.drawable.ic_fast_food, new String[]{"wheelchair", "wheelchair_toilets", "drive_through", "takeaway", "deliver", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType fuel = new OsmObjectType("fuel", "amenity", R.drawable.ic_fuel, new String[]{"wheelchair", "wheelchair_toilets", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType pharmacy = new OsmObjectType("pharmacy", "amenity", R.drawable.ic_pharmacy, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless", "dispensing"}); - private OsmObjectType pub = new OsmObjectType("pub", "amenity", R.drawable.ic_pub, new String[]{"wheelchair", "outdoor_seating", "wifi", "wifi_fee", "cash", "cheques", "credit_card", "debit_card", "contactless", "wheelchair_toilets"}); - private OsmObjectType restaurant = new OsmObjectType("restaurant", "amenity", R.drawable.ic_restaurant, new String[]{"wheelchair", "wheelchair_toilets", "wifi", "wifi_fee", "outdoor_seating", "vegetarian", "vegan", "takeaway", "deliver", "reservation", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - //Shops - private OsmObjectType alcohol = new OsmObjectType("alcohol", "shop", R.drawable.ic_alcohol, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType bakery = new OsmObjectType("bakery", "shop", R.drawable.ic_bakery, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType beauty = new OsmObjectType("beauty", "shop", R.drawable.ic_beauty, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType bicycle = new OsmObjectType("bicycle", "shop", R.drawable.ic_bicycle, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType butcher = new OsmObjectType("butcher", "shop", R.drawable.ic_butcher, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless", "halal", "kosher", "organic"}); - private OsmObjectType car = new OsmObjectType("car", "shop", R.drawable.ic_car, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card"}); - private OsmObjectType car_repair = new OsmObjectType("car_repair", "shop", R.drawable.ic_car_repair, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType chemist = new OsmObjectType("chemist", "shop", R.drawable.ic_chemist, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType clothes = new OsmObjectType("clothes", "shop", R.drawable.ic_clothes, new String[]{"wheelchair", "men", "women", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType convenience = new OsmObjectType("convenience", "shop", R.drawable.ic_convenience, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType cosmetics = new OsmObjectType("cosmetics", "shop", R.drawable.ic_cosmetics, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType department_store = new OsmObjectType("department_store", "shop", R.drawable.ic_department_store, new String[]{"wheelchair", "wheelchair_toilets", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType doityourself = new OsmObjectType("doityourself", "shop", R.drawable.ic_doityourself, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType florist = new OsmObjectType("florist", "shop", R.drawable.ic_florist, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType furniture = new OsmObjectType("furniture", "shop", R.drawable.ic_furniture, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType hairdresser = new OsmObjectType("hairdresser", "shop", R.drawable.ic_hairdresser, new String[]{"wheelchair", "men", "women", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType jewelry = new OsmObjectType("jewelry", "shop", R.drawable.ic_jewelry, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType laundry = new OsmObjectType("laundry", "shop", R.drawable.ic_laundry, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType mobile_phone = new OsmObjectType("mobile_phone", "shop", R.drawable.ic_mobile_phone, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType optician = new OsmObjectType("optician", "shop", R.drawable.ic_optician, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType perfumery = new OsmObjectType("perfumery", "shop", R.drawable.ic_perfumery, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType photo = new OsmObjectType("photo", "shop", R.drawable.ic_photo, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType shoes = new OsmObjectType("shoes", "shop", R.drawable.ic_shoes, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType sports = new OsmObjectType("sports", "shop", R.drawable.ic_sports, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType stationary = new OsmObjectType("stationary", "shop", R.drawable.ic_stationery, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType supermarket = new OsmObjectType("supermarket", "shop", R.drawable.ic_supermarket, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless", "organic"}); - private OsmObjectType variety = new OsmObjectType("variety", "shop", R.drawable.ic_variety_store, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private OsmObjectType veterinary = new OsmObjectType("veterinary", "shop", R.drawable.ic_veterinary, new String[]{"wheelchair", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - //Tourism - private OsmObjectType hotel = new OsmObjectType("hotel", "tourism", R.drawable.ic_hotel, new String[]{"wheelchair", "wheelchair_toilets", "wifi", "wifi_fee", "cash", "cheques", "credit_card", "debit_card", "contactless"}); - private Map map = new HashMap<>(); + private Map map = new HashMap<>(); private PoiTypes() { - map.put("alcohol", this.alcohol); - map.put("bakery", this.bakery); - map.put("bank", this.bank); - map.put("bar", this.bar); - map.put("beauty", this.beauty); - map.put("bicycle", this.bicycle); - map.put("butcher", this.butcher); - map.put("cafe", this.cafe); - map.put("car", this.car); - map.put("car_repair", this.car_repair); - map.put("chemist", this.chemist); - map.put("cinema", this.cinema); - map.put("clothes", this.clothes); - map.put("convenience", this.convenience); - map.put("cosmetics", this.cosmetics); - map.put("dentist", this.dentist); - map.put("department_store", this.department_store); - map.put("doctors", this.doctors); - map.put("doityourself", this.doityourself); - map.put("fast_food", this.fast_food); - map.put("florist", this.florist); - map.put("fuel", this.fuel); - map.put("furniture", this.furniture); - map.put("hairdresser", this.hairdresser); - map.put("hotel", this.hotel); - map.put("jewelry", this.jewelry); - map.put("laundry", this.laundry); - map.put("mobile_phone", this.mobile_phone); - map.put("optician", this.mobile_phone); - map.put("perfumery", this.perfumery); - map.put("pharmacy", this.pharmacy); - map.put("photo", this.photo); - map.put("pub", this.pub); - map.put("restaurant", this.restaurant); - map.put("shoes", this.shoes); - map.put("sports", this.sports); - map.put("stationary", this.stationary); - map.put("supermarket", this.supermarket); - map.put("variety", this.variety); - map.put("veterinary", this.veterinary); + map.put("alcohol", new ShopAlcohol()); + map.put("bakery", new ShopBakery()); + map.put("bank", new AmenityBank()); + map.put("bar", new AmenityBar()); + map.put("beauty", new ShopBeauty()); + map.put("bicycle", new ShopBicycle()); + map.put("butcher", new ShopButcher()); + map.put("cafe", new AmenityCafe()); + map.put("car", new ShopCar()); + map.put("car_repair", new ShopCarRepair()); + map.put("chemist", new ShopChemist()); + map.put("cinema", new AmenityCinema()); + map.put("clothes", new ShopClothes()); + map.put("convenience", new ShopConvenience()); + map.put("cosmetics", new ShopCosmetics()); + map.put("dentist", new AmenityDentist()); + map.put("department_store", new ShopDepartmentStore()); + map.put("doctors", new AmenityDoctors()); + map.put("doityourself", new ShopDoItYourself()); + map.put("fast_food", new AmenityFastFood()); + map.put("florist", new ShopFlorist()); + map.put("fuel", new AmenityFuel()); + map.put("furniture", new ShopFurniture()); + map.put("hairdresser", new ShopHairdresser()); + map.put("jewelry", new ShopJewelry()); + map.put("laundry", new ShopLaundry()); + map.put("mobile_phone", new ShopMobilePhone()); + map.put("optician", new ShopOptician()); + map.put("perfumery", new ShopPerfumery()); + map.put("pharmacy", new AmenityPharmacy()); + map.put("photo", new ShopPhoto()); + map.put("pub", new AmenityPub()); + map.put("restaurant", new AmenityRestaurant()); + map.put("shoes", new ShopShoes()); + map.put("sports", new ShopSports()); + map.put("stationary", new ShopStationary()); + map.put("supermarket", new ShopSupermarket()); + map.put("variety", new ShopVariety()); + map.put("veterinary", new ShopVeterinary()); } private static synchronized PoiTypes getInstance() { @@ -107,7 +103,7 @@ private static synchronized PoiTypes getInstance() { return INSTANCE; } - public static OsmObjectType getPoiType(String type) { + public static PoiContract getPoiType(String type) { getInstance(); return INSTANCE.map.get(type); } diff --git a/app/src/main/java/com/teester/whatsnearby/data/PreferenceList.java b/app/src/main/java/com/teester/whatsnearby/data/PreferenceList.java new file mode 100644 index 0000000..14550bf --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/PreferenceList.java @@ -0,0 +1,29 @@ +package com.teester.whatsnearby.data; + +/** + * A list of the preferences values used throughout the app + */ + +public class PreferenceList { + + public final static String OAUTH_TOKEN = "oauth_token"; + public final static String OAUTH_TOKEN_SECRET = "oauth_token_secret"; + public final static String OAUTH_VERIFIER = "oauth_verifier"; + public final static String LOGGED_IN_TO_OSM = "logged_in_to_osm"; + public final static String DEBUG_MODE = "debug_mode"; + public final static String LAST_QUERY = "last_query"; + public final static String LAST_QUERY_TIME = "last_query_time"; + public final static String DISTANCE_TO_LAST_LOCATION = "distance_to_last_location"; + public final static String LAST_NOTIFICATION_TIME = "last_notification_time"; + public final static String DISTANCE_TO_LAST_QUERY = "distance_to_last_query"; + public final static String LOCATION_ACCURACY = "location_accuracy"; + public final static String LATITUDE = "latitude"; + public final static String LONGITUDE = "longitude"; + public final static String QUERY_INTERVAL = "query_interval"; + public final static String LAST_OVERPASS_QUERY_TIME = "last_overpass_query_time"; + public final static String LAST_LOCATION_LATITUDE = "last_location_latitude"; + public final static String LAST_LOCATION_LONGITUDE = "last_location_longitude"; + public final static String LAST_QUERY_LOCATION_LATITUDE = "last_query_location_latitude"; + public final static String LAST_QUERY_LOCATION_LONGITUDE = "last_query_location_longitude"; + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/QuestionObject.java b/app/src/main/java/com/teester/whatsnearby/data/QuestionObject.java deleted file mode 100644 index c5df7da..0000000 --- a/app/src/main/java/com/teester/whatsnearby/data/QuestionObject.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.teester.whatsnearby.data; - -/** - * Details about the specific question - */ - -public class QuestionObject { - - private int id; - private int question; - private int icon; - private int color; - private String tag; - private String answer_yes; - private String answer_no; - private String answer_unsure; - - public QuestionObject(int id, int question, int icon, int color, String tag, String answer_yes, String answer_no, String answer_unsure) { - this.id = id; - this.question = question; - this.icon = icon; - this.color = color; - this.tag = tag; - this.answer_yes = answer_yes; - this.answer_no = answer_no; - this.answer_unsure = answer_unsure; - } - - public String getTag() { - return tag; - } - - public void setTag(String tag) { - this.tag = tag; - } - - public String getAnswer_yes() { - return answer_yes; - } - - public void setAnswer_yes(String answer_yes) { - this.answer_yes = answer_yes; - } - - public String getAnswer_no() { - return answer_no; - } - - public void setAnswer_no(String answer_no) { - this.answer_no = answer_no; - } - - public String getAnswer_unsure() { - return answer_unsure; - } - - public void setAnswer_unsure(String answer_unsure) { - this.answer_unsure = answer_unsure; - } - - public int getId() { - return this.id; - } - - public int getQuestion() { - return this.question; - } - - public int getIcon() { - return this.icon; - } - - public int getColor() { - return this.color; - } - - public String getAnswer(String response) { - String answer; - switch (response) { - case "yes": - answer = this.answer_yes; - break; - case "no": - answer = this.answer_no; - break; - case "unsure": - answer = this.answer_unsure; - break; - default: - answer = ""; - } - return answer; - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/data/Questions.java b/app/src/main/java/com/teester/whatsnearby/data/Questions.java index 87ce765..ce8dbe8 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/Questions.java +++ b/app/src/main/java/com/teester/whatsnearby/data/Questions.java @@ -1,6 +1,28 @@ package com.teester.whatsnearby.data; -import com.teester.whatsnearby.R; +import com.teester.whatsnearby.data.questions.Cash; +import com.teester.whatsnearby.data.questions.Cheque; +import com.teester.whatsnearby.data.questions.Contactless; +import com.teester.whatsnearby.data.questions.CreditCard; +import com.teester.whatsnearby.data.questions.DebitCard; +import com.teester.whatsnearby.data.questions.Deliver; +import com.teester.whatsnearby.data.questions.Dispensing; +import com.teester.whatsnearby.data.questions.DriveThrough; +import com.teester.whatsnearby.data.questions.Halal; +import com.teester.whatsnearby.data.questions.Kosher; +import com.teester.whatsnearby.data.questions.Men; +import com.teester.whatsnearby.data.questions.Organic; +import com.teester.whatsnearby.data.questions.OutdoorSeating; +import com.teester.whatsnearby.data.questions.Question; +import com.teester.whatsnearby.data.questions.Reservation; +import com.teester.whatsnearby.data.questions.Takeaway; +import com.teester.whatsnearby.data.questions.Vegan; +import com.teester.whatsnearby.data.questions.Vegetarian; +import com.teester.whatsnearby.data.questions.Wheelchair; +import com.teester.whatsnearby.data.questions.WheelchairToilets; +import com.teester.whatsnearby.data.questions.Wifi; +import com.teester.whatsnearby.data.questions.WifiFee; +import com.teester.whatsnearby.data.questions.Women; import java.util.HashMap; import java.util.Map; @@ -12,55 +34,32 @@ public class Questions { private static Questions INSTANCE; - private QuestionObject cash = new QuestionObject(13, R.string.cash, R.drawable.ic_money, R.color.green, "payment:cash", "yes", "no", ""); - private QuestionObject cheques = new QuestionObject(14, R.string.cheques, R.drawable.ic_check, R.color.green, "payment:cheque", "yes", "no", ""); - private QuestionObject contactless = new QuestionObject(17, R.string.contactless, R.drawable.ic_credit_card, R.color.green, "payment:contactless", "yes", "no", ""); - private QuestionObject credit_card = new QuestionObject(15, R.string.credit_card, R.drawable.ic_credit_card, R.color.green, "payment:credit_cards", "yes", "no", ""); - private QuestionObject debit_card = new QuestionObject(16, R.string.debit_card, R.drawable.ic_credit_card, R.color.green, "payment:debit_cards", "yes", "no", ""); - private QuestionObject deliver = new QuestionObject(11, R.string.deliver, R.drawable.ic_delivery_man, R.color.purple, "delivery", "yes", "no", ""); - private QuestionObject dispensing = new QuestionObject(18, R.string.dispensing, R.drawable.ic_drugs, R.color.cyan, "dispensing", "yes", "no", ""); - private QuestionObject drive_through = new QuestionObject(9, R.string.drive_through, R.drawable.ic_drive_through, R.color.purple, "drive_through", "yes", "no", ""); - private QuestionObject halal = new QuestionObject(18, R.string.halal, R.drawable.ic_halal, R.color.red, "butcher", "halal", "", ""); - private QuestionObject kosher = new QuestionObject(18, R.string.kosher, R.drawable.ic_kosher, R.color.red, "butcher", "kosher", "", ""); - private QuestionObject men = new QuestionObject(7, R.string.men, R.drawable.ic_men, R.color.red, "men", "yes", "no", ""); - private QuestionObject organic = new QuestionObject(7, R.string.organic, R.drawable.ic_carrot, R.color.red, "organic", "yes", "no", ""); - private QuestionObject outdoor_seating = new QuestionObject(2, R.string.outdoor_seating, R.drawable.ic_outdoor_cafe, R.color.red, "outdoor_seating", "yes", "no", ""); - private QuestionObject reservation = new QuestionObject(12, R.string.reservation, R.drawable.ic_reserved, R.color.purple, "reservation", "yes", "no", ""); - private QuestionObject takeaway = new QuestionObject(10, R.string.takeaway, R.drawable.ic_takeaway, R.color.purple, "takeaway", "yes", "no", ""); - private QuestionObject vegan = new QuestionObject(6, R.string.vegan, R.drawable.ic_carrot, R.color.blue, "diet:vegan", "yes", "no", ""); - private QuestionObject vegetarian = new QuestionObject(5, R.string.vegetarian, R.drawable.ic_carrot, R.color.blue, "diet:vegetarian", "yes", "no", ""); - private QuestionObject wheelchair = new QuestionObject(0, R.string.wheelchair, R.drawable.ic_wheelchair, R.color.orange, "wheelchair", "yes", "no", ""); - private QuestionObject wheelchair_toilets = new QuestionObject(1, R.string.wheelchair_toilets, R.drawable.ic_wheelchair, R.color.orange, "toilets:wheelchair", "yes", "no", ""); - private QuestionObject wifi = new QuestionObject(3, R.string.wifi, R.drawable.ic_wifi, R.color.orange, "internet_access", "wlan", "no", ""); - private QuestionObject wifi_fee = new QuestionObject(4, R.string.wifi_fee, R.drawable.ic_wifi, R.color.orange, "internet_access:fee", "yes", "no", ""); - private QuestionObject women = new QuestionObject(8, R.string.women, R.drawable.ic_women, R.color.red, "women", "yes", "no", ""); - private Map map = new HashMap<>(); + private Map map = new HashMap<>(); private Questions() { - map.put("cash", this.cash); - map.put("cheques", this.cheques); - map.put("contactless", this.contactless); - map.put("credit_card", this.credit_card); - map.put("debit_card", this.debit_card); - map.put("deliver", this.deliver); - map.put("dispensing", this.dispensing); - map.put("drive_through", this.drive_through); - map.put("halal", this.halal); - map.put("kosher", this.kosher); - map.put("men", this.men); - map.put("organic", this.organic); - map.put("outdoor_seating", this.outdoor_seating); - map.put("reservation", this.reservation); - map.put("takeaway", this.takeaway); - map.put("vegan", this.vegan); - map.put("vegetarian", this.vegetarian); - map.put("wheelchair", this.wheelchair); - map.put("wheelchair_toilets", this.wheelchair_toilets); - map.put("wifi", this.wifi); - map.put("wifi_fee", this.wifi_fee); - map.put("women", this.women); + map.put("cash", new Cash()); + map.put("cheques", new Cheque()); + map.put("contactless", new Contactless()); + map.put("credit_card", new CreditCard()); + map.put("debit_card", new DebitCard()); + map.put("deliver", new Deliver()); + map.put("dispensing", new Dispensing()); + map.put("drive_through", new DriveThrough()); + map.put("halal", new Halal()); + map.put("kosher", new Kosher()); + map.put("men", new Men()); + map.put("organic", new Organic()); + map.put("outdoor_seating", new OutdoorSeating()); + map.put("reservation", new Reservation()); + map.put("takeaway", new Takeaway()); + map.put("vegan", new Vegan()); + map.put("vegetarian", new Vegetarian()); + map.put("wheelchair", new Wheelchair()); + map.put("wheelchair_toilets", new WheelchairToilets()); + map.put("wifi", new Wifi()); + map.put("wifi_fee", new WifiFee()); + map.put("women", new Women()); } - private static synchronized Questions getInstance() { if (INSTANCE == null) { INSTANCE = new Questions(); @@ -68,7 +67,7 @@ private static synchronized Questions getInstance() { return INSTANCE; } - public static QuestionObject getQuestion(String question) { + public static Question getQuestion(String question) { getInstance(); return INSTANCE.map.get(question); } diff --git a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/AppDatabase.java b/app/src/main/java/com/teester/whatsnearby/data/database/AppDatabase.java similarity index 93% rename from app/src/main/java/com/teester/whatsnearby/data/localDatabase/AppDatabase.java rename to app/src/main/java/com/teester/whatsnearby/data/database/AppDatabase.java index e0cd89d..be4dc2a 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/AppDatabase.java +++ b/app/src/main/java/com/teester/whatsnearby/data/database/AppDatabase.java @@ -1,4 +1,4 @@ -package com.teester.whatsnearby.data.localDatabase; +package com.teester.whatsnearby.data.database; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; diff --git a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocation.java b/app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocation.java similarity index 97% rename from app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocation.java rename to app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocation.java index 53ddbce..711dcc5 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocation.java +++ b/app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocation.java @@ -1,4 +1,4 @@ -package com.teester.whatsnearby.data.localDatabase; +package com.teester.whatsnearby.data.database; import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; diff --git a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocationDao.java b/app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocationDao.java similarity index 84% rename from app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocationDao.java rename to app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocationDao.java index 738953a..37df2fb 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/localDatabase/VisitedLocationDao.java +++ b/app/src/main/java/com/teester/whatsnearby/data/database/VisitedLocationDao.java @@ -1,4 +1,4 @@ -package com.teester.whatsnearby.data.localDatabase; +package com.teester.whatsnearby.data.database; import android.arch.persistence.room.Dao; import android.arch.persistence.room.Delete; @@ -6,8 +6,6 @@ import android.arch.persistence.room.Query; import android.arch.persistence.room.Update; -import com.teester.whatsnearby.data.localDatabase.VisitedLocation; - import java.util.List; @Dao diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobNotifier.java similarity index 90% rename from app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java rename to app/src/main/java/com/teester/whatsnearby/data/location/LocationJobNotifier.java index 9b27769..c113bbd 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobNotifier.java @@ -11,15 +11,14 @@ import android.support.v4.content.ContextCompat; import com.teester.whatsnearby.R; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.data.source.SourceContract; import com.teester.whatsnearby.questions.QuestionsActivity; import static android.content.Context.NOTIFICATION_SERVICE; -public class Notifier { - - private static final String OVERPASSLASTQUERYTIMEPREF = "last_overpass_query_time"; +public class LocationJobNotifier implements LocationJobServiceContract.Notifier { /** * Creates a notification and stores the time of notification @@ -29,11 +28,10 @@ public class Notifier { * @param drawable - poi drawable id */ public static void createNotification(Context context, String name, int drawable) { - // Store the time the notification was made SourceContract.Preferences preferences = new Preferences(context); - preferences.setLongPreference(OVERPASSLASTQUERYTIMEPREF, System.currentTimeMillis()); - preferences.setLongPreference("last_notification_time", System.currentTimeMillis()); + preferences.setLongPreference(PreferenceList.LAST_OVERPASS_QUERY_TIME, System.currentTimeMillis()); + preferences.setLongPreference(PreferenceList.LAST_NOTIFICATION_TIME, System.currentTimeMillis()); Intent resultIntent = new Intent(context, QuestionsActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobPresenter.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobPresenter.java new file mode 100644 index 0000000..ad3e2aa --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobPresenter.java @@ -0,0 +1,107 @@ +package com.teester.whatsnearby.data.location; + +import android.content.Context; +import android.location.Location; + +import com.teester.whatsnearby.BuildConfig; +import com.teester.whatsnearby.data.PreferenceList; +import com.teester.whatsnearby.data.source.SourceContract; + +public class LocationJobPresenter implements LocationJobServiceContract.Presenter { + + private static final int MINQUERYINTERVAL = 60 * 60 * 1000; + private static final double MINQUERYDISTANCE = 20; + private static final int MINLOCATIONACCURACY = 100; + + private Location lastLocation; + private Location lastQueryLocation; + + private Context context; + private LocationJobServiceContract.Receiver receiver; + private SourceContract.Preferences preferences; + + public LocationJobPresenter(Context context, LocationJobServiceContract.Receiver service, SourceContract.Preferences preferences) { + this.context = context; + this.receiver = service; + this.preferences = preferences; + } + + @Override + public void processLocation(Location location) { + if (lastLocation == null) { + + double lastLatitude = preferences.getDoublePreference(PreferenceList.LAST_LOCATION_LATITUDE); + double lastLongitude = preferences.getDoublePreference(PreferenceList.LAST_LOCATION_LONGITUDE); + if (lastLatitude == 0 && lastLongitude == 0) { + lastLocation = location; + } else { + lastLocation = new Location("dummyprovider"); + lastLocation.setLatitude(lastLatitude); + lastLocation.setLongitude(lastLongitude); + } + } + if (lastQueryLocation == null) { + double lastQueryLatitude = preferences.getDoublePreference(PreferenceList.LAST_QUERY_LOCATION_LATITUDE); + double lastQueryLongitude = preferences.getDoublePreference(PreferenceList.LAST_QUERY_LOCATION_LONGITUDE); + if (lastQueryLatitude == 0 && lastQueryLongitude == 0) { + lastQueryLocation = location; + } else { + lastQueryLocation = new Location("dummyprovider"); + lastQueryLocation.setLatitude(lastQueryLatitude); + lastQueryLocation.setLongitude(lastQueryLongitude); + } + } + + preferences.setFloatPreference(PreferenceList.LOCATION_ACCURACY, location.getAccuracy()); + preferences.setFloatPreference(PreferenceList.DISTANCE_TO_LAST_QUERY, location.distanceTo(lastQueryLocation)); + preferences.setLongPreference(PreferenceList.QUERY_INTERVAL, System.currentTimeMillis() - preferences.getLongPreference(PreferenceList.LAST_QUERY_TIME)); + preferences.setFloatPreference(PreferenceList.DISTANCE_TO_LAST_LOCATION, location.distanceTo(lastLocation)); + preferences.setDoublePreference(PreferenceList.LATITUDE, location.getLatitude()); + preferences.setDoublePreference(PreferenceList.LONGITUDE, location.getLongitude()); + + if (decideWhetherToQuery(location)) { + lastQueryLocation = location; + preferences.setDoublePreference(PreferenceList.LAST_QUERY_LOCATION_LATITUDE, location.getLatitude()); + preferences.setDoublePreference(PreferenceList.LAST_QUERY_LOCATION_LONGITUDE, location.getLongitude()); + receiver.performOverpassQuery(context, location); + } + lastLocation = location; + preferences.setDoublePreference(PreferenceList.LAST_LOCATION_LATITUDE, location.getLatitude()); + preferences.setDoublePreference(PreferenceList.LAST_LOCATION_LONGITUDE, location.getLongitude()); + } + + private boolean decideWhetherToQuery(Location location) { + boolean query = true; + boolean debug_mode = preferences.getBooleanPreference(PreferenceList.DEBUG_MODE); + long lastQueryTime = preferences.getLongPreference(PreferenceList.LAST_QUERY_TIME); + + // Don't query Overpass if the location is less accurate than 100m + if (location.getAccuracy() > MINLOCATIONACCURACY) { + query = false; + } + + // Don't query Overpass if less than 1 hour has passed since the last query + if (System.currentTimeMillis() - lastQueryTime < MINQUERYINTERVAL) { + query = false; + } + + // Don't query Overpass is you've moved more than 20m from the last location query (5 mins ago) + // (indicates you're probably not in the same place as 5 mins ago) + if (location.distanceTo(lastLocation) > MINQUERYDISTANCE) { + query = false; + } + + // Don't query Overpass is youre still within 20m of the last location query that you were + // notified about (indicates you've probably still in the same place) + if (location.distanceTo(lastQueryLocation) < MINQUERYDISTANCE) { + query = false; + } + + // If we're in debug mode, query every time + if (debug_mode && BuildConfig.DEBUG) { + query = true; + } + return query; + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobService.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobService.java new file mode 100644 index 0000000..0bace14 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobService.java @@ -0,0 +1,90 @@ +package com.teester.whatsnearby.data.location; + +import android.Manifest; +import android.app.PendingIntent; +import android.app.job.JobParameters; +import android.app.job.JobService; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.wifi.WifiManager; +import android.support.v4.app.ActivityCompat; + +import com.mapzen.android.lost.api.LocationRequest; +import com.mapzen.android.lost.api.LocationServices; +import com.mapzen.android.lost.api.LostApiClient; +import com.teester.whatsnearby.main.MainActivity; + +public class LocationJobService extends JobService implements LocationJobServiceContract.Service { + + private LostApiClient client; + + @Override + public boolean onStartJob(JobParameters jobParameters) { + final Context context = getApplicationContext(); + + client = new LostApiClient.Builder(this) + .addConnectionCallbacks(new LostApiClient.ConnectionCallbacks() { + @Override + public void onConnected() { + int priority; + if (checkWifi()) { + priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; + } else { + priority = LocationRequest.PRIORITY_HIGH_ACCURACY; + } + LocationRequest request = LocationRequest.create(); + request.setPriority(priority); + request.setInterval(60000); + request.setFastestInterval(60000); + + Intent resultIntent = new Intent(context, LocationJobServiceReceiver.class); + PendingIntent callbackIntent = PendingIntent.getBroadcast(context, 10000, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); + + checkLocationPermission(); + + LocationServices.FusedLocationApi.requestLocationUpdates(client, request, callbackIntent); + } + + @Override + public void onConnectionSuspended() { + // required empty method + } + }).build(); + client.connect(); + jobFinished(jobParameters, true); + return false; + } + + @Override + public boolean onStopJob(JobParameters jobParameters) { + return false; + } + + public void checkLocationPermission() { + + if (ActivityCompat.checkSelfPermission(getApplicationContext(), + Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + + Intent intent = new Intent(getBaseContext(), MainActivity.class); + startActivity(intent); + + return; + } + } + + private boolean checkWifi() { + WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); + switch (wifiManager.getWifiState()) { + case WifiManager.WIFI_STATE_DISABLED: + case WifiManager.WIFI_STATE_DISABLING: + return false; + case WifiManager.WIFI_STATE_ENABLED: + case WifiManager.WIFI_STATE_ENABLING: + case WifiManager.WIFI_STATE_UNKNOWN: + default: + return true; + } + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceContract.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceContract.java new file mode 100644 index 0000000..7264d4a --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceContract.java @@ -0,0 +1,28 @@ +package com.teester.whatsnearby.data.location; + +import android.content.Context; +import android.location.Location; + +public interface LocationJobServiceContract { + + interface Presenter { + + void processLocation(Location location); + + } + + interface Service { + + } + + interface Receiver { + + void performOverpassQuery(Context context, Location location); + + void createNotification(Context context, String name, int drawable); + + } + + interface Notifier { + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceReceiver.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceReceiver.java new file mode 100644 index 0000000..7114a85 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationJobServiceReceiver.java @@ -0,0 +1,49 @@ +package com.teester.whatsnearby.data.location; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.location.Location; + +import com.mapzen.android.lost.api.LocationResult; +import com.teester.whatsnearby.data.source.Preferences; +import com.teester.whatsnearby.data.source.QueryOverpass; +import com.teester.whatsnearby.data.source.SourceContract; + +import java.util.List; + +public class LocationJobServiceReceiver extends BroadcastReceiver implements LocationJobServiceContract.Receiver { + + @Override + public void onReceive(Context context, Intent intent) { + LocationJobServiceContract.Presenter locationPresenter = new LocationJobPresenter(context, this, new Preferences(context)); + final LocationResult locationResult = LocationResult.extractResult(intent); + + if (locationResult != null) { + Location location; + List locations = locationResult.getLocations(); + if (locations.size() > 0) { + location = locations.get(0); + } else { + location = locationResult.getLastLocation(); + } + locationPresenter.processLocation(location); + } + } + + @Override + public void performOverpassQuery(final Context context, final Location location) { + new Thread(new Runnable() { + @Override + public void run() { + SourceContract.Overpass overpassQuery = new QueryOverpass(context); + overpassQuery.queryOverpass(location.getLatitude(), location.getLongitude(), location.getAccuracy()); + } + }).start(); + } + + @Override + public void createNotification(Context context, String name, int drawable) { + LocationJobNotifier.createNotification(context, name, drawable); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationPresenter.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationPresenter.java deleted file mode 100644 index 4f3dbd2..0000000 --- a/app/src/main/java/com/teester/whatsnearby/data/location/LocationPresenter.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.teester.whatsnearby.data.location; - -import android.location.Location; - -import com.teester.whatsnearby.BuildConfig; -import com.teester.whatsnearby.data.source.SourceContract; - -public class LocationPresenter implements LocationServiceContract.Presenter { - - private static final String TAG = LocationPresenter.class.getSimpleName(); - - private static final int INTERVAL = 1 * 60 * 1000; - private static final int MINQUERYINTERVAL = 60 * 60 * 1000; - private static final double MINQUERYDISTANCE = 20; - private static final int MINLOCATIONACCURACY = 100; - private static final String OVERPASSLASTQUERYTIMEPREF = "last_overpass_query_time"; - - private Location lastLocation; - private Location lastQueryLocation; - - private LocationServiceContract.Service service; - private SourceContract.Preferences preferences; - - public LocationPresenter(LocationServiceContract.Service service, SourceContract.Preferences preferences) { - this.service = service; - this.preferences = preferences; - } - - @Override - public void processLocation(Location location) { - // Get the last time the user was notified that they were in a location - long lastQueryTime = preferences.getLongPreference(OVERPASSLASTQUERYTIMEPREF); - - if (lastLocation == null) { - lastLocation = location; - } - if (lastQueryLocation == null) { - lastQueryLocation = location; - } - - boolean debug_mode = preferences.getBooleanPreference("debug_mode"); - preferences.setFloatPreference("location_accuracy", location.getAccuracy()); - preferences.setFloatPreference("distance_to_last_query", location.distanceTo(lastQueryLocation)); - preferences.setLongPreference("query_interval", System.currentTimeMillis() - lastQueryTime); - preferences.setFloatPreference("distance_to_last_location", location.distanceTo(lastLocation)); - preferences.setDoublePreference("latitude", location.getLatitude()); - preferences.setDoublePreference("longitude", location.getLongitude()); - - boolean query = true; - - // Don't query Overpass if the location is less accurate than 100m - if (location.getAccuracy() > MINLOCATIONACCURACY) { - query = false; - } - - // Don't query Overpass if less than 1 hour has passed since the last query - if (System.currentTimeMillis() - lastQueryTime < MINQUERYINTERVAL) { - query = false; - } - - // Don't query Overpass is you've moved more than 20m from the last location query (5 mins ago) - // (indicates you're probably not in the same place as 5 mins ago) - if (location.distanceTo(lastLocation) > MINQUERYDISTANCE) { - query = false; - } - - // Don't query Overpass is youre still within 20m of the last location query that you were - // notified about (indicates you've probably still in the same place) - if (location.distanceTo(lastQueryLocation) < MINQUERYDISTANCE) { - query = false; - } - - // If we're in debug mode, query every time - if (debug_mode == true) { - if (BuildConfig.DEBUG) { - query = true; - } - } - - if (query == true) { - lastQueryLocation = location; - - // Cancel all notifications before we run a new query. If we're querying, - // Overpass, we're no longer in the same place as the last notification. - //service.cancelNotifications(); - service.performOverpassQuery(location); - } - //service.performOverpassQuery(location); - lastLocation = location; - } - - @Override - public void queryResult() { - service.createNotification("", 0); - } - - @Override - public void updateLastQueryTime() { - } - - - @Override - public void createLostClient() { - } - - @Override - public void init() { - this.service.createLostClient(INTERVAL); - } - - @Override - public void destroy() { - - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationService.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationService.java deleted file mode 100644 index 6074ebc..0000000 --- a/app/src/main/java/com/teester/whatsnearby/data/location/LocationService.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.teester.whatsnearby.data.location; - -import android.Manifest; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.location.Location; -import android.os.IBinder; -import android.support.annotation.Nullable; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; - -import com.mapzen.android.lost.api.LocationListener; -import com.mapzen.android.lost.api.LocationRequest; -import com.mapzen.android.lost.api.LocationServices; -import com.mapzen.android.lost.api.LostApiClient; -import com.teester.whatsnearby.data.source.Preferences; -import com.teester.whatsnearby.data.source.QueryOverpass; -import com.teester.whatsnearby.data.source.SourceContract; -import com.teester.whatsnearby.main.MainActivity; - -public class LocationService extends Service implements LocationServiceContract.Service { - - private static final String TAG = LocationService.class.getSimpleName(); - - private static final int PRIORITY = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; - private static final String OVERPASSLASTQUERYTIMEPREF = "last_overpass_query_time"; - - private LocationServiceContract.Presenter locationPresenter; - LocationListener listener = new LocationListener() { - @Override - public void onLocationChanged(Location location) { - locationPresenter.processLocation(location); - } - }; - private SourceContract.Preferences preferences; - private LostApiClient client; - private Context context; - - /** - * Gets a bitmap of a drawable from a given drawable id - * - * @param context application context - * @param drawableId the id of the required drawable - * @return A bitmap image - */ - private static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) { - Drawable drawable = ContextCompat.getDrawable(context, drawableId); - Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), - drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - - return bitmap; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public void onCreate() { - super.onCreate(); - context = getApplicationContext(); - preferences = new Preferences(context); - locationPresenter = new LocationPresenter(this, preferences); - locationPresenter.init(); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - super.onStartCommand(intent, flags, startId); - return START_STICKY; - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (client.isConnected()) { - LocationServices.FusedLocationApi.removeLocationUpdates(client, listener); - client.disconnect(); - } - } - - @Override - public void setPresenter(LocationServiceContract.Presenter presenter) { - locationPresenter = presenter; - } - - @Override - public void cancelNotifications() { - Notifier.cancelNotifictions(getApplicationContext()); - } - - @Override - public void createLostClient(final int interval) { - client = new LostApiClient.Builder(this).addConnectionCallbacks(new LostApiClient.ConnectionCallbacks() { - @Override - public void onConnected() { - LocationRequest request = LocationRequest.create(); - request.setPriority(PRIORITY); - request.setInterval(interval); - - checkLocationPermission(); - - LocationServices.FusedLocationApi.requestLocationUpdates(client, request, listener); - } - - @Override - public void onConnectionSuspended() { - - } - }).build(); - client.connect(); - } - - @Override - public void performOverpassQuery(final Location location) { - SourceContract.Overpass overpassQuery = new QueryOverpass(getApplicationContext()); - new Thread(new Runnable() { - @Override - public void run() { - SourceContract.Overpass overpassQuery = new QueryOverpass(getApplicationContext()); - overpassQuery.queryOverpass(location.getLatitude(), location.getLongitude(), location.getAccuracy()); - } - }).start(); - } - - public void checkLocationPermission() { - if (ActivityCompat.checkSelfPermission(getApplicationContext(), - Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - - Intent intent = new Intent(getBaseContext(), MainActivity.class); - startActivity(intent); - - return; - } - } - - @Override - public void createNotification(String name, int drawable) { - Notifier.createNotification(getApplicationContext(), name, drawable); - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/LocationServiceContract.java b/app/src/main/java/com/teester/whatsnearby/data/location/LocationServiceContract.java deleted file mode 100644 index cb64b23..0000000 --- a/app/src/main/java/com/teester/whatsnearby/data/location/LocationServiceContract.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.teester.whatsnearby.data.location; - -import android.location.Location; - -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; - -public interface LocationServiceContract { - - interface Presenter extends BasePresenter { - - void processLocation(Location location); - - void createLostClient(); - - void queryResult(); - - void updateLastQueryTime(); - } - - interface Service extends BaseView { - - void cancelNotifications(); - - void createLostClient(int interval); - - void performOverpassQuery(Location location); - - void createNotification(String name, int drawable); - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBank.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBank.java new file mode 100644 index 0000000..4093737 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBank.java @@ -0,0 +1,15 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityBank extends Poi { + + public AmenityBank() { + objectName = "bank"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_bank; + questions = new String[]{ + "wheelchair" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBar.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBar.java new file mode 100644 index 0000000..f8d141f --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityBar.java @@ -0,0 +1,24 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityBar extends Poi { + + public AmenityBar() { + objectName = "bar"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_bar; + questions = new String[]{ + "wheelchair", + "outdoor_seating", + "wifi", + "wifi_fee", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "wheelchair_toilets" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCafe.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCafe.java new file mode 100644 index 0000000..2e0d368 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCafe.java @@ -0,0 +1,24 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityCafe extends Poi { + + public AmenityCafe() { + objectName = "cafe"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_cafe; + questions = new String[]{ + "wheelchair", + "outdoor_seating", + "wifi", + "wifi_fee", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "wheelchair_toilets" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCinema.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCinema.java new file mode 100644 index 0000000..e3d73c0 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityCinema.java @@ -0,0 +1,25 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +/** + * Created by mark on 07/03/18. + */ + +public class AmenityCinema extends Poi { + + public AmenityCinema() { + objectName = "cinema"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_cinema; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "wheelchair_toilets" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDentist.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDentist.java new file mode 100644 index 0000000..a1e1381 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDentist.java @@ -0,0 +1,19 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +/** + * Created by mark on 07/03/18. + */ + +public class AmenityDentist extends Poi { + + public AmenityDentist() { + objectName = "dentist"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_dentist; + questions = new String[]{ + "wheelchair" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDoctors.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDoctors.java new file mode 100644 index 0000000..aaeb16c --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityDoctors.java @@ -0,0 +1,15 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityDoctors extends Poi { + + public AmenityDoctors() { + objectName = "doctors"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_doctors; + questions = new String[]{ + "wheelchair" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFastFood.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFastFood.java new file mode 100644 index 0000000..c0df943 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFastFood.java @@ -0,0 +1,24 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityFastFood extends Poi { + + public AmenityFastFood() { + objectName = "fast_food"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_fast_food; + questions = new String[]{ + "wheelchair", + "wheelchair_toilets", + "drive_through", + "takeaway", + "deliver", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFuel.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFuel.java new file mode 100644 index 0000000..694ff7e --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityFuel.java @@ -0,0 +1,21 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityFuel extends Poi { + + public AmenityFuel() { + objectName = "fuel"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_fuel; + questions = new String[]{ + "wheelchair", + "wheelchair_toilets", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPharmacy.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPharmacy.java new file mode 100644 index 0000000..8a991af --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPharmacy.java @@ -0,0 +1,21 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityPharmacy extends Poi { + + public AmenityPharmacy() { + objectName = "pharmacy"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_pharmacy; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "dispensing" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPub.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPub.java new file mode 100644 index 0000000..062bf60 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityPub.java @@ -0,0 +1,24 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityPub extends Poi { + + public AmenityPub() { + objectName = "pub"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_pub; + questions = new String[]{ + "wheelchair", + "outdoor_seating", + "wifi", + "wifi_fee", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "wheelchair_toilets" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityRestaurant.java b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityRestaurant.java new file mode 100644 index 0000000..d85a278 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/AmenityRestaurant.java @@ -0,0 +1,29 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class AmenityRestaurant extends Poi { + + public AmenityRestaurant() { + objectName = "restaurant"; + objectClass = "amenity"; + objectIcon = R.drawable.ic_restaurant; + questions = new String[]{ + "wheelchair", + "wheelchair_toilets", + "wifi", + "wifi_fee", + "outdoor_seating", + "vegetarian", + "vegan", + "takeaway", + "deliver", + "reservation", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/OsmObjectType.java b/app/src/main/java/com/teester/whatsnearby/data/pois/Poi.java similarity index 54% rename from app/src/main/java/com/teester/whatsnearby/data/OsmObjectType.java rename to app/src/main/java/com/teester/whatsnearby/data/pois/Poi.java index 8dfab12..9a0df38 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/OsmObjectType.java +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/Poi.java @@ -1,64 +1,70 @@ -package com.teester.whatsnearby.data; +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.data.PoiTypes; +import com.teester.whatsnearby.data.Questions; +import com.teester.whatsnearby.data.questions.QuestionsContract; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -public class OsmObjectType { +public class Poi implements PoiContract { - private String objectName; - private String objectClass; - private int objectIcon; - private String[] questions; - - public OsmObjectType(String objectName, String objectClass, int objectIcon, String[] questions) { - this.objectName = objectName; - this.objectClass = objectClass; - this.objectIcon = objectIcon; - this.questions = questions; - } + public String objectName; + public String objectClass; + public int objectIcon; + public String[] questions; + @Override public String getObjectName() { return this.objectName; } + @Override public String getObjectClass() { return this.objectClass; } - public OsmObjectType getObjectType() { + @Override + public PoiContract getObjectType() { return PoiTypes.getPoiType(this.objectClass); } + @Override public int getObjectIcon() { return this.objectIcon; } + @Override public String[] getQuestions() { return this.questions; } + @Override public void setQuestions(String[] questions) { this.questions = questions; } + @Override public void shuffleQuestions() { String[] questions = this.questions; List strList = Arrays.asList(questions); Collections.shuffle(strList); questions = strList.toArray(new String[strList.size()]); - this.questions = questions;; + this.questions = questions; } + @Override public int getNoOfQuestions() { return this.questions.length; } - public List getQuestionObjects() { - List k = new ArrayList(); - for (int i=0; i < questions.length; i++) { - QuestionObject question = Questions.getQuestion(questions[i]); + @Override + public List getQuestion() { + List k = new ArrayList(); + for (int i = 0; i < questions.length; i++) { + QuestionsContract question = Questions.getQuestion(questions[i]); k.add(question); } return k; diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/PoiContract.java b/app/src/main/java/com/teester/whatsnearby/data/pois/PoiContract.java new file mode 100644 index 0000000..6f39170 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/PoiContract.java @@ -0,0 +1,25 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.data.questions.QuestionsContract; + +import java.util.List; + +public interface PoiContract { + String getObjectName(); + + String getObjectClass(); + + PoiContract getObjectType(); + + int getObjectIcon(); + + String[] getQuestions(); + + void setQuestions(String[] questions); + + void shuffleQuestions(); + + int getNoOfQuestions(); + + List getQuestion(); +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopAlcohol.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopAlcohol.java new file mode 100644 index 0000000..6c275ec --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopAlcohol.java @@ -0,0 +1,19 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopAlcohol extends Poi { + + public ShopAlcohol() { + objectName = "alcohol"; + objectClass = "shop"; + objectIcon = R.drawable.ic_alcohol; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBakery.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBakery.java new file mode 100644 index 0000000..260b1ed --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBakery.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopBakery extends Poi { + + public ShopBakery() { + objectName = "bakery"; + objectClass = "shop"; + objectIcon = R.drawable.ic_bakery; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBeauty.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBeauty.java new file mode 100644 index 0000000..fc8bad6 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBeauty.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopBeauty extends Poi { + + public ShopBeauty() { + objectName = "beauty"; + objectClass = "shop"; + objectIcon = R.drawable.ic_beauty; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBicycle.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBicycle.java new file mode 100644 index 0000000..fe9cc3c --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopBicycle.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopBicycle extends Poi { + + public ShopBicycle() { + objectName = "bicycle"; + objectClass = "shop"; + objectIcon = R.drawable.ic_bicycle; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopButcher.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopButcher.java new file mode 100644 index 0000000..12d02fb --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopButcher.java @@ -0,0 +1,23 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopButcher extends Poi { + + public ShopButcher() { + objectName = "butcher"; + objectClass = "shop"; + objectIcon = R.drawable.ic_butcher; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "halal", + "kosher", + "organic" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCar.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCar.java new file mode 100644 index 0000000..464390b --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCar.java @@ -0,0 +1,19 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopCar extends Poi { + + public ShopCar() { + objectName = "car"; + objectClass = "shop"; + objectIcon = R.drawable.ic_car; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCarRepair.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCarRepair.java new file mode 100644 index 0000000..3839d96 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCarRepair.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopCarRepair extends Poi { + + public ShopCarRepair() { + objectName = "car_repair"; + objectClass = "shop"; + objectIcon = R.drawable.ic_car_repair; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopChemist.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopChemist.java new file mode 100644 index 0000000..7389aab --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopChemist.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopChemist extends Poi { + + public ShopChemist() { + objectName = "chemist"; + objectClass = "shop"; + objectIcon = R.drawable.ic_chemist; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopClothes.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopClothes.java new file mode 100644 index 0000000..958bf78 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopClothes.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopClothes extends Poi { + + public ShopClothes() { + objectName = "clothes"; + objectClass = "shop"; + objectIcon = R.drawable.ic_clothes; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopConvenience.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopConvenience.java new file mode 100644 index 0000000..6c1149b --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopConvenience.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopConvenience extends Poi { + + public ShopConvenience() { + objectName = "convenience"; + objectClass = "shop"; + objectIcon = R.drawable.ic_convenience; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCosmetics.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCosmetics.java new file mode 100644 index 0000000..22ff5fc --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopCosmetics.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopCosmetics extends Poi { + + public ShopCosmetics() { + objectName = "cosmetics"; + objectClass = "shop"; + objectIcon = R.drawable.ic_cosmetics; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDepartmentStore.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDepartmentStore.java new file mode 100644 index 0000000..6cc470e --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDepartmentStore.java @@ -0,0 +1,21 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopDepartmentStore extends Poi { + + public ShopDepartmentStore() { + objectName = "department_store"; + objectClass = "shop"; + objectIcon = R.drawable.ic_department_store; + questions = new String[]{ + "wheelchair", + "wheelchair_toilets", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDoItYourself.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDoItYourself.java new file mode 100644 index 0000000..589a107 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopDoItYourself.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopDoItYourself extends Poi { + + public ShopDoItYourself() { + objectName = "doityourself"; + objectClass = "shop"; + objectIcon = R.drawable.ic_doityourself; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFlorist.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFlorist.java new file mode 100644 index 0000000..e9e0807 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFlorist.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopFlorist extends Poi { + + public ShopFlorist() { + objectName = "florist"; + objectClass = "shop"; + objectIcon = R.drawable.ic_florist; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFurniture.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFurniture.java new file mode 100644 index 0000000..c11f1fb --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopFurniture.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopFurniture extends Poi { + + public ShopFurniture() { + objectName = "furniture"; + objectClass = "shop"; + objectIcon = R.drawable.ic_furniture; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopHairdresser.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopHairdresser.java new file mode 100644 index 0000000..9a6b80c --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopHairdresser.java @@ -0,0 +1,22 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopHairdresser extends Poi { + + public ShopHairdresser() { + objectName = "hairdresser"; + objectClass = "shop"; + objectIcon = R.drawable.ic_hairdresser; + questions = new String[]{ + "wheelchair", + "men", + "women", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopJewelry.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopJewelry.java new file mode 100644 index 0000000..4210aa5 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopJewelry.java @@ -0,0 +1,22 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopJewelry extends Poi { + + public ShopJewelry() { + objectName = "jewelry"; + objectClass = "shop"; + objectIcon = R.drawable.ic_jewelry; + questions = new String[]{ + "wheelchair", + "men", + "women", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopLaundry.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopLaundry.java new file mode 100644 index 0000000..c56408b --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopLaundry.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopLaundry extends Poi { + + public ShopLaundry() { + objectName = "laundry"; + objectClass = "shop"; + objectIcon = R.drawable.ic_laundry; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopMobilePhone.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopMobilePhone.java new file mode 100644 index 0000000..8e16e67 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopMobilePhone.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopMobilePhone extends Poi { + + public ShopMobilePhone() { + objectName = "mobile_phone"; + objectClass = "shop"; + objectIcon = R.drawable.ic_mobile_phone; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopOptician.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopOptician.java new file mode 100644 index 0000000..62fc1aa --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopOptician.java @@ -0,0 +1,22 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopOptician extends Poi { + + public ShopOptician() { + objectName = "optician"; + objectClass = "shop"; + objectIcon = R.drawable.ic_optician; + questions = new String[]{ + "wheelchair", + "men", + "women", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPerfumery.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPerfumery.java new file mode 100644 index 0000000..1093f38 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPerfumery.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopPerfumery extends Poi { + + public ShopPerfumery() { + objectName = "optician"; + objectClass = "shop"; + objectIcon = R.drawable.ic_optician; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPhoto.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPhoto.java new file mode 100644 index 0000000..f4e2805 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopPhoto.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopPhoto extends Poi { + + public ShopPhoto() { + objectName = "photo"; + objectClass = "shop"; + objectIcon = R.drawable.ic_photo; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopShoes.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopShoes.java new file mode 100644 index 0000000..8b189e9 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopShoes.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopShoes extends Poi { + + public ShopShoes() { + objectName = "shoes"; + objectClass = "shop"; + objectIcon = R.drawable.ic_shoes; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSports.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSports.java new file mode 100644 index 0000000..653f19d --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSports.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopSports extends Poi { + + public ShopSports() { + objectName = "sports"; + objectClass = "shop"; + objectIcon = R.drawable.ic_sports; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopStationary.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopStationary.java new file mode 100644 index 0000000..a927dd3 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopStationary.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopStationary extends Poi { + + public ShopStationary() { + objectName = "stationary"; + objectClass = "shop"; + objectIcon = R.drawable.ic_stationery; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSupermarket.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSupermarket.java new file mode 100644 index 0000000..4d665fc --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopSupermarket.java @@ -0,0 +1,21 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopSupermarket extends Poi { + + public ShopSupermarket() { + objectName = "supermarket"; + objectClass = "shop"; + objectIcon = R.drawable.ic_supermarket; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless", + "organic" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVariety.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVariety.java new file mode 100644 index 0000000..62a8647 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVariety.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopVariety extends Poi { + + public ShopVariety() { + objectName = "variety"; + objectClass = "shop"; + objectIcon = R.drawable.ic_variety_store; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVeterinary.java b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVeterinary.java new file mode 100644 index 0000000..e32e71e --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/ShopVeterinary.java @@ -0,0 +1,20 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class ShopVeterinary extends Poi { + + public ShopVeterinary() { + objectName = "veterinary"; + objectClass = "shop"; + objectIcon = R.drawable.ic_veterinary; + questions = new String[]{ + "wheelchair", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/pois/TourismHotel.java b/app/src/main/java/com/teester/whatsnearby/data/pois/TourismHotel.java new file mode 100644 index 0000000..0348366 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/pois/TourismHotel.java @@ -0,0 +1,23 @@ +package com.teester.whatsnearby.data.pois; + +import com.teester.whatsnearby.R; + +public class TourismHotel extends Poi { + + public TourismHotel() { + objectName = "hotel"; + objectClass = "tourism"; + objectIcon = R.drawable.ic_hotel; + questions = new String[]{ + "wheelchair", + "wheelchair_toilets", + "wifi", + "wifi_fee", + "cash", + "cheques", + "credit_card", + "debit_card", + "contactless" + }; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Cash.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Cash.java new file mode 100644 index 0000000..d8c81f7 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Cash.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Cash extends Question { + + public Cash() { + question = R.string.cash; + drawable = R.drawable.ic_money; + color = R.color.green; + tag = "payment:cash"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Cheque.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Cheque.java new file mode 100644 index 0000000..9e6bd49 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Cheque.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Cheque extends Question { + + public Cheque() { + question = R.string.cheques; + drawable = R.drawable.ic_check; + color = R.color.green; + tag = "payment:cheque"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Contactless.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Contactless.java new file mode 100644 index 0000000..165b230 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Contactless.java @@ -0,0 +1,14 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Contactless extends Question { + + public Contactless() { + question = R.string.contactless; + drawable = R.drawable.ic_credit_card; + color = R.color.green; + tag = "payment:contactless"; + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/CreditCard.java b/app/src/main/java/com/teester/whatsnearby/data/questions/CreditCard.java new file mode 100644 index 0000000..8e3c31e --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/CreditCard.java @@ -0,0 +1,14 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class CreditCard extends Question { + + public CreditCard() { + question = R.string.credit_card; + drawable = R.drawable.ic_credit_card; + color = R.color.green; + tag = "payment:credit_cards"; + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/DebitCard.java b/app/src/main/java/com/teester/whatsnearby/data/questions/DebitCard.java new file mode 100644 index 0000000..ae4deb6 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/DebitCard.java @@ -0,0 +1,14 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class DebitCard extends Question { + + public DebitCard() { + question = R.string.debit_card; + drawable = R.drawable.ic_credit_card; + color = R.color.green; + tag = "payment:debit_cards"; + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Deliver.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Deliver.java new file mode 100644 index 0000000..f7b4af0 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Deliver.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Deliver extends Question { + + public Deliver() { + question = R.string.deliver; + drawable = R.drawable.ic_delivery_man; + color = R.color.purple; + tag = "delivery"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Dispensing.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Dispensing.java new file mode 100644 index 0000000..9bff822 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Dispensing.java @@ -0,0 +1,14 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Dispensing extends Question { + + public Dispensing() { + question = R.string.dispensing; + drawable = R.drawable.ic_drugs; + color = R.color.cyan; + tag = "dispensing"; + } + +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/DriveThrough.java b/app/src/main/java/com/teester/whatsnearby/data/questions/DriveThrough.java new file mode 100644 index 0000000..961911c --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/DriveThrough.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class DriveThrough extends Question { + + public DriveThrough() { + question = R.string.drive_through; + drawable = R.drawable.ic_drive_through; + color = R.color.purple; + tag = "drive_through"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Halal.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Halal.java new file mode 100644 index 0000000..a11af3d --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Halal.java @@ -0,0 +1,32 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Halal extends Question { + + public Halal() { + question = R.string.halal; + drawable = R.drawable.ic_halal; + color = R.color.red; + tag = "butcher"; + answer_yes = "halal"; + answer_no = ""; + } + + @Override + public String checkPreviousAnswer(String answer) { + String response; + switch (answer) { + case "halal": + response = "yes"; + break; + case "": + response = "unsure"; + break; + default: + response = "no"; + break; + } + return super.checkPreviousAnswer(response); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Kosher.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Kosher.java new file mode 100644 index 0000000..c0aa30d --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Kosher.java @@ -0,0 +1,32 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Kosher extends Question { + + public Kosher() { + question = R.string.kosher; + drawable = R.drawable.ic_kosher; + color = R.color.red; + tag = "butcher"; + answer_yes = "kosher"; + answer_no = ""; + } + + @Override + public String checkPreviousAnswer(String answer) { + String response; + switch (answer) { + case "kosher": + response = "yes"; + break; + case "": + response = "unsure"; + break; + default: + response = "no"; + break; + } + return super.checkPreviousAnswer(response); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Men.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Men.java new file mode 100644 index 0000000..630db95 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Men.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Men extends Question { + + public Men() { + question = R.string.men; + drawable = R.drawable.ic_men; + color = R.color.red; + tag = "men"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Organic.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Organic.java new file mode 100644 index 0000000..8fadd0b --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Organic.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Organic extends Question { + + public Organic() { + question = R.string.organic; + drawable = R.drawable.ic_carrot; + color = R.color.red; + tag = "organic"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/OutdoorSeating.java b/app/src/main/java/com/teester/whatsnearby/data/questions/OutdoorSeating.java new file mode 100644 index 0000000..cd2d7e6 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/OutdoorSeating.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class OutdoorSeating extends Question { + + public OutdoorSeating() { + question = R.string.outdoor_seating; + drawable = R.drawable.ic_outdoor_cafe; + color = R.color.red; + tag = "outdoor_seating"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Question.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Question.java new file mode 100644 index 0000000..d74e615 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Question.java @@ -0,0 +1,119 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public abstract class Question implements QuestionsContract { + + public int question = 0; + public int drawable = R.drawable.ic_unsure; + public int color = 0; + public String tag = ""; + public String answer_yes = "yes"; + public String answer_no = "no"; + public String answer_unsure = ""; + + @Override + public int getQuestion() { + return this.question; + } + + @Override + public int getDrawable() { + return this.drawable; + } + + @Override + public String getTag() { + return tag; + } + + @Override + public void setTag(String tag) { + this.tag = tag; + } + + @Override + public String getAnswerYes() { + return answer_yes; + } + + @Override + public void setAnswerYes(String answer_yes) { + this.answer_yes = answer_yes; + } + + @Override + public String getAnswerNo() { + return answer_no; + } + + @Override + public void setAnswerNo(String answer_no) { + this.answer_no = answer_no; + } + + @Override + public String getAnswerUnsure() { + return answer_unsure; + } + + @Override + public void setAnswerUnsure(String answer_unsure) { + this.answer_unsure = answer_unsure; + } + + @Override + public int getIcon() { + return this.drawable; + } + + @Override + public int getColor() { + return this.color; + } + + @Override + public String getAnswer(String response) { + String answer; + switch (response) { + case "yes": + answer = this.answer_yes; + break; + case "no": + answer = this.answer_no; + break; + case "unsure": + answer = this.answer_unsure; + break; + default: + answer = ""; + break; + } + return answer; + } + + @Override + public int getAnswerInt(String response) { + int answer; + switch (response) { + case "yes": + answer = R.string.yes; + break; + case "no": + answer = R.string.no; + break; + case "unsure": + answer = R.string.unsure; + break; + default: + answer = 0; + break; + } + return answer; + } + + @Override + public String checkPreviousAnswer(String answer) { + return getAnswer(answer); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/QuestionsContract.java b/app/src/main/java/com/teester/whatsnearby/data/questions/QuestionsContract.java new file mode 100644 index 0000000..a7b9a23 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/QuestionsContract.java @@ -0,0 +1,34 @@ +package com.teester.whatsnearby.data.questions; + +public interface QuestionsContract { + + int getQuestion(); + + int getDrawable(); + + String getTag(); + + void setTag(String tag); + + String getAnswerYes(); + + void setAnswerYes(String answer_yes); + + String getAnswerNo(); + + void setAnswerNo(String answer_no); + + String getAnswerUnsure(); + + void setAnswerUnsure(String answer_unsure); + + int getIcon(); + + int getColor(); + + String getAnswer(String response); + + int getAnswerInt(String response); + + String checkPreviousAnswer(String answer); +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Reservation.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Reservation.java new file mode 100644 index 0000000..129a980 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Reservation.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Reservation extends Question { + + public Reservation() { + question = R.string.reservation; + drawable = R.drawable.ic_reserved; + color = R.color.purple; + tag = "reservation"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Takeaway.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Takeaway.java new file mode 100644 index 0000000..c5a8b79 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Takeaway.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Takeaway extends Question { + + public Takeaway() { + question = R.string.takeaway; + drawable = R.drawable.ic_takeaway; + color = R.color.purple; + tag = "takeaway"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Vegan.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Vegan.java new file mode 100644 index 0000000..ac6ce0e --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Vegan.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Vegan extends Question { + + public Vegan() { + question = R.string.vegan; + drawable = R.drawable.ic_carrot; + color = R.color.blue; + tag = "diet:vegan"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Vegetarian.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Vegetarian.java new file mode 100644 index 0000000..03fc136 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Vegetarian.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Vegetarian extends Question { + + public Vegetarian() { + question = R.string.vegetarian; + drawable = R.drawable.ic_carrot; + color = R.color.blue; + tag = "diet:vegetarian"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Wheelchair.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Wheelchair.java new file mode 100644 index 0000000..c1c2a62 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Wheelchair.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Wheelchair extends Question { + + public Wheelchair() { + question = R.string.wheelchair; + drawable = R.drawable.ic_wheelchair; + color = R.color.orange; + tag = "wheelchair"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/WheelchairToilets.java b/app/src/main/java/com/teester/whatsnearby/data/questions/WheelchairToilets.java new file mode 100644 index 0000000..cef4983 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/WheelchairToilets.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class WheelchairToilets extends Question { + + public WheelchairToilets() { + question = R.string.wheelchair_toilets; + drawable = R.drawable.ic_wheelchair; + color = R.color.orange; + tag = "toilets:wheelchair"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Wifi.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Wifi.java new file mode 100644 index 0000000..43a84ef --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Wifi.java @@ -0,0 +1,31 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Wifi extends Question { + + public Wifi() { + question = R.string.wifi; + drawable = R.drawable.ic_wifi; + color = R.color.orange; + tag = "internet_access"; + answer_yes = "wlan"; + } + + @Override + public String checkPreviousAnswer(String answer) { + String response; + switch (answer) { + case "wlan": + response = "yes"; + break; + case "": + response = "unsure"; + break; + default: + response = "no"; + break; + } + return super.checkPreviousAnswer(response); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/WifiFee.java b/app/src/main/java/com/teester/whatsnearby/data/questions/WifiFee.java new file mode 100644 index 0000000..f475686 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/WifiFee.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class WifiFee extends Question { + + public WifiFee() { + question = R.string.wifi_fee; + drawable = R.drawable.ic_wifi; + color = R.color.orange; + tag = "internet_access:fee"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/questions/Women.java b/app/src/main/java/com/teester/whatsnearby/data/questions/Women.java new file mode 100644 index 0000000..b5ba009 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/data/questions/Women.java @@ -0,0 +1,13 @@ +package com.teester.whatsnearby.data.questions; + +import com.teester.whatsnearby.R; + +public class Women extends Question { + + public Women() { + question = R.string.women; + drawable = R.drawable.ic_women; + color = R.color.red; + tag = "women"; + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/data/source/OAuth.java b/app/src/main/java/com/teester/whatsnearby/data/source/OAuth.java index c43454d..262b8fd 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/source/OAuth.java +++ b/app/src/main/java/com/teester/whatsnearby/data/source/OAuth.java @@ -5,6 +5,8 @@ import android.net.Uri; import android.provider.Browser; +import com.teester.whatsnearby.data.PreferenceList; + import oauth.signpost.OAuthConsumer; import oauth.signpost.OAuthProvider; import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; @@ -14,8 +16,8 @@ import oauth.signpost.exception.OAuthMessageSignerException; import oauth.signpost.exception.OAuthNotAuthorizedException; -public class OAuth implements SourceContract.OAuth { - private static final String TAG = OAuth.class.getSimpleName(); +public class OAuth implements SourceContract.oAuth { + private static final String CONSUMER_KEY = "1LJqwD4kMz96HTbv9I1U1XBM0AL1RpcjuFOPvW0B"; private static final String CONSUMER_SECRET = "KDCLveu82AZawLELpC6yIP3EI8fJa0JqF0ALukbl"; private static final String REQUEST_TOKEN_ENDPOINT_URL = "https://www.openstreetmap.org/oauth/request_token"; @@ -34,19 +36,19 @@ public OAuth(Context context) { @Override public void processOAuth() { - String verifier = preferences.getStringPreference("oauth_verifier"); - String token = preferences.getStringPreference("oauth_token"); - String tokenSecret = preferences.getStringPreference("oauth_token_secret"); + String verifier = preferences.getStringPreference(PreferenceList.OAUTH_VERIFIER); + String token = preferences.getStringPreference(PreferenceList.OAUTH_TOKEN); + String tokenSecret = preferences.getStringPreference(PreferenceList.OAUTH_TOKEN_SECRET); OAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); OAuthProvider provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_ENDPOINT_URL, ACCESS_TOKEN_ENDPOINT_URL, AUTHORIZE_WEBSITE_URL); try { - if (verifier == "") { + if ("".equals(verifier)) { String url = provider.retrieveRequestToken(consumer, CALLBACK_URL); - preferences.setStringPreference("oauth_token_secret", consumer.getTokenSecret()); - preferences.setStringPreference("oauth_token", consumer.getToken()); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN_SECRET, consumer.getTokenSecret()); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, consumer.getToken()); //Open the url in an external browser Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); @@ -58,9 +60,9 @@ public void processOAuth() { provider.setOAuth10a(true); provider.retrieveAccessToken(consumer, verifier); - preferences.setStringPreference("oauth_token_secret", consumer.getTokenSecret()); - preferences.setStringPreference("oauth_token", consumer.getToken()); - preferences.setBooleanPreference("logged_in_to_osm", true); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN_SECRET, consumer.getTokenSecret()); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, consumer.getToken()); + preferences.setBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM, true); } } catch (OAuthMessageSignerException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/teester/whatsnearby/data/source/Preferences.java b/app/src/main/java/com/teester/whatsnearby/data/source/Preferences.java index cb00705..20e4d12 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/source/Preferences.java +++ b/app/src/main/java/com/teester/whatsnearby/data/source/Preferences.java @@ -23,8 +23,9 @@ public boolean getBooleanPreference(String preference) { } @Override - public void setStringPreference(String preference, String value) { + public Void setStringPreference(String preference, String value) { prefs.edit().putString(preference, value).apply(); + return null; } @Override diff --git a/app/src/main/java/com/teester/whatsnearby/data/source/QueryOverpass.java b/app/src/main/java/com/teester/whatsnearby/data/source/QueryOverpass.java index db01a5a..f01b72b 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/source/QueryOverpass.java +++ b/app/src/main/java/com/teester/whatsnearby/data/source/QueryOverpass.java @@ -6,12 +6,13 @@ import com.teester.whatsnearby.Utilities; import com.teester.whatsnearby.data.Answers; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; import com.teester.whatsnearby.data.PoiList; import com.teester.whatsnearby.data.PoiTypes; -import com.teester.whatsnearby.data.localDatabase.AppDatabase; -import com.teester.whatsnearby.data.localDatabase.VisitedLocation; -import com.teester.whatsnearby.data.location.Notifier; +import com.teester.whatsnearby.data.PreferenceList; +import com.teester.whatsnearby.data.database.AppDatabase; +import com.teester.whatsnearby.data.database.VisitedLocation; +import com.teester.whatsnearby.data.location.LocationJobNotifier; +import com.teester.whatsnearby.data.pois.PoiContract; import org.json.JSONArray; import org.json.JSONException; @@ -29,10 +30,8 @@ public class QueryOverpass implements SourceContract.Overpass { - private static final String TAG = QueryOverpass.class.getSimpleName(); private double queryLatitude; private double queryLongitude; - private double queryAccuracy; private List poiList = new ArrayList(); private Context context; @@ -53,13 +52,16 @@ public QueryOverpass() { */ @Override public String getOverpassUri(double latitude, double longitude, float accuracy) { + float measuredAccuracy; if (accuracy < 20) { - accuracy = 20; + measuredAccuracy = 20; + } else { + measuredAccuracy = accuracy; } // Build the Overpass query // getting the centre of nodes, ways and relations a given radius around a location for different types - String overpassLocation = String.format("around:%s,%s,%s", accuracy, latitude, longitude); + String overpassLocation = String.format("around:%s,%s,%s", measuredAccuracy, latitude, longitude); String nwr = "%1$s[~\"^(%2$s)$\"~\".\"](%3$s);"; String types = "shop|amenity|leisure|tourism"; @@ -122,7 +124,7 @@ public void processResult(String result) { String type = getType(tags); - OsmObjectType poitype = PoiTypes.getPoiType(type); + PoiContract poitype = PoiTypes.getPoiType(type); if (poitype != null) { OsmObject object = new OsmObject(id, osmType, name, type, lat, lon, distance); Iterator keysIterator = tags.keys(); @@ -150,13 +152,12 @@ public void processResult(String result) { @Override public void queryOverpass(double latitude, double longitude, float accuracy) { SourceContract.Preferences preferences = new Preferences(context); - preferences.setLongPreference("last_query_time", System.currentTimeMillis()); - queryLatitude = latitude; - queryLongitude = longitude; - queryAccuracy = accuracy; + preferences.setLongPreference(PreferenceList.LAST_QUERY_TIME, System.currentTimeMillis()); + this.queryLatitude = latitude; + this.queryLongitude = longitude; String overpassUrl = getOverpassUri(latitude, longitude, accuracy); String overpassQuery = queryOverpassApi(overpassUrl); - preferences.setStringPreference("last_query", overpassQuery); + preferences.setStringPreference(PreferenceList.LAST_QUERY, overpassQuery); processResult(overpassQuery); } @@ -167,7 +168,7 @@ public void queryOverpass(double latitude, double longitude, float accuracy) { * @return - the location type * @throws JSONException - if it's not an amenity, shop, tourism or leisure */ - String getType(JSONObject tags) throws JSONException { + public String getType(JSONObject tags) throws JSONException { String type = ""; if (tags.has("amenity")) { type = tags.getString("amenity"); @@ -193,33 +194,36 @@ private void prepareNotification() { OsmObject poi = poiList.get(0); boolean recentlyVisited = checkDatabaseForLocation(poi.getId()); - OsmObjectType type = PoiTypes.getPoiType(poi.getType()); + PoiContract type = PoiTypes.getPoiType(poi.getType()); int drawable = type.getObjectIcon(); System.out.println(String.format("At %s before: %s", poi.getName(), recentlyVisited)); - if (recentlyVisited == false) { + if (!recentlyVisited) { updateDatabase(poi); - Notifier.createNotification(context, poi.getName(), drawable); + LocationJobNotifier.createNotification(context, poi.getName(), drawable); } } else { - Notifier.cancelNotifictions(context); + LocationJobNotifier.cancelNotifictions(context); } } private boolean checkDatabaseForLocation(long osmId) { + SourceContract.Preferences preferences = new Preferences(context); + if (BuildConfig.DEBUG && preferences.getBooleanPreference(PreferenceList.DEBUG_MODE)) { + return false; + } + AppDatabase db = AppDatabase.getAppDatabase(context); VisitedLocation location = db.visitedLocationDao().findByOsmId(osmId); List list = db.visitedLocationDao().getAllVisitedLocations(); + for (int i = 0; i < list.size(); i++) { - System.out.println("name: " + list.get(i).getName() + new Date(list.get(i).getTimeVisited())); + Date timeVisited = new Date(list.get(i).getTimeVisited()); + System.out.println(String.format("name: %s, Last visited: %s", list.get(i).getName(), timeVisited)); } - if (location != null) { - if (location.getTimeVisited() > System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000)) { - return true; - } - } - - return false; + long time = System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000); + boolean notifyOrNot = location != null && location.getTimeVisited() > time; + return notifyOrNot; } private void updateDatabase(OsmObject osmObject) { diff --git a/app/src/main/java/com/teester/whatsnearby/data/source/SourceContract.java b/app/src/main/java/com/teester/whatsnearby/data/source/SourceContract.java index eb31071..39228bc 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/source/SourceContract.java +++ b/app/src/main/java/com/teester/whatsnearby/data/source/SourceContract.java @@ -7,7 +7,7 @@ interface Preferences { boolean getBooleanPreference(String preference); - void setStringPreference(String preference, String value); + Void setStringPreference(String preference, String value); void setBooleanPreference(String preference, boolean value); @@ -35,12 +35,12 @@ interface Overpass { void queryOverpass(double latitude, double longitude, float accuracy); } - interface Upload { + interface upload { - void Upload(); + void uploadToOsm(); } - interface OAuth { + interface oAuth { void processOAuth(); } diff --git a/app/src/main/java/com/teester/whatsnearby/data/source/UploadToOSM.java b/app/src/main/java/com/teester/whatsnearby/data/source/UploadToOSM.java index 8e8199e..c5b2421 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/source/UploadToOSM.java +++ b/app/src/main/java/com/teester/whatsnearby/data/source/UploadToOSM.java @@ -1,6 +1,7 @@ package com.teester.whatsnearby.data.source; import com.teester.whatsnearby.data.Answers; +import com.teester.whatsnearby.data.PreferenceList; import java.util.Collections; import java.util.Iterator; @@ -18,13 +19,11 @@ * Handles uploading answers to OpenStreetMap */ -public class UploadToOSM implements SourceContract.Upload { - private static final String TAG = UploadToOSM.class.getSimpleName(); +public class UploadToOSM implements SourceContract.upload { private static final String CONSUMER_KEY = "1LJqwD4kMz96HTbv9I1U1XBM0AL1RpcjuFOPvW0B"; private static final String CONSUMER_SECRET = "KDCLveu82AZawLELpC6yIP3EI8fJa0JqF0ALukbl"; - private Element currentElement; private SourceContract.Preferences preferences; public UploadToOSM(SourceContract.Preferences preferences) { @@ -32,7 +31,7 @@ public UploadToOSM(SourceContract.Preferences preferences) { } @Override - public void Upload() { + public void uploadToOsm() { String type = Answers.getPoiType(); long id = Answers.getPoiId(); Map changesetTags = Answers.getChangesetTags(); @@ -50,16 +49,16 @@ public void Upload() { List collection = Collections.singletonList(modifiedElement); if (modifiedElement.isModified()) { try { - long upload = new MapDataDao(osm).updateMap(changesetTags, collection, null); + new MapDataDao(osm).updateMap(changesetTags, collection, null); } catch (OsmAuthorizationException e) { - //Log.i(TAG, e.toString()); + e.printStackTrace(); } } } private OsmConnection getConnection() { - String oauth_token_secret = preferences.getStringPreference("oauth_token_secret"); - String oauth_token = preferences.getStringPreference("oauth_token"); + String oauth_token_secret = preferences.getStringPreference(PreferenceList.OAUTH_TOKEN); + String oauth_token = preferences.getStringPreference(PreferenceList.OAUTH_TOKEN_SECRET); OAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); consumer.setTokenWithSecret(oauth_token, oauth_token_secret); @@ -95,7 +94,7 @@ private Element modifyCurrentElement(Element modifiedElement) { Map.Entry pair = it.next(); String key = pair.getKey(); String value = pair.getValue(); - if (value != "") { + if (!"".equals(value)) { modifiedElement.getTags().put(key, value); } } diff --git a/app/src/main/java/com/teester/whatsnearby/main/AboutPresenter.java b/app/src/main/java/com/teester/whatsnearby/main/AboutPresenter.java new file mode 100644 index 0000000..1f11e2a --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/main/AboutPresenter.java @@ -0,0 +1,30 @@ +package com.teester.whatsnearby.main; + +import com.teester.whatsnearby.BuildConfig; + +public class AboutPresenter implements MainActivityContract.AboutPresenter { + + private MainActivityContract.AboutView view; + + public AboutPresenter(MainActivityContract.AboutView view) { + this.view = view; + } + + @Override + public void findVersion() { + String version = BuildConfig.VERSION_NAME; + view.setVersion(version); + } + + @Override + public void getLicence() { + String uri = "http://www.gnu.org/licenses/gpl-3.0.html"; + view.visitUri(uri); + } + + @Override + public void getGitHub() { + String uri = "https://github.com/Teester/Whats-Nearby"; + view.visitUri(uri); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java b/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java index 3101ea0..3933632 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java @@ -1,6 +1,7 @@ package com.teester.whatsnearby.main; import com.teester.whatsnearby.R; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.SourceContract; import java.util.Locale; @@ -15,16 +16,6 @@ public DebugPresenter(MainActivityContract.DebugView view, SourceContract.Prefer this.preferences = preferences; } - @Override - public void init() { - - } - - @Override - public void destroy() { - - } - @Override public void getDetails() { getLastQuery(); @@ -37,7 +28,7 @@ public void getDetails() { } private void getQueryDistance() { - float preference = preferences.getFloatPreference("distance_to_last_location"); + float preference = preferences.getFloatPreference(PreferenceList.DISTANCE_TO_LAST_LOCATION); String querydistance = String.format(Locale.getDefault(), "%.0fm", preference); int color = R.color.green; if (preference < 20) { @@ -47,7 +38,7 @@ private void getQueryDistance() { } private void getLastQueryTime() { - long lastQueryTime = preferences.getLongPreference("last_query_time"); + long lastQueryTime = preferences.getLongPreference(PreferenceList.LAST_QUERY_TIME); long ago = (System.currentTimeMillis() - lastQueryTime) / 60000; String lastQueryTime2 = String.format(Locale.getDefault(), "%d mins ago", ago); int color = R.color.green; @@ -58,7 +49,7 @@ private void getLastQueryTime() { } private void getLastNotificationTime() { - long lastNotificationTime = preferences.getLongPreference("last_notification_time"); + long lastNotificationTime = preferences.getLongPreference(PreferenceList.LAST_NOTIFICATION_TIME); long ago = (System.currentTimeMillis() - lastNotificationTime) / 60000; int color = R.color.green; if (ago < 60) { @@ -69,7 +60,7 @@ private void getLastNotificationTime() { } private void getCheckDistance() { - float preference = preferences.getFloatPreference("distance_to_last_query"); + float preference = preferences.getFloatPreference(PreferenceList.DISTANCE_TO_LAST_QUERY); String checkdistance = String.format(Locale.getDefault(), "%.0fm", preference); int color = R.color.green; if (preference > 20) { @@ -79,12 +70,12 @@ private void getCheckDistance() { } private void getLastQuery() { - String lastQuery = preferences.getStringPreference("last_query"); + String lastQuery = preferences.getStringPreference(PreferenceList.LAST_QUERY); view.setLastQuery(lastQuery); } private void getAccuracy() { - float accuracy = preferences.getFloatPreference("location_accuracy"); + float accuracy = preferences.getFloatPreference(PreferenceList.LOCATION_ACCURACY); String accuracyString = String.format(Locale.getDefault(), "%.0fm", accuracy); int accuracyColor = R.color.green; if (accuracy > 50) { @@ -94,8 +85,8 @@ private void getAccuracy() { } public void getLocation() { - double latitude = preferences.getDoublePreference("latitude"); - double longitude = preferences.getDoublePreference("longitude"); + double latitude = preferences.getDoublePreference(PreferenceList.LATITUDE); + double longitude = preferences.getDoublePreference(PreferenceList.LONGITUDE); view.setLocation(latitude, longitude); } } diff --git a/app/src/main/java/com/teester/whatsnearby/main/FragmentAbout.java b/app/src/main/java/com/teester/whatsnearby/main/FragmentAbout.java new file mode 100644 index 0000000..7d3fadd --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/main/FragmentAbout.java @@ -0,0 +1,76 @@ +package com.teester.whatsnearby.main; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.teester.whatsnearby.R; + +public class FragmentAbout extends Fragment implements MainActivityContract.AboutView, View.OnClickListener { + + private TextView version; + private MainActivityContract.AboutPresenter aboutPresenter; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + aboutPresenter = new AboutPresenter(this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + return inflater.inflate(R.layout.fragment_about, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + this.version = view.findViewById(R.id.about_version_content); + + view.findViewById(R.id.about_licence_title).setOnClickListener(this); + view.findViewById(R.id.about_licence_content).setOnClickListener(this); + view.findViewById(R.id.about_licence_icon).setOnClickListener(this); + view.findViewById(R.id.about_source_title).setOnClickListener(this); + view.findViewById(R.id.about_source_content).setOnClickListener(this); + view.findViewById(R.id.about_source_icon).setOnClickListener(this); + + aboutPresenter.findVersion(); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.about_licence_content: + case R.id.about_authors_title: + case R.id.about_licence_icon: + aboutPresenter.getLicence(); + break; + case R.id.about_source_content: + case R.id.about_source_title: + case R.id.about_source_icon: + aboutPresenter.getGitHub(); + break; + default: + break; + } + } + + @Override + public void setVersion(String version) { + this.version.setText(version); + } + + @Override + public void visitUri(String uri) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(uri)); + startActivity(browserIntent); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java b/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java index 2d5b0bf..55700a4 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java +++ b/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java @@ -11,6 +11,7 @@ import android.widget.TextView; import com.teester.whatsnearby.R; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.data.source.SourceContract; @@ -26,7 +27,6 @@ public class FragmentDebug extends Fragment implements MainActivityContract.Debu private TextView checkdistance; private TextView lastLocation; private MainActivityContract.DebugPresenter debugPresenter; - private SourceContract.Preferences preferences; private SharedPreferences sharedPreferences; @Override @@ -48,13 +48,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - this.lastQueryTime = view.findViewById(R.id.textView6); - this.lastNotificationTime = view.findViewById(R.id.textView7); - this.lastQuery = view.findViewById(R.id.textView8); - this.accuracy = view.findViewById(R.id.textView16); - this.querydistance = view.findViewById(R.id.textView14); - this.checkdistance = view.findViewById(R.id.textView15); - this.lastLocation = view.findViewById(R.id.textView17); + this.lastQueryTime = view.findViewById(R.id.debug_last_overpass_query_value); + this.lastNotificationTime = view.findViewById(R.id.debug_last_notification_value); + this.lastQuery = view.findViewById(R.id.debug_last_overpass_query_result_value); + this.accuracy = view.findViewById(R.id.debug_accuracy_value); + this.querydistance = view.findViewById(R.id.debug_distance_since_last_query_value); + this.checkdistance = view.findViewById(R.id.debug_distance_since_last_location_check_value); + this.lastLocation = view.findViewById(R.id.debug_most_recent_location_value); debugPresenter.getDetails(); } @@ -111,22 +111,17 @@ public void setLocation(double latitude, double longitude) { this.lastLocation.setText(String.format(Locale.getDefault(), "%f, %f", latitude, longitude)); } - @Override - public void setPresenter(MainActivityContract.DebugPresenter presenter) { - - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { switch (s) { - case "latitude": - case "longitude": - case "distance_to_last_location": - case "last_query_time": - case "last_notification_time": - case "distance_to_last_query": - case "last_query": - case "location_accuracy": + case PreferenceList.LATITUDE: + case PreferenceList.LONGITUDE: + case PreferenceList.DISTANCE_TO_LAST_LOCATION: + case PreferenceList.LAST_QUERY_TIME: + case PreferenceList.LAST_NOTIFICATION_TIME: + case PreferenceList.DISTANCE_TO_LAST_QUERY: + case PreferenceList.LAST_QUERY: + case PreferenceList.LOCATION_ACCURACY: debugPresenter.getDetails(); break; default: diff --git a/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java b/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java index e478757..ad3366e 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java +++ b/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java @@ -1,6 +1,10 @@ package com.teester.whatsnearby.main; import android.Manifest; +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -20,7 +24,8 @@ import com.teester.whatsnearby.BuildConfig; import com.teester.whatsnearby.R; -import com.teester.whatsnearby.data.location.LocationService; +import com.teester.whatsnearby.data.PreferenceList; +import com.teester.whatsnearby.data.location.LocationJobService; import com.teester.whatsnearby.data.source.OAuth; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.data.source.SourceContract; @@ -33,12 +38,8 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener, MainActivityContract.View { - private static final String TAG = MainActivity.class.getSimpleName(); - private final String LOGGED_IN_PREF = "logged_in_to_osm"; - private TextView textView; private Button button; - private Toolbar toolbar; private MenuItem debugMenuItem; private SharedPreferences sharedPreferences; private MainActivityContract.Presenter mainPresenter; @@ -51,12 +52,11 @@ protected void onCreate(Bundle savedInstanceState) { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SourceContract.Preferences preferences = new Preferences(getApplicationContext()); mainPresenter = new MainActivityPresenter(this, preferences); - mainPresenter.init(); this.textView = this.findViewById(R.id.textView); this.button = this.findViewById(R.id.button); - this.toolbar = findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(this.toolbar); + setSupportActionBar(toolbar); this.button.setOnClickListener(this); checkPermission(); @@ -74,7 +74,7 @@ public boolean onCreateOptionsMenu(Menu menu) { if (!BuildConfig.DEBUG) { this.debugMenuItem.setVisible(false); } - toggleDebugMode(sharedPreferences.getBoolean("debug_mode", false)); + toggleDebugMode(sharedPreferences.getBoolean(PreferenceList.DEBUG_MODE, false)); return true; } @@ -93,6 +93,14 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_debug_mode: mainPresenter.toggleDebugMode(); return true; + case R.id.action_about: + Fragment aboutFragment = new FragmentAbout(); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.activity_main, aboutFragment) + .addToBackStack("debug") + .commit(); + return true; default: return super.onOptionsItemSelected(item); } @@ -130,15 +138,24 @@ private void checkPermission() { } private void startLocationService() { - Intent intent = new Intent(this, LocationService.class); - startService(intent); + + JobScheduler jobScheduler = (JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE); + ComponentName jobService = new ComponentName(getApplicationContext().getPackageName(), LocationJobService.class.getName()); + JobInfo jobInfo = new JobInfo.Builder(1, jobService) + .setPeriodic(60000) + .build(); + jobScheduler.schedule(jobInfo); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - Intent intent = new Intent(this, LocationService.class); - startService(intent); + JobScheduler jobScheduler = (JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE); + ComponentName jobService = new ComponentName(getApplicationContext().getPackageName(), LocationJobService.class.getName()); + JobInfo jobInfo = new JobInfo.Builder(1, jobService) + .setPeriodic(60000) + .build(); + jobScheduler.schedule(jobInfo); } @Override @@ -167,16 +184,16 @@ public void onClick(View view) { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { - if (s == LOGGED_IN_PREF) { + if (s.equals(PreferenceList.LOGGED_IN_TO_OSM)) { mainPresenter.showIfLoggedIn(); } - if (s == "debug_mode") { - toggleDebugMode(sharedPreferences.getBoolean("debug_mode", false)); + if (PreferenceList.DEBUG_MODE.equals(s)) { + toggleDebugMode(sharedPreferences.getBoolean(PreferenceList.DEBUG_MODE, false)); } } public void toggleDebugMode(boolean state) { - if (state == true) { + if (state) { this.debugMenuItem.setTitle("Debug Mode is on"); } else { this.debugMenuItem.setTitle("Debug Mode is off"); @@ -198,9 +215,4 @@ public void run() { } }).start(); } - - @Override - public void setPresenter(MainActivityContract.Presenter presenter) { - mainPresenter = presenter; - } } diff --git a/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java b/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java index c9e5247..5d25474 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java +++ b/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java @@ -1,13 +1,10 @@ package com.teester.whatsnearby.main; -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; - import java.net.URI; public interface MainActivityContract { - interface Presenter extends BasePresenter { + interface Presenter { void showIfLoggedIn(); @@ -19,20 +16,20 @@ interface Presenter extends BasePresenter { } - interface View extends BaseView { + interface View { void showIfLoggedIn(int message, int button); void startOAuth(); } - interface DebugPresenter extends BasePresenter { + interface DebugPresenter { void getDetails(); } - interface DebugView extends BaseView { + interface DebugView { void setLastQueryTime(String time, int color); @@ -48,4 +45,19 @@ interface DebugView extends BaseView { void setLocation(double latitude, double longitude); } + + interface AboutPresenter { + + void findVersion(); + + void getLicence(); + + void getGitHub(); + } + + interface AboutView { + void setVersion(String version); + + void visitUri(String uri); + } } \ No newline at end of file diff --git a/app/src/main/java/com/teester/whatsnearby/main/MainActivityPresenter.java b/app/src/main/java/com/teester/whatsnearby/main/MainActivityPresenter.java index d8a8bfa..d6f6e2a 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/MainActivityPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/main/MainActivityPresenter.java @@ -2,6 +2,7 @@ import com.teester.whatsnearby.R; import com.teester.whatsnearby.Utilities; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.SourceContract; import java.io.UnsupportedEncodingException; @@ -15,23 +16,12 @@ public class MainActivityPresenter implements MainActivityContract.Presenter { - private static final String TAG = MainActivityPresenter.class.getSimpleName(); - private SourceContract.Preferences preferences; private MainActivityContract.View view; public MainActivityPresenter(MainActivityContract.View view, SourceContract.Preferences preferences) { this.view = view; this.preferences = preferences; - //this.view.setPresenter(this); - } - - @Override - public void init() { - } - - @Override - public void destroy() { } /** @@ -39,10 +29,10 @@ public void destroy() { */ @Override public void showIfLoggedIn() { - boolean logged_in = preferences.getBooleanPreference("logged_in_to_osm"); + boolean loggedIn = preferences.getBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM); int message; int button; - if (logged_in == true) { + if (loggedIn) { message = R.string.logged_in_as; button = R.string.log_out; } else { @@ -62,10 +52,10 @@ public void checkIfOauth(URI uri) { if (uri != null) { try { Map> list = Utilities.splitQuery(uri); - String verifier = list.get("oauth_verifier").get(0); - String token = list.get("oauth_token").get(0); - preferences.setStringPreference("oauth_verifier", verifier); - preferences.setStringPreference("oauth_token", token); + String verifier = list.get(PreferenceList.OAUTH_VERIFIER).get(0); + String token = list.get(PreferenceList.OAUTH_TOKEN).get(0); + preferences.setStringPreference(PreferenceList.OAUTH_VERIFIER, verifier); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, token); view.startOAuth(); } catch (UnsupportedEncodingException e) { @@ -79,12 +69,12 @@ public void checkIfOauth(URI uri) { * then either do nothing if logging out or start oAuth if logging in. */ public void onButtonClicked() { - preferences.setStringPreference("oauth_verifier", ""); - preferences.setStringPreference("oauth_token", ""); - preferences.setStringPreference("oauth_token_secret", ""); + preferences.setStringPreference(PreferenceList.OAUTH_VERIFIER, ""); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, ""); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN_SECRET, ""); - if (preferences.getBooleanPreference("logged_in_to_osm") == true) { - preferences.setBooleanPreference("logged_in_to_osm", false); + if (preferences.getBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM)) { + preferences.setBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM, false); } else { view.startOAuth(); } @@ -93,9 +83,9 @@ public void onButtonClicked() { @Override public void toggleDebugMode() { - String preference = "debug_mode"; + String preference = PreferenceList.DEBUG_MODE; boolean debug = preferences.getBooleanPreference(preference); - if (debug == true) { + if (debug) { preferences.setBooleanPreference(preference, false); } else { preferences.setBooleanPreference(preference, true); diff --git a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivity.java b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivity.java index 46784ba..52e400d 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivity.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivity.java @@ -12,7 +12,7 @@ import com.teester.whatsnearby.R; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; +import com.teester.whatsnearby.data.pois.PoiContract; import com.teester.whatsnearby.data.source.OAuth; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.data.source.SourceContract; @@ -32,11 +32,8 @@ public class QuestionsActivity extends AppCompatActivity QuestionFragment.OnFragmentInteractionListener, IntroFragment.OnFragmentInteractionListener { - private static final String TAG = QuestionsActivity.class.getSimpleName(); - private NonSwipeableViewPager viewPager; private TextView textView; - private QuestionsActivityContract.Presenter questionsPresenter; @Override @@ -49,7 +46,6 @@ protected void onCreate(Bundle savedInstanceState) { SourceContract.Preferences preferences = new Preferences(getApplicationContext()); questionsPresenter = new QuestionsPresenter(this, preferences); - questionsPresenter.init(); NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); @@ -97,7 +93,7 @@ public void newPlaceClicked(View v) { } @Override - public void setViewPager(OsmObject poi, OsmObjectType listOfQuestions) { + public void setViewPager(OsmObject poi, PoiContract listOfQuestions) { FragmentPagerAdapter adapterViewPager = new MyPagerAdapter(getSupportFragmentManager(), poi, listOfQuestions, getApplicationContext()); viewPager.setAdapter(adapterViewPager); } @@ -128,13 +124,8 @@ public void run() { }).start(); } - @Override - public void setPresenter(QuestionsActivityContract.Presenter presenter) { - questionsPresenter = presenter; - } - @Override public void onNotHereFragmentInteraction() { - + // required empty method } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivityContract.java b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivityContract.java index 30cf4cb..3749710 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivityContract.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsActivityContract.java @@ -1,24 +1,22 @@ package com.teester.whatsnearby.questions; -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; +import com.teester.whatsnearby.data.pois.PoiContract; import java.net.URI; public interface QuestionsActivityContract { - interface Presenter extends BasePresenter { + interface Presenter { void addPoiNameToTextview(); void assessIntentData(URI uri); } - interface View extends BaseView { + interface View { - void setViewPager(OsmObject osmObject, OsmObjectType listOfQuestions); + void setViewPager(OsmObject osmObject, PoiContract listOfQuestions); void startNewActivity(); diff --git a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsPresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsPresenter.java index 3dc8844..ceb26ec 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/QuestionsPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/QuestionsPresenter.java @@ -3,9 +3,10 @@ import com.teester.whatsnearby.Utilities; import com.teester.whatsnearby.data.Answers; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; import com.teester.whatsnearby.data.PoiList; import com.teester.whatsnearby.data.PoiTypes; +import com.teester.whatsnearby.data.PreferenceList; +import com.teester.whatsnearby.data.pois.PoiContract; import com.teester.whatsnearby.data.source.SourceContract; import java.io.UnsupportedEncodingException; @@ -24,23 +25,14 @@ public QuestionsPresenter(QuestionsActivityContract.View view, SourceContract.Pr Answers.clearAnswerList(); } - @Override - public void init() { - } - - @Override - public void destroy() { - - } - @Override public void addPoiNameToTextview() { List poiList = PoiList.getInstance().getPoiList(); String poiType = poiList.get(0).getType(); - OsmObjectType listOfQuestions = PoiTypes.getPoiType(poiType); + PoiContract listOfQuestions = PoiTypes.getPoiType(poiType); listOfQuestions.shuffleQuestions(); - if (preferences.getBooleanPreference("logged_in_to_osm") == true) { + if (preferences.getBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM)) { view.setViewPager(poiList.get(0), listOfQuestions); if (poiList.size() == 1) { view.makeTextViewInvisible(); @@ -57,10 +49,10 @@ public void assessIntentData(URI uri) { if (uri != null) { try { Map> list = Utilities.splitQuery(uri); - String verifier = list.get("oauth_verifier").get(0); - String token = list.get("oauth_token").get(0); - preferences.setStringPreference("oauth_verifier", verifier); - preferences.setStringPreference("oauth_token", token); + String verifier = list.get(PreferenceList.OAUTH_VERIFIER).get(0); + String token = list.get(PreferenceList.OAUTH_TOKEN).get(0); + preferences.setStringPreference(PreferenceList.OAUTH_VERIFIER, verifier); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, token); view.startOAuth(); } catch (UnsupportedEncodingException e) { diff --git a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragment.java b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragment.java index eeb2259..bed1a3d 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragment.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragment.java @@ -17,12 +17,11 @@ public class IntroFragment extends Fragment implements View.OnClickListener, IntroFragmentContract.View { - private TextView intro_name; - private TextView intro_address; - private ImageView intro_imageView; - private Button intro_button; + private TextView introName; + private TextView introAddress; + private ImageView introImageView; private IntroFragmentContract.Presenter introPresenter; - private OnFragmentInteractionListener mListener; + private OnFragmentInteractionListener listener; @NonNull public static IntroFragment newInstance(OsmObject poi) { @@ -33,7 +32,6 @@ public static IntroFragment newInstance(OsmObject poi) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); introPresenter = new IntroPresenter(this); - introPresenter.init(); } @Nullable @@ -47,19 +45,19 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - this.intro_name = view.findViewById(R.id.intro_name); - this.intro_address = view.findViewById(R.id.intro_address); - this.intro_imageView = view.findViewById(R.id.intro_image); - this.intro_button = view.findViewById(R.id.intro_button); + this.introName = view.findViewById(R.id.intro_name); + this.introAddress = view.findViewById(R.id.intro_address); + this.introImageView = view.findViewById(R.id.intro_image); + Button introButton = view.findViewById(R.id.intro_button); - this.intro_button.setOnClickListener(this); + introButton.setOnClickListener(this); } @Override - public void ShowDetails(String name, String address, int drawable) { - this.intro_name.setText(name); - this.intro_address.setText(address); - this.intro_imageView.setImageResource(drawable); + public void showDetails(String name, String address, int drawable) { + this.introName.setText(name); + this.introAddress.setText(address); + this.introImageView.setImageResource(drawable); } @Override @@ -72,9 +70,9 @@ public void onResume() { public void onAttach(Context context) { super.onAttach(context); if (context instanceof IntroFragment.OnFragmentInteractionListener) { - mListener = (IntroFragment.OnFragmentInteractionListener) context; + listener = (IntroFragment.OnFragmentInteractionListener) context; } else { - throw new RuntimeException(context.toString() + throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } } @@ -82,16 +80,11 @@ public void onAttach(Context context) { @Override public void onDetach() { super.onDetach(); - mListener = null; + listener = null; } @Override public void onClick(View v) { - mListener.onIntroFragmentInteraction(); - } - - @Override - public void setPresenter(IntroFragmentContract.Presenter presenter) { - + listener.onIntroFragmentInteraction(); } public interface OnFragmentInteractionListener { diff --git a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragmentContract.java b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragmentContract.java index 0bd91e9..64eac44 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragmentContract.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroFragmentContract.java @@ -1,16 +1,12 @@ package com.teester.whatsnearby.questions.intro; -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; - - public interface IntroFragmentContract { - interface Presenter extends BasePresenter { + interface Presenter { void getDetails(); } - interface View extends BaseView { - void ShowDetails(String name, String address, int drawable); + interface View { + void showDetails(String name, String address, int drawable); } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroPresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroPresenter.java index 0675488..72c53d3 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/intro/IntroPresenter.java @@ -27,16 +27,7 @@ private String getAddress() { @Override public void getDetails() { String address = getAddress(); - view.ShowDetails(poi.getName(), address, poi.getDrawable()); + view.showDetails(poi.getName(), address, poi.getDrawable()); } - @Override - public void init() { - - } - - @Override - public void destroy() { - - } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragment.java b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragment.java index 5c7f263..f751f62 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragment.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragment.java @@ -22,18 +22,12 @@ public class NotHereFragment extends Fragment implements NotHereFragmentContract.View { - private static final String TAG = NotHereFragment.class.getSimpleName(); - private RecyclerView recyclerView; private TextView textView; private NotHereFragmentContract.Presenter notHerePresenter; private OnFragmentInteractionListener mListener; - public NotHereFragment() { - // Required empty public constructor - } - public static NotHereFragment newInstance() { return new NotHereFragment(); } @@ -76,7 +70,7 @@ public void onAttach(Context context) { if (context instanceof OnFragmentInteractionListener) { mListener = (OnFragmentInteractionListener) context; } else { - throw new RuntimeException(context.toString() + throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } } @@ -107,11 +101,6 @@ public void startActivity() { startActivity(intent); } - @Override - public void setPresenter(NotHereFragmentContract.Presenter presenter) { - notHerePresenter = presenter; - } - public interface OnFragmentInteractionListener { void onNotHereFragmentInteraction(); } @@ -125,7 +114,7 @@ public PoiAdapter(List poiList) { @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(getContext()).inflate(R.layout.poi_list_item, parent, false); + View view = LayoutInflater.from(getContext()).inflate(R.layout.list_item_poi, parent, false); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -159,7 +148,7 @@ public class ViewHolder extends RecyclerView.ViewHolder { public ViewHolder(View view) { super(view); name = view.findViewById(R.id.name); - type = view.findViewById(R.id.type); + type = view.findViewById(R.id.about_list_content); distance = view.findViewById(R.id.distance); image = view.findViewById(R.id.type_icon); } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragmentContract.java b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragmentContract.java index 1675f00..0dd5597 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragmentContract.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHereFragmentContract.java @@ -1,20 +1,18 @@ package com.teester.whatsnearby.questions.nothere; -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; import com.teester.whatsnearby.data.OsmObject; import java.util.List; public interface NotHereFragmentContract { - interface Presenter extends BasePresenter { + interface Presenter { void getPoiDetails(); void onItemClicked(int i); } - interface View extends BaseView { + interface View { void setTextview(String string); diff --git a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHerePresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHerePresenter.java index 0c2b081..ba0f159 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHerePresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/nothere/NotHerePresenter.java @@ -8,9 +8,9 @@ public class NotHerePresenter implements NotHereFragmentContract.Presenter { - NotHereFragmentContract.View view; - List poiList; - List alternateList; + private NotHereFragmentContract.View view; + private List poiList; + private List alternateList; public NotHerePresenter(NotHereFragmentContract.View view) { this.view = view; @@ -32,14 +32,4 @@ public void onItemClicked(int i) { PoiList.getInstance().setPoiList(intentList); view.startActivity(); } - - @Override - public void init() { - - } - - @Override - public void destroy() { - - } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragment.java b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragment.java index 8f6e29f..4b55923 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragment.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragment.java @@ -26,14 +26,8 @@ */ public class OsmLoginFragment extends Fragment implements View.OnClickListener, OsmLoginFragmentContract.View { - private static final String TAG = OsmLoginFragment.class.getSimpleName(); - private OsmLoginFragmentContract.Presenter osmLoginPresenter; - private OnFragmentInteractionListener mListener; - - public OsmLoginFragment() { - // Required empty public constructor - } + private OnFragmentInteractionListener listener; /** * Use this factory method to create a new instance of @@ -68,8 +62,8 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { } public void onButtonPressed(Uri uri) { - if (mListener != null) { - mListener.onOsmLoginFragmentInteraction(uri); + if (listener != null) { + listener.onOsmLoginFragmentInteraction(uri); } } @@ -77,9 +71,9 @@ public void onButtonPressed(Uri uri) { public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnFragmentInteractionListener) { - mListener = (OnFragmentInteractionListener) context; + listener = (OnFragmentInteractionListener) context; } else { - throw new RuntimeException(context.toString() + throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } } @@ -87,13 +81,13 @@ public void onAttach(Context context) { @Override public void onDetach() { super.onDetach(); - mListener = null; + listener = null; } @Override public void onClick(View view) { if (view.getId() == R.id.osmLoginButton) { - osmLoginPresenter.ClickedOsmLoginButton(); + osmLoginPresenter.clickedOsmLoginButton(); } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragmentContract.java b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragmentContract.java index ae97322..ce30ca9 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragmentContract.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginFragmentContract.java @@ -4,7 +4,7 @@ interface OsmLoginFragmentContract { interface Presenter { - void ClickedOsmLoginButton(); + void clickedOsmLoginButton(); } interface View { diff --git a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenter.java index a4f3d02..e20859d 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenter.java @@ -1,5 +1,6 @@ package com.teester.whatsnearby.questions.osmlogin; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.SourceContract; class OsmLoginPresenter implements OsmLoginFragmentContract.Presenter { @@ -7,16 +8,16 @@ class OsmLoginPresenter implements OsmLoginFragmentContract.Presenter { private OsmLoginFragmentContract.View view; private SourceContract.Preferences preferences; - public OsmLoginPresenter(OsmLoginFragment view, SourceContract.Preferences preferences) { + public OsmLoginPresenter(OsmLoginFragmentContract.View view, SourceContract.Preferences preferences) { this.view = view; this.preferences = preferences; } @Override - public void ClickedOsmLoginButton() { - preferences.setStringPreference("oauth_verifier", ""); - preferences.setStringPreference("oauth_token", ""); - preferences.setStringPreference("oauth_token_secret", ""); + public void clickedOsmLoginButton() { + preferences.setStringPreference(PreferenceList.OAUTH_VERIFIER, ""); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN, ""); + preferences.setStringPreference(PreferenceList.OAUTH_TOKEN_SECRET, ""); view.startOAuth(); } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragment.java b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragment.java index ee936cb..501e46b 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragment.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragment.java @@ -16,10 +16,9 @@ import com.teester.whatsnearby.R; import com.teester.whatsnearby.data.Answers; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; +import com.teester.whatsnearby.data.pois.PoiContract; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.questions.QuestionsActivity; -import com.teester.whatsnearby.questions.QuestionsPresenter; import java.util.HashMap; import java.util.Map; @@ -36,24 +35,18 @@ public class QuestionFragment extends Fragment implements View.OnClickListener, QuestionFragmentContract.View { protected static final String ARG_PARAM1 = "param1"; - private static final String TAG = QuestionFragment.class.getSimpleName(); - QuestionsPresenter presenter; private OnFragmentInteractionListener mListener; private QuestionFragmentContract.Presenter questionPresenter; - private TextView question_textView; - private ImageView question_imageView; - private TextView question_previous_textView; - private Button answer_yes; - private Button answer_no; - private Button answer_unsure; + private TextView questionTextView; + private ImageView questionImageView; + private TextView questionPreviousTextView; + private Button answerYes; + private Button answerNo; + private Button answerUnsure; private int position; - public QuestionFragment() { - // Required empty public constructor - } - /** * Use this factory method to create a new instance of * this fragment using the provided parameters. @@ -61,7 +54,7 @@ public QuestionFragment() { * @param param1 Parameter 1. * @return A new instance of fragment QuestionFragment. */ - public static QuestionFragment newInstance(OsmObject poi, int position, OsmObjectType listOfQuestions) { + public static QuestionFragment newInstance(OsmObject poi, int position, PoiContract listOfQuestions) { QuestionFragment fragment = new QuestionFragment(); Bundle args = new Bundle(); args.putInt(ARG_PARAM1, position); @@ -79,7 +72,6 @@ public void onCreate(Bundle savedInstanceState) { Preferences preferences = new Preferences(getContext()); questionPresenter = new QuestionPresenter(this, position, preferences); - questionPresenter.init(); } @Override @@ -92,16 +84,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - this.question_textView = view.findViewById(R.id.question_textview); - this.question_imageView = view.findViewById(R.id.question_imageView); - this.question_previous_textView = view.findViewById(R.id.question_previous_answers); - this.answer_yes = view.findViewById(R.id.answer_yes); - this.answer_no = view.findViewById(R.id.answer_no); - this.answer_unsure = view.findViewById(R.id.answer_unsure); - - this.answer_yes.setOnClickListener(this); - this.answer_no.setOnClickListener(this); - this.answer_unsure.setOnClickListener(this); + this.questionTextView = view.findViewById(R.id.question_textview); + this.questionImageView = view.findViewById(R.id.question_imageView); + this.questionPreviousTextView = view.findViewById(R.id.question_previous_answers); + this.answerYes = view.findViewById(R.id.answer_yes); + this.answerNo = view.findViewById(R.id.answer_no); + this.answerUnsure = view.findViewById(R.id.answer_unsure); + + this.answerYes.setOnClickListener(this); + this.answerNo.setOnClickListener(this); + this.answerUnsure.setOnClickListener(this); } @Override @@ -116,7 +108,7 @@ public void onAttach(Context context) { if (context instanceof OnFragmentInteractionListener) { mListener = (OnFragmentInteractionListener) context; } else { - throw new RuntimeException(context.toString() + throw new ClassCastException(context.toString() + " must implement OnFragmentInteractionListener"); } } @@ -140,27 +132,27 @@ public void onClick(View v) { @Override public void showQuestion(int question, String name, int color, int drawable) { int colorResource = ContextCompat.getColor(getContext(), color); - question_textView.setBackgroundColor(colorResource); - question_imageView.setBackgroundTintList(ContextCompat.getColorStateList(this.getContext(), color)); - question_previous_textView.setBackgroundColor(colorResource); + questionTextView.setBackgroundColor(colorResource); + questionImageView.setBackgroundTintList(ContextCompat.getColorStateList(this.getContext(), color)); + questionPreviousTextView.setBackgroundColor(colorResource); - question_textView.setText(String.format(getString(question), name)); + questionTextView.setText(String.format(getString(question), name)); // Not every question has a drawable if (drawable == 0) { - this.question_imageView.setImageResource(R.drawable.ic_unsure); + this.questionImageView.setImageResource(R.drawable.ic_unsure); } else { - this.question_imageView.setImageResource(drawable); - this.question_imageView.setColorFilter(ContextCompat.getColor(getContext(), R.color.white)); + this.questionImageView.setImageResource(drawable); + this.questionImageView.setColorFilter(ContextCompat.getColor(getContext(), R.color.white)); } } @Override public void setPreviousAnswer(String answer) { - if (answer == "") { - question_previous_textView.setVisibility(View.GONE); + if ("".equals(answer)) { + questionPreviousTextView.setVisibility(View.GONE); } else { - question_previous_textView.setText(String.format(getString(R.string.others_have_answered_this_question), answer)); + questionPreviousTextView.setText(String.format(getString(R.string.others_have_answered_this_question), answer)); } } @@ -172,14 +164,9 @@ public void makeActivityTextViewInvisible() { @Override public void setBackgroundColor(int yes, int no, int unsure) { - this.answer_yes.setBackgroundColor(ContextCompat.getColor(getContext(), yes)); - this.answer_no.setBackgroundColor(ContextCompat.getColor(getContext(), no)); - this.answer_unsure.setBackgroundColor(ContextCompat.getColor(getContext(), unsure)); - } - - @Override - public void setPresenter(QuestionFragmentContract.Presenter presenter) { - questionPresenter = presenter; + this.answerYes.setBackgroundColor(ContextCompat.getColor(getContext(), yes)); + this.answerNo.setBackgroundColor(ContextCompat.getColor(getContext(), no)); + this.answerUnsure.setBackgroundColor(ContextCompat.getColor(getContext(), unsure)); } @Override diff --git a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragmentContract.java b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragmentContract.java index cd94d0c..7dce38d 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragmentContract.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionFragmentContract.java @@ -1,20 +1,15 @@ package com.teester.whatsnearby.questions.question; -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; - public interface QuestionFragmentContract { - interface Presenter extends BasePresenter { + interface Presenter { void getQuestion(); - void getPreviousAnswer(String key); - void onAnswerSelected(int id); } - interface View extends BaseView { + interface View { void showQuestion(int question, String name, int color, int drawable); diff --git a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionPresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionPresenter.java index 20a081f..86ec35b 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/question/QuestionPresenter.java @@ -3,10 +3,10 @@ import com.teester.whatsnearby.R; import com.teester.whatsnearby.data.Answers; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; import com.teester.whatsnearby.data.PoiList; import com.teester.whatsnearby.data.PoiTypes; -import com.teester.whatsnearby.data.QuestionObject; +import com.teester.whatsnearby.data.pois.PoiContract; +import com.teester.whatsnearby.data.questions.QuestionsContract; import com.teester.whatsnearby.data.source.SourceContract; import com.teester.whatsnearby.data.source.UploadToOSM; @@ -17,7 +17,7 @@ public class QuestionPresenter implements QuestionFragmentContract.Presenter { private int position; private QuestionFragmentContract.View view; private OsmObject poi; - private OsmObjectType listOfQuestions; + private PoiContract listOfQuestions; private SourceContract.Preferences preferences; public QuestionPresenter(QuestionFragmentContract.View view, int position, SourceContract.Preferences preferences) { @@ -30,15 +30,15 @@ public QuestionPresenter(QuestionFragmentContract.View view, int position, Sourc @Override public void getQuestion() { - List questions = this.listOfQuestions.getQuestionObjects(); - QuestionObject questionObject = questions.get(position); + List questions = this.listOfQuestions.getQuestion(); + QuestionsContract questionsContract = questions.get(position); - int question = questionObject.getQuestion(); - int color = questionObject.getColor(); - int drawable = questionObject.getIcon(); + int question = questionsContract.getQuestion(); + int color = questionsContract.getColor(); + int drawable = questionsContract.getIcon(); view.showQuestion(question, poi.getName(), color, drawable); - String key = questionObject.getTag(); + String key = questionsContract.getTag(); String answer = poi.getTag(key); if (answer != null) { view.setPreviousAnswer(answer); @@ -47,15 +47,13 @@ public void getQuestion() { } } - @Override - public void getPreviousAnswer(String key) { - } - @Override public void onAnswerSelected(int id) { - List questions = listOfQuestions.getQuestionObjects(); - QuestionObject questionObject = questions.get(position); - int selectedColor = questionObject.getColor(); + + List questions = this.listOfQuestions.getQuestion(); + QuestionsContract questionsContract = questions.get(position); + + int selectedColor = questionsContract.getColor(); int unselectedColor = R.color.colorPrimary; String answer = null; switch (id) { @@ -75,8 +73,8 @@ public void onAnswerSelected(int id) { break; } - String answerTag = questionObject.getAnswer(answer); - String questionTag = questionObject.getTag(); + String answerTag = questionsContract.getAnswer(answer); + String questionTag = questionsContract.getTag(); addAnswer(questionTag, answerTag); if (position == listOfQuestions.getNoOfQuestions() - 1) { @@ -84,8 +82,8 @@ public void onAnswerSelected(int id) { new Thread(new Runnable() { @Override public void run() { - SourceContract.Upload upload = new UploadToOSM(preferences); - upload.Upload(); + SourceContract.upload upload = new UploadToOSM(preferences); + upload.uploadToOsm(); } }).start(); } @@ -97,14 +95,4 @@ private void addAnswer(String questionTag, String answerTag) { } Answers.addAnswer(questionTag, answerTag); } - - @Override - public void init() { - - } - - @Override - public void destroy() { - - } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragment.java b/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragment.java index 4d860f2..a1ee21b 100644 --- a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragment.java +++ b/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragment.java @@ -7,8 +7,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; import com.teester.whatsnearby.R; @@ -16,30 +14,15 @@ * Fragment to upload to osm */ -public class UploadFragment extends Fragment implements View.OnClickListener, UploadFragmentContract.View { - - private static final String TAG = UploadFragment.class.getSimpleName(); - -// private OnFragmentInteractionListener mListener; - - private TextView thanks_textview; - private ImageView thanks_imageView; - private Button authorise; - private UploadFragmentContract.Presenter uploadPresenter; - - public UploadFragment() { - // Required empty public constructor - } +public class UploadFragment extends Fragment implements View.OnClickListener { public static UploadFragment newInstance() { return new UploadFragment(); } - @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - uploadPresenter = new UploadPresenter(this); } @Override @@ -52,41 +35,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - this.thanks_textview = view.findViewById(R.id.thanks_textview); - this.thanks_imageView = view.findViewById(R.id.thanks_imageView); - this.authorise = view.findViewById(R.id.authorise); + Button authorise = view.findViewById(R.id.authorise); - this.authorise.setOnClickListener(this); + authorise.setOnClickListener(this); } -// -// @Override -// public void onAttach(Context context) { -// super.onAttach(context); -// if (context instanceof OnFragmentInteractionListener) { -// mListener = (OnFragmentInteractionListener) context; -// } else { -// throw new RuntimeException(context.toString() -// + " must implement OnFragmentInteractionListener"); -// } -// } -// -// @Override -// public void onDetach() { -// super.onDetach(); -// mListener = null; -// } @Override public void onClick(View view) { getActivity().finish(); } - @Override - public void setPresenter(UploadFragmentContract.Presenter presenter) { - uploadPresenter = presenter; - } - -// public interface OnFragmentInteractionListener { -// void onUploadFragmentInteraction(); -// } } diff --git a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragmentContract.java b/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragmentContract.java deleted file mode 100644 index 756967f..0000000 --- a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadFragmentContract.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.teester.whatsnearby.questions.upload; - -import com.teester.whatsnearby.BasePresenter; -import com.teester.whatsnearby.BaseView; - -interface UploadFragmentContract { - - interface Presenter extends BasePresenter { - - } - - interface View extends BaseView { - - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadPresenter.java b/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadPresenter.java deleted file mode 100644 index 6c5c643..0000000 --- a/app/src/main/java/com/teester/whatsnearby/questions/upload/UploadPresenter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.teester.whatsnearby.questions.upload; - -public class UploadPresenter implements UploadFragmentContract.Presenter { - - private UploadFragmentContract.View view; - - public UploadPresenter(UploadFragmentContract.View view) { - this.view = view; - } - - @Override - public void init() { - - } - - @Override - public void destroy() { - - } -} diff --git a/app/src/main/java/com/teester/whatsnearby/view/MyPagerAdapter.java b/app/src/main/java/com/teester/whatsnearby/view/MyPagerAdapter.java index c5bec63..1453dc3 100644 --- a/app/src/main/java/com/teester/whatsnearby/view/MyPagerAdapter.java +++ b/app/src/main/java/com/teester/whatsnearby/view/MyPagerAdapter.java @@ -6,25 +6,24 @@ import android.support.v4.app.FragmentPagerAdapter; import com.teester.whatsnearby.data.OsmObject; -import com.teester.whatsnearby.data.OsmObjectType; +import com.teester.whatsnearby.data.pois.PoiContract; +import com.teester.whatsnearby.data.PreferenceList; import com.teester.whatsnearby.data.source.Preferences; import com.teester.whatsnearby.questions.question.QuestionFragment; import com.teester.whatsnearby.questions.upload.UploadFragment; public class MyPagerAdapter extends FragmentPagerAdapter { - private static final String TAG = MyPagerAdapter.class.getSimpleName(); - - public OsmObjectType listOfQuestions; + public PoiContract listOfQuestions; private OsmObject poi; private int count; - public MyPagerAdapter(FragmentManager fragmentManager, OsmObject poi, OsmObjectType listOfQuestions, Context context) { + public MyPagerAdapter(FragmentManager fragmentManager, OsmObject poi, PoiContract listOfQuestions, Context context) { super(fragmentManager); this.poi = poi; this.listOfQuestions = listOfQuestions; - boolean logged_in = new Preferences(context).getBooleanPreference("logged_in_to_osm"); - if (logged_in == true) { + boolean logged_in = new Preferences(context).getBooleanPreference(PreferenceList.LOGGED_IN_TO_OSM); + if (logged_in) { this.count = listOfQuestions.getNoOfQuestions() + 1; } else { this.count = 1; diff --git a/app/src/main/res/drawable/ic_open_in_browser.xml b/app/src/main/res/drawable/ic_open_in_browser.xml new file mode 100644 index 0000000..ce91234 --- /dev/null +++ b/app/src/main/res/drawable/ic_open_in_browser.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 0000000..04b7d40 --- /dev/null +++ b/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_debug.xml b/app/src/main/res/layout/fragment_debug.xml index 71b98d1..fe9526a 100644 --- a/app/src/main/res/layout/fragment_debug.xml +++ b/app/src/main/res/layout/fragment_debug.xml @@ -17,147 +17,160 @@ android:layout_height="wrap_content"> + app:layout_constraintStart_toStartOf="@+id/debug_distance_since_last_location_check_title" + app:layout_constraintTop_toBottomOf="@+id/debug_distance_since_last_location_check_title"/> + app:layout_constraintEnd_toEndOf="@+id/debug_last_overpass_query_title" + app:layout_constraintStart_toStartOf="@+id/debug_last_overpass_query_title" + app:layout_constraintTop_toBottomOf="@+id/debug_last_overpass_query_title"/> + app:layout_constraintStart_toStartOf="@+id/debug_last_notification_title" + app:layout_constraintTop_toBottomOf="@+id/debug_last_notification_title"/> + app:layout_constraintStart_toStartOf="@+id/debug_last_overpass_query_result_title" + app:layout_constraintTop_toBottomOf="@+id/debug_last_overpass_query_result_title"/> + app:layout_constraintTop_toBottomOf="@+id/debug_toolbar"/> + app:layout_constraintStart_toStartOf="@+id/debug_most_recent_location_title" + app:layout_constraintTop_toBottomOf="@+id/debug_most_recent_location_title"/> + app:layout_constraintStart_toStartOf="@+id/debug_accuracy_title" + app:layout_constraintTop_toBottomOf="@+id/debug_accuracy_title"/> + app:layout_constraintStart_toStartOf="@+id/debug_distance_since_last_query_title" + app:layout_constraintTop_toBottomOf="@+id/debug_distance_since_last_query_title"/> + app:layout_constraintStart_toStartOf="@+id/debug_last_location_details_title" + app:layout_constraintTop_toBottomOf="@+id/debug_last_location_details_title"/> + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_not_here.xml b/app/src/main/res/layout/fragment_not_here.xml index 09b9809..0ed33d4 100644 --- a/app/src/main/res/layout/fragment_not_here.xml +++ b/app/src/main/res/layout/fragment_not_here.xml @@ -49,6 +49,6 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/question_textview" - tools:listitem="@layout/poi_list_item"/> + tools:listitem="@layout/list_item_poi"/> \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_about.xml b/app/src/main/res/layout/list_item_about.xml new file mode 100644 index 0000000..494560a --- /dev/null +++ b/app/src/main/res/layout/list_item_about.xml @@ -0,0 +1,36 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/poi_list_item.xml b/app/src/main/res/layout/list_item_poi.xml similarity index 95% rename from app/src/main/res/layout/poi_list_item.xml rename to app/src/main/res/layout/list_item_poi.xml index 44d01c0..fa7b8ab 100644 --- a/app/src/main/res/layout/poi_list_item.xml +++ b/app/src/main/res/layout/list_item_poi.xml @@ -33,7 +33,7 @@ tools:text="@string/app_name"/> \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main_menu.xml b/app/src/main/res/menu/activity_main_menu.xml index a19ff55..261ba1f 100644 --- a/app/src/main/res/menu/activity_main_menu.xml +++ b/app/src/main/res/menu/activity_main_menu.xml @@ -7,6 +7,10 @@ app:showAsAction="never"/> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 790a3ba..f954760 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,5 +66,15 @@ Distance since last location check See Debug Data Most recent location: + Debug Mode + About What\'s Nearby + Version + Authors + Licence + GNU General Public Licence Version 3 + Source Repository + What\'s Nearby on Github + © 2017–2018 Mark Tully + Debug Details diff --git a/app/src/test/java/com/teester/whatsnearby/ExampleUnitTest.java b/app/src/test/java/com/teester/whatsnearby/ExampleUnitTest.java index b5b85d1..2de9868 100644 --- a/app/src/test/java/com/teester/whatsnearby/ExampleUnitTest.java +++ b/app/src/test/java/com/teester/whatsnearby/ExampleUnitTest.java @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void additionIsCorrect() throws Exception { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/app/src/test/java/com/teester/whatsnearby/UtilitiesTest.java b/app/src/test/java/com/teester/whatsnearby/UtilitiesTest.java index daa7592..fc7b5dc 100644 --- a/app/src/test/java/com/teester/whatsnearby/UtilitiesTest.java +++ b/app/src/test/java/com/teester/whatsnearby/UtilitiesTest.java @@ -13,7 +13,7 @@ public class UtilitiesTest { @Test - public void splitquery_valid_url() throws URISyntaxException, UnsupportedEncodingException { + public void splitqueryValidUrl() throws URISyntaxException, UnsupportedEncodingException { String uri = "http://www.overpass-api.de/api/interpreter?data=[out:json]"; URI url = new URI(uri); @@ -23,7 +23,7 @@ public void splitquery_valid_url() throws URISyntaxException, UnsupportedEncodin } @Test - public void calculate_distance() { + public void calculateDistance() { double lat1 = 53.1; double lon1 = -7.5; double lat2 = 53.2; diff --git a/app/src/test/java/com/teester/whatsnearby/data/AnswersTest.java b/app/src/test/java/com/teester/whatsnearby/data/AnswersTest.java index aeb536c..f8b96d4 100644 --- a/app/src/test/java/com/teester/whatsnearby/data/AnswersTest.java +++ b/app/src/test/java/com/teester/whatsnearby/data/AnswersTest.java @@ -1,5 +1,11 @@ package com.teester.whatsnearby.data; +import com.teester.whatsnearby.data.questions.Halal; +import com.teester.whatsnearby.data.questions.Kosher; +import com.teester.whatsnearby.data.questions.Question; +import com.teester.whatsnearby.data.questions.QuestionsContract; +import com.teester.whatsnearby.data.questions.Wifi; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -11,8 +17,8 @@ public class AnswersTest { - QuestionObject questionObject = new QuestionObject(1, 1, 1, 1, "", "", "", ""); - OsmObject osmObject = new OsmObject(1, "", "", "", 1, 1, 1); + private QuestionsContract questionObject = new SampleQuestion(); + private OsmObject osmObject = new OsmObject(1, "", "", "", 1, 1, 1); @Before public void setUp() { @@ -33,17 +39,17 @@ public void tearDown() { } @Test - public void get_key_from_tag() { + public void getKeyFromTag() { String tag = this.questionObject.getTag(); - String expectedValue = this.questionObject.getAnswer_yes(); + String expectedValue = this.questionObject.getAnswerYes(); String actualValue = Answers.getAnswerMap().get(tag); assertEquals(expectedValue, actualValue); } @Test - public void get_poi_details() { + public void getPoiDetails() { long expectedId = 1; long actualID = Answers.getPoiId(); @@ -59,18 +65,64 @@ public void get_poi_details() { } @Test - public void check_answer_list_is_cleared() { + public void checkAnswerListIsCleared() { Answers.clearAnswerList(); Map actualResult = Answers.getAnswerMap(); assertEquals(0, actualResult.size()); } @Test - public void check_changeset_tags_are_set() { + public void checkChangesetTagsAreSet() { Map actualTags = Answers.getChangesetTags(); Map expectedTags = new HashMap<>(); expectedTags.put("", ""); assertEquals(expectedTags, actualTags); } + + @Test + public void testForCustomResponsesHalal() { + Answers.clearAnswerList(); + QuestionsContract halal = new Halal(); + String answerTag = halal.getAnswer("yes"); + String questionTag = halal.getTag(); + Answers.addAnswer(questionTag, answerTag); + + String expectedValue = halal.getAnswerYes(); + String actualValue = Answers.getAnswerMap().get(halal.getTag()); + + assertEquals(expectedValue, actualValue); + } + + @Test + public void testForCustomResponsesKosher() { + Answers.clearAnswerList(); + QuestionsContract kosher = new Kosher(); + String answerTag = kosher.getAnswer("yes"); + String questionTag = kosher.getTag(); + Answers.addAnswer(questionTag, answerTag); + + String expectedValue = kosher.getAnswerYes(); + String actualValue = Answers.getAnswerMap().get(kosher.getTag()); + + assertEquals(expectedValue, actualValue); + } + + @Test + public void testForCustomResponsesWifi() { + Answers.clearAnswerList(); + QuestionsContract wifi = new Wifi(); + String answerTag = wifi.getAnswer("yes"); + String questionTag = wifi.getTag(); + Answers.addAnswer(questionTag, answerTag); + + String expectedValue = wifi.getAnswerYes(); + String actualValue = Answers.getAnswerMap().get(wifi.getTag()); + + assertEquals(expectedValue, actualValue); + } + + // A sample blank Question to use for tests + private class SampleQuestion extends Question { + } } \ No newline at end of file diff --git a/app/src/test/java/com/teester/whatsnearby/data/PoiListTest.java b/app/src/test/java/com/teester/whatsnearby/data/PoiListTest.java index dee5dab..ef80042 100644 --- a/app/src/test/java/com/teester/whatsnearby/data/PoiListTest.java +++ b/app/src/test/java/com/teester/whatsnearby/data/PoiListTest.java @@ -1,5 +1,7 @@ package com.teester.whatsnearby.data; +import com.teester.whatsnearby.data.pois.PoiContract; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -26,7 +28,7 @@ public void tearDown() { } @Test - public void get_poi_from_poiList() { + public void getPoiFromPoiList() { OsmObject expectedPoi = this.osmObject; OsmObject actualPoi = PoiList.getInstance().getPoiList().get(0); @@ -40,7 +42,7 @@ public void get_poi_from_poiList() { } @Test - public void check_poi_list_is_cleared() { + public void checkPoiListIsCleared() { PoiList.getInstance().clearPoiList(); List actualResult = PoiList.getInstance().getPoiList(); @@ -48,25 +50,24 @@ public void check_poi_list_is_cleared() { } @Test - public void create_alternate_list() { + public void createAlternateList() { List alternateList = PoiList.getInstance().createAlternateList(); assertEquals(0, alternateList.size()); } @Test - public void check_poi_type() { + public void checkPoiType() { OsmObject osmObject = PoiList.getInstance().getPoiList().get(0); - OsmObject expectedType = this.osmObject; - OsmObjectType actualObject = PoiTypes.getPoiType(osmObject.getOsmType()); - OsmObjectType expectedObject = PoiTypes.getPoiType(this.osmObject.getOsmType()); + PoiContract actualObject = PoiTypes.getPoiType(osmObject.getOsmType()); + PoiContract expectedObject = PoiTypes.getPoiType(this.osmObject.getOsmType()); assertEquals(expectedObject, actualObject); } @Test - public void sort_poi_list() { + public void sortPoiList() { OsmObject object1 = new OsmObject(2, "", "", "", 3, 3, 1); OsmObject object2 = new OsmObject(3, "", "", "", 1, 1, 1); OsmObject object3 = new OsmObject(4, "", "", "", 2, 2, 1); diff --git a/app/src/test/java/com/teester/whatsnearby/data/source/QueryOverpassTest.java b/app/src/test/java/com/teester/whatsnearby/data/source/QueryOverpassTest.java index d661828..f145756 100644 --- a/app/src/test/java/com/teester/whatsnearby/data/source/QueryOverpassTest.java +++ b/app/src/test/java/com/teester/whatsnearby/data/source/QueryOverpassTest.java @@ -1,12 +1,9 @@ package com.teester.whatsnearby.data.source; -import com.teester.whatsnearby.data.location.Notifier; - import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import static junit.framework.TestCase.assertEquals; @@ -14,16 +11,13 @@ public class QueryOverpassTest { public QueryOverpass queryOverpass; - @Mock - private Notifier notifier; - @Before public void setUp() { queryOverpass = new QueryOverpass(); } @Test - public void test_generate_overpass_uri() { + public void testGenerateOverpassUri() { double latitude = 53; double longitude = -7; float accuracy = 50; @@ -34,7 +28,7 @@ public void test_generate_overpass_uri() { } @Test - public void test_get_overpass_result_poi_type() throws JSONException { + public void testGetOverpassResultPoiType() throws JSONException { String expected_result = "hairdresser"; JSONObject json = new JSONObject().put("amenity", expected_result); diff --git a/app/src/test/java/com/teester/whatsnearby/main/AboutPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/main/AboutPresenterTest.java new file mode 100644 index 0000000..720fd1d --- /dev/null +++ b/app/src/test/java/com/teester/whatsnearby/main/AboutPresenterTest.java @@ -0,0 +1,44 @@ +package com.teester.whatsnearby.main; + +import com.teester.whatsnearby.BuildConfig; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class AboutPresenterTest { + + private MainActivityContract.AboutPresenter aboutPresenter; + + @Mock + private MainActivityContract.AboutView view; + + @Before + public void setUp() { + aboutPresenter = new AboutPresenter(view); + } + + @Test + public void checkVersionNameIsSet() { + aboutPresenter.findVersion(); + verify(view).setVersion(BuildConfig.VERSION_NAME); + } + + @Test + public void checkLicenceDetailsAreSet() { + aboutPresenter.getLicence(); + verify(view).visitUri("http://www.gnu.org/licenses/gpl-3.0.html"); + } + + @Test + public void checkSourceDetailsAreSet() { + aboutPresenter.getGitHub(); + verify(view).visitUri("https://github.com/Teester/Whats-Nearby"); + } + +} diff --git a/app/src/test/java/com/teester/whatsnearby/main/MainActivityPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/main/MainActivityPresenterTest.java index 0c27388..7663c47 100644 --- a/app/src/test/java/com/teester/whatsnearby/main/MainActivityPresenterTest.java +++ b/app/src/test/java/com/teester/whatsnearby/main/MainActivityPresenterTest.java @@ -19,12 +19,12 @@ public class MainActivityPresenterTest { @Mock - MainActivityContract.View view; + private MainActivityContract.View view; @Mock - SourceContract.Preferences preferences; + private SourceContract.Preferences preferences; - MainActivityContract.Presenter presenter; + private MainActivityContract.Presenter presenter; @Before public void setUp() { @@ -32,7 +32,7 @@ public void setUp() { } @Test - public void logout_button_clicked() { + public void logoutButtonClicked() { presenter.onButtonClicked(); verify(preferences).setStringPreference(eq("oauth_verifier"), eq("")); @@ -43,7 +43,7 @@ public void logout_button_clicked() { } @Test - public void check_if_in_oAuth_flow() { + public void checkIfInOAuthFlow() { URI url = null; try { url = new URI("http://www.teester.com/data=?oauth_verifier=1&oauth_token=2"); diff --git a/app/src/test/java/com/teester/whatsnearby/questions/QuestionsPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/questions/QuestionsPresenterTest.java index 2b0a623..9fc9e5f 100644 --- a/app/src/test/java/com/teester/whatsnearby/questions/QuestionsPresenterTest.java +++ b/app/src/test/java/com/teester/whatsnearby/questions/QuestionsPresenterTest.java @@ -22,13 +22,13 @@ @RunWith(MockitoJUnitRunner.class) public class QuestionsPresenterTest { - QuestionsActivityContract.Presenter questionsPresenter; + private QuestionsActivityContract.Presenter questionsPresenter; @Mock - SourceContract.Preferences preferences; + private SourceContract.Preferences preferences; @Mock - QuestionsActivityContract.View view; + private QuestionsActivityContract.View view; @Before public void setUp() { @@ -36,7 +36,7 @@ public void setUp() { } @Test - public void AddPoiNameToTextViewTestSinglePoiInList() { + public void addPoiNameToTextViewTestSinglePoiInList() { List poiList = new ArrayList<>(); poiList.add(new OsmObject(1, "node", "", "restaurant", 1, 1, 1)); PoiList.getInstance().setPoiList(poiList); @@ -48,7 +48,7 @@ public void AddPoiNameToTextViewTestSinglePoiInList() { } @Test - public void AddPoiNameToTextViewTestMultiplePoiInList() { + public void addPoiNameToTextViewTestMultiplePoiInList() { List poiList = new ArrayList<>(); poiList.add(new OsmObject(1, "node", "Kitchen", "restaurant", 1, 1, 1)); poiList.add(new OsmObject(1, "node", "", "restaurant", 1, 1, 1)); @@ -61,7 +61,7 @@ public void AddPoiNameToTextViewTestMultiplePoiInList() { } @Test - public void AddPoiNameToTextViewTestNotLoggedIn() { + public void addPoiNameToTextViewTestNotLoggedIn() { List poiList = new ArrayList<>(); poiList.add(new OsmObject(1, "node", "Kitchen", "restaurant", 1, 1, 1)); poiList.add(new OsmObject(1, "node", "", "restaurant", 1, 1, 1)); diff --git a/app/src/test/java/com/teester/whatsnearby/questions/intro/IntroPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/questions/intro/IntroPresenterTest.java index b424359..3d85732 100644 --- a/app/src/test/java/com/teester/whatsnearby/questions/intro/IntroPresenterTest.java +++ b/app/src/test/java/com/teester/whatsnearby/questions/intro/IntroPresenterTest.java @@ -19,31 +19,29 @@ @RunWith(MockitoJUnitRunner.class) public class IntroPresenterTest { - IntroFragmentContract.Presenter introPresenter; + private IntroFragmentContract.Presenter introPresenter; - @Mock - IntroFragmentContract.View view; + @Mock + private IntroFragmentContract.View view; - @Before - public void setUp() { - List poiList = new ArrayList<>(); - poiList.add(new OsmObject(1, "node", "Kitchen", "restaurant", 1, 1, 1)); - poiList.add(new OsmObject(1, "node", "", "restaurant", 1, 1, 1)); - PoiList.getInstance().setPoiList(poiList); + @Before + public void setUp() { + List poiList = new ArrayList<>(); + poiList.add(new OsmObject(1, "node", "Kitchen", "restaurant", 1, 1, 1)); + poiList.add(new OsmObject(1, "node", "", "restaurant", 1, 1, 1)); + PoiList.getInstance().setPoiList(poiList); - introPresenter = new IntroPresenter(view); - } + introPresenter = new IntroPresenter(view); + } - @After - public void tearDown() { + @After + public void tearDown() { PoiList.getInstance().clearPoiList(); } - @Test - public void addPoiToTextview() { - introPresenter.getDetails(); - - verify(view).ShowDetails("Kitchen", " ", R.drawable.ic_restaurant); - } - + @Test + public void addPoiToTextview() { + introPresenter.getDetails(); + verify(view).showDetails("Kitchen", " ", R.drawable.ic_restaurant); + } } diff --git a/app/src/test/java/com/teester/whatsnearby/questions/nothere/NotHerePresenterTest.java b/app/src/test/java/com/teester/whatsnearby/questions/nothere/NotHerePresenterTest.java index 1b90fda..c3cdc6e 100644 --- a/app/src/test/java/com/teester/whatsnearby/questions/nothere/NotHerePresenterTest.java +++ b/app/src/test/java/com/teester/whatsnearby/questions/nothere/NotHerePresenterTest.java @@ -13,16 +13,15 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) public class NotHerePresenterTest { - NotHereFragmentContract.Presenter notHerePresenter; + private NotHereFragmentContract.Presenter notHerePresenter; @Mock - NotHereFragmentContract.View view; + private NotHereFragmentContract.View view; @Before public void setUp() { diff --git a/app/src/test/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenterTest.java new file mode 100644 index 0000000..c8dea18 --- /dev/null +++ b/app/src/test/java/com/teester/whatsnearby/questions/osmlogin/OsmLoginPresenterTest.java @@ -0,0 +1,35 @@ +package com.teester.whatsnearby.questions.osmlogin; + +import com.teester.whatsnearby.data.source.SourceContract; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class OsmLoginPresenterTest { + + private OsmLoginFragmentContract.Presenter presenter; + + @Mock + private OsmLoginFragmentContract.View view; + + @Mock + private SourceContract.Preferences preferences; + + @Before + public void setUp() { + presenter = new OsmLoginPresenter(view, preferences); + } + + @Test + public void checkPreferencesAreCleared() { + presenter.clickedOsmLoginButton(); + + verify(view).startOAuth(); + } +} diff --git a/app/src/test/java/com/teester/whatsnearby/questions/question/QuestionPresenterTest.java b/app/src/test/java/com/teester/whatsnearby/questions/question/QuestionPresenterTest.java index bf9b122..f8b32c0 100644 --- a/app/src/test/java/com/teester/whatsnearby/questions/question/QuestionPresenterTest.java +++ b/app/src/test/java/com/teester/whatsnearby/questions/question/QuestionPresenterTest.java @@ -50,25 +50,31 @@ public void tearDown() { } @Test - public void getObjectTest() { + public void getQuestionTest() { + questionPresenter.getQuestion(); + verify(view).showQuestion(anyInt(), anyString(), anyInt(), anyInt()); + } + + @Test + public void getPreviousAnswerTest() { questionPresenter.getQuestion(); verify(view).setPreviousAnswer(anyString()); } @Test - public void yes_answer_selected() { + public void yesAnswerSelected() { questionPresenter.onAnswerSelected(R.id.answer_yes); verify(view).setBackgroundColor(anyInt(), anyInt(), anyInt()); } @Test - public void no_answer_selected() { + public void noAnswerSelected() { questionPresenter.onAnswerSelected(R.id.answer_no); verify(view).setBackgroundColor(anyInt(), anyInt(), anyInt()); } @Test - public void unsure_answer_selected() { + public void unsureAnswerSelected() { questionPresenter.onAnswerSelected(R.id.answer_unsure); Set keySet = Answers.getAnswerMap().keySet(); String key = keySet.toArray(new String[keySet.size()])[0];