Making some more logs.

master
Tomasz Półgrabia 2016-09-18 21:57:33 +02:00
parent a9af2c2015
commit 225d4c0808
3 changed files with 98 additions and 37 deletions

View File

@ -40,6 +40,8 @@ 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;
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);
@ -245,11 +247,11 @@ public class MainActivity extends ActionBarActivity {
} }
private void switchFragment(Fragment fragment, String tag) { private void switchFragment(Fragment newFragment, String tag) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction ctx = fragmentManager.beginTransaction(); FragmentTransaction ctx = fragmentManager.beginTransaction();
lg.trace("old fragment id: {}, current fragment id: {}", oldFragmentId, currentFragmentId); lg.trace("old newFragment id: {}, current newFragment id: {}", oldFragmentId, currentFragmentId);
if (oldFragmentId != currentFragmentId) { if (oldFragmentId != currentFragmentId) {
if (currentFragmentId < oldFragmentId) { if (currentFragmentId < oldFragmentId) {
// slide left animation // slide left animation
@ -270,11 +272,28 @@ public class MainActivity extends ActionBarActivity {
} }
} }
Fragment frag = fragmentManager.findFragmentByTag(tag); final List<Fragment> fragments = fragmentManager.getFragments();
if (frag == null) { if (fragments != null) {
ctx.replace(R.id.fragments, fragment, tag); 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 { } else {
ctx.replace(R.id.fragments, frag); lg.trace("There are no fragments -> null");
}
lg.trace("Trying to search newFragment by tag {}", tag);
Fragment currFragment = fragmentManager.findFragmentByTag(tag);
if (currFragment == null) {
lg.trace("Using new newFragment: {}", System.identityHashCode(newFragment));
ctx.replace(R.id.fragments, newFragment, tag);
} else {
lg.trace("Reusing old newFragment: {}", System.identityHashCode(currFragment));
ctx.replace(R.id.fragments, currFragment);
} }
// ctx.addToBackStack(MAIN_BACKSTACK); // ctx.addToBackStack(MAIN_BACKSTACK);
ctx.commit(); ctx.commit();
@ -429,4 +448,17 @@ public class MainActivity extends ActionBarActivity {
lg.trace("2 Saving current fragment id: {}", currentFragmentId); lg.trace("2 Saving current fragment id: {}", currentFragmentId);
} }
@Override
protected void onStop() {
super.onStop();
lg.trace("onStop {}", System.identityHashCode(this));
}
@Override
protected void onStart() {
super.onStart();
lg.trace("onStart {}", System.identityHashCode(this));
}
} }

View File

@ -66,7 +66,7 @@ public class HomeFragment extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
lg.trace("onCreate"); lg.trace("onCreate {}", System.identityHashCode(this));
pageId = 1L; pageId = 1L;
loading = new Semaphore(1, true); loading = new Semaphore(1, true);
noMorePhotos = false; noMorePhotos = false;
@ -249,31 +249,39 @@ public class HomeFragment extends Fragment {
new PanoramioResponseCallback() { new PanoramioResponseCallback() {
@Override @Override
public void callback(PanoramioResponseStatus status, List<PanoramioImageInfo> images, Long imagesCount) { public void callback(PanoramioResponseStatus status, List<PanoramioImageInfo> images, Long imagesCount) {
lg.debug("Fetched with status: {}, images: {}, count: {}", status, images, imagesCount); try {
if (status != PanoramioResponseStatus.SUCCESS) { lg.debug("Fetched with status: {}, images: {}, count: {}", status, images, imagesCount);
return; if (status != PanoramioResponseStatus.SUCCESS) {
return;
}
ListView locations = (ListView) getView().findViewById(R.id.locations);
if (locations == null) {
lg.trace("Empty locations");
return;
}
ArrayAdapter<PanoramioImageInfo> adapter = (ArrayAdapter<PanoramioImageInfo>) 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));
} else {
adapter.addAll(images);
}
// TODO we can think about removing first items also and last if the number
// TODO of items exceeds the limit (to save the memory)
lg.debug("Finished Fetching additional photos count: {}", photos.size());
} finally {
lg.trace("Releasing fetching lock");
loading.release();
} }
ListView locations = (ListView) getView().findViewById(R.id.locations);
ArrayAdapter<PanoramioImageInfo> adapter = (ArrayAdapter<PanoramioImageInfo>) 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));
} else {
adapter.addAll(images);
}
// TODO we can think about removing first items also and last if the number
// TODO of items exceeds the limit (to save the memory)
lg.debug("Finished Fetching additional photos count: {}", photos.size());
loading.release();
} }
} }
@ -411,4 +419,17 @@ public class HomeFragment extends Fragment {
lg.trace("Saved photos: {}", photos); lg.trace("Saved photos: {}", photos);
} }
@Override
public void onStop() {
super.onStop();
lg.trace("onStop {}", System.identityHashCode(this));
}
@Override
public void onStart() {
super.onStart();
lg.trace("onStart {}", System.identityHashCode(this));
}
} }

View File

@ -56,7 +56,7 @@ public class WikiLocationsFragment extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
lg.trace("onCreate"); lg.trace("onCreate {}", System.identityHashCode(this));
appObjects = savedInstanceState == null ? new ArrayList<WikiAppObject>() appObjects = savedInstanceState == null ? new ArrayList<WikiAppObject>()
: (ArrayList<WikiAppObject>)savedInstanceState.getSerializable(WIKI_APP_OBJECTS);; : (ArrayList<WikiAppObject>)savedInstanceState.getSerializable(WIKI_APP_OBJECTS);;
} }
@ -99,6 +99,12 @@ public class WikiLocationsFragment extends Fragment {
public void fetchWikiLocations() { public void fetchWikiLocations() {
lg.trace("Fetch wiki locations"); lg.trace("Fetch wiki locations");
final FragmentActivity activity = getActivity();
if (activity == null) {
lg.warn("Activity shouldn't be null. No headless fragment");
return;
}
MainActivity mainActivity = (MainActivity) getActivity(); MainActivity mainActivity = (MainActivity) getActivity();
if (lastFetchSize == 0) { if (lastFetchSize == 0) {
@ -113,12 +119,6 @@ public class WikiLocationsFragment extends Fragment {
return; return;
} }
final FragmentActivity activity = getActivity();
if (activity == null) {
lg.warn("Activity shouldn't be null. No headless fragment");
mainActivity.hideProgress();
return;
}
final Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(activity)); final Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(activity));
if (location == null) { if (location == null) {
@ -192,6 +192,7 @@ public class WikiLocationsFragment extends Fragment {
getActivity().setTitle("Wiki search"); getActivity().setTitle("Wiki search");
updateLocationInfo(); updateLocationInfo();
fetchWikiLocations(); fetchWikiLocations();
lg.trace("onResume {}", System.identityHashCode(this));
} }
public void updateLocationInfo() { public void updateLocationInfo() {
@ -212,6 +213,7 @@ public class WikiLocationsFragment extends Fragment {
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
lg.trace("onPause {}", System.identityHashCode(this));
} }
@Override @Override
@ -221,4 +223,10 @@ public class WikiLocationsFragment extends Fragment {
outState.putSerializable(WIKI_APP_OBJECTS, appObjects); outState.putSerializable(WIKI_APP_OBJECTS, appObjects);
} }
@Override
public void onDestroy() {
super.onDestroy();
lg.trace("onDestroy {}", System.identityHashCode(this));
}
} }