Now search is working. Prepare to add localizations
This commit is contained in:
parent
8e393dc2bf
commit
82a58794a1
@ -36,7 +36,7 @@
|
||||
</EditText>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:id="@+id/searchButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
|
@ -11,22 +11,23 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_margin="6dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/transparent"
|
||||
android:src="@drawable/transparent_button"
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
android:contentDescription="@string/news_content_description"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/transparent_button"
|
||||
android:gravity="left|center_vertical"
|
||||
@ -36,7 +37,7 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dateTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -8,6 +8,15 @@
|
||||
android:paddingRight="20dp"
|
||||
tools:context="fishrungames.bashgid.SearchFragment" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -16,6 +16,7 @@ import fishrungames.bashgid.core.BookManager.BookRecord;
|
||||
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||
import fishrungames.bashgid.core.DatabaseDownloadTask;
|
||||
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
|
||||
@ -109,6 +110,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
public static final int DATABASE_GET_JOURNAL_LIST_STATE_UPDATE = 26;
|
||||
public static final int DATABASE_GET_JOURNAL_LIST_STATE_FINISHED = 27;
|
||||
|
||||
public static final int DATABASE_SEARCH_ARTICLE_STATE_UPDATE = 28;
|
||||
public static final int DATABASE_SEARCH_ARTICLE_STATE_FINISHED = 29;
|
||||
|
||||
|
||||
|
||||
|
||||
MainPageFragment mainPageFragment = null;
|
||||
@ -126,6 +131,8 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
VideoRecordFragment videoRecordFragment = null;
|
||||
OsmMapHolderFragment mapHolderFragment = null;
|
||||
|
||||
SearchFragment searchFragment = null;
|
||||
|
||||
CatalogFragment catalogFragment = null;
|
||||
|
||||
static MainActivity instance = null;
|
||||
@ -180,6 +187,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
|
||||
journalDataSource = new JournalDataSource(this, dbHelper);
|
||||
|
||||
|
||||
mHandler = new Handler(Looper.getMainLooper())
|
||||
{
|
||||
@Override
|
||||
@ -235,6 +243,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
break;
|
||||
|
||||
|
||||
case DATABASE_SEARCH_ARTICLE_STATE_UPDATE:
|
||||
case DATABASE_SEARCH_ARTICLE_STATE_FINISHED:
|
||||
UpdateOnArticleSearchPerformed((ArrayList<ArticleShortData>) inputMessage.obj);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
@ -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<ArticleShortData> 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)
|
||||
@ -665,21 +714,37 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
{
|
||||
ClearAllFragmentLinks();
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(), TAG_TO_SEARCHFRAGMENT).commit();
|
||||
searchFragment = new SearchFragment();
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, searchFragment, TAG_TO_MAINFRAGMENT).commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
public void OpenSearchScreen(boolean restorePreviousSearch)
|
||||
public void OpenSearchScreen(String journalName, String journalTitle)
|
||||
{
|
||||
ClearAllFragmentLinks();
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(restorePreviousSearch), TAG_TO_SEARCHFRAGMENT)
|
||||
searchFragment = new SearchFragment(journalName, journalTitle);
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, searchFragment, TAG_TO_MAINFRAGMENT).commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
/*
|
||||
public void OpenSearchScreen()
|
||||
{
|
||||
ClearAllFragmentLinks();
|
||||
|
||||
SearchFragment
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SearchFragment(), TAG_TO_SEARCHFRAGMENT)
|
||||
.commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
public void OpenLinkContentScreen(TextFileRecord contentRecord)
|
||||
{
|
||||
@ -881,6 +946,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -81,6 +81,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
|
||||
|
@ -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,47 +41,59 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
|
||||
|
||||
EditText searchEditText;
|
||||
|
||||
ArrayList<NewsRecord> searchResultArr = new ArrayList<NewsRecord>();
|
||||
ArrayList<ArticleShortData> searchResultArr = new ArrayList<ArticleShortData>();
|
||||
|
||||
volatile boolean searchIsPerformingNow = false;
|
||||
String journalName;
|
||||
String journalTitle;
|
||||
|
||||
//NewsSearchRunnable nextSearchRunnable = null;
|
||||
|
||||
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(){
|
||||
|
||||
@ -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<ArticleShortData> 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();
|
||||
if (databaseSearchArticleTask != null)
|
||||
{
|
||||
databaseSearchArticleTask.cancel(false);
|
||||
}
|
||||
|
||||
listAdapter.notifyDataSetChanged();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Bundle, Integer, Long>
|
||||
{
|
||||
|
||||
public Handler mHandler;
|
||||
|
||||
ArrayList<ArticleShortData> articleArr = new ArrayList<ArticleShortData>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -238,6 +238,79 @@ public class ArticleDataSource
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<ArticleShortData> SearchArticleByQuery(String query)
|
||||
{
|
||||
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = InnerSearchArticleByQuery(query, database);
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<ArticleShortData> SearchArticleByQueryAndJournal(String query, String journalName)
|
||||
{
|
||||
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
ArrayList<ArticleShortData> 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<ArticleShortData> InnerSearchArticleByQuery(String query, SQLiteDatabase database)
|
||||
{
|
||||
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
|
||||
|
||||
|
||||
ArrayList<ArticleRecordData> 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<String> 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<String> 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<String> 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<String> 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<ArticleRecordData> innerGetArticlesByQuery(String query, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
ArrayList<ArticleRecordData> result = new ArrayList<ArticleRecordData>();
|
||||
|
||||
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<String> innerGetAlbumNameArrInArticle(String name, SQLiteDatabase database)
|
||||
{
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user