From fdb62e6fca951db91ae76b3ab4f90ae66c9cd16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Sat, 17 Sep 2016 10:32:48 +0200 Subject: [PATCH] Almost ready. --- .../urbanexplorer/MainActivity.java | 31 +++++++++++++++++++ .../urbanexplorer/fragments/HomeFragment.java | 13 ++++++++ .../fragments/PanoramioShowerFragment.java | 1 + .../fragments/WikiLocationsFragment.java | 10 ++++++ .../main/res/layout/wiki_locations_item.xml | 3 +- 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java index 1402760..63a455b 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java @@ -1,5 +1,6 @@ package pl.tpolgrabia.urbanexplorer; +import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -49,6 +50,8 @@ public class MainActivity extends ActionBarActivity { private static final double MIN_FRAGMENT_ID = HOME_FRAGMENT_ID; private static final String FRAG_ID = "FRAG_ID"; private static final int SETTINGS_ID_INTENT_REQUEST_ID = 2; + private static final String PHOTO_INFO = "PHOTO_INFO"; + private static final String FIRST_TIME_LAUNCH = "FIRST_TIME_LAUNCH_KEY"; public static DisplayImageOptions options; private GestureDetectorCompat gestureDetector; private int currentFragmentId = 0; @@ -57,11 +60,21 @@ public class MainActivity extends ActionBarActivity { private boolean locationServicesActivated = false; private GestureDetector.OnGestureListener swipeHandler; private PanoramioImageInfo photoInfo; + private ProgressDialog progressDlg; public StandardLocationListener getLocationCallback() { return locationCallback; } + public void showProgress() { + progressDlg.show(); + } + + public void hideProgress() { + progressDlg.dismiss(); + } + + @Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); @@ -78,6 +91,7 @@ public class MainActivity extends ActionBarActivity { NetUtils.setGlobalProxyAuth(this); currentFragmentId = 0; + progressDlg = new ProgressDialog(this); // UNIVERSAL IMAGE LOADER SETUP DisplayImageOptions defaultOptions = ImageLoaderUtils.createDefaultOptions(); @@ -103,9 +117,19 @@ public class MainActivity extends ActionBarActivity { Log.v(CLASS_TAG, "Restored orig frag id: " + fragId); currentFragmentId = fragId == null ? 0 : fragId; Log.v(CLASS_TAG, "Set final frag id: " + fragId); + photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(PHOTO_INFO) : null; switchFragment(); updateSwipeHandler(); + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + if (sharedPrefs.getBoolean(FIRST_TIME_LAUNCH, true)) { + Toast.makeText(this, "To interact with any list itemm press long the item. When thgre is no results" + + ", please, click refresh in the menu", Toast.LENGTH_LONG).show(); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putBoolean(FIRST_TIME_LAUNCH, false); + editor.commit(); + } } @Override @@ -123,6 +147,8 @@ public class MainActivity extends ActionBarActivity { startActivityForResult(intent, MainActivity.SETTINGS_ID_INTENT_REQUEST_ID, new Bundle()); return true; case R.id.refresh: + progressDlg.setMessage("Refreshing results"); + progressDlg.show(); switch (currentFragmentId) { case HOME_FRAGMENT_ID: HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager() @@ -145,6 +171,10 @@ public class MainActivity extends ActionBarActivity { } } + public void resetPhotoInfo() { + this.photoInfo = null; + } + public void switchToPhoto(PanoramioImageInfo photoInfo) { this.photoInfo = photoInfo; FragmentManager fragmentManager = getSupportFragmentManager(); @@ -321,6 +351,7 @@ public class MainActivity extends ActionBarActivity { Log.v(CLASS_TAG, "1 Saving current fragment id: " + currentFragmentId); super.onSaveInstanceState(outState); outState.putSerializable(FRAG_ID, currentFragmentId); + outState.putSerializable(PHOTO_INFO, photoInfo); Log.v(CLASS_TAG, "2 Saving current fragment id: " + currentFragmentId); } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java index b207907..7c10801 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -223,6 +223,9 @@ public class HomeFragment extends Fragment { ListView locations = (ListView) getView().findViewById(R.id.locations); ArrayAdapter adapter = (ArrayAdapter) locations.getAdapter(); photos.addAll(images); + if (photos.isEmpty()) { + Toast.makeText(getActivity(), "No results", Toast.LENGTH_SHORT).show(); + } noMorePhotos = images.isEmpty(); if (adapter == null) { locations.setAdapter(new PanoramioAdapter(activity, R.id.list_item, images)); @@ -277,8 +280,18 @@ public class HomeFragment extends Fragment { ArrayAdapter adapter = new PanoramioAdapter(activity, R.layout.location_item, images); + + if (images.isEmpty()) { + Toast.makeText(getActivity(), "No results", Toast.LENGTH_SHORT).show(); + } ListView locations = (ListView)getView().findViewById(R.id.locations); locations.setAdapter(adapter); + MainActivity mainActivity = (MainActivity) getActivity(); + if (mainActivity == null) { + return; + } + + mainActivity.hideProgress(); } } ); diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java index 1882761..3649e5f 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java @@ -91,6 +91,7 @@ public class PanoramioShowerFragment extends Fragment { FragmentActivity acc = getActivity(); if (acc != null) { MainActivity mainActivity = (MainActivity)acc; + mainActivity.resetPhotoInfo(); } } } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java index 00b12ed..f28150b 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -113,6 +113,16 @@ public class WikiLocationsFragment extends Fragment { ListView locations = (ListView) getView().findViewById(R.id.wiki_places); locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(WikiLocationsFragment.this, appObjects)); locations.setAdapter(new WikiLocationsAdapter(activity, appObjects)); + if (appObjects.isEmpty()) { + Toast.makeText(getActivity(), "No results", Toast.LENGTH_SHORT).show(); + } + + MainActivity mainActivity = (MainActivity) getActivity(); + if (mainActivity == null) { + return; + } + + mainActivity.hideProgress(); } } ); diff --git a/app/src/main/res/layout/wiki_locations_item.xml b/app/src/main/res/layout/wiki_locations_item.xml index 1aa3239..83c7d27 100644 --- a/app/src/main/res/layout/wiki_locations_item.xml +++ b/app/src/main/res/layout/wiki_locations_item.xml @@ -6,7 +6,8 @@ + android:layout_height="120dp" + android:layout_marginRight="10dp"/>