Code refactorings.
parent
363c3b5af8
commit
3ef358bfc3
|
@ -27,4 +27,15 @@ public class AppConstants {
|
||||||
public static final int PANORAMIO_BULK_SIZE_DEF_VALUE = 50;
|
public static final int PANORAMIO_BULK_SIZE_DEF_VALUE = 50;
|
||||||
public static final String PANORAMIO_CACHE_FILENAME = "panoramio-cache.dat";
|
public static final String PANORAMIO_CACHE_FILENAME = "panoramio-cache.dat";
|
||||||
public static final String WIKI_CACHE_FILENAME = "wiki-cache.dat";
|
public static final String WIKI_CACHE_FILENAME = "wiki-cache.dat";
|
||||||
|
public static final String PREF_GPS_UPDATE_FREQ = "pref_gps_update_freq";
|
||||||
|
public static final String PREF_GPS_DISTANCE_FREQ = "pref_gps_distance_freq";
|
||||||
|
public static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK";
|
||||||
|
static final int HOME_FRAGMENT_ID = 0;
|
||||||
|
static final double MIN_FRAGMENT_ID = HOME_FRAGMENT_ID;
|
||||||
|
static final int WIKI_FRAGMENT_ID = 1;
|
||||||
|
static final double MAX_FRAGMENT_ID = WIKI_FRAGMENT_ID;
|
||||||
|
static final String FRAG_ID = "FRAG_ID";
|
||||||
|
static final int SETTINGS_ID_INTENT_REQUEST_ID = 2;
|
||||||
|
static final String PHOTO_INFO = "PHOTO_INFO";
|
||||||
|
static final String SAVED_CONFIG_KEY = "SAVED_CONFIG_KEY";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +1,43 @@
|
||||||
package pl.tpolgrabia.urbanexplorer;
|
package pl.tpolgrabia.urbanexplorer;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.location.Location;
|
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.GestureDetectorCompat;
|
import android.support.v4.view.GestureDetectorCompat;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.Toast;
|
|
||||||
import com.androidquery.util.AQUtility;
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
|
||||||
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
|
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
|
||||||
import io.fabric.sdk.android.Fabric;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import pl.tpolgrabia.urbanexplorer.activities.SettingsActivity;
|
import pl.tpolgrabia.urbanexplorer.activities.SettingsActivity;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListener;
|
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListener;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
|
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
||||||
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
|
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
|
||||||
import pl.tpolgrabia.urbanexplorer.fragments.PanoramioShowerFragment;
|
import pl.tpolgrabia.urbanexplorer.fragments.PanoramioShowerFragment;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.fragments.Refreshable;
|
||||||
import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment;
|
import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment;
|
||||||
import pl.tpolgrabia.urbanexplorer.handlers.SwipeHandler;
|
import pl.tpolgrabia.urbanexplorer.handlers.SwipeHandler;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.ImageLoaderUtils;
|
import pl.tpolgrabia.urbanexplorer.utils.HelperUtils;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.LocationUtils;
|
import pl.tpolgrabia.urbanexplorer.utils.LocationUtils;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.NetUtils;
|
import pl.tpolgrabia.urbanexplorer.utils.NetUtils;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.NumberUtils;
|
|
||||||
import pl.tpolgrabia.urbanexplorer.views.CustomInterceptor;
|
import pl.tpolgrabia.urbanexplorer.views.CustomInterceptor;
|
||||||
import pl.tpolgrabia.urbanexplorer.views.SwipeFrameLayout;
|
import pl.tpolgrabia.urbanexplorer.views.SwipeFrameLayout;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity {
|
public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
private static final Logger lg = LoggerFactory.getLogger(MainActivity.class);
|
private static final Logger lg = LoggerFactory.getLogger(MainActivity.class);
|
||||||
|
|
||||||
private static final int LOCATION_SETTINGS_REQUEST_ID = 1;
|
|
||||||
private static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK";
|
|
||||||
private static final int HOME_FRAGMENT_ID = 0;
|
|
||||||
private static final int WIKI_FRAGMENT_ID = 1;
|
|
||||||
private static final double MAX_FRAGMENT_ID = WIKI_FRAGMENT_ID;
|
|
||||||
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";
|
|
||||||
private static final String SAVED_CONFIG_KEY = "SAVED_CONFIG_KEY";
|
|
||||||
public static DisplayImageOptions options;
|
public static DisplayImageOptions options;
|
||||||
private GestureDetectorCompat gestureDetector;
|
private GestureDetectorCompat gestureDetector;
|
||||||
private int currentFragmentId = 0;
|
private int currentFragmentId = 0;
|
||||||
private StandardLocationListener locationCallback;
|
private StandardLocationListener locationCallback;
|
||||||
|
|
||||||
private boolean locationServicesActivated = false;
|
private boolean locationServicesActivated = false;
|
||||||
private GestureDetector.OnGestureListener swipeHandler;
|
private GestureDetector.OnGestureListener swipeHandler;
|
||||||
private PanoramioImageInfo photoInfo;
|
private PanoramioImageInfo photoInfo;
|
||||||
|
@ -69,6 +45,13 @@ public class MainActivity extends ActionBarActivity {
|
||||||
private int oldFragmentId = 0;
|
private int oldFragmentId = 0;
|
||||||
private boolean savedConfiguration;
|
private boolean savedConfiguration;
|
||||||
|
|
||||||
|
private static final Map<Integer, String> fragTags = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
fragTags.put(AppConstants.HOME_FRAGMENT_ID, HomeFragment.TAG);
|
||||||
|
fragTags.put(AppConstants.WIKI_FRAGMENT_ID, WikiLocationsFragment.TAG);
|
||||||
|
}
|
||||||
|
|
||||||
public StandardLocationListener getLocationCallback() {
|
public StandardLocationListener getLocationCallback() {
|
||||||
return locationCallback;
|
return locationCallback;
|
||||||
}
|
}
|
||||||
|
@ -94,9 +77,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
lg.trace("onCreate");
|
lg.trace("onCreate");
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
AQUtility.setDebug(AppConstants.RELEASE != AppStage.FINAL
|
HelperUtils.initErrorAndDebugHanlers();
|
||||||
&& AppConstants.RELEASE != AppStage.RELEASE_CANDIDATE);
|
|
||||||
|
|
||||||
NetUtils.setGlobalProxyAuth(this);
|
NetUtils.setGlobalProxyAuth(this);
|
||||||
|
|
||||||
currentFragmentId = 0;
|
currentFragmentId = 0;
|
||||||
|
@ -104,47 +85,24 @@ public class MainActivity extends ActionBarActivity {
|
||||||
progressDlg.setCancelable(false);
|
progressDlg.setCancelable(false);
|
||||||
|
|
||||||
// UNIVERSAL IMAGE LOADER SETUP
|
// UNIVERSAL IMAGE LOADER SETUP
|
||||||
DisplayImageOptions defaultOptions = ImageLoaderUtils.createDefaultOptions();
|
HelperUtils.initUniversalDownloader(this);
|
||||||
|
|
||||||
options = defaultOptions;
|
|
||||||
|
|
||||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
|
||||||
this)
|
|
||||||
.defaultDisplayImageOptions(defaultOptions)
|
|
||||||
.memoryCache(new WeakMemoryCache())
|
|
||||||
.discCacheSize(100 * 1024 * 1024).build();
|
|
||||||
|
|
||||||
ImageLoader.getInstance().init(config);
|
|
||||||
|
|
||||||
swipeHandler = new SwipeHandler(this);
|
swipeHandler = new SwipeHandler(this);
|
||||||
gestureDetector = new GestureDetectorCompat(this, swipeHandler);
|
gestureDetector = new GestureDetectorCompat(this, swipeHandler);
|
||||||
locationCallback = new StandardLocationListener();
|
locationCallback = new StandardLocationListener();
|
||||||
initLocalication();
|
|
||||||
if (AppConstants.RELEASE == AppStage.FINAL
|
|
||||||
|| AppConstants.RELEASE == AppStage.RELEASE_CANDIDATE) {
|
|
||||||
Fabric.with(this, new Crashlytics());
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer fragId = savedInstanceState != null ? savedInstanceState.getInt(FRAG_ID) : null;
|
// init fragments
|
||||||
|
Integer fragId = savedInstanceState != null ? savedInstanceState.getInt(AppConstants.FRAG_ID) : null;
|
||||||
lg.trace("Restored orig frag id: {}", fragId);
|
lg.trace("Restored orig frag id: {}", fragId);
|
||||||
currentFragmentId = fragId == null ? 0 : fragId;
|
currentFragmentId = fragId == null ? 0 : fragId;
|
||||||
lg.trace("Set final frag id: {}", fragId);
|
lg.trace("Set final frag id: {}", fragId);
|
||||||
photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(PHOTO_INFO) : null;
|
photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(AppConstants.PHOTO_INFO) : null;
|
||||||
savedConfiguration = savedInstanceState != null ? savedInstanceState.getBoolean(SAVED_CONFIG_KEY) : false;
|
savedConfiguration = savedInstanceState != null ? savedInstanceState.getBoolean(AppConstants.SAVED_CONFIG_KEY) : false;
|
||||||
|
|
||||||
|
if (HelperUtils.checkForLocalicatonEnabled(this)) return;
|
||||||
switchFragment();
|
switchFragment();
|
||||||
|
|
||||||
updateSwipeHandler();
|
updateSwipeHandler();
|
||||||
|
HelperUtils.firstTimeNotification(this);
|
||||||
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();
|
|
||||||
Toast.makeText(this, "To change panoramio / wiki search views swipe left or right",
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
|
||||||
editor.putBoolean(FIRST_TIME_LAUNCH, false);
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -159,7 +117,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.settings:
|
case R.id.settings:
|
||||||
final Intent intent = new Intent(this, SettingsActivity.class);
|
final Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
startActivityForResult(intent, MainActivity.SETTINGS_ID_INTENT_REQUEST_ID, new Bundle());
|
startActivityForResult(intent, AppConstants.SETTINGS_ID_INTENT_REQUEST_ID, new Bundle());
|
||||||
return true;
|
return true;
|
||||||
case R.id.refresh:
|
case R.id.refresh:
|
||||||
progressDlg.setMessage("Refreshing results");
|
progressDlg.setMessage("Refreshing results");
|
||||||
|
@ -172,23 +130,21 @@ public class MainActivity extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshFragment() {
|
private void refreshFragment() {
|
||||||
switch (currentFragmentId) {
|
final String tag = fragTags.get(currentFragmentId);
|
||||||
case HOME_FRAGMENT_ID:
|
if (tag == null) {
|
||||||
HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager()
|
lg.warn("Unknown fragment id");
|
||||||
.findFragmentByTag(HomeFragment.TAG);
|
return;
|
||||||
homeFragment.fetchPanoramioPhotos();
|
|
||||||
break;
|
|
||||||
case WIKI_FRAGMENT_ID:
|
|
||||||
WikiLocationsFragment wikiLocationsFragment = (WikiLocationsFragment)
|
|
||||||
getSupportFragmentManager()
|
|
||||||
.findFragmentByTag(WikiLocationsFragment.TAG);
|
|
||||||
wikiLocationsFragment.clearData();
|
|
||||||
wikiLocationsFragment.fetchWikiLocations();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
lg.warn("Unknown current fragment ID");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
|
||||||
|
if (fragment == null) {
|
||||||
|
lg.warn("There is no fragment with the given tag");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Refreshable refreshable = (Refreshable) fragment;
|
||||||
|
refreshable.refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetPhotoInfo() {
|
public void resetPhotoInfo() {
|
||||||
|
@ -215,7 +171,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
ctx.replace(R.id.fragments, panoramioShower, PanoramioShowerFragment.TAG);
|
ctx.replace(R.id.fragments, panoramioShower, PanoramioShowerFragment.TAG);
|
||||||
}
|
}
|
||||||
if (!savedConfiguration) {
|
if (!savedConfiguration) {
|
||||||
ctx.addToBackStack(PHOTO_BACKSTACK);
|
ctx.addToBackStack(AppConstants.PHOTO_BACKSTACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.commit();
|
ctx.commit();
|
||||||
|
@ -234,13 +190,13 @@ public class MainActivity extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (currentFragmentId) {
|
switch (currentFragmentId) {
|
||||||
case HOME_FRAGMENT_ID:
|
case AppConstants.HOME_FRAGMENT_ID:
|
||||||
// switch to home fragment
|
// switch to home fragment
|
||||||
lg.debug("Switching to home fragment");
|
lg.debug("Switching to home fragment");
|
||||||
final HomeFragment fragment = new HomeFragment();
|
final HomeFragment fragment = new HomeFragment();
|
||||||
switchFragment(fragment, HomeFragment.TAG);
|
switchFragment(fragment, HomeFragment.TAG);
|
||||||
break;
|
break;
|
||||||
case WIKI_FRAGMENT_ID:
|
case AppConstants.WIKI_FRAGMENT_ID:
|
||||||
// switch to wiki fragment
|
// switch to wiki fragment
|
||||||
lg.debug("Switching to wiki fragment");
|
lg.debug("Switching to wiki fragment");
|
||||||
switchFragment(new WikiLocationsFragment(), WikiLocationsFragment.TAG);
|
switchFragment(new WikiLocationsFragment(), WikiLocationsFragment.TAG);
|
||||||
|
@ -256,39 +212,9 @@ public class MainActivity extends ActionBarActivity {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
FragmentTransaction ctx = fragmentManager.beginTransaction();
|
FragmentTransaction ctx = fragmentManager.beginTransaction();
|
||||||
lg.trace("old newFragment id: {}, current newFragment id: {}", oldFragmentId, currentFragmentId);
|
lg.trace("old newFragment id: {}, current newFragment id: {}", oldFragmentId, currentFragmentId);
|
||||||
if (oldFragmentId != currentFragmentId) {
|
|
||||||
if (currentFragmentId < oldFragmentId) {
|
|
||||||
// slide left animation
|
|
||||||
lg.trace("sliding left animation");
|
|
||||||
ctx.setCustomAnimations(
|
|
||||||
R.anim.slide_in_left,
|
|
||||||
R.anim.slide_out_left,
|
|
||||||
R.anim.slide_in_right,
|
|
||||||
R.anim.slide_out_right);
|
|
||||||
} else {
|
|
||||||
// slide right animation
|
|
||||||
lg.trace("sliding right animation");
|
|
||||||
ctx.setCustomAnimations(
|
|
||||||
R.anim.slide_in_right,
|
|
||||||
R.anim.slide_out_right,
|
|
||||||
R.anim.slide_in_left,
|
|
||||||
R.anim.slide_out_left);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Fragment> fragments = fragmentManager.getFragments();
|
HelperUtils.appendEffectToTransition(ctx, oldFragmentId, currentFragmentId);
|
||||||
if (fragments != null) {
|
HelperUtils.traceAllAvailableFragments(fragmentManager);
|
||||||
lg.trace("Available fragments {}", fragments.size());
|
|
||||||
for (Fragment frag : fragments) {
|
|
||||||
if (frag != null) {
|
|
||||||
lg.trace("Available fragment with id: {}, tag: {}", frag.getId(), frag.getTag());
|
|
||||||
} else {
|
|
||||||
lg.trace("Available null-fragment");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lg.trace("There are no fragments -> null");
|
|
||||||
}
|
|
||||||
|
|
||||||
lg.trace("Trying to search newFragment by tag {}", tag);
|
lg.trace("Trying to search newFragment by tag {}", tag);
|
||||||
Fragment currFragment = fragmentManager.findFragmentByTag(tag);
|
Fragment currFragment = fragmentManager.findFragmentByTag(tag);
|
||||||
|
@ -318,7 +244,7 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
public void swipeLeft() {
|
public void swipeLeft() {
|
||||||
lg.debug("Swiped left");
|
lg.debug("Swiped left");
|
||||||
changeCurrentFragId((int)Math.max(MIN_FRAGMENT_ID, currentFragmentId-1));
|
changeCurrentFragId((int)Math.max(AppConstants.MIN_FRAGMENT_ID, currentFragmentId-1));
|
||||||
switchFragment();
|
switchFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,50 +255,21 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
public void swipeRight() {
|
public void swipeRight() {
|
||||||
lg.debug("Swiped right");
|
lg.debug("Swiped right");
|
||||||
changeCurrentFragId((int)Math.min(MAX_FRAGMENT_ID, currentFragmentId+1));
|
changeCurrentFragId((int)Math.min(AppConstants.MAX_FRAGMENT_ID, currentFragmentId+1));
|
||||||
switchFragment();
|
switchFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLocalication() {
|
|
||||||
if (checkForLocalicatonEnabled()) return;
|
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
|
|
||||||
locationCallback.addCallback(new StandardLocationListenerCallback() {
|
|
||||||
@Override
|
|
||||||
public void callback(Location location) {
|
|
||||||
double lat = location.getLatitude();
|
|
||||||
double lng = location.getLongitude();
|
|
||||||
Toast.makeText(ctx, "Location: (" + lat + "," + lng + ")", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkForLocalicatonEnabled() {
|
|
||||||
|
|
||||||
lg.trace("Check for location enabled");
|
|
||||||
final String locationProvider = LocationUtils.getDefaultLocation(this);
|
|
||||||
lg.debug("Location provider {}", locationProvider);
|
|
||||||
if (locationProvider == null) {
|
|
||||||
lg.debug("Location provider is null. Prompting for enabling location services");
|
|
||||||
Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
||||||
startActivityForResult(locationSettingsIntent, LOCATION_SETTINGS_REQUEST_ID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
lg.trace("onResume");
|
lg.trace("onResume");
|
||||||
String locationProvider = LocationUtils.getDefaultLocation(this);
|
String locationProvider = LocationUtils.getDefaultLocation(this);
|
||||||
|
|
||||||
if (locationProvider != null) {
|
if (locationProvider != null) {
|
||||||
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
|
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
|
||||||
locationService.requestLocationUpdates(locationProvider,
|
locationService.requestLocationUpdates(locationProvider,
|
||||||
fetchGpsUpdateFreq(),
|
HelperUtils.fetchGpsUpdateFreq(this),
|
||||||
fetchGpsDistanceFreq(),
|
HelperUtils.fetchGpsDistanceFreq(this),
|
||||||
locationCallback);
|
locationCallback);
|
||||||
locationServicesActivated = true;
|
locationServicesActivated = true;
|
||||||
}
|
}
|
||||||
|
@ -381,30 +278,11 @@ public class MainActivity extends ActionBarActivity {
|
||||||
photoInfo = null;
|
photoInfo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Float fetchGpsDistanceFreq() {
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
String prefDistanceUpdateFreq = sharedPreferences.getString(
|
|
||||||
"pref_gps_distance_freq",
|
|
||||||
String.valueOf(AppConstants.GPS_LOCATION_DISTANCE_FREQ));
|
|
||||||
|
|
||||||
lg.debug("Pref GPS distance update frequency {}", prefDistanceUpdateFreq);
|
|
||||||
return NumberUtils.safeParseFloat(prefDistanceUpdateFreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Long fetchGpsUpdateFreq() {
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
String prefGpsUpdateFreq = sharedPreferences.getString(
|
|
||||||
"pref_gps_update_freq",
|
|
||||||
String.valueOf(AppConstants.GPS_LOCATION_UPDATE_FREQ));
|
|
||||||
|
|
||||||
lg.debug("Pref GPS location update frequency {}", prefGpsUpdateFreq);
|
|
||||||
return Math.round(NumberUtils.safeParseDouble(prefGpsUpdateFreq)* 60.0 * 1000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
lg.trace("onPause");
|
lg.trace("onPause");
|
||||||
|
|
||||||
if (locationServicesActivated) {
|
if (locationServicesActivated) {
|
||||||
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
|
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
|
||||||
locationService.removeUpdates(locationCallback);
|
locationService.removeUpdates(locationCallback);
|
||||||
|
@ -419,12 +297,11 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case LOCATION_SETTINGS_REQUEST_ID:
|
case HelperUtils.LOCATION_SETTINGS_REQUEST_ID:
|
||||||
refreshFragment();
|
refreshFragment();
|
||||||
break;
|
break;
|
||||||
case SETTINGS_ID_INTENT_REQUEST_ID:
|
case AppConstants.SETTINGS_ID_INTENT_REQUEST_ID:
|
||||||
NetUtils.setGlobalProxyAuth(this);
|
NetUtils.setGlobalProxyAuth(this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -435,31 +312,23 @@ public class MainActivity extends ActionBarActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
lg.trace("1 Saving current fragment id: {}", currentFragmentId);
|
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putSerializable(FRAG_ID, currentFragmentId);
|
lg.trace("1 Saving current fragment id: {}", currentFragmentId);
|
||||||
outState.putSerializable(PHOTO_INFO, photoInfo);
|
outState.putSerializable(AppConstants.FRAG_ID, currentFragmentId);
|
||||||
outState.putBoolean(SAVED_CONFIG_KEY, true);
|
outState.putSerializable(AppConstants.PHOTO_INFO, photoInfo);
|
||||||
|
outState.putBoolean(AppConstants.SAVED_CONFIG_KEY, true);
|
||||||
// SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
// SharedPreferences.Editor editor = sharedPrefs.edit();
|
|
||||||
// editor.putInt(FRAG_ID, currentFragmentId);
|
|
||||||
// editor.commit();
|
|
||||||
|
|
||||||
lg.trace("2 Saving current fragment id: {}", currentFragmentId);
|
lg.trace("2 Saving current fragment id: {}", currentFragmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
lg.trace("onStop {}", System.identityHashCode(this));
|
lg.trace("onStop {}", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
lg.trace("onStart {}", System.identityHashCode(this));
|
lg.trace("onStart {}", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.concurrent.Semaphore;
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
*/
|
*/
|
||||||
public class HomeFragment extends Fragment {
|
public class HomeFragment extends Fragment implements Refreshable {
|
||||||
|
|
||||||
private static final Logger lg = LoggerFactory.getLogger(HomeFragment.class);
|
private static final Logger lg = LoggerFactory.getLogger(HomeFragment.class);
|
||||||
|
|
||||||
|
@ -497,4 +497,9 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
lg.trace("onStart {}", System.identityHashCode(this));
|
lg.trace("onStart {}", System.identityHashCode(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
fetchPanoramioPhotos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package pl.tpolgrabia.urbanexplorer.fragments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 19.09.16.
|
||||||
|
*/
|
||||||
|
public interface Refreshable {
|
||||||
|
void refresh();
|
||||||
|
}
|
|
@ -39,7 +39,7 @@ import static android.content.Context.LOCATION_SERVICE;
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
*/
|
*/
|
||||||
public class WikiLocationsFragment extends Fragment {
|
public class WikiLocationsFragment extends Fragment implements Refreshable {
|
||||||
|
|
||||||
private static final Logger lg = LoggerFactory.getLogger(WikiLocationsFragment.class);
|
private static final Logger lg = LoggerFactory.getLogger(WikiLocationsFragment.class);
|
||||||
private static final String CLASS_TAG = WikiLocationsFragment.class.getSimpleName();
|
private static final String CLASS_TAG = WikiLocationsFragment.class.getSimpleName();
|
||||||
|
@ -289,4 +289,10 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
lg.error("I/O error", e);
|
lg.error("I/O error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
clearData();
|
||||||
|
fetchWikiLocations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
package pl.tpolgrabia.urbanexplorer.utils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import com.androidquery.util.AQUtility;
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
|
||||||
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||||
|
import io.fabric.sdk.android.Fabric;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.AppConstants;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.AppStage;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.MainActivity;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tpolgrabia on 19.09.16.
|
||||||
|
*/
|
||||||
|
public class HelperUtils {
|
||||||
|
private static final Logger lg = LoggerFactory.getLogger(HelperUtils.class);
|
||||||
|
public static final String FIRST_TIME_LAUNCH = "FIRST_TIME_LAUNCH_KEY";
|
||||||
|
public static final int LOCATION_SETTINGS_REQUEST_ID = 1;
|
||||||
|
|
||||||
|
public static void firstTimeNotification(Context ctx) {
|
||||||
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
|
if (sharedPrefs.getBoolean(FIRST_TIME_LAUNCH, true)) {
|
||||||
|
Toast.makeText(ctx, "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();
|
||||||
|
Toast.makeText(ctx, "To change panoramio / wiki search views swipe left or right",
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||||
|
editor.putBoolean(FIRST_TIME_LAUNCH, false);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initErrorAndDebugHanlers(Context ctx) {
|
||||||
|
AQUtility.setDebug(AppConstants.RELEASE != AppStage.FINAL
|
||||||
|
&& AppConstants.RELEASE != AppStage.RELEASE_CANDIDATE);
|
||||||
|
|
||||||
|
if (AppConstants.RELEASE == AppStage.FINAL
|
||||||
|
|| AppConstants.RELEASE == AppStage.RELEASE_CANDIDATE) {
|
||||||
|
Fabric.with(ctx, new Crashlytics());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initUniversalDownloader(Context ctx) {
|
||||||
|
MainActivity.options = ImageLoaderUtils.createDefaultOptions();
|
||||||
|
initUniversalDownloader(ctx, MainActivity.options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initUniversalDownloader(Context ctx, DisplayImageOptions defaultOptions) {
|
||||||
|
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||||
|
ctx)
|
||||||
|
.defaultDisplayImageOptions(defaultOptions)
|
||||||
|
.memoryCache(new WeakMemoryCache())
|
||||||
|
.discCacheSize(100 * 1024 * 1024).build();
|
||||||
|
|
||||||
|
ImageLoader.getInstance().init(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void appendEffectToTransition(FragmentTransaction ctx, int old, int curr) {
|
||||||
|
if (old != curr) {
|
||||||
|
if (curr < old) {
|
||||||
|
// slide left animation
|
||||||
|
lg.trace("sliding left animation");
|
||||||
|
ctx.setCustomAnimations(
|
||||||
|
R.anim.slide_in_left,
|
||||||
|
R.anim.slide_out_left,
|
||||||
|
R.anim.slide_in_right,
|
||||||
|
R.anim.slide_out_right);
|
||||||
|
} else {
|
||||||
|
// slide right animation
|
||||||
|
lg.trace("sliding right animation");
|
||||||
|
ctx.setCustomAnimations(
|
||||||
|
R.anim.slide_in_right,
|
||||||
|
R.anim.slide_out_right,
|
||||||
|
R.anim.slide_in_left,
|
||||||
|
R.anim.slide_out_left);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long fetchGpsUpdateFreq(Context ctx) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
|
String prefGpsUpdateFreq = sharedPreferences.getString(
|
||||||
|
AppConstants.PREF_GPS_UPDATE_FREQ,
|
||||||
|
String.valueOf(AppConstants.GPS_LOCATION_UPDATE_FREQ));
|
||||||
|
|
||||||
|
lg.debug("Pref GPS location update frequency {}", prefGpsUpdateFreq);
|
||||||
|
return Math.round(NumberUtils.safeParseDouble(prefGpsUpdateFreq)* 60.0 * 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Float fetchGpsDistanceFreq(Context ctx) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
|
String prefDistanceUpdateFreq = sharedPreferences.getString(
|
||||||
|
AppConstants.PREF_GPS_DISTANCE_FREQ,
|
||||||
|
String.valueOf(AppConstants.GPS_LOCATION_DISTANCE_FREQ));
|
||||||
|
|
||||||
|
lg.debug("Pref GPS distance update frequency {}", prefDistanceUpdateFreq);
|
||||||
|
return NumberUtils.safeParseFloat(prefDistanceUpdateFreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkForLocalicatonEnabled(Activity ctx) {
|
||||||
|
|
||||||
|
lg.trace("Check for location enabled");
|
||||||
|
final String locationProvider = LocationUtils.getDefaultLocation(ctx);
|
||||||
|
lg.debug("Location provider {}", locationProvider);
|
||||||
|
if (locationProvider == null) {
|
||||||
|
lg.debug("Location provider is null. Prompting for enabling location services");
|
||||||
|
Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
|
ctx.startActivityForResult(locationSettingsIntent, LOCATION_SETTINGS_REQUEST_ID);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void traceAllAvailableFragments(FragmentManager fragmentManager) {
|
||||||
|
final List<Fragment> fragments = fragmentManager.getFragments();
|
||||||
|
if (fragments != null) {
|
||||||
|
lg.trace("Available fragments {}", fragments.size());
|
||||||
|
for (Fragment frag : fragments) {
|
||||||
|
if (frag != null) {
|
||||||
|
lg.trace("Available fragment with id: {}, tag: {}", frag.getId(), frag.getTag());
|
||||||
|
} else {
|
||||||
|
lg.trace("Available null-fragment");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lg.trace("There are no fragments -> null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue