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:paddingTop="4dp"
android:showDividers="middle" > 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 <it.sephiroth.android.library.widget.HListView
android:id="@+id/hListView" android:id="@+id/hListView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -13,10 +13,4 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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> </LinearLayout>

View File

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

View File

@ -7,6 +7,9 @@
android:orientation="vertical" android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" > tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView <ListView
android:id="@+id/listView" android:id="@+id/listView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -19,4 +22,12 @@
</ListView> </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> </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" android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" > tools:context="fishrungames.bashgid.MainPageFragment" >
<ListView <ListView
android:id="@+id/listView" android:id="@+id/listView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -17,6 +18,9 @@
android:dividerHeight="2dp" android:dividerHeight="2dp"
android:paddingBottom="16dp" > android:paddingBottom="16dp" >
</ListView> </ListView>
</LinearLayout> </LinearLayout>

View File

@ -10,6 +10,17 @@
android:paddingTop="0dp" android:paddingTop="0dp"
tools:context="fishrungames.bashgid.MapHolderFragment" > 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 <org.osmdroid.views.MapView
android:id="@+id/mapview" android:id="@+id/mapview"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

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

View File

@ -7,6 +7,14 @@
android:orientation="vertical" android:orientation="vertical"
tools:context="fishrungames.bashgid.MainPageFragment" > 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 <ListView
android:id="@+id/listView" android:id="@+id/listView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -14,7 +22,7 @@
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:divider="@color/bkg2" android:divider="@color/bkg2"
android:dividerHeight="2dp" android:dividerHeight="12dp"
android:paddingBottom="16dp" > android:paddingBottom="16dp" >
</ListView> </ListView>

View File

@ -4,6 +4,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > 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.support.v4.view.ViewPager
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@ -3,12 +3,23 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > 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 <GridView
android:id="@+id/gridView" android:id="@+id/gridView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:numColumns="3" > android:gravity="bottom"
android:horizontalSpacing="12dp"
android:numColumns="4"
android:verticalSpacing="12dp" >
</GridView> </GridView>
</LinearLayout> </LinearLayout>

View File

@ -5,6 +5,14 @@
android:layout_margin="6dp" android:layout_margin="6dp"
android:orientation="vertical" > 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 <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

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

View File

@ -36,6 +36,12 @@
</LinearLayout> </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 <it.sephiroth.android.library.widget.HListView
android:id="@+id/hListView" android:id="@+id/hListView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

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

View File

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

View File

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

View File

@ -5,10 +5,41 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<ImageView <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:id="@+id/image"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="wrap_content"
android:scaleType="fitCenter" /> 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> </LinearLayout>

View File

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

View File

@ -26,6 +26,8 @@
<string name="news_header">News</string> <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> <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.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -20,6 +23,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.GridView; import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -33,15 +37,28 @@ public class AlbumListFragment extends Fragment
ArrayList<AlbumShortData> albumArr; ArrayList<AlbumShortData> albumArr;
ProgressBar progressBar;
public AlbumListFragment()
{
RestoreAlbumList();
}
public AlbumListFragment(ArrayList<AlbumShortData> albumArr)
{
this.albumArr = albumArr;
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 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); 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); gridView = (GridView) rootView.findViewById(R.id.gridView);
listAdapter = new ListAdapter(getActivity()); listAdapter = new ListAdapter(getActivity());
@ -62,6 +79,58 @@ public class AlbumListFragment extends Fragment
return rootView; 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();
}
}
public class ListAdapter extends BaseAdapter { public class ListAdapter extends BaseAdapter {

View File

@ -14,17 +14,24 @@ import org.osmdroid.views.MapView;
import fishrungames.bashgid.OsmMapHolderFragment.CustomItemizedOverlay; import fishrungames.bashgid.OsmMapHolderFragment.CustomItemizedOverlay;
import fishrungames.bashgid.OsmMapHolderFragment.NoInteractionOverlay; import fishrungames.bashgid.OsmMapHolderFragment.NoInteractionOverlay;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.LocationHolder; import fishrungames.bashgid.core.LocationHolder;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.ArticleManager.ArticleFullData; import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -35,6 +42,7 @@ import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -86,6 +94,9 @@ public class ArticleFragment extends Fragment
ListView listView; ListView listView;
ListAdapter listAdapter; ListAdapter listAdapter;
ProgressBar progressBar;
String articleName; String articleName;
ArticleFullData article; ArticleFullData article;
ArrayList<ArticleLayoutElement> articleLayout = new ArrayList<ArticleLayoutElement>(); ArrayList<ArticleLayoutElement> articleLayout = new ArrayList<ArticleLayoutElement>();
@ -100,6 +111,14 @@ public class ArticleFragment extends Fragment
{ {
this.articleName = articleName; this.articleName = articleName;
RestoreArticle(); RestoreArticle();
ReloadLayout();
}
public ArticleFragment(ArticleFullData article)
{
this.articleName = article.name;
this.article = article;
ReloadLayout();
} }
@Override @Override
@ -110,10 +129,21 @@ public class ArticleFragment extends Fragment
public void RestoreArticle() 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(); articleLayout.clear();
if (article != null)
{
articleLayout.add(new ArticleLayoutElement(0, article.title)); articleLayout.add(new ArticleLayoutElement(0, article.title));
PhotoRecordData zeroPhoto = null; PhotoRecordData zeroPhoto = null;
@ -152,6 +182,18 @@ public class ArticleFragment extends Fragment
} }
} }
}
public void SetArticle(ArticleFullData article)
{
progressBar.setVisibility(View.GONE);
this.article = article;
ReloadLayout();
listAdapter.notifyDataSetChanged();
}
@Override @Override
@ -160,10 +202,16 @@ public class ArticleFragment extends Fragment
if (savedInstanceState != null) { if (savedInstanceState != null) {
articleName = savedInstanceState.getString("articleName"); articleName = savedInstanceState.getString("articleName");
RestoreArticle(); RestoreArticle();
ReloadLayout();
} }
View rootView = inflater.inflate(R.layout.fragment_article_page, container, false); 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); listView = (ListView) rootView.findViewById(R.id.listView);
listAdapter = new ListAdapter(getActivity()); listAdapter = new ListAdapter(getActivity());
@ -173,6 +221,38 @@ public class ArticleFragment extends Fragment
return rootView; 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 { public class ListAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
@ -249,6 +329,10 @@ public class ArticleFragment extends Fragment
textView.setText(articleLayout.get(position).value); textView.setText(articleLayout.get(position).value);
textView.setTextSize(24);
textView.setTypeface(null, Typeface.BOLD);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
} }
else if (getItemViewType(position) == 1) else if (getItemViewType(position) == 1)
{ {
@ -256,6 +340,10 @@ public class ArticleFragment extends Fragment
textView.setText(articleLayout.get(position).value); textView.setText(articleLayout.get(position).value);
textView.setTextSize(12);
textView.setTypeface(null, Typeface.NORMAL);
textView.setGravity(Gravity.LEFT);
} }
else if (getItemViewType(position) == 2) else if (getItemViewType(position) == 2)
{ {
@ -301,6 +389,15 @@ public class ArticleFragment extends Fragment
} }
else if (getItemViewType(position) == 4) 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 hListView = (HListView) view.findViewById(R.id.hListView);
hListView.setAdapter(new MainPageHListViewAdapters.PhotoAlbumElementAdapter(getActivity(), article.albumArr.get(articleLayout.get(position).albumPos))); hListView.setAdapter(new MainPageHListViewAdapters.PhotoAlbumElementAdapter(getActivity(), article.albumArr.get(articleLayout.get(position).albumPos)));
@ -319,20 +416,6 @@ 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) 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.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -15,10 +18,14 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import fishrungames.bashgid.core.AlbumManager; import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.DatabaseGetJournalTask;
import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
@ -29,6 +36,7 @@ public class JournalFragment extends Fragment
String journalName; String journalName;
ListAdapter listAdapter; ListAdapter listAdapter;
ProgressBar progressBar;
public JournalFragment() public JournalFragment()
{ {
@ -42,6 +50,12 @@ public class JournalFragment extends Fragment
RestoreJournal(); RestoreJournal();
} }
public JournalFragment(JournalSemiFullData journal)
{
this.journalName = journal.name;
this.journal = journal;
}
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -59,6 +73,11 @@ public class JournalFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false); 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()); listAdapter = new ListAdapter(getActivity());
ListView listView = (ListView) rootView.findViewById(R.id.listView); ListView listView = (ListView) rootView.findViewById(R.id.listView);
@ -69,20 +88,51 @@ public class JournalFragment extends Fragment
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
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); MainActivity.getInstance().OpenArticleScreen(journal.articleArr.get(position).name, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
} }
}
}); });
return rootView; return rootView;
} }
void RestoreJournal() 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 { public class ListAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
@ -125,12 +175,15 @@ public class JournalFragment extends Fragment
dateTextView.setText(journal.articleArr.get(position).dateTime.toString()); dateTextView.setText(journal.articleArr.get(position).dateTime.toString());
if (journal.previewImageArr.get(position) != null)
{
ImageView imageView = (ImageView) view.findViewById(R.id.imageView); 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; return view;
} }

View File

@ -8,13 +8,18 @@ import java.util.Locale;
import fishrungames.bashgid.core.AlbumManager; import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
import fishrungames.bashgid.core.ArticleManager; import fishrungames.bashgid.core.ArticleManager;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.BookManager.BookRecord; 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.HtmlDownloadManager.TextFileRecord;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsDownloadTask; import fishrungames.bashgid.core.NewsDownloadTask;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
@ -42,7 +47,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -61,6 +65,12 @@ 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_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_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";
@ -75,8 +85,48 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
public static final int NEWS_DOWNLOADER_STATE_UPDATE = 10; public static final int NEWS_DOWNLOADER_STATE_UPDATE = 10;
public static final int NEWS_DOWNLOADER_STATE_FINISHED = 11; 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; MainPageFragment mainPageFragment = null;
NewsListFragment newsListFragment = 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; static MainActivity instance = null;
@ -101,6 +151,8 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ImageManager.getInstance().PredefinedImageId.put("R.drawable.no_picture", R.drawable.no_picture);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
SetupDrawer(); SetupDrawer();
@ -144,6 +196,48 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
case NEWS_DOWNLOADER_STATE_FINISHED: case NEWS_DOWNLOADER_STATE_FINISHED:
UpdateOnNewsDownloaded(); UpdateOnNewsDownloaded();
break; 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: default:
super.handleMessage(inputMessage); 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")); albumDataSource.CreateNewAlbum(new AlbumRecordData("TEST", "Vk Photos", "Wow"));
@ -196,8 +271,9 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
0, 0,
0), "TEST"); 0), "TEST");
AlbumManager.DownloadAndAddPhotoToAlbum(new PhotoRecordData( AlbumManager.DownloadAndAddPhotoToAlbum(new PhotoRecordData(
"Vlad", "Vlad 2",
"Vlad's photo", "Vlad's photo",
"http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg", "http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg",
"", "",
@ -205,13 +281,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
0 0
), "TEST"); ), "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( articleDataSource.CreateNewArticle(new ArticleRecordData(
"TESTART", "TESTART",
0, 0,
@ -225,9 +294,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
articleDataSource.AddAlbumToArticle("TEST", "TESTART"); articleDataSource.AddAlbumToArticle("TEST", "TESTART");
AlbumManager.AddExistingArticleToJournal("TESTART", "news"); //AlbumManager.AddExistingArticleToJournal("TESTART", "news");
AlbumManager.AddExistingArticleToJournal("TESTART", "map");
AlbumManager.AddExistingArticleToJournal("TESTART", "investor");
AlbumManager.AddNewVideoToChannel(new VideoRecordData( AlbumManager.AddNewVideoToChannel(new VideoRecordData(
VideoManager.VIDEO_TYPE_YOUTUBE, VideoManager.VIDEO_TYPE_YOUTUBE,
"http://www.youtube.com/watch?v=dQw4w9WgXcQ", "http://www.youtube.com/watch?v=dQw4w9WgXcQ",
@ -245,17 +318,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
0, 0,
"http://fishrungames.ru", "http://fishrungames.ru",
articleTestDate2 articleTestDate2
), "news"); ), "investor");
//articleDataSource.AddAlbumToArticle("TEST", "testArticle2"); //articleDataSource.AddAlbumToArticle("TEST", "testArticle2");
//articleDataSource.AddChannelToArticle("main", "testArticle2"); //articleDataSource.AddChannelToArticle("main", "testArticle2");
ArrayList<ArticleShortData> fullData = journalDataSource.GetRecentArticles("news", 2); DownloadDatabase();
for (ArticleShortData d : fullData)
{
Log.e("sss", d.title);
}
} }
@ -305,10 +373,33 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
this.DownloadImageArr(new String []{imageUrl}, new String []{imageHash}); this.DownloadImageArr(new String []{imageUrl}, new String []{imageHash});
} }
public void DownloadDatabase()
{
DatabaseDownloadTask task = new DatabaseDownloadTask();
task.mHandler = mHandler;
task.execute();
}
public void ClearAllFragmentLinks() public void ClearAllFragmentLinks()
{ {
mainPageFragment = null; mainPageFragment = null;
newsListFragment = 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) public void StartDownloadImagesTask(ArrayList<String> imageUrlArr, ArrayList<String> imageHashArr)
@ -337,12 +428,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
if (mainPageFragment != null) if (mainPageFragment != null)
{ {
mainPageFragment.RefreshHeader(); mainPageFragment.RefreshJournal();
} }
if (newsListFragment != null) if (newsListFragment != null)
{ {
newsListFragment.RefreshNewsList(); newsListFragment.RefreshJournal();
} }
} }
@ -350,15 +441,115 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
if (mainPageFragment != null) if (mainPageFragment != null)
{ {
mainPageFragment.RefreshHeader(); mainPageFragment.RefreshJournal();
} }
if (newsListFragment != null) 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) public void OnSelectEnglish(View view)
{ {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
@ -416,7 +607,6 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
StartDownloadNewsTask();
} }
public void OpenNewsScreen() public void OpenNewsScreen()
@ -432,14 +622,27 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
} }
public void OpenJournalScreen(String journalName) public void OpenCatalogScreen()
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
JournalFragment journal = new JournalFragment(journalName); catalogFragment = new CatalogFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, journal).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, catalogFragment).commit();
mNavigationDrawerFragment.EnableDrawer();
}
public void OpenJournalScreen(String journalName, String tag)
{
ClearAllFragmentLinks();
journalFragment = new JournalFragment(journalName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, journalFragment, tag).commit();
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
@ -482,13 +685,12 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
public void OpenMapScreen() public void OpenMapScreen(String filter)
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
// getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment = new OsmMapHolderFragment(filter);
// new MapHolderFragment(), TAG_TO_MAINFRAGMENT).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapHolderFragment, TAG_TO_MAINFRAGMENT).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OsmMapHolderFragment("news"), TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
@ -506,7 +708,9 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AlbumListFragment(), TAG_TO_MAINFRAGMENT).commit(); albumListFragment = new AlbumListFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, albumListFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
@ -515,7 +719,9 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PhotoAlbumFragment(albumName), TAG_TO_MAINFRAGMENT).commit(); photoAlbumFragment = new PhotoAlbumFragment(albumName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, photoAlbumFragment, TAG_TO_MAINFRAGMENT).commit();
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
@ -525,7 +731,20 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
ClearAllFragmentLinks(); ClearAllFragmentLinks();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PhotoFragment(albumName, position), tag).commit(); photoFragment = new PhotoFragment(albumName, position);
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(); mNavigationDrawerFragment.EnableDrawer();
} }
@ -541,7 +760,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks(); ClearAllFragmentLinks();
NewsRecordFragment newsRecordFragment = new NewsRecordFragment(articleName); newsRecordFragment = new NewsRecordFragment(articleName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsRecordFragment, tag).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsRecordFragment, tag).commit();
@ -553,7 +772,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks(); ClearAllFragmentLinks();
ArticleFragment articleFragment = new ArticleFragment(articleName); articleFragment = new ArticleFragment(articleName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, articleFragment, tag).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, articleFragment, tag).commit();
@ -599,19 +818,18 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
mNavigationDrawerFragment.EnableDrawer(); mNavigationDrawerFragment.EnableDrawer();
} }
// TAG_FROM_VIDEOLISTFRAGMENT_TO_VIDEORECORDFRAGMENT
public void OpenVideoListScreen(String channelName) public void OpenVideoListScreen(String channelName)
{ {
ClearAllFragmentLinks(); 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(); mNavigationDrawerFragment.EnableDrawer();
} }
public void OpenVideoRecordScreen(String videoUrl, String tag) public void OpenVideoRecordScreen(VideoRecordData video, String tag)
{ {
// Xperimental -- addToBackStack provoke error "Class not found". Need // Xperimental -- addToBackStack provoke error "Class not found". Need
// to resolve somehow! // to resolve somehow!
@ -622,7 +840,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
ClearAllFragmentLinks(); ClearAllFragmentLinks();
VideoRecordFragment videoRecordFragment = new VideoRecordFragment(videoUrl); videoRecordFragment = new VideoRecordFragment(video);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, videoRecordFragment, tag).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, videoRecordFragment, tag).commit();
@ -633,7 +851,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
{ {
if (mainPageFragment != null) if (mainPageFragment != null)
{ {
mainPageFragment.RefreshHeader(); mainPageFragment.RefreshJournal();
} }
} }
@ -700,21 +918,30 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
} else if (position == 2) } else if (position == 2)
{ {
OpenNewsScreen(); OpenNewsScreen();
}
else if (position == 3)
{
OpenCatalogScreen();
} else if (position == 4) } else if (position == 4)
{ {
OpenMapScreen(); OpenMapScreen("map");
} else if (position == 5) } else if (position == 5)
{ {
OpenVideoListScreen("main"); OpenVideoListScreen("main");
} else if (position == 6) } else if (position == 6)
{ {
OpenPhotoAlbumListScreen(); OpenPhotoAlbumListScreen();
//OpenPhotoAlbumScreen(albumDataSource.GetAlbumFullData("TEST")); }
else if (position == 7)
} else if (position == 7)
{ {
OpenBooksScreen(); OpenBooksScreen();
} else if (position == 9) }
else if (position == 8)
{
OpenJournalScreen("investor", MainActivity.TAG_TO_MAINFRAGMENT);
}
else if (position == 9)
{ {
OpenSettingsScreen(); OpenSettingsScreen();
} }
@ -770,6 +997,26 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
OpenArticleScreen(GetLastArticleName(), TAG_TO_MAINFRAGMENT); OpenArticleScreen(GetLastArticleName(), TAG_TO_MAINFRAGMENT);
return; 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) if (getSupportFragmentManager().findFragmentByTag(TAG_TO_SEARCHFRAGMENT) != null)
{ {
@ -785,9 +1032,11 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
return; return;
} }
if (getSupportFragmentManager().findFragmentByTag(TAG_TO_MAPFRAGMENT) != null) if (getSupportFragmentManager().findFragmentByTag(TAG_TO_MAPFRAGMENT) != null)
{ {
OpenMapScreen(); OpenMapScreen("map");
return; return;
} }
@ -832,6 +1081,21 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
return settings.getString("lastArticleName", ""); 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 @Override
protected void onResume() protected void onResume()
{ {

View File

@ -7,7 +7,10 @@ import fishrungames.networkutils.ImageManager;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData; 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.NewsManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsManager.NewsRecord; import fishrungames.bashgid.core.NewsManager.NewsRecord;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -23,6 +26,7 @@ import android.widget.BaseAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import it.sephiroth.android.library.widget.HListView; import it.sephiroth.android.library.widget.HListView;
@ -37,6 +41,9 @@ public class MainPageFragment extends Fragment {
ListView listView; ListView listView;
ListAdapter listAdapter; ListAdapter listAdapter;
View header; View header;
ProgressBar progressBar;
JournalSemiFullData newsJournal;
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
@Override @Override
@ -47,14 +54,20 @@ public class MainPageFragment extends Fragment {
listAdapter = new ListAdapter(getActivity()); listAdapter = new ListAdapter(getActivity());
listView.setAdapter(listAdapter);
header = inflater.inflate(R.layout.main_page_header, null); header = inflater.inflate(R.layout.main_page_header, null);
RefreshHeader(); RestoreJournal();
MainActivity.getInstance().StartDownloadNewsTask();
listView.addHeaderView(header); 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); Button moreNewsButton = (Button) header.findViewById(R.id.moreNewsButton);
moreNewsButton.setOnClickListener(new OnClickListener() moreNewsButton.setOnClickListener(new OnClickListener()
@ -72,9 +85,33 @@ public class MainPageFragment extends Fragment {
} }
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 news1ImageButton = (ImageButton) header.findViewById(R.id.news1ImageButton);
ImageButton news2ImageButton = (ImageButton) header.findViewById(R.id.news2ImageButton); 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 news2Button = (Button)header.findViewById(R.id.news2Button);
Button news3Button = (Button)header.findViewById(R.id.news3Button); Button news3Button = (Button)header.findViewById(R.id.news3Button);
if (newsJournal.articleArr.size() > 0)
ArrayList<ArticleShortData> newsRecordArr = MainActivity.getInstance().journalDataSource.GetRecentArticles("news", 3);
if (newsRecordArr.size() > 0)
{ {
ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsRecordArr.get(0).previewImageUrl); ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsJournal.articleArr.get(0).previewImageUrl);
news1Button.setText(newsRecordArr.get(0).title); news1Button.setText(newsJournal.articleArr.get(0).title);
news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name)); news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name));
news1Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name)); news1Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(0).name));
} }
else else
{ {
@ -104,12 +137,12 @@ public class MainPageFragment extends Fragment {
news1Button.setOnClickListener(null); news1Button.setOnClickListener(null);
} }
if (newsRecordArr.size() > 1) if (newsJournal.articleArr.size() > 1)
{ {
ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsRecordArr.get(1).previewImageUrl); ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsJournal.articleArr.get(1).previewImageUrl);
news2Button.setText(newsRecordArr.get(1).title); news2Button.setText(newsJournal.articleArr.get(1).title);
news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name)); news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name));
news2Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name)); news2Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(1).name));
} }
else else
{ {
@ -119,12 +152,12 @@ public class MainPageFragment extends Fragment {
news2Button.setOnClickListener(null); news2Button.setOnClickListener(null);
} }
if (newsRecordArr.size() > 2) if (newsJournal.articleArr.size() > 2)
{ {
ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsRecordArr.get(2).previewImageUrl); ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsJournal.articleArr.get(2).previewImageUrl);
news3Button.setText(newsRecordArr.get(2).title); news3Button.setText(newsJournal.articleArr.get(2).title);
news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name)); news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name));
news3Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name)); news3Button.setOnClickListener(new NewsButtonOnClickListener(newsJournal.articleArr.get(2).name));
} }
else else
{ {
@ -166,6 +199,7 @@ public class MainPageFragment extends Fragment {
View view; View view;
if (convertView == null) { // if it's not recycled, initialize some attributes if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.main_page_list_element, null); 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.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.HtmlDownloadManager; import fishrungames.bashgid.core.HtmlDownloadManager;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord; import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
@ -64,14 +65,14 @@ public class MainPageHListViewAdapters {
view = convertView; 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); //TextView subTextView = (TextView) view.findViewById(R.id.subTextView);
//ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton); //ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView); ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
textView.setText(albumFullData.photoRecordArr.get(position).title); //textView.setText(albumFullData.photoRecordArr.get(position).title);
//subTextView.setText(""); //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 { public static class SimpleElementAdapter extends BaseAdapter {
private Context mContext; 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.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.JournalManager.JournalSemiFullData;
import fishrungames.bashgid.core.NewsManager.NewsRecord; import fishrungames.bashgid.core.NewsManager.NewsRecord;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -18,6 +28,7 @@ import android.widget.BaseAdapter;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
@ -31,21 +42,38 @@ public class NewsListFragment extends Fragment
JournalSemiFullData journal; JournalSemiFullData journal;
ProgressBar progressBar;
TextView footerTextView;
@SuppressLint("InflateParams") @Override @SuppressLint("InflateParams") @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RestoreJournal();
View rootView = inflater.inflate(R.layout.fragment_news_page, container, false); View rootView = inflater.inflate(R.layout.fragment_news_page, container, false);
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news");
listView = (ListView) rootView.findViewById(R.id.listView); 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()); listAdapter = new ListAdapter(getActivity());
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
View header = inflater.inflate(R.layout.news_page_list_header, null);
listView.addHeaderView(header);
listView.setOnItemClickListener(new OnItemClickListener(){ listView.setOnItemClickListener(new OnItemClickListener(){
@ -53,10 +81,17 @@ public class NewsListFragment extends Fragment
public void onItemClick(AdapterView<?> parent, View view, int position, long id) public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{ {
//Add position + 1, because first element of list is always title //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; return rootView;
} }
void RestoreJournal()
public void RefreshNewsList()
{ {
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData("news"); 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(); listAdapter.notifyDataSetChanged();
} }
public class ListAdapter extends BaseAdapter { public class ListAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
@ -114,12 +206,18 @@ public class NewsListFragment extends Fragment
dateTextView.setText(journal.articleArr.get(position).dateTime.toString()); dateTextView.setText(journal.articleArr.get(position).dateTime.toString());
if (journal.previewImageArr.get(position) != null)
{
ImageView imageView = (ImageView) view.findViewById(R.id.imageView); 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; return view;
} }
@ -127,22 +225,4 @@ public class NewsListFragment extends Fragment
} }
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,32 +13,28 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
public class NewsRecordFragment extends Fragment public class NewsRecordFragment extends ArticleFragment
{ {
String articleName; TextView titleTextView;
ArticleFullData articleData; WebView webView;
public NewsRecordFragment() public NewsRecordFragment()
{ {
this.articleName = ""; super();
this.articleData = null;
} }
public NewsRecordFragment(String articleName) public NewsRecordFragment(String articleName)
{ {
this.articleName = articleName; super(articleName);
RestoreArticle();
} }
@Override public NewsRecordFragment(ArticleFullData article)
public void onSaveInstanceState(final Bundle outState) { {
super.onSaveInstanceState(outState); super(article);
outState.putString("articleName", articleName);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 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); View rootView = inflater.inflate(R.layout.fragment_news_record_page, container, false);
TextView titleTextView = (TextView) rootView.findViewById(R.id.titleTextView); titleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
titleTextView.setText(articleData.title);
//ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView); webView = (WebView) rootView.findViewById(R.id.webView);
//ImageManager.getInstance().ApplyImageToImageView(imageView, articleData.);
WebView webView = (WebView) rootView.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(false); webView.getSettings().setJavaScriptEnabled(false);
String htmlCode = "<html><body>" + articleData.content + "</body></html>";
webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);
return rootView; 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.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import org.osmdroid.DefaultResourceProxyImpl; import org.osmdroid.DefaultResourceProxyImpl;
@ -30,6 +31,8 @@ import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.OverlayItem.HotspotPlace; import org.osmdroid.views.overlay.OverlayItem.HotspotPlace;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; 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.LocationHolder;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData; import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
@ -42,9 +45,11 @@ public class OsmMapHolderFragment extends Fragment
private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>(); private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();
private ArrayList<String> mArticles = new ArrayList<String>(); private ArrayList<String> mArticles = new ArrayList<String>();
String journalName;
public CustomItemizedOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) { public CustomItemizedOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy, String journalName) {
super(pDefaultMarker, pResourceProxy); super(pDefaultMarker, pResourceProxy);
this.journalName = journalName;
} }
@Override @Override
@ -97,7 +102,8 @@ public class OsmMapHolderFragment extends Fragment
dialog.setPositiveButton("Open", new DialogInterface.OnClickListener() { dialog.setPositiveButton("Open", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), null); MainActivity.getInstance().SetLastMapFilterName(journalName);
MainActivity.getInstance().OpenArticleScreen(mArticles.get(index), MainActivity.TAG_FROM_MAPFRAGMENT_TO_ARTICLEFRAGMENT);
} }
}); });
@ -185,6 +191,8 @@ public class OsmMapHolderFragment extends Fragment
} }
MapView mapView;
TextView textView;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -196,7 +204,11 @@ public class OsmMapHolderFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_osm_map_page, container, false); 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.setMaxZoomLevel(20);
mapView.setMinZoomLevel(4); mapView.setMinZoomLevel(4);
@ -207,21 +219,53 @@ public class OsmMapHolderFragment extends Fragment
IMapController mapController = mapView.getController(); IMapController mapController = mapView.getController();
GeoPoint center = new GeoPoint(LocationHolder.CONST_UFA_LATITUDE, LocationHolder.CONST_UFA_LONGITUDE); GeoPoint center = new GeoPoint(LocationHolder.CONST_UFA_LATITUDE, LocationHolder.CONST_UFA_LONGITUDE);
mapController.setZoom(10); mapController.setZoom(10);
mapController.animateTo(center); mapController.animateTo(center);
RefreshView();
return rootView;
}
void RestoreJournal()
{
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()); ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getActivity());
itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy); itemizedOverlay = new CustomItemizedOverlay(getResources().getDrawable(R.drawable.russia_icon), resourceProxy, journalName);
//JournalSemiFullData journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName);
for (int i = 0; i < journal.articleArr.size(); i++) for (int i = 0; i < journal.articleArr.size(); i++)
//for (ArticleRecordData article : journal.articleArr)
{ {
ArticleRecordData article = journal.articleArr.get(i); ArticleRecordData article = journal.articleArr.get(i);
@ -229,22 +273,17 @@ public class OsmMapHolderFragment extends Fragment
{ {
GeoPoint markerPoint = new GeoPoint(article.geoLat, article.geoLon); GeoPoint markerPoint = new GeoPoint(article.geoLat, article.geoLon);
itemizedOverlay.addOverlayItem(markerPoint, article.name, article.title, journal.articleArr.get(i).previewImageUrl);
itemizedOverlay.addOverlayItem(markerPoint, article.name, article.title, journal.previewImageArr.get(i));
} }
} }
//itemizedOverlay.addOverlayItem(markerPoint); mapView.getOverlays().clear();
mapView.getOverlays().add(itemizedOverlay); mapView.getOverlays().add(itemizedOverlay);
return rootView; mapView.invalidate();
}
void RestoreJournal() }
{
journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName);
} }
} }

View File

@ -14,9 +14,11 @@ import android.widget.BaseAdapter;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import fishrungames.bashgid.core.AlbumManager; import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
@ -28,12 +30,20 @@ public class PhotoAlbumFragment extends Fragment
ListAdapter listAdapter; ListAdapter listAdapter;
ProgressBar progressBar;
public PhotoAlbumFragment() public PhotoAlbumFragment()
{ {
album = null; album = null;
albumName = ""; albumName = "";
} }
public PhotoAlbumFragment(AlbumFullData album)
{
this.album = album;
this.albumName = album.name;
}
public PhotoAlbumFragment(String albumName) public PhotoAlbumFragment(String albumName)
{ {
this.albumName = albumName; this.albumName = albumName;
@ -57,6 +67,10 @@ public class PhotoAlbumFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_photo_album_page, container, false); 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()); listAdapter = new ListAdapter(getActivity());
ListView listView = (ListView) rootView.findViewById(R.id.listView); ListView listView = (ListView) rootView.findViewById(R.id.listView);
@ -69,7 +83,7 @@ public class PhotoAlbumFragment extends Fragment
public void onItemClick(AdapterView<?> parent, View view, int position, long id) public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{ {
MainActivity.getInstance().SetLastAlbumName(albumName); 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() 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 { public class ListAdapter extends BaseAdapter {

View File

@ -1,14 +1,19 @@
package fishrungames.bashgid; package fishrungames.bashgid;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
public class PhotoFragment extends Fragment public class PhotoFragment extends Fragment
{ {
@ -18,6 +23,9 @@ public class PhotoFragment extends Fragment
int currentPhoto; int currentPhoto;
PhotoFragmentAdapter listAdapter; PhotoFragmentAdapter listAdapter;
ViewPager pager;
ProgressBar progressBar;
public PhotoFragment() public PhotoFragment()
{ {
@ -26,8 +34,16 @@ public class PhotoFragment extends Fragment
currentPhoto = -1; currentPhoto = -1;
} }
public PhotoFragment(AlbumFullData album, int currentPhoto)
{
this.album = album;
this.albumName = album.name;
this.currentPhoto = currentPhoto;
}
public PhotoFragment(String albumName, int currentPhoto) public PhotoFragment(String albumName, int currentPhoto)
{ {
this.album = null;
this.albumName = albumName; this.albumName = albumName;
this.currentPhoto = currentPhoto; this.currentPhoto = currentPhoto;
RestoreAlbum(); RestoreAlbum();
@ -53,9 +69,20 @@ public class PhotoFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_photo_page, container, false); View rootView = inflater.inflate(R.layout.fragment_photo_page, container, false);
listAdapter = new PhotoFragmentAdapter(getActivity(), album/*, currentPhoto*/); progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager); 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); pager.setAdapter(listAdapter);
@ -66,7 +93,29 @@ public class PhotoFragment extends Fragment
void RestoreAlbum() 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.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
public class PhotoFragmentAdapter extends PagerAdapter { public class PhotoFragmentAdapter extends PagerAdapter {
@ -44,11 +45,21 @@ public class PhotoFragmentAdapter extends PagerAdapter {
public Object instantiateItem(ViewGroup container, int position) { public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.photo_page_element, container, View viewLayout = inflater.inflate(R.layout.photo_page_element, container,
false); 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); ImageView image = (ImageView) viewLayout.findViewById(R.id.image);
ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl); ImageManager.getInstance().ApplyImageToImageView(image, album.photoRecordArr.get(position).imageUrl);

View File

@ -2,13 +2,17 @@ package fishrungames.bashgid;
import fishrungames.bashgid.core.ChannelManager;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData; import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -18,6 +22,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.GridView; import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -28,6 +33,7 @@ public class VideoListFragment extends Fragment
ListAdapter listAdapter; ListAdapter listAdapter;
GridView gridView; GridView gridView;
ProgressBar progressBar;
String channelName; String channelName;
ChannelFullData channelFullData; ChannelFullData channelFullData;
@ -44,6 +50,12 @@ public class VideoListFragment extends Fragment
RestoreChannel(); RestoreChannel();
} }
public VideoListFragment(ChannelFullData channelFullData)
{
this.channelName = channelFullData.name;
this.channelFullData = channelFullData;
}
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -61,6 +73,11 @@ public class VideoListFragment extends Fragment
View rootView = inflater.inflate(R.layout.fragment_video_page, container, false); 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); gridView = (GridView) rootView.findViewById(R.id.gridView);
listAdapter = new ListAdapter(getActivity()); listAdapter = new ListAdapter(getActivity());
@ -73,7 +90,7 @@ public class VideoListFragment extends Fragment
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) 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);
} }
}); });
@ -81,12 +98,61 @@ public class VideoListFragment extends Fragment
return rootView; return rootView;
} }
void RestoreChannel() 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 { public class ListAdapter extends BaseAdapter {
private Context mContext; private Context mContext;
@ -132,4 +198,6 @@ public class VideoListFragment extends Fragment
} }
} }
} }

View File

@ -1,19 +1,26 @@
package fishrungames.bashgid; package fishrungames.bashgid;
import fishrungames.bashgid.core.AlbumManager;
import fishrungames.bashgid.core.DatabaseGetAlbumTask;
import fishrungames.bashgid.core.VideoManager; import fishrungames.bashgid.core.VideoManager;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.bashgid.core.VideoManager.VideoRecordData; import fishrungames.bashgid.core.VideoManager.VideoRecordData;
import fishrungames.networkutils.ImageManager; import fishrungames.networkutils.ImageManager;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -24,6 +31,11 @@ public class VideoRecordFragment extends Fragment
VideoRecordData recordData; VideoRecordData recordData;
TextView nameTextView;
TextView descriptionTextView;
ImageView imageView;
ProgressBar progressBar;
public VideoRecordFragment() public VideoRecordFragment()
{ {
this.videoUrl = ""; this.videoUrl = "";
@ -32,10 +44,17 @@ public class VideoRecordFragment extends Fragment
public VideoRecordFragment(String videoUrl) public VideoRecordFragment(String videoUrl)
{ {
this.recordData = null;
this.videoUrl = videoUrl; this.videoUrl = videoUrl;
RestoreVideo(); RestoreVideo();
} }
public VideoRecordFragment(VideoRecordData recordData)
{
this.videoUrl = recordData.videoUrl;
this.recordData = recordData;
}
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(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); 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); nameTextView.setText(recordData.title);
TextView descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView);
descriptionTextView.setText(recordData.description); descriptionTextView.setText(recordData.description);
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
ImageManager.getInstance().ApplyImageToImageView(imageView, recordData.previewImageUrl); ImageManager.getInstance().ApplyImageToImageView(imageView, recordData.previewImageUrl);
imageView.setOnClickListener(new OnClickListener() imageView.setOnClickListener(new OnClickListener()
@ -69,19 +129,45 @@ public class VideoRecordFragment extends Fragment
{ {
if (recordData.type == VideoManager.VIDEO_TYPE_YOUTUBE) 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>
{ {
VideoRecordData recordData = null;
public Handler mHandler;
protected Long doInBackground(String... queryArr)
{
String videoUrl = queryArr[0];
recordData = MainActivity.getInstance().videoDataSource.GetVideoByVideoUrl(videoUrl); 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) public static void DownloadAndAddPhoto(PhotoRecordData recordData)
{ {

View File

@ -2,11 +2,13 @@ package fishrungames.bashgid.core;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.ChannelManager.ChannelFullData; import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;
public class ArticleManager public class ArticleManager
{ {
@ -89,4 +91,16 @@ public class ArticleManager
//channelArr = new ArrayList<ChannelFullData>(); //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.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData; import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
@ -54,6 +56,14 @@ public class ChannelManager
this.id = id; this.id = id;
} }
} }
public static ChannelFullData CreateEmptyChannel()
{
ChannelFullData result = new ChannelFullData(new ChannelRecordData("", "", ""));
return result;
}
/* /*
public static void DownloadAndAddPhoto(PhotoRecordData recordData) 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; package fishrungames.bashgid.core;
import java.util.ArrayList; 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.ArticleFullData;
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData; import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.NewsManager.NewsRecord;
public class JournalManager public class JournalManager
@ -34,14 +39,14 @@ public class JournalManager
public static class JournalSemiFullData extends JournalRecordData public static class JournalSemiFullData extends JournalRecordData
{ {
public ArrayList<ArticleRecordData> articleArr; public ArrayList<ArticleShortData> articleArr;
public ArrayList<String> previewImageArr; //public ArrayList<String> previewImageArr;
public JournalSemiFullData(JournalRecordData copyFrom) public JournalSemiFullData(JournalRecordData copyFrom)
{ {
super(copyFrom); super(copyFrom);
articleArr = new ArrayList<ArticleRecordData>(); articleArr = new ArrayList<ArticleShortData>();
previewImageArr = new ArrayList<String>(); //previewImageArr = new ArrayList<String>();
} }
} }
@ -59,5 +64,12 @@ public class JournalManager
} }
public static JournalSemiFullData CreateEmptyJournal()
{
JournalSemiFullData result = new JournalSemiFullData(new JournalRecordData("", "", ""));
return result;
}
} }

View File

@ -1,17 +1,12 @@
package fishrungames.bashgid.core; package fishrungames.bashgid.core;
import java.util.ArrayList;
import java.util.Collections;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import fishrungames.bashgid.MainActivity; 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> 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) 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++) for (int i = 0; i < NewsManager.urlArr.length; i++)
{ {

View File

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

View File

@ -1,5 +1,8 @@
package fishrungames.bashgid.core; package fishrungames.bashgid.core;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
public class VideoManager public class VideoManager
{ {
public static final int VIDEO_TYPE_YOUTUBE = 1; 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); database.insert(BashgidSqliteHelper.TABLE_ALBUM, null, values);
} else } else
{ {
// Replace database.update(BashgidSqliteHelper.TABLE_ALBUM, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
} }
} finally } finally

View File

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

View File

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

View File

@ -7,6 +7,8 @@ import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.AlbumManager.AlbumFullData; import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData; 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.ArticleManager.ArticleShortData;
import fishrungames.bashgid.core.JournalManager; import fishrungames.bashgid.core.JournalManager;
import fishrungames.bashgid.core.JournalManager.JournalRecordData; import fishrungames.bashgid.core.JournalManager.JournalRecordData;
@ -51,6 +53,7 @@ public class JournalDataSource
} else } else
{ {
// Replace // Replace
database.update(BashgidSqliteHelper.TABLE_JOURNAL, values, BashgidSqliteHelper.COLUMN_NAME + " = " +"\"" + recordData.name +"\"", null);
} }
} finally } finally
@ -100,11 +103,11 @@ public class JournalDataSource
if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database)) if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database))
{ {
Log.e("a", "aaa1"); //Log.e("a", "aaa1");
database.insert(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, null, values); 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 } finally
{ {
@ -156,6 +159,16 @@ public class JournalDataSource
} }
public JournalSemiFullData GetJournalSemiFullData(String name) 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; JournalSemiFullData result = null;
@ -166,7 +179,7 @@ public class JournalDataSource
try try
{ {
result = InnerGetJournalSemiFullData(name, database); result = InnerGetJournalSemiFullData(name, database, startAfterArticleName, count);
} finally } finally
{ {
@ -177,25 +190,42 @@ public class JournalDataSource
return result; 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
{ {
JournalSemiFullData result = null; Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME,
BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null);
JournalRecordData recordData = innerGetJournalByName(name, database); if (cursor != null)
{
if (recordData != null) if (cursor.moveToFirst())
{ {
result = new JournalSemiFullData(recordData); do
ArrayList<String> articleArr = innerGetArticleArrInJournal(name, database); {
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) for (String article : articleArr)
{ {
result.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database)); journal.articleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database));
String imageUrl = null; /*
String imageUrl = "R.drawable.no_picture";
//Find first photo in first album (if exist) //Find first photo in first album (if exist)
ArrayList<String> albumArr = MainActivity.getInstance().articleDataSource.innerGetAlbumNameArrInArticle(article, database); ArrayList<String> albumArr = MainActivity.getInstance().articleDataSource.innerGetAlbumNameArrInArticle(article, database);
@ -209,17 +239,86 @@ public class JournalDataSource
} }
} }
result.previewImageArr.add(imageUrl); journal.previewImageArr.add(imageUrl);*/
} }
/*
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(name, database);
for (String imageUrl : imageUrlArr)
result.add(journal);
}
} while (cursor.moveToNext());
}
}
}
finally
{ {
result.photoRecordArr.add(MainActivity.getInstance().photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database)); 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)
{
intermediateArticleArr.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(article, database));
}
Collections.sort(intermediateArticleArr, new ArticleManager.ArticleShortDataTimeSortComparator());
boolean articleCanGo = false;
if (startAfterArticleName == null || startAfterArticleName.length() == 0)
{
articleCanGo = true;
}
int i = 0;
for (ArticleShortData article : intermediateArticleArr)
{
if (!articleCanGo)
{
if (article.name.equals(startAfterArticleName))
{
articleCanGo = true;
}
}
else
{
if (count == 0 || i < count)
{
result.articleArr.add(article);
i++;
}
}
}
} }
return result; return result;

View File

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

View File

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