Now search is working. Prepare to add localizations
This commit is contained in:
parent
8e393dc2bf
commit
82a58794a1
@ -36,7 +36,7 @@
|
|||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button"
|
android:id="@+id/searchButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
@ -11,22 +11,23 @@
|
|||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/imageButton"
|
android:id="@+id/imageButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="40dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_margin="6dp"
|
android:layout_margin="6dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
android:background="@drawable/transparent"
|
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
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button"
|
android:id="@+id/button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/transparent_button"
|
android:background="@drawable/transparent_button"
|
||||||
android:gravity="left|center_vertical"
|
android:gravity="left|center_vertical"
|
||||||
@ -36,7 +37,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/dateTextView"
|
android:id="@+id/dateTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -8,6 +8,15 @@
|
|||||||
android:paddingRight="20dp"
|
android:paddingRight="20dp"
|
||||||
tools:context="fishrungames.bashgid.SearchFragment" >
|
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
|
<EditText
|
||||||
android:id="@+id/editText"
|
android:id="@+id/editText"
|
||||||
android:layout_width="match_parent"
|
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.AlbumManager.AlbumFullData;
|
||||||
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
||||||
|
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||||
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||||
import fishrungames.bashgid.core.DatabaseDownloadTask;
|
import fishrungames.bashgid.core.DatabaseDownloadTask;
|
||||||
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
|
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_UPDATE = 26;
|
||||||
public static final int DATABASE_GET_JOURNAL_LIST_STATE_FINISHED = 27;
|
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;
|
MainPageFragment mainPageFragment = null;
|
||||||
@ -126,6 +131,8 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
VideoRecordFragment videoRecordFragment = null;
|
VideoRecordFragment videoRecordFragment = null;
|
||||||
OsmMapHolderFragment mapHolderFragment = null;
|
OsmMapHolderFragment mapHolderFragment = null;
|
||||||
|
|
||||||
|
SearchFragment searchFragment = null;
|
||||||
|
|
||||||
CatalogFragment catalogFragment = null;
|
CatalogFragment catalogFragment = null;
|
||||||
|
|
||||||
static MainActivity instance = null;
|
static MainActivity instance = null;
|
||||||
@ -179,6 +186,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
channelDataSource = new ChannelDataSource(this, dbHelper);
|
channelDataSource = new ChannelDataSource(this, dbHelper);
|
||||||
|
|
||||||
journalDataSource = new JournalDataSource(this, dbHelper);
|
journalDataSource = new JournalDataSource(this, dbHelper);
|
||||||
|
|
||||||
|
|
||||||
mHandler = new Handler(Looper.getMainLooper())
|
mHandler = new Handler(Looper.getMainLooper())
|
||||||
{
|
{
|
||||||
@ -235,7 +243,11 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case DATABASE_SEARCH_ARTICLE_STATE_UPDATE:
|
||||||
|
case DATABASE_SEARCH_ARTICLE_STATE_FINISHED:
|
||||||
|
UpdateOnArticleSearchPerformed((ArrayList<ArticleShortData>) inputMessage.obj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -399,6 +411,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
videoRecordFragment = null;
|
videoRecordFragment = null;
|
||||||
mapHolderFragment = null;
|
mapHolderFragment = null;
|
||||||
|
|
||||||
|
searchFragment = null;
|
||||||
catalogFragment = null;
|
catalogFragment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,8 +530,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
mapHolderFragment.SetJournal(journal);
|
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)
|
public void OnSelectEnglish(View view)
|
||||||
@ -664,22 +713,38 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
public void OpenSearchScreen()
|
public void OpenSearchScreen()
|
||||||
{
|
{
|
||||||
ClearAllFragmentLinks();
|
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();
|
mNavigationDrawerFragment.EnableDrawer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSearchScreen(boolean restorePreviousSearch)
|
/*
|
||||||
|
public void OpenSearchScreen()
|
||||||
{
|
{
|
||||||
ClearAllFragmentLinks();
|
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();
|
.commit();
|
||||||
|
|
||||||
mNavigationDrawerFragment.EnableDrawer();
|
mNavigationDrawerFragment.EnableDrawer();
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void OpenLinkContentScreen(TextFileRecord contentRecord)
|
public void OpenLinkContentScreen(TextFileRecord contentRecord)
|
||||||
{
|
{
|
||||||
@ -880,6 +945,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
mainPageFragment.RefreshJournal();
|
mainPageFragment.RefreshJournal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachFragment(Fragment fragment)
|
public void onAttachFragment(Fragment fragment)
|
||||||
@ -920,11 +986,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
|
|
||||||
if (id == R.id.action_search)
|
if (id == R.id.action_search)
|
||||||
{
|
{
|
||||||
if (getSupportFragmentManager().findFragmentByTag(TAG_TO_SEARCHFRAGMENT) == null
|
OnSearchPressed();
|
||||||
&& getSupportFragmentManager().findFragmentByTag(TAG_TO_WELCOMEFRAGMENT) == null)
|
|
||||||
{
|
|
||||||
OpenSearchScreen();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,7 +1069,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
|||||||
|
|
||||||
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT) != null)
|
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT) != null)
|
||||||
{
|
{
|
||||||
OpenSearchScreen(true);
|
OpenSearchScreen();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
return rootView;
|
||||||
}
|
}
|
||||||
@ -197,7 +210,6 @@ public class MainPageFragment extends Fragment {
|
|||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
|
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
if (convertView == null) { // if it's not recycled, initialize some attributes
|
if (convertView == null) { // if it's not recycled, initialize some attributes
|
||||||
|
@ -3,6 +3,10 @@ package fishrungames.bashgid;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
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;
|
||||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||||
import fishrungames.bashgid.core.db.NewsDataSource;
|
import fishrungames.bashgid.core.db.NewsDataSource;
|
||||||
@ -28,7 +32,7 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchFragment extends Fragment implements UpdateAndFinishCallbackInterface
|
public class SearchFragment extends Fragment
|
||||||
{
|
{
|
||||||
|
|
||||||
ListView listView;
|
ListView listView;
|
||||||
@ -37,48 +41,60 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
|
|||||||
|
|
||||||
EditText searchEditText;
|
EditText searchEditText;
|
||||||
|
|
||||||
ArrayList<NewsRecord> searchResultArr = new ArrayList<NewsRecord>();
|
ArrayList<ArticleShortData> searchResultArr = new ArrayList<ArticleShortData>();
|
||||||
|
|
||||||
volatile boolean searchIsPerformingNow = false;
|
|
||||||
|
|
||||||
//NewsSearchRunnable nextSearchRunnable = null;
|
String journalName;
|
||||||
|
String journalTitle;
|
||||||
|
|
||||||
boolean restorePreviousSearch = false;
|
DatabaseSearchArticleTask databaseSearchArticleTask = null;
|
||||||
|
|
||||||
RemoveCallbackInterface removeCallback = null;
|
|
||||||
Object removeCallbackSynchronizer = new Object();
|
|
||||||
|
|
||||||
public SearchFragment()
|
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
|
@SuppressLint("InflateParams") @Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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);
|
View rootView = inflater.inflate(R.layout.fragment_search_page, container, false);
|
||||||
|
|
||||||
listView = (ListView) rootView.findViewById(R.id.listView);
|
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);
|
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());
|
textView.setText("Search everywhere");
|
||||||
searchResultArr = NewsManager.getInstance().getSearchResultNews();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textView.setText("Search in: " + journalTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchEditText = (EditText) header.findViewById(R.id.editText);
|
||||||
|
|
||||||
searchEditText.addTextChangedListener(new TextWatcher(){
|
searchEditText.addTextChangedListener(new TextWatcher(){
|
||||||
|
|
||||||
public void afterTextChanged(Editable s) {
|
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){}
|
public void onTextChanged(CharSequence s, int start, int before, int count){}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
listView.addHeaderView(header);
|
listView.addHeaderView(header);
|
||||||
|
|
||||||
|
listAdapter = new ListAdapter(getActivity());
|
||||||
|
|
||||||
|
listView.setAdapter(listAdapter);
|
||||||
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView()
|
public void SetSearchResult(ArrayList<ArticleShortData> articleArr)
|
||||||
{
|
{
|
||||||
synchronized (removeCallbackSynchronizer)
|
searchResultArr = articleArr;
|
||||||
{
|
listAdapter.notifyDataSetChanged();
|
||||||
if (removeCallback != null)
|
|
||||||
{
|
|
||||||
removeCallback.RemoveCallback();
|
|
||||||
removeCallback = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onDestroyView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ListAdapter extends BaseAdapter {
|
public class ListAdapter extends BaseAdapter {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@ -154,76 +167,78 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
|
|||||||
|
|
||||||
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
|
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);
|
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;
|
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)
|
public void CallUpdateNews(String text)
|
||||||
{
|
{
|
||||||
Bundle query = new Bundle();
|
if (text.length() >= 3)
|
||||||
|
|
||||||
query.putString("query", text);
|
|
||||||
|
|
||||||
removeCallback = UniversalActionWithCallback.PerformAction(new NewsSearchRunnable(), query, this, "NewsSearchRunnable");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RefreshSearchListRunnable implements Runnable
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
searchResultArr = NewsManager.getInstance().getSearchResultNews();
|
if (databaseSearchArticleTask != null)
|
||||||
|
{
|
||||||
listAdapter.notifyDataSetChanged();
|
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
|
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
|
@Override
|
||||||
public void onClick(View v)
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -237,6 +237,79 @@ public class ArticleDataSource
|
|||||||
|
|
||||||
return result;
|
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)
|
public ArticleShortData InnerGetArticleShortData(String name, SQLiteDatabase database)
|
||||||
@ -251,35 +324,8 @@ public class ArticleDataSource
|
|||||||
|
|
||||||
result = new ArticleShortData(recordData);
|
result = new ArticleShortData(recordData);
|
||||||
|
|
||||||
ArrayList<String> albumNameArr = innerGetAlbumNameArrInArticle(name, database);
|
|
||||||
|
|
||||||
result.previewImageUrl = "R.drawable.no_picture";
|
result.previewImageUrl = getPreviewImageUrlForArticle(name, database);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,6 +333,41 @@ public class ArticleDataSource
|
|||||||
return result;
|
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)
|
private boolean innerIsArticleAlreadyExist(String name, SQLiteDatabase database)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
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)
|
public ArrayList<String> innerGetAlbumNameArrInArticle(String name, SQLiteDatabase database)
|
||||||
{
|
{
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
|
@ -101,7 +101,7 @@ public class JournalDataSource
|
|||||||
values.put(BashgidSqliteHelper.COLUMN_ARTICLE_NAME, articleName);
|
values.put(BashgidSqliteHelper.COLUMN_ARTICLE_NAME, articleName);
|
||||||
values.put(BashgidSqliteHelper.COLUMN_JOURNAL_NAME, journalName);
|
values.put(BashgidSqliteHelper.COLUMN_JOURNAL_NAME, journalName);
|
||||||
|
|
||||||
if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database))
|
if (!InnerArticleJournalRelationAlreadyExist(articleName, journalName, database))
|
||||||
{
|
{
|
||||||
//Log.e("a", "aaa1");
|
//Log.e("a", "aaa1");
|
||||||
database.insert(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, null, values);
|
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;
|
boolean result = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user