diff --git a/android/res/layout/article_photo_element.xml b/android/res/layout/article_photo_element.xml index 392d5f3..955c158 100644 --- a/android/res/layout/article_photo_element.xml +++ b/android/res/layout/article_photo_element.xml @@ -8,11 +8,14 @@ android:orientation="vertical" android:showDividers="middle" > - + android:layout_gravity="center_horizontal" + android:adjustViewBounds="true" + android:cropToPadding="false" + android:scaleType="centerCrop" /> - - + + + + diff --git a/android/res/layout/journal_page_header.xml b/android/res/layout/journal_page_header.xml new file mode 100644 index 0000000..396de02 --- /dev/null +++ b/android/res/layout/journal_page_header.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index 40d076d..3abdb76 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -23,6 +23,8 @@ Новости + Загрузить больше + Картинка к новости @@ -51,5 +53,15 @@ Читать Стоимость: Руб. + + Показать на карте + Карта загружается... + Карта загружена + + Новости загружаются... + + Открыть + Отмена + diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml index d5fc94b..acf0ba1 100644 --- a/android/res/values-zh-rCN/strings.xml +++ b/android/res/values-zh-rCN/strings.xml @@ -20,6 +20,7 @@ 头条新闻 + Load more 新闻内容描述 @@ -41,5 +42,18 @@ 去现场 + Buy + Read + Price: + RUB + + Show on map + Map is loading... + Map is loaded + News are loading... + + Open + Cancel + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 16f51f1..4887391 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -54,6 +54,15 @@ Read Price: RUB + + Show on map + Map is loading... + Map is loaded + + News are loading... + + Open + Cancel diff --git a/android/src/fishrungames/bashgid/CatalogFragment.java b/android/src/fishrungames/bashgid/CatalogFragment.java index 1407c39..138d433 100644 --- a/android/src/fishrungames/bashgid/CatalogFragment.java +++ b/android/src/fishrungames/bashgid/CatalogFragment.java @@ -6,6 +6,7 @@ import it.sephiroth.android.library.widget.HListView; import fishrungames.bashgid.AlbumListFragment.DatabaseGetAlbumListTask; import fishrungames.bashgid.MainPageFragment.ListAdapter; import fishrungames.bashgid.core.AlbumManager.AlbumShortData; +import fishrungames.bashgid.core.DatabaseGetJournalListTask; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import android.annotation.SuppressLint; import android.content.Context; @@ -33,6 +34,8 @@ public class CatalogFragment extends Fragment ArrayList journalList; + DatabaseGetJournalListTask databaseGetJournalListTask = null; + public CatalogFragment() { RestoreJournalList(); @@ -62,19 +65,34 @@ public class CatalogFragment extends Fragment return rootView; } + @Override + public void onDestroyView () + { + + if (databaseGetJournalListTask != null) + { + databaseGetJournalListTask.cancel(false); + databaseGetJournalListTask = null; + } + + super.onDestroyView(); + } + public void RestoreJournalList() { journalList = new ArrayList(); - DatabaseGetJournalListTask task = new DatabaseGetJournalListTask(); + databaseGetJournalListTask = new DatabaseGetJournalListTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetJournalListTask.mHandler = MainActivity.getInstance().mHandler; - task.execute(); + databaseGetJournalListTask.execute(); } public void SetJournalList(ArrayList journalList) { + databaseGetJournalListTask = null; + progressBar.setVisibility(View.GONE); this.journalList = journalList; @@ -82,36 +100,6 @@ public class CatalogFragment extends Fragment listAdapter.notifyDataSetChanged(); } - public static class DatabaseGetJournalListTask extends AsyncTask - { - - ArrayList journalList; - - public Handler mHandler; - - protected Long doInBackground(String... queryArr) - { - - journalList = MainActivity.getInstance().journalDataSource.GetAllJournalList(); - - return (long) 0; - } - - protected void onProgressUpdate(Integer... progress) - { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_UPDATE, journalList); - - completeMessage.sendToTarget(); - - } - - protected void onPostExecute(Long result) - { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); - - completeMessage.sendToTarget(); - } - } public class ListAdapter extends BaseAdapter { diff --git a/android/src/fishrungames/bashgid/JournalFragment.java b/android/src/fishrungames/bashgid/JournalFragment.java index c67016f..6d08dc3 100644 --- a/android/src/fishrungames/bashgid/JournalFragment.java +++ b/android/src/fishrungames/bashgid/JournalFragment.java @@ -3,10 +3,7 @@ package fishrungames.bashgid; import android.annotation.SuppressLint; import android.content.Context; -import android.os.AsyncTask; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -21,9 +18,7 @@ import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; -import fishrungames.bashgid.core.AlbumManager; -import fishrungames.bashgid.core.DatabaseGetAlbumTask; -import fishrungames.bashgid.core.AlbumManager.AlbumFullData; + import fishrungames.bashgid.core.DatabaseGetJournalTask; import fishrungames.bashgid.core.JournalManager; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; @@ -38,6 +33,8 @@ public class JournalFragment extends Fragment ListAdapter listAdapter; ProgressBar progressBar; + DatabaseGetJournalTask databaseGetJournalTask = null; + public JournalFragment() { journal = null; @@ -77,10 +74,15 @@ public class JournalFragment extends Fragment progressBar.setVisibility(View.VISIBLE); + + ListView listView = (ListView) rootView.findViewById(R.id.listView); + + View header = inflater.inflate(R.layout.journal_page_header, null); + + listView.addHeaderView(header); listAdapter = new ListAdapter(getActivity()); - ListView listView = (ListView) rootView.findViewById(R.id.listView); listView.setAdapter(listAdapter); @@ -89,39 +91,66 @@ public class JournalFragment extends Fragment @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (journalName.equals("news")) + if (position == 0) { - MainActivity.getInstance().OpenNewsRecordScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT); + MainActivity.getInstance().OpenMapScreen(journalName); } else { - MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT); + if (journalName.equals("news")) + { + MainActivity.getInstance().OpenNewsRecordScreen(journal.articleArr.get(position-1).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT); + } + else + { + MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position-1).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT); + } } } - }); return rootView; } + @Override + public void onDestroyView () + { + + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + + super.onDestroyView(); + } + void RestoreJournal() { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + journal = JournalManager.CreateEmptyJournal(); - DatabaseGetJournalTask task = new DatabaseGetJournalTask(); + databaseGetJournalTask = new DatabaseGetJournalTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; Bundle bundle = new Bundle(); bundle.putString("journalName", journalName); - task.execute(bundle); + databaseGetJournalTask.execute(bundle); } public void SetJournal(JournalSemiFullData journal) { + databaseGetJournalTask = null; + progressBar.setVisibility(View.GONE); diff --git a/android/src/fishrungames/bashgid/MainActivity.java b/android/src/fishrungames/bashgid/MainActivity.java index 31d26d1..2e0d6bb 100644 --- a/android/src/fishrungames/bashgid/MainActivity.java +++ b/android/src/fishrungames/bashgid/MainActivity.java @@ -72,7 +72,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public static final String TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT = "TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT"; public static final String TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT = "TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT"; - @@ -263,7 +262,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF }; - + /* albumDataSource.CreateNewAlbum(new AlbumRecordData("TEST", "Vk Photos", "Wow")); @@ -343,7 +342,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF translationDataSource.CreateNewTranslation(new TranslationRecordData("Wow 2 photos", "Wow 2 photos", "Вау 2 фото", "哇2张照片")); translationDataSource.CreateNewTranslation(new TranslationRecordData("Rickroll", "Rickroll", "Рикролл", "笑话")); - + */ DownloadDatabase(); } @@ -450,12 +449,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF { if (mainPageFragment != null) { - mainPageFragment.RefreshJournal(); + mainPageFragment.RefreshAdapter(); } if (newsListFragment != null) { - newsListFragment.RefreshJournal(); + newsListFragment.RefreshAdapter(); } } @@ -570,9 +569,16 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF { catalogFragment.SetJournalList(journalList); } + + if (mainPageFragment != null) + { + mainPageFragment.SetJournalList(journalList); + } + } + public void UpdateOnArticleSearchPerformed(ArrayList articleArr) { diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java index b5b99d0..f744795 100644 --- a/android/src/fishrungames/bashgid/MainPageFragment.java +++ b/android/src/fishrungames/bashgid/MainPageFragment.java @@ -4,14 +4,12 @@ import java.util.ArrayList; import fishrungames.networkutils.ImageManager; - -import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; -import fishrungames.bashgid.core.ArticleManager.ArticleShortData; +import fishrungames.bashgid.core.DatabaseGetJournalListTask; import fishrungames.bashgid.core.DatabaseGetJournalTask; import fishrungames.bashgid.core.JournalManager; -import fishrungames.bashgid.core.NewsManager; + import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; -import fishrungames.bashgid.core.NewsManager.NewsRecord; + import android.annotation.SuppressLint; import android.content.Context; @@ -33,10 +31,7 @@ import it.sephiroth.android.library.widget.HListView; public class MainPageFragment extends Fragment { - String [] teaserHeaderArray = { "Разное"}; - - int[] varietyContentIdArray = { 1, 2, 3, 4 }; - + ArrayList journalList = new ArrayList(); ListView listView; ListAdapter listAdapter; @@ -44,17 +39,28 @@ public class MainPageFragment extends Fragment { ProgressBar progressBar; JournalSemiFullData newsJournal; + + DatabaseGetJournalTask databaseGetJournalTask = null; + DatabaseGetJournalListTask databaseGetJournalListTask = null; + + public MainPageFragment() + { + } @SuppressLint("InflateParams") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + journalList.clear(); + + RestoreJournalList(); + View rootView = inflater.inflate(R.layout.fragment_main_page, container, false); listView = (ListView) rootView.findViewById(R.id.listView); listAdapter = new ListAdapter(getActivity()); - header = inflater.inflate(R.layout.main_page_header, null); RestoreJournal(); @@ -96,6 +102,24 @@ public class MainPageFragment extends Fragment { return rootView; } + + @Override + public void onDestroyView () + { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + + if (databaseGetJournalListTask != null) + { + databaseGetJournalListTask.cancel(false); + databaseGetJournalListTask = null; + } + + super.onDestroyView(); + } void RestoreJournal() @@ -107,9 +131,14 @@ public class MainPageFragment extends Fragment { void RefreshJournal() { - DatabaseGetJournalTask task = new DatabaseGetJournalTask(); + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + } + + databaseGetJournalTask = new DatabaseGetJournalTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; Bundle bundle = new Bundle(); @@ -117,11 +146,13 @@ public class MainPageFragment extends Fragment { bundle.putInt("count", 3); - task.execute(bundle); + databaseGetJournalTask.execute(bundle); } public void SetJournal(JournalSemiFullData journal) { + databaseGetJournalTask = null; + //Xperimental if (journal != null) { @@ -191,6 +222,38 @@ public class MainPageFragment extends Fragment { } + public void RefreshAdapter() + { + listAdapter.notifyDataSetChanged(); + } + + public void RestoreJournalList() + { + journalList = new ArrayList(); + + if (databaseGetJournalListTask != null) + { + databaseGetJournalListTask.cancel(false); + } + + databaseGetJournalListTask = new DatabaseGetJournalListTask(); + + databaseGetJournalListTask.mHandler = MainActivity.getInstance().mHandler; + + databaseGetJournalListTask.execute("featured"); + } + + public void SetJournalList(ArrayList journalList) + { + databaseGetJournalListTask = null; + + progressBar.setVisibility(View.GONE); + + this.journalList = journalList; + + listAdapter.notifyDataSetChanged(); + } + public class ListAdapter extends BaseAdapter { private Context mContext; @@ -200,7 +263,7 @@ public class MainPageFragment extends Fragment { } public int getCount() { - return teaserHeaderArray.length; + return journalList.size(); } public Object getItem(int position) { @@ -213,7 +276,7 @@ public class MainPageFragment extends Fragment { // create a new ImageView for each item referenced by the Adapter @SuppressLint("InflateParams") - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(final int position, View convertView, ViewGroup parent) { View view; @@ -227,24 +290,40 @@ public class MainPageFragment extends Fragment { } TextView textView = (TextView) view.findViewById(R.id.dateTextView); - + TextView descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView); + Button button = (Button) view.findViewById(R.id.button); HListView hListView = (HListView) view.findViewById(R.id.hListView); - hListView.setAdapter(new MainPageHListViewAdapters.SimpleElementAdapter(getActivity())); + hListView.setAdapter(new MainPageHListViewAdapters.JournalElementAdapter(getActivity(), journalList.get(position))); - textView.setText(teaserHeaderArray[position]); + textView.setText(journalList.get(position).title); + + descriptionTextView.setText(journalList.get(position).description); + button.setText(R.string.see_all); + button.setOnClickListener(new OnClickListener() + { + @Override + public void onClick(View v) + { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + } + MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_TO_MAINFRAGMENT); + } + }); return view; } } - public static class NewsButtonOnClickListener implements OnClickListener + public class NewsButtonOnClickListener implements OnClickListener { String articleName; @@ -257,6 +336,7 @@ public class MainPageFragment extends Fragment { @Override public void onClick(View v) { + databaseGetJournalTask.cancel(false); MainActivity.getInstance().OpenNewsRecordScreen(articleName, MainActivity.TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT); } diff --git a/android/src/fishrungames/bashgid/NewsListFragment.java b/android/src/fishrungames/bashgid/NewsListFragment.java index 5a28139..6569b4a 100644 --- a/android/src/fishrungames/bashgid/NewsListFragment.java +++ b/android/src/fishrungames/bashgid/NewsListFragment.java @@ -46,6 +46,8 @@ public class NewsListFragment extends Fragment TextView footerTextView; + DatabaseGetJournalTask databaseGetJournalTask = null; + @SuppressLint("InflateParams") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -83,7 +85,7 @@ public class NewsListFragment extends Fragment //Add position + 1, because first element of list is always title if (position == journal.articleArr.size() + 1) { - footerTextView.setText("Loading..."); + footerTextView.setText(R.string.news_are_loading); LoadMoreNews(); } else if (position > 0) @@ -99,6 +101,24 @@ public class NewsListFragment extends Fragment return rootView; } + @Override + public void onDestroyView () + { + + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + + super.onDestroyView(); + } + + public void RefreshAdapter() + { + listAdapter.notifyDataSetChanged(); + } + void RestoreJournal() { journal = JournalManager.CreateEmptyJournal(); @@ -108,9 +128,9 @@ public class NewsListFragment extends Fragment void RefreshJournal() { - DatabaseGetJournalTask task = new DatabaseGetJournalTask(); + databaseGetJournalTask = new DatabaseGetJournalTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; Bundle bundle = new Bundle(); @@ -118,14 +138,19 @@ public class NewsListFragment extends Fragment bundle.putInt("count", 20); - task.execute(bundle); + databaseGetJournalTask.execute(bundle); } void LoadMoreNews() { - DatabaseGetJournalTask task = new DatabaseGetJournalTask(); + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + } + + databaseGetJournalTask = new DatabaseGetJournalTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; Bundle bundle = new Bundle(); @@ -135,7 +160,7 @@ public class NewsListFragment extends Fragment bundle.putInt("count", 10); - task.execute(bundle); + databaseGetJournalTask.execute(bundle); } public void SetJournal(JournalSemiFullData journal) @@ -155,9 +180,7 @@ public class NewsListFragment extends Fragment //this.journal.previewImageArr.addAll(journal.previewImageArr); - - - footerTextView.setText("Load more"); + footerTextView.setText(R.string.news_load_more); listAdapter.notifyDataSetChanged(); diff --git a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java index c4d3181..f03f1ae 100644 --- a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java +++ b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java @@ -34,12 +34,10 @@ import fishrungames.bashgid.core.ArticleManager.ArticleFullData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.DatabaseGetArticleTask; import fishrungames.bashgid.core.DatabaseGetJournalTask; -import fishrungames.bashgid.core.JournalManager; import fishrungames.bashgid.core.LocationHolder; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import fishrungames.networkutils.ImageManager; - public class OsmMapHolderFragment extends Fragment { @@ -101,15 +99,17 @@ public class OsmMapHolderFragment extends Fragment dialog.setView(image); + + - dialog.setPositiveButton("Open", new DialogInterface.OnClickListener() { + dialog.setPositiveButton(R.string.dialog_open, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MainActivity.getInstance().SetLastMapFilterName(journalName); MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), MainActivity.TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT); } }); - dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + dialog.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } @@ -234,11 +234,11 @@ public class OsmMapHolderFragment extends Fragment if ((filterType == 0 && journal == null) || (filterType == 1 && article == null)) { - textView.setText("Loading map..."); + textView.setText(R.string.map_is_loading); } else { - textView.setText("Map is loaded"); + textView.setText(R.string.map_is_loaded); } mapView = (MapView) rootView.findViewById(R.id.mapview); @@ -308,7 +308,7 @@ public class OsmMapHolderFragment extends Fragment { filterType = 0; - textView.setText("Map is loaded"); + textView.setText(R.string.map_is_loaded); this.journal = journal; @@ -320,7 +320,7 @@ public class OsmMapHolderFragment extends Fragment { filterType = 1; - textView.setText("Map is loaded"); + textView.setText(R.string.map_is_loaded); this.article = article; diff --git a/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java b/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java index 237f818..8683209 100644 --- a/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java +++ b/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java @@ -68,10 +68,12 @@ public class PhotoFragmentAdapter extends PagerAdapter { return viewLayout; } - + @Override - public void destroyItem(ViewGroup container, int position, Object object) { - ((ViewPager) container).removeView((LinearLayout) object); - + public void destroyItem(View collection, int position, Object o) { + View view = (View)o; + ((ViewPager) collection).removeView(view); + view = null; } + } \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java index 8af03f6..47d9a4d 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java @@ -32,6 +32,7 @@ import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ChannelManager.ChannelRecordData; import fishrungames.bashgid.core.JournalManager.JournalRecordData; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; +import fishrungames.bashgid.core.TranslationManager.TranslationRecordData; import fishrungames.bashgid.core.VideoManager.VideoRecordData; public class DatabaseDownloadTask extends AsyncTask @@ -41,6 +42,7 @@ public class DatabaseDownloadTask extends AsyncTask protected Long doInBackground(Bundle... queryArr) { + /* ParseJsonPhoto(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=photo/json")); ParseJsonAlbum(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=album/json")); @@ -55,6 +57,23 @@ public class DatabaseDownloadTask extends AsyncTask ParseJsonAlbumArticleRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=albumArticleRelation/json")); ParseJsonChannelArticleRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=channelArticleRelation/json")); ParseJsonArticleJournalRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=articleJournalRelation/json")); + ParseJsonTranslation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=translation/json")); + */ + + ParseJsonPhoto(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=photo/json")); + ParseJsonAlbum(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=album/json")); + ParseJsonPhotoAlbumRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=photoAlbumRelation/json")); + + ParseJsonVideo(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=video/json")); + ParseJsonChannel(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=channel/json")); + ParseJsonVideoChannelRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=videoChannelRelation/json")); + + ParseJsonArticle(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=article/json")); + ParseJsonJournal(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=journal/json")); + ParseJsonAlbumArticleRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=albumArticleRelation/json")); + ParseJsonChannelArticleRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=channelArticleRelation/json")); + ParseJsonArticleJournalRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=articleJournalRelation/json")); + ParseJsonTranslation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=translation/json")); @@ -440,5 +459,28 @@ public class DatabaseDownloadTask extends AsyncTask Log.e("JSONException", "Error: " + e.toString()); } } + + private void ParseJsonTranslation(String jsonCode) + { + try { + JSONArray jArray = new JSONArray(jsonCode); + + for(int i=0; i < jArray.length(); i++) { + + JSONObject jObject = jArray.getJSONObject(i); + + String name = jObject.getString("name"); + String textEn = jObject.getString("textEn"); + String textRu = jObject.getString("textRu"); + String textZh = jObject.getString("textZh"); + + MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(name, textEn, textRu, textZh)); + + } // End Loop + + } catch (JSONException e) { + Log.e("JSONException", "Error: " + e.toString()); + } + } } \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java new file mode 100644 index 0000000..ad73493 --- /dev/null +++ b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java @@ -0,0 +1,51 @@ +package fishrungames.bashgid.core; + +import java.util.ArrayList; + +import android.os.AsyncTask; +import android.os.Handler; +import android.os.Message; +import fishrungames.bashgid.MainActivity; +import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; + +public class DatabaseGetJournalListTask extends AsyncTask +{ + + ArrayList journalList; + + public Handler mHandler; + + protected Long doInBackground(String... queryArr) + { + + String superJournal = ""; + + if (queryArr.length > 0) + { + superJournal = queryArr[0]; + journalList = MainActivity.getInstance().journalDataSource.GetJournalList(superJournal, 3); //Xperimental -- need to pass exactly how many articles + } + else + { + journalList = MainActivity.getInstance().journalDataSource.GetAllJournalList(3); //Xperimental -- need to pass exactly how many articles + } + + + return (long) 0; + } + + protected void onProgressUpdate(Integer... progress) + { + Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_UPDATE, journalList); + + completeMessage.sendToTarget(); + + } + + protected void onPostExecute(Long result) + { + Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); + + completeMessage.sendToTarget(); + } +} diff --git a/android/src/fishrungames/bashgid/core/TranslationManager.java b/android/src/fishrungames/bashgid/core/TranslationManager.java new file mode 100644 index 0000000..8c649d2 --- /dev/null +++ b/android/src/fishrungames/bashgid/core/TranslationManager.java @@ -0,0 +1,32 @@ +package fishrungames.bashgid.core; + + +public class TranslationManager +{ + + public static class TranslationRecordData + { + public String name; + public String textEn; + public String textRu; + public String textZh; + + + public TranslationRecordData(String name, String textEn, String textRu, String textZh) + { + this.name = name; + this.textEn = textEn; + this.textRu = textRu; + this.textZh = textZh; + } + + public TranslationRecordData(TranslationRecordData copyFrom) + { + this.name = copyFrom.name; + this.textEn = copyFrom.textEn; + this.textRu = copyFrom.textRu; + this.textZh = copyFrom.textZh; + } + } + +} diff --git a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java index 226d5ed..1f80d8c 100644 --- a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java @@ -207,7 +207,6 @@ public class AlbumDataSource { try { - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null); @@ -235,6 +234,7 @@ public class AlbumDataSource } cursor.close(); + cursor = null; } } finally @@ -262,6 +262,7 @@ public class AlbumDataSource } cursor.close(); + cursor = null; } @@ -286,6 +287,7 @@ public class AlbumDataSource } cursor.close(); + cursor = null; } return result; @@ -311,6 +313,7 @@ public class AlbumDataSource } cursor.close(); + cursor = null; } return result; @@ -333,6 +336,7 @@ public class AlbumDataSource } cursor.close(); + cursor = null; } return result; diff --git a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java index b79b798..563713e 100644 --- a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java @@ -392,6 +392,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; @@ -413,8 +414,8 @@ public class ArticleDataSource { result = true; } - cursor.close(); + cursor = null; } return result; @@ -436,6 +437,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; @@ -480,6 +482,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; @@ -530,6 +533,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; @@ -556,6 +560,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; @@ -582,6 +587,7 @@ public class ArticleDataSource } cursor.close(); + cursor = null; } return result; diff --git a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java index af050d7..2ddd965 100644 --- a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java @@ -170,6 +170,7 @@ public class ChannelDataSource } cursor.close(); + cursor = null; } return result; @@ -192,6 +193,7 @@ public class ChannelDataSource } cursor.close(); + cursor = null; } return result; @@ -216,6 +218,7 @@ public class ChannelDataSource } cursor.close(); + cursor = null; } return result; @@ -239,6 +242,7 @@ public class ChannelDataSource } cursor.close(); + cursor = null; } return result; diff --git a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java index 96964c0..f643b95 100644 --- a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java @@ -190,8 +190,83 @@ public class JournalDataSource return result; } - public ArrayList GetAllJournalList() + public ArrayList GetAllJournalList(int count) { + ArrayList result = new ArrayList(); + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + try + { + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME, + BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null); + + if (cursor != null) + { + if (cursor.moveToFirst()) + { + + do + + { + + String name = cursor.getString(0); + if (!name.equals("news") && !name.equals("map")) + { + + JournalSemiFullData journal = new JournalSemiFullData(new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2))); + + ArrayList articleArr; + + if (count > 0) + { + articleArr = innerGetArticleArrInJournal(cursor.getString(0), database, count); + } + else + { + articleArr = innerGetArticleArrInJournal(cursor.getString(0), database); + } + for (String article : articleArr) + { + journal.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database)); + + } + + journal.title = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.title, database); + journal.description = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.description, database); + + result.add(journal); + + } + + + } while (cursor.moveToNext()); + + + + } + + cursor.close(); + cursor = null; + } + } + finally + { + dbHelper.close(); + } + } + + return result; + } + + + public ArrayList GetJournalList(String superJournalName, int count) + { + //Xperimental - need to create a real superjournal + + ArrayList result = new ArrayList(); SQLiteDatabase database = dbHelper.getWritableDatabase(); @@ -213,12 +288,22 @@ public class JournalDataSource { String name = cursor.getString(0); - if (!name.equals("news") && !name.equals("map")) + if (name.equals("Universities") || name.equals("hotels")) //Xperimental { JournalSemiFullData journal = new JournalSemiFullData(new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2))); - ArrayList articleArr = innerGetArticleArrInJournal(cursor.getString(0), database); + + ArrayList articleArr; + + if (count > 0) + { + articleArr = innerGetArticleArrInJournal(cursor.getString(0), database, count); + } + else + { + articleArr = innerGetArticleArrInJournal(cursor.getString(0), database); + } for (String article : articleArr) { @@ -236,9 +321,10 @@ public class JournalDataSource } while (cursor.moveToNext()); - - } + + cursor.close(); + cursor = null; } } finally @@ -329,6 +415,7 @@ public class JournalDataSource } cursor.close(); + cursor = null; } return result; @@ -351,13 +438,13 @@ public class JournalDataSource } cursor.close(); + cursor = null; } return result; } - private ArrayList innerGetArticleArrInJournal(String name, SQLiteDatabase database) { ArrayList result = new ArrayList(); @@ -377,6 +464,35 @@ public class JournalDataSource } cursor.close(); + cursor = null; + } + + return result; + + } + + private ArrayList innerGetArticleArrInJournal(String name, SQLiteDatabase database, int count) + { + ArrayList result = new ArrayList(); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ARTICLE_NAME }, + BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?", new String[] { name }, null, null, null, null); + + if (cursor != null) + { + if (cursor.moveToFirst()) + { + int i = 0; + do + { + result.add(cursor.getString(0)); + i++; + } while (cursor.moveToNext() && i < count); + + } + + cursor.close(); + cursor = null; } return result; @@ -400,6 +516,7 @@ public class JournalDataSource result = new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2)); } cursor.close(); + cursor = null; } return result; diff --git a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java index bbb8069..d7d5571 100644 --- a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java @@ -103,6 +103,7 @@ public class PhotoDataSource } cursor.close(); + cursor = null; } return result; @@ -124,6 +125,7 @@ public class PhotoDataSource } cursor.close(); + cursor = null; } return result; diff --git a/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java b/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java new file mode 100644 index 0000000..15c0755 --- /dev/null +++ b/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java @@ -0,0 +1,395 @@ +package fishrungames.bashgid.core.db; + +import java.util.ArrayList; +import java.util.Locale; + +import fishrungames.bashgid.MainActivity; +import fishrungames.bashgid.core.AlbumManager; +import fishrungames.bashgid.core.AlbumManager.AlbumFullData; +import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; +import fishrungames.bashgid.core.AlbumManager.AlbumShortData; +import fishrungames.bashgid.core.TranslationManager.TranslationRecordData; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; + +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +public class TranslationDataSource +{ + + private BashgidSqliteHelper dbHelper = null; + + public TranslationDataSource(Context context, BashgidSqliteHelper dbHelper) + { + this.dbHelper = dbHelper; + + } + + public void CreateNewTranslation(TranslationRecordData recordData) + { + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + + try + { + ContentValues values = new ContentValues(); + + values.put(BashgidSqliteHelper.COLUMN_NAME, recordData.name); + values.put(BashgidSqliteHelper.COLUMN_TEXT_EN, recordData.textEn); + values.put(BashgidSqliteHelper.COLUMN_TEXT_RU, recordData.textRu); + values.put(BashgidSqliteHelper.COLUMN_TEXT_ZH, recordData.textZh); + + if (!innerIsTranslationAlreadyExist(recordData.name, database)) + { + database.insert(BashgidSqliteHelper.TABLE_TRANSLATION, null, values); + } else + { + database.update(BashgidSqliteHelper.TABLE_TRANSLATION, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null); + } + + } finally + { + dbHelper.close(); + } + } + + } + + public String TryTranslateText(String name, SQLiteDatabase database) + { + if (innerIsTranslationAlreadyExist(name, database)) + { + TranslationRecordData record = innerGetTranslationByName(name, database); + + if (Locale.getDefault().equals(new Locale("ru"))) + { + return record.textRu; + } + else if (Locale.getDefault() == Locale.CHINA) + { + return record.textZh; + } + + return record.textEn; + } + else + { + return name; + } + } +/* + public boolean IsTranslationAlreadyExist(String name) + { + boolean result = false; + + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + + try + { + result = innerIsAlbumAlreadyExist(name, database); + + } finally + { + dbHelper.close(); + } + } + + return result; + + }*/ +/* + public void AddPhotoToAlbum(String imageUrl, String albumName) + { + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + + try + { + ContentValues values = new ContentValues(); + + values.put(BashgidSqliteHelper.COLUMN_IMAGE_URL, imageUrl); + values.put(BashgidSqliteHelper.COLUMN_NAME, albumName); + + if (!innerPhotoAlbumRelationAlreadyExist(imageUrl, albumName, database)) + { + Log.e("a", "aaa1"); + database.insert(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, null, values); + Log.e("a", "aaa2"); + } + Log.e("a", "aaa3"); + + } finally + { + dbHelper.close(); + } + } + } +*/ + + public TranslationRecordData GetTranslationRecordData(String name) + { + TranslationRecordData result = null; + + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + try + { + + result = innerGetTranslationByName(name, database); + + + } finally + { + dbHelper.close(); + } + } + + return result; + } + + /* + public AlbumFullData GetAlbumFullData(String name) + { + AlbumFullData result = null; + + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + try + { + + result = InnerGetAlbumFullData(name, database); + + } finally + { + dbHelper.close(); + } + } + + return result; + } + + public AlbumFullData InnerGetAlbumFullData(String name, SQLiteDatabase database) + { + + AlbumFullData result = null; + + AlbumRecordData recordData = innerGetAlbumByName(name, database); + + if (recordData != null) + { + + result = new AlbumFullData(recordData); + + ArrayList imageUrlArr = innerGetImageUrlArrInAlbum(name, database); + + for (String imageUrl : imageUrlArr) + { + result.photoRecordArr.add(MainActivity.getInstance().photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database)); + } + + } + + return result; + } + + public AlbumShortData GetAlbumShortData(String name) + { + AlbumShortData result = null; + + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + try + { + + AlbumRecordData recordData = innerGetAlbumByName(name, database); + + if (recordData != null) + { + + result = new AlbumShortData(recordData); + + ArrayList imageUrlArr = innerGetImageUrlArrInAlbum(name, database); + + result.photoCount = imageUrlArr.size(); + + if (imageUrlArr.size() > 0) + { + result.firstImageUrl = imageUrlArr.get(0); + } + } + + } finally + { + dbHelper.close(); + } + } + + return result; + } + + public ArrayList GetAllAlbumShortData() + { + + ArrayList result = new ArrayList(); + + SQLiteDatabase database = dbHelper.getWritableDatabase(); + + if (database != null) + { + try + { + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME, + BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null); + + if (cursor != null) + { + if (cursor.moveToFirst()) + { + do + { + + AlbumShortData shortData = new AlbumShortData(new AlbumRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2))); + + ArrayList imageUrlArr = innerGetImageUrlArrInAlbum(shortData.name, database); + + shortData.photoCount = imageUrlArr.size(); + + if (imageUrlArr.size() > 0) + { + shortData.firstImageUrl = imageUrlArr.get(0); + } + + result.add(shortData); + } while (cursor.moveToNext()); + + } + + cursor.close(); + } + + } finally + { + dbHelper.close(); + } + + } + + return result; + } +*/ + private boolean innerIsTranslationAlreadyExist(String name, SQLiteDatabase database) + { + boolean result = false; + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_TRANSLATION, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME + + "=?", new String[] { name }, null, null, null, null); + + if (cursor != null) + { + if (cursor.getCount() > 0) + { + result = true; + } + + cursor.close(); + cursor = null; + + + } + + return result; + + } +/* + private boolean innerPhotoAlbumRelationAlreadyExist(String imageUrl, String name, SQLiteDatabase database) + { + boolean result = false; + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL, + BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?" + " AND " + BashgidSqliteHelper.COLUMN_NAME + "=?", + new String[] { imageUrl, name }, null, null, null, null); + + if (cursor != null) + { + if (cursor.getCount() > 0) + { + result = true; + } + + cursor.close(); + } + + return result; + + } + + private ArrayList innerGetImageUrlArrInAlbum(String name, SQLiteDatabase database) + { + ArrayList result = new ArrayList(); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL }, + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + + if (cursor != null) + { + if (cursor.moveToFirst()) + { + do + { + result.add(cursor.getString(0)); + } while (cursor.moveToNext()); + + } + + cursor.close(); + } + + return result; + + } + +*/ + public TranslationRecordData innerGetTranslationByName(String name, SQLiteDatabase database) + { + + TranslationRecordData result = null; + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_TRANSLATION, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TEXT_EN, + BashgidSqliteHelper.COLUMN_TEXT_RU, BashgidSqliteHelper.COLUMN_TEXT_ZH }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + + if (cursor != null) + { + if (cursor.moveToFirst()) + { + result = new TranslationRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getString(3)); + } + + cursor.close(); + cursor = null; + } + + return result; + + } + + + + +} diff --git a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java index 9f6a667..8e93220 100644 --- a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java @@ -106,6 +106,7 @@ public class VideoDataSource } cursor.close(); + cursor = null; } return result; @@ -127,6 +128,7 @@ public class VideoDataSource } cursor.close(); + cursor = null; } return result;