diff --git a/android/res/layout/main_page_search.xml b/android/res/layout/main_page_search.xml
index 2123d6f..abf740e 100644
--- a/android/res/layout/main_page_search.xml
+++ b/android/res/layout/main_page_search.xml
@@ -36,7 +36,7 @@
+ android:contentDescription="@string/news_content_description"
+ android:scaleType="centerInside" />
diff --git a/android/res/layout/search_page_list_header.xml b/android/res/layout/search_page_list_header.xml
index 4ac816d..edf3957 100644
--- a/android/res/layout/search_page_list_header.xml
+++ b/android/res/layout/search_page_list_header.xml
@@ -8,6 +8,15 @@
android:paddingRight="20dp"
tools:context="fishrungames.bashgid.SearchFragment" >
+
+
) inputMessage.obj);
+ break;
+
default:
@@ -399,6 +411,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
videoRecordFragment = null;
mapHolderFragment = null;
+ searchFragment = null;
catalogFragment = null;
}
@@ -517,8 +530,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mapHolderFragment.SetJournal(journal);
}
-
-
}
@@ -553,6 +564,44 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
}
+ public void UpdateOnArticleSearchPerformed(ArrayList articleArr)
+ {
+
+ if (searchFragment != null)
+ {
+ searchFragment.SetSearchResult(articleArr);
+ }
+ }
+
+
+ public void OnSearchPressed()
+ {
+ if (searchFragment != null)
+ {
+ return;
+ }
+
+ if (newsListFragment != null || newsRecordFragment != null)
+ {
+ OpenSearchScreen("news", "News");
+ return;
+ }
+
+ if (journalFragment != null)
+ {
+ if (journalFragment.journal == null)
+ {
+ OpenSearchScreen(journalFragment.journalName, "");
+ }
+ else
+ {
+ OpenSearchScreen(journalFragment.journalName, journalFragment.journal.title);
+ }
+ return;
+ }
+
+ OpenSearchScreen();
+ }
public void OnSelectEnglish(View view)
@@ -664,22 +713,38 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public void OpenSearchScreen()
{
ClearAllFragmentLinks();
+
+ searchFragment = new SearchFragment();
- getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(), TAG_TO_SEARCHFRAGMENT).commit();
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, searchFragment, TAG_TO_MAINFRAGMENT).commit();
+
+ mNavigationDrawerFragment.EnableDrawer();
+ }
+
+ public void OpenSearchScreen(String journalName, String journalTitle)
+ {
+ ClearAllFragmentLinks();
+
+ searchFragment = new SearchFragment(journalName, journalTitle);
+
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, searchFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
- public void OpenSearchScreen(boolean restorePreviousSearch)
+ /*
+ public void OpenSearchScreen()
{
ClearAllFragmentLinks();
+
+ SearchFragment
- getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(restorePreviousSearch), TAG_TO_SEARCHFRAGMENT)
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(), TAG_TO_SEARCHFRAGMENT)
.commit();
mNavigationDrawerFragment.EnableDrawer();
- }
+ }*/
public void OpenLinkContentScreen(TextFileRecord contentRecord)
{
@@ -880,6 +945,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mainPageFragment.RefreshJournal();
}
}
+
@Override
public void onAttachFragment(Fragment fragment)
@@ -920,11 +986,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
if (id == R.id.action_search)
{
- if (getSupportFragmentManager().findFragmentByTag(TAG_TO_SEARCHFRAGMENT) == null
- && getSupportFragmentManager().findFragmentByTag(TAG_TO_WELCOMEFRAGMENT) == null)
- {
- OpenSearchScreen();
- }
+ OnSearchPressed();
return true;
}
@@ -1007,7 +1069,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT) != null)
{
- OpenSearchScreen(true);
+ OpenSearchScreen();
return;
}
diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java
index 502ea31..e7f711c 100644
--- a/android/src/fishrungames/bashgid/MainPageFragment.java
+++ b/android/src/fishrungames/bashgid/MainPageFragment.java
@@ -80,6 +80,19 @@ public class MainPageFragment extends Fragment {
}
}
);
+
+ Button searchButton = (Button) header.findViewById(R.id.searchButton);
+
+ searchButton.setOnClickListener(new OnClickListener()
+ {
+
+ @Override
+ public void onClick(View v)
+ {
+ MainActivity.getInstance().OpenSearchScreen();
+ }
+ }
+ );
return rootView;
}
@@ -197,7 +210,6 @@ public class MainPageFragment extends Fragment {
@SuppressLint("InflateParams")
public View getView(int position, View convertView, ViewGroup parent) {
-
View view;
if (convertView == null) { // if it's not recycled, initialize some attributes
diff --git a/android/src/fishrungames/bashgid/SearchFragment.java b/android/src/fishrungames/bashgid/SearchFragment.java
index 4fd2b83..f30abab 100644
--- a/android/src/fishrungames/bashgid/SearchFragment.java
+++ b/android/src/fishrungames/bashgid/SearchFragment.java
@@ -3,6 +3,10 @@ package fishrungames.bashgid;
import java.util.ArrayList;
+import fishrungames.bashgid.core.ArticleManager;
+import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
+import fishrungames.bashgid.core.DatabaseGetJournalTask;
+import fishrungames.bashgid.core.DatabaseSearchArticleTask;
import fishrungames.bashgid.core.NewsManager;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
import fishrungames.bashgid.core.db.NewsDataSource;
@@ -28,7 +32,7 @@ import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
-public class SearchFragment extends Fragment implements UpdateAndFinishCallbackInterface
+public class SearchFragment extends Fragment
{
ListView listView;
@@ -37,48 +41,60 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
EditText searchEditText;
- ArrayList searchResultArr = new ArrayList();
-
- volatile boolean searchIsPerformingNow = false;
+ ArrayList searchResultArr = new ArrayList();
- //NewsSearchRunnable nextSearchRunnable = null;
+ String journalName;
+ String journalTitle;
- boolean restorePreviousSearch = false;
-
- RemoveCallbackInterface removeCallback = null;
- Object removeCallbackSynchronizer = new Object();
+ DatabaseSearchArticleTask databaseSearchArticleTask = null;
public SearchFragment()
{
+ this.journalName = "";
+ this.journalTitle = "";
}
- public SearchFragment(boolean restorePreviousSearch)
+ public SearchFragment(String journalName, String journalTitle)
{
- this.restorePreviousSearch = restorePreviousSearch;
+ this.journalName = journalName;
+ this.journalTitle = journalTitle;
}
+ @Override
+ public void onSaveInstanceState(final Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString("journalName", journalName);
+ outState.putString("journalTitle", journalTitle);
+ }
+
@SuppressLint("InflateParams") @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+ if (savedInstanceState != null) {
+ journalName = savedInstanceState.getString("journalName");
+ journalTitle = savedInstanceState.getString("journalTitle");
+
+ }
View rootView = inflater.inflate(R.layout.fragment_search_page, container, false);
listView = (ListView) rootView.findViewById(R.id.listView);
- listAdapter = new ListAdapter(getActivity());
-
- listView.setAdapter(listAdapter);
-
View header = inflater.inflate(R.layout.search_page_list_header, null);
- searchEditText = (EditText) header.findViewById(R.id.editText);
+ TextView textView = (TextView) header.findViewById(R.id.textView);
- if (restorePreviousSearch)
+ if (journalTitle == null || journalTitle.length() == 0)
{
- searchEditText.setText(NewsManager.getInstance().getLastSearchQuery());
- searchResultArr = NewsManager.getInstance().getSearchResultNews();
+ textView.setText("Search everywhere");
+ }
+ else
+ {
+ textView.setText("Search in: " + journalTitle);
}
-
+ searchEditText = (EditText) header.findViewById(R.id.editText);
+
searchEditText.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
@@ -93,28 +109,25 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
-
-
listView.addHeaderView(header);
-
+
+ listAdapter = new ListAdapter(getActivity());
+
+ listView.setAdapter(listAdapter);
+
+
return rootView;
}
- @Override
- public void onDestroyView()
+
+ public void SetSearchResult(ArrayList articleArr)
{
- synchronized (removeCallbackSynchronizer)
- {
- if (removeCallback != null)
- {
- removeCallback.RemoveCallback();
- removeCallback = null;
- }
- }
- super.onDestroyView();
+ searchResultArr = articleArr;
+ listAdapter.notifyDataSetChanged();
}
+
public class ListAdapter extends BaseAdapter {
private Context mContext;
@@ -154,76 +167,78 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
- ImageManager.getInstance().ApplyImageToImageView(imageButton, searchResultArr.get(position).imageId);
+ ImageManager.getInstance().ApplyImageToImageView(imageButton, searchResultArr.get(position).previewImageUrl);
button.setText(searchResultArr.get(position).title);
- textView.setText(NewsDataSource.iso8601Format.format(searchResultArr.get(position).pubDate));
+ textView.setText(NewsDataSource.iso8601Format.format(searchResultArr.get(position).dateTime));
- button.setOnClickListener(new ButtonOnClickListener(searchResultArr.get(position)));
- imageButton.setOnClickListener(new ButtonOnClickListener(searchResultArr.get(position)));
+
+ button.setOnClickListener(new ButtonOnClickListener(searchResultArr.get(position).name, searchResultArr.get(position).type));
+
+ imageButton.setOnClickListener(new ButtonOnClickListener(searchResultArr.get(position).name, searchResultArr.get(position).type));
return view;
}
}
- @Override
- public void OnFinished()
- {
- synchronized (removeCallbackSynchronizer)
- {
- removeCallback = null;
- }
-
- }
-
- @Override
- public void OnUpdated(Bundle result)
- {
- getActivity().runOnUiThread(new RefreshSearchListRunnable());
- }
public void CallUpdateNews(String text)
{
- Bundle query = new Bundle();
-
- query.putString("query", text);
-
- removeCallback = UniversalActionWithCallback.PerformAction(new NewsSearchRunnable(), query, this, "NewsSearchRunnable");
-
- }
-
- private class RefreshSearchListRunnable implements Runnable
- {
-
- @Override
- public void run()
+ if (text.length() >= 3)
{
- searchResultArr = NewsManager.getInstance().getSearchResultNews();
-
- listAdapter.notifyDataSetChanged();
+ if (databaseSearchArticleTask != null)
+ {
+ databaseSearchArticleTask.cancel(false);
+ }
+ databaseSearchArticleTask = new DatabaseSearchArticleTask();
+
+ databaseSearchArticleTask.mHandler = MainActivity.getInstance().mHandler;
+
+ Bundle bundle = new Bundle();
+
+ bundle.putString("journalName", journalName);
+ bundle.putString("query", text);
+
+ databaseSearchArticleTask.execute(bundle);
+ }
+ else
+ {
+ searchResultArr.clear();
+ listAdapter.notifyDataSetChanged();
}
-
}
-
-
+
+
public static class ButtonOnClickListener implements OnClickListener
{
- NewsRecord newsRecord;
+ //NewsRecord newsRecord;
+ String articleName;
+ int articleType;
- public ButtonOnClickListener(NewsRecord newsRecord)
+ public ButtonOnClickListener(String articleName, int articleType)
{
- this.newsRecord = newsRecord;
+ this.articleName = articleName;
+ this.articleType = articleType;
+ //this.newsRecord = newsRecord;
}
@Override
public void onClick(View v)
{
- //MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT);
+ if (articleType == ArticleManager.ARTICLE_TYPE_NEWS)
+ {
+ MainActivity.getInstance().OpenNewsRecordScreen(articleName, MainActivity.TAG_TO_MAINFRAGMENT);
+ }
+ else
+ {
+ MainActivity.getInstance().OpenArticleScreen(articleName, MainActivity.TAG_TO_MAINFRAGMENT);
+ }
+
}
}
diff --git a/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java b/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java
new file mode 100644
index 0000000..2f8b301
--- /dev/null
+++ b/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java
@@ -0,0 +1,60 @@
+package fishrungames.bashgid.core;
+
+
+import java.util.ArrayList;
+
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+
+import fishrungames.bashgid.MainActivity;
+import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
+import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
+
+public class DatabaseSearchArticleTask extends AsyncTask
+{
+
+ public Handler mHandler;
+
+ ArrayList articleArr = new ArrayList();
+
+ protected Long doInBackground(Bundle... queryArr)
+ {
+ String query = queryArr[0].getString("query");
+
+ String journalName = queryArr[0].getString("journalName");
+
+
+ if (journalName != null && journalName.length() > 0)
+ {
+ articleArr = MainActivity.getInstance().articleDataSource.SearchArticleByQueryAndJournal(query, journalName);
+ }
+ else
+ {
+ articleArr = MainActivity.getInstance().articleDataSource.SearchArticleByQuery(query);
+
+ }
+
+ //articleArr.addAll(journal.articleArr);
+
+ return (long) 0;
+ }
+
+ protected void onProgressUpdate(Integer... progress)
+ {
+ Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_SEARCH_ARTICLE_STATE_UPDATE, articleArr);
+
+ completeMessage.sendToTarget();
+
+ }
+
+ protected void onPostExecute(Long result)
+ {
+ Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_SEARCH_ARTICLE_STATE_FINISHED, articleArr);
+
+ completeMessage.sendToTarget();
+ }
+
+
+}
\ No newline at end of file
diff --git a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java
index 6397cef..f3bcc07 100644
--- a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java
+++ b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java
@@ -237,6 +237,79 @@ public class ArticleDataSource
return result;
}
+
+ public ArrayList SearchArticleByQuery(String query)
+ {
+ ArrayList result = new ArrayList();
+
+ SQLiteDatabase database = dbHelper.getWritableDatabase();
+
+ if (database != null)
+ {
+ try
+ {
+ result = InnerSearchArticleByQuery(query, database);
+
+
+ } finally
+ {
+ dbHelper.close();
+ }
+ }
+
+ return result;
+ }
+
+ public ArrayList SearchArticleByQueryAndJournal(String query, String journalName)
+ {
+ ArrayList result = new ArrayList();
+
+ SQLiteDatabase database = dbHelper.getWritableDatabase();
+
+ if (database != null)
+ {
+ try
+ {
+
+ ArrayList intermediateResult = InnerSearchArticleByQuery(query, database);
+
+ for (ArticleShortData article : intermediateResult)
+ {
+ if (MainActivity.getInstance().journalDataSource.InnerArticleJournalRelationAlreadyExist(article.name, journalName, database))
+ {
+ result.add(article);
+ }
+ }
+
+
+ } finally
+ {
+ dbHelper.close();
+ }
+ }
+
+ return result;
+ }
+
+ public ArrayList InnerSearchArticleByQuery(String query, SQLiteDatabase database)
+ {
+ ArrayList result = new ArrayList();
+
+
+ ArrayList recordDataArr = innerGetArticlesByQuery(query, database);
+
+ for (int i = 0; i < recordDataArr.size(); i++)
+ {
+ ArticleShortData article = new ArticleShortData(recordDataArr.get(i));
+
+ article.previewImageUrl = getPreviewImageUrlForArticle(recordDataArr.get(i).name, database);
+
+ result.add(article);
+ }
+
+
+ return result;
+ }
public ArticleShortData InnerGetArticleShortData(String name, SQLiteDatabase database)
@@ -251,35 +324,8 @@ public class ArticleDataSource
result = new ArticleShortData(recordData);
- ArrayList albumNameArr = innerGetAlbumNameArrInArticle(name, database);
- result.previewImageUrl = "R.drawable.no_picture";
-
- if (albumNameArr.size() > 0)
- {
- AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database);
-
- if (album.photoRecordArr.size() > 0)
- {
- result.previewImageUrl = album.photoRecordArr.get(0).imageUrl;
- }
-
- }
-
- if (result.previewImageUrl.equals("R.drawable.no_picture"))
- {
- ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database);
-
- if (channelNameArr.size() > 0)
- {
- ChannelFullData channelFullData = MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database);
-
- if (channelFullData.videoRecordArr.size() > 0)
- {
- result.previewImageUrl = channelFullData.videoRecordArr.get(0).previewImageUrl;
- }
- }
- }
+ result.previewImageUrl = getPreviewImageUrlForArticle(name, database);
}
@@ -287,6 +333,41 @@ public class ArticleDataSource
return result;
}
+ private String getPreviewImageUrlForArticle(String name, SQLiteDatabase database)
+ {
+ String result = "R.drawable.no_picture";
+
+ ArrayList albumNameArr = innerGetAlbumNameArrInArticle(name, database);
+
+ if (albumNameArr.size() > 0)
+ {
+ AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database);
+
+ if (album.photoRecordArr.size() > 0)
+ {
+ result = album.photoRecordArr.get(0).imageUrl;
+ }
+
+ }
+
+ if (result.equals("R.drawable.no_picture"))
+ {
+ ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database);
+
+ if (channelNameArr.size() > 0)
+ {
+ ChannelFullData channelFullData = MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database);
+
+ if (channelFullData.videoRecordArr.size() > 0)
+ {
+ result = channelFullData.videoRecordArr.get(0).previewImageUrl;
+ }
+ }
+ }
+
+ return result;
+ }
+
private boolean innerIsArticleAlreadyExist(String name, SQLiteDatabase database)
{
boolean result = false;
@@ -396,6 +477,56 @@ public class ArticleDataSource
}
+ private ArrayList innerGetArticlesByQuery(String query, SQLiteDatabase database)
+ {
+
+ ArrayList result = new ArrayList();
+
+ Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] {
+ BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TYPE, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_CONTENT, BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON, BashgidSqliteHelper.COLUMN_EXTERNAL_LINK,BashgidSqliteHelper.COLUMN_DATE_TIME },
+ BashgidSqliteHelper.COLUMN_TITLE + " LIKE ?", new String[] { "%" + query + "%" }, null, null, null, null);
+
+ if (cursor != null)
+ {
+ if (cursor.moveToFirst())
+ {
+
+ do
+ {
+
+ Date d = new Date();
+
+ try
+ {
+ d = ArticleManager.iso8601Format.parse(cursor.getString(7));
+ }
+ catch(ParseException e)
+ {
+ Log.e("aaa", "aaa!!!!!");
+ }
+
+ result.add(new ArticleRecordData(
+ cursor.getString(0),
+ cursor.getInt(1),
+ cursor.getString(2),
+ cursor.getString(3),
+ cursor.getDouble(4),
+ cursor.getDouble(5),
+ cursor.getString(6),
+ d
+ ));
+
+ }
+ while (cursor.moveToNext());
+ }
+
+ cursor.close();
+ }
+
+ return result;
+
+ }
+
public ArrayList innerGetAlbumNameArrInArticle(String name, SQLiteDatabase database)
{
ArrayList result = new ArrayList();
diff --git a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java
index 2240770..2567eaa 100644
--- a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java
+++ b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java
@@ -101,7 +101,7 @@ public class JournalDataSource
values.put(BashgidSqliteHelper.COLUMN_ARTICLE_NAME, articleName);
values.put(BashgidSqliteHelper.COLUMN_JOURNAL_NAME, journalName);
- if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database))
+ if (!InnerArticleJournalRelationAlreadyExist(articleName, journalName, database))
{
//Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, null, values);
@@ -346,7 +346,7 @@ public class JournalDataSource
}
- private boolean innerArticleJournalRelationAlreadyExist(String articleName, String journalName, SQLiteDatabase database)
+ public boolean InnerArticleJournalRelationAlreadyExist(String articleName, String journalName, SQLiteDatabase database)
{
boolean result = false;