Prepare to do search

This commit is contained in:
Vladislav Khorev 2015-06-25 20:15:00 +00:00
parent c5e5df9e52
commit 8e393dc2bf
4 changed files with 220 additions and 49 deletions

View File

@ -15,6 +15,7 @@ import org.osmdroid.views.MapView;
import fishrungames.bashgid.OsmMapHolderFragment.CustomItemizedOverlay; import fishrungames.bashgid.OsmMapHolderFragment.CustomItemizedOverlay;
import fishrungames.bashgid.OsmMapHolderFragment.NoInteractionOverlay; import fishrungames.bashgid.OsmMapHolderFragment.NoInteractionOverlay;
import fishrungames.bashgid.core.DatabaseGetAlbumTask; import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.DatabaseGetArticleTask;
import fishrungames.bashgid.core.LocationHolder; import fishrungames.bashgid.core.LocationHolder;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData; import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
@ -24,6 +25,7 @@ import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -33,6 +35,7 @@ import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -90,6 +93,31 @@ public class ArticleFragment extends Fragment
} }
} }
public class MapOverlay extends org.osmdroid.views.overlay.Overlay {
public MapOverlay(Context ctx)
{
super(ctx);
}
@Override
protected void draw(Canvas arg0, MapView arg1, boolean arg2)
{
}
@Override
public boolean onTouchEvent(final MotionEvent event, final MapView mapView) {
if (event.getAction() == MotionEvent.ACTION_UP)
{
MainActivity.getInstance().OpenMapScreen(article);
}
return true;
}
}
ListView listView; ListView listView;
@ -221,38 +249,6 @@ public class ArticleFragment extends Fragment
return rootView; return rootView;
} }
public class DatabaseGetArticleTask extends AsyncTask<String, Integer, Long>
{
ArticleFullData article;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String articleName = queryArr[0];
article = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_UPDATE, article);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_FINISHED, article);
completeMessage.sendToTarget();
}
}
public class ListAdapter extends BaseAdapter { public class ListAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
@ -367,7 +363,7 @@ public class ArticleFragment extends Fragment
mapView.setMinZoomLevel(4); mapView.setMinZoomLevel(4);
//mapView.setBuiltInZoomControls(true); //mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true); //mapView.setMultiTouchControls(true);
IMapController mapController = mapView.getController(); IMapController mapController = mapView.getController();
@ -386,6 +382,12 @@ public class ArticleFragment extends Fragment
mapView.getOverlays().add(itemizedOverlay); mapView.getOverlays().add(itemizedOverlay);
MapOverlay mapOverlay = new MapOverlay(getActivity());
mapView.getOverlays().add(mapOverlay);
} }
else if (getItemViewType(position) == 4) else if (getItemViewType(position) == 4)
{ {

View File

@ -479,6 +479,11 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
newsRecordFragment.SetArticle(article); newsRecordFragment.SetArticle(article);
} }
if (mapHolderFragment != null)
{
mapHolderFragment.SetArticle(article);
}
} }
public void UpdateOnAlbumListLoaded(ArrayList<AlbumShortData> albumList) public void UpdateOnAlbumListLoaded(ArrayList<AlbumShortData> albumList)
@ -689,7 +694,28 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
mapHolderFragment = new OsmMapHolderFragment(filter); mapHolderFragment = new OsmMapHolderFragment(0, filter);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
/*
public void OpenMapScreenByArticleName(String articleName)
{
ClearAllFragmentLinks();
mapHolderFragment = new OsmMapHolderFragment(1, articleName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}*/
public void OpenMapScreen(ArticleFullData articleFullData)
{
ClearAllFragmentLinks();
mapHolderFragment = new OsmMapHolderFragment(articleFullData);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();

View File

@ -30,7 +30,9 @@ import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.OverlayItem; import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.OverlayItem.HotspotPlace; import org.osmdroid.views.overlay.OverlayItem.HotspotPlace;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.DatabaseGetArticleTask;
import fishrungames.bashgid.core.DatabaseGetJournalTask; import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager; import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.LocationHolder; import fishrungames.bashgid.core.LocationHolder;
@ -162,32 +164,54 @@ public class OsmMapHolderFragment extends Fragment
{ {
return false; return false;
} }
} }
CustomItemizedOverlay itemizedOverlay; CustomItemizedOverlay itemizedOverlay;
String journalName; String filter;
JournalSemiFullData journal; JournalSemiFullData journal;
ArticleFullData article;
int filterType;
public OsmMapHolderFragment() public OsmMapHolderFragment()
{ {
journal = null; journal = null;
journalName = ""; article = null;
filter = "";
filterType = 0;
} }
public OsmMapHolderFragment(String journalName) public OsmMapHolderFragment(int filterType, String filter)
{ {
this.journalName = journalName; this.journal = null;
RestoreJournal(); this.article = null;
this.filter = filter;
this.filterType = filterType;
RestoreJournalOrArticle();
}
public OsmMapHolderFragment(ArticleFullData article)
{
this.filter = article.name;
this.filterType = 1;
this.article = article;
this.journal = null;
} }
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putString("journalName", journalName); outState.putString("filter", filter);
outState.putInt("filterType", filterType);
} }
@ -198,15 +222,24 @@ public class OsmMapHolderFragment extends Fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) { if (savedInstanceState != null) {
journalName = savedInstanceState.getString("journalName"); filter = savedInstanceState.getString("filter");
RestoreJournal(); filterType = savedInstanceState.getInt("filterType");
RestoreJournalOrArticle();
} }
View rootView = inflater.inflate(R.layout.fragment_osm_map_page, container, false); View rootView = inflater.inflate(R.layout.fragment_osm_map_page, container, false);
textView = (TextView) rootView.findViewById(R.id.textView); textView = (TextView) rootView.findViewById(R.id.textView);
if ((filterType == 0 && journal == null) || (filterType == 1 && article == null))
{
textView.setText("Loading map..."); textView.setText("Loading map...");
}
else
{
textView.setText("Map is loaded");
}
mapView = (MapView) rootView.findViewById(R.id.mapview); mapView = (MapView) rootView.findViewById(R.id.mapview);
@ -231,9 +264,22 @@ public class OsmMapHolderFragment extends Fragment
} }
void RestoreJournalOrArticle()
{
if (filterType == 0)
{
RestoreJournal();
}
else
{
RestoreArticle();
}
}
void RestoreJournal() void RestoreJournal()
{ {
journal = JournalManager.CreateEmptyJournal(); //journal = JournalManager.CreateEmptyJournal();
DatabaseGetJournalTask task = new DatabaseGetJournalTask(); DatabaseGetJournalTask task = new DatabaseGetJournalTask();
@ -241,15 +287,27 @@ public class OsmMapHolderFragment extends Fragment
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("journalName", journalName); bundle.putString("journalName", filter);
task.execute(bundle); task.execute(bundle);
}
void RestoreArticle()
{
DatabaseGetArticleTask task = new DatabaseGetArticleTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(filter);
} }
public void SetJournal(JournalSemiFullData journal) public void SetJournal(JournalSemiFullData journal)
{ {
filterType = 0;
textView.setText("Map is loaded"); textView.setText("Map is loaded");
this.journal = journal; this.journal = journal;
@ -258,12 +316,29 @@ public class OsmMapHolderFragment extends Fragment
} }
public void SetArticle(ArticleFullData article)
{
filterType = 1;
textView.setText("Map is loaded");
this.article = article;
RefreshView();
}
public void RefreshView() public void RefreshView()
{
ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getActivity());
itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy, filter);
if (filterType == 0)
{ {
if (journal != null) if (journal != null)
{ {
ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getActivity());
itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy, journalName);
for (int i = 0; i < journal.articleArr.size(); i++) for (int i = 0; i < journal.articleArr.size(); i++)
{ {
@ -277,6 +352,35 @@ public class OsmMapHolderFragment extends Fragment
} }
} }
}
}
else
{
if (article != null)
{
if (article.geoLat != 0 || article.geoLon != 0)
{
GeoPoint markerPoint = new GeoPoint(article.geoLat, article.geoLon);
String imageUrl = "R.drawable.no_picture";
if (article.albumArr.size() > 0)
{
if (article.albumArr.get(0).photoRecordArr.size() > 0)
{
imageUrl = article.albumArr.get(0).photoRecordArr.get(0).imageUrl;
}
}
itemizedOverlay.addOverlayItem(markerPoint, article.name, article.title, imageUrl);
}
}
}
mapView.getOverlays().clear(); mapView.getOverlays().clear();
mapView.getOverlays().add(itemizedOverlay); mapView.getOverlays().add(itemizedOverlay);
@ -284,6 +388,6 @@ public class OsmMapHolderFragment extends Fragment
mapView.invalidate(); mapView.invalidate();
} }
}
} }

View File

@ -0,0 +1,39 @@
package fishrungames.bashgid.core;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
public class DatabaseGetArticleTask extends AsyncTask<String, Integer, Long>
{
ArticleFullData article;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String articleName = queryArr[0];
article = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_UPDATE, article);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_FINISHED, article);
completeMessage.sendToTarget();
}
}