Added SQLite, added languages
This commit is contained in:
parent
628f816a9e
commit
f50fd1ac61
@ -12,5 +12,4 @@
|
||||
|
||||
# Project target.
|
||||
target=android-21
|
||||
android.library.reference.1=..\\appcompat_v7
|
||||
android.library.reference.2=../HorizontalListViewLibrary
|
||||
android.library.reference.1=..\\HorizontalListViewLibrary
|
||||
|
9
android/res/drawable/transparent_button.xml
Normal file
9
android/res/drawable/transparent_button.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/transparent" />
|
||||
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/transparent_highlighted" />
|
||||
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/transparent_highlighted" />
|
||||
<item android:drawable="@drawable/transparent" />
|
||||
|
||||
</selector>
|
8
android/res/drawable/transparent_highlighted.xml
Normal file
8
android/res/drawable/transparent_highlighted.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/transparent"/>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@color/button_highlighted" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
@ -12,13 +12,13 @@
|
||||
android:id="@+id/imageButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/related_image" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="TextView" />
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -9,11 +9,11 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_margin="4dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:src="@drawable/test_drawer_icon" />
|
||||
android:contentDescription="@string/icon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
@ -22,7 +22,7 @@
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="4dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:text="TextView"
|
||||
android:text=""
|
||||
android:textColor="@color/text_white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
22
android/res/layout/fragment_news_page.xml
Normal file
22
android/res/layout/fragment_news_page.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="0dp"
|
||||
android:background="@color/bkg1"
|
||||
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_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:divider="@color/bkg2"
|
||||
android:dividerHeight="2dp"
|
||||
android:paddingBottom="16dp" >
|
||||
|
||||
</ListView>
|
||||
|
||||
</LinearLayout>
|
38
android/res/layout/fragment_news_record_page.xml
Normal file
38
android/res/layout/fragment_news_record_page.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="0dp"
|
||||
android:background="@color/bkg1"
|
||||
tools:context="fishrungames.bashgid.MainPageFragment" >
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColorHint="@color/text_black"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:src="@drawable/transparent"
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descriptionTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
@ -29,7 +29,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/news_content_description_1" />
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/news1TextView"
|
||||
@ -51,7 +51,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/news_content_description_2" />
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/news2TextView"
|
||||
@ -73,7 +73,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/news_content_description_3" />
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/news3TextView"
|
||||
@ -92,3 +92,4 @@
|
||||
android:text="@string/other_news" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
33
android/res/layout/news_page_list_element.xml
Normal file
33
android/res/layout/news_page_list_element.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:background="@color/bkg1"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingTop="4dp"
|
||||
android:showDividers="middle" >
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_margin="6dp"
|
||||
android:background="@drawable/transparent"
|
||||
android:src="@drawable/transparent_button"
|
||||
android:contentDescription="@string/news_content_description" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/transparent_button"
|
||||
android:gravity="left|center_vertical"
|
||||
android:minHeight="0dip"
|
||||
android:minWidth="0dip"
|
||||
android:textColor="@color/text_grey" />
|
||||
|
||||
</LinearLayout>
|
21
android/res/layout/news_page_list_header.xml
Normal file
21
android/res/layout/news_page_list_header.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bkg1"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
tools:context="fishrungames.bashgid.MainPageFragment" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="8dp"
|
||||
android:text="@string/news_header"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
@ -3,10 +3,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="fishrungames.bashgid.MainActivity" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_example"
|
||||
android:title="@string/action_example"
|
||||
app:showAsAction="withText|ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
41
android/res/values-ru/strings.xml
Normal file
41
android/res/values-ru/strings.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Гид РБ</string>
|
||||
|
||||
<string name="navigation_drawer_open">Открыть левую панель</string>
|
||||
<string name="navigation_drawer_close">Закрыть левую панель</string>
|
||||
|
||||
<string name="action_settings">Настройки</string>
|
||||
|
||||
<string name="search_title">Поиск</string>
|
||||
|
||||
<string name="news_record_not_available">Запись недоступна</string>
|
||||
<string name="other_news">Другие новости…</string>
|
||||
|
||||
<string name="see_all">Посмотреть все</string>
|
||||
|
||||
|
||||
<string name="news_header">Новости</string>
|
||||
|
||||
<string name="news_content_description">Картинка к новости</string>
|
||||
|
||||
<string name="related_image">Картинка к странице</string>
|
||||
<string name="icon">Иконка</string>
|
||||
|
||||
|
||||
|
||||
<string name="RB_Coat">Логотип</string>
|
||||
|
||||
<string name="drawer_header">Гид РБ</string>
|
||||
<string name="drawer_guide">Гид</string>
|
||||
<string name="drawer_news">Новости</string>
|
||||
<string name="drawer_catalogue">Каталог</string>
|
||||
<string name="drawer_map">Карта</string>
|
||||
<string name="drawer_video">Видео</string>
|
||||
<string name="drawer_photo_gallery">Фотогалерея</string>
|
||||
<string name="drawer_for_investor">Инвестору</string>
|
||||
<string name="drawer_settings">Настройки</string>
|
||||
|
||||
|
||||
</resources>
|
38
android/res/values-zh-rCN/strings.xml
Normal file
38
android/res/values-zh-rCN/strings.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">巴什科尔托斯坦指南</string>
|
||||
<string name="navigation_drawer_open">打开导航窗格</string>
|
||||
<string name="navigation_drawer_close">关闭导航窗格</string>
|
||||
<string name="action_settings">设置</string>
|
||||
|
||||
<string name="search_title">搜索</string>
|
||||
|
||||
<string name="news_record_not_available">文章不可</string>
|
||||
<string name="other_news">其他新闻…</string>
|
||||
|
||||
<string name="see_all">查看更多新闻</string>
|
||||
|
||||
|
||||
<string name="news_header">新闻</string>
|
||||
|
||||
<string name="news_content_description">图片相关的新闻</string>
|
||||
|
||||
<string name="related_image">图片相关文章</string>
|
||||
<string name="icon">图标</string>
|
||||
|
||||
<string name="RB_Coat">徽标</string>
|
||||
|
||||
<string name="drawer_header">巴什科尔托斯坦指南</string>
|
||||
<string name="drawer_guide">指南</string>
|
||||
<string name="drawer_news">新闻</string>
|
||||
<string name="drawer_catalogue">目录</string>
|
||||
<string name="drawer_map">地图</string>
|
||||
<string name="drawer_video">视频</string>
|
||||
<string name="drawer_photo_gallery">图片库</string>
|
||||
<string name="drawer_for_investor">投资者信息</string>
|
||||
<string name="drawer_settings">设置</string>
|
||||
|
||||
|
||||
|
||||
</resources>
|
@ -9,6 +9,11 @@
|
||||
<color name="light_grey_1">#60d0d0d0</color>
|
||||
|
||||
<color name="text_white">#F0F0F0</color>
|
||||
|
||||
<color name="text_black">#080808</color>
|
||||
|
||||
<color name="text_grey">#808080</color>
|
||||
|
||||
|
||||
<color name="teaser_color">#2B517F</color>
|
||||
|
||||
|
@ -1,35 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Гид РБ</string>
|
||||
<string name="title_section1">Section 1</string>
|
||||
<string name="title_section2">Section 2</string>
|
||||
<string name="title_section3">Section 3</string>
|
||||
<string name="app_name">RB Guide</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="action_example">Example action</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
|
||||
|
||||
<string name="lang_english">English</string>
|
||||
<string name="lang_russian">Russian</string>
|
||||
<string name="lang_chinese">Chinese</string>
|
||||
<string name="lang_russian">Русский</string>
|
||||
<string name="lang_chinese">中文</string>
|
||||
|
||||
|
||||
|
||||
<string name="search_title">Поиск</string>
|
||||
<string name="search_title">Search</string>
|
||||
|
||||
<string name="news_record_not_available">Запись недоступна</string>
|
||||
<string name="other_news">Другие новости...</string>
|
||||
<string name="news_record_not_available">Record is not available</string>
|
||||
<string name="other_news">Other news…</string>
|
||||
|
||||
<string name="news_header">Новости</string>
|
||||
|
||||
<string name="news_content_description_1">Image related to news record</string>
|
||||
<string name="news_content_description_2">Image related to news record</string>
|
||||
<string name="news_content_description_3">Image related to news record</string>
|
||||
<string name="see_all">See all</string>
|
||||
|
||||
|
||||
|
||||
<string name="RB_Coat">Coat of Bashkortostan</string>
|
||||
<string name="news_header">News</string>
|
||||
|
||||
<string name="news_content_description">Image related to news record</string>
|
||||
|
||||
<string name="related_image">Related image</string>
|
||||
<string name="icon">Icon</string>
|
||||
|
||||
<string name="RB_Coat">Logo</string>
|
||||
|
||||
<string name="drawer_header">RB Guide</string>
|
||||
<string name="drawer_guide">Guide</string>
|
||||
<string name="drawer_news">News</string>
|
||||
<string name="drawer_catalogue">Catalogue</string>
|
||||
<string name="drawer_map">Map</string>
|
||||
<string name="drawer_video">Video</string>
|
||||
<string name="drawer_photo_gallery">Photo gallery</string>
|
||||
<string name="drawer_for_investor">For investor</string>
|
||||
<string name="drawer_settings">Settings</string>
|
||||
|
||||
|
||||
|
||||
</resources>
|
||||
|
@ -1,28 +1,21 @@
|
||||
package fishrungames.bashgid;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
import fishrungames.bashgid.core.db.NewsDataSource;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -34,6 +27,8 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
private NavigationDrawerFragment mNavigationDrawerFragment = null;
|
||||
|
||||
public NewsDataSource newsDataSource;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -44,13 +39,14 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new WelcomeFragment()).commit();
|
||||
|
||||
|
||||
instance = this;
|
||||
|
||||
|
||||
newsDataSource = new NewsDataSource(this);
|
||||
|
||||
newsDataSource.open();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static MainActivity getInstance()
|
||||
{
|
||||
return instance;
|
||||
@ -60,16 +56,42 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
public void OnSelectEnglish(View view)
|
||||
{
|
||||
Locale.setDefault(Locale.US);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = Locale.US;
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
getSupportActionBar().setTitle(R.string.app_name);
|
||||
|
||||
SetupDrawer();
|
||||
|
||||
OpenMainScreen();
|
||||
}
|
||||
|
||||
public void OnSelectRussian(View view)
|
||||
{
|
||||
Locale locale = new Locale("ru");
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
getSupportActionBar().setTitle(R.string.app_name);
|
||||
SetupDrawer();
|
||||
|
||||
OpenMainScreen();
|
||||
}
|
||||
|
||||
public void OnSelectChinese(View view)
|
||||
{
|
||||
Locale.setDefault(Locale.CHINA);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = Locale.CHINA;
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
getSupportActionBar().setTitle(R.string.app_name);
|
||||
SetupDrawer();
|
||||
|
||||
OpenMainScreen();
|
||||
}
|
||||
|
||||
@ -81,13 +103,27 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
public void OpenMainScreen()
|
||||
{
|
||||
|
||||
//mainFragment = new MainFragment();
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MainPageFragment()).commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
public void OpenNewsScreen()
|
||||
{
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NewsListFragment()).commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
public void OpenNewsRecordScreen(NewsRecord newsRecord)
|
||||
{
|
||||
//Xperimental -- addToBackStack provoke error "Class not found". Need to resolve somehow!
|
||||
//getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NewsRecordFragment(newsRecord)).addToBackStack(null).commit();
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NewsRecordFragment(newsRecord)).commit();
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachFragment(Fragment fragment)
|
||||
@ -135,17 +171,40 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
|
||||
@Override
|
||||
public void onNavigationDrawerItemSelected(int position) {
|
||||
// update the main content by replacing fragments
|
||||
//FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
//fragmentManager.beginTransaction()
|
||||
// .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
|
||||
// .commit();
|
||||
public void onNavigationDrawerItemSelected(int position)
|
||||
{
|
||||
if (position == 1)
|
||||
{
|
||||
OpenMainScreen();
|
||||
}
|
||||
else if (position == 2)
|
||||
{
|
||||
OpenNewsScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if(getSupportFragmentManager().getBackStackEntryCount() != 0) {
|
||||
getSupportFragmentManager().popBackStack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
newsDataSource.open();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
newsDataSource.close();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
@ -44,6 +45,8 @@ public class MainPageFragment extends Fragment implements NewsUpdatedCallbackInt
|
||||
|
||||
ListView listView;
|
||||
View header;
|
||||
|
||||
NewsManager.RemoveCallbackInterface downloadNewsCanceller;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -57,13 +60,34 @@ public class MainPageFragment extends Fragment implements NewsUpdatedCallbackInt
|
||||
|
||||
RefreshHeader();
|
||||
|
||||
NewsManager.GetInstance().DownloadNews(this);
|
||||
downloadNewsCanceller = NewsManager.GetInstance().DownloadNews(this);
|
||||
|
||||
listView.addHeaderView(header);
|
||||
|
||||
Button moreNewsButton = (Button) header.findViewById(R.id.moreNewsButton);
|
||||
|
||||
moreNewsButton.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MainActivity.getInstance().OpenNewsScreen();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
downloadNewsCanceller.RemoveCallback();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void RefreshHeader()
|
||||
{
|
||||
@ -176,11 +200,8 @@ public class MainPageFragment extends Fragment implements NewsUpdatedCallbackInt
|
||||
|
||||
textView.setText(teaserHeaderArray[position]);
|
||||
|
||||
button.setText("Посмотреть все");
|
||||
|
||||
|
||||
|
||||
|
||||
button.setText(R.string.see_all);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
package fishrungames.bashgid;
|
||||
|
||||
import it.sephiroth.android.library.widget.HListView;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@ -67,10 +65,8 @@ public class MainPageHListViewAdapters {
|
||||
|
||||
subTextView.setText(subTextsArray[position]);
|
||||
|
||||
//imageButton.setImageResource(imgIdArray[position]);
|
||||
imageButton.setBackgroundResource(imgIdArray[position]);
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
@ -64,9 +63,10 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
private int mCurrentSelectedPosition = 0;
|
||||
private boolean mFromSavedInstanceState;
|
||||
private boolean mUserLearnedDrawer;
|
||||
|
||||
private DrawerAdapter drawerAdapter;
|
||||
|
||||
public NavigationDrawerFragment() {
|
||||
String s = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +75,7 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
|
||||
// Read in the flag indicating whether or not the user has demonstrated awareness of the
|
||||
// drawer. See PREF_USER_LEARNED_DRAWER for details.
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
//SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
//Don't need this shit
|
||||
//mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
|
||||
@ -110,7 +110,10 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
mDrawerListView.setAdapter(new DrawerAdapter(getActivity()));
|
||||
|
||||
drawerAdapter = new DrawerAdapter(getActivity());
|
||||
|
||||
mDrawerListView.setAdapter(drawerAdapter);
|
||||
|
||||
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
|
||||
return mDrawerListView;
|
||||
@ -202,6 +205,8 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
|
||||
drawerAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
@ -261,11 +266,13 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
//Xperimental -- check if we need options or not
|
||||
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.getItemId() == R.id.action_example) {
|
||||
if (item.getItemId() == R.id.action_settings) {
|
||||
Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
@ -302,17 +309,18 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
|
||||
public class DrawerAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
|
||||
|
||||
final String [] titles = {
|
||||
"Виртуальный гид",
|
||||
"Гид",
|
||||
"Новости",
|
||||
"Каталог",
|
||||
"Карта",
|
||||
"Видео",
|
||||
"Фотогалерея",
|
||||
"Инвестору",
|
||||
"Настройки"
|
||||
final int [] titles = {
|
||||
R.string.drawer_header,
|
||||
R.string.drawer_guide,
|
||||
R.string.drawer_news,
|
||||
R.string.drawer_catalogue,
|
||||
R.string.drawer_map,
|
||||
R.string.drawer_video,
|
||||
R.string.drawer_photo_gallery,
|
||||
R.string.drawer_for_investor,
|
||||
R.string.drawer_settings
|
||||
};
|
||||
|
||||
final int [] iconIds = {
|
||||
@ -377,8 +385,8 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
else
|
||||
{
|
||||
LayoutParams params = imageView.getLayoutParams();
|
||||
params.width = 24;
|
||||
params.height = 24;
|
||||
params.width = 48;
|
||||
params.height = 48;
|
||||
imageView.setLayoutParams(params);
|
||||
|
||||
textView.setTypeface(null, Typeface.NORMAL);
|
||||
|
151
android/src/fishrungames/bashgid/NewsListFragment.java
Normal file
151
android/src/fishrungames/bashgid/NewsListFragment.java
Normal file
@ -0,0 +1,151 @@
|
||||
package fishrungames.bashgid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
import fishrungames.bashgid.core.ImageManager;
|
||||
import fishrungames.bashgid.core.NewsManager;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsUpdatedCallbackInterface;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
|
||||
|
||||
public class NewsListFragment extends Fragment implements NewsUpdatedCallbackInterface
|
||||
{
|
||||
|
||||
ListView listView;
|
||||
|
||||
ListAdapter listAdapter;
|
||||
|
||||
ArrayList<NewsRecord> newsRecordArr;
|
||||
|
||||
NewsManager.RemoveCallbackInterface downloadNewsCanceller;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_news_page, container, false);
|
||||
|
||||
newsRecordArr = NewsManager.GetInstance().getNews();
|
||||
|
||||
downloadNewsCanceller = NewsManager.GetInstance().DownloadNews(this);
|
||||
|
||||
listView = (ListView) rootView.findViewById(R.id.listView);
|
||||
|
||||
listAdapter = new ListAdapter(getActivity());
|
||||
|
||||
listView.setAdapter(listAdapter);
|
||||
|
||||
View header = inflater.inflate(R.layout.news_page_list_header, null);
|
||||
|
||||
listView.addHeaderView(header);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
downloadNewsCanceller.RemoveCallback();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public void RefreshNewsList()
|
||||
{
|
||||
newsRecordArr = NewsManager.GetInstance().getNews();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public class ListAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
|
||||
public ListAdapter(Context c) {
|
||||
mContext = c;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return newsRecordArr.size();
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// create a new ImageView for each item referenced by the Adapter
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
|
||||
|
||||
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.news_page_list_element, null);
|
||||
|
||||
|
||||
} else {
|
||||
view = convertView;
|
||||
}
|
||||
|
||||
ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);
|
||||
|
||||
Button button = (Button) view.findViewById(R.id.button);
|
||||
|
||||
ImageManager.getInstance().ApplyImageToImageView(imageButton, newsRecordArr.get(position).imageId);
|
||||
|
||||
button.setText(newsRecordArr.get(position).title);
|
||||
|
||||
button.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(position)));
|
||||
|
||||
imageButton.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(position)));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void OnNewsUpdated()
|
||||
{
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
RefreshNewsList();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static class ButtonOnClickListener implements OnClickListener
|
||||
{
|
||||
|
||||
NewsRecord newsRecord;
|
||||
|
||||
public ButtonOnClickListener(NewsRecord newsRecord)
|
||||
{
|
||||
this.newsRecord = newsRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MainActivity.getInstance().OpenNewsRecordScreen(newsRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
42
android/src/fishrungames/bashgid/NewsRecordFragment.java
Normal file
42
android/src/fishrungames/bashgid/NewsRecordFragment.java
Normal file
@ -0,0 +1,42 @@
|
||||
package fishrungames.bashgid;
|
||||
|
||||
|
||||
import fishrungames.bashgid.core.ImageManager;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class NewsRecordFragment extends Fragment
|
||||
{
|
||||
|
||||
NewsRecord newsRecord;
|
||||
|
||||
public NewsRecordFragment(NewsRecord newsRecord)
|
||||
{
|
||||
this.newsRecord = newsRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_news_record_page, container, false);
|
||||
|
||||
TextView titleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
|
||||
|
||||
TextView descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView);
|
||||
|
||||
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
|
||||
|
||||
titleTextView.setText(newsRecord.title);
|
||||
descriptionTextView.setText(newsRecord.description);
|
||||
|
||||
ImageManager.getInstance().ApplyImageToImageView(imageView, newsRecord.imageId);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
}
|
@ -1,22 +1,15 @@
|
||||
package fishrungames.bashgid.core;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.util.ByteArrayBuffer;
|
||||
import org.apache.http.util.CharArrayBuffer;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
|
||||
public class DownloadManager {
|
||||
|
||||
@ -54,4 +47,10 @@ public class DownloadManager {
|
||||
// return XML
|
||||
return xml;
|
||||
}
|
||||
|
||||
|
||||
public static boolean MimeTypeIsImage(String mimeType)
|
||||
{
|
||||
return mimeType.equals("image/bmp") || mimeType.equals("image/gif") || mimeType.equals("image/jpeg") || mimeType.equals("image/png");
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,18 @@
|
||||
package fishrungames.bashgid.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
import fishrungames.bashgid.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@ -49,6 +58,67 @@ public class ImageManager {
|
||||
|
||||
imageView.setImageResource(resourceId);
|
||||
}
|
||||
else
|
||||
{
|
||||
String fileName = ImageUrlToFileName(imageId);
|
||||
|
||||
File f = MainActivity.getInstance().getFileStreamPath(fileName);
|
||||
|
||||
if (f.exists())
|
||||
{
|
||||
Bitmap bitmap = BitmapFactory.decodeFile( MainActivity.getInstance().getFileStreamPath(fileName).getAbsolutePath());
|
||||
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e("Error: ", "Image requested but not downloaded: " + imageId);
|
||||
|
||||
imageView.setImageResource(R.drawable.transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String ImageUrlToFileName(String imageUrl)
|
||||
{
|
||||
String beforeExtension = imageUrl.substring(0, imageUrl.lastIndexOf("."));
|
||||
String extension = imageUrl.substring(imageUrl.lastIndexOf("."));
|
||||
|
||||
return Base64.encodeToString(beforeExtension.getBytes(), Base64.DEFAULT) + extension;
|
||||
}
|
||||
|
||||
public void DownloadImageIfNeeded(String imageUrl)
|
||||
{
|
||||
String fileName = ImageUrlToFileName(imageUrl);
|
||||
|
||||
File f = MainActivity.getInstance().getFileStreamPath(fileName);
|
||||
|
||||
if (f.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream is = (InputStream) new URL(imageUrl).getContent();
|
||||
|
||||
FileOutputStream out = null;
|
||||
|
||||
out = MainActivity.getInstance().openFileOutput(fileName, Context.MODE_PRIVATE);
|
||||
|
||||
byte [] buf = new byte[1024];
|
||||
|
||||
int numRead;
|
||||
|
||||
while ( (numRead = is.read(buf) ) >= 0) {
|
||||
out.write(buf, 0, numRead);
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,8 @@ package fishrungames.bashgid.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
|
||||
public class NewsManager {
|
||||
|
||||
private static NewsManager instance = null;
|
||||
@ -24,7 +26,7 @@ public class NewsManager {
|
||||
public String description;
|
||||
public String imageId;
|
||||
|
||||
NewsRecord(String title, String description, String imageId)
|
||||
public NewsRecord(String title, String description, String imageId)
|
||||
{
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
@ -35,20 +37,33 @@ public class NewsManager {
|
||||
{
|
||||
this.title = rss2Item.title;
|
||||
this.description = rss2Item.description;
|
||||
this.imageId = "R.drawable.news_image1";
|
||||
|
||||
if ((rss2Item.rss2Enclosure != null) && (DownloadManager.MimeTypeIsImage(rss2Item.rss2Enclosure.mimeType)))
|
||||
{
|
||||
this.imageId = rss2Item.rss2Enclosure.url;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.imageId = "R.drawable.transparent";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<NewsRecord> newsRecord = new ArrayList<NewsRecord>();
|
||||
|
||||
public void DownloadNews(NewsUpdatedCallbackInterface callback)
|
||||
public RemoveCallbackInterface DownloadNews(NewsUpdatedCallbackInterface callback)
|
||||
{
|
||||
Thread thread = new Thread(new DownloadNewsRunnable(callback));
|
||||
|
||||
DownloadNewsRunnable downloadNewsRunnable = new DownloadNewsRunnable(callback);
|
||||
|
||||
Thread thread = new Thread(downloadNewsRunnable);
|
||||
|
||||
thread.start();
|
||||
|
||||
return downloadNewsRunnable;
|
||||
}
|
||||
|
||||
class DownloadNewsRunnable implements Runnable
|
||||
class DownloadNewsRunnable implements Runnable, RemoveCallbackInterface
|
||||
{
|
||||
|
||||
NewsUpdatedCallbackInterface callback;
|
||||
@ -58,17 +73,39 @@ public class NewsManager {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RemoveCallback()
|
||||
{
|
||||
callback = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
String xmlCode = DownloadManager.getXmlFromUrl("http://www.bashinform.ru/rss/all.xml");
|
||||
|
||||
if (xmlCode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RssReader rssReader = new RssReader();
|
||||
|
||||
rssReader.ReadRss(xmlCode);
|
||||
|
||||
ArrayList<NewsRecord> localNewsRecord = new ArrayList<NewsRecord>();
|
||||
|
||||
for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr)
|
||||
{
|
||||
if (rss2Item.rss2Enclosure != null)
|
||||
{
|
||||
if (DownloadManager.MimeTypeIsImage(rss2Item.rss2Enclosure.mimeType))
|
||||
{
|
||||
ImageManager.getInstance().DownloadImageIfNeeded(rss2Item.rss2Enclosure.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr)
|
||||
{
|
||||
localNewsRecord.add(new NewsRecord(rss2Item));
|
||||
@ -77,7 +114,13 @@ public class NewsManager {
|
||||
//Xperimental -- need mutex right here
|
||||
newsRecord = localNewsRecord;
|
||||
|
||||
callback.OnNewsUpdated();
|
||||
MainActivity.getInstance().newsDataSource.replaceNews(newsRecord);
|
||||
|
||||
//Xperimental -- need mutex here, too
|
||||
if (callback != null)
|
||||
{
|
||||
callback.OnNewsUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,12 +129,21 @@ public class NewsManager {
|
||||
public void OnNewsUpdated();
|
||||
}
|
||||
|
||||
public static interface RemoveCallbackInterface
|
||||
{
|
||||
public void RemoveCallback();
|
||||
}
|
||||
|
||||
|
||||
public NewsManager()
|
||||
{
|
||||
/*
|
||||
newsRecord.add(new NewsRecord("Власти Башкирии создадут выезд из Уфы на трассу М-5 «Урал»", "Власти Башкирии создадут выезд из Уфы на трассу М-5 «Урал»", "R.drawable.news_image1"));
|
||||
newsRecord.add(new NewsRecord("Башкирия заняла первое место индекса «деловой активности»", "Башкирия заняла первое место индекса «деловой активности»", "R.drawable.news_image2"));
|
||||
newsRecord.add(new NewsRecord("«Салават Юлаев» обыграл «Ладу» и прервал серию из 5 поражений в КХЛ", "«Салават Юлаев» обыграл «Ладу» и прервал серию из 5 поражений в КХЛ", "R.drawable.news_image3"));
|
||||
*/
|
||||
newsRecord = MainActivity.getInstance().newsDataSource.getNews();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,8 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class RssReader {
|
||||
|
||||
|
||||
@ -75,6 +77,11 @@ public class RssReader {
|
||||
{
|
||||
Document xmlDoc = XmlProcessor.getDomElement(xmlCode);
|
||||
|
||||
if (xmlDoc == null)
|
||||
{
|
||||
Log.e("Error XML parsing", "Error XML parsing in ReadRss");
|
||||
return;
|
||||
}
|
||||
|
||||
Element channel = (Element) xmlDoc.getElementsByTagName("channel").item(0);
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
public class BashgidSqliteHelper extends SQLiteOpenHelper
|
||||
{
|
||||
|
||||
public static final String TABLE_NEWS = "table_news";
|
||||
public static final String COLUMN_ID = "_id";
|
||||
public static final String COLUMN_TITLE = "title";
|
||||
public static final String COLUMN_DESCRIPTION = "description";
|
||||
public static final String COLUMN_IMAGE_ID = "imageId";
|
||||
|
||||
|
||||
private static final String DATABASE_NAME = "bashgid.db";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
// Database creation sql statement
|
||||
private static final String DATABASE_CREATE = "create table "
|
||||
+ TABLE_NEWS +
|
||||
"(" + COLUMN_ID + " integer primary key autoincrement" +
|
||||
", " + COLUMN_TITLE + " text not null" +
|
||||
", " + COLUMN_DESCRIPTION + " text not null" +
|
||||
", " + COLUMN_IMAGE_ID + " text not null" +
|
||||
");";
|
||||
|
||||
public BashgidSqliteHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database) {
|
||||
database.execSQL(DATABASE_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
Log.w(BashgidSqliteHelper.class.getName(),
|
||||
"Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NEWS);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
|
||||
}
|
88
android/src/fishrungames/bashgid/core/db/NewsDataSource.java
Normal file
88
android/src/fishrungames/bashgid/core/db/NewsDataSource.java
Normal file
@ -0,0 +1,88 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import fishrungames.bashgid.core.NewsManager;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
public class NewsDataSource
|
||||
{
|
||||
|
||||
private SQLiteDatabase database;
|
||||
|
||||
private BashgidSqliteHelper dbHelper;
|
||||
|
||||
private String[] allColumns = { BashgidSqliteHelper.COLUMN_ID, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION,
|
||||
BashgidSqliteHelper.COLUMN_IMAGE_ID };
|
||||
|
||||
public NewsDataSource(Context context) {
|
||||
dbHelper = new BashgidSqliteHelper(context);
|
||||
}
|
||||
|
||||
public void open() throws SQLException
|
||||
{
|
||||
database = dbHelper.getWritableDatabase();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
|
||||
public void createNewsRecord(NewsManager.NewsRecord newsRecord)
|
||||
{
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put(BashgidSqliteHelper.COLUMN_TITLE, newsRecord.title);
|
||||
values.put(BashgidSqliteHelper.COLUMN_DESCRIPTION, newsRecord.description);
|
||||
values.put(BashgidSqliteHelper.COLUMN_IMAGE_ID, newsRecord.imageId);
|
||||
|
||||
database.insert(BashgidSqliteHelper.TABLE_NEWS, null, values);
|
||||
|
||||
}
|
||||
|
||||
public void replaceNews(ArrayList<NewsManager.NewsRecord> newsRecordArr)
|
||||
{
|
||||
|
||||
database.delete(BashgidSqliteHelper.TABLE_NEWS, null, null);
|
||||
|
||||
for (NewsManager.NewsRecord newsRecord : newsRecordArr)
|
||||
{
|
||||
createNewsRecord(newsRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<NewsManager.NewsRecord> getNews()
|
||||
{
|
||||
|
||||
ArrayList<NewsManager.NewsRecord> newsRecordArr = new ArrayList<NewsManager.NewsRecord>();
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_NEWS, allColumns, null, null, null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
while (!cursor.isAfterLast())
|
||||
{
|
||||
NewsManager.NewsRecord newsRecord = cursorToNewsRecord(cursor);
|
||||
newsRecordArr.add(newsRecord);
|
||||
cursor.moveToNext();
|
||||
}
|
||||
// make sure to close the cursor
|
||||
cursor.close();
|
||||
return newsRecordArr;
|
||||
}
|
||||
|
||||
private NewsManager.NewsRecord cursorToNewsRecord(Cursor cursor)
|
||||
{
|
||||
|
||||
NewsManager.NewsRecord newsRecord = new NewsManager.NewsRecord(cursor.getString(1), cursor.getString(2), cursor.getString(3));
|
||||
|
||||
return newsRecord;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
public class NewsDbRecord
|
||||
{
|
||||
public long id;
|
||||
public String title;
|
||||
public String description;
|
||||
public String imageId;
|
||||
}
|
Loading…
Reference in New Issue
Block a user