diff --git a/android/res/layout/fragment_news_record_page.xml b/android/res/layout/fragment_news_record_page.xml index 2da8fe4..44d31d3 100644 --- a/android/res/layout/fragment_news_record_page.xml +++ b/android/res/layout/fragment_news_record_page.xml @@ -1,16 +1,12 @@ - - - - - + - diff --git a/android/res/layout/main_page_list_header.xml b/android/res/layout/main_page_list_header.xml index aa34768..7369622 100644 --- a/android/res/layout/main_page_list_header.xml +++ b/android/res/layout/main_page_list_header.xml @@ -24,19 +24,25 @@ android:layout_marginBottom="8dp" android:layout_marginTop="8dp" > - - + android:layout_marginLeft="8dp" + android:background="@drawable/transparent_button" + android:gravity="left|center_vertical" + android:minHeight="0dp" + android:minWidth="0dp" + android:textColor="@color/text_grey" /> @@ -46,19 +52,25 @@ android:layout_marginBottom="8dp" android:layout_marginTop="8dp" > - - + android:layout_marginLeft="8dp" + android:background="@drawable/transparent_button" + android:gravity="left|center_vertical" + android:minHeight="0dp" + android:minWidth="0dp" + android:textColor="@color/text_grey" /> @@ -68,19 +80,25 @@ android:layout_marginBottom="8dp" android:layout_marginTop="8dp" > - - + android:layout_marginLeft="8dp" + android:background="@drawable/transparent_button" + android:gravity="left|center_vertical" + android:minHeight="0dp" + android:minWidth="0dp" + android:textColor="@color/text_grey" /> diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml index 66e9d71..76a696d 100644 --- a/android/res/values-zh-rCN/strings.xml +++ b/android/res/values-zh-rCN/strings.xml @@ -1,29 +1,29 @@ - - - 巴什科尔托斯坦指南 - 打开导航窗格 - 关闭导航窗格 + + + 俄罗斯联邦巴什基尔自治共和国指南 + 打开导航窗口 + 关闭导航窗口 设置 - 搜索 + 搜索标题 - 文章不可 + 无法查看新闻记录 其他新闻… - 查看更多新闻 + 查看所有新闻 - 新闻 + 头条新闻 - 图片相关的新闻 + 新闻内容描述 - 图片相关文章 + 相关图片 图标 - 徽标 + 标识 - 巴什科尔托斯坦指南 + 俄罗斯联邦巴什基尔自治共和国指南 指南 新闻 目录 @@ -33,6 +33,6 @@ 投资者信息 设置 - - - + + + diff --git a/android/src/fishrungames/bashgid/MainActivity.java b/android/src/fishrungames/bashgid/MainActivity.java index 2b984ff..03851da 100644 --- a/android/src/fishrungames/bashgid/MainActivity.java +++ b/android/src/fishrungames/bashgid/MainActivity.java @@ -23,6 +23,9 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { + public static final String TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT = "TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT"; + public static final String TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT = "TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT"; + static MainActivity instance = null; private NavigationDrawerFragment mNavigationDrawerFragment = null; @@ -116,11 +119,16 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks { mNavigationDrawerFragment.EnableDrawer(); } - public void OpenNewsRecordScreen(NewsRecord newsRecord) + public void OpenNewsRecordScreen(NewsRecord newsRecord, String tag) { //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(); + + //I added workaround: + + NewsRecordFragment newsRecordFragment = new NewsRecordFragment(newsRecord); + + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsRecordFragment, tag).commit(); mNavigationDrawerFragment.EnableDrawer(); } @@ -187,11 +195,33 @@ implements NavigationDrawerFragment.NavigationDrawerCallbacks { @Override public void onBackPressed() { + + if ( getSupportFragmentManager().findFragmentByTag(TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT) != null) + { + OpenMainScreen(); + + return; + } + + if ( getSupportFragmentManager().findFragmentByTag(TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT) != null) + { + OpenNewsScreen(); + + return; + } + + + + super.onBackPressed(); + + + /* + * AddToBackStack is falling. Here is workaround if(getSupportFragmentManager().getBackStackEntryCount() != 0) { getSupportFragmentManager().popBackStack(); } else { super.onBackPressed(); - } + }*/ } @Override diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java index fab970b..8650de6 100644 --- a/android/src/fishrungames/bashgid/MainPageFragment.java +++ b/android/src/fishrungames/bashgid/MainPageFragment.java @@ -4,6 +4,7 @@ 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; @@ -14,7 +15,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; -import android.widget.ImageView; +import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; import it.sephiroth.android.library.widget.HListView; @@ -93,48 +94,61 @@ public class MainPageFragment extends Fragment implements NewsUpdatedCallbackInt { - ImageView news1ImageView = (ImageView) header.findViewById(R.id.news1ImageView); - ImageView news2ImageView = (ImageView) header.findViewById(R.id.news2ImageView); - ImageView news3ImageView = (ImageView) header.findViewById(R.id.news3ImageView); + ImageButton news1ImageButton = (ImageButton) header.findViewById(R.id.news1ImageButton); + ImageButton news2ImageButton = (ImageButton) header.findViewById(R.id.news2ImageButton); + ImageButton news3ImageButton = (ImageButton) header.findViewById(R.id.news3ImageButton); - TextView news1TextView = (TextView)header.findViewById(R.id.news1TextView); - TextView news2TextView = (TextView)header.findViewById(R.id.news2TextView); - TextView news3TextView = (TextView)header.findViewById(R.id.news3TextView); + Button news1Button = (Button)header.findViewById(R.id.news1Button); + Button news2Button = (Button)header.findViewById(R.id.news2Button); + Button news3Button = (Button)header.findViewById(R.id.news3Button); ArrayList newsRecordArr = NewsManager.GetInstance().getNews(); if (newsRecordArr.size() > 0) { - ImageManager.getInstance().ApplyImageToImageView(news1ImageView, newsRecordArr.get(0).imageId); - news1TextView.setText(newsRecordArr.get(0).title); + ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsRecordArr.get(0).imageId); + news1Button.setText(newsRecordArr.get(0).title); + + news1ImageButton.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(0))); + news1Button.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(0))); } else { - news1ImageView.setImageResource(R.drawable.transparent); - news1TextView.setText(R.string.news_record_not_available); + news1ImageButton.setImageResource(R.drawable.transparent); + news1Button.setText(R.string.news_record_not_available); + news1ImageButton.setOnClickListener(null); + news1Button.setOnClickListener(null); } if (newsRecordArr.size() > 1) { - ImageManager.getInstance().ApplyImageToImageView(news2ImageView, newsRecordArr.get(1).imageId); - news2TextView.setText(newsRecordArr.get(1).title); + ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsRecordArr.get(1).imageId); + news2Button.setText(newsRecordArr.get(1).title); + news2ImageButton.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(1))); + news2Button.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(1))); } else { - news2ImageView.setImageResource(R.drawable.transparent); - news2TextView.setText(R.string.news_record_not_available); + news2ImageButton.setImageResource(R.drawable.transparent); + news2Button.setText(R.string.news_record_not_available); + news2ImageButton.setOnClickListener(null); + news2Button.setOnClickListener(null); } if (newsRecordArr.size() > 2) { - ImageManager.getInstance().ApplyImageToImageView(news3ImageView, newsRecordArr.get(2).imageId); - news3TextView.setText(newsRecordArr.get(2).title); + ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsRecordArr.get(2).imageId); + news3Button.setText(newsRecordArr.get(2).title); + news3ImageButton.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(2))); + news3Button.setOnClickListener(new ButtonOnClickListener(newsRecordArr.get(2))); } else { - news3ImageView.setImageResource(R.drawable.transparent); - news3TextView.setText(R.string.news_record_not_available); + news3ImageButton.setImageResource(R.drawable.transparent); + news3Button.setText(R.string.news_record_not_available); + news3ImageButton.setOnClickListener(null); + news3Button.setOnClickListener(null); } @@ -222,5 +236,22 @@ public class MainPageFragment extends Fragment implements NewsUpdatedCallbackInt }); } + 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, MainActivity.TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT); + } + + } } diff --git a/android/src/fishrungames/bashgid/NewsListFragment.java b/android/src/fishrungames/bashgid/NewsListFragment.java index f61c38c..e74018c 100644 --- a/android/src/fishrungames/bashgid/NewsListFragment.java +++ b/android/src/fishrungames/bashgid/NewsListFragment.java @@ -143,7 +143,7 @@ public class NewsListFragment extends Fragment implements NewsUpdatedCallbackInt @Override public void onClick(View v) { - MainActivity.getInstance().OpenNewsRecordScreen(newsRecord); + MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT); } } diff --git a/android/src/fishrungames/bashgid/NewsRecordFragment.java b/android/src/fishrungames/bashgid/NewsRecordFragment.java index 30edfe3..5cd81d5 100644 --- a/android/src/fishrungames/bashgid/NewsRecordFragment.java +++ b/android/src/fishrungames/bashgid/NewsRecordFragment.java @@ -8,6 +8,7 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebView; import android.widget.ImageView; import android.widget.TextView; @@ -27,16 +28,25 @@ public class NewsRecordFragment extends Fragment View rootView = inflater.inflate(R.layout.fragment_news_record_page, container, false); TextView titleTextView = (TextView) rootView.findViewById(R.id.titleTextView); + titleTextView.setText(newsRecord.title); - TextView descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView); + //TextView descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView); + //descriptionTextView.setText(newsRecord.description); ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView); - - titleTextView.setText(newsRecord.title); - descriptionTextView.setText(newsRecord.description); - ImageManager.getInstance().ApplyImageToImageView(imageView, newsRecord.imageId); + + WebView webView = (WebView) rootView.findViewById(R.id.webView); + + webView.getSettings().setJavaScriptEnabled(false); + + String htmlCode = "" + newsRecord.description + ""; + + webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null); + return rootView; } + + } diff --git a/android/src/fishrungames/bashgid/core/DownloadManager.java b/android/src/fishrungames/bashgid/core/DownloadManager.java index 0b97141..598d055 100644 --- a/android/src/fishrungames/bashgid/core/DownloadManager.java +++ b/android/src/fishrungames/bashgid/core/DownloadManager.java @@ -10,6 +10,8 @@ import java.net.URLConnection; import org.apache.http.client.ClientProtocolException; +import android.util.Log; + public class DownloadManager { @@ -53,4 +55,20 @@ public class DownloadManager { { return mimeType.equals("image/bmp") || mimeType.equals("image/gif") || mimeType.equals("image/jpeg") || mimeType.equals("image/png"); } + + public static String GetUrlFolder(String url) + { + int pos = url.lastIndexOf("/"); + + if (pos == -1) + { + Log.e("Error", "GetUrlFolder got incorrect agrument"); + + return ""; + } + + String substr = url.substring(0, pos); + + return substr; + } } diff --git a/android/src/fishrungames/bashgid/core/ImageManager.java b/android/src/fishrungames/bashgid/core/ImageManager.java index 85f94b7..3bb3240 100644 --- a/android/src/fishrungames/bashgid/core/ImageManager.java +++ b/android/src/fishrungames/bashgid/core/ImageManager.java @@ -85,7 +85,7 @@ public class ImageManager { String beforeExtension = imageUrl.substring(0, imageUrl.lastIndexOf(".")); String extension = imageUrl.substring(imageUrl.lastIndexOf(".")); - return Base64.encodeToString(beforeExtension.getBytes(), Base64.DEFAULT) + extension; + return Base64.encodeToString(beforeExtension.getBytes(), Base64.DEFAULT).replace("\n", "") + extension; } public void DownloadImageIfNeeded(String imageUrl) @@ -121,6 +121,11 @@ public class ImageManager { } } + public String GetImageLocalUrl(String imageUrl) + { + return "file://" + MainActivity.getInstance().getFilesDir().getAbsolutePath() + "/" + ImageUrlToFileName(imageUrl); + } + } diff --git a/android/src/fishrungames/bashgid/core/NewsManager.java b/android/src/fishrungames/bashgid/core/NewsManager.java index 822e867..390fbab 100644 --- a/android/src/fishrungames/bashgid/core/NewsManager.java +++ b/android/src/fishrungames/bashgid/core/NewsManager.java @@ -82,13 +82,25 @@ public class NewsManager { @Override public void run() { - String xmlCode = DownloadManager.getXmlFromUrl("http://www.bashinform.ru/rss/all.xml"); + //String url = "http://www.bashinform.ru/rss/all.xml"; + + String url = "http://www.bashedu.ru/rss.xml"; + + String xmlCode = DownloadManager.getXmlFromUrl(url); if (xmlCode == null) { return; } + //Remove BOM character if present + if (xmlCode.startsWith("\uFEFF")) + { + xmlCode = xmlCode.substring(1); + } + + + RssReader rssReader = new RssReader(); rssReader.ReadRss(xmlCode); @@ -97,6 +109,7 @@ public class NewsManager { for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr) { + //Enclosure if (rss2Item.rss2Enclosure != null) { if (DownloadManager.MimeTypeIsImage(rss2Item.rss2Enclosure.mimeType)) @@ -104,6 +117,38 @@ public class NewsManager { ImageManager.getInstance().DownloadImageIfNeeded(rss2Item.rss2Enclosure.url); } } + + //And images inside text + int i = rss2Item.description.indexOf("