Fixing bugs

This commit is contained in:
Vladislav Khorev 2015-07-05 11:03:52 +00:00
parent 2345ed733c
commit b0021bbbf6
87 changed files with 2483 additions and 1167 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fishrungames.bashgid"
android:versionCode="1"
android:versionName="1.0" >
android:versionCode="2"
android:versionName="1.01" >
<uses-feature
android:glEsVersion="0x00020000"
@ -16,11 +16,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@ -34,8 +30,7 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait" >
android:configChanges="orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -45,11 +40,6 @@
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAN67lwiJpFHprBo7VOio4jAdSzIIOY4s8"/>
</application>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 828 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1022 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -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" />

View File

@ -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" />

View File

@ -7,14 +7,16 @@
android:orientation="vertical"
android:showDividers="middle" >
<fishrungames.bashgid.DynamicImageView
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
android:cropToPadding="false"
android:minHeight="10dp"
android:minWidth="10dp"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/dateTextView"

View File

@ -11,15 +11,17 @@
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<GridView
<fishrungames.bashgid.StaticGridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:horizontalSpacing="@dimen/grid_view_horizontal_spacing"
android:numColumns="@integer/grid_columns"
android:verticalSpacing="@dimen/grid_view_vertical_spacing" >
android:verticalSpacing="@dimen/grid_view_vertical_spacing"
android:isScrollContainer="false"
android:stretchMode="columnWidth" />
</GridView>
</LinearLayout>

View File

@ -7,7 +7,7 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
@ -20,4 +20,13 @@
</ListView>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="@dimen/progress_bar_size"
android:layout_height="@dimen/progress_bar_size"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
</LinearLayout>

View File

@ -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" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/large_margin"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="@dimen/large_margin"
android:layout_marginRight="@dimen/large_margin"
android:divider="@color/bkg2"
android:divider="@color/black"
android:dividerHeight="@dimen/small_divider_height" >
</ListView>

View File

@ -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" />

View File

@ -32,7 +32,9 @@
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin" />
</LinearLayout>
</ScrollView>

View File

@ -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" />
<ImageButton
android:id="@+id/image_flag_usa"
@ -65,7 +67,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/lang_russian"
android:textSize="@dimen/language_text_size" />
android:textColor="@color/text_white"
android:textSize="@dimen/language_text_size"
android:textStyle="bold" />
<ImageButton
android:id="@+id/image_flag_russia"
@ -94,7 +98,9 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/lang_chinese"
android:textSize="@dimen/language_text_size" />
android:textColor="@color/text_white"
android:textSize="@dimen/language_text_size"
android:textStyle="bold" />
<ImageButton
android:id="@+id/image_flag_china"

View File

@ -2,27 +2,27 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="@dimen/video_page_height"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/bkg1"
android:gravity="center_vertical"
android:orientation="vertical"
android:showDividers="middle" >
<fishrungames.bashgid.DynamicImageView
<fishrungames.bashgid.SquareImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_gravity="clip_vertical"
android:layout_margin="@dimen/medium_margin"
android:text="dsdsd"
android:textSize="@dimen/large_text_size"

View File

@ -13,6 +13,61 @@
android:background="@color/bkg2" />
<include layout="@layout/main_page_news"/>
<View
android:id="@+id/View01"
android:layout_width="match_parent"
android:layout_height="@dimen/large_divider_height"
android:background="@color/bkg2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bkg1"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="@+id/shortCatalogTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="@dimen/medium_margin"
android:text="@string/featured"
android:textSize="@dimen/large_text_size"
android:textStyle="bold" />
<ImageButton
android:id="@+id/refreshCatalogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/transparent"
android:src="@drawable/ic_action_refresh" />
</LinearLayout>
<ProgressBar
android:id="@+id/databaseDownloadProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="0" />
</LinearLayout>
</LinearLayout>

View File

@ -6,23 +6,40 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="@+id/selectLanguageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="@dimen/medium_margin"
android:text="@string/news_header"
android:textSize="@dimen/large_text_size"
android:textStyle="bold" />
<ImageButton
android:id="@+id/refreshNewsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/transparent"
android:src="@drawable/ic_action_refresh" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="@dimen/progress_bar_size"
android:layout_height="@dimen/progress_bar_size"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
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" />
<LinearLayout
android:layout_width="match_parent"
@ -36,6 +53,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:background="@drawable/transparent_button"
android:gravity="left|center_vertical"
android:minHeight="0dp"
@ -56,6 +74,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:background="@drawable/transparent_button"
android:gravity="left|center_vertical"
android:minHeight="0dp"
@ -76,6 +95,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/medium_margin"
android:layout_marginRight="@dimen/medium_margin"
android:background="@drawable/transparent_button"
android:gravity="left|center_vertical"
android:minHeight="0dp"
@ -90,7 +110,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/transparent"
android:layout_margin="@dimen/medium_margin"
android:background="@color/button_default"
android:padding="@dimen/medium_margin"
android:text="@string/other_news" />
</LinearLayout>

View File

@ -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" >
<requestFocus />
@ -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" />

View File

@ -8,22 +8,38 @@
android:paddingRight="20dp"
tools:context="fishrungames.bashgid.MainPageFragment" >
<TextView
android:id="@+id/dateTextView"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="@dimen/medium_margin"
android:text="@string/news_header"
android:textSize="@dimen/large_text_size"
android:textStyle="bold" />
android:layout_gravity="center_vertical|center_horizontal" >
<TextView
android:id="@+id/dateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="@dimen/medium_margin"
android:text="@string/news_header"
android:textSize="@dimen/large_text_size"
android:textStyle="bold" />
<ImageButton
android:id="@+id/refreshNewsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/transparent"
android:src="@drawable/ic_action_refresh" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="@dimen/progress_bar_size"
android:layout_height="@dimen/progress_bar_size"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
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" />
</LinearLayout>

View File

@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/light_grey_1"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:background="@color/black"
android:orientation="vertical"
android:showDividers="middle" >
<fishrungames.bashgid.DynamicImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
</LinearLayout>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light_grey_1"
android:orientation="vertical"
android:showDividers="middle" >
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:contentDescription="@string/related_image"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/dateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>

View File

@ -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" />
</LinearLayout>

View File

@ -7,20 +7,30 @@
tools:context="fishrungames.bashgid.SearchFragment" >
<TextView
android:id="@+id/addressTextView"
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="@dimen/medium_text_size"
android:textSize="@dimen/xlarge_text_size"
android:textStyle="bold" />
<TextView
android:id="@+id/smallHintTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/search_small_hint"
android:textSize="@dimen/xsmall_text_size" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/enter_search_query"
android:inputType="text" >
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:textSize="@dimen/medium_text_size" >
<requestFocus />
</EditText>
@ -28,6 +38,7 @@
<TextView
android:id="@+id/hintTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:textSize="@dimen/xsmall_text_size" />
</LinearLayout>

View File

@ -4,7 +4,7 @@
<item android:id="@+id/action_search"
android:title="@string/search_title"
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="always|withText"
app:showAsAction="always"
android:actionViewClass="android.widget.SearchView" />
</menu>

View File

@ -49,11 +49,6 @@
<string name="go_to_website">Перейти на сайт</string>
<string name="buy">Купить...</string>
<string name="read">Читать</string>
<string name="price">Стоимость: </string>
<string name="rub">Руб.</string>
<string name="journal_open_map">Показать на карте</string>
<string name="map_is_loading">Карта загружается...</string>
<string name="map_is_loaded">Карта загружена</string>
@ -74,7 +69,7 @@
<string name="search_is_performing">Идет поиск, пожалуйста, подождите...</string>
<string name="search_at_least_3_symbols">Чтобы начать поиск, введите как минимум 3 символа</string>
<string name="credits">Башгид (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</string>
<string name="credits">Башгид (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/</string>
<string name="call_support">У вас возникли трудности при работе с приложением? Нажмите сюда, чтобы позвонить в техподдержку.</string>
@ -90,6 +85,13 @@
<string name="category_is_loaded">Категория загружена</string>
<string name="search_small_hint">Чтобы искать во всех категориях, нажмите кнопку Поиск справа вверху</string>
<string name="littlefoxlilia_link" formatted="false">http://littlefoxlilia.ru/ru/%D0%BE-%D1%81%D0%B5%D0%B1%D0%B5/</string>
<string name="featured">Символы РБ</string>
</resources>

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">俄罗斯联邦巴什基尔自治共和国指南</string>
<string name="app_name">巴什科尔托斯坦指南</string>
<string name="navigation_drawer_open">打开导航窗口</string>
<string name="navigation_drawer_close">关闭导航窗口</string>
<string name="action_settings">设置</string>
@ -10,13 +11,13 @@
<string name="search_title">搜索标题</string>
<string name="enter_search_query">输入问题</string>
<string name="enter_search_query">输入关键词</string>
<string name="news_record_not_available">无法查看新闻记录</string>
<string name="other_news">其他新闻</string>
<string name="news_record_not_available">无法查看记录</string>
<string name="other_news">其他…</string>
<string name="see_all">查看所有新闻</string>
<string name="see_all">更多</string>
<string name="news_header">头条新闻</string>
@ -29,10 +30,10 @@
<string name="RB_Coat">标识</string>
<string name="drawer_header">俄罗斯联邦巴什基尔自治共和国指南</string>
<string name="drawer_header">巴什科尔托斯坦指南</string>
<string name="drawer_guide">指南</string>
<string name="drawer_news">新闻</string>
<string name="drawer_catalogue">目录</string>
<string name="drawer_catalogue">所有文章</string>
<string name="drawer_map">地图</string>
<string name="drawer_video">视频</string>
<string name="drawer_photo_gallery">图片库</string>
@ -40,12 +41,7 @@
<string name="drawer_for_investor">投资者信息</string>
<string name="drawer_settings">设置</string>
<string name="go_to_website">去现场</string>
<string name="buy">Buy</string>
<string name="read">Read</string>
<string name="price">Price: </string>
<string name="rub">RUB</string>
<string name="go_to_website">跳转至详细信息页面</string>
<string name="journal_open_map">在地图上显示</string>
@ -57,7 +53,7 @@
<string name="dialog_cancel">取消</string>
<string name="search_everywhere">全面搜索</string>
<string name="search_in">在%%搜索: </string>
<string name="search_in">在%%搜索: %%</string>
<string name="address_form">地址:</string>
<string name="copied_text">复制文本</string>
@ -65,23 +61,28 @@
<string name="search_result_count">搜索结果: %% 文章被找到</string>
<string name="search_is_performing">正在搜索,请稍等…</string>
<string name="search_at_least_3_symbols">输入关键字符,开始搜索</string>
<string name="search_at_least_3_symbols">请输入关键字并开始搜索</string>
<string name="credits">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</string>
<string name="credits">巴什科尔托斯坦指南 (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/</string>
<string name="call_support">Having problems with application? Click here to call support.</string>
<string name="call_support">程序出现问题?请点击这里寻求技术支持</string>
<string name="visit_kitap">Visit ГУП «Китап» website</string>
<string name="visit_kitap">查看“基塔普”公司网站</string>
<string name="visit_developer">Visit developer\'s website</string>
<string name="visit_developer">查看开发人员的个人网站</string>
<string name="visit_translator">Visit translator\'s website</string>
<string name="visit_translator">查看翻译人员的个人网站</string>
<string name="hold_address">Tap and hold address to copy it to clipboard.</string>
<string name="hold_address">请轻按地址直至复制到剪贴板</string>
<string name="category_is_loading">Category is loading...</string>
<string name="category_is_loaded">Category is loaded</string>
<string name="category_is_loading">正在加载目录...</string>
<string name="category_is_loaded">目录加载完毕</string>
<string name="search_small_hint">如果您想要搜索所有的目录,请点击右上角的搜索按钮</string>
<string name="littlefoxlilia_link" formatted="false">http://littlefoxlilia.ru/zh/%E5%85%B3%E4%BA%8E%E6%88%91/</string>
<string name="featured">巴什科尔托斯坦特色</string>
</resources>

View File

@ -27,6 +27,7 @@
<color name="bkg2">#d0d0d0</color>
<color name="button_default">#e0e0e0</color>
<color name="drawer_color">#202020</color>

View File

@ -49,12 +49,7 @@
<string name="go_to_website">Go to website</string>
<string name="buy">Buy</string>
<string name="read">Read</string>
<string name="price">Price: </string>
<string name="rub">RUB</string>
<string name="journal_open_map">Show on map</string>
<string name="map_is_loading">Map is loading...</string>
<string name="map_is_loaded">Map is loaded</string>
@ -75,7 +70,7 @@
<string name="search_is_performing">Search is performing, please wait...</string>
<string name="search_at_least_3_symbols">To start search, enter at least 3 symbols</string>
<string name="credits">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</string>
<string name="credits">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/</string>
<string name="call_support">Having problems with application? Click here to call support.</string>
@ -91,6 +86,11 @@
<string name="category_is_loaded">Category is loaded</string>
<string name="search_small_hint">If you want to search in all categories, click search button at top right</string>
<string name="littlefoxlilia_link" formatted="false">http://littlefoxlilia.ru/en/about/</string>
<string name="featured">Featured RB</string>
</resources>

View File

@ -32,13 +32,14 @@ public class AlbumListFragment extends Fragment
GridView gridView;
ArrayList<AlbumShortData> albumArr;
ArrayList<AlbumShortData> albumArr = new ArrayList<AlbumShortData>();
ProgressBar progressBar;
DatabaseGetAlbumListTask databaseGetAlbumListTask = null;
public AlbumListFragment()
{
RestoreAlbumList();
}
public AlbumListFragment(ArrayList<AlbumShortData> 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<AlbumShortData>();
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<AlbumShortData> 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<String, Integer, Long>
{
@ -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;
}

View File

@ -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<ArticleLayoutElement> articleLayout = new ArrayList<ArticleLayoutElement>();
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);

View File

@ -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<JournalSemiFullData> journalList;
ArrayList<JournalSemiFullData> journalList = new ArrayList<JournalSemiFullData>();
DatabaseGetJournalListTask databaseGetJournalListTask = null;
public CatalogFragment()
{
RestoreJournalList();
}
public CatalogFragment(ArrayList<JournalSemiFullData> 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<JournalSemiFullData>();
CancelTaskIfRunning();
//journalList = new ArrayList<JournalSemiFullData>();
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<JournalSemiFullData> 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
{

View File

@ -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();

View File

@ -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
{

View File

@ -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<String> queuedImgUrlArr = new ArrayList<String>();
private ArrayList<String> queuedImgHashArr = new ArrayList<String>();
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<JournalSemiFullData>) 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<AlbumShortData> albumShortList = (ArrayList<AlbumShortData>) 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<ArticleShortData>) inputMessage.obj);
break;
case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE:
case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED:
UpdateOnGeoJournalListLoaded((ArrayList<JournalRecordData>) 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<JournalSemiFullData> journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(3);
Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList);
completeMessage.sendToTarget();
}
if (catalogFragment != null)
{
ArrayList<JournalSemiFullData> journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(3);
Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList);
completeMessage.sendToTarget();
}
}
/*
public void StartDownloadImagesTask(ArrayList<String> imageUrlArr, ArrayList<String> 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()

View File

@ -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<JournalSemiFullData>();
if (databaseGetJournalListTask != null)
{
databaseGetJournalListTask.cancel(false);
}
databaseGetJournalListTask = new DatabaseGetJournalListTask();
databaseGetJournalListTask.mHandler = MainActivity.getInstance().mHandler;
databaseGetJournalListTask.execute("featured");
}
public void SetJournalList(ArrayList<JournalSemiFullData> 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);
}

View File

@ -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()
{

View File

@ -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
{

View File

@ -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<JournalRecordData> availableGeoJournals;
ArrayList<String> availableGeoJournalNames;
ArrayList<JournalRecordData> availableGeoJournals = new ArrayList<JournalRecordData>();
ArrayList<String> availableGeoJournalNames = new ArrayList<String>();
ArrayAdapter<String> 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<JournalRecordData>();
availableGeoJournalNames = new ArrayList<String>();
}
public OsmMapHolderFragment(int filterType, String filter)
{
this.journal = null;
this.article = null;
this.filter = filter;
this.filterType = filterType;
availableGeoJournals = new ArrayList<JournalRecordData>();
availableGeoJournalNames = new ArrayList<String>();
}
public OsmMapHolderFragment(ArticleFullData article)
@ -338,10 +333,6 @@ public class OsmMapHolderFragment extends Fragment
this.article = article;
this.journal = null;
availableGeoJournals = new ArrayList<JournalRecordData>();
availableGeoJournalNames = new ArrayList<String>();
}
@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<String>(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<JournalRecordData> availableGeoJournals)
{
databaseGetGeoJournalListTask = null;
this.availableGeoJournals = availableGeoJournals;
availableGeoJournalNames.clear();

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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<ArticleShortData> searchResultArr = new ArrayList<ArticleShortData>();
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<ArticleShortData> 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);
}
}
}

View File

@ -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);
}
});

View File

@ -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);
}*/
}
}

View File

@ -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);
}
}

View File

@ -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<String, Integer, Long>
@ -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;
}

View File

@ -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()
{

View File

@ -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);
}
}*/
}

View File

@ -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;

View File

@ -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<ArticleShortData> {
public int compare(ArticleShortData record1, ArticleShortData record2) {
return record2.name.compareTo(record1.name);

View File

@ -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;

View File

@ -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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
{
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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;
}
}

View File

@ -24,9 +24,9 @@ public class DatabaseGetAlbumTask extends AsyncTask<String, Integer, Long>
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();
}

View File

@ -11,20 +11,18 @@ import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
public class DatabaseGetJournalListTask extends AsyncTask<String, Integer, Long>
{
ArrayList<JournalSemiFullData> journalList;
ArrayList<JournalSemiFullData> 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<JournalSemiFullData> 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();
}

View File

@ -12,8 +12,6 @@ public class DatabaseGetJournalTask extends AsyncTask<Bundle, Integer, Long>
JournalSemiFullData journal = null;
public Handler mHandler;
protected Long doInBackground(Bundle... queryArr)
{
@ -30,15 +28,15 @@ public class DatabaseGetJournalTask extends AsyncTask<Bundle, Integer, Long>
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();
}

View File

@ -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;
}
}

View File

@ -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<Bundle, Integer, Long>
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<Bundle, Integer, Long>
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();
}
}

View File

@ -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<String> ExtractEnclosureImageUrl(ArrayList<RssReader.Rss2Item> rss2ItemArr)
{
ArrayList<String> imageToDownloadList = new ArrayList<String>();
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<String> ExtractDescriptionImageUrl(ArrayList<RssReader.Rss2Item> rss2ItemArr)
{
ArrayList<String> imageToDownloadList = new ArrayList<String>();
for (RssReader.Rss2Item rss2Item : rss2ItemArr)
{
//And images inside text
// And images inside text
int i = rss2Item.description.indexOf("<img");
while (i != -1)
{
int j = rss2Item.description.indexOf("src=\"", i);
if (j != -1)
{
j += ("src=\"").length();
int k = rss2Item.description.indexOf("\"", j);
String imageUrl = rss2Item.description.substring(j, k);
imageToDownloadList.add(imageUrl);
}
i = rss2Item.description.indexOf("<img", j);
}
}
return imageToDownloadList;
}
public static ArrayList<String> ConvertRelativeToAbsoluteImageUrlList(ArrayList<String> relativeImageUrlList, String url)
{
ArrayList<String> absoluteImageUrlList = new ArrayList<String>();
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<RssReader.Rss2Item> rss2ItemArr, ArrayList<String> relativeImageUrlList, ArrayList<String> absoluteImageUrlList)
static void ReplaceRemoteUrlToLocalUrl(ArrayList<RssReader.Rss2Item> rss2ItemArr, ArrayList<String> relativeImageUrlList,
ArrayList<String> 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();
}
}
}
}

View File

@ -39,4 +39,12 @@ public class TranslationManager
}
}
public static TranslationRecordData CreateEmptyTranslation()
{
TranslationRecordData result = new TranslationRecordData("", "", "", "", "", "", "");
return result;
}
}

View File

@ -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;

View File

@ -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<AlbumShortData> result = new ArrayList<AlbumShortData>();
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<String> result = new ArrayList<String>();
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)
{

View File

@ -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<ArticleManager.ArticleRecordData> {
public int compare(ArticleManager.ArticleRecordData record1, ArticleManager.ArticleRecordData record2) {
return record2.dateTime.compareTo(record1.dateTime);
}
public static class DateSortComparator implements Comparator<ArticleManager.ArticleRecordData>
{
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<String> albumNameArr = innerGetAlbumNameArrInArticle(name, database);
ArticleFullData result = new ArticleFullData(ArticleManager.CreateEmptyArticle());
for (String albumName : albumNameArr)
{
result.albumArr.add(MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumName, database));
}
ArrayList<String> channelNameArr = innerGetChannelNameArrInArticle(name, database);
ArticleRecordData recordData = innerGetArticleByName(name, database);
if (recordData != null)
{
result = new ArticleFullData(recordData);
ArrayList<String> albumNameArr = innerGetAlbumNameArrInArticle(name, database);
for (String albumName : albumNameArr)
{
result.albumArr.add(MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumName, database));
}
ArrayList<String> 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<ArticleShortData> SearchArticleByTitleOrText(String query)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
try
{
ArrayList<String> articleNameArr = InnerSearchArticleByTitleOrText(query, database);
for (String articleName : articleNameArr)
{
result.add(InnerGetArticleShortData(articleName, database));
}
} finally
{
dbHelper.close();
}
}
return result;
}
public ArrayList<ArticleShortData> SearchArticleByTitleOrTextInJournal(String query, String journalName)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
try
{
ArrayList<String> 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<ArticleShortData> SearchArticleByQuery(String query)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
try
{
result = InnerSearchArticleByQuery(query, database);
} finally
{
dbHelper.close();
}
}
return result;
}
public ArrayList<ArticleShortData> SearchArticleByQueryAndJournal(String query, String journalName)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
try
{
ArrayList<ArticleShortData> 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<ArticleShortData> InnerSearchArticleByQuery(String query, SQLiteDatabase database)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
ArrayList<ArticleRecordData> recordDataArr = innerGetArticlesByQuery(query, database);
for (int i = 0; i < recordDataArr.size(); i++)
{
ArticleShortData article = new ArticleShortData(recordDataArr.get(i));
article.previewImageUrl = getPreviewImageUrlForArticle(recordDataArr.get(i).name, database);
result.add(article);
}
return result;
}
public ArrayList<ArticleShortData> InnerSearchArticleByQuery(String query, SQLiteDatabase database)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
ArrayList<ArticleRecordData> recordDataArr = innerGetArticlesByQuery(query, database);
for (int i = 0; i < recordDataArr.size(); i++)
{
ArticleShortData article = new ArticleShortData(recordDataArr.get(i));
article.previewImageUrl = getPreviewImageUrlForArticle(recordDataArr.get(i).name, database);
result.add(article);
}
return result;
}
public 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<String> albumNameArr = innerGetAlbumNameArrInArticle(name, database);
if (albumNameArr.size() > 0)
{
AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database);
if (album.photoRecordArr.size() > 0)
{
result = album.photoRecordArr.get(0).imageUrl;
}
}
if (result.equals("R.drawable.no_picture"))
{
ArrayList<String> channelNameArr = innerGetChannelNameArrInArticle(name, database);
if (channelNameArr.size() > 0)
{
ChannelFullData channelFullData = MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database);
if (channelFullData.videoRecordArr.size() > 0)
{
result = channelFullData.videoRecordArr.get(0).previewImageUrl;
}
}
}
return result;
}
private boolean innerIsArticleAlreadyExist(String name, SQLiteDatabase database)
{
boolean result = false;
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<ArticleRecordData> innerGetArticlesByQuery(String query, SQLiteDatabase database)
{
ArrayList<ArticleRecordData> result = new ArrayList<ArticleRecordData>();
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] {
BashgidSqliteHelper.COLUMN_NAME,
BashgidSqliteHelper.COLUMN_TYPE,
BashgidSqliteHelper.COLUMN_TITLE,
BashgidSqliteHelper.COLUMN_CONTENT,
BashgidSqliteHelper.COLUMN_GEOLAT,
BashgidSqliteHelper.COLUMN_GEOLON,
BashgidSqliteHelper.COLUMN_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<String> InnerSearchArticleByTitleOrText(String query, SQLiteDatabase database)
{
ArrayList<String> result = new ArrayList<String>();
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<String> innerGetAlbumNameArrInArticle(String name, SQLiteDatabase database)
{
ArrayList<String> result = new ArrayList<String>();
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<String> innerGetChannelNameArrInArticle(String name, SQLiteDatabase database)
{
ArrayList<String> result = new ArrayList<String>();
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;
}
}

View File

@ -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

View File

@ -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<String> result = new ArrayList<String>();
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)

View File

@ -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<JournalSemiFullData> GetAllJournalListExceptHidden(int count)
{
ArrayList<JournalSemiFullData> result = new ArrayList<JournalSemiFullData>();
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<JournalSemiFullData> result = new ArrayList<JournalSemiFullData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
@ -282,7 +283,7 @@ public class JournalDataSource
public ArrayList<JournalRecordData> GetGeoJournalList()
{
ArrayList<JournalRecordData> result = new ArrayList<JournalRecordData>();
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<String> result = new ArrayList<String>();
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<String> result = new ArrayList<String>();
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)
{

View File

@ -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)
{

View File

@ -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<String> result = new ArrayList<String>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
@ -105,7 +107,7 @@ public class TranslationDataSource
{
ArrayList<String> result = new ArrayList<String>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
SQLiteDatabase database = dbHelper.getReadableDatabase();
if (database != null)
{
@ -127,7 +129,7 @@ public class TranslationDataSource
{
ArrayList<String> result = new ArrayList<String>();
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<String> result = new ArrayList<String>();
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<String> result = new ArrayList<String>();
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<String> result = new ArrayList<String>();
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)
{

View File

@ -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)
{