diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 08c03cf..60bc839 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="2" + android:versionName="1.01" > - - - - + @@ -34,8 +30,7 @@ + android:configChanges="orientation" > @@ -45,11 +40,6 @@ - - - diff --git a/android/ic_launcher-web.png b/android/ic_launcher-web.png index 3a3c3f6..3a3f4ba 100644 Binary files a/android/ic_launcher-web.png and b/android/ic_launcher-web.png differ diff --git a/android/res/drawable-hdpi/ic_action_refresh.png b/android/res/drawable-hdpi/ic_action_refresh.png new file mode 100644 index 0000000..45b2228 Binary files /dev/null and b/android/res/drawable-hdpi/ic_action_refresh.png differ diff --git a/android/res/drawable-hdpi/ic_launcher.png b/android/res/drawable-hdpi/ic_launcher.png index 476e7c9..e6c3377 100644 Binary files a/android/res/drawable-hdpi/ic_launcher.png and b/android/res/drawable-hdpi/ic_launcher.png differ diff --git a/android/res/drawable-ldpi/abc_ic_search_api_mtrl_alpha.png b/android/res/drawable-ldpi/abc_ic_search_api_mtrl_alpha.png index 0a26547..30b62d0 100644 Binary files a/android/res/drawable-ldpi/abc_ic_search_api_mtrl_alpha.png and b/android/res/drawable-ldpi/abc_ic_search_api_mtrl_alpha.png differ diff --git a/android/res/drawable-mdpi/ic_action_refresh.png b/android/res/drawable-mdpi/ic_action_refresh.png new file mode 100644 index 0000000..de008e5 Binary files /dev/null and b/android/res/drawable-mdpi/ic_action_refresh.png differ diff --git a/android/res/drawable-mdpi/ic_launcher.png b/android/res/drawable-mdpi/ic_launcher.png index 6d651e7..21fd621 100644 Binary files a/android/res/drawable-mdpi/ic_launcher.png and b/android/res/drawable-mdpi/ic_launcher.png differ diff --git a/android/res/drawable-xhdpi/drawer_agenda.png b/android/res/drawable-xhdpi/drawer_agenda.png new file mode 100644 index 0000000..95001c9 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_agenda.png differ diff --git a/android/res/drawable-xhdpi/drawer_bookmark.png b/android/res/drawable-xhdpi/drawer_bookmark.png new file mode 100644 index 0000000..68d3951 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_bookmark.png differ diff --git a/android/res/drawable-xhdpi/drawer_books.png b/android/res/drawable-xhdpi/drawer_books.png new file mode 100644 index 0000000..eeeb783 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_books.png differ diff --git a/android/res/drawable-xhdpi/drawer_gear.png b/android/res/drawable-xhdpi/drawer_gear.png new file mode 100644 index 0000000..4c08fbe Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_gear.png differ diff --git a/android/res/drawable-xhdpi/drawer_id.png b/android/res/drawable-xhdpi/drawer_id.png new file mode 100644 index 0000000..98f2580 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_id.png differ diff --git a/android/res/drawable-xhdpi/drawer_industry.png b/android/res/drawable-xhdpi/drawer_industry.png new file mode 100644 index 0000000..b35e8ba Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_industry.png differ diff --git a/android/res/drawable-xhdpi/drawer_news.png b/android/res/drawable-xhdpi/drawer_news.png new file mode 100644 index 0000000..157b6cc Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_news.png differ diff --git a/android/res/drawable-xhdpi/drawer_phone.png b/android/res/drawable-xhdpi/drawer_phone.png new file mode 100644 index 0000000..efa2240 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_phone.png differ diff --git a/android/res/drawable-xhdpi/drawer_photography.png b/android/res/drawable-xhdpi/drawer_photography.png new file mode 100644 index 0000000..acba6eb Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_photography.png differ diff --git a/android/res/drawable-xhdpi/drawer_pushpin.png b/android/res/drawable-xhdpi/drawer_pushpin.png new file mode 100644 index 0000000..31134e7 Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_pushpin.png differ diff --git a/android/res/drawable-xhdpi/drawer_tv.png b/android/res/drawable-xhdpi/drawer_tv.png new file mode 100644 index 0000000..b6b73bb Binary files /dev/null and b/android/res/drawable-xhdpi/drawer_tv.png differ diff --git a/android/res/drawable-xhdpi/ic_action_refresh.png b/android/res/drawable-xhdpi/ic_action_refresh.png new file mode 100644 index 0000000..cdc160d Binary files /dev/null and b/android/res/drawable-xhdpi/ic_action_refresh.png differ diff --git a/android/res/drawable-xhdpi/ic_launcher.png b/android/res/drawable-xhdpi/ic_launcher.png index 4217fe2..852a133 100644 Binary files a/android/res/drawable-xhdpi/ic_launcher.png and b/android/res/drawable-xhdpi/ic_launcher.png differ diff --git a/android/res/drawable-xxhdpi/ic_action_refresh.png b/android/res/drawable-xxhdpi/ic_action_refresh.png new file mode 100644 index 0000000..cb847f3 Binary files /dev/null and b/android/res/drawable-xxhdpi/ic_action_refresh.png differ diff --git a/android/res/drawable-xxhdpi/ic_launcher.png b/android/res/drawable-xxhdpi/ic_launcher.png index 3e03653..4111868 100644 Binary files a/android/res/drawable-xxhdpi/ic_launcher.png and b/android/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/android/res/drawable/background.png b/android/res/drawable/background.png index 524a705..de08217 100644 Binary files a/android/res/drawable/background.png and b/android/res/drawable/background.png differ diff --git a/android/res/drawable/bashgid_logo_main.png b/android/res/drawable/bashgid_logo_main.png index 212a935..bac916e 100644 Binary files a/android/res/drawable/bashgid_logo_main.png and b/android/res/drawable/bashgid_logo_main.png differ diff --git a/android/res/layout/article_button_element.xml b/android/res/layout/article_button_element.xml index 6a1250a..e1cba27 100644 --- a/android/res/layout/article_button_element.xml +++ b/android/res/layout/article_button_element.xml @@ -13,7 +13,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/medium_margin" - android:background="@color/bkg2" + android:background="@color/button_default" android:drawableLeft="@drawable/ic_action_web_site" android:text="@string/go_to_website" android:textSize="@dimen/xlarge_text_size" /> diff --git a/android/res/layout/article_phone_element.xml b/android/res/layout/article_phone_element.xml index e6403e2..f7e41bb 100644 --- a/android/res/layout/article_phone_element.xml +++ b/android/res/layout/article_phone_element.xml @@ -13,7 +13,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/medium_margin" - android:background="@color/bkg2" + android:background="@color/button_default" android:drawableLeft="@drawable/ic_action_call" android:gravity="left|center_vertical" android:textSize="@dimen/xlarge_text_size" /> diff --git a/android/res/layout/article_photo_element.xml b/android/res/layout/article_photo_element.xml index ac3f1ce..2587f6e 100644 --- a/android/res/layout/article_photo_element.xml +++ b/android/res/layout/article_photo_element.xml @@ -7,14 +7,16 @@ android:orientation="vertical" android:showDividers="middle" > - + android:cropToPadding="false" + android:minHeight="10dp" + android:minWidth="10dp" + android:scaleType="centerCrop" /> - + android:verticalSpacing="@dimen/grid_view_vertical_spacing" + android:isScrollContainer="false" + android:stretchMode="columnWidth" /> + - diff --git a/android/res/layout/fragment_photo_album_list_page.xml b/android/res/layout/fragment_journal_page.xml similarity index 69% rename from android/res/layout/fragment_photo_album_list_page.xml rename to android/res/layout/fragment_journal_page.xml index e1b0494..c939213 100644 --- a/android/res/layout/fragment_photo_album_list_page.xml +++ b/android/res/layout/fragment_journal_page.xml @@ -7,7 +7,7 @@ android:orientation="vertical" tools:context="fishrungames.bashgid.MainPageFragment" > - + + + + diff --git a/android/res/layout/fragment_photo_album_page.xml b/android/res/layout/fragment_photo_album_page.xml index c939213..825ef54 100644 --- a/android/res/layout/fragment_photo_album_page.xml +++ b/android/res/layout/fragment_photo_album_page.xml @@ -3,19 +3,18 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="0dp" - android:background="@color/bkg1" + android:background="@color/black" android:orientation="vertical" tools:context="fishrungames.bashgid.MainPageFragment" > - diff --git a/android/res/layout/fragment_settings_page.xml b/android/res/layout/fragment_settings_page.xml index dc69a87..fcdf5f2 100644 --- a/android/res/layout/fragment_settings_page.xml +++ b/android/res/layout/fragment_settings_page.xml @@ -139,6 +139,7 @@ style="?android:attr/borderlessButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@color/button_default" android:text="@string/call_support" android:textSize="@dimen/small_text_size" android:layout_marginBottom="@dimen/medium_margin" @@ -149,6 +150,7 @@ style="?android:attr/borderlessButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@color/button_default" android:text="@string/visit_kitap" android:textSize="@dimen/small_text_size" android:layout_marginBottom="@dimen/medium_margin" /> @@ -158,6 +160,7 @@ style="?android:attr/borderlessButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@color/button_default" android:text="@string/visit_developer" android:textSize="@dimen/small_text_size" android:layout_marginBottom="@dimen/medium_margin" /> @@ -167,6 +170,7 @@ style="?android:attr/borderlessButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="@color/button_default" android:text="@string/visit_translator" android:textSize="@dimen/small_text_size" android:layout_marginBottom="@dimen/medium_margin" /> diff --git a/android/res/layout/fragment_video_record_page.xml b/android/res/layout/fragment_video_record_page.xml index 880824e..47d7c07 100644 --- a/android/res/layout/fragment_video_record_page.xml +++ b/android/res/layout/fragment_video_record_page.xml @@ -32,7 +32,9 @@ + android:layout_height="wrap_content" + android:layout_margin="@dimen/medium_margin" /> + diff --git a/android/res/layout/fragment_welcome.xml b/android/res/layout/fragment_welcome.xml index 2158ea9..d8999d7 100644 --- a/android/res/layout/fragment_welcome.xml +++ b/android/res/layout/fragment_welcome.xml @@ -36,7 +36,9 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/lang_english" - android:textSize="@dimen/language_text_size" /> + android:textColor="@color/text_white" + android:textSize="@dimen/language_text_size" + android:textStyle="bold" /> + android:textColor="@color/text_white" + android:textSize="@dimen/language_text_size" + android:textStyle="bold" /> + android:textColor="@color/text_white" + android:textSize="@dimen/language_text_size" + android:textStyle="bold" /> - + + + + + + + + + + + + + + + + + + + + diff --git a/android/res/layout/main_page_news.xml b/android/res/layout/main_page_news.xml index b69dbf7..b29ad8f 100644 --- a/android/res/layout/main_page_news.xml +++ b/android/res/layout/main_page_news.xml @@ -6,23 +6,40 @@ android:orientation="vertical" tools:context="fishrungames.bashgid.MainPageFragment" > + + + + + + + android:id="@+id/newsDownloadProgressBar" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:indeterminate="false" + android:max="100" + android:progress="0" /> diff --git a/android/res/layout/main_page_search.xml b/android/res/layout/main_page_search.xml index 65d388b..17e46b7 100644 --- a/android/res/layout/main_page_search.xml +++ b/android/res/layout/main_page_search.xml @@ -29,6 +29,8 @@ android:id="@+id/searchEditText" android:layout_width="match_parent" android:layout_height="wrap_content" + android:lines="1" + android:maxLines="1" android:hint="@string/enter_search_query" > @@ -41,6 +43,9 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:drawableLeft="@drawable/ic_action_search" + android:layout_margin="@dimen/medium_margin" + android:background="@color/button_default" + android:padding="@dimen/medium_margin" android:text="@string/search_title" android:textSize="@dimen/large_text_size" /> diff --git a/android/res/layout/news_page_list_header.xml b/android/res/layout/news_page_list_header.xml index 7368bf5..cfe2afd 100644 --- a/android/res/layout/news_page_list_header.xml +++ b/android/res/layout/news_page_list_header.xml @@ -8,22 +8,38 @@ android:paddingRight="20dp" tools:context="fishrungames.bashgid.MainPageFragment" > - - + android:layout_gravity="center_vertical|center_horizontal" > + + + + + + + + android:id="@+id/newsDownloadProgressBar" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:indeterminate="false" + android:max="100" + android:progress="0" /> \ No newline at end of file diff --git a/android/res/layout/photo_album_element.xml b/android/res/layout/photo_album_element.xml index 21d64c7..0d7d17a 100644 --- a/android/res/layout/photo_album_element.xml +++ b/android/res/layout/photo_album_element.xml @@ -1,18 +1,20 @@ - + diff --git a/android/res/layout/photo_album_list_element.xml b/android/res/layout/photo_album_list_element.xml deleted file mode 100644 index 61e84b6..0000000 --- a/android/res/layout/photo_album_list_element.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - diff --git a/android/res/layout/photo_page_element.xml b/android/res/layout/photo_page_element.xml index 41ec3a8..a5d6b4c 100644 --- a/android/res/layout/photo_page_element.xml +++ b/android/res/layout/photo_page_element.xml @@ -3,6 +3,7 @@ android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/black" android:gravity="center_vertical" android:orientation="vertical" > @@ -32,6 +33,7 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/large_margin" android:text="TextView" + android:textColor="@color/text_white" android:textSize="@dimen/xlarge_text_size" android:textStyle="bold" /> @@ -42,6 +44,7 @@ android:layout_marginLeft="@dimen/large_margin" android:layout_marginRight="@dimen/large_margin" android:text="TextView" + android:textColor="@color/text_white" android:textSize="@dimen/medium_text_size" /> diff --git a/android/res/layout/search_page_list_header.xml b/android/res/layout/search_page_list_header.xml index e671c90..1974d1c 100644 --- a/android/res/layout/search_page_list_header.xml +++ b/android/res/layout/search_page_list_header.xml @@ -7,20 +7,30 @@ tools:context="fishrungames.bashgid.SearchFragment" > + + + android:inputType="text" + android:lines="1" + android:maxLines="1" + android:textSize="@dimen/medium_text_size" > @@ -28,6 +38,7 @@ + android:layout_height="wrap_content" + android:textSize="@dimen/xsmall_text_size" /> \ No newline at end of file diff --git a/android/res/menu/global.xml b/android/res/menu/global.xml index 21f8f37..91ed1e6 100644 --- a/android/res/menu/global.xml +++ b/android/res/menu/global.xml @@ -4,7 +4,7 @@ diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml index c1e4e13..692176f 100644 --- a/android/res/values-ru/strings.xml +++ b/android/res/values-ru/strings.xml @@ -49,11 +49,6 @@ Перейти на сайт - Купить... - Читать - Стоимость: - Руб. - Показать на карте Карта загружается... Карта загружена @@ -74,7 +69,7 @@ Идет поиск, пожалуйста, подождите... Чтобы начать поиск, введите как минимум 3 символа -Башгид (c) 2015\n\nВсе права принадлежат ГУП «Китап»\nТелефон: +73472238838\nhttp://kitap-ufa.ru/\n\nРазработчик - Владислав Хорев\nТелефон: +79260492730\nEmail: mephi1984@gmail.com\n\nПеревод на китайский язык сделан Лилией Лисицей\nТелефон: +8615756011926\nEmail:lilialoo926@mail.ru +Башгид (c) 2015\n\nВсе права принадлежат ГУП «Китап»\nТелефон: +73472238838\nhttp://kitap-ufa.ru/\n\nРазработчик - Владислав Хорев\nТелефон: +79260492730\nEmail: mephi1984@gmail.com\nhttp://fishrungames.ru/\n\nПеревод на китайский язык сделан Лилией Лисицей\nТелефон: +8615756011926\nEmail: littlefoxlilia@mail.ru\nhttp://littlefoxlilia.ru/ У вас возникли трудности при работе с приложением? Нажмите сюда, чтобы позвонить в техподдержку. @@ -90,6 +85,13 @@ Категория загружена + +Чтобы искать во всех категориях, нажмите кнопку Поиск справа вверху + +http://littlefoxlilia.ru/ru/%D0%BE-%D1%81%D0%B5%D0%B1%D0%B5/ + +Символы РБ + diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml index 8d56e7d..b5ac520 100644 --- a/android/res/values-zh-rCN/strings.xml +++ b/android/res/values-zh-rCN/strings.xml @@ -1,7 +1,8 @@ - 俄罗斯联邦巴什基尔自治共和国指南 + + 巴什科尔托斯坦指南 打开导航窗口 关闭导航窗口 设置 @@ -10,13 +11,13 @@ 搜索标题 - 输入问题 + 输入关键词 - 无法查看新闻记录 - 其他新闻… + 无法查看记录 + 其他… - 查看所有新闻 + 更多 头条新闻 @@ -29,10 +30,10 @@ 标识 - 俄罗斯联邦巴什基尔自治共和国指南 + 巴什科尔托斯坦指南 指南 新闻 - 目录 + 所有文章 地图 视频 图片库 @@ -40,12 +41,7 @@ 投资者信息 设置 - 去现场 - - Buy - Read - Price: - RUB + 跳转至详细信息页面 在地图上显示 @@ -57,7 +53,7 @@ 取消 全面搜索 -在%%搜索: +在%%搜索: %% 地址: 复制文本 @@ -65,23 +61,28 @@ 搜索结果: %% 文章被找到 正在搜索,请稍等… -输入关键字符,开始搜索 +请输入关键字并开始搜索 -Bashguide (c) 2015\n\nApplication owner: ГУП «Китап»\nPhone: +73472238838\nhttp://kitap-ufa.ru/\n\nApplication is made by Vladislav Khorev\nPhone: +79260492730\nEmail: mephi1984@gmail.com\n\nTranslation to Chinese made by Little Fox Lilia\nPhone: +8615756011926\nEmail:lilialoo926@mail.ru +巴什科尔托斯坦指南 (c) 2015\n\n软件所有权:版权归俄罗斯国企“基塔普”公司所有 (ГУП «Китап»)\n电话: +73472238838\nhttp://kitap-ufa.ru/\n\n软件开发者:弗拉季斯拉夫·郝列夫\n电话: +79260492730\n邮箱: mephi1984@gmail.com\nhttp://fishrungames.ru/\n\n软件翻译:小狐狸莉莉娅\n电话: +8615756011926\n邮箱:littlefoxlilia@mail.ru\nhttp://littlefoxlilia.ru/ -Having problems with application? Click here to call support. +程序出现问题?请点击这里寻求技术支持 -Visit ГУП «Китап» website +查看“基塔普”公司网站 -Visit developer\'s website +查看开发人员的个人网站 -Visit translator\'s website +查看翻译人员的个人网站 -Tap and hold address to copy it to clipboard. +请轻按地址直至复制到剪贴板 -Category is loading... - -Category is loaded +正在加载目录... +目录加载完毕 +如果您想要搜索所有的目录,请点击右上角的搜索按钮 + +http://littlefoxlilia.ru/zh/%E5%85%B3%E4%BA%8E%E6%88%91/ + +巴什科尔托斯坦特色 + diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml index 6902d6f..70720eb 100644 --- a/android/res/values/colors.xml +++ b/android/res/values/colors.xml @@ -27,6 +27,7 @@ #d0d0d0 +#e0e0e0 #202020 diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 10d1467..b53a150 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -49,12 +49,7 @@ Go to website - - Buy - Read - Price: - RUB - + Show on map Map is loading... Map is loaded @@ -75,7 +70,7 @@ Search is performing, please wait... To start search, enter at least 3 symbols -Bashguide (c) 2015\n\nApplication owner: ГУП «Китап»\nPhone: +73472238838\nhttp://kitap-ufa.ru/\n\nApplication is made by Vladislav Khorev\nPhone: +79260492730\nEmail: mephi1984@gmail.com\n\nTranslation to Chinese made by Little Fox Lilia\nPhone: +8615756011926\nEmail:lilialoo926@mail.ru +Bashguide (c) 2015\n\nApplication owner: ГУП «Китап»\nPhone: +73472238838\nhttp://kitap-ufa.ru/\n\nApplication is made by Vladislav Khorev\nPhone: +79260492730\nEmail: mephi1984@gmail.com\nhttp://fishrungames.ru/\n\nTranslation to Chinese made by Little Fox Lilia\nPhone: +8615756011926\nEmail: littlefoxlilia@mail.ru\nhttp://littlefoxlilia.ru/ Having problems with application? Click here to call support. @@ -91,6 +86,11 @@ Category is loaded +If you want to search in all categories, click search button at top right + +http://littlefoxlilia.ru/en/about/ + +Featured RB diff --git a/android/src/fishrungames/bashgid/AlbumListFragment.java b/android/src/fishrungames/bashgid/AlbumListFragment.java index 3c8a268..44b4f7a 100644 --- a/android/src/fishrungames/bashgid/AlbumListFragment.java +++ b/android/src/fishrungames/bashgid/AlbumListFragment.java @@ -32,13 +32,14 @@ public class AlbumListFragment extends Fragment GridView gridView; - ArrayList albumArr; + ArrayList albumArr = new ArrayList(); ProgressBar progressBar; + + DatabaseGetAlbumListTask databaseGetAlbumListTask = null; public AlbumListFragment() { - RestoreAlbumList(); } public AlbumListFragment(ArrayList albumArr) @@ -50,7 +51,7 @@ public class AlbumListFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_video_page, container, false); + View rootView = inflater.inflate(R.layout.fragment_grid_page, container, false); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); @@ -72,29 +73,88 @@ public class AlbumListFragment extends Fragment } }); + + if (albumArr.size() == 0) + { + RestoreAlbumList(); + } return rootView; } + + @Override + public void onDestroyView() + { + + CancelTaskIfRunning(); + + super.onDestroyView(); + } + + public void OnDatabaseDonwloadProgress(Integer percent) + { + /* + databaseDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + databaseDownloadProgressBar.setVisibility(View.GONE); + } + else + { + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + } + */ + if (databaseGetAlbumListTask == null || percent == 100) + { + RestoreAlbumList(); + } + + //SetJournalList(r.journalList); + } public void RestoreAlbumList() { + CancelTaskIfRunning(); + albumArr = new ArrayList(); - DatabaseGetAlbumListTask task = new DatabaseGetAlbumListTask(); + databaseGetAlbumListTask = new DatabaseGetAlbumListTask(); - task.mHandler = MainActivity.getInstance().mHandler; + //databaseGetAlbumListTask.mHandler = MainActivity.getInstance().databaseHandler; - task.execute(); + //databaseGetAlbumListTask.execute(); + databaseGetAlbumListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } public void SetAlbumList(ArrayList albumArr) { + databaseGetAlbumListTask = null; + progressBar.setVisibility(View.GONE); this.albumArr = albumArr; listAdapter.notifyDataSetChanged(); } + + public void CancelTaskIfRunning() + { + if (databaseGetAlbumListTask != null) + { + databaseGetAlbumListTask.cancel(false); + databaseGetAlbumListTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } public static class DatabaseGetAlbumListTask extends AsyncTask { @@ -113,15 +173,15 @@ public class AlbumListFragment extends Fragment protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_UPDATE, albumArr); + //Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_UPDATE, albumArr); - completeMessage.sendToTarget(); + //completeMessage.sendToTarget(); } protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_FINISHED, albumArr); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_FINISHED, albumArr); completeMessage.sendToTarget(); } @@ -160,7 +220,7 @@ public class AlbumListFragment extends Fragment if (convertView == null) { // if it's not recycled, initialize some attributes LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.video_page_list_element, null); + view = inflater.inflate(R.layout.grid_page_list_element, null); } else { @@ -169,11 +229,20 @@ public class AlbumListFragment extends Fragment ImageView imageView = (ImageView) view.findViewById(R.id.imageView); TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView); + + if (albumArr.get(position) != null) + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, albumArr.get(position).firstImageUrl); + nameTextView.setText(albumArr.get(position).title); - ImageManager.getInstance().ApplyImageToImageView(imageView, albumArr.get(position).firstImageUrl); - - nameTextView.setText(albumArr.get(position).title); + } + else + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, "R.drawable.no_picture"); + nameTextView.setText(""); + } + return view; } diff --git a/android/src/fishrungames/bashgid/ArticleFragment.java b/android/src/fishrungames/bashgid/ArticleFragment.java index a0836b8..f755402 100644 --- a/android/src/fishrungames/bashgid/ArticleFragment.java +++ b/android/src/fishrungames/bashgid/ArticleFragment.java @@ -26,6 +26,7 @@ import android.graphics.Canvas; import android.graphics.Typeface; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -121,28 +122,29 @@ public class ArticleFragment extends Fragment ProgressBar progressBar; - String articleName; - ArticleFullData article; + String articleName = ""; + + ArticleFullData article = null; + + DatabaseGetArticleTask databaseGetArticleTask = null; + + ArrayList articleLayout = new ArrayList(); public ArticleFragment() { - articleName = ""; - article = null; } public ArticleFragment(String articleName) { this.articleName = articleName; RestoreArticle(); - ReloadLayout(); } public ArticleFragment(ArticleFullData article) { this.articleName = article.name; this.article = article; - ReloadLayout(); } @Override @@ -154,11 +156,13 @@ public class ArticleFragment extends Fragment public void RestoreArticle() { - DatabaseGetArticleTask task = new DatabaseGetArticleTask(); + CancelTaskIfRunning(); + + databaseGetArticleTask = new DatabaseGetArticleTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetArticleTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(articleName); + databaseGetArticleTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, articleName); } public void ReloadLayout() @@ -214,6 +218,8 @@ public class ArticleFragment extends Fragment public void SetArticle(ArticleFullData article) { + databaseGetArticleTask = null; + progressBar.setVisibility(View.GONE); this.article = article; @@ -222,18 +228,20 @@ public class ArticleFragment extends Fragment listAdapter.notifyDataSetChanged(); } + + public void CancelTaskIfRunning() + { + if (databaseGetArticleTask != null) + { + databaseGetArticleTask.cancel(false); + databaseGetArticleTask = null; + } + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) - { - articleName = savedInstanceState.getString("articleName"); - RestoreArticle(); - ReloadLayout(); - } - View rootView = inflater.inflate(R.layout.fragment_article_page, container, false); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); @@ -245,9 +253,39 @@ public class ArticleFragment extends Fragment listAdapter = new ListAdapter(getActivity()); listView.setAdapter(listAdapter); + + + if (savedInstanceState != null) + { + articleName = savedInstanceState.getString("articleName"); + RestoreArticle(); + } + else if (articleName.length() > 0 && article == null) + { + RestoreArticle(); + } + + ReloadLayout(); return rootView; } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } + + @Override + public void onDestroyView() + { + + CancelTaskIfRunning(); + + super.onDestroyView(); + } public class ListAdapter extends BaseAdapter { @@ -314,8 +352,7 @@ public class ArticleFragment extends Fragment { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.article_button_element, null); - } else - // if (getItemViewType(position) == 6) + } else // if (getItemViewType(position) == 6) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.article_phone_element, null); @@ -333,10 +370,10 @@ public class ArticleFragment extends Fragment if (article.type == ArticleManager.ARTICLE_TYPE_NEWS) { - textView.setTextSize(getResources().getDimension(R.dimen.xlarge_text_size)); + textView.setTextSize(getResources().getDimension(R.dimen.large_text_size)); } else { - textView.setTextSize(getResources().getDimension(R.dimen.xxlarge_text_size)); + textView.setTextSize(getResources().getDimension(R.dimen.xlarge_text_size)); } textView.setTypeface(null, Typeface.BOLD); @@ -359,7 +396,23 @@ public class ArticleFragment extends Fragment PhotoRecordData photo = MainActivity.getInstance().photoDataSource.GetPhotoByImageUrl(articleLayout.get(position).value); - ImageManager.getInstance().ApplyImageToImageView(imageView, photo.imageUrl); + //ImageManager.getInstance().ApplyImageToImageView(imageView, photo.imageUrl); + ImageManager.getInstance().ApplySmallImageToImageView(imageView, photo.imageUrl); + + imageView.setOnClickListener(new OnClickListener() + { + + @Override + public void onClick(View v) + { + MainActivity.getInstance().SetLastArticleName(articleName); + + String albumName = article.albumArr.get(0).name; + + MainActivity.getInstance().OpenPhotoScreen(albumName, 0, MainActivity.TAG_BACK_TO_ARTICLEFRAGMENT); + } + + }); textView.setText(photo.title); } else if (getItemViewType(position) == 3) @@ -382,6 +435,7 @@ public class ArticleFragment extends Fragment addressTextView.setOnLongClickListener(new OnLongClickListener() { + @SuppressWarnings("deprecation") @Override public boolean onLongClick(View v) { @@ -407,7 +461,7 @@ public class ArticleFragment extends Fragment } }); - // editText.setKeyListener(null); + } else { @@ -494,7 +548,7 @@ public class ArticleFragment extends Fragment startActivity(i); } }); - } else if (getItemViewType(position) == 6) + } else //if (getItemViewType(position) == 6) { Button button = (Button) view.findViewById(R.id.button); diff --git a/android/src/fishrungames/bashgid/CatalogFragment.java b/android/src/fishrungames/bashgid/CatalogFragment.java index 4ff853d..07504da 100644 --- a/android/src/fishrungames/bashgid/CatalogFragment.java +++ b/android/src/fishrungames/bashgid/CatalogFragment.java @@ -8,6 +8,7 @@ import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -29,13 +30,12 @@ public class CatalogFragment extends Fragment ListAdapter listAdapter; ProgressBar progressBar; - ArrayList journalList; + ArrayList journalList = new ArrayList(); DatabaseGetJournalListTask databaseGetJournalListTask = null; public CatalogFragment() { - RestoreJournalList(); } public CatalogFragment(ArrayList journalList) @@ -58,6 +58,11 @@ public class CatalogFragment extends Fragment listAdapter = new ListAdapter(getActivity()); listView.setAdapter(listAdapter); + + if (journalList.size() == 0) + { + RestoreJournalList(); + } return rootView; } @@ -66,24 +71,44 @@ public class CatalogFragment extends Fragment public void onDestroyView() { - if (databaseGetJournalListTask != null) - { - databaseGetJournalListTask.cancel(false); - databaseGetJournalListTask = null; - } + CancelTaskIfRunning(); super.onDestroyView(); } + + public void OnDatabaseDonwloadProgress(Integer percent) + { + /* + databaseDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + databaseDownloadProgressBar.setVisibility(View.GONE); + } + else + { + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + } + */ + if (databaseGetJournalListTask == null || percent == 100) + { + RestoreJournalList(); + } + + //SetJournalList(r.journalList); + } public void RestoreJournalList() { - journalList = new ArrayList(); + CancelTaskIfRunning(); + + //journalList = new ArrayList(); databaseGetJournalListTask = new DatabaseGetJournalListTask(); - databaseGetJournalListTask.mHandler = MainActivity.getInstance().mHandler; + //databaseGetJournalListTask.mHandler = MainActivity.getInstance().mainHandler; - databaseGetJournalListTask.execute(); + databaseGetJournalListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void SetJournalList(ArrayList journalList) @@ -96,6 +121,23 @@ public class CatalogFragment extends Fragment listAdapter.notifyDataSetChanged(); } + + public void CancelTaskIfRunning() + { + if (databaseGetJournalListTask != null) + { + databaseGetJournalListTask.cancel(false); + databaseGetJournalListTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } public class ListAdapter extends BaseAdapter { diff --git a/android/src/fishrungames/bashgid/DynamicImageView.java b/android/src/fishrungames/bashgid/DynamicImageView.java index 433ac56..80747e5 100644 --- a/android/src/fishrungames/bashgid/DynamicImageView.java +++ b/android/src/fishrungames/bashgid/DynamicImageView.java @@ -10,7 +10,7 @@ public class DynamicImageView extends ImageView { public DynamicImageView(final Context context, final AttributeSet attrs) { super(context, attrs); } - + @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { final Drawable d = this.getDrawable(); diff --git a/android/src/fishrungames/bashgid/JournalFragment.java b/android/src/fishrungames/bashgid/JournalFragment.java index 362b3d2..5abe956 100644 --- a/android/src/fishrungames/bashgid/JournalFragment.java +++ b/android/src/fishrungames/bashgid/JournalFragment.java @@ -3,6 +3,7 @@ package fishrungames.bashgid; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -27,8 +28,8 @@ import fishrungames.networkutils.ImageManager; public class JournalFragment extends Fragment { - JournalSemiFullData journal; - String journalName; + JournalSemiFullData journal = null; + String journalName = ""; ListAdapter listAdapter; ProgressBar progressBar; @@ -38,8 +39,6 @@ public class JournalFragment extends Fragment public JournalFragment() { - journal = null; - journalName = ""; } public JournalFragment(String journalName) @@ -61,15 +60,10 @@ public class JournalFragment extends Fragment } - @Override + @SuppressLint("InflateParams") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - if (savedInstanceState != null) { - journalName = savedInstanceState.getString("journalName"); - RestoreJournal(); - } - - View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false); + + View rootView = inflater.inflate(R.layout.fragment_journal_page, container, false); progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar); @@ -78,10 +72,8 @@ public class JournalFragment extends Fragment ListView listView = (ListView) rootView.findViewById(R.id.listView); - View header = inflater.inflate(R.layout.journal_page_header, null); - headerTextView = (TextView)header.findViewById(R.id.headerTextView); listView.addHeaderView(header); @@ -114,6 +106,15 @@ public class JournalFragment extends Fragment } }); + if (savedInstanceState != null) { + journalName = savedInstanceState.getString("journalName"); + RestoreJournal(); + } + else if (journalName.length() > 0 && journal == null) + { + RestoreJournal(); + } + return rootView; } @@ -121,11 +122,7 @@ public class JournalFragment extends Fragment public void onDestroyView () { - if (databaseGetJournalTask != null) - { - databaseGetJournalTask.cancel(false); - databaseGetJournalTask = null; - } + CancelTaskIfRunning(); super.onDestroyView(); } @@ -133,23 +130,17 @@ public class JournalFragment extends Fragment void RestoreJournal() { - if (databaseGetJournalTask != null) - { - databaseGetJournalTask.cancel(false); - databaseGetJournalTask = null; - } + CancelTaskIfRunning(); - journal = JournalManager.CreateEmptyJournal(); + journal = JournalManager.CreateEmptyJournalSemiFull(); databaseGetJournalTask = new DatabaseGetJournalTask(); - databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; - Bundle bundle = new Bundle(); bundle.putString("journalName", journalName); - databaseGetJournalTask.execute(bundle); + databaseGetJournalTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); } public void SetJournal(JournalSemiFullData journal) @@ -175,6 +166,23 @@ public class JournalFragment extends Fragment } + public void CancelTaskIfRunning() + { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } + public class ListAdapter extends BaseAdapter { @@ -223,7 +231,9 @@ public class JournalFragment extends Fragment if (journal.articleArr.get(position).previewImageUrl != null) { - ImageManager.getInstance().ApplyImageToImageView(imageView, journal.articleArr.get(position).previewImageUrl); + //ImageManager.getInstance().ApplyImageToImageView(imageView, journal.articleArr.get(position).previewImageUrl); + ImageManager.getInstance().ApplySmallImageToImageView(imageView, journal.articleArr.get(position).previewImageUrl); + } else { diff --git a/android/src/fishrungames/bashgid/MainActivity.java b/android/src/fishrungames/bashgid/MainActivity.java index ed38404..f4e8854 100644 --- a/android/src/fishrungames/bashgid/MainActivity.java +++ b/android/src/fishrungames/bashgid/MainActivity.java @@ -2,6 +2,7 @@ package fishrungames.bashgid; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.Locale; @@ -35,8 +36,11 @@ import android.support.v4.app.Fragment; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.drawable.BitmapDrawable; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; +import android.os.HandlerThread; import android.os.Looper; import android.os.Message; @@ -48,6 +52,7 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; import android.support.v4.widget.DrawerLayout; +import android.text.format.DateUtils; public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { @@ -56,7 +61,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public static final String TAG_BACK_TO_CATALOGFRAGMENT = "TAG_BACK_TO_CATALOGFRAGMENT"; public static final String TAG_BACK_TO_ALBUMLISTFRAGMENT = "TAG_BACK_TO_ALBUMLISTFRAGMENT"; - public static final String TAG_BACK_TO_JOURNALFRAGMENT = "TAG_BACK_TO_JOURNALFRAGMENT"; public static final String TAG_BACK_TO_ARTICLEFRAGMENT = "TAG_BACK_TO_ARTICLEFRAGMENT"; public static final String TAG_BACK_TO_ALBUMFRAGMENT = "TAG_BACK_TO_ALBUMFRAGMENT"; @@ -68,9 +72,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public static final String TAG_BACK_TO_NEWSLISTFRAGMENT = "TAG_BACK_TO_NEWSLISTFRAGMENT"; - - - public static final String PREFS_MAIN = "PREFS_MAIN"; @@ -107,7 +108,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE = 30; public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED = 31; - MainPageFragment mainPageFragment = null; NewsListFragment newsListFragment = null; @@ -144,9 +144,26 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public TranslationDataSource translationDataSource = null; + + private NewsDownloadTask newsDownloadTask = null; + private DatabaseDownloadTask databaseDownloadTask = null; + private ImageDownloadTask imageDownloadTask = null; + + //private Object imgUrlSynchronizer = new Object(); + private ArrayList queuedImgUrlArr = new ArrayList(); + private ArrayList queuedImgHashArr = new ArrayList(); + public static final SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); + - public Handler mHandler; + //public Handler mHandler; + + //public Handler databaseHandler; + + public Handler mainHandler; + + //public HandlerThread downloadHandlerThread; + //public HandlerThread databaseHandlerThread; @Override protected void onCreate(Bundle savedInstanceState) @@ -154,7 +171,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF super.onCreate(savedInstanceState); ImageManager.getInstance().PredefinedImageId.put("R.drawable.no_picture", R.drawable.no_picture); - + ImageManager.getInstance().PredefinedImageIdBitmap.put("R.drawable.no_picture", ((BitmapDrawable)getResources().getDrawable(R.drawable.no_picture)).getBitmap()); + + ImageManager.PreferredEmptyPicture = "R.drawable.no_picture"; + setContentView(R.layout.activity_main); SetupDrawer(); @@ -182,26 +202,65 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF translationDataSource = new TranslationDataSource(this, dbHelper); - mHandler = new Handler(Looper.getMainLooper()) + + /* + + downloadHandlerThread = new HandlerThread("downloadHandlerThread"); + downloadHandlerThread.start(); + + + mHandler = new Handler(downloadHandlerThread.getLooper()) { @Override public void handleMessage(Message inputMessage) { + Message msg; switch (inputMessage.what) { + + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: - UpdateOnImageDownloaded(); - break; + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); + + UpdateDatabaseRelatedThingsAndSendMessage(); + case NEWS_DOWNLOADER_STATE_UPDATE: + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); + break; case NEWS_DOWNLOADER_STATE_FINISHED: - UpdateOnNewsDownloaded(); + + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); + JournalSemiFullData journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news", null, 3); + Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); + completeMessage.sendToTarget(); break; + case DATABASE_DOWNLOADER_STATE_UPDATE: - case DATABASE_DOWNLOADER_STATE_FINISHED: - UpdateOnDatabaseDownloaded(); + + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); break; + + case DATABASE_DOWNLOADER_STATE_FINISHED: + + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); + + //UpdateDatabaseRelatedThingsAndSendMessage(); + + break; + + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: + msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + msg.sendToTarget(); + break; + case DATABASE_GET_ALBUM_STATE_UPDATE: case DATABASE_GET_ALBUM_STATE_FINISHED: UpdateOnAlbumLoaded((AlbumFullData) inputMessage.obj); @@ -252,8 +311,141 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF } }; + + + databaseHandlerThread = new HandlerThread("databaseHandlerThread"); + databaseHandlerThread.start(); + + databaseHandler = new Handler(databaseHandlerThread.getLooper()) + { + @Override + public void handleMessage(Message inputMessage) + { - DownloadDatabase(); + switch (inputMessage.what) + { + + case DATABASE_GET_ALBUM_STATE_UPDATE: + case DATABASE_GET_ALBUM_STATE_FINISHED: + case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: + case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: + case DATABASE_GET_ARTICLE_STATE_UPDATE: + case DATABASE_GET_ARTICLE_STATE_FINISHED: + case DATABASE_GET_JOURNAL_STATE_UPDATE: + case DATABASE_GET_JOURNAL_STATE_FINISHED: + case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: + case DATABASE_GET_CHANNEL_STATE_UPDATE: + case DATABASE_GET_CHANNEL_STATE_FINISHED: + case DATABASE_GET_VIDEO_STATE_UPDATE: + case DATABASE_GET_VIDEO_STATE_FINISHED: + case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: + case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: + + Message msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); + + msg.sendToTarget(); + + //DownloadRestImageArr(); + + break; + + default: + super.handleMessage(inputMessage); + } + } + + };*/ + + + mainHandler = new Handler(Looper.getMainLooper()) + { + @Override + public void handleMessage(Message inputMessage) + { + + switch (inputMessage.what) + { + + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: + UpdateOnImageDownloaded(); + break; + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: + UpdateOnImageDownloaded(); + imageDownloadTask = null; + DownloadRestImageArr(); + break; + case NEWS_DOWNLOADER_STATE_UPDATE: + UpdateOnNewsDownloaded((Integer)inputMessage.obj); + break; + case NEWS_DOWNLOADER_STATE_FINISHED: + UpdateOnNewsDownloaded((Integer)inputMessage.obj); + newsDownloadTask = null; + break; + case DATABASE_DOWNLOADER_STATE_UPDATE: + UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); + break; + case DATABASE_DOWNLOADER_STATE_FINISHED: + UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); + databaseDownloadTask = null; + break; + + case DATABASE_GET_JOURNAL_STATE_UPDATE: + case DATABASE_GET_JOURNAL_STATE_FINISHED: + final JournalSemiFullData journal = (JournalSemiFullData) inputMessage.obj; + UpdateOnJournalLoaded(journal); + break; + case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: + UpdateOnJournalListLoaded((ArrayList) inputMessage.obj); + break; + + case DATABASE_GET_ALBUM_STATE_UPDATE: + case DATABASE_GET_ALBUM_STATE_FINISHED: + UpdateOnAlbumLoaded((AlbumFullData) inputMessage.obj); + break; + case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: + case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: + + ArrayList albumShortList = (ArrayList) inputMessage.obj; + UpdateOnAlbumListLoaded(albumShortList); + break; + case DATABASE_GET_ARTICLE_STATE_UPDATE: + case DATABASE_GET_ARTICLE_STATE_FINISHED: + UpdateOnArticleLoaded((ArticleFullData) inputMessage.obj); + break; + + case DATABASE_GET_CHANNEL_STATE_UPDATE: + case DATABASE_GET_CHANNEL_STATE_FINISHED: + UpdateOnChannelLoaded((ChannelFullData) inputMessage.obj); + break; + + case DATABASE_GET_VIDEO_STATE_UPDATE: + case DATABASE_GET_VIDEO_STATE_FINISHED: + UpdateOnVideoLoaded((VideoRecordData) inputMessage.obj); + break; + + + + case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: + case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: + UpdateOnArticleSearchPerformed((ArrayList) inputMessage.obj); + break; + + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: + UpdateOnGeoJournalListLoaded((ArrayList) inputMessage.obj); + break; + default: + super.handleMessage(inputMessage); + } + } + + }; + + //DownloadDatabase(); } @@ -262,7 +454,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF return instance; } - +/* public void DownloadImageArr(String[] imageUrlArr) { @@ -275,41 +467,105 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF task.mHandler = mHandler; task.execute(innerQuery); - } + }*/ public void DownloadImageArr(String[] imageUrlArr, String[] imageHashArr) { + + synchronized(queuedImgUrlArr) + { + + for (int i = 0; i < imageUrlArr.length; i++) + { + queuedImgUrlArr.add(imageUrlArr[i]); + + if (imageHashArr[i] == null) + { + queuedImgHashArr.add(""); + } + else + { + queuedImgHashArr.add(imageHashArr[i]); + } + } - Bundle innerQuery = new Bundle(); + + } + + if (imageDownloadTask == null) + { + DownloadRestImageArr(); + } + + + } + + public void DownloadRestImageArr() + { + synchronized(queuedImgUrlArr) + { + if (queuedImgUrlArr.size() > 0) + { + imageDownloadTask = new ImageDownloadTask(); - innerQuery.putStringArray("imageUrlArr", imageUrlArr); - innerQuery.putStringArray("imageHashArr", imageHashArr); + imageDownloadTask.mHandler = mainHandler; + + Bundle innerQuery = new Bundle(); + + String[] imageUrlArr = queuedImgUrlArr.toArray(new String[queuedImgUrlArr.size()]); + String[] imageHashArr = queuedImgHashArr.toArray(new String[queuedImgHashArr.size()]); + + innerQuery.putStringArray("imageUrlArr", imageUrlArr); + innerQuery.putStringArray("imageHashArr", imageHashArr); + + queuedImgUrlArr.clear(); + queuedImgHashArr.clear(); - ImageDownloadTask task = new ImageDownloadTask(); - - task.mHandler = mHandler; - - task.execute(innerQuery); + imageDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, innerQuery); + + } + } } + /* public void DownloadImage(String imageUrl) { this.DownloadImageArr(new String[] { imageUrl }); } - +*/ public void DownloadImage(String imageUrl, String imageHash) { this.DownloadImageArr(new String[] { imageUrl }, new String[] { imageHash }); } + + public void CancelDownloadDatabaseTask() + { + if (databaseDownloadTask != null) + { + databaseDownloadTask.cancel(false); + databaseDownloadTask = null; + } + + UpdateOnDatabaseDownloaded(0); + } public void DownloadDatabase() { - DatabaseDownloadTask task = new DatabaseDownloadTask(); + /* + if (databaseDownloadTask != null) + { + databaseDownloadTask.cancel(false); + databaseDownloadTask = null; + }*/ + if (databaseDownloadTask != null) + { + return; + } + + databaseDownloadTask = new DatabaseDownloadTask(); - task.mHandler = mHandler; - - task.execute(); + databaseDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void ClearAllFragmentLinks() @@ -334,7 +590,27 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); } + + public void UpdateDatabaseRelatedThingsAndSendMessage() + { + if (mainPageFragment != null) + { + ArrayList journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(3); + + Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); + completeMessage.sendToTarget(); + } + + if (catalogFragment != null) + { + ArrayList journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(3); + + Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); + completeMessage.sendToTarget(); + } + } + /* public void StartDownloadImagesTask(ArrayList imageUrlArr, ArrayList imageHashArr) { ImageDownloadTask task = new ImageDownloadTask(); @@ -346,15 +622,36 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF query.putStringArray("imageUrlArr", (String[]) imageUrlArr.toArray()); task.execute(query); - } + }*/ + + public void CancelDownloadNewsTask() + { + if (newsDownloadTask != null) + { + newsDownloadTask.cancel(false); + newsDownloadTask = null; + } + + UpdateOnNewsDownloaded(0); + } + public void StartDownloadNewsTask() { - NewsDownloadTask task = new NewsDownloadTask(); + /* + if (newsDownloadTask != null) + { + newsDownloadTask.cancel(false); + newsDownloadTask = null; + }*/ + if (newsDownloadTask != null) + { + return; + } + + newsDownloadTask = new NewsDownloadTask(); - task.mHandler = mHandler; - - task.execute(); + newsDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void UpdateOnImageDownloaded() @@ -363,29 +660,98 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF { mainPageFragment.RefreshAdapter(); } - - if (newsListFragment != null) + + if (albumListFragment != null) { - newsListFragment.RefreshAdapter(); + albumListFragment.RefreshAdapter(); + } + + + if (photoAlbumFragment != null) + { + photoAlbumFragment.RefreshAdapter(); + } + + if (photoFragment != null) + { + photoFragment.RefreshAdapter(); + } + + if (articleFragment != null) + { + articleFragment.RefreshAdapter(); + } + + if (journalFragment != null) + { + journalFragment.RefreshAdapter(); + } + + if (catalogFragment != null) + { + catalogFragment.RefreshAdapter(); + } + + if (searchFragment != null) + { + searchFragment.RefreshAdapter(); + } + + if (videoListFragment != null) + { + videoListFragment.RefreshAdapter(); + } + + if (videoRecordFragment != null) + { + videoRecordFragment.RefreshView(); } } - public void UpdateOnNewsDownloaded() + public void UpdateOnNewsDownloaded(Integer percent) { + SetNewsDownloadProgress(percent); + if (mainPageFragment != null) { - mainPageFragment.RefreshJournal(); + mainPageFragment.OnNewsDownloadProgress(percent); } - + if (newsListFragment != null) { - newsListFragment.RefreshJournal(); + newsListFragment.OnNewsDownloadProgress(percent); } } - public void UpdateOnDatabaseDownloaded() + public void UpdateOnDatabaseDownloaded(Integer percent) { - + SetDatabaseDownloadProgress(percent); + + if (mainPageFragment != null) + { + mainPageFragment.OnDatabaseDonwloadProgress(percent); + } + + if (catalogFragment != null) + { + catalogFragment.OnDatabaseDonwloadProgress(percent); + } + + if (albumListFragment != null) + { + albumListFragment.OnDatabaseDonwloadProgress(percent); + } + + if (photoAlbumFragment != null) + { + photoAlbumFragment.OnDatabaseDonwloadProgress(percent); + } + + if (videoListFragment != null) + { + videoListFragment.OnDatabaseDonwloadProgress(percent); + } + } public void UpdateOnAlbumLoaded(AlbumFullData album) @@ -502,6 +868,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF { if (searchFragment != null) { + OpenSearchScreen(); return; } @@ -776,13 +1143,14 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } + /* public void UpdateMainScreenIfPossible(Bundle result) { if (mainPageFragment != null) { mainPageFragment.RefreshJournal(); } - } + }*/ @Override public void onAttachFragment(Fragment fragment) @@ -903,6 +1271,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF return; } + if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_ALBUMLISTFRAGMENT) != null) + { + OpenPhotoAlbumListScreen(); + return; + } + + if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_CHANNELFRAGMENT) != null) { OpenVideoListScreen(GetLastChannelName()); @@ -988,8 +1363,8 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); return settings.getString("lastJournalName", ""); } + - public void SetLastJournalTitle(String lastJournalTitle) { SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); @@ -1034,6 +1409,43 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); return settings.getString("lastMapFilterName", ""); } + + public void SetNewsDownloadProgress(int newsDownloadProgress) + { + SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("newsDownloadProgress", newsDownloadProgress); + editor.commit(); + } + + public int GetNewsDownloadProgress() + { + SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); + return settings.getInt("newsDownloadProgress", 0); + } + + public void SetDatabaseDownloadProgress(int databaseDownloadProgress) + { + SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("databaseDownloadProgress", databaseDownloadProgress); + editor.commit(); + } + + public int GetDatabaseDownloadProgress() + { + SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); + return settings.getInt("databaseDownloadProgress", 0); + } + + public String DateFormattedForLocale(Date date) + { + return DateUtils.formatDateTime(this, date.getTime(), DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR); + + } + @Override protected void onResume() diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java index d828eed..0b791ff 100644 --- a/android/src/fishrungames/bashgid/MainPageFragment.java +++ b/android/src/fishrungames/bashgid/MainPageFragment.java @@ -2,20 +2,25 @@ package fishrungames.bashgid; import java.util.ArrayList; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.DatabaseGetJournalListTask; import fishrungames.bashgid.core.DatabaseGetJournalTask; import fishrungames.bashgid.core.JournalManager; +import fishrungames.bashgid.core.NewsDownloadTask; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnKeyListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; @@ -34,10 +39,11 @@ public class MainPageFragment extends Fragment ListView listView; ListAdapter listAdapter; View header; - ProgressBar progressBar; + ProgressBar newsDownloadProgressBar; + ProgressBar databaseDownloadProgressBar; EditText searchEditText; - JournalSemiFullData newsJournal; + JournalSemiFullData newsJournal = JournalManager.CreateEmptyJournalSemiFull(); DatabaseGetJournalTask databaseGetJournalTask = null; DatabaseGetJournalListTask databaseGetJournalListTask = null; @@ -51,10 +57,6 @@ public class MainPageFragment extends Fragment 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); @@ -63,16 +65,21 @@ public class MainPageFragment extends Fragment header = inflater.inflate(R.layout.main_page_header, null); - RestoreJournal(); - MainActivity.getInstance().StartDownloadNewsTask(); - listView.addHeaderView(header); listView.setAdapter(listAdapter); - progressBar = (ProgressBar) header.findViewById(R.id.progressBar); + newsDownloadProgressBar = (ProgressBar) header.findViewById(R.id.newsDownloadProgressBar); - progressBar.setVisibility(View.VISIBLE); + newsDownloadProgressBar.setVisibility(View.VISIBLE); + + newsDownloadProgressBar.setProgress(MainActivity.getInstance().GetNewsDownloadProgress()); + + databaseDownloadProgressBar = (ProgressBar) header.findViewById(R.id.databaseDownloadProgressBar); + + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + + databaseDownloadProgressBar.setProgress(MainActivity.getInstance().GetDatabaseDownloadProgress()); Button moreNewsButton = (Button) header.findViewById(R.id.moreNewsButton); @@ -100,12 +107,67 @@ public class MainPageFragment extends Fragment MainActivity.getInstance().OpenSearchScreen(query); } }); + + searchEditText.setOnKeyListener(new OnKeyListener() { + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) + { + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + String query = searchEditText.getText().toString(); + MainActivity.getInstance().OpenSearchScreen(query); + return true; + } + return false; + } + }); + + ImageButton refreshCatalogButton = (ImageButton) header.findViewById(R.id.refreshCatalogButton); + refreshCatalogButton.setOnClickListener(new OnClickListener() + { + + @Override + public void onClick(View v) + { + MainActivity.getInstance().CancelDownloadDatabaseTask(); + MainActivity.getInstance().DownloadDatabase(); + } + }); + + ImageButton refreshNewsButton = (ImageButton) header.findViewById(R.id.refreshNewsButton); + + refreshNewsButton.setOnClickListener(new OnClickListener() + { + + @Override + public void onClick(View v) + { + MainActivity.getInstance().CancelDownloadNewsTask(); + MainActivity.getInstance().StartDownloadNewsTask(); + } + }); + + + RestoreJournalListFromDatabase(); + RestoreNewsFromDatabase(); + MainActivity.getInstance().StartDownloadNewsTask(); + MainActivity.getInstance().DownloadDatabase(); + return rootView; } @Override public void onDestroyView() + { + CancelRestoreNewsTaskIfRunning(); + CancelRestoreJournalListTasksIfRunning(); + + super.onDestroyView(); + } + + public void CancelRestoreNewsTaskIfRunning() { if (databaseGetJournalTask != null) { @@ -113,32 +175,24 @@ public class MainPageFragment extends Fragment databaseGetJournalTask = null; } + } + + public void CancelRestoreJournalListTasksIfRunning() + { if (databaseGetJournalListTask != null) { databaseGetJournalListTask.cancel(false); databaseGetJournalListTask = null; } - - super.onDestroyView(); } - - void RestoreJournal() + + public void RestoreNewsFromDatabase() { - newsJournal = JournalManager.CreateEmptyJournal(); - - RefreshJournal(); - } - - void RefreshJournal() - { - if (databaseGetJournalTask != null) - { - databaseGetJournalTask.cancel(false); - } + CancelRestoreNewsTaskIfRunning(); databaseGetJournalTask = new DatabaseGetJournalTask(); - databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; + //databaseGetJournalTask.mHandler = MainActivity.getInstance().databaseHandler; Bundle bundle = new Bundle(); @@ -146,101 +200,140 @@ public class MainPageFragment extends Fragment bundle.putInt("count", 3); - databaseGetJournalTask.execute(bundle); + databaseGetJournalTask .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); + } + + public void OnNewsDownloadProgress(Integer percent) + { + + newsDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + newsDownloadProgressBar.setVisibility(View.GONE); + } + else + { + newsDownloadProgressBar.setVisibility(View.VISIBLE); + } + + if (databaseGetJournalTask == null || percent == 100) + { + RestoreNewsFromDatabase(); + } + + //RestoreNewsFromDatabase(); + + //SetJournal(r.journal); + + } + + public void OnDatabaseDonwloadProgress(Integer percent) + { + databaseDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + databaseDownloadProgressBar.setVisibility(View.GONE); + } + else + { + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + } + + if (databaseGetJournalListTask == null || percent == 100) + { + RestoreJournalListFromDatabase(); + } + + //SetJournalList(r.journalList); + } + + + void RestoreJournalListFromDatabase() + { + + CancelRestoreJournalListTasksIfRunning(); + + + databaseGetJournalListTask = new DatabaseGetJournalListTask(); + + //databaseGetJournalListTask.mHandler = MainActivity.getInstance().databaseHandler; + + databaseGetJournalListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "featured"); + } public void SetJournal(JournalSemiFullData journal) { - databaseGetJournalTask = null; + CancelRestoreNewsTaskIfRunning(); - // Xperimental - if (journal != null) + newsJournal = journal; + + Button news1Button = (Button) header.findViewById(R.id.news1Button); + Button news2Button = (Button) header.findViewById(R.id.news2Button); + Button news3Button = (Button) header.findViewById(R.id.news3Button); + + if (newsJournal.articleArr.size() > 0) { - progressBar.setVisibility(View.GONE); - newsJournal = journal; + news1Button.setText(newsJournal.articleArr.get(0).title); - Button news1Button = (Button) header.findViewById(R.id.news1Button); - Button news2Button = (Button) header.findViewById(R.id.news2Button); - Button news3Button = (Button) header.findViewById(R.id.news3Button); + news1Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name)); + } else + { - if (newsJournal.articleArr.size() > 0) - { - - news1Button.setText(newsJournal.articleArr.get(0).title); - - news1Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name)); - } else - { - - news1Button.setText(R.string.news_record_not_available); - - news1Button.setOnClickListener(null); - } - - if (newsJournal.articleArr.size() > 1) - { - - news2Button.setText(newsJournal.articleArr.get(1).title); - - news2Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name)); - } else - { - - news2Button.setText(R.string.news_record_not_available); - news2Button.setOnClickListener(null); - } - - if (newsJournal.articleArr.size() > 2) - { - - news3Button.setText(newsJournal.articleArr.get(2).title); - news3Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name)); - } else - { - - news3Button.setText(R.string.news_record_not_available); - news3Button.setOnClickListener(null); - } - - listAdapter.notifyDataSetChanged(); + news1Button.setText(R.string.news_record_not_available); + news1Button.setOnClickListener(null); } - } + if (newsJournal.articleArr.size() > 1) + { + + news2Button.setText(newsJournal.articleArr.get(1).title); + + news2Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name)); + } else + { + + news2Button.setText(R.string.news_record_not_available); + news2Button.setOnClickListener(null); + } + + if (newsJournal.articleArr.size() > 2) + { + + news3Button.setText(newsJournal.articleArr.get(2).title); + news3Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name)); + } else + { + + news3Button.setText(R.string.news_record_not_available); + news3Button.setOnClickListener(null); + } - 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 void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } + public class ListAdapter extends BaseAdapter { private Context mContext; @@ -356,7 +449,7 @@ public class MainPageFragment extends Fragment databaseGetJournalTask.cancel(false); databaseGetJournalTask = null; } - + MainActivity.getInstance().OpenArticleScreen(articleName, MainActivity.TAG_BACK_TO_MAINFRAGMENT); } diff --git a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java index 140d5ab..f0887af 100644 --- a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java +++ b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java @@ -64,13 +64,17 @@ public class MainPageHListViewAdapters } ImageView imageView = (ImageView) view.findViewById(R.id.imageView); - - ImageManager.getInstance().ApplyImageToImageView(imageView, albumFullData.photoRecordArr.get(position).imageUrl); + + //ImageManager.getInstance().ApplyImageToImageView(imageView, albumFullData.photoRecordArr.get(position).imageUrl); + ImageManager.getInstance().ApplySmallImageToImageView(imageView, albumFullData.photoRecordArr.get(position).imageUrl); return view; } } + + + public static class JournalElementAdapter extends BaseAdapter { @@ -125,11 +129,12 @@ public class MainPageHListViewAdapters textView.setText(journal.articleArr.get(position).title); - subTextView.setText(journal.articleArr.get(position).dateTime.toString()); + subTextView.setText(MainActivity.getInstance().DateFormattedForLocale(journal.articleArr.get(position).dateTime)); String imageUrl = journal.articleArr.get(position).previewImageUrl; - ImageManager.getInstance().ApplyImageToImageView(imageButton, imageUrl); + //ImageManager.getInstance().ApplyImageToImageView(imageButton, imageUrl); + ImageManager.getInstance().ApplySmallImageToImageView(imageButton, imageUrl); imageButton.setOnClickListener(new OnClickListener() { diff --git a/android/src/fishrungames/bashgid/NewsListFragment.java b/android/src/fishrungames/bashgid/NewsListFragment.java index 2c92d56..d4eb010 100644 --- a/android/src/fishrungames/bashgid/NewsListFragment.java +++ b/android/src/fishrungames/bashgid/NewsListFragment.java @@ -9,20 +9,24 @@ import fishrungames.bashgid.core.ArticleManager; import fishrungames.bashgid.core.ArticleManager.ArticleShortData; import fishrungames.bashgid.core.DatabaseGetJournalTask; import fishrungames.bashgid.core.JournalManager; +import fishrungames.bashgid.core.NewsDownloadTask; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnClickListener; import android.widget.BaseAdapter; import android.widget.AdapterView; +import android.widget.ImageButton; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; @@ -35,9 +39,9 @@ public class NewsListFragment extends Fragment ListAdapter listAdapter; - JournalSemiFullData journal; + JournalSemiFullData journal = JournalManager.CreateEmptyJournalSemiFull(); - ProgressBar progressBar; + ProgressBar newsDownloadProgressBar; TextView footerTextView; @@ -48,8 +52,6 @@ public class NewsListFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - RestoreJournal(); - View rootView = inflater.inflate(R.layout.fragment_news_page, container, false); listView = (ListView) rootView.findViewById(R.id.listView); @@ -58,15 +60,19 @@ public class NewsListFragment extends Fragment listView.addHeaderView(header); - progressBar = (ProgressBar) header.findViewById(R.id.progressBar); + newsDownloadProgressBar = (ProgressBar) header.findViewById(R.id.newsDownloadProgressBar); - progressBar.setVisibility(View.VISIBLE); + newsDownloadProgressBar.setVisibility(View.VISIBLE); + + newsDownloadProgressBar.setProgress(MainActivity.getInstance().GetNewsDownloadProgress()); View footer = inflater.inflate(R.layout.news_page_list_footer, null); listView.addFooterView(footer); footerTextView = (TextView) footer.findViewById(R.id.footerTextView); + + footerTextView.setVisibility(View.GONE); listAdapter = new ListAdapter(getActivity()); @@ -92,6 +98,22 @@ public class NewsListFragment extends Fragment } }); + + ImageButton refreshNewsButton = (ImageButton) header.findViewById(R.id.refreshNewsButton); + + refreshNewsButton.setOnClickListener(new OnClickListener() + { + + @Override + public void onClick(View v) + { + MainActivity.getInstance().CancelDownloadNewsTask(); + MainActivity.getInstance().StartDownloadNewsTask(); + } + }); + + RestoreNewsFromDatabase(); + MainActivity.getInstance().StartDownloadNewsTask(); return rootView; } @@ -99,12 +121,7 @@ public class NewsListFragment extends Fragment @Override public void onDestroyView() { - - if (databaseGetJournalTask != null) - { - databaseGetJournalTask.cancel(false); - databaseGetJournalTask = null; - } + CancelTaskIfRunning(); super.onDestroyView(); } @@ -113,19 +130,35 @@ public class NewsListFragment extends Fragment { listAdapter.notifyDataSetChanged(); } - - void RestoreJournal() + + public void OnNewsDownloadProgress(Integer percent) { - journal = JournalManager.CreateEmptyJournal(); - - RefreshJournal(); + + newsDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + newsDownloadProgressBar.setVisibility(View.GONE); + } + else + { + newsDownloadProgressBar.setVisibility(View.VISIBLE); + } + + if (databaseGetJournalTask == null || percent == 100) + { + RestoreNewsFromDatabase(); + } + } - void RefreshJournal() + public void RestoreNewsFromDatabase() { + CancelTaskIfRunning(); + databaseGetJournalTask = new DatabaseGetJournalTask(); - databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; + //databaseGetJournalTask.mHandler = MainActivity.getInstance().databaseHandler; Bundle bundle = new Bundle(); @@ -133,19 +166,16 @@ public class NewsListFragment extends Fragment bundle.putInt("count", 20); - databaseGetJournalTask.execute(bundle); + databaseGetJournalTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); } - + void LoadMoreNews() - { - if (databaseGetJournalTask != null) - { - databaseGetJournalTask.cancel(false); - } + { + CancelTaskIfRunning(); databaseGetJournalTask = new DatabaseGetJournalTask(); - databaseGetJournalTask.mHandler = MainActivity.getInstance().mHandler; + //databaseGetJournalTask.mHandler = MainActivity.getInstance().databaseHandler; Bundle bundle = new Bundle(); @@ -155,12 +185,13 @@ public class NewsListFragment extends Fragment bundle.putInt("count", 10); - databaseGetJournalTask.execute(bundle); + databaseGetJournalTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); } public void SetJournal(JournalSemiFullData journal) { - progressBar.setVisibility(View.GONE); + databaseGetJournalTask = null; + this.journal.articleArr.addAll(journal.articleArr); @@ -171,11 +202,22 @@ public class NewsListFragment extends Fragment Collections.sort(this.journal.articleArr, new ArticleManager.ArticleShortDataTimeSortComparator()); + footerTextView.setVisibility(View.VISIBLE); + footerTextView.setText(R.string.news_load_more); listAdapter.notifyDataSetChanged(); } + + public void CancelTaskIfRunning() + { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + } public class ListAdapter extends BaseAdapter { diff --git a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java index 352139f..f822cfa 100644 --- a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java +++ b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java @@ -2,6 +2,7 @@ package fishrungames.bashgid; import java.util.ArrayList; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -9,6 +10,7 @@ import android.content.Intent; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -102,7 +104,7 @@ public class OsmMapHolderFragment extends Fragment DetailsOverlayItem item = new DetailsOverlayItem(title, imageUrl, geoPoint, address, phone); item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default)); - item.setMarkerHotspot(HotspotPlace.CENTER); + item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER); mOverlayItems.add(item); mArticles.add(articleName); @@ -122,6 +124,7 @@ public class OsmMapHolderFragment extends Fragment return false; } + @SuppressLint("InflateParams") @Override protected boolean onTap(final int index) { @@ -154,6 +157,7 @@ public class OsmMapHolderFragment extends Fragment textView.setOnLongClickListener(new OnLongClickListener() { + @SuppressWarnings("deprecation") @Override public boolean onLongClick(View v) { @@ -270,7 +274,7 @@ public class OsmMapHolderFragment extends Fragment OverlayItem item = new OverlayItem("", "", geoPoint); item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default)); - item.setMarkerHotspot(HotspotPlace.CENTER); + item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER); mOverlayItems.add(item); @@ -292,43 +296,34 @@ public class OsmMapHolderFragment extends Fragment CustomItemizedOverlay itemizedOverlay; - String filter; + String filter = ""; - ArrayList availableGeoJournals; - ArrayList availableGeoJournalNames; + ArrayList availableGeoJournals = new ArrayList(); + ArrayList availableGeoJournalNames = new ArrayList(); ArrayAdapter spinnerAdapter; - JournalSemiFullData journal; - ArticleFullData article; + JournalSemiFullData journal = null; + ArticleFullData article = null; - int filterType; + int filterType = 0; Spinner spinner; MapView mapView; TextView titleTextView; + DatabaseGetArticleTask databaseGetArticleTask = null; + DatabaseGetJournalTask databaseGetJournalTask = null; + DatabaseGetGeoJournalListTask databaseGetGeoJournalListTask = null; + public OsmMapHolderFragment() { - journal = null; - article = null; - filter = ""; - filterType = 0; - availableGeoJournals = new ArrayList(); - availableGeoJournalNames = new ArrayList(); - } public OsmMapHolderFragment(int filterType, String filter) { - this.journal = null; - this.article = null; this.filter = filter; this.filterType = filterType; - - availableGeoJournals = new ArrayList(); - availableGeoJournalNames = new ArrayList(); - } public OsmMapHolderFragment(ArticleFullData article) @@ -338,10 +333,6 @@ public class OsmMapHolderFragment extends Fragment this.article = article; this.journal = null; - - availableGeoJournals = new ArrayList(); - availableGeoJournalNames = new ArrayList(); - } @Override @@ -356,12 +347,6 @@ public class OsmMapHolderFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) - { - filter = savedInstanceState.getString("filter"); - filterType = savedInstanceState.getInt("filterType"); - } - View rootView = inflater.inflate(R.layout.fragment_osm_map_page, container, false); titleTextView = (TextView) rootView.findViewById(R.id.titleTextView); @@ -381,8 +366,6 @@ public class OsmMapHolderFragment extends Fragment mapController.setZoom(10); mapController.animateTo(center); - RefreshView(); - spinnerAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, availableGeoJournalNames); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); @@ -406,7 +389,7 @@ public class OsmMapHolderFragment extends Fragment filterType = 0; filter = availableGeoJournals.get(position).name; titleTextView.setText(R.string.map_is_loading); - RestoreJournalOrArticle(); + RestoreJournal(); } } @@ -419,13 +402,28 @@ public class OsmMapHolderFragment extends Fragment }); - if ((filterType == 0 && journal == null) || (filterType == 1 && article == null)) + RefreshView(); + + if (savedInstanceState != null) + { + filter = savedInstanceState.getString("filter"); + filterType = savedInstanceState.getInt("filterType"); + } + + if (filterType == 0 && journal == null) { titleTextView.setText(R.string.map_is_loading); - RestoreJournalOrArticle(); + RestoreJournal(); - } else + } else if (filterType == 1 && article == null) + { + titleTextView.setText(R.string.map_is_loading); + + RestoreArticle(); + + } + else { titleTextView.setText(R.string.map_is_loaded); RestoreGeoJournals(); @@ -434,29 +432,29 @@ public class OsmMapHolderFragment extends Fragment return rootView; } - void RestoreJournalOrArticle() + @Override + public void onDestroyView() { - if (filterType == 0) - { - RestoreJournal(); - } else - { - RestoreArticle(); - } + CancelRestoreArticleTaskIfRunning(); + CancelRestoreJournalTaskIfRunning(); + CancelRestoreGeoJournalListTasksIfRunning(); + + super.onDestroyView(); } void RestoreJournal() { + CancelRestoreJournalTaskIfRunning(); - DatabaseGetJournalTask task = new DatabaseGetJournalTask(); + databaseGetJournalTask = new DatabaseGetJournalTask(); - task.mHandler = MainActivity.getInstance().mHandler; + //databaseGetJournalTask.mHandler = MainActivity.getInstance().mainHandler; Bundle bundle = new Bundle(); bundle.putString("journalName", filter); - task.execute(bundle); + databaseGetJournalTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); availableGeoJournals.clear(); availableGeoJournalNames.clear(); @@ -466,12 +464,13 @@ public class OsmMapHolderFragment extends Fragment void RestoreArticle() { + CancelRestoreArticleTaskIfRunning(); - DatabaseGetArticleTask task = new DatabaseGetArticleTask(); + databaseGetArticleTask = new DatabaseGetArticleTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetArticleTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(filter); + databaseGetArticleTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, filter); availableGeoJournals.clear(); availableGeoJournalNames.clear(); @@ -481,17 +480,49 @@ public class OsmMapHolderFragment extends Fragment void RestoreGeoJournals() { + CancelRestoreGeoJournalListTasksIfRunning(); - DatabaseGetGeoJournalListTask task = new DatabaseGetGeoJournalListTask(); + databaseGetGeoJournalListTask = new DatabaseGetGeoJournalListTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetGeoJournalListTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(); + databaseGetGeoJournalListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + public void CancelRestoreArticleTaskIfRunning() + { + if (databaseGetArticleTask != null) + { + databaseGetArticleTask.cancel(false); + databaseGetArticleTask = null; + } + + } + + public void CancelRestoreJournalTaskIfRunning() + { + if (databaseGetJournalTask != null) + { + databaseGetJournalTask.cancel(false); + databaseGetJournalTask = null; + } + + } + + public void CancelRestoreGeoJournalListTasksIfRunning() + { + if (databaseGetGeoJournalListTask != null) + { + databaseGetGeoJournalListTask.cancel(false); + databaseGetGeoJournalListTask = null; + } + } + public void SetJournal(JournalSemiFullData journal) { + databaseGetJournalTask = null; + filterType = 0; titleTextView.setText(R.string.map_is_loaded); @@ -506,6 +537,8 @@ public class OsmMapHolderFragment extends Fragment public void SetArticle(ArticleFullData article) { + databaseGetArticleTask = null; + filterType = 1; titleTextView.setText(R.string.map_is_loaded); @@ -521,6 +554,8 @@ public class OsmMapHolderFragment extends Fragment public void SetGeoJournals(ArrayList availableGeoJournals) { + databaseGetGeoJournalListTask = null; + this.availableGeoJournals = availableGeoJournals; availableGeoJournalNames.clear(); diff --git a/android/src/fishrungames/bashgid/PhotoAlbumFragment.java b/android/src/fishrungames/bashgid/PhotoAlbumFragment.java index 65ae3d1..9958820 100644 --- a/android/src/fishrungames/bashgid/PhotoAlbumFragment.java +++ b/android/src/fishrungames/bashgid/PhotoAlbumFragment.java @@ -3,6 +3,7 @@ package fishrungames.bashgid; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -25,17 +26,17 @@ import fishrungames.networkutils.ImageManager; public class PhotoAlbumFragment extends Fragment { - AlbumFullData album; - String albumName; + AlbumFullData album = AlbumManager.CreateEmptyAlbum(); + String albumName = ""; ListAdapter listAdapter; ProgressBar progressBar; + DatabaseGetAlbumTask databaseGetAlbumTask = null; + public PhotoAlbumFragment() { - album = null; - albumName = ""; } public PhotoAlbumFragment(AlbumFullData album) @@ -60,11 +61,7 @@ public class PhotoAlbumFragment extends Fragment @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) { - albumName = savedInstanceState.getString("albumName"); - RestoreAlbum(); - } - + View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false); progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar); @@ -89,22 +86,63 @@ public class PhotoAlbumFragment extends Fragment }); + if (savedInstanceState != null) + { + albumName = savedInstanceState.getString("albumName"); + } + + if (albumName.length() > 0 && album.photoRecordArr.size() == 0) + { + RestoreAlbum(); + } + return rootView; } + @Override + public void onDestroyView() + { + CancelTaskIfRunning(); + + super.onDestroyView(); + } + + public void OnDatabaseDonwloadProgress(Integer percent) + { + /* + databaseDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + databaseDownloadProgressBar.setVisibility(View.GONE); + } + else + { + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + } + */ + if (databaseGetAlbumTask == null || percent == 100) + { + RestoreAlbum(); + } + + //SetJournalList(r.journalList); + } + + void RestoreAlbum() { - album = AlbumManager.CreateEmptyAlbum(); - - DatabaseGetAlbumTask task = new DatabaseGetAlbumTask(); + databaseGetAlbumTask = new DatabaseGetAlbumTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(albumName); + databaseGetAlbumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, albumName); } public void SetAlbum(AlbumFullData album) { + databaseGetAlbumTask = null; + progressBar.setVisibility(View.GONE); this.album = album; @@ -113,6 +151,23 @@ public class PhotoAlbumFragment extends Fragment } + public void CancelTaskIfRunning() + { + if (databaseGetAlbumTask != null) + { + databaseGetAlbumTask.cancel(false); + databaseGetAlbumTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } + public class ListAdapter extends BaseAdapter { private Context mContext; @@ -149,7 +204,15 @@ public class PhotoAlbumFragment extends Fragment ImageView imageView = (ImageView) view.findViewById(R.id.imageView); - ImageManager.getInstance().ApplyImageToImageView(imageView, album.photoRecordArr.get(position).imageUrl); + + if (album.photoRecordArr.get(position) != null) + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, album.photoRecordArr.get(position).imageUrl); + } + else + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, "R.drawable.no_picture"); + } return view; } diff --git a/android/src/fishrungames/bashgid/PhotoFragment.java b/android/src/fishrungames/bashgid/PhotoFragment.java index 08ab638..bf9ba64 100644 --- a/android/src/fishrungames/bashgid/PhotoFragment.java +++ b/android/src/fishrungames/bashgid/PhotoFragment.java @@ -1,7 +1,6 @@ package fishrungames.bashgid; - - +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -17,105 +16,134 @@ import fishrungames.bashgid.core.DatabaseGetAlbumTask; public class PhotoFragment extends Fragment { - - AlbumFullData album; - String albumName; - int currentPhoto; - + + AlbumFullData album = AlbumManager.CreateEmptyAlbum(); + String albumName = ""; + int currentPhoto = -1; + PhotoFragmentAdapter listAdapter; ViewPager pager; - + ProgressBar progressBar; + DatabaseGetAlbumTask databaseGetAlbumTask = null; + public PhotoFragment() { - album = null; - albumName = ""; - currentPhoto = -1; } - + public PhotoFragment(AlbumFullData album, int currentPhoto) { this.album = album; this.albumName = album.name; this.currentPhoto = currentPhoto; } - + public PhotoFragment(String albumName, int currentPhoto) { - this.album = null; this.albumName = albumName; this.currentPhoto = currentPhoto; - RestoreAlbum(); } - + @Override - public void onSaveInstanceState(final Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString("albumName", albumName); - outState.putInt("currentPhoto", currentPhoto); - - } - - + public void onSaveInstanceState(final Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putString("albumName", albumName); + outState.putInt("currentPhoto", currentPhoto); + } + @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - if (savedInstanceState != null) { - albumName = savedInstanceState.getString("albumName"); - currentPhoto = savedInstanceState.getInt("currentPhoto"); - RestoreAlbum(); - } - + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + { + View rootView = inflater.inflate(R.layout.fragment_photo_page, container, false); - - progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar); - + + progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); + if (album == null) { - progressBar.setVisibility(View.VISIBLE); - } - else + progressBar.setVisibility(View.VISIBLE); + } else { progressBar.setVisibility(View.GONE); } listAdapter = new PhotoFragmentAdapter(getActivity(), album); - + pager = (ViewPager) rootView.findViewById(R.id.pager); - + pager.setAdapter(listAdapter); - + pager.setCurrentItem(currentPhoto); + + if (savedInstanceState != null) + { + albumName = savedInstanceState.getString("albumName"); + currentPhoto = savedInstanceState.getInt("currentPhoto"); + } + + if (album.photoRecordArr.size() == 0 && albumName.length() > 0) + { + RestoreAlbum(); + } + return rootView; } + @Override + public void onDestroyView() + { + CancelTaskIfRunning(); + + super.onDestroyView(); + } + void RestoreAlbum() { - album = AlbumManager.CreateEmptyAlbum(); - - DatabaseGetAlbumTask task = new DatabaseGetAlbumTask(); + databaseGetAlbumTask = new DatabaseGetAlbumTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(albumName); + databaseGetAlbumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, albumName); } - + public void SetAlbum(AlbumFullData album) { + databaseGetAlbumTask = null; + progressBar.setVisibility(View.GONE); this.album = album; - + listAdapter.album = album; - + listAdapter.notifyDataSetChanged(); + if (currentPhoto < 0) + { + currentPhoto = 0; + } + pager.setCurrentItem(currentPhoto); } + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } - - + public void CancelTaskIfRunning() + { + if (databaseGetAlbumTask != null) + { + databaseGetAlbumTask.cancel(false); + databaseGetAlbumTask = null; + } + } + } \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java b/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java index ca32be7..09e6b7a 100644 --- a/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java +++ b/android/src/fishrungames/bashgid/PhotoFragmentAdapter.java @@ -59,7 +59,16 @@ public class PhotoFragmentAdapter extends PagerAdapter { ImageView image = (ImageView) viewLayout.findViewById(R.id.image); - ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl); + //ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl); + + if (album.photoRecordArr.get(position) != null) + { + ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl); + } + else + { + ImageManager.getInstance().ApplyImageToImageView(image, "R.drawable.no_picture"); + } ((ViewPager) container).addView(viewLayout); diff --git a/android/src/fishrungames/bashgid/SearchFragment.java b/android/src/fishrungames/bashgid/SearchFragment.java index 0f53167..9ec37d2 100644 --- a/android/src/fishrungames/bashgid/SearchFragment.java +++ b/android/src/fishrungames/bashgid/SearchFragment.java @@ -11,14 +11,17 @@ import fishrungames.networkutils.ImageManager; import android.annotation.SuppressLint; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.TextWatcher; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnKeyListener; import android.widget.AdapterView; import android.widget.BaseAdapter; @@ -42,24 +45,18 @@ public class SearchFragment extends Fragment ArrayList searchResultArr = new ArrayList(); - String journalName; - String journalTitle; - String query; + String journalName = ""; + String journalTitle = ""; + String query = ""; DatabaseSearchArticleTask databaseSearchArticleTask = null; public SearchFragment() { - this.journalName = ""; - this.journalTitle = ""; - this.query = ""; } public SearchFragment(String query) { - this.journalName = ""; - this.journalTitle = ""; - this.journalTitle = ""; this.query = query; } @@ -91,32 +88,30 @@ public class SearchFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) - { - journalName = savedInstanceState.getString("journalName"); - journalTitle = savedInstanceState.getString("journalTitle"); - query = savedInstanceState.getString("query"); - - } - View rootView = inflater.inflate(R.layout.fragment_search_page, container, false); listView = (ListView) rootView.findViewById(R.id.listView); View header = inflater.inflate(R.layout.search_page_list_header, null); - TextView addressTextView = (TextView) header.findViewById(R.id.addressTextView); + TextView titleTextView = (TextView) header.findViewById(R.id.titleTextView); + + TextView smallHintTextView = (TextView) header.findViewById(R.id.smallHintTextView); if (journalTitle == null || journalTitle.length() == 0) { - addressTextView.setText(R.string.search_everywhere); + titleTextView.setText(R.string.search_everywhere); + + smallHintTextView.setVisibility(View.GONE); } else { String search_in = this.getResources().getString(R.string.search_in); search_in = search_in.replace("%%", journalTitle); - addressTextView.setText(search_in); + titleTextView.setText(search_in); + + smallHintTextView.setVisibility(View.VISIBLE); } hintTextView = (TextView) header.findViewById(R.id.hintTextView); @@ -124,6 +119,9 @@ public class SearchFragment extends Fragment searchEditText = (EditText) header.findViewById(R.id.editText); searchEditText.setText(query); + + int textLength = searchEditText.getText().length(); + searchEditText.setSelection(textLength, textLength); searchEditText.addTextChangedListener(new TextWatcher() { @@ -145,6 +143,19 @@ public class SearchFragment extends Fragment { } }); + + searchEditText.setOnKeyListener(new OnKeyListener() { + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) + { + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + return true; + } + return false; + } + }); listView.addHeaderView(header); @@ -166,14 +177,60 @@ public class SearchFragment extends Fragment MainActivity.getInstance().OpenArticleScreen(searchResultArr.get(position - 1).name, MainActivity.TAG_BACK_TO_SEARCHFRAGMENT); } }); + + if (savedInstanceState != null) + { + journalName = savedInstanceState.getString("journalName"); + journalTitle = savedInstanceState.getString("journalTitle"); + query = savedInstanceState.getString("query"); + + } CallUpdateNews(); return rootView; } + + @Override + public void onDestroyView() + { + CancelTaskIfRunning(); + + super.onDestroyView(); + } + + public void CallUpdateNews() + { + + if (query.length() >= 3 || (Locale.getDefault() == Locale.CHINA && query.length() >= 1)) + { + CancelTaskIfRunning(); + + databaseSearchArticleTask = new DatabaseSearchArticleTask(); + + databaseSearchArticleTask.mHandler = MainActivity.getInstance().mainHandler; + + Bundle bundle = new Bundle(); + + bundle.putString("journalName", journalName); + bundle.putString("query", query); + + databaseSearchArticleTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bundle); + + hintTextView.setText(R.string.search_is_performing); + } else + { + searchResultArr.clear(); + listAdapter.notifyDataSetChanged(); + + hintTextView.setText(R.string.search_at_least_3_symbols); + } + } public void SetSearchResult(ArrayList articleArr) { + databaseSearchArticleTask = null; + searchResultArr = articleArr; listAdapter.notifyDataSetChanged(); @@ -183,6 +240,24 @@ public class SearchFragment extends Fragment hintTextView.setText(searchResultCount); } + + public void CancelTaskIfRunning() + { + if (databaseSearchArticleTask != null) + { + databaseSearchArticleTask.cancel(false); + databaseSearchArticleTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } + public class ListAdapter extends BaseAdapter { @@ -246,35 +321,6 @@ public class SearchFragment extends Fragment } - public void CallUpdateNews() - { - - if (query.length() >= 3 || Locale.getDefault() == Locale.CHINA) - { - if (databaseSearchArticleTask != null) - { - databaseSearchArticleTask.cancel(false); - } - - databaseSearchArticleTask = new DatabaseSearchArticleTask(); - - databaseSearchArticleTask.mHandler = MainActivity.getInstance().mHandler; - - Bundle bundle = new Bundle(); - - bundle.putString("journalName", journalName); - bundle.putString("query", query); - - databaseSearchArticleTask.execute(bundle); - - hintTextView.setText(R.string.search_is_performing); - } else - { - searchResultArr.clear(); - listAdapter.notifyDataSetChanged(); - - hintTextView.setText(R.string.search_at_least_3_symbols); - } - } + } diff --git a/android/src/fishrungames/bashgid/SettingsFragment.java b/android/src/fishrungames/bashgid/SettingsFragment.java index ecdffab..99127da 100644 --- a/android/src/fishrungames/bashgid/SettingsFragment.java +++ b/android/src/fishrungames/bashgid/SettingsFragment.java @@ -68,8 +68,9 @@ public class SettingsFragment extends Fragment @Override public void onClick(View v) { + String link = getResources().getString(R.string.littlefoxlilia_link); Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("http://littlefoxlilia.ru/")); + i.setData(Uri.parse(link)); startActivity(i); } }); diff --git a/android/src/fishrungames/bashgid/SquareImageView.java b/android/src/fishrungames/bashgid/SquareImageView.java new file mode 100644 index 0000000..dc8bce6 --- /dev/null +++ b/android/src/fishrungames/bashgid/SquareImageView.java @@ -0,0 +1,37 @@ +package fishrungames.bashgid; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ImageView; + +public class SquareImageView extends ImageView { + +public SquareImageView(final Context context) { + super(context); +} + +public SquareImageView(final Context context, final AttributeSet attrs) { + super(context, attrs); +} + +public SquareImageView(final Context context, final AttributeSet attrs, + final int defStyle) { + super(context, attrs, defStyle); +} + +@Override +protected void onMeasure(int width, int height) { + super.onMeasure(width, height); + int measuredWidth = getMeasuredWidth(); + //int measuredHeight = getMeasuredHeight(); + + setMeasuredDimension(measuredWidth, measuredWidth); + + /*if (measuredWidth > measuredHeight) { + setMeasuredDimension(measuredHeight, measuredHeight); + } else { + setMeasuredDimension(measuredWidth, measuredWidth); + }*/ +} + +} \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/StaticGridView.java b/android/src/fishrungames/bashgid/StaticGridView.java new file mode 100644 index 0000000..695a072 --- /dev/null +++ b/android/src/fishrungames/bashgid/StaticGridView.java @@ -0,0 +1,50 @@ +package fishrungames.bashgid; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.GridView; + +public class StaticGridView extends GridView { + + public StaticGridView(Context context) { + super(context); + } + + public StaticGridView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public StaticGridView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + + //super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST)); + //getLayoutParams().height = getMeasuredHeight(); + + + /*int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, + MeasureSpec.AT_MOST); + super.onMeasure(widthMeasureSpec, expandSpec);*/ + + + //super.onMeasure(widthMeasureSpec, MeasureSpec.UNSPECIFIED); + + + int heightSpec; + + if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { + + heightSpec = MeasureSpec.makeMeasureSpec( + Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); + } + else { + // Any other height should be respected as is. + heightSpec = heightMeasureSpec; + } + + super.onMeasure(widthMeasureSpec, heightSpec); + } +} \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/VideoListFragment.java b/android/src/fishrungames/bashgid/VideoListFragment.java index 3fd82b3..137f4d0 100644 --- a/android/src/fishrungames/bashgid/VideoListFragment.java +++ b/android/src/fishrungames/bashgid/VideoListFragment.java @@ -35,13 +35,13 @@ public class VideoListFragment extends Fragment GridView gridView; ProgressBar progressBar; - String channelName; - ChannelFullData channelFullData; + String channelName = ""; + ChannelFullData channelFullData = ChannelManager.CreateEmptyChannel(); + + DatabaseGetChannelTask databaseGetChannelTask = null; public VideoListFragment() { - channelName = ""; - channelFullData = null; } public VideoListFragment(String channelName) @@ -65,13 +65,7 @@ public class VideoListFragment extends Fragment @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - if (savedInstanceState != null) { - channelName = savedInstanceState.getString("channelName"); - RestoreChannel(); - } - - View rootView = inflater.inflate(R.layout.fragment_video_page, container, false); + View rootView = inflater.inflate(R.layout.fragment_grid_page, container, false); progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar); @@ -97,29 +91,88 @@ public class VideoListFragment extends Fragment } }); + + if (savedInstanceState != null) { + channelName = savedInstanceState.getString("channelName"); + + } + + if (channelName.length() > 0 && channelFullData.videoRecordArr.size() == 0) + { + RestoreChannel(); + } return rootView; } + @Override + public void onDestroyView() + { + CancelTaskIfRunning(); + + super.onDestroyView(); + } + + public void OnDatabaseDonwloadProgress(Integer percent) + { + /* + databaseDownloadProgressBar.setProgress(percent); + + if (percent >= 100) + { + databaseDownloadProgressBar.setVisibility(View.GONE); + } + else + { + databaseDownloadProgressBar.setVisibility(View.VISIBLE); + } + */ + if (databaseGetChannelTask == null || percent == 100) + { + RestoreChannel(); + } + + //SetJournalList(r.journalList); + } + void RestoreChannel() { - channelFullData = ChannelManager.CreateEmptyChannel(); + CancelTaskIfRunning(); - DatabaseGetChannelTask task = new DatabaseGetChannelTask(); + databaseGetChannelTask = new DatabaseGetChannelTask(); - task.mHandler = MainActivity.getInstance().mHandler; + databaseGetChannelTask.mHandler = MainActivity.getInstance().mainHandler; - task.execute(channelName); + databaseGetChannelTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, channelName); } void SetChannel(ChannelFullData channelFullData) { + databaseGetChannelTask = null; + progressBar.setVisibility(View.GONE); this.channelFullData = channelFullData; + listAdapter.notifyDataSetChanged(); } + public void CancelTaskIfRunning() + { + if (databaseGetChannelTask != null) + { + databaseGetChannelTask.cancel(false); + databaseGetChannelTask = null; + } + } + + public void RefreshAdapter() + { + if (listAdapter != null) + { + listAdapter.notifyDataSetChanged(); + } + } public class DatabaseGetChannelTask extends AsyncTask @@ -182,7 +235,7 @@ public class VideoListFragment extends Fragment View view; if (convertView == null) { // if it's not recycled, initialize some attributes LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.video_page_list_element, null); + view = inflater.inflate(R.layout.grid_page_list_element, null); } else { @@ -192,9 +245,22 @@ public class VideoListFragment extends Fragment ImageView imageView = (ImageView)view.findViewById(R.id.imageView); TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView); - ImageManager.getInstance().ApplyImageToImageView(imageView, channelFullData.videoRecordArr.get(position).previewImageUrl); + //ImageManager.getInstance().ApplyImageToImageView(imageView, channelFullData.videoRecordArr.get(position).previewImageUrl); + + + if (channelFullData.videoRecordArr.get(position) != null) + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, channelFullData.videoRecordArr.get(position).previewImageUrl); - nameTextView.setText(channelFullData.videoRecordArr.get(position).title); + nameTextView.setText(channelFullData.videoRecordArr.get(position).title); + } + else + { + ImageManager.getInstance().ApplySmallImageToImageView(imageView, "R.drawable.no_picture"); + nameTextView.setText(""); + } + + return view; } diff --git a/android/src/fishrungames/bashgid/VideoRecordFragment.java b/android/src/fishrungames/bashgid/VideoRecordFragment.java index 87e36ca..f75384e 100644 --- a/android/src/fishrungames/bashgid/VideoRecordFragment.java +++ b/android/src/fishrungames/bashgid/VideoRecordFragment.java @@ -24,26 +24,24 @@ import android.widget.TextView; public class VideoRecordFragment extends Fragment { - String videoUrl; + String videoUrl = ""; - VideoRecordData recordData; + VideoRecordData recordData = VideoManager.CreateEmptyVideo(); TextView nameTextView; TextView descriptionTextView; ImageView imageView; ProgressBar progressBar; + + DatabaseGetVideoTask databaseGetVideoTask = null; public VideoRecordFragment() { - this.videoUrl = ""; - this.recordData = null; } public VideoRecordFragment(String videoUrl) { - this.recordData = null; this.videoUrl = videoUrl; - RestoreVideo(); } public VideoRecordFragment(VideoRecordData recordData) @@ -63,12 +61,6 @@ public class VideoRecordFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) - { - videoUrl = savedInstanceState.getString("videoUrl"); - RestoreVideo(); - } - View rootView = inflater.inflate(R.layout.fragment_video_record_page, container, false); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); @@ -87,29 +79,57 @@ public class VideoRecordFragment extends Fragment imageView = (ImageView) rootView.findViewById(R.id.imageView); RefreshView(); + + + if (savedInstanceState != null) + { + videoUrl = savedInstanceState.getString("videoUrl"); + } + + if (videoUrl.length() > 0 && recordData.videoUrl.length() == 0) + { + RestoreVideo(); + } return rootView; } + @Override + public void onDestroyView() + { + CancelTaskIfRunning(); + + super.onDestroyView(); + } + void RestoreVideo() { - // recordData = - // MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl); - recordData = VideoManager.CreateEmptyVideo(); + CancelTaskIfRunning(); + + databaseGetVideoTask = new DatabaseGetVideoTask(); - DatabaseGetVideoTask task = new DatabaseGetVideoTask(); - - task.mHandler = MainActivity.getInstance().mHandler; - - task.execute(videoUrl); + databaseGetVideoTask.mHandler = MainActivity.getInstance().mainHandler; + + databaseGetVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, videoUrl); } void SetVideo(VideoRecordData recordData) { + databaseGetVideoTask = null; + progressBar.setVisibility(View.GONE); this.recordData = recordData; RefreshView(); } + + public void CancelTaskIfRunning() + { + if (databaseGetVideoTask != null) + { + databaseGetVideoTask.cancel(false); + databaseGetVideoTask = null; + } + } void RefreshView() { diff --git a/android/src/fishrungames/bashgid/WelcomeFragment.java b/android/src/fishrungames/bashgid/WelcomeFragment.java index 3d18ac6..f764219 100644 --- a/android/src/fishrungames/bashgid/WelcomeFragment.java +++ b/android/src/fishrungames/bashgid/WelcomeFragment.java @@ -21,6 +21,22 @@ public class WelcomeFragment extends Fragment { } @Override + public void onStart() + { + super.onStart(); + + ImageView flagView1 = (ImageView) rootView.findViewById(R.id.image_flag_china); + ImageView flagView2 = (ImageView) rootView.findViewById(R.id.image_flag_russia); + ImageView flagView3 = (ImageView) rootView.findViewById(R.id.image_flag_usa); + + Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.language_flag_in); + flagView1.startAnimation(animation); + flagView2.startAnimation(animation); + flagView3.startAnimation(animation); + } + + /* + @Override public void onResume() { super.onResume(); @@ -33,5 +49,5 @@ public class WelcomeFragment extends Fragment { flagView1.startAnimation(animation); flagView2.startAnimation(animation); flagView3.startAnimation(animation); - } + }*/ } diff --git a/android/src/fishrungames/bashgid/core/AlbumManager.java b/android/src/fishrungames/bashgid/core/AlbumManager.java index cae7d26..c833706 100644 --- a/android/src/fishrungames/bashgid/core/AlbumManager.java +++ b/android/src/fishrungames/bashgid/core/AlbumManager.java @@ -21,7 +21,6 @@ public class AlbumManager public String description; public int hidden; - public AlbumRecordData(String name, String title, String description, int hidden) { this.name = name; diff --git a/android/src/fishrungames/bashgid/core/ArticleManager.java b/android/src/fishrungames/bashgid/core/ArticleManager.java index 88e7ef0..5683d6e 100644 --- a/android/src/fishrungames/bashgid/core/ArticleManager.java +++ b/android/src/fishrungames/bashgid/core/ArticleManager.java @@ -91,6 +91,13 @@ public class ArticleManager } } + public static ArticleRecordData CreateEmptyArticle() + { + ArticleRecordData result = new ArticleRecordData("", 0, "", "", 0.0, 0.0, "", "", "", "", new Date(), 1); + + return result; + } + public static class ArticleShortDataSortComparator implements Comparator { public int compare(ArticleShortData record1, ArticleShortData record2) { return record2.name.compareTo(record1.name); diff --git a/android/src/fishrungames/bashgid/core/ChannelManager.java b/android/src/fishrungames/bashgid/core/ChannelManager.java index 52be1e7..43d400d 100644 --- a/android/src/fishrungames/bashgid/core/ChannelManager.java +++ b/android/src/fishrungames/bashgid/core/ChannelManager.java @@ -11,8 +11,7 @@ public class ChannelManager public String title; public String description; public int hidden; - - + public ChannelRecordData(String name, String title, String description, int hidden) { this.name = name; diff --git a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java index 35d8f87..41223c7 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java @@ -21,9 +21,8 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import android.os.AsyncTask; +import android.database.DatabaseUtils; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.util.Log; import fishrungames.bashgid.MainActivity; @@ -34,36 +33,122 @@ import fishrungames.bashgid.core.JournalManager.JournalRecordData; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; import fishrungames.bashgid.core.TranslationManager.TranslationRecordData; import fishrungames.bashgid.core.VideoManager.VideoRecordData; +import fishrungames.networkutils.SimpleAsyncTask; -public class DatabaseDownloadTask extends AsyncTask +public class DatabaseDownloadTask extends SimpleAsyncTask { - public Handler mHandler; - protected Long doInBackground(Bundle... queryArr) { + + + + PublishProgress(0.1f); + + if (isCancelled()) + { + return (long)0; + } + + ParseJsonTranslation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=translation/json")); + PublishProgress(0.2f); + + if (isCancelled()) + { + return (long)0; + } ParseJsonPhoto(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=photo/json")); + PublishProgress(0.25f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonAlbum(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=album/json")); + PublishProgress(0.3f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonPhotoAlbumRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=photoAlbumRelation/json")); + PublishProgress(0.35f); + + if (isCancelled()) + { + return (long)0; + } 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")); + PublishProgress(0.4f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonChannel(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=channel/json")); + PublishProgress(0.5f); + + if (isCancelled()) + { + return (long)0; + } + + ParseJsonVideoChannelRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=videoChannelRelation/json")); + PublishProgress(0.6f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonArticle(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=article/json")); - ParseJsonJournal(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=journal/json")); + PublishProgress(0.65f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonAlbumArticleRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=albumArticleRelation/json")); + PublishProgress(0.85f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonChannelArticleRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=channelArticleRelation/json")); + PublishProgress(0.9f); + + if (isCancelled()) + { + return (long)0; + } + + ParseJsonJournal(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=journal/json")); + PublishProgress(0.75f); + + if (isCancelled()) + { + return (long)0; + } + ParseJsonArticleJournalRelation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=articleJournalRelation/json")); - ParseJsonTranslation(getJsonFromUrl("http://bashgid.hallyu.ru/index.php?r=translation/json")); + PublishProgress(0.95f); return (long) 0; } + + protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_UPDATE, this); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_UPDATE, progress[0]); completeMessage.sendToTarget(); @@ -71,10 +156,15 @@ public class DatabaseDownloadTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_FINISHED, this); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_FINISHED, 100); completeMessage.sendToTarget(); } + + public void ReloadDatabaseContent() + { + //journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(3); + } private String getJsonFromUrl(String url_select) { @@ -152,10 +242,10 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String title = jObject.getString("title"); - String description = jObject.getString("description"); - String imageUrl = jObject.getString("imageUrl"); - String imageHash = jObject.getString("imageHash"); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); + String imageUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("imageUrl")); + String imageHash = DatabaseDownloadTask.sqlEscapeString(jObject.getString("imageHash")); double geoLat = jObject.getDouble("geoLat"); double geoLon = jObject.getDouble("geoLon"); @@ -182,9 +272,9 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String name = jObject.getString("name"); - String title = jObject.getString("title"); - String description = jObject.getString("description"); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); int hidden = jObject.getInt("hidden"); MainActivity.getInstance().albumDataSource.CreateNewAlbum(new AlbumRecordData(name, title, description, hidden)); @@ -208,8 +298,8 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String imageUrl = jObject.getString("imageUrl"); - String name = jObject.getString("name"); + String imageUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("imageUrl")); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); MainActivity.getInstance().albumDataSource.AddPhotoToAlbum(imageUrl, name); @@ -233,12 +323,12 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); int type = jObject.getInt("type"); - String videoUrl = jObject.getString("videoUrl"); + String videoUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("videoUrl")); - String title = jObject.getString("title"); - String description = jObject.getString("description"); - String previewImageUrl = jObject.getString("previewImageUrl"); - String previewImageHash = jObject.getString("previewImageHash"); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); + String previewImageUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("previewImageUrl")); + String previewImageHash = DatabaseDownloadTask.sqlEscapeString(jObject.getString("previewImageHash")); MainActivity.getInstance().videoDataSource.AddOrReplaceVideo(new VideoRecordData(type, videoUrl, title, description, previewImageUrl, previewImageHash)); @@ -264,9 +354,9 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String name = jObject.getString("name"); - String title = jObject.getString("title"); - String description = jObject.getString("description"); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); int hidden = jObject.getInt("hidden"); MainActivity.getInstance().channelDataSource.CreateNewChannel(new ChannelRecordData(name, title, description, hidden)); @@ -290,8 +380,8 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String videoUrl = jObject.getString("videoUrl"); - String name = jObject.getString("name"); + String videoUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("videoUrl")); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); MainActivity.getInstance().channelDataSource.AddVideoToChannel(videoUrl, name); @@ -316,16 +406,16 @@ public class DatabaseDownloadTask extends AsyncTask { JSONObject jObject = jArray.getJSONObject(i); - String name = jObject.getString("name"); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); int type = jObject.getInt("type"); - String title = jObject.getString("title"); - String content = jObject.getString("content"); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String content = DatabaseDownloadTask.sqlEscapeString(jObject.getString("content")); double geoLat = jObject.getDouble("geoLat"); double geoLon = jObject.getDouble("geoLon"); - String address = jObject.getString("address"); - String phone = jObject.getString("phone"); - String externalLink = jObject.getString("externalLink"); - String externalLinkText = jObject.getString("externalLinkText"); + String address = DatabaseDownloadTask.sqlEscapeString(jObject.getString("address")); + String phone = DatabaseDownloadTask.sqlEscapeString(jObject.getString("phone")); + String externalLink = DatabaseDownloadTask.sqlEscapeString(jObject.getString("externalLink")); + String externalLinkText = DatabaseDownloadTask.sqlEscapeString(jObject.getString("externalLinkText")); Date dateTime = ArticleManager.iso8601Format.parse(jObject.getString("dateTime")); int hidden = jObject.getInt("hidden"); @@ -357,9 +447,9 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String name = jObject.getString("name"); - String title = jObject.getString("title"); - String description = jObject.getString("description"); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); + String title = DatabaseDownloadTask.sqlEscapeString(jObject.getString("title")); + String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); int hidden = jObject.getInt("hidden"); int geoCategory = jObject.getInt("geoCategory"); int main = jObject.getInt("main"); @@ -385,8 +475,8 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String albumName = jObject.getString("albumName"); - String articleName = jObject.getString("articleName"); + String albumName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("albumName")); + String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); MainActivity.getInstance().articleDataSource.AddAlbumToArticle(albumName, articleName); @@ -409,8 +499,8 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String channelName = jObject.getString("channelName"); - String articleName = jObject.getString("articleName"); + String channelName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("channelName")); + String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); MainActivity.getInstance().articleDataSource.AddChannelToArticle(channelName, articleName); @@ -433,8 +523,8 @@ public class DatabaseDownloadTask extends AsyncTask JSONObject jObject = jArray.getJSONObject(i); - String articleName = jObject.getString("articleName"); - String journalName = jObject.getString("journalName"); + String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); + String journalName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("journalName")); MainActivity.getInstance().journalDataSource.AddArticleToJournal(articleName, journalName); @@ -457,13 +547,13 @@ public class DatabaseDownloadTask extends AsyncTask 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"); - String textEnUp = jObject.getString("textEnUp"); - String textRuUp = jObject.getString("textRuUp"); - String textZhUp = jObject.getString("textZhUp"); + String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); + String textEn = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textEn")); + String textRu = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textRu")); + String textZh = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textZh")); + String textEnUp = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textEnUp")); + String textRuUp = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textRuUp")); + String textZhUp = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textZhUp")); MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(name, textEn, textRu, textZh, textEnUp, textRuUp, textZhUp)); @@ -475,5 +565,28 @@ public class DatabaseDownloadTask extends AsyncTask Log.e("JSONException", "Error: " + e.toString()); } } + + + public static String sqlEscapeString_withquotes(String s) + { + String result = DatabaseUtils.sqlEscapeString(s); + + result = result.substring(1, result.length()-1); + + return result; + } + + public static String sqlEscapeString(String s) + { + /* + String result = s; + + result = DatabaseUtils.sqlEscapeString(result); + + result = result.substring(1, result.length()-1); + + return result;*/ + return s; + } } \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java index 370ca26..b7898a8 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java @@ -24,9 +24,9 @@ public class DatabaseGetAlbumTask extends AsyncTask protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_STATE_UPDATE, album); + //Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_STATE_UPDATE, album); - completeMessage.sendToTarget(); + //completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java index 5e69f66..07fb4b4 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java @@ -11,20 +11,18 @@ import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; public class DatabaseGetJournalListTask extends AsyncTask { -ArrayList journalList; + ArrayList journalList; - public Handler mHandler; - protected Long doInBackground(String... queryArr) { if (queryArr.length > 0) { - journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(3); //Xperimental -- need to pass exactly how many articles + journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(7); //Xperimental -- need to pass exactly how many articles } else { - journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(3); //Xperimental -- need to pass exactly how many articles + journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(7); //Xperimental -- need to pass exactly how many articles } @@ -33,15 +31,16 @@ ArrayList journalList; protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_UPDATE, journalList); + //Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_UPDATE, journalList); - completeMessage.sendToTarget(); + //completeMessage.sendToTarget(); } protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); + + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java index ec59e52..89d8742 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java @@ -12,8 +12,6 @@ public class DatabaseGetJournalTask extends AsyncTask JournalSemiFullData journal = null; - public Handler mHandler; - protected Long doInBackground(Bundle... queryArr) { @@ -30,15 +28,15 @@ public class DatabaseGetJournalTask extends AsyncTask protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_UPDATE, journal); + //Message completeMessage = MainActivity.getInstance().obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_UPDATE, journal); - completeMessage.sendToTarget(); + //completeMessage.sendToTarget(); } protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/JournalManager.java b/android/src/fishrungames/bashgid/core/JournalManager.java index 4c381c8..75f172b 100644 --- a/android/src/fishrungames/bashgid/core/JournalManager.java +++ b/android/src/fishrungames/bashgid/core/JournalManager.java @@ -67,12 +67,23 @@ public class JournalManager } - public static JournalSemiFullData CreateEmptyJournal() + + public static JournalRecordData CreateEmptyJournal() { - JournalSemiFullData result = new JournalSemiFullData(new JournalRecordData("", "", "", 1, 0, 0)); + JournalRecordData result = new JournalRecordData("", "", "", 1, 0, 0); + + return result; + } + + public static JournalSemiFullData CreateEmptyJournalSemiFull() + { + JournalSemiFullData result = new JournalSemiFullData(CreateEmptyJournal()); return result; } + + + } diff --git a/android/src/fishrungames/bashgid/core/NewsDownloadTask.java b/android/src/fishrungames/bashgid/core/NewsDownloadTask.java index c11fe3d..48f8402 100644 --- a/android/src/fishrungames/bashgid/core/NewsDownloadTask.java +++ b/android/src/fishrungames/bashgid/core/NewsDownloadTask.java @@ -1,33 +1,32 @@ package fishrungames.bashgid.core; - -import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import fishrungames.bashgid.MainActivity; +import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; +import fishrungames.networkutils.SimpleAsyncTask; -public class NewsDownloadTask extends AsyncTask +public class NewsDownloadTask extends SimpleAsyncTask { - - public Handler mHandler; + protected Long doInBackground(Bundle... queryArr) { - for (int i = 0; i < NewsManager.urlArr.length; i++) { - NewsManager.LoadNewsAndImagesFromRss(NewsManager.urlArr[i]); + NewsManager.LoadNewsFromRss(NewsManager.urlArr[i], this); } + return (long) 0; } protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_UPDATE, this); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_UPDATE, progress[0]); completeMessage.sendToTarget(); @@ -35,9 +34,10 @@ public class NewsDownloadTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_FINISHED, this); + Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_FINISHED, 100); completeMessage.sendToTarget(); } + } diff --git a/android/src/fishrungames/bashgid/core/NewsManager.java b/android/src/fishrungames/bashgid/core/NewsManager.java index 1d781c6..a9cf50a 100644 --- a/android/src/fishrungames/bashgid/core/NewsManager.java +++ b/android/src/fishrungames/bashgid/core/NewsManager.java @@ -2,43 +2,40 @@ package fishrungames.bashgid.core; import fishrungames.networkutils.ImageManager; - import java.util.ArrayList; import java.util.Locale; +import android.os.Bundle; + import fishrungames.networkutils.DownloadFunctions; +import fishrungames.networkutils.SimpleAsyncTask; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.R; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.TranslationManager.TranslationRecordData; - -public class NewsManager { +public class NewsManager +{ /* - public static final String [] urlArr = { - "https://www.bashkortostan.ru/presscenter/news/rss/", - "http://www.bashedu.ru/rss.xml", - "http://www.bashinform.ru/rss/all.xml", - "http://www.minkult-rb.ru/news/rss/", - "http://02.mvd.ru/news/rss/" - }; */ - - public static final String [] urlArr = { - "https://news.yandex.ru/Ufa/index.rss", - }; - - + * public static final String [] urlArr = { + * "https://www.bashkortostan.ru/presscenter/news/rss/", + * "http://www.bashedu.ru/rss.xml", "http://www.bashinform.ru/rss/all.xml", + * "http://www.minkult-rb.ru/news/rss/", "http://02.mvd.ru/news/rss/" }; + */ + + public static final String[] urlArr = { "https://news.yandex.ru/Ufa/index.rss", }; + public static ArrayList ExtractEnclosureImageUrl(ArrayList rss2ItemArr) { ArrayList imageToDownloadList = new ArrayList(); - + for (RssReader.Rss2Item rss2Item : rss2ItemArr) { - //Enclosure + // Enclosure if (rss2Item.rss2Enclosure != null) { if (DownloadFunctions.MimeTypeIsImage(rss2Item.rss2Enclosure.mimeType)) @@ -47,62 +44,62 @@ public class NewsManager { } } } - + return imageToDownloadList; } - + public static ArrayList ExtractDescriptionImageUrl(ArrayList rss2ItemArr) { ArrayList imageToDownloadList = new ArrayList(); - + for (RssReader.Rss2Item rss2Item : rss2ItemArr) { - //And images inside text + // And images inside text int i = rss2Item.description.indexOf(" ConvertRelativeToAbsoluteImageUrlList(ArrayList relativeImageUrlList, String url) { ArrayList absoluteImageUrlList = new ArrayList(); - + for (String relativeImageUrl : relativeImageUrlList) { if (!relativeImageUrl.startsWith("http://")) { String homeFolder = DownloadFunctions.GetUrlFolder(url); - + relativeImageUrl = homeFolder + relativeImageUrl; } - + absoluteImageUrlList.add(relativeImageUrl); } - + return absoluteImageUrlList; } - - - static void ReplaceRemoteUrlToLocalUrl(ArrayList rss2ItemArr, ArrayList relativeImageUrlList, ArrayList absoluteImageUrlList) + + static void ReplaceRemoteUrlToLocalUrl(ArrayList rss2ItemArr, ArrayList relativeImageUrlList, + ArrayList absoluteImageUrlList) { for (RssReader.Rss2Item rss2Item : rss2ItemArr) @@ -110,85 +107,93 @@ public class NewsManager { for (int i = 0; i < relativeImageUrlList.size(); i++) { String fileName = ImageManager.GetImageLocalUrl(absoluteImageUrlList.get(i)); - - rss2Item.description = rss2Item.description.replace("\"" +relativeImageUrlList.get(i) + "\"" , "\"" +fileName + "\""); + + rss2Item.description = rss2Item.description.replace("\"" + relativeImageUrlList.get(i) + "\"", "\"" + fileName + "\""); } } } - - static void LoadNewsAndImagesFromRss(String url) + + static void LoadNewsFromRss(String url, SimpleAsyncTask task) { - //Xperimental -- need to optimize this code. slow block BEGINS - String xmlCode = DownloadFunctions.getXmlFromUrl(url); - + // Xperimental -- need to optimize this code. slow block BEGINS + String xmlCode = DownloadFunctions.getXmlFromUrl(url, task); + if (xmlCode == null) { return; } - - //Remove BOM character if present + + // Remove BOM character if present if (xmlCode.startsWith("\uFEFF")) { xmlCode = xmlCode.substring(1); - } - - RssReader rssReader = new RssReader(); - - rssReader.ReadRss(xmlCode); - - - - //Xperimental -- need to optimize this code. slow block ENDS - - - for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr) - { - - String title = rss2Item.title.replace("'", "''").replace("\"", "\"\""); - String description = rss2Item.description.replace("'", "''").replace("\"", "\"\""); - - String titleUp = title.toUpperCase(new Locale("ru")); - String descriptionUp = description.toUpperCase(new Locale("ru")); - - - ArticleRecordData newsArticle = new ArticleRecordData( - title, - ArticleManager.ARTICLE_TYPE_NEWS, - title, - description, - 0, - 0, - "", - "", - rss2Item.link, - MainActivity.getInstance().getResources().getString(R.string.dialog_open), - rss2Item.pubDate, - 0); - - AlbumManager.AddNewArticleToJournal(newsArticle, "news"); - - //To perform search - MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData( - title, - title, //En - title, //Ru - title, //Zh - titleUp, //En Up - titleUp, //Ru Up - titleUp //Zh Up - )); - - MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData( - description, - description, //En - description, //Ru - description, //Zh - descriptionUp, //En Up - descriptionUp, //Ru Up - descriptionUp //Zh Up - )); - } + if (task != null) + { + if (task.isCancelled()) + { + return; + } + + task.PublishMoreProgress(); + } + + RssReader rssReader = new RssReader(); + + rssReader.ReadRss(xmlCode); + + // Xperimental -- need to optimize this code. slow block ENDS + + //for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr) + for (int i = 0; i < rssReader.rss2ItemArr.size(); i++) + { + + RssReader.Rss2Item rss2Item = rssReader.rss2ItemArr.get(i); + + String title = rss2Item.title.replace("'", "''").replace("\"", "\"\""); + String description = rss2Item.description.replace("'", "''").replace("\"", "\"\""); + + String titleUp = title.toUpperCase(new Locale("ru")); + String descriptionUp = description.toUpperCase(new Locale("ru")); + + ArticleRecordData newsArticle = new ArticleRecordData(title, ArticleManager.ARTICLE_TYPE_NEWS, title, description, 0, 0, "", "", rss2Item.link, + MainActivity.getInstance().getResources().getString(R.string.dialog_open), rss2Item.pubDate, 0); + + AlbumManager.AddNewArticleToJournal(newsArticle, "news"); + + // To perform search + MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(title, title, // En + title, // Ru + title, // Zh + titleUp, // En Up + titleUp, // Ru Up + titleUp // Zh Up + )); + + MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(description, description, // En + description, // Ru + description, // Zh + descriptionUp, // En Up + descriptionUp, // Ru Up + descriptionUp // Zh Up + )); + + + if (task != null) + { + if (task.isCancelled()) + { + return; + } + + task.PublishProgress(i / (float) rssReader.rss2ItemArr.size()); + task.ReloadDatabaseContent(); + } + + + + } + } } diff --git a/android/src/fishrungames/bashgid/core/TranslationManager.java b/android/src/fishrungames/bashgid/core/TranslationManager.java index 4fb5da5..ce6f9a7 100644 --- a/android/src/fishrungames/bashgid/core/TranslationManager.java +++ b/android/src/fishrungames/bashgid/core/TranslationManager.java @@ -39,4 +39,12 @@ public class TranslationManager } } + + public static TranslationRecordData CreateEmptyTranslation() + { + TranslationRecordData result = new TranslationRecordData("", "", "", "", "", "", ""); + + return result; + } + } diff --git a/android/src/fishrungames/bashgid/core/VideoManager.java b/android/src/fishrungames/bashgid/core/VideoManager.java index 881586c..a367499 100644 --- a/android/src/fishrungames/bashgid/core/VideoManager.java +++ b/android/src/fishrungames/bashgid/core/VideoManager.java @@ -1,8 +1,5 @@ package fishrungames.bashgid.core; -import fishrungames.bashgid.core.AlbumManager.AlbumFullData; -import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; - public class VideoManager { public static final int VIDEO_TYPE_YOUTUBE = 1; diff --git a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java index 4c4d934..70d3d2d 100644 --- a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; import fishrungames.bashgid.core.AlbumManager.AlbumShortData; @@ -13,7 +14,6 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.util.Log; public class AlbumDataSource { @@ -47,7 +47,7 @@ public class AlbumDataSource database.insert(BashgidSqliteHelper.TABLE_ALBUM, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_ALBUM, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null); + database.update(BashgidSqliteHelper.TABLE_ALBUM, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.name) +"'", null); } } finally @@ -62,7 +62,7 @@ public class AlbumDataSource { boolean result = false; - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -109,9 +109,9 @@ public class AlbumDataSource public AlbumFullData GetAlbumFullData(String name) { - AlbumFullData result = null; + AlbumFullData result = AlbumManager.CreateEmptyAlbum(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -132,7 +132,7 @@ public class AlbumDataSource public AlbumFullData InnerGetAlbumFullData(String name, SQLiteDatabase database) { - AlbumFullData result = null; + AlbumFullData result = AlbumManager.CreateEmptyAlbum(); AlbumRecordData recordData = innerGetAlbumByName(name, database); @@ -158,9 +158,9 @@ public class AlbumDataSource public AlbumShortData GetAlbumShortData(String name) { - AlbumShortData result = null; + AlbumShortData result = new AlbumShortData(new AlbumRecordData("", "", "", 1)); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -202,7 +202,7 @@ public class AlbumDataSource ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -228,6 +228,13 @@ public class AlbumDataSource { shortData.firstImageUrl = imageUrlArr.get(0); } + else + { + shortData.firstImageUrl = "R.drawable.no_picture"; + } + + shortData.title = MainActivity.getInstance().translationDataSource.TryTranslateText(shortData.title, database); + shortData.description = MainActivity.getInstance().translationDataSource.TryTranslateText(shortData.description, database); result.add(shortData); } while (cursor.moveToNext()); @@ -253,7 +260,7 @@ public class AlbumDataSource boolean result = false; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME - + "=?", new String[] { name }, null, null, null, null); + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -278,7 +285,7 @@ public class AlbumDataSource 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); + new String[] { DatabaseDownloadTask.sqlEscapeString(imageUrl), DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -300,7 +307,7 @@ public class AlbumDataSource 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); + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -323,10 +330,10 @@ public class AlbumDataSource public AlbumRecordData innerGetAlbumByName(String name, SQLiteDatabase database) { - AlbumRecordData result = null; + AlbumRecordData result = new AlbumRecordData("", "", "", 1); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE, - BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_HIDDEN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_HIDDEN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { diff --git a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java index 7060596..d7a5608 100644 --- a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java @@ -1,26 +1,25 @@ package fishrungames.bashgid.core.db; - import java.text.ParseException; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; - import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.ArticleManager; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.ArticleManager.ArticleFullData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleShortData; import fishrungames.bashgid.core.ChannelManager.ChannelFullData; - import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.text.Html; import android.util.Log; public class ArticleDataSource @@ -28,14 +27,13 @@ public class ArticleDataSource private BashgidSqliteHelper dbHelper = null; - - - public static class DateSortComparator implements Comparator { - public int compare(ArticleManager.ArticleRecordData record1, ArticleManager.ArticleRecordData record2) { - return record2.dateTime.compareTo(record1.dateTime); - } + public static class DateSortComparator implements Comparator + { + public int compare(ArticleManager.ArticleRecordData record1, ArticleManager.ArticleRecordData record2) + { + return record2.dateTime.compareTo(record1.dateTime); + } } - public ArticleDataSource(Context context, BashgidSqliteHelper dbHelper) { @@ -48,7 +46,6 @@ public class ArticleDataSource if (database != null) { - try { ContentValues values = new ContentValues(); @@ -65,13 +62,13 @@ public class ArticleDataSource values.put(BashgidSqliteHelper.COLUMN_EXTERNAL_LINK_TEXT, recordData.externalLinkText); values.put(BashgidSqliteHelper.COLUMN_DATE_TIME, ArticleManager.iso8601Format.format(recordData.dateTime)); values.put(BashgidSqliteHelper.COLUMN_HIDDEN, recordData.hidden); - + if (!innerIsArticleAlreadyExist(recordData.name, database)) { database.insert(BashgidSqliteHelper.TABLE_ARTICLE, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_ARTICLE, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null); + database.update(BashgidSqliteHelper.TABLE_ARTICLE, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.name) + "'", null); } } finally @@ -81,12 +78,12 @@ public class ArticleDataSource } } - + public boolean IsArticleAlreadyExist(String name) { boolean result = false; - - SQLiteDatabase database = dbHelper.getWritableDatabase(); + + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -94,18 +91,17 @@ public class ArticleDataSource try { result = innerIsArticleAlreadyExist(name, database); - } finally { dbHelper.close(); } } - + return result; } - + public void AddAlbumToArticle(String albumName, String articleName) { SQLiteDatabase database = dbHelper.getWritableDatabase(); @@ -122,11 +118,10 @@ public class ArticleDataSource if (!innerAlbumArticleRelationAlreadyExist(albumName, articleName, database)) { - //Log.e("a", "aaa1"); + database.insert(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, null, values); - //Log.e("a", "aaa2"); - } - //Log.e("a", "aaa3"); + + } } finally { @@ -134,7 +129,7 @@ public class ArticleDataSource } } } - + public void AddChannelToArticle(String channelName, String articleName) { SQLiteDatabase database = dbHelper.getWritableDatabase(); @@ -151,11 +146,8 @@ public class ArticleDataSource if (!innerChannelArticleRelationAlreadyExist(channelName, articleName, database)) { - //Log.e("a", "aaa1"); database.insert(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, null, values); - //Log.e("a", "aaa2"); - } - //Log.e("a", "aaa3"); + } } finally { @@ -163,132 +155,130 @@ public class ArticleDataSource } } } - + public ArticleFullData GetArticleFullData(String name) { ArticleFullData result = null; - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { - result = InnerGetArticleFullData(name, database); - - + } finally { dbHelper.close(); } } - + return result; } - + public ArticleFullData InnerGetArticleFullData(String name, SQLiteDatabase database) { - ArticleFullData result = null; - - - ArticleRecordData recordData = innerGetArticleByName(name, database); - - if (recordData != null) - { - - result = new ArticleFullData(recordData); - - ArrayList albumNameArr = innerGetAlbumNameArrInArticle(name, database); + ArticleFullData result = new ArticleFullData(ArticleManager.CreateEmptyArticle()); - for (String albumName : albumNameArr) - { - result.albumArr.add(MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumName, database)); - } - - ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database); + ArticleRecordData recordData = innerGetArticleByName(name, database); + + if (recordData != null) + { + + result = new ArticleFullData(recordData); + + ArrayList albumNameArr = innerGetAlbumNameArrInArticle(name, database); + + for (String albumName : albumNameArr) + { + result.albumArr.add(MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumName, database)); + } + + ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database); + + for (String channelName : channelNameArr) + { + result.channelArr.add(MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelName, database)); + } + + result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); + result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); + result.address = MainActivity.getInstance().translationDataSource.TryTranslateText(result.address, database); + result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); + result.externalLinkText = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLinkText, database); + + if (result.type == ArticleManager.ARTICLE_TYPE_NEWS) + { + result.title = Html.fromHtml(result.title).toString(); + result.content = Html.fromHtml(result.content).toString(); + } + + } - for (String channelName : channelNameArr) - { - result.channelArr.add(MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelName, database)); - } - - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); - result.address = MainActivity.getInstance().translationDataSource.TryTranslateText(result.address, database); - result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); - result.externalLinkText = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLinkText, database); - - - - } - - return result; } - - + public ArticleShortData GetArticleShortData(String name) { - ArticleShortData result = null; - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + ArticleShortData result = new ArticleShortData(ArticleManager.CreateEmptyArticle()); + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { - + result = InnerGetArticleShortData(name, database); - - + } finally { dbHelper.close(); } } - + return result; } - + public ArrayList SearchArticleByTitleOrText(String query) { ArrayList result = new ArrayList(); - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { ArrayList articleNameArr = InnerSearchArticleByTitleOrText(query, database); - + for (String articleName : articleNameArr) { result.add(InnerGetArticleShortData(articleName, database)); } - + } finally { dbHelper.close(); } } - + return result; } - + public ArrayList SearchArticleByTitleOrTextInJournal(String query, String journalName) { ArrayList result = new ArrayList(); - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { ArrayList articleNameArr = InnerSearchArticleByTitleOrText(query, database); - + for (String articleName : articleNameArr) { if (MainActivity.getInstance().journalDataSource.InnerArticleJournalRelationAlreadyExist(articleName, journalName, database)) @@ -296,51 +286,50 @@ public class ArticleDataSource result.add(InnerGetArticleShortData(articleName, database)); } } - + } finally { dbHelper.close(); } } - + return result; } public ArrayList SearchArticleByQuery(String query) { ArrayList result = new ArrayList(); - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { result = InnerSearchArticleByQuery(query, database); - - + } finally { dbHelper.close(); } } - + return result; } - + public ArrayList SearchArticleByQueryAndJournal(String query, String journalName) { ArrayList result = new ArrayList(); - - SQLiteDatabase database = dbHelper.getWritableDatabase(); - + + SQLiteDatabase database = dbHelper.getReadableDatabase(); + if (database != null) { try { - + ArrayList intermediateResult = InnerSearchArticleByQuery(query, database); - + for (ArticleShortData article : intermediateResult) { if (MainActivity.getInstance().journalDataSource.InnerArticleJournalRelationAlreadyExist(article.name, journalName, database)) @@ -348,44 +337,40 @@ public class ArticleDataSource result.add(article); } } - - + } finally { dbHelper.close(); } } - - return result; - } - - public ArrayList InnerSearchArticleByQuery(String query, SQLiteDatabase database) - { - ArrayList result = new ArrayList(); - - - ArrayList recordDataArr = innerGetArticlesByQuery(query, database); - - for (int i = 0; i < recordDataArr.size(); i++) - { - ArticleShortData article = new ArticleShortData(recordDataArr.get(i)); - - article.previewImageUrl = getPreviewImageUrlForArticle(recordDataArr.get(i).name, database); - - result.add(article); - } - return result; } - - + + public ArrayList InnerSearchArticleByQuery(String query, SQLiteDatabase database) + { + ArrayList result = new ArrayList(); + + ArrayList recordDataArr = innerGetArticlesByQuery(query, database); + + for (int i = 0; i < recordDataArr.size(); i++) + { + ArticleShortData article = new ArticleShortData(recordDataArr.get(i)); + + article.previewImageUrl = getPreviewImageUrlForArticle(recordDataArr.get(i).name, database); + + result.add(article); + } + + return result; + } + public boolean InnerArticleIsHidden(String name, SQLiteDatabase database) { boolean result = false; - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME }, - BashgidSqliteHelper.COLUMN_NAME + "=? AND " +BashgidSqliteHelper.COLUMN_HIDDEN + "=1", new String[] { name }, null, null, null, null); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME + + "=? AND " + BashgidSqliteHelper.COLUMN_HIDDEN + "=1", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -393,82 +378,83 @@ public class ArticleDataSource { result = true; } - + cursor.close(); cursor = null; - } - + } + return result; } - - - + public ArticleShortData InnerGetArticleShortData(String name, SQLiteDatabase database) { - ArticleShortData result = null; - - - ArticleRecordData recordData = innerGetArticleByName(name, database); - - if (recordData != null) - { - - result = new ArticleShortData(recordData); - - result.previewImageUrl = getPreviewImageUrlForArticle(name, database); - - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); - result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); + ArticleShortData result = new ArticleShortData(ArticleManager.CreateEmptyArticle()); + + ArticleRecordData recordData = innerGetArticleByName(name, database); + + if (recordData != null) + { + + result = new ArticleShortData(recordData); + + result.previewImageUrl = getPreviewImageUrlForArticle(name, database); + + result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); + result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); + result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); + result.externalLinkText = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLinkText, database); - - } - - + if (result.type == ArticleManager.ARTICLE_TYPE_NEWS) + { + result.title = Html.fromHtml(result.title).toString(); + result.content = Html.fromHtml(result.content).toString(); + } + } + return result; } - + private String getPreviewImageUrlForArticle(String name, SQLiteDatabase database) { String result = "R.drawable.no_picture"; - + ArrayList albumNameArr = innerGetAlbumNameArrInArticle(name, database); - + if (albumNameArr.size() > 0) { AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database); - + if (album.photoRecordArr.size() > 0) { result = album.photoRecordArr.get(0).imageUrl; } - + } - + if (result.equals("R.drawable.no_picture")) { ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database); - + if (channelNameArr.size() > 0) { ChannelFullData channelFullData = MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database); - + if (channelFullData.videoRecordArr.size() > 0) { result = channelFullData.videoRecordArr.get(0).previewImageUrl; } } } - + return result; } - + private boolean innerIsArticleAlreadyExist(String name, SQLiteDatabase database) { boolean result = false; - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME }, - BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -476,23 +462,22 @@ public class ArticleDataSource { result = true; } - + cursor.close(); cursor = null; - } - + } + return result; } - - - + private boolean innerAlbumArticleRelationAlreadyExist(String albumName, String articleName, SQLiteDatabase database) { boolean result = false; - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ALBUM_NAME, BashgidSqliteHelper.COLUMN_ARTICLE_NAME }, - BashgidSqliteHelper.COLUMN_ALBUM_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { albumName, articleName }, null, null, null, null); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ALBUM_NAME, + BashgidSqliteHelper.COLUMN_ARTICLE_NAME }, BashgidSqliteHelper.COLUMN_ALBUM_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(albumName), DatabaseDownloadTask.sqlEscapeString(articleName) }, null, null, null, null); if (cursor != null) { @@ -502,18 +487,19 @@ public class ArticleDataSource } cursor.close(); cursor = null; - } - + } + return result; } - + private boolean innerChannelArticleRelationAlreadyExist(String channelName, String articleName, SQLiteDatabase database) { boolean result = false; - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_CHANNEL_NAME, BashgidSqliteHelper.COLUMN_ARTICLE_NAME }, - BashgidSqliteHelper.COLUMN_CHANNEL_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { channelName, articleName }, null, null, null, null); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_CHANNEL_NAME, + BashgidSqliteHelper.COLUMN_ARTICLE_NAME }, BashgidSqliteHelper.COLUMN_CHANNEL_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(channelName), DatabaseDownloadTask.sqlEscapeString(articleName) }, null, null, null, null); if (cursor != null) { @@ -521,182 +507,131 @@ public class ArticleDataSource { result = true; } - + cursor.close(); cursor = null; - } - + } + return result; } - + private ArticleRecordData innerGetArticleByName(String name, SQLiteDatabase database) { - - ArticleRecordData result = null; - - 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_ADDRESS, - BashgidSqliteHelper.COLUMN_PHONE, - BashgidSqliteHelper.COLUMN_EXTERNAL_LINK, - BashgidSqliteHelper.COLUMN_EXTERNAL_LINK_TEXT, - BashgidSqliteHelper.COLUMN_DATE_TIME, - BashgidSqliteHelper.COLUMN_HIDDEN - }, - BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + + ArticleRecordData result = ArticleManager.CreateEmptyArticle(); + + 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_ADDRESS, BashgidSqliteHelper.COLUMN_PHONE, BashgidSqliteHelper.COLUMN_EXTERNAL_LINK, + BashgidSqliteHelper.COLUMN_EXTERNAL_LINK_TEXT, BashgidSqliteHelper.COLUMN_DATE_TIME, BashgidSqliteHelper.COLUMN_HIDDEN }, + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { - + Date d = new Date(); - + try { d = ArticleManager.iso8601Format.parse(cursor.getString(10)); - } - catch(ParseException e) + } catch (ParseException e) { Log.e("aaa", "aaa!!!!!"); } - - result = new ArticleRecordData( - cursor.getString(0), - cursor.getInt(1), - cursor.getString(2), - cursor.getString(3), - cursor.getDouble(4), - cursor.getDouble(5), - cursor.getString(6), - cursor.getString(7), - cursor.getString(8), - cursor.getString(9), - d, - cursor.getInt(11) - ); + + result = new ArticleRecordData(cursor.getString(0), cursor.getInt(1), cursor.getString(2), cursor.getString(3), cursor.getDouble(4), + cursor.getDouble(5), cursor.getString(6), cursor.getString(7), cursor.getString(8), cursor.getString(9), d, cursor.getInt(11)); } - + cursor.close(); cursor = null; - } - + } + return result; } - + private ArrayList innerGetArticlesByQuery(String query, SQLiteDatabase database) { - + ArrayList result = new ArrayList(); - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { - BashgidSqliteHelper.COLUMN_NAME, - BashgidSqliteHelper.COLUMN_TYPE, - BashgidSqliteHelper.COLUMN_TITLE, - BashgidSqliteHelper.COLUMN_CONTENT, - BashgidSqliteHelper.COLUMN_GEOLAT, - BashgidSqliteHelper.COLUMN_GEOLON, - BashgidSqliteHelper.COLUMN_ADDRESS, - BashgidSqliteHelper.COLUMN_PHONE, - BashgidSqliteHelper.COLUMN_EXTERNAL_LINK, - BashgidSqliteHelper.COLUMN_EXTERNAL_LINK_TEXT, - BashgidSqliteHelper.COLUMN_DATE_TIME, - BashgidSqliteHelper.COLUMN_HIDDEN - }, - BashgidSqliteHelper.COLUMN_TITLE + " LIKE ?", new String[] { "%" + query + "%" }, null, null, null, null); + + 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_ADDRESS, BashgidSqliteHelper.COLUMN_PHONE, BashgidSqliteHelper.COLUMN_EXTERNAL_LINK, + BashgidSqliteHelper.COLUMN_EXTERNAL_LINK_TEXT, BashgidSqliteHelper.COLUMN_DATE_TIME, BashgidSqliteHelper.COLUMN_HIDDEN }, + BashgidSqliteHelper.COLUMN_TITLE + " LIKE ?", new String[] { "%" + DatabaseDownloadTask.sqlEscapeString(query) + "%" }, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { - + do { - - Date d = new Date(); - - try - { - d = ArticleManager.iso8601Format.parse(cursor.getString(10)); - } - 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), - cursor.getString(7), - cursor.getString(8), - cursor.getString(9), - d, - cursor.getInt(11) - )); - - } - while (cursor.moveToNext()); + + Date d = new Date(); + + try + { + d = ArticleManager.iso8601Format.parse(cursor.getString(10)); + } 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), cursor.getString(7), cursor.getString(8), cursor.getString(9), d, cursor.getInt(11))); + + } while (cursor.moveToNext()); } - + cursor.close(); cursor = null; - } - + } + return result; } - - + private ArrayList InnerSearchArticleByTitleOrText(String query, SQLiteDatabase database) { - + ArrayList result = new ArrayList(); - - Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { - BashgidSqliteHelper.COLUMN_NAME - }, - BashgidSqliteHelper.COLUMN_TITLE + " = ? OR " + BashgidSqliteHelper.COLUMN_CONTENT + " = ?", new String[] { query, query }, null, null, null, null); + + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_TITLE + + " = ? OR " + BashgidSqliteHelper.COLUMN_CONTENT + " = ?", new String[] { DatabaseDownloadTask.sqlEscapeString(query), DatabaseDownloadTask.sqlEscapeString(query) }, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { - + do { - - result.add(cursor.getString(0)); - - } - while (cursor.moveToNext()); + + result.add(cursor.getString(0)); + + } while (cursor.moveToNext()); } - + cursor.close(); cursor = null; - } - + } + return result; } - + public ArrayList innerGetAlbumNameArrInArticle(String name, SQLiteDatabase database) { ArrayList result = new ArrayList(); - + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ALBUM_NAME }, - BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -705,25 +640,24 @@ public class ArticleDataSource do { result.add(cursor.getString(0)); - } - while (cursor.moveToNext()); - + } while (cursor.moveToNext()); + } - + cursor.close(); cursor = null; - } - + } + return result; } - + private ArrayList innerGetChannelNameArrInArticle(String name, SQLiteDatabase database) { ArrayList result = new ArrayList(); - + Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_CHANNEL_NAME }, - BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -732,19 +666,16 @@ public class ArticleDataSource do { result.add(cursor.getString(0)); - } - while (cursor.moveToNext()); - + } while (cursor.moveToNext()); + } - + cursor.close(); cursor = null; - } - + } + return result; } - - } diff --git a/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java b/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java index 388f873..26cf439 100644 --- a/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java +++ b/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java @@ -180,6 +180,7 @@ public class BashgidSqliteHelper extends SQLiteOpenHelper @Override public SQLiteDatabase getWritableDatabase() { + SQLiteDatabase result = null; try @@ -200,6 +201,36 @@ public class BashgidSqliteHelper extends SQLiteOpenHelper return result; + //return super.getWritableDatabase(); + + } + + @Override + public SQLiteDatabase getReadableDatabase() + { + + SQLiteDatabase result = null; + + try + { + mutex.acquire(); + try + { + result = super.getReadableDatabase(); + + } catch (Exception e) + { + mutex.release(); + } + } catch (InterruptedException ie) + { + Log.e("Error in getWritableDatabase()", "Error in getWritableDatabase()"); + } + + return result; + + //return super.getReadableDatabase(); + } @Override diff --git a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java index 3630bb8..fc4d9e2 100644 --- a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ChannelManager; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.ChannelManager.ChannelFullData; import fishrungames.bashgid.core.ChannelManager.ChannelRecordData; @@ -46,7 +47,7 @@ public class ChannelDataSource database.insert(BashgidSqliteHelper.TABLE_CHANNEL, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_CHANNEL, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "\"" + recordData.name + "\"", null); + database.update(BashgidSqliteHelper.TABLE_CHANNEL, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.name) + "'", null); } } finally @@ -61,7 +62,7 @@ public class ChannelDataSource { boolean result = false; - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -108,9 +109,9 @@ public class ChannelDataSource public ChannelFullData GetChannelFullData(String name) { - ChannelFullData result = null; + ChannelFullData result = ChannelManager.CreateEmptyChannel(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -131,7 +132,7 @@ public class ChannelDataSource public ChannelFullData InnerGetChannelFullData(String name, SQLiteDatabase database) { - ChannelFullData result = null; + ChannelFullData result = ChannelManager.CreateEmptyChannel(); ChannelRecordData recordData = InnerGetChannelByName(name, database); @@ -160,7 +161,7 @@ public class ChannelDataSource boolean result = false; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME - + "=?", new String[] { name }, null, null, null, null); + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -183,7 +184,7 @@ public class ChannelDataSource Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL, BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?" + " AND " + BashgidSqliteHelper.COLUMN_NAME + "=?", - new String[] { videoUrl, name }, null, null, null, null); + new String[] { DatabaseDownloadTask.sqlEscapeString(videoUrl), DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -205,7 +206,7 @@ public class ChannelDataSource ArrayList result = new ArrayList(); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL }, - BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -228,10 +229,10 @@ public class ChannelDataSource public ChannelRecordData InnerGetChannelByName(String name, SQLiteDatabase database) { - ChannelRecordData result = null; + ChannelRecordData result = new ChannelRecordData("", "", "", 1); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE, - BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_HIDDEN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, + BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_HIDDEN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) diff --git a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java index f26d654..cfb35bf 100644 --- a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java @@ -6,6 +6,7 @@ import java.util.Collections; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ArticleManager; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.ArticleManager.ArticleShortData; import fishrungames.bashgid.core.JournalManager; import fishrungames.bashgid.core.JournalManager.JournalRecordData; @@ -52,7 +53,7 @@ public class JournalDataSource } else { // Replace - database.update(BashgidSqliteHelper.TABLE_JOURNAL, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "\"" + recordData.name + "\"", null); + database.update(BashgidSqliteHelper.TABLE_JOURNAL, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.name) + "'", null); } } finally @@ -67,7 +68,7 @@ public class JournalDataSource { boolean result = false; - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -126,9 +127,9 @@ public class JournalDataSource public JournalSemiFullData GetJournalSemiFullData(String name, String startAfterArticleName, int count) { - JournalSemiFullData result = null; + JournalSemiFullData result = JournalManager.CreateEmptyJournalSemiFull(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -149,7 +150,7 @@ public class JournalDataSource public ArrayList GetAllJournalListExceptHidden(int count) { ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -216,7 +217,7 @@ public class JournalDataSource // Xperimental - need to create a real superjournal ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -282,7 +283,7 @@ public class JournalDataSource public ArrayList GetGeoJournalList() { ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -332,7 +333,7 @@ public class JournalDataSource public JournalSemiFullData InnerGetJournalSemiFullData(String name, SQLiteDatabase database, String startAfterArticleName, int count) { - JournalSemiFullData result = null; + JournalSemiFullData result = JournalManager.CreateEmptyJournalSemiFull(); JournalRecordData recordData = innerGetJournalByName(name, database); @@ -395,7 +396,7 @@ public class JournalDataSource boolean result = false; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME - + "=?", new String[] { name }, null, null, null, null); + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -418,7 +419,7 @@ public class JournalDataSource Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ARTICLE_NAME, BashgidSqliteHelper.COLUMN_JOURNAL_NAME }, BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_JOURNAL_NAME - + "=?", new String[] { articleName, journalName }, null, null, null, null); + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(articleName), DatabaseDownloadTask.sqlEscapeString(journalName) }, null, null, null, null); if (cursor != null) { @@ -440,7 +441,7 @@ public class JournalDataSource 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); + BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -466,7 +467,7 @@ public class JournalDataSource 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); + BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -492,11 +493,11 @@ public class JournalDataSource public JournalRecordData innerGetJournalByName(String name, SQLiteDatabase database) { - JournalRecordData result = null; + JournalRecordData result = JournalManager.CreateEmptyJournal(); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_HIDDEN, BashgidSqliteHelper.COLUMN_GEOCATEGORY, - BashgidSqliteHelper.COLUMN_MAIN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_MAIN }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { diff --git a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java index 0f016dc..b891924 100644 --- a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java @@ -1,6 +1,7 @@ package fishrungames.bashgid.core.db; import fishrungames.bashgid.MainActivity; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; import android.content.ContentValues; @@ -45,7 +46,7 @@ public class PhotoDataSource database.insert(BashgidSqliteHelper.TABLE_PHOTO, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_PHOTO, values, BashgidSqliteHelper.COLUMN_IMAGE_URL + " = " + "\"" + recordData.imageUrl + "\"", + database.update(BashgidSqliteHelper.TABLE_PHOTO, values, BashgidSqliteHelper.COLUMN_IMAGE_URL + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.imageUrl) + "'", null); } @@ -59,9 +60,9 @@ public class PhotoDataSource public PhotoRecordData GetPhotoByImageUrl(String imageUrl) { - PhotoRecordData result = null; + PhotoRecordData result = new PhotoRecordData("", "", "", "", 0, 0); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -81,11 +82,11 @@ public class PhotoDataSource public PhotoRecordData InnerGetPhotoByImageUrl(String imageUrl, SQLiteDatabase database) { - PhotoRecordData result = null; + PhotoRecordData result = new PhotoRecordData("", "", "", "", 0, 0); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO, new String[] { BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_IMAGE_URL, BashgidSqliteHelper.COLUMN_IMAGE_HASH, - BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON }, BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { imageUrl }, + BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON }, BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(imageUrl) }, null, null, null, null); if (cursor != null) @@ -113,7 +114,7 @@ public class PhotoDataSource boolean result = false; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL }, - BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { imageUrl }, null, null, null, null); + BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(imageUrl) }, null, null, null, null); if (cursor != null) { diff --git a/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java b/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java index ae49060..adb2dba 100644 --- a/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/TranslationDataSource.java @@ -3,6 +3,8 @@ package fishrungames.bashgid.core.db; import java.util.ArrayList; import java.util.Locale; +import fishrungames.bashgid.core.DatabaseDownloadTask; +import fishrungames.bashgid.core.TranslationManager; import fishrungames.bashgid.core.TranslationManager.TranslationRecordData; import android.content.ContentValues; @@ -46,7 +48,7 @@ public class TranslationDataSource database.insert(BashgidSqliteHelper.TABLE_TRANSLATION, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_TRANSLATION, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "\"" + recordData.name + "\"", + database.update(BashgidSqliteHelper.TABLE_TRANSLATION, values, BashgidSqliteHelper.COLUMN_NAME + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.name) + "'", null); } @@ -83,7 +85,7 @@ public class TranslationDataSource { ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -105,7 +107,7 @@ public class TranslationDataSource { ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -127,7 +129,7 @@ public class TranslationDataSource { ArrayList result = new ArrayList(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -147,9 +149,9 @@ public class TranslationDataSource public TranslationRecordData GetTranslationRecordData(String name) { - TranslationRecordData result = null; + TranslationRecordData result = TranslationManager.CreateEmptyTranslation(); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -172,7 +174,7 @@ public class TranslationDataSource 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); + + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -193,12 +195,12 @@ public class TranslationDataSource public TranslationRecordData innerGetTranslationByName(String name, SQLiteDatabase database) { - TranslationRecordData result = null; + TranslationRecordData result = TranslationManager.CreateEmptyTranslation(); 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_TEXT_EN_UP, BashgidSqliteHelper.COLUMN_TEXT_RU_UP, BashgidSqliteHelper.COLUMN_TEXT_ZH_UP }, - BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null); + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(name) }, null, null, null, null); if (cursor != null) { @@ -222,7 +224,7 @@ public class TranslationDataSource ArrayList result = new ArrayList(); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_TRANSLATION, new String[] { BashgidSqliteHelper.COLUMN_NAME }, - BashgidSqliteHelper.COLUMN_TEXT_RU_UP + " LIKE ?", new String[] { "%" + partString + "%" }, null, null, null, null); + BashgidSqliteHelper.COLUMN_TEXT_RU_UP + " LIKE ?", new String[] { "%" + DatabaseDownloadTask.sqlEscapeString(partString) + "%" }, null, null, null, null); if (cursor != null) { @@ -248,7 +250,7 @@ public class TranslationDataSource ArrayList result = new ArrayList(); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_TRANSLATION, new String[] { BashgidSqliteHelper.COLUMN_NAME }, - BashgidSqliteHelper.COLUMN_TEXT_EN_UP + " LIKE ?", new String[] { "%" + partString + "%" }, null, null, null, null); + BashgidSqliteHelper.COLUMN_TEXT_EN_UP + " LIKE ?", new String[] { "%" + DatabaseDownloadTask.sqlEscapeString(partString) + "%" }, null, null, null, null); if (cursor != null) { @@ -274,7 +276,7 @@ public class TranslationDataSource ArrayList result = new ArrayList(); Cursor cursor = database.query(BashgidSqliteHelper.TABLE_TRANSLATION, new String[] { BashgidSqliteHelper.COLUMN_NAME }, - BashgidSqliteHelper.COLUMN_TEXT_ZH_UP + " LIKE ?", new String[] { "%" + partString + "%" }, null, null, null, null); + BashgidSqliteHelper.COLUMN_TEXT_ZH_UP + " LIKE ?", new String[] { "%" + DatabaseDownloadTask.sqlEscapeString(partString) + "%" }, null, null, null, null); if (cursor != null) { diff --git a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java index 7d325c0..3f525a6 100644 --- a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java @@ -1,6 +1,7 @@ package fishrungames.bashgid.core.db; import fishrungames.bashgid.MainActivity; +import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.VideoManager.VideoRecordData; import android.content.ContentValues; @@ -43,7 +44,7 @@ public class VideoDataSource database.insert(BashgidSqliteHelper.TABLE_VIDEO, null, values); } else { - database.update(BashgidSqliteHelper.TABLE_VIDEO, values, BashgidSqliteHelper.COLUMN_VIDEO_URL + " = " + "\"" + recordData.videoUrl + "\"", + database.update(BashgidSqliteHelper.TABLE_VIDEO, values, BashgidSqliteHelper.COLUMN_VIDEO_URL + " = " + "'" + DatabaseDownloadTask.sqlEscapeString_withquotes(recordData.videoUrl) + "'", null); } @@ -57,9 +58,9 @@ public class VideoDataSource public VideoRecordData GetVideoByVideoUrl(String videoUrl) { - VideoRecordData result = null; + VideoRecordData result = new VideoRecordData(0, "", "", "", "", ""); - SQLiteDatabase database = dbHelper.getWritableDatabase(); + SQLiteDatabase database = dbHelper.getReadableDatabase(); if (database != null) { @@ -79,12 +80,12 @@ public class VideoDataSource public VideoRecordData InnerGetVideoByVideoUrl(String videoUrl, SQLiteDatabase database) { - VideoRecordData result = null; + VideoRecordData result = new VideoRecordData(0, "", "", "", "", ""); Cursor cursor = database .query(BashgidSqliteHelper.TABLE_VIDEO, new String[] { BashgidSqliteHelper.COLUMN_TYPE, BashgidSqliteHelper.COLUMN_VIDEO_URL, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_PREVIEW_IMAGE_URL, - BashgidSqliteHelper.COLUMN_PREVIEW_IMAGE_HASH }, BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?", new String[] { videoUrl }, null, null, + BashgidSqliteHelper.COLUMN_PREVIEW_IMAGE_HASH }, BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(videoUrl) }, null, null, null, null); if (cursor != null) @@ -112,7 +113,7 @@ public class VideoDataSource boolean result = false; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL }, - BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?", new String[] { videoUrl }, null, null, null, null); + BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?", new String[] { DatabaseDownloadTask.sqlEscapeString(videoUrl) }, null, null, null, null); if (cursor != null) {