From c0c8ba61c66d88d44bbe2c798ac04847e15a8975 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Mon, 6 Jul 2015 00:44:07 +0000 Subject: [PATCH] Fixing context bugs --- android/AndroidManifest.xml | 15 +- android/project.properties | 3 +- android/res/layout/activity_main.xml | 4 +- android/res/layout/fragment_grid_page.xml | 4 +- android/res/layout/fragment_settings_page.xml | 3 +- android/res/layout/grid_page_list_element.xml | 2 +- android/res/values-large/dimens.xml | 16 +- android/res/values-normal/dimens.xml | 16 +- android/res/values-small/dimens.xml | 16 +- android/res/values-xlarge/dimens.xml | 16 +- android/res/values/dimens.xml | 16 +- .../bashgid/AlbumListFragment.java | 4 +- .../fishrungames/bashgid/ArticleFragment.java | 10 +- .../bashgid/BashgidApplication.java | 529 ++++++++++ .../fishrungames/bashgid/CatalogFragment.java | 4 +- .../fishrungames/bashgid/JournalFragment.java | 9 +- .../fishrungames/bashgid/MainActivity.java | 909 +++--------------- .../bashgid/MainPageFragment.java | 22 +- .../bashgid/MainPageHListViewAdapters.java | 2 +- .../bashgid/NavigationDrawerFragment.java | 24 +- .../bashgid/NewsListFragment.java | 8 +- .../bashgid/OsmMapHolderFragment.java | 6 +- .../bashgid/PhotoAlbumFragment.java | 4 +- .../fishrungames/bashgid/PhotoFragment.java | 2 +- .../fishrungames/bashgid/SearchFragment.java | 13 +- .../fishrungames/bashgid/SquareImageView.java | 1 + .../bashgid/VideoListFragment.java | 13 +- .../bashgid/VideoRecordFragment.java | 10 +- .../bashgid/core/AlbumManager.java | 29 +- .../bashgid/core/DatabaseDownloadTask.java | 33 +- .../bashgid/core/DatabaseGetAlbumTask.java | 7 +- .../bashgid/core/DatabaseGetArticleTask.java | 9 +- .../core/DatabaseGetGeoJournalListTask.java | 9 +- .../core/DatabaseGetJournalListTask.java | 7 +- .../bashgid/core/DatabaseGetJournalTask.java | 5 +- .../core/DatabaseSearchArticleTask.java | 17 +- .../bashgid/core/NewsDownloadTask.java | 5 +- .../bashgid/core/NewsManager.java | 5 +- .../bashgid/core/db/AlbumDataSource.java | 15 +- .../bashgid/core/db/ArticleDataSource.java | 31 +- .../bashgid/core/db/ChannelDataSource.java | 7 +- .../bashgid/core/db/JournalDataSource.java | 25 +- .../bashgid/core/db/PhotoDataSource.java | 5 +- .../bashgid/core/db/VideoDataSource.java | 5 +- 44 files changed, 938 insertions(+), 957 deletions(-) create mode 100644 android/src/fishrungames/bashgid/BashgidApplication.java diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 60bc839..3977a39 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="4" + android:versionName="1.03" > - - - - - - + diff --git a/android/project.properties b/android/project.properties index a80681a..7a718db 100644 --- a/android/project.properties +++ b/android/project.properties @@ -13,5 +13,4 @@ # Project target. target=android-21 android.library.reference.1=..\\HorizontalListViewLibrary -android.library.reference.2=..\\google-play-services_lib -android.library.reference.3=../networkutils +android.library.reference.2=..\\networkutils diff --git a/android/res/layout/activity_main.xml b/android/res/layout/activity_main.xml index 273f290..7e12798 100644 --- a/android/res/layout/activity_main.xml +++ b/android/res/layout/activity_main.xml @@ -6,12 +6,15 @@ tools:context="fishrungames.bashgid.MainActivity" > + + + - \ No newline at end of file diff --git a/android/res/layout/fragment_grid_page.xml b/android/res/layout/fragment_grid_page.xml index 0ef55f3..3f2e1cc 100644 --- a/android/res/layout/fragment_grid_page.xml +++ b/android/res/layout/fragment_grid_page.xml @@ -2,6 +2,7 @@ - diff --git a/android/res/layout/fragment_settings_page.xml b/android/res/layout/fragment_settings_page.xml index fcdf5f2..15f8f23 100644 --- a/android/res/layout/fragment_settings_page.xml +++ b/android/res/layout/fragment_settings_page.xml @@ -1,10 +1,11 @@ diff --git a/android/res/layout/grid_page_list_element.xml b/android/res/layout/grid_page_list_element.xml index f507678..677d2f1 100644 --- a/android/res/layout/grid_page_list_element.xml +++ b/android/res/layout/grid_page_list_element.xml @@ -9,7 +9,7 @@ android:orientation="vertical" android:showDividers="middle" > - 4dp - 60dp - 30dp + 40sp + 30sp - 24dp + 24sp - 20dp + 20sp - 18dp + 18sp - 14dp + 14sp - 30dp + 30sp - 24dp + 20sp diff --git a/android/res/values-normal/dimens.xml b/android/res/values-normal/dimens.xml index c8189eb..d940d4a 100644 --- a/android/res/values-normal/dimens.xml +++ b/android/res/values-normal/dimens.xml @@ -27,20 +27,20 @@ 4dp - 30dp - 24dp + 30sp + 24sp - 24dp + 24sp - 20dp + 20sp - 18dp + 18sp - 14dp + 14sp - 20dp + 20sp - 14dp + 14sp diff --git a/android/res/values-small/dimens.xml b/android/res/values-small/dimens.xml index 833a445..76d73af 100644 --- a/android/res/values-small/dimens.xml +++ b/android/res/values-small/dimens.xml @@ -27,20 +27,20 @@ 4dp - 30dp - 24dp + 30sp + 24sp - 24dp + 24sp - 20dp + 20sp - 18dp + 18sp - 14dp + 14sp - 20dp + 20sp - 14dp + 14sp 12dp diff --git a/android/res/values-xlarge/dimens.xml b/android/res/values-xlarge/dimens.xml index c22598e..4772fd0 100644 --- a/android/res/values-xlarge/dimens.xml +++ b/android/res/values-xlarge/dimens.xml @@ -27,21 +27,21 @@ 4dp - 60dp - 30dp + 40sp + 30sp - 24dp + 24sp - 20dp + 20sp - 18dp + 18sp - 14dp + 14sp - 30dp + 30sp - 24dp + 20sp diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index c22598e..4772fd0 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -27,21 +27,21 @@ 4dp - 60dp - 30dp + 40sp + 30sp - 24dp + 24sp - 20dp + 20sp - 18dp + 18sp - 14dp + 14sp - 30dp + 30sp - 24dp + 20sp diff --git a/android/src/fishrungames/bashgid/AlbumListFragment.java b/android/src/fishrungames/bashgid/AlbumListFragment.java index 44b4f7a..973b6eb 100644 --- a/android/src/fishrungames/bashgid/AlbumListFragment.java +++ b/android/src/fishrungames/bashgid/AlbumListFragment.java @@ -166,7 +166,7 @@ public class AlbumListFragment extends Fragment protected Long doInBackground(String... queryArr) { - albumArr = MainActivity.getInstance().albumDataSource.GetAllAlbumShortDataExceptHidden(); + albumArr = BashgidApplication.albumDataSource.GetAllAlbumShortDataExceptHidden(); return (long) 0; } @@ -181,7 +181,7 @@ public class AlbumListFragment extends Fragment protected void onPostExecute(Long result) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_FINISHED, albumArr); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_ALBUM_LIST_STATE_FINISHED, albumArr); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/ArticleFragment.java b/android/src/fishrungames/bashgid/ArticleFragment.java index f755402..7c55167 100644 --- a/android/src/fishrungames/bashgid/ArticleFragment.java +++ b/android/src/fishrungames/bashgid/ArticleFragment.java @@ -106,7 +106,7 @@ public class ArticleFragment extends Fragment @Override public boolean onTouchEvent(final MotionEvent event, final MapView mapView) { - MainActivity.getInstance().SetLastArticleName(articleName); + BashgidApplication.SetLastArticleName(articleName); if (event.getAction() == MotionEvent.ACTION_UP) { @@ -160,8 +160,6 @@ public class ArticleFragment extends Fragment databaseGetArticleTask = new DatabaseGetArticleTask(); - databaseGetArticleTask.mHandler = MainActivity.getInstance().mainHandler; - databaseGetArticleTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, articleName); } @@ -394,7 +392,7 @@ public class ArticleFragment extends Fragment TextView textView = (TextView) view.findViewById(R.id.dateTextView); ImageView imageView = (ImageView) view.findViewById(R.id.imageView); - PhotoRecordData photo = MainActivity.getInstance().photoDataSource.GetPhotoByImageUrl(articleLayout.get(position).value); + PhotoRecordData photo = BashgidApplication.photoDataSource.GetPhotoByImageUrl(articleLayout.get(position).value); //ImageManager.getInstance().ApplyImageToImageView(imageView, photo.imageUrl); ImageManager.getInstance().ApplySmallImageToImageView(imageView, photo.imageUrl); @@ -405,7 +403,7 @@ public class ArticleFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().SetLastArticleName(articleName); + BashgidApplication.SetLastArticleName(articleName); String albumName = article.albumArr.get(0).name; @@ -517,7 +515,7 @@ public class ArticleFragment extends Fragment @Override public void onItemClick(it.sephiroth.android.library.widget.AdapterView parent, View view, int innerPosition, long id) { - MainActivity.getInstance().SetLastArticleName(articleName); + BashgidApplication.SetLastArticleName(articleName); String albumName = article.albumArr.get(articleLayout.get(position).albumPos).name; diff --git a/android/src/fishrungames/bashgid/BashgidApplication.java b/android/src/fishrungames/bashgid/BashgidApplication.java new file mode 100644 index 0000000..f414347 --- /dev/null +++ b/android/src/fishrungames/bashgid/BashgidApplication.java @@ -0,0 +1,529 @@ +package fishrungames.bashgid; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; + +import fishrungames.bashgid.core.DatabaseDownloadTask; +import fishrungames.bashgid.core.NewsDownloadTask; +import fishrungames.bashgid.core.AlbumManager.AlbumFullData; +import fishrungames.bashgid.core.AlbumManager.AlbumShortData; +import fishrungames.bashgid.core.ArticleManager.ArticleFullData; +import fishrungames.bashgid.core.ArticleManager.ArticleShortData; +import fishrungames.bashgid.core.ChannelManager.ChannelFullData; +import fishrungames.bashgid.core.JournalManager.JournalRecordData; +import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; +import fishrungames.bashgid.core.VideoManager.VideoRecordData; +import fishrungames.bashgid.core.db.AlbumDataSource; +import fishrungames.bashgid.core.db.ArticleDataSource; +import fishrungames.bashgid.core.db.BashgidSqliteHelper; +import fishrungames.bashgid.core.db.ChannelDataSource; +import fishrungames.bashgid.core.db.JournalDataSource; +import fishrungames.bashgid.core.db.PhotoDataSource; +import fishrungames.bashgid.core.db.TranslationDataSource; +import fishrungames.bashgid.core.db.VideoDataSource; +import fishrungames.networkutils.ContextHolder; +import fishrungames.networkutils.ImageDownloadTask; +import fishrungames.networkutils.ImageManager; + +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.drawable.BitmapDrawable; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.text.format.DateUtils; + +public class BashgidApplication extends android.app.Application { + + public static final String PREFS_MAIN = "PREFS_MAIN"; + + public static final int NEWS_DOWNLOADER_STATE_UPDATE = 10; + public static final int NEWS_DOWNLOADER_STATE_FINISHED = 11; + + public static final int DATABASE_DOWNLOADER_STATE_UPDATE = 12; + public static final int DATABASE_DOWNLOADER_STATE_FINISHED = 13; + + public static final int DATABASE_GET_ALBUM_STATE_UPDATE = 14; + public static final int DATABASE_GET_ALBUM_STATE_FINISHED = 15; + + public static final int DATABASE_GET_ALBUM_LIST_STATE_UPDATE = 16; + public static final int DATABASE_GET_ALBUM_LIST_STATE_FINISHED = 17; + + public static final int DATABASE_GET_ARTICLE_STATE_UPDATE = 18; + public static final int DATABASE_GET_ARTICLE_STATE_FINISHED = 19; + + public static final int DATABASE_GET_JOURNAL_STATE_UPDATE = 20; + public static final int DATABASE_GET_JOURNAL_STATE_FINISHED = 21; + + public static final int DATABASE_GET_CHANNEL_STATE_UPDATE = 22; + public static final int DATABASE_GET_CHANNEL_STATE_FINISHED = 23; + + public static final int DATABASE_GET_VIDEO_STATE_UPDATE = 24; + public static final int DATABASE_GET_VIDEO_STATE_FINISHED = 25; + + public static final int DATABASE_GET_JOURNAL_LIST_STATE_UPDATE = 26; + public static final int DATABASE_GET_JOURNAL_LIST_STATE_FINISHED = 27; + + public static final int DATABASE_SEARCH_ARTICLE_STATE_UPDATE = 28; + public static final int DATABASE_SEARCH_ARTICLE_STATE_FINISHED = 29; + + public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE = 30; + public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED = 31; + + + private static BashgidApplication instance = null; + + public static final SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); + + private static ImageDownloadTask imageDownloadTask = null; + + private static ArrayList queuedImgUrlArr = new ArrayList(); + private static ArrayList queuedImgHashArr = new ArrayList(); + + + public static Handler mainHandler; + + public BashgidSqliteHelper dbHelper = null; + + + public static PhotoDataSource photoDataSource = null; + public static AlbumDataSource albumDataSource = null; + public static ArticleDataSource articleDataSource = null; + + public static VideoDataSource videoDataSource = null; + public static ChannelDataSource channelDataSource = null; + + public static JournalDataSource journalDataSource = null; + + public static TranslationDataSource translationDataSource = null; + + public static NewsDownloadTask newsDownloadTask = null; + public static DatabaseDownloadTask databaseDownloadTask = null; + + + + public BashgidApplication() { + instance = this; + + ImageManager.getInstance().PredefinedImageId.put("R.drawable.no_picture", R.drawable.no_picture); + + ImageManager.PreferredEmptyPicture = "R.drawable.no_picture"; + + ImageManager.getInstance().alwaysUpdateImagesWithoutHash = false; + + ContextHolder.setContext(instance); + + + + + dbHelper = new BashgidSqliteHelper(this); + + photoDataSource = new PhotoDataSource(this, dbHelper); + + albumDataSource = new AlbumDataSource(this, dbHelper); + + articleDataSource = new ArticleDataSource(this, dbHelper); + + videoDataSource = new VideoDataSource(this, dbHelper); + + channelDataSource = new ChannelDataSource(this, dbHelper); + + journalDataSource = new JournalDataSource(this, dbHelper); + + translationDataSource = new TranslationDataSource(this, dbHelper); + + + + + + + mainHandler = new Handler(Looper.getMainLooper()) + { + @Override + public void handleMessage(Message inputMessage) + { + + switch (inputMessage.what) + { + + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: + MainActivity.getInstance().UpdateOnImageDownloaded(); + break; + case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: + MainActivity.getInstance().UpdateOnImageDownloaded(); + + OnImageDownloaderStateFinished(); + + break; + case NEWS_DOWNLOADER_STATE_UPDATE: + SetNewsDownloadProgress((Integer)inputMessage.obj); + MainActivity.getInstance().UpdateOnNewsDownloaded((Integer)inputMessage.obj); + break; + case NEWS_DOWNLOADER_STATE_FINISHED: + MainActivity.getInstance().UpdateOnNewsDownloaded((Integer)inputMessage.obj); + newsDownloadTask = null; + break; + case DATABASE_DOWNLOADER_STATE_UPDATE: + MainActivity.getInstance().UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); + break; + case DATABASE_DOWNLOADER_STATE_FINISHED: + MainActivity.getInstance().UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); + databaseDownloadTask = null; + break; + + case DATABASE_GET_JOURNAL_STATE_UPDATE: + case DATABASE_GET_JOURNAL_STATE_FINISHED: + final JournalSemiFullData journal = (JournalSemiFullData) inputMessage.obj; + MainActivity.getInstance().UpdateOnJournalLoaded(journal); + break; + case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: + MainActivity.getInstance().UpdateOnJournalListLoaded((ArrayList) inputMessage.obj); + break; + + case DATABASE_GET_ALBUM_STATE_UPDATE: + case DATABASE_GET_ALBUM_STATE_FINISHED: + MainActivity.getInstance().UpdateOnAlbumLoaded((AlbumFullData) inputMessage.obj); + break; + case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: + case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: + + ArrayList albumShortList = (ArrayList) inputMessage.obj; + MainActivity.getInstance().UpdateOnAlbumListLoaded(albumShortList); + break; + case DATABASE_GET_ARTICLE_STATE_UPDATE: + case DATABASE_GET_ARTICLE_STATE_FINISHED: + MainActivity.getInstance().UpdateOnArticleLoaded((ArticleFullData) inputMessage.obj); + break; + + case DATABASE_GET_CHANNEL_STATE_UPDATE: + case DATABASE_GET_CHANNEL_STATE_FINISHED: + MainActivity.getInstance().UpdateOnChannelLoaded((ChannelFullData) inputMessage.obj); + break; + + case DATABASE_GET_VIDEO_STATE_UPDATE: + case DATABASE_GET_VIDEO_STATE_FINISHED: + MainActivity.getInstance().UpdateOnVideoLoaded((VideoRecordData) inputMessage.obj); + break; + + + + case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: + case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: + MainActivity.getInstance().UpdateOnArticleSearchPerformed((ArrayList) inputMessage.obj); + break; + + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: + case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: + MainActivity.getInstance().UpdateOnGeoJournalListLoaded((ArrayList) inputMessage.obj); + break; + default: + super.handleMessage(inputMessage); + } + } + + }; + + } + + public static Context getContext() { + return instance; + } + + + + + public static void OnImageDownloaderStateFinished() + { + imageDownloadTask = null; + DownloadRestImageArr(); + } + + + public static void DownloadImageArr(String[] imageUrlArr, String[] imageHashArr) + { + + synchronized(queuedImgUrlArr) + { + + for (int i = 0; i < imageUrlArr.length; i++) + { + queuedImgUrlArr.add(imageUrlArr[i]); + + if (imageHashArr[i] == null) + { + queuedImgHashArr.add(""); + } + else + { + queuedImgHashArr.add(imageHashArr[i]); + } + } + + + } + + if (imageDownloadTask == null) + { + DownloadRestImageArr(); + } + + + } + + public static void DownloadRestImageArr() + { + synchronized(queuedImgUrlArr) + { + if (queuedImgUrlArr.size() > 0) + { + imageDownloadTask = new ImageDownloadTask(); + + imageDownloadTask.mHandler = mainHandler; + + Bundle innerQuery = new Bundle(); + + String[] imageUrlArr = queuedImgUrlArr.toArray(new String[queuedImgUrlArr.size()]); + String[] imageHashArr = queuedImgHashArr.toArray(new String[queuedImgHashArr.size()]); + + innerQuery.putStringArray("imageUrlArr", imageUrlArr); + innerQuery.putStringArray("imageHashArr", imageHashArr); + + queuedImgUrlArr.clear(); + queuedImgHashArr.clear(); + + imageDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, innerQuery); + + } + } + } + + public static void DownloadImage(String imageUrl, String imageHash) + { + + DownloadImageArr(new String[] { imageUrl }, new String[] { imageHash }); + } + + + + + + + public static void CancelDownloadDatabaseTask() + { + if (databaseDownloadTask != null) + { + databaseDownloadTask.cancel(false); + databaseDownloadTask = null; + } + + MainActivity.getInstance().UpdateOnDatabaseDownloaded(0); + } + + public static void DownloadDatabase() + { + + if (databaseDownloadTask != null) + { + return; + } + + databaseDownloadTask = new DatabaseDownloadTask(); + + databaseDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + + + public static void CancelDownloadNewsTask() + { + if (newsDownloadTask != null) + { + newsDownloadTask.cancel(false); + newsDownloadTask = null; + } + + MainActivity.getInstance().UpdateOnNewsDownloaded(0); + } + + public static void StartDownloadNewsTask() + { + + if (newsDownloadTask != null) + { + return; + } + + newsDownloadTask = new NewsDownloadTask(); + + newsDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + + + + public static void SetLastAlbumName(String lastAlbumName) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastAlbumName", lastAlbumName); + editor.commit(); + } + + public static String GetLastAlbumName() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastAlbumName", ""); + } + + public static void SetLastChannelName(String lastChannelName) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastChannelName", lastChannelName); + editor.commit(); + } + + public static String GetLastChannelName() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastChannelName", ""); + } + + public static void SetLastArticleName(String lastArticleName) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastArticleName", lastArticleName); + editor.commit(); + } + + public static String GetLastArticleName() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastArticleName", ""); + } + + + + public static void SetLastJournalName(String lastJournalName) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastJournalName", lastJournalName); + editor.commit(); + } + + + public static String GetLastJournalName() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastJournalName", ""); + } + + + public static void SetLastJournalTitle(String lastJournalTitle) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastJournalTitle", lastJournalTitle); + editor.commit(); + } + + public static String GetLastJournalTitle() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastJournalTitle", ""); + } + + public static void SetLastSearchQuery(String searchQuery) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("searchQuery", searchQuery); + editor.commit(); + } + + public static String GetLastSearchQuery() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("searchQuery", ""); + } + + public static void SetLastMapFilterName(String lastMapFilterName) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putString("lastMapFilterName", lastMapFilterName); + editor.commit(); + } + + public static String GetLastMapFilterName() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getString("lastMapFilterName", ""); + } + + public static void SetNewsDownloadProgress(int newsDownloadProgress) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("newsDownloadProgress", newsDownloadProgress); + editor.commit(); + } + + public static int GetNewsDownloadProgress() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getInt("newsDownloadProgress", 0); + } + + public static void SetDatabaseDownloadProgress(int databaseDownloadProgress) + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("databaseDownloadProgress", databaseDownloadProgress); + editor.commit(); + } + + public static int GetDatabaseDownloadProgress() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getInt("databaseDownloadProgress", 0); + } + + public static void SetLastLanguage(int lastLanguage) //0 russian, 1 english, 2 chinese + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("lastLanguage", lastLanguage); + editor.commit(); + } + + public static int GetLastLanguage() + { + SharedPreferences settings = instance.getSharedPreferences(PREFS_MAIN, 0); + return settings.getInt("lastLanguage", 0); + } + + public static String DateFormattedForLocale(Date date) + { + return DateUtils.formatDateTime(instance, date.getTime(), DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR); + + } + +} \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/CatalogFragment.java b/android/src/fishrungames/bashgid/CatalogFragment.java index 07504da..c58e987 100644 --- a/android/src/fishrungames/bashgid/CatalogFragment.java +++ b/android/src/fishrungames/bashgid/CatalogFragment.java @@ -210,7 +210,7 @@ public class CatalogFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_BACK_TO_CATALOGFRAGMENT); + MainActivity.getInstance().OpenJournalScreen(false, journalList.get(position).name, MainActivity.TAG_BACK_TO_CATALOGFRAGMENT); } }); @@ -220,7 +220,7 @@ public class CatalogFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_BACK_TO_CATALOGFRAGMENT); + MainActivity.getInstance().OpenJournalScreen(false, journalList.get(position).name, MainActivity.TAG_BACK_TO_CATALOGFRAGMENT); } }); diff --git a/android/src/fishrungames/bashgid/JournalFragment.java b/android/src/fishrungames/bashgid/JournalFragment.java index 5abe956..b3de09a 100644 --- a/android/src/fishrungames/bashgid/JournalFragment.java +++ b/android/src/fishrungames/bashgid/JournalFragment.java @@ -89,13 +89,13 @@ public class JournalFragment extends Fragment @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - MainActivity.getInstance().SetLastJournalName(journalName); + BashgidApplication.SetLastJournalName(journalName); if (position == 0) { if (journal.geoCategory == 1) { - MainActivity.getInstance().OpenMapScreen(journalName, MainActivity.TAG_BACK_TO_JOURNALFRAGMENT); + MainActivity.getInstance().OpenMapScreen(false, journalName, MainActivity.TAG_BACK_TO_JOURNALFRAGMENT); } } else @@ -225,8 +225,11 @@ public class JournalFragment extends Fragment TextView dateTextView = (TextView)view.findViewById(R.id.dateTextView); - dateTextView.setText(journal.articleArr.get(position).dateTime.toString()); + //datiiiiieTextView.setText(journal.articleArr.get(position).dateTime.toString()); + dateTextView.setText(BashgidApplication.DateFormattedForLocale(journal.articleArr.get(position).dateTime)); + + ImageView imageView = (ImageView) view.findViewById(R.id.imageView); if (journal.articleArr.get(position).previewImageUrl != null) diff --git a/android/src/fishrungames/bashgid/MainActivity.java b/android/src/fishrungames/bashgid/MainActivity.java index f4e8854..4ab3b14 100644 --- a/android/src/fishrungames/bashgid/MainActivity.java +++ b/android/src/fishrungames/bashgid/MainActivity.java @@ -1,8 +1,6 @@ package fishrungames.bashgid; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.Locale; @@ -11,38 +9,20 @@ import fishrungames.bashgid.core.AlbumManager.AlbumShortData; import fishrungames.bashgid.core.ArticleManager.ArticleFullData; import fishrungames.bashgid.core.ArticleManager.ArticleShortData; import fishrungames.bashgid.core.ChannelManager.ChannelFullData; -import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.JournalManager.JournalRecordData; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; -import fishrungames.bashgid.core.NewsDownloadTask; import fishrungames.bashgid.core.VideoManager.VideoRecordData; -import fishrungames.bashgid.core.db.AlbumDataSource; -import fishrungames.bashgid.core.db.ArticleDataSource; -import fishrungames.bashgid.core.db.BashgidSqliteHelper; -import fishrungames.bashgid.core.db.ChannelDataSource; -import fishrungames.bashgid.core.db.JournalDataSource; -import fishrungames.bashgid.core.db.PhotoDataSource; -import fishrungames.bashgid.core.db.TranslationDataSource; -import fishrungames.bashgid.core.db.VideoDataSource; -import fishrungames.networkutils.ContextHolder; -import fishrungames.networkutils.ImageDownloadTask; -import fishrungames.networkutils.ImageManager; import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Configuration; -import android.graphics.drawable.BitmapDrawable; -import android.os.AsyncTask; + import android.os.Bundle; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Looper; -import android.os.Message; + import android.view.Menu; import android.view.MenuInflater; @@ -52,7 +32,6 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; import android.support.v4.widget.DrawerLayout; -import android.text.format.DateUtils; public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { @@ -73,40 +52,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF - public static final String PREFS_MAIN = "PREFS_MAIN"; - - public static final int NEWS_DOWNLOADER_STATE_UPDATE = 10; - public static final int NEWS_DOWNLOADER_STATE_FINISHED = 11; - - public static final int DATABASE_DOWNLOADER_STATE_UPDATE = 12; - public static final int DATABASE_DOWNLOADER_STATE_FINISHED = 13; - - public static final int DATABASE_GET_ALBUM_STATE_UPDATE = 14; - public static final int DATABASE_GET_ALBUM_STATE_FINISHED = 15; - - public static final int DATABASE_GET_ALBUM_LIST_STATE_UPDATE = 16; - public static final int DATABASE_GET_ALBUM_LIST_STATE_FINISHED = 17; - - public static final int DATABASE_GET_ARTICLE_STATE_UPDATE = 18; - public static final int DATABASE_GET_ARTICLE_STATE_FINISHED = 19; - - public static final int DATABASE_GET_JOURNAL_STATE_UPDATE = 20; - public static final int DATABASE_GET_JOURNAL_STATE_FINISHED = 21; - - public static final int DATABASE_GET_CHANNEL_STATE_UPDATE = 22; - public static final int DATABASE_GET_CHANNEL_STATE_FINISHED = 23; - - public static final int DATABASE_GET_VIDEO_STATE_UPDATE = 24; - public static final int DATABASE_GET_VIDEO_STATE_FINISHED = 25; - - public static final int DATABASE_GET_JOURNAL_LIST_STATE_UPDATE = 26; - public static final int DATABASE_GET_JOURNAL_LIST_STATE_FINISHED = 27; - - public static final int DATABASE_SEARCH_ARTICLE_STATE_UPDATE = 28; - public static final int DATABASE_SEARCH_ARTICLE_STATE_FINISHED = 29; - - public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE = 30; - public static final int DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED = 31; + MainPageFragment mainPageFragment = null; @@ -130,443 +76,41 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF static MainActivity instance = null; private NavigationDrawerFragment mNavigationDrawerFragment = null; - - public BashgidSqliteHelper dbHelper = null; - - public PhotoDataSource photoDataSource = null; - public AlbumDataSource albumDataSource = null; - public ArticleDataSource articleDataSource = null; - - public VideoDataSource videoDataSource = null; - public ChannelDataSource channelDataSource = null; - - public JournalDataSource journalDataSource = null; - - public TranslationDataSource translationDataSource = null; + private int postnotedDrawerSelection = 0; - private NewsDownloadTask newsDownloadTask = null; - private DatabaseDownloadTask databaseDownloadTask = null; - private ImageDownloadTask imageDownloadTask = null; - - //private Object imgUrlSynchronizer = new Object(); - private ArrayList queuedImgUrlArr = new ArrayList(); - private ArrayList queuedImgHashArr = new ArrayList(); - - public static final SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); - - - //public Handler mHandler; - - //public Handler databaseHandler; - - public Handler mainHandler; - - //public HandlerThread downloadHandlerThread; - //public HandlerThread databaseHandlerThread; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + SetLanguage(BashgidApplication.GetLastLanguage()); - ImageManager.getInstance().PredefinedImageId.put("R.drawable.no_picture", R.drawable.no_picture); - ImageManager.getInstance().PredefinedImageIdBitmap.put("R.drawable.no_picture", ((BitmapDrawable)getResources().getDrawable(R.drawable.no_picture)).getBitmap()); - - ImageManager.PreferredEmptyPicture = "R.drawable.no_picture"; - setContentView(R.layout.activity_main); - + SetupDrawer(); - - ImageManager.getInstance().alwaysUpdateImagesWithoutHash = false; - - getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new WelcomeFragment(), null).commit(); + + CreateSelectedFragment(postnotedDrawerSelection); instance = this; - ContextHolder.setContext(instance); - - dbHelper = new BashgidSqliteHelper(this); - - photoDataSource = new PhotoDataSource(this, dbHelper); - - albumDataSource = new AlbumDataSource(this, dbHelper); - - articleDataSource = new ArticleDataSource(this, dbHelper); - - videoDataSource = new VideoDataSource(this, dbHelper); - - channelDataSource = new ChannelDataSource(this, dbHelper); - - journalDataSource = new JournalDataSource(this, dbHelper); - - translationDataSource = new TranslationDataSource(this, dbHelper); - - /* - - downloadHandlerThread = new HandlerThread("downloadHandlerThread"); - downloadHandlerThread.start(); - - - mHandler = new Handler(downloadHandlerThread.getLooper()) - { - @Override - public void handleMessage(Message inputMessage) - { - Message msg; - - switch (inputMessage.what) - { - - - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - - UpdateDatabaseRelatedThingsAndSendMessage(); - - case NEWS_DOWNLOADER_STATE_UPDATE: - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - break; - case NEWS_DOWNLOADER_STATE_FINISHED: - - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - JournalSemiFullData journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news", null, 3); - Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); - completeMessage.sendToTarget(); - break; - - case DATABASE_DOWNLOADER_STATE_UPDATE: - - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - break; - - case DATABASE_DOWNLOADER_STATE_FINISHED: - - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - - //UpdateDatabaseRelatedThingsAndSendMessage(); - - break; - - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: - msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - msg.sendToTarget(); - break; - - case DATABASE_GET_ALBUM_STATE_UPDATE: - case DATABASE_GET_ALBUM_STATE_FINISHED: - UpdateOnAlbumLoaded((AlbumFullData) inputMessage.obj); - break; - case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: - case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: - - ArrayList albumShortList = (ArrayList) inputMessage.obj; - - UpdateOnAlbumListLoaded(albumShortList); - break; - case DATABASE_GET_ARTICLE_STATE_UPDATE: - case DATABASE_GET_ARTICLE_STATE_FINISHED: - UpdateOnArticleLoaded((ArticleFullData) inputMessage.obj); - break; - case DATABASE_GET_JOURNAL_STATE_UPDATE: - case DATABASE_GET_JOURNAL_STATE_FINISHED: - UpdateOnJournalLoaded((JournalSemiFullData) inputMessage.obj); - break; - case DATABASE_GET_CHANNEL_STATE_UPDATE: - case DATABASE_GET_CHANNEL_STATE_FINISHED: - UpdateOnChannelLoaded((ChannelFullData) inputMessage.obj); - break; - - case DATABASE_GET_VIDEO_STATE_UPDATE: - case DATABASE_GET_VIDEO_STATE_FINISHED: - UpdateOnVideoLoaded((VideoRecordData) inputMessage.obj); - break; - - case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: - UpdateOnJournalListLoaded((ArrayList) inputMessage.obj); - break; - - case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: - case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: - UpdateOnArticleSearchPerformed((ArrayList) inputMessage.obj); - break; - - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: - UpdateOnGeoJournalListLoaded((ArrayList) inputMessage.obj); - break; - - default: - super.handleMessage(inputMessage); - } - } - - }; - - - databaseHandlerThread = new HandlerThread("databaseHandlerThread"); - databaseHandlerThread.start(); - - databaseHandler = new Handler(databaseHandlerThread.getLooper()) - { - @Override - public void handleMessage(Message inputMessage) - { - - switch (inputMessage.what) - { - - case DATABASE_GET_ALBUM_STATE_UPDATE: - case DATABASE_GET_ALBUM_STATE_FINISHED: - case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: - case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: - case DATABASE_GET_ARTICLE_STATE_UPDATE: - case DATABASE_GET_ARTICLE_STATE_FINISHED: - case DATABASE_GET_JOURNAL_STATE_UPDATE: - case DATABASE_GET_JOURNAL_STATE_FINISHED: - case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: - case DATABASE_GET_CHANNEL_STATE_UPDATE: - case DATABASE_GET_CHANNEL_STATE_FINISHED: - case DATABASE_GET_VIDEO_STATE_UPDATE: - case DATABASE_GET_VIDEO_STATE_FINISHED: - case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: - case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: - - Message msg = mainHandler.obtainMessage(inputMessage.what, inputMessage.obj); - - msg.sendToTarget(); - - //DownloadRestImageArr(); - - break; - - default: - super.handleMessage(inputMessage); - } - } - - };*/ - - - mainHandler = new Handler(Looper.getMainLooper()) - { - @Override - public void handleMessage(Message inputMessage) - { - - switch (inputMessage.what) - { - - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE: - UpdateOnImageDownloaded(); - break; - case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED: - UpdateOnImageDownloaded(); - imageDownloadTask = null; - DownloadRestImageArr(); - break; - case NEWS_DOWNLOADER_STATE_UPDATE: - UpdateOnNewsDownloaded((Integer)inputMessage.obj); - break; - case NEWS_DOWNLOADER_STATE_FINISHED: - UpdateOnNewsDownloaded((Integer)inputMessage.obj); - newsDownloadTask = null; - break; - case DATABASE_DOWNLOADER_STATE_UPDATE: - UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); - break; - case DATABASE_DOWNLOADER_STATE_FINISHED: - UpdateOnDatabaseDownloaded((Integer)inputMessage.obj); - databaseDownloadTask = null; - break; - - case DATABASE_GET_JOURNAL_STATE_UPDATE: - case DATABASE_GET_JOURNAL_STATE_FINISHED: - final JournalSemiFullData journal = (JournalSemiFullData) inputMessage.obj; - UpdateOnJournalLoaded(journal); - break; - case DATABASE_GET_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_JOURNAL_LIST_STATE_FINISHED: - UpdateOnJournalListLoaded((ArrayList) inputMessage.obj); - break; - - case DATABASE_GET_ALBUM_STATE_UPDATE: - case DATABASE_GET_ALBUM_STATE_FINISHED: - UpdateOnAlbumLoaded((AlbumFullData) inputMessage.obj); - break; - case DATABASE_GET_ALBUM_LIST_STATE_UPDATE: - case DATABASE_GET_ALBUM_LIST_STATE_FINISHED: - - ArrayList albumShortList = (ArrayList) inputMessage.obj; - UpdateOnAlbumListLoaded(albumShortList); - break; - case DATABASE_GET_ARTICLE_STATE_UPDATE: - case DATABASE_GET_ARTICLE_STATE_FINISHED: - UpdateOnArticleLoaded((ArticleFullData) inputMessage.obj); - break; - - case DATABASE_GET_CHANNEL_STATE_UPDATE: - case DATABASE_GET_CHANNEL_STATE_FINISHED: - UpdateOnChannelLoaded((ChannelFullData) inputMessage.obj); - break; - - case DATABASE_GET_VIDEO_STATE_UPDATE: - case DATABASE_GET_VIDEO_STATE_FINISHED: - UpdateOnVideoLoaded((VideoRecordData) inputMessage.obj); - break; - - - - case DATABASE_SEARCH_ARTICLE_STATE_UPDATE: - case DATABASE_SEARCH_ARTICLE_STATE_FINISHED: - UpdateOnArticleSearchPerformed((ArrayList) inputMessage.obj); - break; - - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE: - case DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED: - UpdateOnGeoJournalListLoaded((ArrayList) inputMessage.obj); - break; - default: - super.handleMessage(inputMessage); - } - } - - }; - - //DownloadDatabase(); - } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + mNavigationDrawerFragment.onConfigurationChanged(newConfig); + } + public static MainActivity getInstance() { return instance; } -/* - public void DownloadImageArr(String[] imageUrlArr) - { - - Bundle innerQuery = new Bundle(); - - innerQuery.putStringArray("imageUrlArr", imageUrlArr); - - ImageDownloadTask task = new ImageDownloadTask(); - - task.mHandler = mHandler; - - task.execute(innerQuery); - }*/ - - public void DownloadImageArr(String[] imageUrlArr, String[] imageHashArr) - { - - synchronized(queuedImgUrlArr) - { - - for (int i = 0; i < imageUrlArr.length; i++) - { - queuedImgUrlArr.add(imageUrlArr[i]); - - if (imageHashArr[i] == null) - { - queuedImgHashArr.add(""); - } - else - { - queuedImgHashArr.add(imageHashArr[i]); - } - } - - - } - - if (imageDownloadTask == null) - { - DownloadRestImageArr(); - } - - - } - public void DownloadRestImageArr() - { - synchronized(queuedImgUrlArr) - { - if (queuedImgUrlArr.size() > 0) - { - imageDownloadTask = new ImageDownloadTask(); - - imageDownloadTask.mHandler = mainHandler; - - Bundle innerQuery = new Bundle(); - - String[] imageUrlArr = queuedImgUrlArr.toArray(new String[queuedImgUrlArr.size()]); - String[] imageHashArr = queuedImgHashArr.toArray(new String[queuedImgHashArr.size()]); - - innerQuery.putStringArray("imageUrlArr", imageUrlArr); - innerQuery.putStringArray("imageHashArr", imageHashArr); - - queuedImgUrlArr.clear(); - queuedImgHashArr.clear(); - - imageDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, innerQuery); - - } - } - } - - /* - public void DownloadImage(String imageUrl) - { - this.DownloadImageArr(new String[] { imageUrl }); - } -*/ - public void DownloadImage(String imageUrl, String imageHash) - { - - this.DownloadImageArr(new String[] { imageUrl }, new String[] { imageHash }); - } - public void CancelDownloadDatabaseTask() - { - if (databaseDownloadTask != null) - { - databaseDownloadTask.cancel(false); - databaseDownloadTask = null; - } - - UpdateOnDatabaseDownloaded(0); - } - - public void DownloadDatabase() - { - /* - if (databaseDownloadTask != null) - { - databaseDownloadTask.cancel(false); - databaseDownloadTask = null; - }*/ - if (databaseDownloadTask != null) - { - return; - } - - databaseDownloadTask = new DatabaseDownloadTask(); - - databaseDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } + public void ClearAllFragmentLinks() { @@ -591,69 +135,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); } - public void UpdateDatabaseRelatedThingsAndSendMessage() - { - if (mainPageFragment != null) - { - ArrayList journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(3); - - Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); - completeMessage.sendToTarget(); - } - - if (catalogFragment != null) - { - ArrayList journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(3); - - Message completeMessage = mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); - completeMessage.sendToTarget(); - } - } - - /* - public void StartDownloadImagesTask(ArrayList imageUrlArr, ArrayList imageHashArr) - { - ImageDownloadTask task = new ImageDownloadTask(); - - task.mHandler = mHandler; - - Bundle query = new Bundle(); - - query.putStringArray("imageUrlArr", (String[]) imageUrlArr.toArray()); - - task.execute(query); - }*/ - - - public void CancelDownloadNewsTask() - { - if (newsDownloadTask != null) - { - newsDownloadTask.cancel(false); - newsDownloadTask = null; - } - - UpdateOnNewsDownloaded(0); - } - - public void StartDownloadNewsTask() - { - /* - if (newsDownloadTask != null) - { - newsDownloadTask.cancel(false); - newsDownloadTask = null; - }*/ - if (newsDownloadTask != null) - { - return; - } - - newsDownloadTask = new NewsDownloadTask(); - - newsDownloadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - public void UpdateOnImageDownloaded() { if (mainPageFragment != null) @@ -710,8 +191,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public void UpdateOnNewsDownloaded(Integer percent) { - SetNewsDownloadProgress(percent); - if (mainPageFragment != null) { mainPageFragment.OnNewsDownloadProgress(percent); @@ -725,7 +204,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public void UpdateOnDatabaseDownloaded(Integer percent) { - SetDatabaseDownloadProgress(percent); + BashgidApplication.SetDatabaseDownloadProgress(percent); if (mainPageFragment != null) { @@ -868,7 +347,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF { if (searchFragment != null) { - OpenSearchScreen(); + OpenSearchScreen(false); return; } @@ -891,76 +370,110 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF return; } - OpenSearchScreen(); + OpenSearchScreen(false); + } + + public void SetLanguage(int language) + { + Configuration config = new Configuration(); + + if (language == 0) + { + Locale locale = new Locale("ru"); + Locale.setDefault(locale); + config.locale = locale; + } + else if (language == 2) + { + Locale.setDefault(Locale.CHINA); + config.locale = Locale.CHINA; + } + else + { + Locale.setDefault(Locale.US); + config.locale = Locale.US; + } + + getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); + } public void OnSelectEnglish(View view) { - Locale.setDefault(Locale.US); - Configuration config = new Configuration(); - config.locale = Locale.US; - getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); - + + SetLanguage(1); + BashgidApplication.SetLastLanguage(1); + getSupportActionBar().setTitle(R.string.app_name); SetupDrawer(); - OpenMainScreen(); + OpenMainScreen(false); } 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()); - + SetLanguage(0); + BashgidApplication.SetLastLanguage(0); getSupportActionBar().setTitle(R.string.app_name); SetupDrawer(); - OpenMainScreen(); + OpenMainScreen(false); } public void OnSelectChinese(View view) { - Locale.setDefault(Locale.CHINA); - Configuration config = new Configuration(); - config.locale = Locale.CHINA; - getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); - + SetLanguage(2); + BashgidApplication.SetLastLanguage(2); getSupportActionBar().setTitle(R.string.app_name); SetupDrawer(); - OpenMainScreen(); + OpenMainScreen(false); } - public void OpenMainScreen() + public void OpenMainScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); mainPageFragment = new MainPageFragment(); - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mainPageFragment).commit(); + if (fromSavedInstanceState) + { + getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mainPageFragment).commit(); + } + else + { + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mainPageFragment).commit(); + } mNavigationDrawerFragment.EnableDrawer(); } - public void OpenNewsScreen() + public void OpenNewsScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); newsListFragment = new NewsListFragment(); + + if (fromSavedInstanceState) + { + getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, newsListFragment, TAG_BACK_TO_MAINFRAGMENT).commit(); - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsListFragment, TAG_BACK_TO_MAINFRAGMENT).commit(); + } + else + { + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsListFragment, TAG_BACK_TO_MAINFRAGMENT).commit(); + } + + mNavigationDrawerFragment.EnableDrawer(); } - public void OpenCatalogScreen() + public void OpenCatalogScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); @@ -973,7 +486,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF } - public void OpenJournalScreen(String journalName, String tag) + public void OpenJournalScreen(boolean fromSavedInstanceState, String journalName, String tag) { ClearAllFragmentLinks(); @@ -985,16 +498,25 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } - public void OpenSettingsScreen() + public void OpenSettingsScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); + + + if (fromSavedInstanceState) + { + getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new SettingsFragment()).commit(); - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); + } + else + { + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); + } mNavigationDrawerFragment.EnableDrawer(); } - public void OpenSearchScreen() + public void OpenSearchScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); @@ -1038,7 +560,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } - public void OpenMapScreen(String filter, String tag) + public void OpenMapScreen(boolean fromSavedInstanceState, String filter, String tag) { ClearAllFragmentLinks(); @@ -1058,7 +580,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } - public void OpenPhotoAlbumListScreen() + public void OpenPhotoAlbumListScreen(boolean fromSavedInstanceState) { ClearAllFragmentLinks(); @@ -1114,7 +636,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } - public void OpenVideoListScreen(String channelName) + public void OpenVideoListScreen(boolean fromSavedInstanceState, String channelName) { ClearAllFragmentLinks(); @@ -1127,12 +649,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF public void OpenVideoRecordScreen(VideoRecordData video) { - // Xperimental -- addToBackStack provoke error "Class not found". Need - // to resolve somehow! - // getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, - // new NewsRecordFragment(newsRecord)).addToBackStack(null).commit(); - - // I added workaround: ClearAllFragmentLinks(); @@ -1143,15 +659,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF mNavigationDrawerFragment.EnableDrawer(); } - /* - public void UpdateMainScreenIfPossible(Bundle result) - { - if (mainPageFragment != null) - { - mainPageFragment.RefreshJournal(); - } - }*/ - @Override public void onAttachFragment(Fragment fragment) { @@ -1159,6 +666,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF } + public void SetupDrawer() { @@ -1199,33 +707,79 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF } @Override - public void onNavigationDrawerItemSelected(int position) + public void onNavigationDrawerItemSelected(int position, boolean fromSavedInstanceState) { + + if (fromSavedInstanceState) + { + + postnotedDrawerSelection = position; + return; + } + if (position == 1) { - OpenMainScreen(); + OpenMainScreen(false); } else if (position == 2) { - OpenNewsScreen(); + OpenNewsScreen(false); } else if (position == 3) { - OpenCatalogScreen(); + OpenCatalogScreen(false); } else if (position == 4) { - OpenMapScreen("map", MainActivity.TAG_BACK_TO_MAINFRAGMENT); + OpenMapScreen(false, "map", MainActivity.TAG_BACK_TO_MAINFRAGMENT); } else if (position == 5) { - OpenVideoListScreen("main"); + OpenVideoListScreen(false, "main"); } else if (position == 6) { - OpenPhotoAlbumListScreen(); + OpenPhotoAlbumListScreen(false); } else if (position == 7) { - OpenJournalScreen("investor", MainActivity.TAG_BACK_TO_MAINFRAGMENT); + OpenJournalScreen(false, "investor", MainActivity.TAG_BACK_TO_MAINFRAGMENT); } else if (position == 8) { - OpenSettingsScreen(); + OpenSettingsScreen(false); + } + } + + public void CreateSelectedFragment(int position) + { + if (position == 1) + { + OpenMainScreen(true); + } else if (position == 2) + { + OpenNewsScreen(true); + + } else if (position == 3) + { + OpenCatalogScreen(true); + } else if (position == 4) + { + OpenMapScreen(true, "map", MainActivity.TAG_BACK_TO_MAINFRAGMENT); + } else if (position == 5) + { + OpenVideoListScreen(true, "main"); + } else if (position == 6) + { + OpenPhotoAlbumListScreen(true); + } else if (position == 7) + { + OpenJournalScreen(true, "investor", MainActivity.TAG_BACK_TO_MAINFRAGMENT); + } else if (position == 8) + { + OpenSettingsScreen(true); + } + else + { + if (true) + { + getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new WelcomeFragment(), null).commit(); + + } } } @@ -1237,62 +791,62 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_MAPFRAGMENT) != null) { - OpenMapScreen(GetLastMapFilterName(), TAG_BACK_TO_MAINFRAGMENT); + OpenMapScreen(false, BashgidApplication.GetLastMapFilterName(), TAG_BACK_TO_MAINFRAGMENT); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_NEWSLISTFRAGMENT) != null) { - OpenNewsScreen(); + OpenNewsScreen(false); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_SEARCHFRAGMENT) != null) { - OpenSearchScreen(GetLastSearchQuery(), GetLastJournalName(), GetLastJournalTitle()); + OpenSearchScreen(BashgidApplication.GetLastSearchQuery(), BashgidApplication.GetLastJournalName(), BashgidApplication.GetLastJournalTitle()); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_JOURNALFRAGMENT) != null) { - OpenJournalScreen(GetLastJournalName(), TAG_BACK_TO_MAINFRAGMENT); + OpenJournalScreen(false, BashgidApplication.GetLastJournalName(), TAG_BACK_TO_MAINFRAGMENT); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_ARTICLEFRAGMENT) != null) { - OpenArticleScreen(GetLastArticleName(), TAG_BACK_TO_MAINFRAGMENT); + OpenArticleScreen(BashgidApplication.GetLastArticleName(), TAG_BACK_TO_MAINFRAGMENT); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_ALBUMFRAGMENT) != null) { - OpenPhotoAlbumScreen(GetLastAlbumName()); + OpenPhotoAlbumScreen(BashgidApplication.GetLastAlbumName()); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_ALBUMLISTFRAGMENT) != null) { - OpenPhotoAlbumListScreen(); + OpenPhotoAlbumListScreen(false); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_CHANNELFRAGMENT) != null) { - OpenVideoListScreen(GetLastChannelName()); + OpenVideoListScreen(false, BashgidApplication.GetLastChannelName()); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_CATALOGFRAGMENT) != null) { - OpenCatalogScreen(); + OpenCatalogScreen(false); return; } if (getSupportFragmentManager().findFragmentByTag(TAG_BACK_TO_MAINFRAGMENT) != null) { - OpenMainScreen(); + OpenMainScreen(false); return; } @@ -1301,150 +855,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF } - public void SetLastAlbumName(String lastAlbumName) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastAlbumName", lastAlbumName); - editor.commit(); - } - - public String GetLastAlbumName() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastAlbumName", ""); - } - public void SetLastChannelName(String lastChannelName) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastChannelName", lastChannelName); - editor.commit(); - } - - public String GetLastChannelName() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastChannelName", ""); - } - - public void SetLastArticleName(String lastArticleName) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastArticleName", lastArticleName); - editor.commit(); - } - - public String GetLastArticleName() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastArticleName", ""); - } - - - - public void SetLastJournalName(String lastJournalName) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastJournalName", lastJournalName); - editor.commit(); - } - - - public String GetLastJournalName() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastJournalName", ""); - } - - - public void SetLastJournalTitle(String lastJournalTitle) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastJournalTitle", lastJournalTitle); - editor.commit(); - } - - public String GetLastJournalTitle() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastJournalTitle", ""); - } - - public void SetLastSearchQuery(String searchQuery) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("searchQuery", searchQuery); - editor.commit(); - } - - public String GetLastSearchQuery() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("searchQuery", ""); - } - - public void SetLastMapFilterName(String lastMapFilterName) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putString("lastMapFilterName", lastMapFilterName); - editor.commit(); - } - - public String GetLastMapFilterName() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getString("lastMapFilterName", ""); - } - - public void SetNewsDownloadProgress(int newsDownloadProgress) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putInt("newsDownloadProgress", newsDownloadProgress); - editor.commit(); - } - - public int GetNewsDownloadProgress() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getInt("newsDownloadProgress", 0); - } - - public void SetDatabaseDownloadProgress(int databaseDownloadProgress) - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - - SharedPreferences.Editor editor = settings.edit(); - editor.putInt("databaseDownloadProgress", databaseDownloadProgress); - editor.commit(); - } - - public int GetDatabaseDownloadProgress() - { - SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0); - return settings.getInt("databaseDownloadProgress", 0); - } - - public String DateFormattedForLocale(Date date) - { - return DateUtils.formatDateTime(this, date.getTime(), DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR); - - } @Override diff --git a/android/src/fishrungames/bashgid/MainPageFragment.java b/android/src/fishrungames/bashgid/MainPageFragment.java index 0b791ff..e12dca8 100644 --- a/android/src/fishrungames/bashgid/MainPageFragment.java +++ b/android/src/fishrungames/bashgid/MainPageFragment.java @@ -73,13 +73,13 @@ public class MainPageFragment extends Fragment newsDownloadProgressBar.setVisibility(View.VISIBLE); - newsDownloadProgressBar.setProgress(MainActivity.getInstance().GetNewsDownloadProgress()); + newsDownloadProgressBar.setProgress(BashgidApplication.GetNewsDownloadProgress()); databaseDownloadProgressBar = (ProgressBar) header.findViewById(R.id.databaseDownloadProgressBar); databaseDownloadProgressBar.setVisibility(View.VISIBLE); - databaseDownloadProgressBar.setProgress(MainActivity.getInstance().GetDatabaseDownloadProgress()); + databaseDownloadProgressBar.setProgress(BashgidApplication.GetDatabaseDownloadProgress()); Button moreNewsButton = (Button) header.findViewById(R.id.moreNewsButton); @@ -89,7 +89,7 @@ public class MainPageFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().OpenNewsScreen(); + MainActivity.getInstance().OpenNewsScreen(false); } }); @@ -131,8 +131,8 @@ public class MainPageFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().CancelDownloadDatabaseTask(); - MainActivity.getInstance().DownloadDatabase(); + BashgidApplication.CancelDownloadDatabaseTask(); + BashgidApplication.DownloadDatabase(); } }); @@ -144,16 +144,16 @@ public class MainPageFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().CancelDownloadNewsTask(); - MainActivity.getInstance().StartDownloadNewsTask(); + BashgidApplication.CancelDownloadNewsTask(); + BashgidApplication.StartDownloadNewsTask(); } }); RestoreJournalListFromDatabase(); RestoreNewsFromDatabase(); - MainActivity.getInstance().StartDownloadNewsTask(); - MainActivity.getInstance().DownloadDatabase(); + BashgidApplication.StartDownloadNewsTask(); + BashgidApplication.DownloadDatabase(); return rootView; } @@ -409,7 +409,7 @@ public class MainPageFragment extends Fragment { databaseGetJournalTask.cancel(false); } - MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_BACK_TO_MAINFRAGMENT); + MainActivity.getInstance().OpenJournalScreen(false, journalList.get(position).name, MainActivity.TAG_BACK_TO_MAINFRAGMENT); } }); @@ -422,7 +422,7 @@ public class MainPageFragment extends Fragment { databaseGetJournalTask.cancel(false); } - MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_BACK_TO_MAINFRAGMENT); + MainActivity.getInstance().OpenJournalScreen(false, journalList.get(position).name, MainActivity.TAG_BACK_TO_MAINFRAGMENT); } }); diff --git a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java index f0887af..2c67545 100644 --- a/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java +++ b/android/src/fishrungames/bashgid/MainPageHListViewAdapters.java @@ -129,7 +129,7 @@ public class MainPageHListViewAdapters textView.setText(journal.articleArr.get(position).title); - subTextView.setText(MainActivity.getInstance().DateFormattedForLocale(journal.articleArr.get(position).dateTime)); + subTextView.setText(BashgidApplication.DateFormattedForLocale(journal.articleArr.get(position).dateTime)); String imageUrl = journal.articleArr.get(position).previewImageUrl; diff --git a/android/src/fishrungames/bashgid/NavigationDrawerFragment.java b/android/src/fishrungames/bashgid/NavigationDrawerFragment.java index 9a6c173..0bb3611 100644 --- a/android/src/fishrungames/bashgid/NavigationDrawerFragment.java +++ b/android/src/fishrungames/bashgid/NavigationDrawerFragment.java @@ -94,7 +94,8 @@ public class NavigationDrawerFragment extends Fragment } // Select either the default item (0) or the last selected item. - selectItem(mCurrentSelectedPosition); + selectItemFromStart(mCurrentSelectedPosition); + } @@ -252,7 +253,24 @@ public class NavigationDrawerFragment extends Fragment } if (mCallbacks != null) { - mCallbacks.onNavigationDrawerItemSelected(position); + mCallbacks.onNavigationDrawerItemSelected(position, false); + } + } + + private void selectItemFromStart(int position) + { + mCurrentSelectedPosition = position; + if (mDrawerListView != null) + { + mDrawerListView.setItemChecked(position, true); + } + if (mDrawerLayout != null) + { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + if (mCallbacks != null) + { + mCallbacks.onNavigationDrawerItemSelected(position, true); } } @@ -351,7 +369,7 @@ public class NavigationDrawerFragment extends Fragment /** * Called when an item in the navigation drawer is selected. */ - void onNavigationDrawerItemSelected(int position); + void onNavigationDrawerItemSelected(int position, boolean fromSavedInstanceState); } public class DrawerAdapter extends BaseAdapter diff --git a/android/src/fishrungames/bashgid/NewsListFragment.java b/android/src/fishrungames/bashgid/NewsListFragment.java index d4eb010..4810edf 100644 --- a/android/src/fishrungames/bashgid/NewsListFragment.java +++ b/android/src/fishrungames/bashgid/NewsListFragment.java @@ -64,7 +64,7 @@ public class NewsListFragment extends Fragment newsDownloadProgressBar.setVisibility(View.VISIBLE); - newsDownloadProgressBar.setProgress(MainActivity.getInstance().GetNewsDownloadProgress()); + newsDownloadProgressBar.setProgress(BashgidApplication.GetNewsDownloadProgress()); View footer = inflater.inflate(R.layout.news_page_list_footer, null); @@ -107,13 +107,13 @@ public class NewsListFragment extends Fragment @Override public void onClick(View v) { - MainActivity.getInstance().CancelDownloadNewsTask(); - MainActivity.getInstance().StartDownloadNewsTask(); + BashgidApplication.CancelDownloadNewsTask(); + BashgidApplication.StartDownloadNewsTask(); } }); RestoreNewsFromDatabase(); - MainActivity.getInstance().StartDownloadNewsTask(); + BashgidApplication.StartDownloadNewsTask(); return rootView; } diff --git a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java index f822cfa..21e1aa1 100644 --- a/android/src/fishrungames/bashgid/OsmMapHolderFragment.java +++ b/android/src/fishrungames/bashgid/OsmMapHolderFragment.java @@ -222,7 +222,7 @@ public class OsmMapHolderFragment extends Fragment { if (journalName != null && journalName.length() > 0) { - MainActivity.getInstance().SetLastMapFilterName(journalName); + BashgidApplication.SetLastMapFilterName(journalName); MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), MainActivity.TAG_BACK_TO_MAPFRAGMENT); } else { @@ -468,7 +468,7 @@ public class OsmMapHolderFragment extends Fragment databaseGetArticleTask = new DatabaseGetArticleTask(); - databaseGetArticleTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetArticleTask.mHandler = MainActivity.getInstance().mainHandler; databaseGetArticleTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, filter); @@ -484,7 +484,7 @@ public class OsmMapHolderFragment extends Fragment databaseGetGeoJournalListTask = new DatabaseGetGeoJournalListTask(); - databaseGetGeoJournalListTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetGeoJournalListTask.mHandler = MainActivity.getInstance().mainHandler; databaseGetGeoJournalListTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/android/src/fishrungames/bashgid/PhotoAlbumFragment.java b/android/src/fishrungames/bashgid/PhotoAlbumFragment.java index 9958820..91854f5 100644 --- a/android/src/fishrungames/bashgid/PhotoAlbumFragment.java +++ b/android/src/fishrungames/bashgid/PhotoAlbumFragment.java @@ -79,7 +79,7 @@ public class PhotoAlbumFragment extends Fragment @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - MainActivity.getInstance().SetLastAlbumName(albumName); + BashgidApplication.SetLastAlbumName(albumName); MainActivity.getInstance().OpenPhotoScreen(album, position, MainActivity.TAG_BACK_TO_ALBUMFRAGMENT); } @@ -134,7 +134,7 @@ public class PhotoAlbumFragment extends Fragment { databaseGetAlbumTask = new DatabaseGetAlbumTask(); - databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; databaseGetAlbumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, albumName); } diff --git a/android/src/fishrungames/bashgid/PhotoFragment.java b/android/src/fishrungames/bashgid/PhotoFragment.java index bf9ba64..fd8ec9b 100644 --- a/android/src/fishrungames/bashgid/PhotoFragment.java +++ b/android/src/fishrungames/bashgid/PhotoFragment.java @@ -104,7 +104,7 @@ public class PhotoFragment extends Fragment { databaseGetAlbumTask = new DatabaseGetAlbumTask(); - databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetAlbumTask.mHandler = MainActivity.getInstance().mainHandler; databaseGetAlbumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, albumName); } diff --git a/android/src/fishrungames/bashgid/SearchFragment.java b/android/src/fishrungames/bashgid/SearchFragment.java index 9ec37d2..5b00308 100644 --- a/android/src/fishrungames/bashgid/SearchFragment.java +++ b/android/src/fishrungames/bashgid/SearchFragment.java @@ -170,10 +170,10 @@ public class SearchFragment extends Fragment public void onItemClick(AdapterView parent, View view, int position, long id) { - MainActivity.getInstance().SetLastJournalName(journalName); - MainActivity.getInstance().SetLastJournalTitle(journalTitle); + BashgidApplication.SetLastJournalName(journalName); + BashgidApplication.SetLastJournalTitle(journalTitle); - MainActivity.getInstance().SetLastSearchQuery(query); + BashgidApplication.SetLastSearchQuery(query); MainActivity.getInstance().OpenArticleScreen(searchResultArr.get(position - 1).name, MainActivity.TAG_BACK_TO_SEARCHFRAGMENT); } }); @@ -208,7 +208,7 @@ public class SearchFragment extends Fragment databaseSearchArticleTask = new DatabaseSearchArticleTask(); - databaseSearchArticleTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseSearchArticleTask.mHandler = MainActivity.getInstance().mainHandler; Bundle bundle = new Bundle(); @@ -305,7 +305,10 @@ public class SearchFragment extends Fragment TextView dateTextView = (TextView) view.findViewById(R.id.dateTextView); - dateTextView.setText(MainActivity.iso8601Format.format(searchResultArr.get(position).dateTime)); + //dateTextView.setText(MainActivity.iso8601Format.format(searchResultArr.get(position).dateTime)); + //dateTextView.setText(MainActivity.iso8601Format.format(searchResultArr.get(position).dateTime)); + dateTextView.setText(BashgidApplication.DateFormattedForLocale(searchResultArr.get(position).dateTime)); + ImageView imageView = (ImageView) view.findViewById(R.id.imageView); diff --git a/android/src/fishrungames/bashgid/SquareImageView.java b/android/src/fishrungames/bashgid/SquareImageView.java index dc8bce6..3743190 100644 --- a/android/src/fishrungames/bashgid/SquareImageView.java +++ b/android/src/fishrungames/bashgid/SquareImageView.java @@ -34,4 +34,5 @@ protected void onMeasure(int width, int height) { }*/ } + } \ No newline at end of file diff --git a/android/src/fishrungames/bashgid/VideoListFragment.java b/android/src/fishrungames/bashgid/VideoListFragment.java index 137f4d0..6f31407 100644 --- a/android/src/fishrungames/bashgid/VideoListFragment.java +++ b/android/src/fishrungames/bashgid/VideoListFragment.java @@ -42,6 +42,7 @@ public class VideoListFragment extends Fragment public VideoListFragment() { + this.channelName = ""; } public VideoListFragment(String channelName) @@ -85,7 +86,7 @@ public class VideoListFragment extends Fragment public void onItemClick(AdapterView parent, View view, int position, long id) { - MainActivity.getInstance().SetLastChannelName(channelName); + BashgidApplication.SetLastChannelName(channelName); MainActivity.getInstance().OpenVideoRecordScreen(channelFullData.videoRecordArr.get(position)); } @@ -141,7 +142,7 @@ public class VideoListFragment extends Fragment databaseGetChannelTask = new DatabaseGetChannelTask(); - databaseGetChannelTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetChannelTask.mHandler = MainActivity.getInstance().mainHandler; databaseGetChannelTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, channelName); } @@ -180,20 +181,20 @@ public class VideoListFragment extends Fragment ChannelFullData channel = null; - public Handler mHandler; + //public Handler mHandler; protected Long doInBackground(String... queryArr) { String channelName = queryArr[0]; - channel = MainActivity.getInstance().channelDataSource.GetChannelFullData(channelName); + channel = BashgidApplication.channelDataSource.GetChannelFullData(channelName); return (long) 0; } protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_CHANNEL_STATE_UPDATE, channel); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_CHANNEL_STATE_UPDATE, channel); completeMessage.sendToTarget(); @@ -201,7 +202,7 @@ public class VideoListFragment extends Fragment protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_CHANNEL_STATE_FINISHED, channel); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_CHANNEL_STATE_FINISHED, channel); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/VideoRecordFragment.java b/android/src/fishrungames/bashgid/VideoRecordFragment.java index f75384e..a7a5768 100644 --- a/android/src/fishrungames/bashgid/VideoRecordFragment.java +++ b/android/src/fishrungames/bashgid/VideoRecordFragment.java @@ -108,7 +108,7 @@ public class VideoRecordFragment extends Fragment databaseGetVideoTask = new DatabaseGetVideoTask(); - databaseGetVideoTask.mHandler = MainActivity.getInstance().mainHandler; + //databaseGetVideoTask.mHandler = BashgidApplication.mainHandler; databaseGetVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, videoUrl); } @@ -159,20 +159,20 @@ public class VideoRecordFragment extends Fragment VideoRecordData recordData = null; - public Handler mHandler; + //public Handler mHandler; protected Long doInBackground(String... queryArr) { String videoUrl = queryArr[0]; - recordData = MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl); + recordData = BashgidApplication.videoDataSource.GetVideoByVideoUrl(videoUrl); return (long) 0; } protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_VIDEO_STATE_UPDATE, recordData); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_VIDEO_STATE_UPDATE, recordData); completeMessage.sendToTarget(); @@ -180,7 +180,7 @@ public class VideoRecordFragment extends Fragment protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_VIDEO_STATE_FINISHED, recordData); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_VIDEO_STATE_FINISHED, recordData); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/AlbumManager.java b/android/src/fishrungames/bashgid/core/AlbumManager.java index c833706..f097e53 100644 --- a/android/src/fishrungames/bashgid/core/AlbumManager.java +++ b/android/src/fishrungames/bashgid/core/AlbumManager.java @@ -3,6 +3,7 @@ package fishrungames.bashgid.core; import java.util.ArrayList; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ChannelManager.ChannelRecordData; @@ -73,19 +74,19 @@ public class AlbumManager public static void DownloadAndAddPhoto(PhotoRecordData recordData) { - MainActivity.getInstance().DownloadImage(recordData.imageUrl, recordData.imageHash); + BashgidApplication.DownloadImage(recordData.imageUrl, recordData.imageHash); - MainActivity.getInstance().photoDataSource.AddOrReplacePhoto(recordData); + BashgidApplication.photoDataSource.AddOrReplacePhoto(recordData); } public static void AddExistingPhotoToAlbum(String imageUrl, String albumName) { - if (!MainActivity.getInstance().albumDataSource.IsAlbumAlreadyExist(albumName)) + if (!BashgidApplication.albumDataSource.IsAlbumAlreadyExist(albumName)) { - MainActivity.getInstance().albumDataSource.CreateNewAlbum(new AlbumRecordData(albumName, albumName, "", 1)); + BashgidApplication.albumDataSource.CreateNewAlbum(new AlbumRecordData(albumName, albumName, "", 1)); } - MainActivity.getInstance().albumDataSource.AddPhotoToAlbum(imageUrl, albumName); + BashgidApplication.albumDataSource.AddPhotoToAlbum(imageUrl, albumName); } @@ -99,20 +100,20 @@ public class AlbumManager public static void AddNewVideo(VideoRecordData recordData) { - MainActivity.getInstance().DownloadImage(recordData.previewImageUrl, recordData.previewImageHash); + BashgidApplication.DownloadImage(recordData.previewImageUrl, recordData.previewImageHash); - MainActivity.getInstance().videoDataSource.AddOrReplaceVideo(recordData); + BashgidApplication.videoDataSource.AddOrReplaceVideo(recordData); } public static void AddExistingVideoToChannel(String videoUrl, String channelName) { - if (!MainActivity.getInstance().channelDataSource.IsChannelAlreadyExist(channelName)) + if (!BashgidApplication.channelDataSource.IsChannelAlreadyExist(channelName)) { - MainActivity.getInstance().channelDataSource.CreateNewChannel(new ChannelRecordData(channelName, channelName, "", 1)); + BashgidApplication.channelDataSource.CreateNewChannel(new ChannelRecordData(channelName, channelName, "", 1)); } - MainActivity.getInstance().channelDataSource.AddVideoToChannel(videoUrl, channelName); + BashgidApplication.channelDataSource.AddVideoToChannel(videoUrl, channelName); } @@ -126,18 +127,18 @@ public class AlbumManager public static void AddNewArticle(ArticleRecordData recordData) { - MainActivity.getInstance().articleDataSource.CreateNewArticle(recordData); + BashgidApplication.articleDataSource.CreateNewArticle(recordData); } public static void AddExistingArticleToJournal(String articleName, String journalName) { - if (!MainActivity.getInstance().journalDataSource.IsJournalAlreadyExist(journalName)) + if (!BashgidApplication.journalDataSource.IsJournalAlreadyExist(journalName)) { - MainActivity.getInstance().journalDataSource.CreateNewJournal(new JournalRecordData(journalName, journalName, "", 1, 0, 0)); + BashgidApplication.journalDataSource.CreateNewJournal(new JournalRecordData(journalName, journalName, "", 1, 0, 0)); } - MainActivity.getInstance().journalDataSource.AddArticleToJournal(articleName, journalName); + BashgidApplication.journalDataSource.AddArticleToJournal(articleName, journalName); } public static void AddNewArticleToJournal(ArticleRecordData recordData, String journalName) diff --git a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java index 41223c7..89eb1ad 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseDownloadTask.java @@ -25,6 +25,7 @@ import android.database.DatabaseUtils; import android.os.Bundle; import android.os.Message; import android.util.Log; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; @@ -148,7 +149,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask protected void onProgressUpdate(Integer... progress) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_UPDATE, progress[0]); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_DOWNLOADER_STATE_UPDATE, progress[0]); completeMessage.sendToTarget(); @@ -156,7 +157,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask protected void onPostExecute(Long result) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_FINISHED, 100); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_DOWNLOADER_STATE_FINISHED, 100); completeMessage.sendToTarget(); } @@ -249,9 +250,9 @@ public class DatabaseDownloadTask extends SimpleAsyncTask double geoLat = jObject.getDouble("geoLat"); double geoLon = jObject.getDouble("geoLon"); - MainActivity.getInstance().photoDataSource.AddOrReplacePhoto(new PhotoRecordData(title, description, imageUrl, imageHash, geoLat, geoLon)); + BashgidApplication.photoDataSource.AddOrReplacePhoto(new PhotoRecordData(title, description, imageUrl, imageHash, geoLat, geoLon)); - MainActivity.getInstance().DownloadImage(imageUrl, imageHash); + BashgidApplication.DownloadImage(imageUrl, imageHash); } // End Loop @@ -277,7 +278,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); int hidden = jObject.getInt("hidden"); - MainActivity.getInstance().albumDataSource.CreateNewAlbum(new AlbumRecordData(name, title, description, hidden)); + BashgidApplication.albumDataSource.CreateNewAlbum(new AlbumRecordData(name, title, description, hidden)); } // End Loop @@ -301,7 +302,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String imageUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("imageUrl")); String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); - MainActivity.getInstance().albumDataSource.AddPhotoToAlbum(imageUrl, name); + BashgidApplication.albumDataSource.AddPhotoToAlbum(imageUrl, name); } // End Loop @@ -330,10 +331,10 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String previewImageUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("previewImageUrl")); String previewImageHash = DatabaseDownloadTask.sqlEscapeString(jObject.getString("previewImageHash")); - MainActivity.getInstance().videoDataSource.AddOrReplaceVideo(new VideoRecordData(type, videoUrl, title, description, previewImageUrl, + BashgidApplication.videoDataSource.AddOrReplaceVideo(new VideoRecordData(type, videoUrl, title, description, previewImageUrl, previewImageHash)); - MainActivity.getInstance().DownloadImage(previewImageUrl, previewImageHash); + BashgidApplication.DownloadImage(previewImageUrl, previewImageHash); } // End Loop @@ -359,7 +360,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String description = DatabaseDownloadTask.sqlEscapeString(jObject.getString("description")); int hidden = jObject.getInt("hidden"); - MainActivity.getInstance().channelDataSource.CreateNewChannel(new ChannelRecordData(name, title, description, hidden)); + BashgidApplication.channelDataSource.CreateNewChannel(new ChannelRecordData(name, title, description, hidden)); } // End Loop @@ -383,7 +384,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String videoUrl = DatabaseDownloadTask.sqlEscapeString(jObject.getString("videoUrl")); String name = DatabaseDownloadTask.sqlEscapeString(jObject.getString("name")); - MainActivity.getInstance().channelDataSource.AddVideoToChannel(videoUrl, name); + BashgidApplication.channelDataSource.AddVideoToChannel(videoUrl, name); } // End Loop @@ -419,7 +420,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask Date dateTime = ArticleManager.iso8601Format.parse(jObject.getString("dateTime")); int hidden = jObject.getInt("hidden"); - MainActivity.getInstance().articleDataSource.CreateNewArticle(new ArticleRecordData(name, type, title, content, geoLat, geoLon, address, + BashgidApplication.articleDataSource.CreateNewArticle(new ArticleRecordData(name, type, title, content, geoLat, geoLon, address, phone, externalLink, externalLinkText, dateTime, hidden)); } catch (ParseException e) @@ -454,7 +455,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask int geoCategory = jObject.getInt("geoCategory"); int main = jObject.getInt("main"); - MainActivity.getInstance().journalDataSource.CreateNewJournal(new JournalRecordData(name, title, description, hidden, geoCategory, main)); + BashgidApplication.journalDataSource.CreateNewJournal(new JournalRecordData(name, title, description, hidden, geoCategory, main)); } // End Loop @@ -478,7 +479,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String albumName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("albumName")); String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); - MainActivity.getInstance().articleDataSource.AddAlbumToArticle(albumName, articleName); + BashgidApplication.articleDataSource.AddAlbumToArticle(albumName, articleName); } // End Loop @@ -502,7 +503,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String channelName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("channelName")); String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); - MainActivity.getInstance().articleDataSource.AddChannelToArticle(channelName, articleName); + BashgidApplication.articleDataSource.AddChannelToArticle(channelName, articleName); } // End Loop @@ -526,7 +527,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String articleName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("articleName")); String journalName = DatabaseDownloadTask.sqlEscapeString(jObject.getString("journalName")); - MainActivity.getInstance().journalDataSource.AddArticleToJournal(articleName, journalName); + BashgidApplication.journalDataSource.AddArticleToJournal(articleName, journalName); } // End Loop @@ -555,7 +556,7 @@ public class DatabaseDownloadTask extends SimpleAsyncTask String textRuUp = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textRuUp")); String textZhUp = DatabaseDownloadTask.sqlEscapeString(jObject.getString("textZhUp")); - MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(name, textEn, textRu, textZh, textEnUp, + BashgidApplication.translationDataSource.CreateNewTranslation(new TranslationRecordData(name, textEn, textRu, textZh, textEnUp, textRuUp, textZhUp)); } // End Loop diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java index b7898a8..1204951 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetAlbumTask.java @@ -3,6 +3,7 @@ package fishrungames.bashgid.core; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager.AlbumFullData; @@ -11,13 +12,13 @@ public class DatabaseGetAlbumTask extends AsyncTask AlbumFullData album = null; - public Handler mHandler; + //public Handler mHandler; protected Long doInBackground(String... queryArr) { String albumName = queryArr[0]; - album = MainActivity.getInstance().albumDataSource.GetAlbumFullData(albumName); + album = BashgidApplication.albumDataSource.GetAlbumFullData(albumName); return (long) 0; } @@ -32,7 +33,7 @@ public class DatabaseGetAlbumTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_STATE_FINISHED, album); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_ALBUM_STATE_FINISHED, album); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetArticleTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetArticleTask.java index e63d948..11c82ae 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetArticleTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetArticleTask.java @@ -3,6 +3,7 @@ package fishrungames.bashgid.core; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ArticleManager.ArticleFullData; @@ -11,20 +12,20 @@ public class DatabaseGetArticleTask extends AsyncTask ArticleFullData article; - public Handler mHandler; + //public Handler mHandler; protected Long doInBackground(String... queryArr) { String articleName = queryArr[0]; - article = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName); + article = BashgidApplication.articleDataSource.GetArticleFullData(articleName); return (long) 0; } protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_UPDATE, article); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_ARTICLE_STATE_UPDATE, article); completeMessage.sendToTarget(); @@ -32,7 +33,7 @@ public class DatabaseGetArticleTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_FINISHED, article); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_ARTICLE_STATE_FINISHED, article); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetGeoJournalListTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetGeoJournalListTask.java index 962dbc9..9cda635 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetGeoJournalListTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetGeoJournalListTask.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.JournalManager.JournalRecordData; @@ -14,13 +15,13 @@ public class DatabaseGetGeoJournalListTask extends AsyncTask geoJournalList; - public Handler mHandler; + //public Handler mHandler; protected Long doInBackground(String... queryArr) { - geoJournalList = MainActivity.getInstance().journalDataSource.GetGeoJournalList(); + geoJournalList = BashgidApplication.journalDataSource.GetGeoJournalList(); @@ -29,7 +30,7 @@ ArrayList geoJournalList; protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE, geoJournalList); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_GEO_JOURNAL_LIST_STATE_UPDATE, geoJournalList); completeMessage.sendToTarget(); @@ -37,7 +38,7 @@ ArrayList geoJournalList; protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED, geoJournalList); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_GEO_JOURNAL_LIST_STATE_FINISHED, geoJournalList); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java index 07fb4b4..17d2235 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetJournalListTask.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; @@ -18,11 +19,11 @@ public class DatabaseGetJournalListTask extends AsyncTask if (queryArr.length > 0) { - journalList = MainActivity.getInstance().journalDataSource.GetJournalListMain(7); //Xperimental -- need to pass exactly how many articles + journalList = BashgidApplication.journalDataSource.GetJournalListMain(12); //Xperimental -- need to pass exactly how many articles } else { - journalList = MainActivity.getInstance().journalDataSource.GetAllJournalListExceptHidden(7); //Xperimental -- need to pass exactly how many articles + journalList = BashgidApplication.journalDataSource.GetAllJournalListExceptHidden(12); //Xperimental -- need to pass exactly how many articles } @@ -40,7 +41,7 @@ public class DatabaseGetJournalListTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java b/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java index 89d8742..d6ddf1d 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseGetJournalTask.java @@ -4,6 +4,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; @@ -21,7 +22,7 @@ public class DatabaseGetJournalTask extends AsyncTask int count = queryArr[0].getInt("count", 0); - journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName, startAfterArticleName, count); + journal = BashgidApplication.journalDataSource.GetJournalSemiFullData(journalName, startAfterArticleName, count); return (long) 0; } @@ -36,7 +37,7 @@ public class DatabaseGetJournalTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_GET_JOURNAL_STATE_FINISHED, journal); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java b/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java index f1bceb6..dcc579b 100644 --- a/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java +++ b/android/src/fishrungames/bashgid/core/DatabaseSearchArticleTask.java @@ -11,13 +11,14 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ArticleManager.ArticleShortData; public class DatabaseSearchArticleTask extends AsyncTask { - public Handler mHandler; + //public Handler mHandler; ArrayList articleArr = new ArrayList(); @@ -34,26 +35,26 @@ public class DatabaseSearchArticleTask extends AsyncTask if (Locale.getDefault().equals(new Locale("ru"))) { - translationNamesArr = MainActivity.getInstance().translationDataSource.SearchRussian(query); + translationNamesArr = BashgidApplication.translationDataSource.SearchRussian(query); } else if (Locale.getDefault() == Locale.CHINA) { - translationNamesArr = MainActivity.getInstance().translationDataSource.SearchChinese(query); + translationNamesArr = BashgidApplication.translationDataSource.SearchChinese(query); } else { - translationNamesArr = MainActivity.getInstance().translationDataSource.SearchEnglish(query); + translationNamesArr = BashgidApplication.translationDataSource.SearchEnglish(query); } if (journalName != null && journalName.length() > 0) { for (String translationName : translationNamesArr) { - articleArr.addAll(MainActivity.getInstance().articleDataSource.SearchArticleByTitleOrTextInJournal(translationName, journalName)); + articleArr.addAll(BashgidApplication.articleDataSource.SearchArticleByTitleOrTextInJournal(translationName, journalName)); } } else { for (String translationName : translationNamesArr) { - articleArr.addAll(MainActivity.getInstance().articleDataSource.SearchArticleByTitleOrText(translationName)); + articleArr.addAll(BashgidApplication.articleDataSource.SearchArticleByTitleOrText(translationName)); } } @@ -80,7 +81,7 @@ public class DatabaseSearchArticleTask extends AsyncTask protected void onProgressUpdate(Integer... progress) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_SEARCH_ARTICLE_STATE_UPDATE, articleArr); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_SEARCH_ARTICLE_STATE_UPDATE, articleArr); completeMessage.sendToTarget(); @@ -88,7 +89,7 @@ public class DatabaseSearchArticleTask extends AsyncTask protected void onPostExecute(Long result) { - Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_SEARCH_ARTICLE_STATE_FINISHED, articleArr); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.DATABASE_SEARCH_ARTICLE_STATE_FINISHED, articleArr); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/NewsDownloadTask.java b/android/src/fishrungames/bashgid/core/NewsDownloadTask.java index 48f8402..dfffe76 100644 --- a/android/src/fishrungames/bashgid/core/NewsDownloadTask.java +++ b/android/src/fishrungames/bashgid/core/NewsDownloadTask.java @@ -4,6 +4,7 @@ package fishrungames.bashgid.core; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import fishrungames.networkutils.SimpleAsyncTask; @@ -26,7 +27,7 @@ public class NewsDownloadTask extends SimpleAsyncTask protected void onProgressUpdate(Integer... progress) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_UPDATE, progress[0]); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.NEWS_DOWNLOADER_STATE_UPDATE, progress[0]); completeMessage.sendToTarget(); @@ -34,7 +35,7 @@ public class NewsDownloadTask extends SimpleAsyncTask protected void onPostExecute(Long result) { - Message completeMessage = MainActivity.getInstance().mainHandler.obtainMessage(MainActivity.NEWS_DOWNLOADER_STATE_FINISHED, 100); + Message completeMessage = BashgidApplication.mainHandler.obtainMessage(BashgidApplication.NEWS_DOWNLOADER_STATE_FINISHED, 100); completeMessage.sendToTarget(); } diff --git a/android/src/fishrungames/bashgid/core/NewsManager.java b/android/src/fishrungames/bashgid/core/NewsManager.java index a9cf50a..6b34ca3 100644 --- a/android/src/fishrungames/bashgid/core/NewsManager.java +++ b/android/src/fishrungames/bashgid/core/NewsManager.java @@ -12,6 +12,7 @@ import android.os.Bundle; import fishrungames.networkutils.DownloadFunctions; import fishrungames.networkutils.SimpleAsyncTask; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.R; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; @@ -163,7 +164,7 @@ public class NewsManager AlbumManager.AddNewArticleToJournal(newsArticle, "news"); // To perform search - MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(title, title, // En + BashgidApplication.translationDataSource.CreateNewTranslation(new TranslationRecordData(title, title, // En title, // Ru title, // Zh titleUp, // En Up @@ -171,7 +172,7 @@ public class NewsManager titleUp // Zh Up )); - MainActivity.getInstance().translationDataSource.CreateNewTranslation(new TranslationRecordData(description, description, // En + BashgidApplication.translationDataSource.CreateNewTranslation(new TranslationRecordData(description, description, // En description, // Ru description, // Zh descriptionUp, // En Up diff --git a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java index 70d3d2d..4bd62fc 100644 --- a/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/AlbumDataSource.java @@ -2,6 +2,7 @@ package fishrungames.bashgid.core.db; import java.util.ArrayList; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager; import fishrungames.bashgid.core.DatabaseDownloadTask; @@ -145,11 +146,11 @@ public class AlbumDataSource for (String imageUrl : imageUrlArr) { - result.photoRecordArr.add(MainActivity.getInstance().photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database)); + result.photoRecordArr.add(BashgidApplication.photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database)); } - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } @@ -183,8 +184,8 @@ public class AlbumDataSource result.firstImageUrl = imageUrlArr.get(0); } - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } @@ -233,8 +234,8 @@ public class AlbumDataSource shortData.firstImageUrl = "R.drawable.no_picture"; } - shortData.title = MainActivity.getInstance().translationDataSource.TryTranslateText(shortData.title, database); - shortData.description = MainActivity.getInstance().translationDataSource.TryTranslateText(shortData.description, database); + shortData.title = BashgidApplication.translationDataSource.TryTranslateText(shortData.title, database); + shortData.description = BashgidApplication.translationDataSource.TryTranslateText(shortData.description, database); result.add(shortData); } while (cursor.moveToNext()); diff --git a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java index d7a5608..c35464f 100644 --- a/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ArticleDataSource.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.Date; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.AlbumManager.AlbumFullData; @@ -192,21 +193,21 @@ public class ArticleDataSource for (String albumName : albumNameArr) { - result.albumArr.add(MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumName, database)); + result.albumArr.add(BashgidApplication.albumDataSource.InnerGetAlbumFullData(albumName, database)); } ArrayList channelNameArr = innerGetChannelNameArrInArticle(name, database); for (String channelName : channelNameArr) { - result.channelArr.add(MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelName, database)); + result.channelArr.add(BashgidApplication.channelDataSource.InnerGetChannelFullData(channelName, database)); } - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); - result.address = MainActivity.getInstance().translationDataSource.TryTranslateText(result.address, database); - result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); - result.externalLinkText = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLinkText, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.content = BashgidApplication.translationDataSource.TryTranslateText(result.content, database); + result.address = BashgidApplication.translationDataSource.TryTranslateText(result.address, database); + result.externalLink = BashgidApplication.translationDataSource.TryTranslateText(result.externalLink, database); + result.externalLinkText = BashgidApplication.translationDataSource.TryTranslateText(result.externalLinkText, database); if (result.type == ArticleManager.ARTICLE_TYPE_NEWS) { @@ -281,7 +282,7 @@ public class ArticleDataSource for (String articleName : articleNameArr) { - if (MainActivity.getInstance().journalDataSource.InnerArticleJournalRelationAlreadyExist(articleName, journalName, database)) + if (BashgidApplication.journalDataSource.InnerArticleJournalRelationAlreadyExist(articleName, journalName, database)) { result.add(InnerGetArticleShortData(articleName, database)); } @@ -332,7 +333,7 @@ public class ArticleDataSource for (ArticleShortData article : intermediateResult) { - if (MainActivity.getInstance().journalDataSource.InnerArticleJournalRelationAlreadyExist(article.name, journalName, database)) + if (BashgidApplication.journalDataSource.InnerArticleJournalRelationAlreadyExist(article.name, journalName, database)) { result.add(article); } @@ -399,10 +400,10 @@ public class ArticleDataSource result.previewImageUrl = getPreviewImageUrlForArticle(name, database); - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.content = MainActivity.getInstance().translationDataSource.TryTranslateText(result.content, database); - result.externalLink = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLink, database); - result.externalLinkText = MainActivity.getInstance().translationDataSource.TryTranslateText(result.externalLinkText, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.content = BashgidApplication.translationDataSource.TryTranslateText(result.content, database); + result.externalLink = BashgidApplication.translationDataSource.TryTranslateText(result.externalLink, database); + result.externalLinkText = BashgidApplication.translationDataSource.TryTranslateText(result.externalLinkText, database); if (result.type == ArticleManager.ARTICLE_TYPE_NEWS) { @@ -422,7 +423,7 @@ public class ArticleDataSource if (albumNameArr.size() > 0) { - AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database); + AlbumFullData album = BashgidApplication.albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database); if (album.photoRecordArr.size() > 0) { @@ -437,7 +438,7 @@ public class ArticleDataSource if (channelNameArr.size() > 0) { - ChannelFullData channelFullData = MainActivity.getInstance().channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database); + ChannelFullData channelFullData = BashgidApplication.channelDataSource.InnerGetChannelFullData(channelNameArr.get(0), database); if (channelFullData.videoRecordArr.size() > 0) { diff --git a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java index fc4d9e2..4574c70 100644 --- a/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/ChannelDataSource.java @@ -2,6 +2,7 @@ package fishrungames.bashgid.core.db; import java.util.ArrayList; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ChannelManager; @@ -145,11 +146,11 @@ public class ChannelDataSource for (String videoUrl : videoUrlArr) { - result.videoRecordArr.add(MainActivity.getInstance().videoDataSource.InnerGetVideoByVideoUrl(videoUrl, database)); + result.videoRecordArr.add(BashgidApplication.videoDataSource.InnerGetVideoByVideoUrl(videoUrl, database)); } - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } diff --git a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java index cfb35bf..f0b1747 100644 --- a/android/src/fishrungames/bashgid/core/db/JournalDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/JournalDataSource.java @@ -3,6 +3,7 @@ package fishrungames.bashgid.core.db; import java.util.ArrayList; import java.util.Collections; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.ArticleManager; @@ -185,14 +186,14 @@ public class JournalDataSource } for (String article : articleArr) { - if (!MainActivity.getInstance().articleDataSource.InnerArticleIsHidden(article, database)) + if (!BashgidApplication.articleDataSource.InnerArticleIsHidden(article, database)) { - journal.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database)); + journal.articleArr.add(BashgidApplication.articleDataSource.InnerGetArticleShortData(article, database)); } } - journal.title = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.title, database); - journal.description = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.description, database); + journal.title = BashgidApplication.translationDataSource.TryTranslateText(journal.title, database); + journal.description = BashgidApplication.translationDataSource.TryTranslateText(journal.description, database); result.add(journal); @@ -253,14 +254,14 @@ public class JournalDataSource for (String article : articleArr) { - if (!MainActivity.getInstance().articleDataSource.InnerArticleIsHidden(article, database)) + if (!BashgidApplication.articleDataSource.InnerArticleIsHidden(article, database)) { - journal.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database)); + journal.articleArr.add(BashgidApplication.articleDataSource.InnerGetArticleShortData(article, database)); } } - journal.title = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.title, database); - journal.description = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.description, database); + journal.title = BashgidApplication.translationDataSource.TryTranslateText(journal.title, database); + journal.description = BashgidApplication.translationDataSource.TryTranslateText(journal.description, database); result.add(journal); @@ -306,7 +307,7 @@ public class JournalDataSource JournalRecordData journal = new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3), cursor.getInt(4), cursor.getInt(5)); - journal.title = MainActivity.getInstance().translationDataSource.TryTranslateText(journal.title, database); + journal.title = BashgidApplication.translationDataSource.TryTranslateText(journal.title, database); // journal.description = // MainActivity.getInstance().translationDataSource.TryTranslateText(journal.description, @@ -349,7 +350,7 @@ public class JournalDataSource for (String article : articleArr) { - intermediateArticleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database)); + intermediateArticleArr.add(BashgidApplication.articleDataSource.InnerGetArticleShortData(article, database)); } @@ -383,8 +384,8 @@ public class JournalDataSource } } - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } diff --git a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java index b891924..b563bf2 100644 --- a/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/PhotoDataSource.java @@ -1,5 +1,6 @@ package fishrungames.bashgid.core.db; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; @@ -97,8 +98,8 @@ public class PhotoDataSource result = new PhotoRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getDouble(4), cursor.getDouble(5)); - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } cursor.close(); diff --git a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java index 3f525a6..1ebfb95 100644 --- a/android/src/fishrungames/bashgid/core/db/VideoDataSource.java +++ b/android/src/fishrungames/bashgid/core/db/VideoDataSource.java @@ -1,5 +1,6 @@ package fishrungames.bashgid.core.db; +import fishrungames.bashgid.BashgidApplication; import fishrungames.bashgid.MainActivity; import fishrungames.bashgid.core.DatabaseDownloadTask; import fishrungames.bashgid.core.VideoManager.VideoRecordData; @@ -96,8 +97,8 @@ public class VideoDataSource result = new VideoRecordData(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5)); - result.title = MainActivity.getInstance().translationDataSource.TryTranslateText(result.title, database); - result.description = MainActivity.getInstance().translationDataSource.TryTranslateText(result.description, database); + result.title = BashgidApplication.translationDataSource.TryTranslateText(result.title, database); + result.description = BashgidApplication.translationDataSource.TryTranslateText(result.description, database); } cursor.close();