Fixes to basic navigation.

master
Tomasz Półgrabia 2016-09-19 23:03:08 +02:00
parent 9e3d5428ab
commit 1bd1ca9dc1
6 changed files with 75 additions and 11 deletions

View File

@ -43,7 +43,7 @@ public class MainActivity extends ActionBarActivity {
private GestureDetector.OnGestureListener swipeHandler; private GestureDetector.OnGestureListener swipeHandler;
private PanoramioImageInfo photoInfo; private PanoramioImageInfo photoInfo;
private ProgressDialog progressDlg; private ProgressDialog progressDlg;
private MainActivityState oldFragmentId = MainActivityState.PANORAMIO private MainActivityState oldFrag = MainActivityState.PANORAMIO_SHOWER;
private boolean savedConfiguration; private boolean savedConfiguration;
private static final Map<Integer, String> fragTags = new HashMap<>(); private static final Map<Integer, String> fragTags = new HashMap<>();
@ -78,7 +78,7 @@ public class MainActivity extends ActionBarActivity {
lg.trace("onCreate"); lg.trace("onCreate");
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
HelperUtils.initErrorAndDebugHanlers(); HelperUtils.initErrorAndDebugHanlers(this);
NetUtils.setGlobalProxyAuth(this); NetUtils.setGlobalProxyAuth(this);
currFrag = MainActivityState.PANORAMIO; currFrag = MainActivityState.PANORAMIO;
@ -198,9 +198,12 @@ public class MainActivity extends ActionBarActivity {
private void switchFragment() { private void switchFragment() {
if (currFrag == oldFrag) {
return;
}
if (!savedConfiguration) { if (!savedConfiguration) {
photoInfo = null; photoInfo = null;
currFrag = MainActivityState.PANORAMIO;
} }
switch (currFrag) { switch (currFrag) {
@ -228,9 +231,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, currFrag); lg.trace("old newFragment id: {}, current newFragment id: {}", oldFrag, currFrag);
HelperUtils.appendEffectToTransition(ctx, oldFragmentId, currFrag); HelperUtils.appendEffectToTransition(ctx, oldFrag, currFrag);
HelperUtils.traceAllAvailableFragments(fragmentManager); HelperUtils.traceAllAvailableFragments(fragmentManager);
lg.trace("Trying to search newFragment by tag {}", tag); lg.trace("Trying to search newFragment by tag {}", tag);
@ -261,18 +264,22 @@ public class MainActivity extends ActionBarActivity {
public void swipeLeft() { public void swipeLeft() {
lg.debug("Swiped left"); lg.debug("Swiped left");
changeCurrentFragId((int)Math.max(AppConstants.MIN_FRAGMENT_ID, currFrag -1)); changeCurrentFragId(currFrag.prev());
switchFragment(); switchFragment();
} }
private void changeCurrentFragId(MainActivityState nextFragmentId) { private void changeCurrentFragId(MainActivityState nextFragmentId) {
oldFragmentId = currFrag; if (nextFragmentId == null) {
oldFrag = currFrag;
return;
}
oldFrag = currFrag;
currFrag = nextFragmentId; currFrag = nextFragmentId;
} }
public void swipeRight() { public void swipeRight() {
lg.debug("Swiped right"); lg.debug("Swiped right");
changeCurrentFragId((int)Math.min(AppConstants.MAX_FRAGMENT_ID, currFrag +1)); changeCurrentFragId(currFrag.next());
switchFragment(); switchFragment();
} }

View File

@ -2,6 +2,7 @@ package pl.tpolgrabia.urbanexplorer.callbacks;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast; import android.widget.Toast;
import com.androidquery.callback.AjaxCallback; import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus; import com.androidquery.callback.AjaxStatus;
@ -44,7 +45,13 @@ public class WikiInfoRunBrowserCallback extends AjaxCallback<JSONObject> {
.getString("fullurl"); .getString("fullurl");
Intent intent = new Intent(Intent.ACTION_VIEW, Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(wikiUrl)); Uri.parse(wikiUrl));
wikiLocationsFragment.startActivity(intent); FragmentActivity activity = wikiLocationsFragment.getActivity();
if (activity == null) {
lg.debug("Fragment is not attached to activity");
return;
}
activity.startActivity(intent);
} catch (JSONException e) { } catch (JSONException e) {
lg.error("JSON error", e); lg.error("JSON error", e);
} }

View File

@ -1,5 +1,7 @@
package pl.tpolgrabia.urbanexplorer.dto; package pl.tpolgrabia.urbanexplorer.dto;
import pl.tpolgrabia.urbanexplorer.MainActivity;
/** /**
* Created by tpolgrabia on 19.09.16. * Created by tpolgrabia on 19.09.16.
*/ */
@ -17,4 +19,42 @@ public enum MainActivityState {
public Integer getOrder() { public Integer getOrder() {
return order; return order;
} }
public MainActivityState prev() {
int val = Integer.MIN_VALUE;
MainActivityState greatestSmaller = null;
for (MainActivityState state : values()) {
if (state.getOrder() >= order || state.getOrder() < 0) {
continue;
}
// we need the greatest smaller
if (state.getOrder() > val) {
val = state.getOrder();
greatestSmaller = state;
}
}
return greatestSmaller;
}
public MainActivityState next() {
int val = Integer.MAX_VALUE;
MainActivityState smallestGreater = null;
for (MainActivityState state : values()) {
if (state.getOrder() <= order || state.getOrder() < 0) {
continue;
}
// we need the smallest greater
if (state.getOrder() < val) {
val = state.getOrder();
smallestGreater = state;
}
}
return smallestGreater;
}
} }

View File

@ -295,7 +295,13 @@ public class HomeFragment extends Fragment implements Refreshable {
return; return;
} }
ListView locations = (ListView) getView().findViewById(R.id.locations); final View view = getView();
if (view == null) {
lg.debug("View still not initialized");
return;
}
ListView locations = (ListView) view.findViewById(R.id.locations);
if (locations == null) { if (locations == null) {
lg.trace("Empty locations"); lg.trace("Empty locations");
return; return;

View File

@ -49,7 +49,7 @@ public class WikiLocationsFragment extends Fragment implements Refreshable {
private static final String WIKI_APP_OBJECTS = "WIKI_APP_OBJECTS"; private static final String WIKI_APP_OBJECTS = "WIKI_APP_OBJECTS";
private LocationManager locationService; private LocationManager locationService;
private TextView currentLocation; private TextView currentLocation;
private ArrayList<WikiAppObject> appObjects; private ArrayList<WikiAppObject> appObjects = new ArrayList<>();
private int lastFetchSize = -1; private int lastFetchSize = -1;
public WikiLocationsFragment() { public WikiLocationsFragment() {

View File

@ -74,6 +74,10 @@ public class HelperUtils {
} }
public static void appendEffectToTransition(FragmentTransaction ctx, MainActivityState old, MainActivityState curr) { public static void appendEffectToTransition(FragmentTransaction ctx, MainActivityState old, MainActivityState curr) {
if (old.getOrder() == -1 || curr.getOrder() == -1) {
return;
}
if (old != curr) { if (old != curr) {
if (curr.getOrder() < old.getOrder()) { if (curr.getOrder() < old.getOrder()) {
// slide left animation // slide left animation