From 99d9e5ab31b48b32a71d42e0a3a33ccb8b2f70f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Sat, 8 Oct 2016 20:19:15 +0200 Subject: [PATCH] Fixing additional dependency of settings refreshing. --- .../callbacks/wiki/FetchWikiLocationsCallback.java | 10 +++++----- .../callbacks/wiki/WikiFetchAppDataCallback.java | 10 ++++------ .../urbanexplorer/fragments/WikiLocationsFragment.java | 8 +++++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/FetchWikiLocationsCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/FetchWikiLocationsCallback.java index b238ca5..b96fbed 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/FetchWikiLocationsCallback.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/FetchWikiLocationsCallback.java @@ -1,5 +1,6 @@ package pl.tpolgrabia.urbanexplorer.callbacks.wiki; +import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.AdapterView; import pl.tpolgrabia.urbanexplorer.AppConstants; @@ -15,17 +16,16 @@ import java.util.List; public class FetchWikiLocationsCallback implements AdapterView.OnItemLongClickListener { private final WikiUtils wikiUtils; private WikiLocationsFragment wikiLocationsFragment; - private final List appObjects; - public FetchWikiLocationsCallback(WikiLocationsFragment wikiLocationsFragment, List appObjects) { + public FetchWikiLocationsCallback(WikiLocationsFragment wikiLocationsFragment) { this.wikiLocationsFragment = wikiLocationsFragment; - this.wikiUtils = new WikiUtils(wikiLocationsFragment.getActivity(), AppConstants.DEF_WIKI_COUNTRY_CODE); - this.appObjects = appObjects; + final FragmentActivity activity = wikiLocationsFragment.getActivity(); + this.wikiUtils = new WikiUtils(activity, wikiLocationsFragment.getWikiLocale(activity)); } @Override public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { - final WikiAppObject item = appObjects.get(position); + final WikiAppObject item = wikiLocationsFragment.getAppObjects().get(position); wikiUtils.fetchSingleWikiInfoItemAndRunWikiPage( wikiLocationsFragment.getActivity(), item.getPageId(), diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java index cf38b96..eee05ed 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java @@ -5,16 +5,14 @@ import android.view.View; import android.widget.ListView; import android.widget.Toast; import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; import pl.tpolgrabia.urbanexplorer.MainActivity; import pl.tpolgrabia.urbanexplorer.R; import pl.tpolgrabia.urbanexplorer.adapters.WikiLocationsAdapter; -import pl.tpolgrabia.urbanexplorerutils.events.RefreshEvent; +import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment; +import pl.tpolgrabia.urbanexplorerutils.events.DataLoadingFinishEvent; +import pl.tpolgrabia.wikibinding.callback.WikiAppResponseCallback; import pl.tpolgrabia.wikibinding.callback.WikiStatus; import pl.tpolgrabia.wikibinding.dto.app.WikiAppObject; -import pl.tpolgrabia.urbanexplorerutils.events.DataLoadingFinishEvent; -import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment; -import pl.tpolgrabia.wikibinding.callback.WikiAppResponseCallback; import java.util.ArrayList; import java.util.List; @@ -53,7 +51,7 @@ public class WikiFetchAppDataCallback implements WikiAppResponseCallback { } ListView locations = (ListView) view.findViewById(R.id.wiki_places); - locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(wikiLocationsFragment, nobjects)); + locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(wikiLocationsFragment)); locations.setAdapter(new WikiLocationsAdapter(activity, objects)); if (objects.isEmpty()) { Toast.makeText(wikiLocationsFragment.getActivity(), "No results", Toast.LENGTH_SHORT).show(); 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 ce921e1..fec45a5 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -74,6 +74,8 @@ public class WikiLocationsFragment extends Fragment { private void refreshSettings() { geocoderUtils = new GeocoderUtils(getActivity(), AppConstants.GOOGLE_API_KEY); wikiUtils = new WikiUtils(getActivity(), getWikiLocale(getActivity())); + ListView locations = (ListView) getView().findViewById(R.id.wiki_places); + locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(this)); } @Override @@ -94,7 +96,7 @@ public class WikiLocationsFragment extends Fragment { EventBus.getDefault().register(providerHandler); ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places); - locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(WikiLocationsFragment.this, appObjects)); + locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(this)); locations.setAdapter(new WikiLocationsAdapter(getActivity(), appObjects)); return inflatedView; @@ -203,4 +205,8 @@ public class WikiLocationsFragment extends Fragment { lg.debug("Refreshing settings {}", event); refreshSettings(); } + + public ArrayList getAppObjects() { + return appObjects; + } }