new system
This commit is contained in:
parent
e882bf6e05
commit
5fd5dd703b
android/src/fishrungames/bashgid
@ -1,6 +1,8 @@
|
||||
package fishrungames.bashgid;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import fishrungames.bashgid.core.AlbumManager;
|
||||
@ -11,6 +13,8 @@ import fishrungames.bashgid.core.ArticleManager;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
|
||||
import fishrungames.bashgid.core.BookManager.BookRecord;
|
||||
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||
import fishrungames.bashgid.core.HtmlDownloadManager.TextFileRecord;
|
||||
import fishrungames.bashgid.core.NewsDownloadTask;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
@ -37,6 +41,7 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@ -124,11 +129,11 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
{
|
||||
case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_UPDATE:
|
||||
case ImageDownloadTask.IMAGE_DOWNLOADER_STATE_FINISHED:
|
||||
//UpdateOnImageDownloaded();
|
||||
UpdateOnImageDownloaded();
|
||||
break;
|
||||
case NEWS_DOWNLOADER_STATE_UPDATE:
|
||||
case NEWS_DOWNLOADER_STATE_FINISHED:
|
||||
//UpdateOnNewsDownloaded();
|
||||
UpdateOnNewsDownloaded();
|
||||
break;
|
||||
default:
|
||||
super.handleMessage(inputMessage);
|
||||
@ -160,14 +165,27 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
*/
|
||||
albumDataSource.CreateNewAlbum(new AlbumRecordData("TEST", "Vk Photos", "Wow"));
|
||||
|
||||
|
||||
Date articleTestDate = new Date();
|
||||
Date articleTestDate2 = new Date();
|
||||
|
||||
try
|
||||
{
|
||||
articleTestDate = ArticleManager.iso8601Format.parse("2015-05-30 9:00:00");
|
||||
articleTestDate2 = ArticleManager.iso8601Format.parse("2015-05-30 9:30:00");
|
||||
} catch (ParseException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
AlbumManager.DownloadAndAddPhotoToAlbum(new PhotoRecordData(
|
||||
"Lilia",
|
||||
"Lilia photo",
|
||||
"http://pp.vk.me/c622725/v622725384/3290f/hfnoyPHe5y8.jpg",
|
||||
"",
|
||||
0,
|
||||
0
|
||||
), "TEST");
|
||||
0), "TEST");
|
||||
|
||||
AlbumManager.DownloadAndAddPhotoToAlbum(new PhotoRecordData(
|
||||
"Vlad",
|
||||
@ -178,6 +196,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
0
|
||||
), "TEST");
|
||||
|
||||
PhotoRecordData photo = photoDataSource.GetPhotoByImageUrl("http://pp.vk.me/c623226/v623226718/2af84/NeEYYIlnR-I.jpg");
|
||||
|
||||
if (photo != null)
|
||||
{
|
||||
Log.e("aaa", "xxx");
|
||||
}
|
||||
|
||||
articleDataSource.CreateNewArticle(new ArticleRecordData(
|
||||
"TESTART",
|
||||
0,
|
||||
@ -185,9 +210,13 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
"Wow 2 photos",
|
||||
0,
|
||||
0,
|
||||
""));
|
||||
"",
|
||||
articleTestDate
|
||||
));
|
||||
|
||||
articleDataSource.AddAlbumToArticle("TEST", "TESTART");
|
||||
//articleDataSource.AddAlbumToArticle("TEST", "TESTART");
|
||||
|
||||
AlbumManager.AddExistingArticleToJournal("TESTART", "news");
|
||||
|
||||
|
||||
AlbumManager.AddNewVideoToChannel(new VideoRecordData(
|
||||
@ -196,8 +225,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
"Rickroll",
|
||||
"Mega Rickroll",
|
||||
"http://img.youtube.com/vi/dQw4w9WgXcQ/0.jpg",
|
||||
""
|
||||
), "main");
|
||||
""), "main");
|
||||
|
||||
AlbumManager.AddNewArticleToJournal(new ArticleRecordData(
|
||||
"testArticle2",
|
||||
@ -206,11 +234,19 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
"Wow content lol",
|
||||
0,
|
||||
0,
|
||||
"http://fishrungames.ru"
|
||||
), "main");
|
||||
"http://fishrungames.ru",
|
||||
articleTestDate2
|
||||
), "news");
|
||||
|
||||
articleDataSource.AddAlbumToArticle("TEST", "testArticle2");
|
||||
articleDataSource.AddChannelToArticle("main", "testArticle2");
|
||||
//articleDataSource.AddAlbumToArticle("TEST", "testArticle2");
|
||||
//articleDataSource.AddChannelToArticle("main", "testArticle2");
|
||||
|
||||
ArrayList<ArticleShortData> fullData = journalDataSource.GetRecentArticles("news", 2);
|
||||
|
||||
for (ArticleShortData d : fullData)
|
||||
{
|
||||
Log.e("sss", d.title);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -371,7 +407,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
|
||||
//StartDownloadNewsTask();
|
||||
StartDownloadNewsTask();
|
||||
}
|
||||
|
||||
public void OpenNewsScreen()
|
||||
@ -463,7 +499,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
mNavigationDrawerFragment.EnableDrawer();
|
||||
}
|
||||
|
||||
public void OpenNewsRecordScreen(NewsRecord newsRecord, String tag)
|
||||
public void OpenNewsRecordScreen(String articleName, String tag)
|
||||
{
|
||||
// Xperimental -- addToBackStack provoke error "Class not found". Need
|
||||
// to resolve somehow!
|
||||
@ -474,7 +510,7 @@ public class MainActivity extends ActionBarActivity implements NavigationDrawerF
|
||||
|
||||
ClearAllFragmentLinks();
|
||||
|
||||
NewsRecordFragment newsRecordFragment = new NewsRecordFragment(newsRecord);
|
||||
NewsRecordFragment newsRecordFragment = new NewsRecordFragment(articleName);
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, newsRecordFragment, tag).commit();
|
||||
|
||||
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
||||
import fishrungames.networkutils.ImageManager;
|
||||
|
||||
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||
import fishrungames.bashgid.core.NewsManager;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
|
||||
@ -83,15 +85,16 @@ public class MainPageFragment extends Fragment {
|
||||
Button news3Button = (Button)header.findViewById(R.id.news3Button);
|
||||
|
||||
|
||||
ArrayList<NewsManager.NewsRecord> newsRecordArr = NewsManager.getInstance().getNews();
|
||||
ArrayList<ArticleShortData> newsRecordArr = MainActivity.getInstance().journalDataSource.GetRecentArticles("news", 3);
|
||||
|
||||
|
||||
if (newsRecordArr.size() > 0)
|
||||
{
|
||||
ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsRecordArr.get(0).imageId);
|
||||
ImageManager.getInstance().ApplyImageToImageView(news1ImageButton, newsRecordArr.get(0).previewImageUrl);
|
||||
news1Button.setText(newsRecordArr.get(0).title);
|
||||
|
||||
news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0)));
|
||||
news1Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0)));
|
||||
news1ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name));
|
||||
news1Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(0).name));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -103,10 +106,10 @@ public class MainPageFragment extends Fragment {
|
||||
|
||||
if (newsRecordArr.size() > 1)
|
||||
{
|
||||
ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsRecordArr.get(1).imageId);
|
||||
ImageManager.getInstance().ApplyImageToImageView(news2ImageButton, newsRecordArr.get(1).previewImageUrl);
|
||||
news2Button.setText(newsRecordArr.get(1).title);
|
||||
news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1)));
|
||||
news2Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1)));
|
||||
news2ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name));
|
||||
news2Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(1).name));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -118,10 +121,10 @@ public class MainPageFragment extends Fragment {
|
||||
|
||||
if (newsRecordArr.size() > 2)
|
||||
{
|
||||
ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsRecordArr.get(2).imageId);
|
||||
ImageManager.getInstance().ApplyImageToImageView(news3ImageButton, newsRecordArr.get(2).previewImageUrl);
|
||||
news3Button.setText(newsRecordArr.get(2).title);
|
||||
news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2)));
|
||||
news3Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2)));
|
||||
news3ImageButton.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name));
|
||||
news3Button.setOnClickListener(new NewsButtonOnClickListener(newsRecordArr.get(2).name));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -193,17 +196,17 @@ public class MainPageFragment extends Fragment {
|
||||
public static class NewsButtonOnClickListener implements OnClickListener
|
||||
{
|
||||
|
||||
NewsRecord newsRecord;
|
||||
String articleName;
|
||||
|
||||
public NewsButtonOnClickListener(NewsRecord newsRecord)
|
||||
public NewsButtonOnClickListener(String articleName)
|
||||
{
|
||||
this.newsRecord = newsRecord;
|
||||
this.articleName = articleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
MainActivity.getInstance().OpenNewsRecordScreen(articleName, MainActivity.TAG_FROM_MAINFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class NewsListFragment extends Fragment
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
//MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_NEWSLISTFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package fishrungames.bashgid;
|
||||
|
||||
|
||||
import fishrungames.networkutils.ImageManager;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -16,34 +16,60 @@ import android.widget.TextView;
|
||||
public class NewsRecordFragment extends Fragment
|
||||
{
|
||||
|
||||
NewsRecord newsRecord;
|
||||
String articleName;
|
||||
|
||||
public NewsRecordFragment(NewsRecord newsRecord)
|
||||
ArticleFullData articleData;
|
||||
|
||||
public NewsRecordFragment()
|
||||
{
|
||||
this.newsRecord = newsRecord;
|
||||
this.articleName = "";
|
||||
this.articleData = null;
|
||||
}
|
||||
|
||||
public NewsRecordFragment(String articleName)
|
||||
{
|
||||
this.articleName = articleName;
|
||||
RestoreArticle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString("articleName", articleName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
articleName = savedInstanceState.getString("articleName");
|
||||
RestoreArticle();
|
||||
}
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_news_record_page, container, false);
|
||||
|
||||
TextView titleTextView = (TextView) rootView.findViewById(R.id.titleTextView);
|
||||
titleTextView.setText(newsRecord.title);
|
||||
|
||||
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
|
||||
ImageManager.getInstance().ApplyImageToImageView(imageView, newsRecord.imageId);
|
||||
titleTextView.setText(articleData.title);
|
||||
|
||||
//ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
|
||||
//ImageManager.getInstance().ApplyImageToImageView(imageView, articleData.);
|
||||
|
||||
WebView webView = (WebView) rootView.findViewById(R.id.webView);
|
||||
|
||||
webView.getSettings().setJavaScriptEnabled(false);
|
||||
|
||||
String htmlCode = "<html><body>" + newsRecord.description + "</body></html>";
|
||||
String htmlCode = "<html><body>" + articleData.content + "</body></html>";
|
||||
|
||||
webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
public void RestoreArticle()
|
||||
{
|
||||
articleData = MainActivity.getInstance().articleDataSource.GetArticleFullData(articleName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public class SearchFragment extends Fragment implements UpdateAndFinishCallbackI
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
//MainActivity.getInstance().OpenNewsRecordScreen(newsRecord, MainActivity.TAG_FROM_SEARCHFRAGMENT_TO_NEWSRECORDFRAGMENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,8 +36,20 @@ public class VideoRecordFragment extends Fragment
|
||||
RestoreVideo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString("videoUrl", videoUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
videoUrl = savedInstanceState.getString("videoUrl");
|
||||
RestoreVideo();
|
||||
}
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_video_record_page, container, false);
|
||||
|
||||
TextView nameTextView = (TextView) rootView.findViewById(R.id.nameTextView);
|
||||
|
@ -1,6 +1,9 @@
|
||||
package fishrungames.bashgid.core;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||
@ -8,7 +11,10 @@ import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||
public class ArticleManager
|
||||
{
|
||||
|
||||
public static final SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
||||
|
||||
public static final int ARTICLE_TYPE_NORMAL = 0;
|
||||
public static final int ARTICLE_TYPE_NEWS = 1;
|
||||
|
||||
public static class ArticleRecordData
|
||||
{
|
||||
@ -20,8 +26,9 @@ public class ArticleManager
|
||||
public double geoLat;
|
||||
public double geoLon;
|
||||
public String externalLink;
|
||||
public Date dateTime;
|
||||
|
||||
public ArticleRecordData(String name, int type, String title, String content, double geoLat, double geoLon, String externalLink)
|
||||
public ArticleRecordData(String name, int type, String title, String content, double geoLat, double geoLon, String externalLink, Date dateTime)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
@ -30,6 +37,7 @@ public class ArticleManager
|
||||
this.geoLat = geoLat;
|
||||
this.geoLon = geoLon;
|
||||
this.externalLink = externalLink;
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
public ArticleRecordData(ArticleRecordData copyFrom)
|
||||
@ -41,6 +49,7 @@ public class ArticleManager
|
||||
this.geoLat = copyFrom.geoLat;
|
||||
this.geoLon = copyFrom.geoLon;
|
||||
this.externalLink = copyFrom.externalLink;
|
||||
this.dateTime = copyFrom.dateTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsRecord;
|
||||
import fishrungames.bashgid.core.NewsManager.NewsSortComparator;
|
||||
import fishrungames.networkutils.ImageDownloadTask;
|
||||
@ -19,11 +20,10 @@ public class NewsDownloadTask extends AsyncTask<Bundle, Integer, Long>
|
||||
|
||||
protected Long doInBackground(Bundle... queryArr)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
ArrayList<NewsRecord> localNewsRecordArr = MainActivity.getInstance().newsDataSource.getNews();
|
||||
|
||||
ArrayList<String> imageToDownloadList = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < NewsManager.urlArr.length; i++)
|
||||
{
|
||||
|
||||
@ -35,6 +35,7 @@ public class NewsDownloadTask extends AsyncTask<Bundle, Integer, Long>
|
||||
|
||||
NewsManager.getInstance().replaceNews(localNewsRecordArr);
|
||||
|
||||
|
||||
Bundle innerQuery = new Bundle();
|
||||
|
||||
innerQuery.putStringArray("imageUrlArr", imageToDownloadList.toArray(new String[imageToDownloadList.size()]));
|
||||
@ -44,7 +45,13 @@ public class NewsDownloadTask extends AsyncTask<Bundle, Integer, Long>
|
||||
task.mHandler = this.mHandler;
|
||||
|
||||
task.execute(innerQuery);
|
||||
|
||||
*/
|
||||
|
||||
for (int i = 0; i < NewsManager.urlArr.length; i++)
|
||||
{
|
||||
NewsManager.LoadNewsAndImagesFromRss2_new(NewsManager.urlArr[i]);
|
||||
}
|
||||
|
||||
return (long) 0;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import android.util.Log;
|
||||
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
|
||||
|
||||
|
||||
public class NewsManager {
|
||||
@ -322,6 +323,84 @@ public class NewsManager {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void LoadNewsAndImagesFromRss2_new(String url)
|
||||
{
|
||||
//Xperimental -- need to optimize this code. slow block BEGINS
|
||||
String xmlCode = DownloadFunctions.getXmlFromUrl(url);
|
||||
|
||||
if (xmlCode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Remove BOM character if present
|
||||
if (xmlCode.startsWith("\uFEFF"))
|
||||
{
|
||||
xmlCode = xmlCode.substring(1);
|
||||
}
|
||||
|
||||
RssReader rssReader = new RssReader();
|
||||
|
||||
rssReader.ReadRss(xmlCode);
|
||||
|
||||
|
||||
//Xperimental -- need to optimize this code. slow block ENDS
|
||||
|
||||
|
||||
for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr)
|
||||
{
|
||||
|
||||
ArticleRecordData newsArticle = new ArticleRecordData(
|
||||
rss2Item.title,
|
||||
ArticleManager.ARTICLE_TYPE_NEWS,
|
||||
rss2Item.title,
|
||||
rss2Item.description,
|
||||
0,
|
||||
0,
|
||||
rss2Item.link,
|
||||
rss2Item.pubDate
|
||||
);
|
||||
|
||||
AlbumManager.AddNewArticleToJournal(newsArticle, "news");
|
||||
//newsRecordArr.add(newsArticle);
|
||||
|
||||
}
|
||||
/*imageUrlArr.addAll(ExtractEnclosureImageUrl(rssReader.rss2ItemArr));
|
||||
|
||||
|
||||
ArrayList<String> relativeImageUrlList = ExtractDescriptionImageUrl(rssReader.rss2ItemArr);
|
||||
|
||||
ArrayList<String> absoluteImageUrlList = ConvertRelativeToAbsoluteImageUrlList(relativeImageUrlList, url);
|
||||
|
||||
imageUrlArr.addAll(absoluteImageUrlList);
|
||||
|
||||
//Xperimental -- this function is very slow, need to speed up
|
||||
ReplaceRemoteUrlToLocalUrl(rssReader.rss2ItemArr, relativeImageUrlList, absoluteImageUrlList);
|
||||
|
||||
for (RssReader.Rss2Item rss2Item : rssReader.rss2ItemArr)
|
||||
{
|
||||
boolean exists = false;
|
||||
|
||||
for (NewsRecord newsRecord : newsRecordArr)
|
||||
{
|
||||
if (newsRecord.title.equals(rss2Item.title))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
newsRecordArr.add(new NewsRecord(rss2Item));
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public static class NewsSortComparator implements Comparator<NewsRecord> {
|
||||
public int compare(NewsRecord newsRecord1, NewsRecord newsRecord2) {
|
||||
return newsRecord2.pubDate.compareTo(newsRecord1.pubDate);
|
||||
|
@ -203,15 +203,6 @@ public class AlbumDataSource
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
* Cursor cursor =
|
||||
* database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[]
|
||||
* { BashgidSqliteHelper.COLUMN_NAME,
|
||||
* BashgidSqliteHelper.COLUMN_TITLE,
|
||||
* BashgidSqliteHelper.COLUMN_DESCRIPTION },
|
||||
* BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name
|
||||
* }, null, null, null, null);
|
||||
*/
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME,
|
||||
BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null);
|
||||
@ -238,6 +229,8 @@ public class AlbumDataSource
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
} finally
|
||||
@ -252,6 +245,8 @@ public class AlbumDataSource
|
||||
|
||||
private boolean innerIsAlbumAlreadyExist(String name, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME
|
||||
+ "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
@ -259,16 +254,22 @@ public class AlbumDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private boolean innerPhotoAlbumRelationAlreadyExist(String imageUrl, String name, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL,
|
||||
BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?" + " AND " + BashgidSqliteHelper.COLUMN_NAME + "=?",
|
||||
new String[] { imageUrl, name }, null, null, null, null);
|
||||
@ -277,11 +278,13 @@ public class AlbumDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@ -302,6 +305,8 @@ public class AlbumDataSource
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -310,21 +315,23 @@ public class AlbumDataSource
|
||||
|
||||
public AlbumRecordData innerGetAlbumByName(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
AlbumRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE,
|
||||
BashgidSqliteHelper.COLUMN_DESCRIPTION }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
return new AlbumRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||
result = new AlbumRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
|
||||
@ -9,8 +14,6 @@ import fishrungames.bashgid.core.ArticleManager.ArticleFullData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleRecordData;
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelRecordData;
|
||||
import fishrungames.bashgid.core.VideoManager.VideoRecordData;
|
||||
|
||||
|
||||
import android.content.ContentValues;
|
||||
@ -21,11 +24,17 @@ import android.util.Log;
|
||||
|
||||
public class ArticleDataSource
|
||||
{
|
||||
// private SQLiteDatabase database = null;
|
||||
|
||||
private BashgidSqliteHelper dbHelper = null;
|
||||
|
||||
// private final Semaphore mutex = new Semaphore(1, true);
|
||||
|
||||
|
||||
public static class DateSortComparator implements Comparator<ArticleManager.ArticleRecordData> {
|
||||
public int compare(ArticleManager.ArticleRecordData record1, ArticleManager.ArticleRecordData record2) {
|
||||
return record2.dateTime.compareTo(record1.dateTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ArticleDataSource(Context context, BashgidSqliteHelper dbHelper)
|
||||
{
|
||||
@ -50,6 +59,7 @@ public class ArticleDataSource
|
||||
values.put(BashgidSqliteHelper.COLUMN_GEOLAT, recordData.geoLat);
|
||||
values.put(BashgidSqliteHelper.COLUMN_GEOLON, recordData.geoLon);
|
||||
values.put(BashgidSqliteHelper.COLUMN_EXTERNAL_LINK, recordData.externalLink);
|
||||
values.put(BashgidSqliteHelper.COLUMN_DATE_TIME, ArticleManager.iso8601Format.format(recordData.dateTime));
|
||||
|
||||
if (!innerIsArticleAlreadyExist(recordData.name, database))
|
||||
{
|
||||
@ -160,6 +170,23 @@ public class ArticleDataSource
|
||||
try
|
||||
{
|
||||
|
||||
result = InnerGetArticleFullData(name, database);
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArticleFullData InnerGetArticleFullData(String name, SQLiteDatabase database)
|
||||
{
|
||||
ArticleFullData result = null;
|
||||
|
||||
|
||||
ArticleRecordData recordData = innerGetArticleByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
@ -182,12 +209,6 @@ public class ArticleDataSource
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -204,6 +225,24 @@ public class ArticleDataSource
|
||||
try
|
||||
{
|
||||
|
||||
result = InnerGetArticleShortData(name, database);
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public ArticleShortData InnerGetArticleShortData(String name, SQLiteDatabase database)
|
||||
{
|
||||
ArticleShortData result = null;
|
||||
|
||||
|
||||
ArticleRecordData recordData = innerGetArticleByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
@ -235,18 +274,14 @@ public class ArticleDataSource
|
||||
|
||||
}
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private boolean innerIsArticleAlreadyExist(String name, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] { BashgidSqliteHelper.COLUMN_NAME },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
@ -254,11 +289,13 @@ public class ArticleDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@ -266,6 +303,8 @@ public class ArticleDataSource
|
||||
|
||||
private boolean innerAlbumArticleRelationAlreadyExist(String albumName, String articleName, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ALBUM_NAME, BashgidSqliteHelper.COLUMN_ARTICLE_NAME },
|
||||
BashgidSqliteHelper.COLUMN_ALBUM_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { albumName, articleName }, null, null, null, null);
|
||||
|
||||
@ -273,16 +312,20 @@ public class ArticleDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private boolean innerChannelArticleRelationAlreadyExist(String channelName, String articleName, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL_ARTICLE_RELATION, new String[] { BashgidSqliteHelper.COLUMN_CHANNEL_NAME, BashgidSqliteHelper.COLUMN_ARTICLE_NAME },
|
||||
BashgidSqliteHelper.COLUMN_CHANNEL_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?", new String[] { channelName, articleName }, null, null, null, null);
|
||||
|
||||
@ -290,39 +333,57 @@ public class ArticleDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private ArticleRecordData innerGetArticleByName(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
ArticleRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE, new String[] {
|
||||
BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TYPE, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_CONTENT, BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON, BashgidSqliteHelper.COLUMN_EXTERNAL_LINK },
|
||||
BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TYPE, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_CONTENT, BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON, BashgidSqliteHelper.COLUMN_EXTERNAL_LINK,BashgidSqliteHelper.COLUMN_DATE_TIME },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
Date d = new Date();
|
||||
|
||||
try
|
||||
{
|
||||
d = ArticleManager.iso8601Format.parse(cursor.getString(7));
|
||||
}
|
||||
catch(ParseException e)
|
||||
{
|
||||
Log.e("aaa", "aaa!!!!!");
|
||||
}
|
||||
|
||||
return new ArticleRecordData(
|
||||
result = new ArticleRecordData(
|
||||
cursor.getString(0),
|
||||
cursor.getInt(1),
|
||||
cursor.getString(2),
|
||||
cursor.getString(3),
|
||||
cursor.getDouble(4),
|
||||
cursor.getDouble(5),
|
||||
cursor.getString(6)
|
||||
cursor.getString(6),
|
||||
d
|
||||
);
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@ -344,6 +405,8 @@ public class ArticleDataSource
|
||||
while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -368,10 +431,14 @@ public class ArticleDataSource
|
||||
while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ public class BashgidSqliteHelper extends SQLiteOpenHelper
|
||||
public static final String COLUMN_PREVIEW_IMAGE_URL = "previewImageUrl";
|
||||
public static final String COLUMN_PREVIEW_IMAGE_HASH = "previewImageHash";
|
||||
|
||||
public static final String COLUMN_DATE_TIME = "dateTime";
|
||||
|
||||
|
||||
|
||||
|
||||
private static final String DATABASE_NAME = "bashgid.db";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
@ -83,7 +88,7 @@ public class BashgidSqliteHelper extends SQLiteOpenHelper
|
||||
|
||||
private static final String TABLE_ARTICLE_CREATE = "create table " + TABLE_ARTICLE + "(" + COLUMN_ID + " integer primary key autoincrement" + ", " + COLUMN_NAME + " text not null"
|
||||
+ ", " + COLUMN_TYPE + " integer not null" + ", " + COLUMN_TITLE + " text not null" + ", " + COLUMN_CONTENT + " text not null" + ", " + COLUMN_GEOLAT
|
||||
+ " real not null" + ", " + COLUMN_GEOLON + " real not null" + ", " + COLUMN_EXTERNAL_LINK + " text not null" +");";
|
||||
+ " real not null" + ", " + COLUMN_GEOLON + " real not null" + ", " + COLUMN_EXTERNAL_LINK + " text not null" + ", " + COLUMN_DATE_TIME + " text not null" +");";
|
||||
|
||||
private static final String TABLE_ALBUM_ARTICLE_RELATION_CREATE = "create table " + TABLE_ALBUM_ARTICLE_RELATION + "(" + COLUMN_ID + " integer primary key autoincrement" + ", " + COLUMN_ALBUM_NAME + " text not null"
|
||||
+ ", " + COLUMN_ARTICLE_NAME + " text not null" + ");";
|
||||
@ -186,8 +191,8 @@ public class BashgidSqliteHelper extends SQLiteOpenHelper
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
mutex.release();
|
||||
super.close();
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,22 +1,17 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
import fishrungames.bashgid.core.AlbumManager;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
|
||||
|
||||
import fishrungames.bashgid.core.ChannelManager;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelFullData;
|
||||
import fishrungames.bashgid.core.ChannelManager.ChannelRecordData;
|
||||
import fishrungames.bashgid.core.PhotoManager;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
@ -30,7 +25,7 @@ public class ChannelDataSource
|
||||
this.dbHelper = dbHelper;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void CreateNewChannel(ChannelManager.ChannelRecordData recordData)
|
||||
{
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
@ -61,11 +56,11 @@ public class ChannelDataSource
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean IsChannelAlreadyExist(String name)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
@ -74,18 +69,17 @@ public class ChannelDataSource
|
||||
try
|
||||
{
|
||||
result = innerIsChannelAlreadyExist(name, database);
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void AddVideoToChannel(String videoUrl, String channelName)
|
||||
{
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
@ -105,7 +99,7 @@ public class ChannelDataSource
|
||||
Log.e("a", "aaa1");
|
||||
database.insert(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, null, values);
|
||||
Log.e("a", "aaa2");
|
||||
}
|
||||
}
|
||||
Log.e("a", "aaa3");
|
||||
|
||||
} finally
|
||||
@ -114,132 +108,100 @@ public class ChannelDataSource
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ChannelFullData GetChannelFullData(String name)
|
||||
{
|
||||
ChannelFullData result = null;
|
||||
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
result = InnerGetChannelFullData(name, database);
|
||||
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public ChannelFullData InnerGetChannelFullData(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
ChannelFullData result = null;
|
||||
|
||||
ChannelRecordData recordData = InnerGetChannelByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
{
|
||||
|
||||
result = new ChannelFullData(recordData);
|
||||
|
||||
ArrayList<String> videoUrlArr = innerGetVideoUrlArrInAlbum(name, database);
|
||||
|
||||
for (String videoUrl : videoUrlArr)
|
||||
{
|
||||
result.videoRecordArr.add(MainActivity.getInstance().videoDataSource.InnerGetVideoByVideoUrl(videoUrl, database));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
public AlbumShortData GetAlbumShortData(String name)
|
||||
{
|
||||
AlbumShortData result = null;
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
ChannelRecordData recordData = InnerGetChannelByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
AlbumRecordData recordData = innerGetAlbumByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
{
|
||||
|
||||
result = new AlbumShortData(recordData);
|
||||
|
||||
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(name, database);
|
||||
|
||||
result.photoCount = imageUrlArr.size();
|
||||
|
||||
if (imageUrlArr.size() > 0)
|
||||
{
|
||||
result.firstImageUrl = imageUrlArr.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} finally
|
||||
result = new ChannelFullData(recordData);
|
||||
|
||||
ArrayList<String> videoUrlArr = innerGetVideoUrlArrInAlbum(name, database);
|
||||
|
||||
for (String videoUrl : videoUrlArr)
|
||||
{
|
||||
dbHelper.close();
|
||||
result.videoRecordArr.add(MainActivity.getInstance().videoDataSource.InnerGetVideoByVideoUrl(videoUrl, database));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
*/
|
||||
private boolean innerIsChannelAlreadyExist(String name, SQLiteDatabase database)
|
||||
{
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL, new String[] { BashgidSqliteHelper.COLUMN_NAME },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME
|
||||
+ "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean innerVideoChannelRelationAlreadyExist(String videoUrl, String name, SQLiteDatabase database)
|
||||
{
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL, BashgidSqliteHelper.COLUMN_NAME },
|
||||
BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?" + " AND " + BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { videoUrl, name }, null, null, null, null);
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL,
|
||||
BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?" + " AND " + BashgidSqliteHelper.COLUMN_NAME + "=?",
|
||||
new String[] { videoUrl, name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<String> innerGetVideoUrlArrInAlbum(String name, SQLiteDatabase database)
|
||||
{
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO_CHANNEL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
@ -250,38 +212,36 @@ public class ChannelDataSource
|
||||
do
|
||||
{
|
||||
result.add(cursor.getString(0));
|
||||
}
|
||||
while (cursor.moveToNext());
|
||||
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ChannelRecordData InnerGetChannelByName(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
ChannelRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL,
|
||||
new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_CHANNEL, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE,
|
||||
BashgidSqliteHelper.COLUMN_DESCRIPTION }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
return new ChannelRecordData(
|
||||
cursor.getString(0),
|
||||
cursor.getString(1),
|
||||
cursor.getString(2)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
|
||||
return null;
|
||||
result = new ChannelRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import fishrungames.bashgid.MainActivity;
|
||||
import fishrungames.bashgid.core.AlbumManager;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumFullData;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumRecordData;
|
||||
import fishrungames.bashgid.core.AlbumManager.AlbumShortData;
|
||||
|
||||
import fishrungames.bashgid.core.ArticleManager.ArticleShortData;
|
||||
import fishrungames.bashgid.core.JournalManager;
|
||||
import fishrungames.bashgid.core.JournalManager.JournalRecordData;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -98,7 +98,7 @@ public class JournalDataSource
|
||||
if (!innerArticleJournalRelationAlreadyExist(articleName, journalName, database))
|
||||
{
|
||||
Log.e("a", "aaa1");
|
||||
database.insert(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, null, values);
|
||||
database.insert(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, null, values);
|
||||
Log.e("a", "aaa2");
|
||||
}
|
||||
Log.e("a", "aaa3");
|
||||
@ -110,10 +110,10 @@ public class JournalDataSource
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public AlbumFullData GetAlbumFullData(String name)
|
||||
|
||||
public ArrayList<ArticleShortData> GetRecentArticles(String journalName, int count)
|
||||
{
|
||||
AlbumFullData result = null;
|
||||
ArrayList<ArticleShortData> result = new ArrayList<ArticleShortData>();
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
@ -122,115 +122,23 @@ public class JournalDataSource
|
||||
try
|
||||
{
|
||||
|
||||
result = InnerGetAlbumFullData(name, database);
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public AlbumFullData InnerGetAlbumFullData(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
AlbumFullData result = null;
|
||||
|
||||
AlbumRecordData recordData = innerGetAlbumByName(name, database);
|
||||
|
||||
if (recordData != null)
|
||||
{
|
||||
|
||||
result = new AlbumFullData(recordData);
|
||||
|
||||
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(name, database);
|
||||
|
||||
for (String imageUrl : imageUrlArr)
|
||||
{
|
||||
result.photoRecordArr.add(MainActivity.getInstance().photoDataSource.InnerGetPhotoByImageUrl(imageUrl, database));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public AlbumShortData GetAlbumShortData(String name)
|
||||
{
|
||||
AlbumShortData result = null;
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
AlbumRecordData recordData = innerGetAlbumByName(name, database);
|
||||
JournalRecordData recordData = innerGetJournalByName(journalName, database);
|
||||
|
||||
if (recordData != null)
|
||||
{
|
||||
|
||||
result = new AlbumShortData(recordData);
|
||||
ArrayList<String> articleNameArr = innerGetArticleArrInJournal(journalName, database);
|
||||
|
||||
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(name, database);
|
||||
|
||||
result.photoCount = imageUrlArr.size();
|
||||
|
||||
if (imageUrlArr.size() > 0)
|
||||
for (String articleName : articleNameArr)
|
||||
{
|
||||
result.firstImageUrl = imageUrlArr.get(0);
|
||||
result.add(MainActivity.getInstance().articleDataSource.InnerGetArticleShortData(articleName, database));
|
||||
}
|
||||
}
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<AlbumShortData> GetAllAlbumShortData()
|
||||
{
|
||||
|
||||
ArrayList<AlbumShortData> result = new ArrayList<AlbumShortData>();
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME,
|
||||
BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION }, null, null, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.moveToFirst())
|
||||
|
||||
Collections.sort(result, new ArticleDataSource.DateSortComparator());
|
||||
|
||||
if (result.size() > count)
|
||||
{
|
||||
do
|
||||
{
|
||||
|
||||
AlbumShortData shortData = new AlbumShortData(new AlbumRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2)));
|
||||
|
||||
ArrayList<String> imageUrlArr = innerGetImageUrlArrInAlbum(shortData.name, database);
|
||||
|
||||
shortData.photoCount = imageUrlArr.size();
|
||||
|
||||
if (imageUrlArr.size() > 0)
|
||||
{
|
||||
shortData.firstImageUrl = imageUrlArr.get(0);
|
||||
}
|
||||
|
||||
result.add(shortData);
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
result.subList(count, result.size() - count - 1).clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,10 +151,11 @@ public class JournalDataSource
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
private boolean innerIsJournalAlreadyExist(String name, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME }, BashgidSqliteHelper.COLUMN_NAME
|
||||
+ "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
@ -254,16 +163,20 @@ public class JournalDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private boolean innerArticleJournalRelationAlreadyExist(String articleName, String journalName, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ARTICLE_NAME,
|
||||
BashgidSqliteHelper.COLUMN_JOURNAL_NAME }, BashgidSqliteHelper.COLUMN_ARTICLE_NAME + "=?" + " AND " + BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?",
|
||||
new String[] { articleName, journalName }, null, null, null, null);
|
||||
@ -272,21 +185,23 @@ public class JournalDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private ArrayList<String> innerGetImageUrlArrInAlbum(String name, SQLiteDatabase database)
|
||||
|
||||
private ArrayList<String> innerGetArticleArrInJournal(String name, SQLiteDatabase database)
|
||||
{
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO_ALBUM_RELATION, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL },
|
||||
BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ARTICLE_JOURNAL_RELATION, new String[] { BashgidSqliteHelper.COLUMN_ARTICLE_NAME },
|
||||
BashgidSqliteHelper.COLUMN_JOURNAL_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
@ -298,16 +213,20 @@ public class JournalDataSource
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public AlbumRecordData innerGetAlbumByName(String name, SQLiteDatabase database)
|
||||
public JournalRecordData innerGetJournalByName(String name, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
JournalRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_ALBUM, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE,
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_JOURNAL, new String[] { BashgidSqliteHelper.COLUMN_NAME, BashgidSqliteHelper.COLUMN_TITLE,
|
||||
BashgidSqliteHelper.COLUMN_DESCRIPTION }, BashgidSqliteHelper.COLUMN_NAME + "=?", new String[] { name }, null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
@ -316,12 +235,13 @@ public class JournalDataSource
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
return new AlbumRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||
result = new JournalRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
return result;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
|
||||
import fishrungames.bashgid.core.PhotoManager;
|
||||
import fishrungames.bashgid.core.PhotoManager.PhotoRecordData;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -12,15 +11,9 @@ import android.util.Log;
|
||||
|
||||
public class PhotoDataSource
|
||||
{
|
||||
// private SQLiteDatabase database = null;
|
||||
|
||||
private BashgidSqliteHelper dbHelper = null;
|
||||
|
||||
// private String[] allColumns = { BashgidSqliteHelper.COLUMN_ID,
|
||||
// BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION,
|
||||
// BashgidSqliteHelper.COLUMN_IMAGE_URL, BashgidSqliteHelper.COLUMN_GEOLAT,
|
||||
// BashgidSqliteHelper.COLUMN_GEOLON };
|
||||
|
||||
public PhotoDataSource(Context context, BashgidSqliteHelper dbHelper)
|
||||
{
|
||||
|
||||
@ -28,7 +21,7 @@ public class PhotoDataSource
|
||||
|
||||
}
|
||||
|
||||
public void AddOrReplacePhoto(PhotoManager.PhotoRecordData recordData)
|
||||
public void AddOrReplacePhoto(PhotoRecordData recordData)
|
||||
{
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
@ -38,7 +31,7 @@ public class PhotoDataSource
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
//values.put(BashgidSqliteHelper.COLUMN_ID, 1);
|
||||
// values.put(BashgidSqliteHelper.COLUMN_ID, 1);
|
||||
values.put(BashgidSqliteHelper.COLUMN_TITLE, recordData.title);
|
||||
values.put(BashgidSqliteHelper.COLUMN_DESCRIPTION, recordData.description);
|
||||
values.put(BashgidSqliteHelper.COLUMN_IMAGE_URL, recordData.imageUrl);
|
||||
@ -66,19 +59,19 @@ public class PhotoDataSource
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PhotoManager.PhotoRecordData GetPhotoByImageUrl(String imageUrl)
|
||||
|
||||
public PhotoRecordData GetPhotoByImageUrl(String imageUrl)
|
||||
{
|
||||
PhotoManager.PhotoRecordData result = null;
|
||||
|
||||
PhotoRecordData result = null;
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
if (database != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = InnerGetPhotoByImageUrl(imageUrl, database);
|
||||
|
||||
result = InnerGetPhotoByImageUrl(imageUrl, database);
|
||||
|
||||
} finally
|
||||
{
|
||||
dbHelper.close();
|
||||
@ -87,37 +80,38 @@ public class PhotoDataSource
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public PhotoManager.PhotoRecordData InnerGetPhotoByImageUrl(String imageUrl, SQLiteDatabase database)
|
||||
|
||||
public PhotoRecordData InnerGetPhotoByImageUrl(String imageUrl, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
PhotoRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO,
|
||||
new String[] { BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_IMAGE_URL, BashgidSqliteHelper.COLUMN_IMAGE_HASH, BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON },
|
||||
BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { imageUrl }, null, null, null, null);
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO, new String[] { BashgidSqliteHelper.COLUMN_TITLE,
|
||||
BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_IMAGE_URL, BashgidSqliteHelper.COLUMN_IMAGE_HASH,
|
||||
BashgidSqliteHelper.COLUMN_GEOLAT, BashgidSqliteHelper.COLUMN_GEOLON }, BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { imageUrl },
|
||||
null, null, null, null);
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
return new PhotoManager.PhotoRecordData(
|
||||
cursor.getString(0),
|
||||
cursor.getString(1),
|
||||
cursor.getString(2),
|
||||
cursor.getString(3),
|
||||
cursor.getDouble(4),
|
||||
cursor.getDouble(5)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
|
||||
return null;
|
||||
|
||||
result = new PhotoRecordData(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getString(3),
|
||||
cursor.getDouble(4), cursor.getDouble(5));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private boolean isPhotoAlreadyExist(String imageUrl, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_PHOTO, new String[] { BashgidSqliteHelper.COLUMN_IMAGE_URL },
|
||||
BashgidSqliteHelper.COLUMN_IMAGE_URL + "=?", new String[] { imageUrl }, null, null, null, null);
|
||||
|
||||
@ -125,12 +119,13 @@ public class PhotoDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fishrungames.bashgid.core.db;
|
||||
|
||||
|
||||
import fishrungames.bashgid.core.VideoManager;
|
||||
import fishrungames.bashgid.core.VideoManager.VideoRecordData;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -21,7 +21,7 @@ public class VideoDataSource
|
||||
|
||||
}
|
||||
|
||||
public void AddOrReplaceVideo(VideoManager.VideoRecordData recordData)
|
||||
public void AddOrReplaceVideo(VideoRecordData recordData)
|
||||
{
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
@ -59,9 +59,9 @@ public class VideoDataSource
|
||||
|
||||
}
|
||||
|
||||
public VideoManager.VideoRecordData GetVideoByVideoUrl(String videoUrl)
|
||||
public VideoRecordData GetVideoByVideoUrl(String videoUrl)
|
||||
{
|
||||
VideoManager.VideoRecordData result = null;
|
||||
VideoRecordData result = null;
|
||||
|
||||
SQLiteDatabase database = dbHelper.getWritableDatabase();
|
||||
|
||||
@ -80,10 +80,10 @@ public class VideoDataSource
|
||||
return result;
|
||||
}
|
||||
|
||||
public VideoManager.VideoRecordData InnerGetVideoByVideoUrl(String videoUrl, SQLiteDatabase database)
|
||||
public VideoRecordData InnerGetVideoByVideoUrl(String videoUrl, SQLiteDatabase database)
|
||||
{
|
||||
|
||||
VideoManager.VideoRecordData result = null;
|
||||
VideoRecordData result = null;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO,
|
||||
new String[] { BashgidSqliteHelper.COLUMN_TYPE, BashgidSqliteHelper.COLUMN_VIDEO_URL, BashgidSqliteHelper.COLUMN_TITLE, BashgidSqliteHelper.COLUMN_DESCRIPTION, BashgidSqliteHelper.COLUMN_PREVIEW_IMAGE_URL, BashgidSqliteHelper.COLUMN_PREVIEW_IMAGE_HASH },
|
||||
@ -91,11 +91,11 @@ public class VideoDataSource
|
||||
|
||||
if (cursor != null)
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
|
||||
result = new VideoManager.VideoRecordData(
|
||||
|
||||
result = new VideoRecordData(
|
||||
cursor.getInt(0),
|
||||
cursor.getString(1),
|
||||
cursor.getString(2),
|
||||
@ -104,6 +104,8 @@ public class VideoDataSource
|
||||
cursor.getString(5)
|
||||
);
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -112,6 +114,8 @@ public class VideoDataSource
|
||||
|
||||
private boolean isVideoAlreadyExist(String videoUrl, SQLiteDatabase database)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Cursor cursor = database.query(BashgidSqliteHelper.TABLE_VIDEO, new String[] { BashgidSqliteHelper.COLUMN_VIDEO_URL },
|
||||
BashgidSqliteHelper.COLUMN_VIDEO_URL + "=?", new String[] { videoUrl }, null, null, null, null);
|
||||
|
||||
@ -119,11 +123,13 @@ public class VideoDataSource
|
||||
{
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user