From f21591e5ba6295e8e73812babf8e5796cc409939 Mon Sep 17 00:00:00 2001 From: Mark Tully Date: Thu, 15 Feb 2018 01:36:00 +0000 Subject: [PATCH 1/5] Initial implementation of debug screen --- .idea/misc.xml | 2 +- .../data/location/LocationPresenter.java | 5 + .../whatsnearby/data/location/Notifier.java | 5 +- .../data/source/QueryOverpass.java | 4 +- .../whatsnearby/main/DebugPresenter.java | 33 ++++++ .../whatsnearby/main/FragmentDebug.java | 59 ++++++++++ .../whatsnearby/main/MainActivity.java | 8 ++ .../main/MainActivityContract.java | 11 ++ app/src/main/res/layout/activity_main.xml | 14 +++ app/src/main/res/layout/fragment_debug.xml | 108 ++++++++++++++++++ 10 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java create mode 100644 app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java create mode 100644 app/src/main/res/layout/fragment_debug.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index c89d42a..cc5b915 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + 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 index 0bb77a9..199b650 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/location/LocationPresenter.java +++ b/app/src/main/java/com/teester/whatsnearby/data/location/LocationPresenter.java @@ -2,6 +2,7 @@ import android.location.Location; +import com.teester.whatsnearby.BuildConfig; import com.teester.whatsnearby.data.source.SourceContract; public class LocationPresenter implements LocationServiceContract.Presenter { @@ -61,6 +62,10 @@ public void processLocation(Location location) { query = false; } + if (BuildConfig.DEBUG) { + query = true; + } + if (query == true) { lastQueryLocation = location; diff --git a/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java b/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java index 6c515d6..c24f2b7 100644 --- a/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java +++ b/app/src/main/java/com/teester/whatsnearby/data/location/Notifier.java @@ -17,6 +17,8 @@ import com.teester.whatsnearby.data.source.SourceContract; import com.teester.whatsnearby.questions.QuestionsActivity; +import java.util.Date; + import static android.content.Context.NOTIFICATION_SERVICE; public class Notifier { @@ -35,7 +37,8 @@ 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()); - + System.out.println(new Date(System.currentTimeMillis()).toString()); + preferences.setStringPreference("last_notification_time", new Date(System.currentTimeMillis()).toString()); 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/source/QueryOverpass.java b/app/src/main/java/com/teester/whatsnearby/data/source/QueryOverpass.java index bf76c71..8141bfe 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 @@ -155,12 +155,14 @@ public void processResult(String result) { @Override public void queryOverpass(double latitude, double longitude, float accuracy) { - + SourceContract.Preferences preferences = new Preferences(context); + preferences.setStringPreference("last_query_time", new Date(System.currentTimeMillis()).toString()); queryLatitude = latitude; queryLongitude = longitude; queryAccuracy = accuracy; String overpassUrl = getOverpassUri(latitude, longitude, accuracy); String overpassQuery = queryOverpassApi(overpassUrl); + preferences.setStringPreference("last_query", overpassQuery); processResult(overpassQuery); } diff --git a/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java b/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java new file mode 100644 index 0000000..d370346 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/main/DebugPresenter.java @@ -0,0 +1,33 @@ +package com.teester.whatsnearby.main; + +import com.teester.whatsnearby.data.source.SourceContract; + +public class DebugPresenter implements MainActivityContract.DebugPresenter { + + private MainActivityContract.DebugView view; + private SourceContract.Preferences preferences; + + public DebugPresenter(MainActivityContract.DebugView view, SourceContract.Preferences preferences) { + this.view = view; + this.preferences = preferences; + } + + @Override + public void init() { + + } + + @Override + public void destroy() { + + } + + @Override + public void getDetails() { + String lastQueryTime = preferences.getStringPreference("last_query_time"); + String lastNotificationTime = preferences.getStringPreference("last_notification_time"); + String lastQuery = preferences.getStringPreference("last_query"); + + view.setLastQueryTime(lastQueryTime, lastNotificationTime, lastQuery); + } +} diff --git a/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java b/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java new file mode 100644 index 0000000..bbd1683 --- /dev/null +++ b/app/src/main/java/com/teester/whatsnearby/main/FragmentDebug.java @@ -0,0 +1,59 @@ +package com.teester.whatsnearby.main; + +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; +import com.teester.whatsnearby.data.source.Preferences; +import com.teester.whatsnearby.data.source.SourceContract; + +public class FragmentDebug extends Fragment implements MainActivityContract.DebugView { + + private TextView lastQueryTime; + private TextView lastNotificationTime; + private TextView lastQuery; + private MainActivityContract.DebugPresenter debugPresenter; + private SourceContract.Preferences preferences; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + SourceContract.Preferences preferences = new Preferences(getContext()); + debugPresenter = new DebugPresenter(this, preferences); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + return inflater.inflate(R.layout.fragment_debug, container, false); + } + + @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); + + debugPresenter.getDetails(); + } + + @Override + public void setLastQueryTime(String time, String notificationTime, String queryTime) { + this.lastQueryTime.setText(time); + this.lastNotificationTime.setText(notificationTime); + this.lastQuery.setText(queryTime); + } + + @Override + public void setPresenter(MainActivityContract.DebugPresenter presenter) { + + } +} 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 77d7961..a26e2e4 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java +++ b/app/src/main/java/com/teester/whatsnearby/main/MainActivity.java @@ -9,6 +9,7 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; @@ -33,6 +34,7 @@ public class MainActivity extends AppCompatActivity implements private TextView textView; private Button button; + private Button debugButton; private SharedPreferences sharedPreferences; private MainActivityContract.Presenter mainPresenter; @@ -47,8 +49,10 @@ protected void onCreate(Bundle savedInstanceState) { mainPresenter.init(); this.textView = this.findViewById(R.id.textView); this.button = this.findViewById(R.id.button); + this.debugButton = this.findViewById(R.id.button2); this.button.setOnClickListener(this); + this.debugButton.setOnClickListener(this); checkPermission(); mainPresenter.showIfLoggedIn(); } @@ -115,6 +119,10 @@ public void onClick(View view) { if (view == findViewById(R.id.button)) { mainPresenter.onButtonClicked(); } + if (view == findViewById(R.id.button2)) { + Fragment fragment = new FragmentDebug(); + getSupportFragmentManager().beginTransaction().replace(R.id.activity_main, fragment).commit(); + } } @Override 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 c112ae4..5b47888 100644 --- a/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java +++ b/app/src/main/java/com/teester/whatsnearby/main/MainActivityContract.java @@ -23,4 +23,15 @@ interface View extends BaseView { void startOAuth(); } + + interface DebugPresenter extends BasePresenter { + + void getDetails(); + } + + interface DebugView extends BaseView { + + void setLastQueryTime(String lastQuerytime, String lastNotificationTime, String lastQuery); + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 41e9c15..5835e85 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#333333"> @@ -40,4 +41,17 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView"/> + +