Many changes + minor bug fixing

This commit is contained in:
Vladislav Khorev 2015-06-25 19:00:11 +00:00
parent 1fb07ff884
commit c5e5df9e52
54 changed files with 2483 additions and 488 deletions

View File

@ -9,6 +9,20 @@
android:paddingTop="4dp"
android:showDividers="middle" >
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/contentTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<it.sephiroth.android.library.widget.HListView
android:id="@+id/hListView"
android:layout_width="match_parent"

View File

@ -13,10 +13,4 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/dateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>

View File

@ -11,12 +11,16 @@
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/dateTextView"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
android:gravity="center_horizontal"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>

View File

@ -7,6 +7,9 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
@ -19,4 +22,12 @@
</ListView>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
</LinearLayout>

View File

@ -0,0 +1,30 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:background="@color/bkg2"
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:divider="@drawable/transparent"
android:dividerHeight="18dp"
android:paddingBottom="16dp" >
</ListView>
</LinearLayout>

View File

@ -7,6 +7,7 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
@ -16,7 +17,10 @@
android:divider="@color/bkg2"
android:dividerHeight="2dp"
android:paddingBottom="16dp" >
</ListView>
</LinearLayout>

View File

@ -9,6 +9,17 @@
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="fishrungames.bashgid.MapHolderFragment" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="6dp"
android:gravity="center_horizontal"
android:text="TextView"
android:textSize="24dp"
android:textStyle="bold" />
<org.osmdroid.views.MapView
android:id="@+id/mapview"

View File

@ -7,6 +7,7 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"

View File

@ -7,6 +7,14 @@
android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
@ -14,7 +22,7 @@
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:divider="@color/bkg2"
android:dividerHeight="2dp"
android:dividerHeight="12dp"
android:paddingBottom="16dp" >
</ListView>

View File

@ -4,6 +4,14 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"

View File

@ -3,12 +3,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3" >
android:gravity="bottom"
android:horizontalSpacing="12dp"
android:numColumns="4"
android:verticalSpacing="12dp" >
</GridView>
</LinearLayout>

View File

@ -5,6 +5,14 @@
android:layout_margin="6dp"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"

View File

@ -11,6 +11,7 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
@ -31,6 +32,9 @@
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp" />
android:layout_height="80dp"
android:layout_gravity="right"
android:layout_weight="0"
android:scaleType="centerInside" />
</LinearLayout>

View File

@ -36,6 +36,12 @@
</LinearLayout>
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<it.sephiroth.android.library.widget.HListView
android:id="@+id/hListView"
android:layout_width="match_parent"

View File

@ -18,6 +18,14 @@
android:textSize="24sp"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -27,10 +35,13 @@
<ImageButton
android:id="@+id/news1ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|left"
android:adjustViewBounds="true"
android:background="@drawable/transparent"
android:contentDescription="@string/news_content_description" />
android:contentDescription="@string/news_content_description"
android:maxWidth="40dp"
android:scaleType="centerInside" />
<Button
android:id="@+id/news1Button"
@ -55,10 +66,13 @@
<ImageButton
android:id="@+id/news2ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:background="@drawable/transparent"
android:contentDescription="@string/news_content_description" />
android:contentDescription="@string/news_content_description"
android:maxWidth="40dp"
android:scaleType="centerInside" />
<Button
android:id="@+id/news2Button"
@ -83,10 +97,13 @@
<ImageButton
android:id="@+id/news3ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:background="@drawable/transparent"
android:contentDescription="@string/news_content_description" />
android:contentDescription="@string/news_content_description"
android:maxWidth="40dp"
android:scaleType="centerInside" />
<Button
android:id="@+id/news3Button"

View File

@ -0,0 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bkg1"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
tools:context="fishrungames.bashgid.MainPageFragment" >
<TextView
android:id="@+id/footerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="@string/news_load_more"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>

View File

@ -18,4 +18,12 @@
android:textSize="24sp"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:indeterminate="true" />
</LinearLayout>

View File

@ -8,11 +8,12 @@
android:orientation="horizontal"
android:showDividers="middle" >
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<fishrungames.bashgid.DynamicImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
</LinearLayout>

View File

@ -15,7 +15,7 @@
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:contentDescription="@string/related_image"
android:scaleType="fitXY" />
android:scaleType="fitCenter" />
<TextView
android:id="@+id/dateTextView"

View File

@ -5,10 +5,41 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<fishrungames.bashgid.DynamicImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -2,28 +2,30 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="800dp"
android:layout_height="150dp"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:background="@color/bkg1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:showDividers="middle" >
<ImageView
<fishrungames.bashgid.DynamicImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="2dp"
android:scaleType="fitCenter"
android:src="@drawable/img_culture1" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_gravity="bottom"
android:text="dsdsd"
android:textSize="16sp"
android:textStyle="bold" />

View File

@ -26,6 +26,8 @@
<string name="news_header">News</string>
<string name="news_load_more">Load more</string>
<string name="news_content_description">Image related to news record</string>

View File

@ -10,7 +10,10 @@ import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -20,6 +23,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -32,15 +36,28 @@ public class AlbumListFragment extends Fragment
GridView gridView;
ArrayList<AlbumShortData> albumArr;
ProgressBar progressBar;
public AlbumListFragment()
{
RestoreAlbumList();
}
public AlbumListFragment(ArrayList<AlbumShortData> albumArr)
{
this.albumArr = albumArr;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
albumArr = MainActivity.getInstance().albumDataSource.GetAllAlbumShortData();
View rootView = inflater.inflate(R.layout.fragment_video_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
gridView = (GridView) rootView.findViewById(R.id.gridView);
@ -61,6 +78,58 @@ public class AlbumListFragment extends Fragment
return rootView;
}
public void RestoreAlbumList()
{
albumArr = new ArrayList<AlbumShortData>();
DatabaseGetAlbumListTask task = new DatabaseGetAlbumListTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute();
}
public void SetAlbumList(ArrayList<AlbumShortData> albumArr)
{
progressBar.setVisibility(View.GONE);
this.albumArr = albumArr;
listAdapter.notifyDataSetChanged();
}
public static class DatabaseGetAlbumListTask extends AsyncTask<String, Integer, Long>
{
ArrayList<AlbumShortData> albumArr;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
albumArr = MainActivity.getInstance().albumDataSource.GetAllAlbumShortData();
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_UPDATE, albumArr);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_LIST_STATE_FINISHED, albumArr);
completeMessage.sendToTarget();
}
}

View File

@ -14,17 +14,24 @@ import org.osmdroid.views.MapView;
import fishrungames.bashgid.OsmMapHolderFragment.CustomItemizedOverlay;
import fishrungames.bashgid.OsmMapHolderFragment.NoInteractionOverlay;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.LocationHolder;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -35,6 +42,7 @@ import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -86,6 +94,9 @@ public class ArticleFragment extends Fragment
ListView listView;
ListAdapter listAdapter;
ProgressBar progressBar;
String articleName;
ArticleFullData article;
ArrayList<ArticleLayoutElement> articleLayout = new ArrayList<ArticleLayoutElement>();
@ -100,6 +111,14 @@ public class ArticleFragment extends Fragment
{
this.articleName = articleName;
RestoreArticle();
ReloadLayout();
}
public ArticleFragment(ArticleFullData article)
{
this.articleName = article.name;
this.article = article;
ReloadLayout();
}
@Override
@ -110,10 +129,21 @@ public class ArticleFragment extends Fragment
public void RestoreArticle()
{
article = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
DatabaseGetArticleTask task = new DatabaseGetArticleTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(articleName);
}
public void ReloadLayout()
{
articleLayout.clear();
if (article != null)
{
articleLayout.add(new ArticleLayoutElement(0, article.title));
PhotoRecordData zeroPhoto = null;
@ -151,19 +181,37 @@ public class ArticleFragment extends Fragment
articleLayout.add(new ArticleLayoutElement(5, article.externalLink));
}
}
}
public void SetArticle(ArticleFullData article)
{
progressBar.setVisibility(View.GONE);
this.article = article;
ReloadLayout();
listAdapter.notifyDataSetChanged();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
articleName = savedInstanceState.getString("articleName");
RestoreArticle();
ReloadLayout();
}
View rootView = inflater.inflate(R.layout.fragment_article_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
listView = (ListView) rootView.findViewById(R.id.listView);
listAdapter = new ListAdapter(getActivity());
@ -173,6 +221,38 @@ public class ArticleFragment extends Fragment
return rootView;
}
public class DatabaseGetArticleTask extends AsyncTask<String, Integer, Long>
{
ArticleFullData article;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String articleName = queryArr[0];
article = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_UPDATE, article);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ARTICLE_STATE_FINISHED, article);
completeMessage.sendToTarget();
}
}
public class ListAdapter extends BaseAdapter {
private Context mContext;
@ -248,6 +328,10 @@ public class ArticleFragment extends Fragment
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
textView.setText(articleLayout.get(position).value);
textView.setTextSize(24);
textView.setTypeface(null, Typeface.BOLD);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
}
else if (getItemViewType(position) == 1)
@ -255,6 +339,10 @@ public class ArticleFragment extends Fragment
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
textView.setText(articleLayout.get(position).value);
textView.setTextSize(12);
textView.setTypeface(null, Typeface.NORMAL);
textView.setGravity(Gravity.LEFT);
}
else if (getItemViewType(position) == 2)
@ -301,6 +389,15 @@ public class ArticleFragment extends Fragment
}
else if (getItemViewType(position) == 4)
{
TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
titleTextView.setText(article.albumArr.get(articleLayout.get(position).albumPos).title);
TextView contentTextView = (TextView) view.findViewById(R.id.contentTextView);
contentTextView.setText(article.albumArr.get(articleLayout.get(position).albumPos).description);
HListView hListView = (HListView) view.findViewById(R.id.hListView);
hListView.setAdapter(new MainPageHListViewAdapters.PhotoAlbumElementAdapter(getActivity(), article.albumArr.get(articleLayout.get(position).albumPos)));
@ -318,21 +415,7 @@ public class ArticleFragment extends Fragment
}
});
/*
*
hListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
MainActivity.getInstance().SetLastAlbumName(albumName);
MainActivity.getInstance().OpenPhotoScreen(albumName, position, MainActivity.TAG_FROM_PHOTOLISTFRAGMENT_TO_PHOTOFRAGMENT);
}
});*/
}
else if (getItemViewType(position) == 5)
{

View File

@ -0,0 +1,184 @@
package fishrungames.bashgid;
import java.util.ArrayList;
import it.sephiroth.android.library.widget.HListView;
import fishrungames.bashgid.AlbumListFragment.DatabaseGetAlbumListTask;
import fishrungames.bashgid.MainPageFragment.ListAdapter;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class CatalogFragment extends Fragment
{
ListView listView;
ListAdapter listAdapter;
ProgressBar progressBar;
ArrayList<JournalSemiFullData> journalList;
public CatalogFragment()
{
RestoreJournalList();
}
public CatalogFragment(ArrayList<JournalSemiFullData> journalList)
{
this.journalList = journalList;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_catalog_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
listView = (ListView) rootView.findViewById(R.id.listView);
listAdapter = new ListAdapter(getActivity());
listView.setAdapter(listAdapter);
return rootView;
}
public void RestoreJournalList()
{
journalList = new ArrayList<JournalSemiFullData>();
DatabaseGetJournalListTask task = new DatabaseGetJournalListTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute();
}
public void SetJournalList(ArrayList<JournalSemiFullData> journalList)
{
progressBar.setVisibility(View.GONE);
this.journalList = journalList;
listAdapter.notifyDataSetChanged();
}
public static class DatabaseGetJournalListTask extends AsyncTask<String, Integer, Long>
{
ArrayList<JournalSemiFullData> journalList;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
journalList = MainActivity.getInstance().journalDataSource.GetAllJournalList();
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_UPDATE, journalList);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_LIST_STATE_FINISHED, journalList);
completeMessage.sendToTarget();
}
}
public class ListAdapter extends BaseAdapter {
private Context mContext;
public ListAdapter(Context c) {
mContext = c;
}
public int getCount() {
return journalList.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
@SuppressLint("InflateParams")
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.main_page_list_element, null);
} else {
view = convertView;
}
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
TextView descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
Button button = (Button) view.findViewById(R.id.button);
HListView hListView = (HListView) view.findViewById(R.id.hListView);
hListView.setAdapter(new MainPageHListViewAdapters.JournalElementAdapter(getActivity(), journalList.get(position)));
textView.setText(journalList.get(position).title);
descriptionTextView.setText(journalList.get(position).description);
button.setText(R.string.see_all);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
MainActivity.getInstance().OpenJournalScreen(journalList.get(position).name, MainActivity.TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT);
}
});
return view;
}
}
}

View File

@ -0,0 +1,27 @@
package fishrungames.bashgid;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class DynamicImageView extends ImageView {
public DynamicImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final Drawable d = this.getDrawable();
if (d != null) {
// ceil not round - avoid thin vertical gaps along the left/right edges
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int height = (int) Math.ceil(width * (float) d.getIntrinsicHeight() / d.getIntrinsicWidth());
this.setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}

View File

@ -3,7 +3,10 @@ package fishrungames.bashgid;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -15,10 +18,14 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.networkutils.ImageManager;
@ -29,6 +36,7 @@ public class JournalFragment extends Fragment
String journalName;
ListAdapter listAdapter;
ProgressBar progressBar;
public JournalFragment()
{
@ -42,6 +50,12 @@ public class JournalFragment extends Fragment
RestoreJournal();
}
public JournalFragment(JournalSemiFullData journal)
{
this.journalName = journal.name;
this.journal = journal;
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
@ -58,6 +72,11 @@ public class JournalFragment extends Fragment
}
View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
listAdapter = new ListAdapter(getActivity());
@ -70,7 +89,14 @@ public class JournalFragment extends Fragment
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
if (journalName.equals("news"))
{
MainActivity.getInstance().OpenNewsRecordScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
}
else
{
MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
}
}
});
@ -78,11 +104,35 @@ public class JournalFragment extends Fragment
return rootView;
}
void RestoreJournal()
{
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName);
journal = JournalManager.CreateEmptyJournal();
DatabaseGetJournalTask task = new DatabaseGetJournalTask();
task.mHandler = MainActivity.getInstance().mHandler;
Bundle bundle = new Bundle();
bundle.putString("journalName", journalName);
task.execute(bundle);
}
public void SetJournal(JournalSemiFullData journal)
{
progressBar.setVisibility(View.GONE);
this.journal = journal;
listAdapter.notifyDataSetChanged();
}
public class ListAdapter extends BaseAdapter {
private Context mContext;
@ -124,13 +174,16 @@ public class JournalFragment extends Fragment
TextView dateTextView = (TextView)view.findViewById(R.id.dateTextView);
dateTextView.setText(journal.articleArr.get(position).dateTime.toString());
if (journal.previewImageArr.get(position) != null)
{
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
ImageManager.getInstance().ApplyImageToImageView(imageView, journal.previewImageArr.get(position));
if (journal.articleArr.get(position).previewImageUrl != null)
{
ImageManager.getInstance().ApplyImageToImageView(imageView, journal.articleArr.get(position).previewImageUrl);
}
else
{
imageView.setImageResource(R.drawable.transparent);
}
return view;
}

View File

@ -8,13 +8,18 @@ import java.util.Locale;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.ArticleManager;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.BookManager.BookRecord;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.bashgid.core.DatabaseDownloadTask;
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsDownloadTask;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
@ -42,7 +47,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -61,7 +65,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public static final String TAG_FROM_PHOTOLISTFRAGMENT_TO_PHOTOFRAGMENT = "TAG_FROM_PHOTOLISTFRAGMENT_TO_PHOTOFRAGMENT";
public static final String TAG_FROM_ARTICLEFRAGMENT_TO_PHOTOFRAGMENT = "TAG_FROM_ARTICLEFRAGMENT_TO_PHOTOFRAGMENT";
public static final String TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT = "TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT";
public static final String TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT = "TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT";
public static final String TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT = "TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT";
public static final String TAG_TO_WELCOMEFRAGMENT = "WelcomeFragment";
@ -74,9 +84,49 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
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;
MainPageFragment mainPageFragment = null;
NewsListFragment newsListFragment = null;
NewsRecordFragment newsRecordFragment = null;
AlbumListFragment albumListFragment = null;
PhotoAlbumFragment photoAlbumFragment = null;
PhotoFragment photoFragment = null;
ArticleFragment articleFragment = null;
JournalFragment journalFragment = null;
VideoListFragment videoListFragment = null;
VideoRecordFragment videoRecordFragment = null;
OsmMapHolderFragment mapHolderFragment = null;
CatalogFragment catalogFragment = null;
static MainActivity instance = null;
@ -101,6 +151,8 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{
super.onCreate(savedInstanceState);
ImageManager.getInstance().PredefinedImageId.put("R.drawable.no_picture", R.drawable.no_picture);
setContentView(R.layout.activity_main);
SetupDrawer();
@ -144,6 +196,48 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
case NEWS_DOWNLOADER_STATE_FINISHED:
UpdateOnNewsDownloaded();
break;
case DATABASE_DOWNLOADER_STATE_UPDATE:
case DATABASE_DOWNLOADER_STATE_FINISHED:
UpdateOnDatabaseDownloaded();
break;
case DATABASE_GET_ALBUM_STATE_UPDATE:
case DATABASE_GET_ALBUM_STATE_FINISHED:
UpdateOnAlbumLoaded((AlbumFullData)inputMessage.obj);
break;
case DATABASE_GET_ALBUM_LIST_STATE_UPDATE:
case DATABASE_GET_ALBUM_LIST_STATE_FINISHED:
ArrayList<AlbumShortData> albumShortList = (ArrayList<AlbumShortData>) inputMessage.obj;
UpdateOnAlbumListLoaded(albumShortList);
break;
case DATABASE_GET_ARTICLE_STATE_UPDATE:
case DATABASE_GET_ARTICLE_STATE_FINISHED:
UpdateOnArticleLoaded((ArticleFullData)inputMessage.obj);
break;
case DATABASE_GET_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<JournalSemiFullData>) inputMessage.obj);
break;
default:
super.handleMessage(inputMessage);
}
@ -152,26 +246,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
};
/*
photoDataSource.AddOrReplacePhoto(new PhotoRecordData(
"Vlad",
"Vlad's photo",
"http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg",
"",
0,
0
));
photoDataSource.AddOrReplacePhoto(new PhotoRecordData(
"Lilia",
"Lilia photo",
"http://http://pp.vk.me/c622725/v622725384/3290f/hfnoyPHe5y8.jpg",
"",
0,
0
));
*/
albumDataSource.CreateNewAlbum(new AlbumRecordData("TEST", "Vk Photos", "Wow"));
@ -195,9 +270,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
"",
0,
0), "TEST");
AlbumManager.DownloadAndAddPhotoToAlbum(new PhotoRecordData(
"Vlad",
"Vlad 2",
"Vlad's photo",
"http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg",
"",
@ -205,13 +281,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
0
), "TEST");
PhotoRecordData photo = photoDataSource.GetPhotoByImageUrl("http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg");
if (photo != null)
{
Log.e("aaa", "xxx");
}
articleDataSource.CreateNewArticle(new ArticleRecordData(
"TESTART",
0,
@ -225,9 +294,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
articleDataSource.AddAlbumToArticle("TEST", "TESTART");
AlbumManager.AddExistingArticleToJournal("TESTART", "news");
//AlbumManager.AddExistingArticleToJournal("TESTART", "news");
AlbumManager.AddExistingArticleToJournal("TESTART", "map");
AlbumManager.AddExistingArticleToJournal("TESTART", "investor");
AlbumManager.AddNewVideoToChannel(new VideoRecordData(
VideoManager.VIDEO_TYPE_YOUTUBE,
"http://www.youtube.com/watch?v=dQw4w9WgXcQ",
@ -245,17 +318,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
0,
"http://fishrungames.ru",
articleTestDate2
), "news");
), "investor");
//articleDataSource.AddAlbumToArticle("TEST", "testArticle2");
//articleDataSource.AddChannelToArticle("main", "testArticle2");
ArrayList<ArticleShortData> fullData = journalDataSource.GetRecentArticles("news", 2);
for (ArticleShortData d : fullData)
{
Log.e("sss", d.title);
}
DownloadDatabase();
}
@ -304,11 +372,34 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
this.DownloadImageArr(new String []{imageUrl}, new String []{imageHash});
}
public void DownloadDatabase()
{
DatabaseDownloadTask task = new DatabaseDownloadTask();
task.mHandler = mHandler;
task.execute();
}
public void ClearAllFragmentLinks()
{
mainPageFragment = null;
newsListFragment = null;
newsRecordFragment = null;
albumListFragment = null;
photoAlbumFragment = null;
photoFragment = null;
articleFragment = null;
journalFragment = null;
videoListFragment = null;
videoRecordFragment = null;
mapHolderFragment = null;
catalogFragment = null;
}
public void StartDownloadImagesTask(ArrayList<String> imageUrlArr, ArrayList<String> imageHashArr)
@ -337,12 +428,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{
if (mainPageFragment != null)
{
mainPageFragment.RefreshHeader();
mainPageFragment.RefreshJournal();
}
if (newsListFragment != null)
{
newsListFragment.RefreshNewsList();
newsListFragment.RefreshJournal();
}
}
@ -350,14 +441,114 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{
if (mainPageFragment != null)
{
mainPageFragment.RefreshHeader();
mainPageFragment.RefreshJournal();
}
if (newsListFragment != null)
{
newsListFragment.RefreshNewsList();
newsListFragment.RefreshJournal();
}
}
public void UpdateOnDatabaseDownloaded()
{
}
public void UpdateOnAlbumLoaded(AlbumFullData album)
{
if (photoFragment != null)
{
photoFragment.SetAlbum(album);
}
if (photoAlbumFragment != null)
{
photoAlbumFragment.SetAlbum(album);
}
}
public void UpdateOnArticleLoaded(ArticleFullData article)
{
if (articleFragment != null)
{
articleFragment.SetArticle(article);
}
if (newsRecordFragment != null)
{
newsRecordFragment.SetArticle(article);
}
}
public void UpdateOnAlbumListLoaded(ArrayList<AlbumShortData> albumList)
{
if (albumListFragment != null)
{
albumListFragment.SetAlbumList(albumList);
}
}
public void UpdateOnJournalLoaded(JournalSemiFullData journal)
{
if (journalFragment != null)
{
journalFragment.SetJournal(journal);
}
if (newsListFragment != null)
{
newsListFragment.SetJournal(journal);
}
if (mainPageFragment != null)
{
mainPageFragment.SetJournal(journal);
}
if (mapHolderFragment != null)
{
mapHolderFragment.SetJournal(journal);
}
}
public void UpdateOnChannelLoaded(ChannelFullData channel)
{
if (videoListFragment != null)
{
videoListFragment.SetChannel(channel);
}
}
public void UpdateOnVideoLoaded(VideoRecordData video)
{
if (videoRecordFragment != null)
{
videoRecordFragment.SetVideo(video);
}
}
public void UpdateOnJournalListLoaded(ArrayList<JournalSemiFullData> journalList)
{
if (catalogFragment != null)
{
catalogFragment.SetJournalList(journalList);
}
}
public void OnSelectEnglish(View view)
{
@ -416,7 +607,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer();
StartDownloadNewsTask();
}
public void OpenNewsScreen()
@ -432,14 +622,27 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
}
public void OpenJournalScreen(String journalName)
public void OpenCatalogScreen()
{
ClearAllFragmentLinks();
catalogFragment = new CatalogFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, catalogFragment).commit();
mNavigationDrawerFragment.EnableDrawer();
}
public void OpenJournalScreen(String journalName, String tag)
{
ClearAllFragmentLinks();
JournalFragment journal = new JournalFragment(journalName);
journalFragment = new JournalFragment(journalName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, journal).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, journalFragment, tag).commit();
mNavigationDrawerFragment.EnableDrawer();
}
@ -482,13 +685,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer();
}
public void OpenMapScreen()
public void OpenMapScreen(String filter)
{
ClearAllFragmentLinks();
// getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
// new MapHolderFragment(), TAG_TO_MAINFRAGMENT).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OsmMapHolderFragment("news"), TAG_TO_MAINFRAGMENT).commit();
mapHolderFragment = new OsmMapHolderFragment(filter);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
@ -505,8 +707,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public void OpenPhotoAlbumListScreen()
{
ClearAllFragmentLinks();
albumListFragment = new AlbumListFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AlbumListFragment(), TAG_TO_MAINFRAGMENT).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, albumListFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
@ -514,8 +718,10 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public void OpenPhotoAlbumScreen(String albumName)
{
ClearAllFragmentLinks();
photoAlbumFragment = new PhotoAlbumFragment(albumName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PhotoAlbumFragment(albumName), TAG_TO_MAINFRAGMENT).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, photoAlbumFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
@ -524,8 +730,21 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public void OpenPhotoScreen(String albumName, int position, String tag)
{
ClearAllFragmentLinks();
photoFragment = new PhotoFragment(albumName, position);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PhotoFragment(albumName, position), tag).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, photoFragment, tag).commit();
mNavigationDrawerFragment.EnableDrawer();
}
public void OpenPhotoScreen(AlbumFullData album, int position, String tag)
{
ClearAllFragmentLinks();
photoFragment = new PhotoFragment(album, position);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, photoFragment, tag).commit();
mNavigationDrawerFragment.EnableDrawer();
}
@ -541,7 +760,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks();
NewsRecordFragment newsRecordFragment = new NewsRecordFragment(articleName);
newsRecordFragment = new NewsRecordFragment(articleName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsRecordFragment, tag).commit();
@ -553,7 +772,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks();
ArticleFragment articleFragment = new ArticleFragment(articleName);
articleFragment = new ArticleFragment(articleName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, articleFragment, tag).commit();
@ -598,20 +817,19 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer();
}
// TAG_FROM_VIDEOLISTFRAGMENT_TO_VIDEORECORDFRAGMENT
public void OpenVideoListScreen(String channelName)
{
ClearAllFragmentLinks();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new VideoListFragment(channelName), TAG_TO_MAINFRAGMENT).commit();
videoListFragment = new VideoListFragment(channelName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, videoListFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer();
}
public void OpenVideoRecordScreen(String videoUrl, String tag)
public void OpenVideoRecordScreen(VideoRecordData video, String tag)
{
// Xperimental -- addToBackStack provoke error "Class not found". Need
// to resolve somehow!
@ -622,7 +840,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks();
VideoRecordFragment videoRecordFragment = new VideoRecordFragment(videoUrl);
videoRecordFragment = new VideoRecordFragment(video);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, videoRecordFragment, tag).commit();
@ -633,7 +851,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{
if (mainPageFragment != null)
{
mainPageFragment.RefreshHeader();
mainPageFragment.RefreshJournal();
}
}
@ -700,21 +918,30 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
} else if (position == 2)
{
OpenNewsScreen();
}
else if (position == 3)
{
OpenCatalogScreen();
} else if (position == 4)
{
OpenMapScreen();
OpenMapScreen("map");
} else if (position == 5)
{
OpenVideoListScreen("main");
} else if (position == 6)
{
OpenPhotoAlbumListScreen();
//OpenPhotoAlbumScreen(albumDataSource.GetAlbumFullData("TEST"));
} else if (position == 7)
OpenPhotoAlbumListScreen();
}
else if (position == 7)
{
OpenBooksScreen();
} else if (position == 9)
}
else if (position == 8)
{
OpenJournalScreen("investor", MainActivity.TAG_TO_MAINFRAGMENT);
}
else if (position == 9)
{
OpenSettingsScreen();
}
@ -770,7 +997,27 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
OpenArticleScreen(GetLastArticleName(), TAG_TO_MAINFRAGMENT);
return;
}
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT) != null)
{
OpenMapScreen(GetLastMapFilterName());
return;
}
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT) != null)
{
OpenCatalogScreen();
return;
}
if (getSupportFragmentManager().findFragmentByTag(TAG_FROM_CATALOGFRAGMENT_TO_JOURNALFRAGMENT) != null)
{
OpenCatalogScreen();
return;
}
if (getSupportFragmentManager().findFragmentByTag(TAG_TO_SEARCHFRAGMENT) != null)
{
OpenMainScreen();
@ -784,10 +1031,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
return;
}
if (getSupportFragmentManager().findFragmentByTag(TAG_TO_MAPFRAGMENT) != null)
{
OpenMapScreen();
OpenMapScreen("map");
return;
}
@ -831,6 +1080,21 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
SharedPreferences settings = MainActivity.getInstance().getSharedPreferences(PREFS_MAIN, 0);
return settings.getString("lastArticleName", "");
}
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", "");
}
@Override
protected void onResume()

View File

@ -7,7 +7,10 @@ import fishrungames.networkutils.ImageManager;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.NewsManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
import android.annotation.SuppressLint;
@ -23,6 +26,7 @@ import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import it.sephiroth.android.library.widget.HListView;
@ -37,6 +41,9 @@ public class MainPageFragment extends Fragment {
ListView listView;
ListAdapter listAdapter;
View header;
ProgressBar progressBar;
JournalSemiFullData newsJournal;
@SuppressLint("InflateParams")
@Override
@ -47,14 +54,20 @@ public class MainPageFragment extends Fragment {
listAdapter = new ListAdapter(getActivity());
listView.setAdapter(listAdapter);
header = inflater.inflate(R.layout.main_page_header, null);
RefreshHeader();
RestoreJournal();
MainActivity.getInstance().StartDownloadNewsTask();
listView.addHeaderView(header);
listView.setAdapter(listAdapter);
progressBar = (ProgressBar)header.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
Button moreNewsButton = (Button) header.findViewById(R.id.moreNewsButton);
moreNewsButton.setOnClickListener(new OnClickListener()
@ -70,11 +83,35 @@ public class MainPageFragment extends Fragment {
return rootView;
}
public void RefreshHeader()
void RestoreJournal()
{
newsJournal = JournalManager.CreateEmptyJournal();
RefreshJournal();
}
void RefreshJournal()
{
DatabaseGetJournalTask task = new DatabaseGetJournalTask();
task.mHandler = MainActivity.getInstance().mHandler;
Bundle bundle = new Bundle();
bundle.putString("journalName", "news");
bundle.putInt("count", 3);
task.execute(bundle);
}
public void SetJournal(JournalSemiFullData journal)
{
progressBar.setVisibility(View.GONE);
newsJournal = journal;
ImageButton news1ImageButton = (ImageButton) header.findViewById(R.id.news1ImageButton);
ImageButton news2ImageButton = (ImageButton) header.findViewById(R.id.news2ImageButton);
@ -84,17 +121,13 @@ public class MainPageFragment extends Fragment {
Button news2Button = (Button)header.findViewById(R.id.news2Button);
Button news3Button = (Button)header.findViewById(R.id.news3Button);
ArrayList<ArticleShortData> newsRecordArr = MainActivity.getInstance().journalDataSource.GetRecentArticles("news", 3);
if (newsRecordArr.size() > 0)
if (newsJournal.articleArr.size() > 0)
{
ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsRecordArr.get(0).previewImageUrl);
news1Button.setText(newsRecordArr.get(0).title);
ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsJournal.articleArr.get(0).previewImageUrl);
news1Button.setText(newsJournal.articleArr.get(0).title);
news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name));
news1Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name));
news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name));
news1Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name));
}
else
{
@ -104,12 +137,12 @@ public class MainPageFragment extends Fragment {
news1Button.setOnClickListener(null);
}
if (newsRecordArr.size() > 1)
if (newsJournal.articleArr.size() > 1)
{
ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsRecordArr.get(1).previewImageUrl);
news2Button.setText(newsRecordArr.get(1).title);
news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name));
news2Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name));
ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsJournal.articleArr.get(1).previewImageUrl);
news2Button.setText(newsJournal.articleArr.get(1).title);
news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name));
news2Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name));
}
else
{
@ -119,12 +152,12 @@ public class MainPageFragment extends Fragment {
news2Button.setOnClickListener(null);
}
if (newsRecordArr.size() > 2)
if (newsJournal.articleArr.size() > 2)
{
ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsRecordArr.get(2).previewImageUrl);
news3Button.setText(newsRecordArr.get(2).title);
news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name));
news3Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name));
ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsJournal.articleArr.get(2).previewImageUrl);
news3Button.setText(newsJournal.articleArr.get(2).title);
news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name));
news3Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name));
}
else
{
@ -166,6 +199,7 @@ public class MainPageFragment extends Fragment {
View view;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.main_page_list_element, null);

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.HtmlDownloadManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
import fishrungames.networkutils.ImageManager;
@ -64,14 +65,14 @@ public class MainPageHListViewAdapters {
view = convertView;
}
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
//TextView textView = (TextView) view.findViewById(R.id.dateTextView);
//TextView subTextView = (TextView) view.findViewById(R.id.subTextView);
//ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
textView.setText(albumFullData.photoRecordArr.get(position).title);
//textView.setText(albumFullData.photoRecordArr.get(position).title);
//subTextView.setText("");
@ -84,6 +85,77 @@ public class MainPageHListViewAdapters {
}
public static class JournalElementAdapter extends BaseAdapter {
private Context mContext;
//String albumName;
JournalSemiFullData journal;
//ArrayList<TextFileRecord> localHtmlList;
public JournalElementAdapter(Context c, JournalSemiFullData journal) {
this.mContext = c;
this.journal = journal;
//localHtmlList = HtmlDownloadManager.getInstance().getGlobalHtmlList();
}
public int getCount() {
return journal.articleArr.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
@SuppressLint("InflateParams")
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.simple_hview_list_element, null);
} else {
view = convertView;
}
TextView textView = (TextView) view.findViewById(R.id.dateTextView);
TextView subTextView = (TextView) view.findViewById(R.id.subTextView);
ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);
textView.setText(journal.articleArr.get(position).title);
subTextView.setText(journal.articleArr.get(position).dateTime.toString());
String imageUrl = journal.articleArr.get(position).previewImageUrl;
ImageManager.getInstance().ApplyImageToImageView(imageButton, imageUrl);
imageButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_CATALOGFRAGMENT_TO_ARTICLEFRAGMENT);
}
});
return view;
}
}
public static class SimpleElementAdapter extends BaseAdapter {
private Context mContext;

View File

@ -2,7 +2,17 @@ package fishrungames.bashgid;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;
import fishrungames.networkutils.ImageManager;
import fishrungames.bashgid.core.ArticleManager;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
import android.annotation.SuppressLint;
@ -18,6 +28,7 @@ import android.widget.BaseAdapter;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
@ -31,21 +42,38 @@ public class NewsListFragment extends Fragment
JournalSemiFullData journal;
ProgressBar progressBar;
TextView footerTextView;
@SuppressLint("InflateParams") @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RestoreJournal();
View rootView = inflater.inflate(R.layout.fragment_news_page, container, false);
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news");
listView = (ListView) rootView.findViewById(R.id.listView);
View header = inflater.inflate(R.layout.news_page_list_header, null);
listView.addHeaderView(header);
progressBar = (ProgressBar)header.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
View footer = inflater.inflate(R.layout.news_page_list_footer, null);
listView.addFooterView(footer);
footerTextView = (TextView)footer.findViewById(R.id.footerTextView);
listAdapter = new ListAdapter(getActivity());
listView.setAdapter(listAdapter);
View header = inflater.inflate(R.layout.news_page_list_header, null);
listView.addHeaderView(header);
listView.setOnItemClickListener(new OnItemClickListener(){
@ -53,10 +81,17 @@ public class NewsListFragment extends Fragment
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
//Add position + 1, because first element of list is always title
if (position > 0)
if (position == journal.articleArr.size() + 1)
{
MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position - 1).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
footerTextView.setText("Loading...");
LoadMoreNews();
}
else if (position > 0)
{
MainActivity.getInstance().OpenNewsRecordScreen(journal.articleArr.get(position - 1).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
}
}
});
@ -64,14 +99,71 @@ public class NewsListFragment extends Fragment
return rootView;
}
public void RefreshNewsList()
void RestoreJournal()
{
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news");
listAdapter.notifyDataSetChanged();
journal = JournalManager.CreateEmptyJournal();
RefreshJournal();
}
void RefreshJournal()
{
DatabaseGetJournalTask task = new DatabaseGetJournalTask();
task.mHandler = MainActivity.getInstance().mHandler;
Bundle bundle = new Bundle();
bundle.putString("journalName", "news");
bundle.putInt("count", 20);
task.execute(bundle);
}
void LoadMoreNews()
{
DatabaseGetJournalTask task = new DatabaseGetJournalTask();
task.mHandler = MainActivity.getInstance().mHandler;
Bundle bundle = new Bundle();
bundle.putString("journalName", "news");
bundle.putString("startAfterArticleName", journal.articleArr.get(journal.articleArr.size()-1).name);
bundle.putInt("count", 10);
task.execute(bundle);
}
public void SetJournal(JournalSemiFullData journal)
{
progressBar.setVisibility(View.GONE);
this.journal.articleArr.addAll(journal.articleArr);
Set<ArticleShortData> articleSet = new TreeSet<ArticleShortData>(new ArticleManager.ArticleShortDataSortComparator());
articleSet.addAll(this.journal.articleArr);
this.journal.articleArr.clear();
this.journal.articleArr.addAll(articleSet);
Collections.sort(this.journal.articleArr, new ArticleManager.ArticleShortDataTimeSortComparator());
//this.journal.previewImageArr.addAll(journal.previewImageArr);
footerTextView.setText("Load more");
listAdapter.notifyDataSetChanged();
}
public class ListAdapter extends BaseAdapter {
private Context mContext;
@ -114,35 +206,23 @@ public class NewsListFragment extends Fragment
dateTextView.setText(journal.articleArr.get(position).dateTime.toString());
if (journal.previewImageArr.get(position) != null)
{
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
ImageManager.getInstance().ApplyImageToImageView(imageView, journal.previewImageArr.get(position));
if (journal.articleArr.get(position).previewImageUrl != null)
{
ImageManager.getInstance().ApplyImageToImageView(imageView, journal.articleArr.get(position).previewImageUrl);
}
else
{
imageView.setImageResource(R.drawable.transparent);
}
return view;
}
}
public static class ButtonOnClickListener implements OnClickListener
{
NewsRecord newsRecord;
public ButtonOnClickListener(NewsRecord newsRecord)
{
this.newsRecord = newsRecord;
}
@Override
public void onClick(View v)
{
//MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
}
}
}

View File

@ -13,31 +13,27 @@ import android.widget.ImageView;
import android.widget.TextView;
public class NewsRecordFragment extends Fragment
public class NewsRecordFragment extends ArticleFragment
{
String articleName;
TextView titleTextView;
ArticleFullData articleData;
WebView webView;
public NewsRecordFragment()
{
this.articleName = "";
this.articleData = null;
super();
}
public NewsRecordFragment(String articleName)
{
this.articleName = articleName;
RestoreArticle();
super(articleName);
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("articleName", articleName);
}
public NewsRecordFragment(ArticleFullData article)
{
super(article);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -49,27 +45,26 @@ public class NewsRecordFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_news_record_page, container, false);
TextView titleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
titleTextView.setText(articleData.title);
titleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
//ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
//ImageManager.getInstance().ApplyImageToImageView(imageView, articleData.);
WebView webView = (WebView) rootView.findViewById(R.id.webView);
webView = (WebView) rootView.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(false);
String htmlCode = "<html><body>" + articleData.content + "</body></html>";
webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);
return rootView;
}
public void RestoreArticle()
@Override
public void SetArticle(ArticleFullData article)
{
articleData = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
this.article = article;
titleTextView.setText(article.title);
String htmlCode = "<html><body>" + article.content + "</body></html>";
webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);
}
}

View File

@ -15,6 +15,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.osmdroid.DefaultResourceProxyImpl;
@ -30,6 +31,8 @@ import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.OverlayItem.HotspotPlace;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.LocationHolder;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.networkutils.ImageManager;
@ -37,42 +40,44 @@ import fishrungames.networkutils.ImageManager;
public class OsmMapHolderFragment extends Fragment
{
public static class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
private ArrayList<String> mArticles = new ArrayList<String>();
public CustomItemizedOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
super(pDefaultMarker, pResourceProxy);
}
private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
private ArrayList<String> mArticles = new ArrayList<String>();
String journalName;
@Override
protected OverlayItem createItem(int pos) {
return mOverlayItems.get(pos);
}
public CustomItemizedOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy, String journalName) {
super(pDefaultMarker, pResourceProxy);
this.journalName = journalName;
}
@Override
public int size() {
if(mOverlayItems!=null) return mOverlayItems.size();
else return 0;
}
@Override
protected OverlayItem createItem(int pos) {
return mOverlayItems.get(pos);
}
public void addOverlayItem(GeoPoint geoPoint, String articleName, String title, String imageUrl){
OverlayItem item = new OverlayItem(title, imageUrl, geoPoint);
item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default));
item.setMarkerHotspot(HotspotPlace.CENTER);
mOverlayItems.add(item);
mArticles.add(articleName);
populateNow();
}
@Override
public int size() {
if(mOverlayItems!=null) return mOverlayItems.size();
else return 0;
}
public void populateNow(){
populate();
}
public void addOverlayItem(GeoPoint geoPoint, String articleName, String title, String imageUrl){
OverlayItem item = new OverlayItem(title, imageUrl, geoPoint);
item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default));
item.setMarkerHotspot(HotspotPlace.CENTER);
mOverlayItems.add(item);
mArticles.add(articleName);
populateNow();
}
public void populateNow(){
populate();
}
@Override
public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3)
@ -80,76 +85,77 @@ public class OsmMapHolderFragment extends Fragment
// TODO Auto-generated method stub
return false;
}
@Override
protected boolean onTap(final int index) {
OverlayItem item = mOverlayItems.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.getInstance());
dialog.setTitle(item.getTitle());
//dialog.setMessage(item.getSnippet());
ImageView image = new ImageView(MainActivity.getInstance());
ImageManager.getInstance().ApplyImageToImageView(image, item.getSnippet());
//image.setImageResource(R.drawable.YOUR_IMAGE_ID);
dialog.setView(image);
dialog.setPositiveButton("Open", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), null);
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
dialog.show();
return true;
OverlayItem item = mOverlayItems.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.getInstance());
dialog.setTitle(item.getTitle());
//dialog.setMessage(item.getSnippet());
ImageView image = new ImageView(MainActivity.getInstance());
ImageManager.getInstance().ApplyImageToImageView(image, item.getSnippet());
//image.setImageResource(R.drawable.YOUR_IMAGE_ID);
dialog.setView(image);
dialog.setPositiveButton("Open", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.getInstance().SetLastMapFilterName(journalName);
MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), MainActivity.TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT);
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
dialog.show();
return true;
}
}
public static class NoInteractionOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
public NoInteractionOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
super(pDefaultMarker, pResourceProxy);
}
public NoInteractionOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
super(pDefaultMarker, pResourceProxy);
}
@Override
protected OverlayItem createItem(int pos) {
return mOverlayItems.get(pos);
}
@Override
protected OverlayItem createItem(int pos) {
return mOverlayItems.get(pos);
}
@Override
public int size() {
if(mOverlayItems!=null) return mOverlayItems.size();
else return 0;
}
@Override
public int size() {
if(mOverlayItems!=null) return mOverlayItems.size();
else return 0;
}
public void addOverlayItem(GeoPoint geoPoint){
OverlayItem item = new OverlayItem("", "", geoPoint);
item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default));
item.setMarkerHotspot(HotspotPlace.CENTER);
mOverlayItems.add(item);
populateNow();
}
public void addOverlayItem(GeoPoint geoPoint){
public void populateNow(){
populate();
}
OverlayItem item = new OverlayItem("", "", geoPoint);
item.setMarker(MainActivity.getInstance().getResources().getDrawable(R.drawable.marker_default));
item.setMarkerHotspot(HotspotPlace.CENTER);
mOverlayItems.add(item);
populateNow();
}
public void populateNow(){
populate();
}
@Override
public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3)
@ -157,94 +163,127 @@ public class OsmMapHolderFragment extends Fragment
return false;
}
}
CustomItemizedOverlay itemizedOverlay;
String journalName;
JournalSemiFullData journal;
public OsmMapHolderFragment()
{
journal = null;
journalName = "";
}
public OsmMapHolderFragment(String journalName)
{
this.journalName = journalName;
RestoreJournal();
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("journalName", journalName);
}
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("journalName", journalName);
}
MapView mapView;
TextView textView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
journalName = savedInstanceState.getString("journalName");
RestoreJournal();
}
}
View rootView = inflater.inflate(R.layout.fragment_osm_map_page, container, false);
MapView mapView = (MapView) rootView.findViewById(R.id.mapview);
textView = (TextView) rootView.findViewById(R.id.textView);
textView.setText("Loading map...");
mapView = (MapView) rootView.findViewById(R.id.mapview);
mapView.setMaxZoomLevel(20);
mapView.setMinZoomLevel(4);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
IMapController mapController = mapView.getController();
GeoPoint center = new GeoPoint(LocationHolder.CONST_UFA_LATITUDE, LocationHolder.CONST_UFA_LONGITUDE);
mapController.setZoom(10);
mapController.animateTo(center);
ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getActivity());
itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy);
//JournalSemiFullData journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName);
for (int i = 0; i < journal.articleArr.size(); i++)
//for (ArticleRecordData article : journal.articleArr)
{
ArticleRecordData article = journal.articleArr.get(i);
if (article.geoLat != 0 || article.geoLon != 0)
{
GeoPoint markerPoint = new GeoPoint(article.geoLat, article.geoLon);
itemizedOverlay.addOverlayItem(markerPoint, article.name, article.title, journal.previewImageArr.get(i));
}
}
//itemizedOverlay.addOverlayItem(markerPoint);
mapView.getOverlays().add(itemizedOverlay);
mapController.animateTo(center);
RefreshView();
return rootView;
}
void RestoreJournal()
{
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName);
journal = JournalManager.CreateEmptyJournal();
DatabaseGetJournalTask task = new DatabaseGetJournalTask();
task.mHandler = MainActivity.getInstance().mHandler;
Bundle bundle = new Bundle();
bundle.putString("journalName", journalName);
task.execute(bundle);
}
public void SetJournal(JournalSemiFullData journal)
{
textView.setText("Map is loaded");
this.journal = journal;
RefreshView();
}
public void RefreshView()
{
if (journal != null)
{
ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getActivity());
itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy, journalName);
for (int i = 0; i < journal.articleArr.size(); i++)
{
ArticleRecordData article = journal.articleArr.get(i);
if (article.geoLat != 0 || article.geoLon != 0)
{
GeoPoint markerPoint = new GeoPoint(article.geoLat, article.geoLon);
itemizedOverlay.addOverlayItem(markerPoint, article.name, article.title, journal.articleArr.get(i).previewImageUrl);
}
}
mapView.getOverlays().clear();
mapView.getOverlays().add(itemizedOverlay);
mapView.invalidate();
}
}
}

View File

@ -14,9 +14,11 @@ import android.widget.BaseAdapter;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.AdapterView.OnItemClickListener;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.networkutils.ImageManager;
@ -28,12 +30,20 @@ public class PhotoAlbumFragment extends Fragment
ListAdapter listAdapter;
ProgressBar progressBar;
public PhotoAlbumFragment()
{
album = null;
albumName = "";
}
public PhotoAlbumFragment(AlbumFullData album)
{
this.album = album;
this.albumName = album.name;
}
public PhotoAlbumFragment(String albumName)
{
this.albumName = albumName;
@ -56,6 +66,10 @@ public class PhotoAlbumFragment extends Fragment
}
View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
listAdapter = new ListAdapter(getActivity());
@ -69,7 +83,7 @@ public class PhotoAlbumFragment extends Fragment
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
MainActivity.getInstance().SetLastAlbumName(albumName);
MainActivity.getInstance().OpenPhotoScreen(albumName, position, MainActivity.TAG_FROM_PHOTOLISTFRAGMENT_TO_PHOTOFRAGMENT);
MainActivity.getInstance().OpenPhotoScreen(album, position, MainActivity.TAG_FROM_PHOTOLISTFRAGMENT_TO_PHOTOFRAGMENT);
}
@ -80,7 +94,23 @@ public class PhotoAlbumFragment extends Fragment
void RestoreAlbum()
{
album = MainActivity.getInstance().albumDataSource.GetAlbumFullData(albumName);
album = AlbumManager.CreateEmptyAlbum();
DatabaseGetAlbumTask task = new DatabaseGetAlbumTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(albumName);
}
public void SetAlbum(AlbumFullData album)
{
progressBar.setVisibility(View.GONE);
this.album = album;
listAdapter.notifyDataSetChanged();
}
public class ListAdapter extends BaseAdapter {

View File

@ -1,14 +1,19 @@
package fishrungames.bashgid;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
public class PhotoFragment extends Fragment
{
@ -18,6 +23,9 @@ public class PhotoFragment extends Fragment
int currentPhoto;
PhotoFragmentAdapter listAdapter;
ViewPager pager;
ProgressBar progressBar;
public PhotoFragment()
{
@ -26,8 +34,16 @@ public class PhotoFragment extends Fragment
currentPhoto = -1;
}
public PhotoFragment(AlbumFullData album, int currentPhoto)
{
this.album = album;
this.albumName = album.name;
this.currentPhoto = currentPhoto;
}
public PhotoFragment(String albumName, int currentPhoto)
{
this.album = null;
this.albumName = albumName;
this.currentPhoto = currentPhoto;
RestoreAlbum();
@ -52,10 +68,21 @@ public class PhotoFragment extends Fragment
}
View rootView = inflater.inflate(R.layout.fragment_photo_page, container, false);
listAdapter = new PhotoFragmentAdapter(getActivity(), album/*, currentPhoto*/);
ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
if (album == null)
{
progressBar.setVisibility(View.VISIBLE);
}
else
{
progressBar.setVisibility(View.GONE);
}
listAdapter = new PhotoFragmentAdapter(getActivity(), album);
pager = (ViewPager) rootView.findViewById(R.id.pager);
pager.setAdapter(listAdapter);
@ -66,7 +93,29 @@ public class PhotoFragment extends Fragment
void RestoreAlbum()
{
album = MainActivity.getInstance().albumDataSource.GetAlbumFullData(albumName);
album = AlbumManager.CreateEmptyAlbum();
DatabaseGetAlbumTask task = new DatabaseGetAlbumTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(albumName);
}
public void SetAlbum(AlbumFullData album)
{
progressBar.setVisibility(View.GONE);
this.album = album;
listAdapter.album = album;
listAdapter.notifyDataSetChanged();
pager.setCurrentItem(currentPhoto);
}
}

View File

@ -15,6 +15,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class PhotoFragmentAdapter extends PagerAdapter {
@ -43,16 +44,26 @@ public class PhotoFragmentAdapter extends PagerAdapter {
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.photo_page_element, container,
false);
TextView titleTextView = (TextView) viewLayout.findViewById(R.id.titleTextView);
titleTextView.setText(album.photoRecordArr.get(position).title);
TextView descriptionTextView = (TextView) viewLayout.findViewById(R.id.descriptionTextView);
descriptionTextView.setText(album.photoRecordArr.get(position).description);
ImageView image = (ImageView) viewLayout.findViewById(R.id.image);
ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl);
((ViewPager) container).addView(viewLayout);
return viewLayout;

View File

@ -2,13 +2,17 @@ package fishrungames.bashgid;
import fishrungames.bashgid.core.ChannelManager;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -18,6 +22,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -28,6 +33,7 @@ public class VideoListFragment extends Fragment
ListAdapter listAdapter;
GridView gridView;
ProgressBar progressBar;
String channelName;
ChannelFullData channelFullData;
@ -44,6 +50,12 @@ public class VideoListFragment extends Fragment
RestoreChannel();
}
public VideoListFragment(ChannelFullData channelFullData)
{
this.channelName = channelFullData.name;
this.channelFullData = channelFullData;
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
@ -60,6 +72,11 @@ public class VideoListFragment extends Fragment
}
View rootView = inflater.inflate(R.layout.fragment_video_page, container, false);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
gridView = (GridView) rootView.findViewById(R.id.gridView);
@ -73,20 +90,69 @@ public class VideoListFragment extends Fragment
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
MainActivity.getInstance().OpenVideoRecordScreen(channelFullData.videoRecordArr.get(position).videoUrl, MainActivity.TAG_FROM_VIDEOLISTFRAGMENT_TO_VIDEORECORDFRAGMENT);
MainActivity.getInstance().OpenVideoRecordScreen(channelFullData.videoRecordArr.get(position), MainActivity.TAG_FROM_VIDEOLISTFRAGMENT_TO_VIDEORECORDFRAGMENT);
}
});
return rootView;
}
void RestoreChannel()
{
channelFullData = MainActivity.getInstance().channelDataSource.GetChannelFullData(channelName);
channelFullData = ChannelManager.CreateEmptyChannel();
DatabaseGetChannelTask task = new DatabaseGetChannelTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(channelName);
}
void SetChannel(ChannelFullData channelFullData)
{
progressBar.setVisibility(View.GONE);
this.channelFullData = channelFullData;
listAdapter.notifyDataSetChanged();
//channelFullData = MainActivity.getInstance().channelDataSource.GetChannelFullData(channelName);
}
public class DatabaseGetChannelTask extends AsyncTask<String, Integer, Long>
{
ChannelFullData channel = null;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String channelName = queryArr[0];
channel = MainActivity.getInstance().channelDataSource.GetChannelFullData(channelName);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_CHANNEL_STATE_UPDATE, channel);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_CHANNEL_STATE_FINISHED, channel);
completeMessage.sendToTarget();
}
}
public class ListAdapter extends BaseAdapter {
private Context mContext;
@ -132,4 +198,6 @@ public class VideoListFragment extends Fragment
}
}
}

View File

@ -1,19 +1,26 @@
package fishrungames.bashgid;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.VideoManager;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.bashgid.core.VideoManager.VideoRecordData;
import fishrungames.networkutils.ImageManager;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -24,6 +31,11 @@ public class VideoRecordFragment extends Fragment
VideoRecordData recordData;
TextView nameTextView;
TextView descriptionTextView;
ImageView imageView;
ProgressBar progressBar;
public VideoRecordFragment()
{
this.videoUrl = "";
@ -32,10 +44,17 @@ public class VideoRecordFragment extends Fragment
public VideoRecordFragment(String videoUrl)
{
this.recordData = null;
this.videoUrl = videoUrl;
RestoreVideo();
}
public VideoRecordFragment(VideoRecordData recordData)
{
this.videoUrl = recordData.videoUrl;
this.recordData = recordData;
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
@ -52,13 +71,54 @@ public class VideoRecordFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_video_record_page, container, false);
TextView nameTextView = (TextView) rootView.findViewById(R.id.nameTextView);
progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
if (recordData == null)
{
progressBar.setVisibility(View.VISIBLE);
}
else
{
progressBar.setVisibility(View.GONE);
}
nameTextView = (TextView) rootView.findViewById(R.id.nameTextView);
descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView);
imageView = (ImageView) rootView.findViewById(R.id.imageView);
RefreshView();
return rootView;
}
void RestoreVideo()
{
//recordData = MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl);
recordData = VideoManager.CreateEmptyVideo();
DatabaseGetVideoTask task = new DatabaseGetVideoTask();
task.mHandler = MainActivity.getInstance().mHandler;
task.execute(videoUrl);
}
void SetVideo(VideoRecordData recordData)
{
progressBar.setVisibility(View.GONE);
this.recordData = recordData;
RefreshView();
}
void RefreshView()
{
nameTextView.setText(recordData.title);
TextView descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView);
descriptionTextView.setText(recordData.description);
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
ImageManager.getInstance().ApplyImageToImageView(imageView, recordData.previewImageUrl);
imageView.setOnClickListener(new OnClickListener()
@ -69,19 +129,45 @@ public class VideoRecordFragment extends Fragment
{
if (recordData.type == VideoManager.VIDEO_TYPE_YOUTUBE)
{
MainActivity.getInstance().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(recordData.videoUrl)));
MainActivity.getInstance().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(videoUrl)));
}
}
});
return rootView;
}
void RestoreVideo()
public static class DatabaseGetVideoTask extends AsyncTask<String, Integer, Long>
{
recordData = MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl);
VideoRecordData recordData = null;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String videoUrl = queryArr[0];
recordData = MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_VIDEO_STATE_UPDATE, recordData);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_VIDEO_STATE_FINISHED, recordData);
completeMessage.sendToTarget();
}
}
}

View File

@ -72,6 +72,13 @@ public class AlbumManager
}
}
public static AlbumFullData CreateEmptyAlbum()
{
AlbumFullData result = new AlbumFullData(new AlbumRecordData("", "", ""));
return result;
}
public static void DownloadAndAddPhoto(PhotoRecordData recordData)
{

View File

@ -2,11 +2,13 @@ package fishrungames.bashgid.core;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.Locale;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
public class ArticleManager
{
@ -89,4 +91,16 @@ public class ArticleManager
//channelArr = new ArrayList<ChannelFullData>();
}
}
public static class ArticleShortDataSortComparator implements Comparator<ArticleShortData> {
public int compare(ArticleShortData record1, ArticleShortData record2) {
return record2.name.compareTo(record1.name);
}
}
public static class ArticleShortDataTimeSortComparator implements Comparator<ArticleShortData> {
public int compare(ArticleShortData record1, ArticleShortData record2) {
return record2.dateTime.compareTo(record1.dateTime);
}
}
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
@ -54,6 +56,14 @@ public class ChannelManager
this.id = id;
}
}
public static ChannelFullData CreateEmptyChannel()
{
ChannelFullData result = new ChannelFullData(new ChannelRecordData("", "", ""));
return result;
}
/*
public static void DownloadAndAddPhoto(PhotoRecordData recordData)

View File

@ -0,0 +1,444 @@
package fishrungames.bashgid.core;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ChannelManager.ChannelRecordData;
import fishrungames.bashgid.core.JournalManager.JournalRecordData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
import fishrungames.bashgid.core.VideoManager.VideoRecordData;
public class DatabaseDownloadTask extends AsyncTask<Bundle, Integer, Long>
{
public Handler mHandler;
protected Long doInBackground(Bundle... queryArr)
{
ParseJsonPhoto(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=photo/json"));
ParseJsonAlbum(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=album/json"));
ParseJsonPhotoAlbumRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=photoAlbumRelation/json"));
ParseJsonVideo(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=video/json"));
ParseJsonChannel(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=channel/json"));
ParseJsonVideoChannelRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=videoChannelRelation/json"));
ParseJsonArticle(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=article/json"));
ParseJsonJournal(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=journal/json"));
ParseJsonAlbumArticleRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=albumArticleRelation/json"));
ParseJsonChannelArticleRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=channelArticleRelation/json"));
ParseJsonArticleJournalRelation(getJsonFromUrl("http://192.168.0.72/bashgid/index.php?r=articleJournalRelation/json"));
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_UPDATE, this);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_DOWNLOADER_STATE_FINISHED, this);
completeMessage.sendToTarget();
}
private String getJsonFromUrl(String url_select)
{
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
InputStream inputStream = null;
try {
// Set up HTTP post
// HttpClient is more then less deprecated. Need to change to URLConnection
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_select);
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// Read content & Log
inputStream = httpEntity.getContent();
} catch (UnsupportedEncodingException e1) {
Log.e("UnsupportedEncodingException", e1.toString());
e1.printStackTrace();
} catch (ClientProtocolException e2) {
Log.e("ClientProtocolException", e2.toString());
e2.printStackTrace();
} catch (IllegalStateException e3) {
Log.e("IllegalStateException", e3.toString());
e3.printStackTrace();
} catch (IOException e4) {
Log.e("IOException", e4.toString());
e4.printStackTrace();
}
// Convert response to string using String Builder
try {
BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder sBuilder = new StringBuilder();
String line = null;
while ((line = bReader.readLine()) != null) {
sBuilder.append(line + "\n");
}
inputStream.close();
String result = sBuilder.toString();
return result;
} catch (Exception e) {
Log.e("StringBuilding & BufferedReader", "Error converting result " + e.toString());
}
return "";
}
private void ParseJsonPhoto(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String title = jObject.getString("title");
String description = jObject.getString("description");
String imageUrl = jObject.getString("imageUrl");
String imageHash = jObject.getString("imageHash");
double geoLat = jObject.getDouble("geoLat");
double geoLon = jObject.getDouble("geoLon");
MainActivity.getInstance().photoDataSource.AddOrReplacePhoto(new PhotoRecordData(
title,
description,
imageUrl,
imageHash,
geoLat,
geoLon));
MainActivity.getInstance().DownloadImage(imageUrl, imageHash);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonAlbum(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String name = jObject.getString("name");
String title = jObject.getString("title");
String description = jObject.getString("description");
MainActivity.getInstance().albumDataSource.CreateNewAlbum(new AlbumRecordData(
name,
title,
description));
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonPhotoAlbumRelation(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String imageUrl = jObject.getString("imageUrl");
String name = jObject.getString("name");
MainActivity.getInstance().albumDataSource.AddPhotoToAlbum(imageUrl, name);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonVideo(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
int type = jObject.getInt("type");
String videoUrl = jObject.getString("videoUrl");
String title = jObject.getString("title");
String description = jObject.getString("description");
String previewImageUrl = jObject.getString("previewImageUrl");
String previewImageHash = jObject.getString("previewImageHash");
MainActivity.getInstance().videoDataSource.AddOrReplaceVideo(new VideoRecordData(
type,
videoUrl,
title,
description,
previewImageUrl,
previewImageHash
));
MainActivity.getInstance().DownloadImage(previewImageUrl, previewImageHash);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonChannel(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String name = jObject.getString("name");
String title = jObject.getString("title");
String description = jObject.getString("description");
MainActivity.getInstance().channelDataSource.CreateNewChannel(new ChannelRecordData(
name,
title,
description));
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonVideoChannelRelation(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String videoUrl = jObject.getString("videoUrl");
String name = jObject.getString("name");
MainActivity.getInstance().channelDataSource.AddVideoToChannel(videoUrl, name);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonArticle(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
try
{
JSONObject jObject = jArray.getJSONObject(i);
String name = jObject.getString("name");
int type = jObject.getInt("type");
String title = jObject.getString("title");
String content = jObject.getString("content");
double geoLat = jObject.getDouble("geoLat");
double geoLon = jObject.getDouble("geoLon");
String externalLink = jObject.getString("externalLink");
Date dateTime = ArticleManager.iso8601Format.parse(jObject.getString("dateTime"));
MainActivity.getInstance().articleDataSource.CreateNewArticle(new ArticleRecordData(
name,
type,
title,
content,
geoLat,
geoLon,
externalLink,
dateTime
));
} catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonJournal(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String name = jObject.getString("name");
String title = jObject.getString("title");
String description = jObject.getString("description");
MainActivity.getInstance().journalDataSource.CreateNewJournal(new JournalRecordData(
name,
title,
description));
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonAlbumArticleRelation(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String albumName = jObject.getString("albumName");
String articleName = jObject.getString("articleName");
MainActivity.getInstance().articleDataSource.AddAlbumToArticle(albumName, articleName);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonChannelArticleRelation(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String channelName = jObject.getString("channelName");
String articleName = jObject.getString("articleName");
MainActivity.getInstance().articleDataSource.AddChannelToArticle(channelName, articleName);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
private void ParseJsonArticleJournalRelation(String jsonCode)
{
try {
JSONArray jArray = new JSONArray(jsonCode);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String articleName = jObject.getString("articleName");
String journalName = jObject.getString("journalName");
MainActivity.getInstance().journalDataSource.AddArticleToJournal(articleName, journalName);
} // End Loop
} catch (JSONException e) {
Log.e("JSONException", "Error: " + e.toString());
}
}
}

View File

@ -0,0 +1,39 @@
package fishrungames.bashgid.core;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
public class DatabaseGetAlbumTask extends AsyncTask<String, Integer, Long>
{
AlbumFullData album = null;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String albumName = queryArr[0];
album = MainActivity.getInstance().albumDataSource.GetAlbumFullData(albumName);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_STATE_UPDATE, album);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_ALBUM_STATE_FINISHED, album);
completeMessage.sendToTarget();
}
}

View File

@ -0,0 +1,45 @@
package fishrungames.bashgid.core;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
public class DatabaseGetJournalTask extends AsyncTask<Bundle, Integer, Long>
{
JournalSemiFullData journal = null;
public Handler mHandler;
protected Long doInBackground(Bundle... queryArr)
{
String journalName = queryArr[0].getString("journalName");
String startAfterArticleName = queryArr[0].getString("startAfterArticleName");
int count = queryArr[0].getInt("count", 0);
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName, startAfterArticleName, count);
return (long) 0;
}
protected void onProgressUpdate(Integer... progress)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_UPDATE, journal);
completeMessage.sendToTarget();
}
protected void onPostExecute(Long result)
{
Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal);
completeMessage.sendToTarget();
}
}

View File

@ -1,9 +1,14 @@
package fishrungames.bashgid.core;
import java.util.ArrayList;
import java.util.Comparator;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
public class JournalManager
@ -34,14 +39,14 @@ public class JournalManager
public static class JournalSemiFullData extends JournalRecordData
{
public ArrayList<ArticleRecordData> articleArr;
public ArrayList<String> previewImageArr;
public ArrayList<ArticleShortData> articleArr;
//public ArrayList<String> previewImageArr;
public JournalSemiFullData(JournalRecordData copyFrom)
{
super(copyFrom);
articleArr = new ArrayList<ArticleRecordData>();
previewImageArr = new ArrayList<String>();
articleArr = new ArrayList<ArticleShortData>();
//previewImageArr = new ArrayList<String>();
}
}
@ -57,7 +62,14 @@ public class JournalManager
this.id = id;
}
}
public static JournalSemiFullData CreateEmptyJournal()
{
JournalSemiFullData result = new JournalSemiFullData(new JournalRecordData("", "", ""));
return result;
}
}

View File

@ -1,17 +1,12 @@
package fishrungames.bashgid.core;
import java.util.ArrayList;
import java.util.Collections;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
import fishrungames.bashgid.core.NewsManager.NewsSortComparator;
import fishrungames.networkutils.ImageDownloadTask;
public class NewsDownloadTask extends AsyncTask<Bundle, Integer, Long>
{
@ -21,31 +16,6 @@ public class NewsDownloadTask extends AsyncTask<Bundle, Integer, Long>
protected Long doInBackground(Bundle... queryArr)
{
/*
ArrayList<NewsRecord> localNewsRecordArr = MainActivity.getInstance().newsDataSource.getNews();
for (int i = 0; i < NewsManager.urlArr.length; i++)
{
NewsManager.LoadNewsAndImagesFromRss2(NewsManager.urlArr[i], localNewsRecordArr, imageToDownloadList);
}
Collections.sort(localNewsRecordArr, new NewsSortComparator());
NewsManager.getInstance().replaceNews(localNewsRecordArr);
Bundle innerQuery = new Bundle();
innerQuery.putStringArray("imageUrlArr", imageToDownloadList.toArray(new String[imageToDownloadList.size()]));
ImageDownloadTask task = new ImageDownloadTask();
task.mHandler = this.mHandler;
task.execute(innerQuery);
*/
for (int i = 0; i < NewsManager.urlArr.length; i++)
{

View File

@ -344,6 +344,7 @@ public class NewsManager {
rssReader.ReadRss(xmlCode);
//Xperimental -- need to optimize this code. slow block ENDS
@ -351,11 +352,12 @@ public class NewsManager {
for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr)
{
ArticleRecordData newsArticle = new ArticleRecordData(
rss2Item.title,
rss2Item.title.replace("'", "''").replace("\"", "\"\""),
ArticleManager.ARTICLE_TYPE_NEWS,
rss2Item.title,
rss2Item.description,
rss2Item.title.replace("'", "''").replace("\"", "\"\""),
rss2Item.description.replace("'", "''").replace("\"", "\"\""),
0,
0,
rss2Item.link,

View File

@ -1,5 +1,8 @@
package fishrungames.bashgid.core;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
public class VideoManager
{
public static final int VIDEO_TYPE_YOUTUBE = 1;
@ -51,5 +54,13 @@ public class VideoManager
}
public static VideoRecordData CreateEmptyVideo()
{
VideoRecordData result = new VideoRecordData(0, "", "", "", "", "");
return result;
}
}

View File

@ -46,7 +46,7 @@ public class AlbumDataSource
database.insert(BashgidSqliteHelper.TABLE_ALBUM, null, values);
} else
{
// Replace
database.update(BashgidSqliteHelper.TABLE_ALBUM, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
}
} finally

View File

@ -9,6 +9,7 @@ import java.util.Date;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.ArticleManager;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
@ -66,7 +67,7 @@ public class ArticleDataSource
database.insert(BashgidSqliteHelper.TABLE_ARTICLE, null, values);
} else
{
// Replace
database.update(BashgidSqliteHelper.TABLE_ARTICLE, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
}
} finally
@ -117,11 +118,11 @@ public class ArticleDataSource
if (!innerAlbumArticleRelationAlreadyExist(albumName, articleName, database))
{
Log.e("a", "aaa1");
//Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, null, values);
Log.e("a", "aaa2");
//Log.e("a", "aaa2");
}
Log.e("a", "aaa3");
//Log.e("a", "aaa3");
} finally
{
@ -146,11 +147,11 @@ public class ArticleDataSource
if (!innerChannelArticleRelationAlreadyExist(channelName, articleName, database))
{
Log.e("a", "aaa1");
//Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, null, values);
Log.e("a", "aaa2");
//Log.e("a", "aaa2");
}
Log.e("a", "aaa3");
//Log.e("a", "aaa3");
} finally
{
@ -252,11 +253,20 @@ public class ArticleDataSource
ArrayList<String> albumNameArr = innerGetAlbumNameArrInArticle(name, database);
result.previewImageUrl = "R.drawable.no_picture";
if (albumNameArr.size() > 0)
{
result.previewImageUrl = albumNameArr.get(0);
AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumNameArr.get(0), database);
if (album.photoRecordArr.size() > 0)
{
result.previewImageUrl = album.photoRecordArr.get(0).imageUrl;
}
}
else
if (result.previewImageUrl.equals("R.drawable.no_picture"))
{
ArrayList<String> channelNameArr = innerGetChannelNameArrInArticle(name, database);
@ -268,7 +278,6 @@ public class ArticleDataSource
{
result.previewImageUrl = channelFullData.videoRecordArr.get(0).previewImageUrl;
}
}
}

View File

@ -46,7 +46,7 @@ public class ChannelDataSource
database.insert(BashgidSqliteHelper.TABLE_CHANNEL, null, values);
} else
{
// Replace
database.update(BashgidSqliteHelper.TABLE_CHANNEL, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
}
} finally

View File

@ -7,6 +7,8 @@ import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.ArticleManager;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.JournalManager.JournalRecordData;
@ -51,6 +53,7 @@ public class JournalDataSource
} else
{
// Replace
database.update(BashgidSqliteHelper.TABLE_JOURNAL, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
}
} finally
@ -100,11 +103,11 @@ public class JournalDataSource
if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database))
{
Log.e("a", "aaa1");
//Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, null, values);
Log.e("a", "aaa2");
//Log.e("a", "aaa2");
}
Log.e("a", "aaa3");
//Log.e("a", "aaa3");
} finally
{
@ -113,7 +116,7 @@ public class JournalDataSource
}
}
public ArrayList<ArticleShortData> GetRecentArticles(String journalName, int count)
{
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
@ -136,9 +139,9 @@ public class JournalDataSource
{
result.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(articleName, database));
}
Collections.sort(result, new ArticleDataSource.DateSortComparator());
if (result.size() > count)
{
result.subList(count, result.size() - count - 1).clear();
@ -156,6 +159,16 @@ public class JournalDataSource
}
public JournalSemiFullData GetJournalSemiFullData(String name)
{
return GetJournalSemiFullData(name, null, 0);
}
public JournalSemiFullData GetJournalSemiFullData(String name, int count)
{
return GetJournalSemiFullData(name, null, count);
}
public JournalSemiFullData GetJournalSemiFullData(String name, String startAfterArticleName, int count)
{
JournalSemiFullData result = null;
@ -166,7 +179,7 @@ public class JournalDataSource
try
{
result = InnerGetJournalSemiFullData(name, database);
result = InnerGetJournalSemiFullData(name, database, startAfterArticleName, count);
} finally
{
@ -176,60 +189,146 @@ public class JournalDataSource
return result;
}
public JournalSemiFullData InnerGetJournalSemiFullData(String name, SQLiteDatabase database)
public ArrayList<JournalSemiFullData> GetAllJournalList()
{
ArrayList<JournalSemiFullData> result = new ArrayList<JournalSemiFullData>();
SQLiteDatabase database = dbHelper.getWritableDatabase();
if (database != null)
{
try
{
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME,
BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null);
if (cursor != null)
{
if (cursor.moveToFirst())
{
do
{
String name = cursor.getString(0);
if (!name.equals("news") && !name.equals("map"))
{
JournalSemiFullData journal = new JournalSemiFullData(new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2)));
ArrayList<String> articleArr = innerGetArticleArrInJournal(cursor.getString(0), database);
for (String article : articleArr)
{
journal.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database));
/*
String imageUrl = "R.drawable.no_picture";
//Find first photo in first album (if exist)
ArrayList<String> albumArr = MainActivity.getInstance().articleDataSource.innerGetAlbumNameArrInArticle(article, database);
if (albumArr.size() > 0)
{
AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumArr.get(0), database);
if (album.photoRecordArr.size() > 0)
{
imageUrl = album.photoRecordArr.get(0).imageUrl;
}
}
journal.previewImageArr.add(imageUrl);*/
}
result.add(journal);
}
} while (cursor.moveToNext());
}
}
}
finally
{
dbHelper.close();
}
}
return result;
}
public JournalSemiFullData InnerGetJournalSemiFullData(String name, SQLiteDatabase database, String startAfterArticleName, int count)
{
JournalSemiFullData result = null;
JournalRecordData recordData = innerGetJournalByName(name, database);
if (recordData != null)
{
result = new JournalSemiFullData(recordData);
ArrayList<String> articleArr = innerGetArticleArrInJournal(name, database);
ArrayList<ArticleShortData> intermediateArticleArr = new ArrayList<ArticleShortData>();
for (String article : articleArr)
{
result.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database));
String imageUrl = null;
//Find first photo in first album (if exist)
ArrayList<String> albumArr = MainActivity.getInstance().articleDataSource.innerGetAlbumNameArrInArticle(article, database);
if (albumArr.size() > 0)
{
AlbumFullData album = MainActivity.getInstance().albumDataSource.InnerGetAlbumFullData(albumArr.get(0), database);
intermediateArticleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database));
}
Collections.sort(intermediateArticleArr, new ArticleManager.ArticleShortDataTimeSortComparator());
boolean articleCanGo = false;
if (album.photoRecordArr.size() > 0)
if (startAfterArticleName == null || startAfterArticleName.length() == 0)
{
articleCanGo = true;
}
int i = 0;
for (ArticleShortData article : intermediateArticleArr)
{
if (!articleCanGo)
{
if (article.name.equals(startAfterArticleName))
{
imageUrl = album.photoRecordArr.get(0).imageUrl;
articleCanGo = true;
}
}
result.previewImageArr.add(imageUrl);
else
{
if (count == 0 || i < count)
{
result.articleArr.add(article);
i++;
}
}
}
/*
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(name, database);
for (String imageUrl : imageUrlArr)
{
result.photoRecordArr.add(MainActivity.getInstance().photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database));
}*/
}
return result;
}
private boolean innerIsJournalAlreadyExist(String name, SQLiteDatabase database)
{
boolean result = false;
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME
+ "=?", new String[] { name }, null, null, null, null);
@ -239,7 +338,7 @@ public class JournalDataSource
{
result = true;
}
cursor.close();
}
@ -250,7 +349,7 @@ public class JournalDataSource
private boolean innerArticleJournalRelationAlreadyExist(String articleName, String journalName, SQLiteDatabase database)
{
boolean result = false;
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ARTICLE_NAME,
BashgidSqliteHelper.COLUMN_JOURNAL_NAME }, BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?",
new String[] { articleName, journalName }, null, null, null, null);
@ -261,7 +360,7 @@ public class JournalDataSource
{
result = true;
}
cursor.close();
}
@ -269,7 +368,7 @@ public class JournalDataSource
}
private ArrayList<String> innerGetArticleArrInJournal(String name, SQLiteDatabase database)
{
ArrayList<String> result = new ArrayList<String>();
@ -287,7 +386,7 @@ public class JournalDataSource
} while (cursor.moveToNext());
}
cursor.close();
}
@ -297,7 +396,7 @@ public class JournalDataSource
public JournalRecordData innerGetJournalByName(String name, SQLiteDatabase database)
{
JournalRecordData result = null;
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE,

View File

@ -42,13 +42,10 @@ public class PhotoDataSource
boolean r = isPhotoAlreadyExist(recordData.imageUrl, database);
if (!r)
{
Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_PHOTO, null, values);
Log.e("a", "aaa2");
} else
{
// Replace
Log.e("a", "aaa3");
database.update(BashgidSqliteHelper.TABLE_PHOTO, values, BashgidSqliteHelper.COLUMN_IMAGE_URL + " = " +"\"" + recordData.imageUrl +"\"", null);
}
Log.e("a", "aaa4");

View File

@ -41,16 +41,12 @@ public class VideoDataSource
boolean r = isVideoAlreadyExist(recordData.videoUrl, database);
if (!r)
{
Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_VIDEO, null, values);
Log.e("a", "aaa2");
} else
{
// Replace
Log.e("a", "aaa3");
database.update(BashgidSqliteHelper.TABLE_VIDEO, values, BashgidSqliteHelper.COLUMN_VIDEO_URL + " = " +"\"" + recordData.videoUrl +"\"", null);
}
Log.e("a", "aaa4");
} finally
{
dbHelper.close();