diff --git a/android/project.properties b/android/project.properties
index 173817e..1865458 100644
--- a/android/project.properties
+++ b/android/project.properties
@@ -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
diff --git a/android/res/drawable/transparent_button.xml b/android/res/drawable/transparent_button.xml
new file mode 100644
index 0000000..54885d4
--- /dev/null
+++ b/android/res/drawable/transparent_button.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/res/drawable/transparent_highlighted.xml b/android/res/drawable/transparent_highlighted.xml
new file mode 100644
index 0000000..4abf642
--- /dev/null
+++ b/android/res/drawable/transparent_highlighted.xml
@@ -0,0 +1,8 @@
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/android/res/layout/button_hview_list_element.xml b/android/res/layout/button_hview_list_element.xml
index bd57d10..6996e4e 100644
--- a/android/res/layout/button_hview_list_element.xml
+++ b/android/res/layout/button_hview_list_element.xml
@@ -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" />
+ android:layout_gravity="center_vertical" />
diff --git a/android/res/layout/drawer_list_element.xml b/android/res/layout/drawer_list_element.xml
index 3938449..d6d4ebd 100644
--- a/android/res/layout/drawer_list_element.xml
+++ b/android/res/layout/drawer_list_element.xml
@@ -9,11 +9,11 @@
+ android:contentDescription="@string/icon" />
diff --git a/android/res/layout/fragment_news_page.xml b/android/res/layout/fragment_news_page.xml
new file mode 100644
index 0000000..6508282
--- /dev/null
+++ b/android/res/layout/fragment_news_page.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
diff --git a/android/res/layout/fragment_news_record_page.xml b/android/res/layout/fragment_news_record_page.xml
new file mode 100644
index 0000000..2da8fe4
--- /dev/null
+++ b/android/res/layout/fragment_news_record_page.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/res/layout/main_page_list_header.xml b/android/res/layout/main_page_list_header.xml
index 0b20900..aa34768 100644
--- a/android/res/layout/main_page_list_header.xml
+++ b/android/res/layout/main_page_list_header.xml
@@ -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" />
+ android:contentDescription="@string/news_content_description" />
+ android:contentDescription="@string/news_content_description" />
+
diff --git a/android/res/layout/news_page_list_element.xml b/android/res/layout/news_page_list_element.xml
new file mode 100644
index 0000000..7d50f41
--- /dev/null
+++ b/android/res/layout/news_page_list_element.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
diff --git a/android/res/layout/news_page_list_header.xml b/android/res/layout/news_page_list_header.xml
new file mode 100644
index 0000000..fcaaa85
--- /dev/null
+++ b/android/res/layout/news_page_list_header.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/android/res/menu/main.xml b/android/res/menu/main.xml
index 69d1953..510ec97 100644
--- a/android/res/menu/main.xml
+++ b/android/res/menu/main.xml
@@ -3,10 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="fishrungames.bashgid.MainActivity" >
-
-
+
+
+ Гид РБ
+
+ Открыть левую панель
+ Закрыть левую панель
+
+ Настройки
+
+ Поиск
+
+ Запись недоступна
+ Другие новости…
+
+ Посмотреть все
+
+
+ Новости
+
+ Картинка к новости
+
+ Картинка к странице
+ Иконка
+
+
+
+ Логотип
+
+ Гид РБ
+ Гид
+ Новости
+ Каталог
+ Карта
+ Видео
+ Фотогалерея
+ Инвестору
+ Настройки
+
+
+
diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml
new file mode 100644
index 0000000..66e9d71
--- /dev/null
+++ b/android/res/values-zh-rCN/strings.xml
@@ -0,0 +1,38 @@
+
+
+
+ 巴什科尔托斯坦指南
+ 打开导航窗格
+ 关闭导航窗格
+ 设置
+
+ 搜索
+
+ 文章不可
+ 其他新闻…
+
+ 查看更多新闻
+
+
+ 新闻
+
+ 图片相关的新闻
+
+ 图片相关文章
+ 图标
+
+ 徽标
+
+ 巴什科尔托斯坦指南
+ 指南
+ 新闻
+ 目录
+ 地图
+ 视频
+ 图片库
+ 投资者信息
+ 设置
+
+
+
+
diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml
index 8259fa0..6902d6f 100644
--- a/android/res/values/colors.xml
+++ b/android/res/values/colors.xml
@@ -9,6 +9,11 @@
#60d0d0d0
#F0F0F0
+
+#080808
+
+#808080
+
#2B517F
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index bf5a763..d5f5ed9 100644
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -1,35 +1,46 @@
- Гид РБ
- Section 1
- Section 2
- Section 3
+ RB Guide
Open navigation drawer
Close navigation drawer
- Example action
- Settings
+ Settings
+
+
English
- Russian
- Chinese
+ Русский
+ 中文
- Поиск
+ Search
- Запись недоступна
- Другие новости...
+ Record is not available
+ Other news…
- Новости
-
- Image related to news record
- Image related to news record
- Image related to news record
+ See all
-
- Coat of Bashkortostan
+ News
+
+ Image related to news record
+
+ Related image
+ Icon
+
+ Logo
+
+ RB Guide
+ Guide
+ News
+ Catalogue
+ Map
+ Video
+ Photo gallery
+ For investor
+ Settings
+
diff --git a/android/src/fishrungames/bashgid/MainActivity.java b/android/src/fishrungames/bashgid/MainActivity.java
index 1b40108..2b984ff 100644
--- a/android/src/fishrungames/bashgid/MainActivity.java
+++ b/android/src/fishrungames/bashgid/MainActivity.java
@@ -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();
+ }
}
diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java
index a930461..fab970b 100644
--- a/android/src/fishrungames/bashgid/MainPageFragment.java
+++ b/android/src/fishrungames/bashgid/MainPageFragment.java
@@ -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;
}
diff --git a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java
index 2fd8bb2..27d7254 100644
--- a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java
+++ b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java
@@ -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;
}
diff --git a/android/src/fishrungames/bashgid/NavigationDrawerFragment.java b/android/src/fishrungames/bashgid/NavigationDrawerFragment.java
index de485e7..3faf8f8 100644
--- a/android/src/fishrungames/bashgid/NavigationDrawerFragment.java
+++ b/android/src/fishrungames/bashgid/NavigationDrawerFragment.java
@@ -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);
diff --git a/android/src/fishrungames/bashgid/NewsListFragment.java b/android/src/fishrungames/bashgid/NewsListFragment.java
new file mode 100644
index 0000000..f61c38c
--- /dev/null
+++ b/android/src/fishrungames/bashgid/NewsListFragment.java
@@ -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 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);
+ }
+
+ }
+
+}
diff --git a/android/src/fishrungames/bashgid/NewsRecordFragment.java b/android/src/fishrungames/bashgid/NewsRecordFragment.java
new file mode 100644
index 0000000..30edfe3
--- /dev/null
+++ b/android/src/fishrungames/bashgid/NewsRecordFragment.java
@@ -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;
+ }
+}
diff --git a/android/src/fishrungames/bashgid/core/DownloadManager.java b/android/src/fishrungames/bashgid/core/DownloadManager.java
index e42aef8..0b97141 100644
--- a/android/src/fishrungames/bashgid/core/DownloadManager.java
+++ b/android/src/fishrungames/bashgid/core/DownloadManager.java
@@ -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");
+ }
}
diff --git a/android/src/fishrungames/bashgid/core/ImageManager.java b/android/src/fishrungames/bashgid/core/ImageManager.java
index 6f04397..85f94b7 100644
--- a/android/src/fishrungames/bashgid/core/ImageManager.java
+++ b/android/src/fishrungames/bashgid/core/ImageManager.java
@@ -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();
+ }
}
diff --git a/android/src/fishrungames/bashgid/core/NewsManager.java b/android/src/fishrungames/bashgid/core/NewsManager.java
index c122030..822e867 100644
--- a/android/src/fishrungames/bashgid/core/NewsManager.java
+++ b/android/src/fishrungames/bashgid/core/NewsManager.java
@@ -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 = new ArrayList();
- 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 localNewsRecord = new ArrayList();
+ 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();
+
}
diff --git a/android/src/fishrungames/bashgid/core/RssReader.java b/android/src/fishrungames/bashgid/core/RssReader.java
index 5c94545..47b6f3b 100644
--- a/android/src/fishrungames/bashgid/core/RssReader.java
+++ b/android/src/fishrungames/bashgid/core/RssReader.java
@@ -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);
diff --git a/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java b/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java
new file mode 100644
index 0000000..5137997
--- /dev/null
+++ b/android/src/fishrungames/bashgid/core/db/BashgidSqliteHelper.java
@@ -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);
+ }
+
+
+}
diff --git a/android/src/fishrungames/bashgid/core/db/NewsDataSource.java b/android/src/fishrungames/bashgid/core/db/NewsDataSource.java
new file mode 100644
index 0000000..c7b6168
--- /dev/null
+++ b/android/src/fishrungames/bashgid/core/db/NewsDataSource.java
@@ -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 newsRecordArr)
+ {
+
+ database.delete(BashgidSqliteHelper.TABLE_NEWS, null, null);
+
+ for (NewsManager.NewsRecord newsRecord : newsRecordArr)
+ {
+ createNewsRecord(newsRecord);
+ }
+
+ }
+
+ public ArrayList getNews()
+ {
+
+ ArrayList newsRecordArr = new ArrayList();
+
+ 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;
+ }
+}
diff --git a/android/src/fishrungames/bashgid/core/db/NewsDbRecord.java b/android/src/fishrungames/bashgid/core/db/NewsDbRecord.java
new file mode 100644
index 0000000..3b6b6aa
--- /dev/null
+++ b/android/src/fishrungames/bashgid/core/db/NewsDbRecord.java
@@ -0,0 +1,9 @@
+package fishrungames.bashgid.core.db;
+
+public class NewsDbRecord
+{
+ public long id;
+ public String title;
+ public String description;
+ public String imageId;
+}