From bf7bc4ed61a098a037d1eb71623fc370af689976 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 10 Jun 2015 18:35:37 +0200 Subject: Moving stuff around --- .../java/org/rssin/neurons/FeedSorterTest.java | 3 +- .../java/org/rssin/android/ArticleActivity.java | 5 +- .../java/org/rssin/android/FeedItemAdapter.java | 37 ++++---- .../org/rssin/android/FeedItemsListFragment.java | 3 +- .../java/org/rssin/android/FeedSorterProvider.java | 100 -------------------- .../java/org/rssin/android/FeedSorterTrainer.java | 47 ---------- .../org/rssin/android/SortedFeedItemContainer.java | 74 +++++++++++++++ .../main/java/org/rssin/neurons/FeedSorter.java | 38 ++++---- .../java/org/rssin/rss/FeedSorterProvider.java | 101 +++++++++++++++++++++ .../main/java/org/rssin/rss/FeedSorterTrainer.java | 47 ++++++++++ .../java/org/rssin/rssin/FeedLoaderAndSorter.java | 45 ++++----- .../org/rssin/rssin/SortedFeedItemContainer.java | 74 --------------- 12 files changed, 287 insertions(+), 287 deletions(-) delete mode 100644 app/src/main/java/org/rssin/android/FeedSorterProvider.java delete mode 100644 app/src/main/java/org/rssin/android/FeedSorterTrainer.java create mode 100644 app/src/main/java/org/rssin/android/SortedFeedItemContainer.java create mode 100644 app/src/main/java/org/rssin/rss/FeedSorterProvider.java create mode 100644 app/src/main/java/org/rssin/rss/FeedSorterTrainer.java delete mode 100644 app/src/main/java/org/rssin/rssin/SortedFeedItemContainer.java (limited to 'app') diff --git a/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java index ba76dea..f921fcc 100644 --- a/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java +++ b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java @@ -24,9 +24,8 @@ import junit.framework.Assert; import junit.framework.TestCase; import org.rssin.rss.FeedItem; -import org.rssin.rssin.SortedFeedItemContainer; +import org.rssin.android.SortedFeedItemContainer; -import java.net.URL; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; diff --git a/app/src/main/java/org/rssin/android/ArticleActivity.java b/app/src/main/java/org/rssin/android/ArticleActivity.java index 119d937..82190db 100644 --- a/app/src/main/java/org/rssin/android/ArticleActivity.java +++ b/app/src/main/java/org/rssin/android/ArticleActivity.java @@ -28,8 +28,9 @@ import android.widget.TextView; import android.widget.Toast; import org.rssin.rss.FeedItem; +import org.rssin.rss.FeedSorterProvider; +import org.rssin.rss.FeedSorterTrainer; import org.rssin.rssin.R; -import org.rssin.rssin.SortedFeedItemContainer; import static org.rssin.neurons.Feedback.Dislike; import static org.rssin.neurons.Feedback.Like; @@ -68,7 +69,7 @@ public class ArticleActivity extends ActionBarActivity { date.setText(R.string.article_published_on_unknown); } - new Thread(new FeedSorterTrainer(FeedSorterProvider.getInstance(this))).start(); + new Thread(new FeedSorterTrainer(FeedSorterProvider.getInstance(DefaultStorageProvider.getInstance(this)))).start(); } catch (NullPointerException e) { Frontend.error(this, R.string.error_load_article, e); finish(); diff --git a/app/src/main/java/org/rssin/android/FeedItemAdapter.java b/app/src/main/java/org/rssin/android/FeedItemAdapter.java index 249d5ec..a67b267 100644 --- a/app/src/main/java/org/rssin/android/FeedItemAdapter.java +++ b/app/src/main/java/org/rssin/android/FeedItemAdapter.java @@ -1,21 +1,21 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.rssin.android; /** @@ -31,7 +31,6 @@ import android.widget.TextView; import org.rssin.neurons.Feedback; import org.rssin.rssin.R; -import org.rssin.rssin.SortedFeedItemContainer; import org.rssin.summaries.BablukiAPI; import org.rssin.summaries.LengthMode; import org.rssin.summaries.SummaryAPIInterface; diff --git a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java index d41be81..488c5b5 100644 --- a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java +++ b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java @@ -31,7 +31,6 @@ import org.rssin.listener.RealtimeListener; import org.rssin.rssin.Feed; import org.rssin.rssin.FeedLoaderAndSorter; import org.rssin.rssin.R; -import org.rssin.rssin.SortedFeedItemContainer; import java.util.ArrayList; import java.util.List; @@ -83,7 +82,7 @@ public class FeedItemsListFragment extends Fragment { FeedLoaderAndSorter loaderAndSorter = new FeedLoaderAndSorter(feeds); loaderAndSorter.getFilteredFeedItems( - context, + DefaultStorageProvider.getInstance(context), VolleyFetcher.getInstance(context), new RealtimeListener, Object>() { @Override diff --git a/app/src/main/java/org/rssin/android/FeedSorterProvider.java b/app/src/main/java/org/rssin/android/FeedSorterProvider.java deleted file mode 100644 index 8e08c7e..0000000 --- a/app/src/main/java/org/rssin/android/FeedSorterProvider.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.rssin.android; - -import android.content.Context; -import android.util.Log; - -import org.rssin.neurons.FeedSorter; -import org.rssin.storage.StorageProvider; - -/** - * @author Jos. - */ -public class FeedSorterProvider { - private static FeedSorterProvider instance; - private FeedSorter sorter = null; - private final String storageKey = "FeedSorter"; - private final StorageProvider storageProvider; - - private FeedSorterProvider(Context context) - { - storageProvider = SharedPreferencesStorageProvider.getInstance(context); - } - - public synchronized static FeedSorterProvider getInstance() - { - return instance; - } - - public synchronized static FeedSorterProvider getInstance(Context context) - { - if(instance == null) - { - instance = new FeedSorterProvider(context); - } - - return instance; - } - - public synchronized FeedSorter getFeedSorter() - { - if(sorter == null) - { - try { - sorter = (FeedSorter) storageProvider.fetch(storageKey, FeedSorter.class); - } catch (Exception e) { - sorter = new FeedSorter(); - Log.v("FST", "Saving new empty sorterProvider", e); - this.save(); - } - } - - return sorter; - } - - public void save() - { - FeedSorterStorer storer = new FeedSorterStorer(storageKey, storageProvider, sorter); - new Thread(storer).start(); - } - - private class FeedSorterStorer implements Runnable { - private final Object storageKey; - private final StorageProvider storageProvider; - private final FeedSorter feedSorter; - - public FeedSorterStorer(Object storageKey, StorageProvider storageProvider, FeedSorter feedSorter) { - this.storageKey = storageKey; - this.storageProvider = storageProvider; - this.feedSorter = feedSorter; - } - - @Override - public void run() { - try { - synchronized (feedSorter) { - storageProvider.store(storageKey, feedSorter); - } - } catch (Exception e) { - Log.e("Filter", "Failed to store FeedSorter", e); - } - } - } -} diff --git a/app/src/main/java/org/rssin/android/FeedSorterTrainer.java b/app/src/main/java/org/rssin/android/FeedSorterTrainer.java deleted file mode 100644 index d982fb9..0000000 --- a/app/src/main/java/org/rssin/android/FeedSorterTrainer.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.rssin.android; - -import android.util.Log; - -/** - * @author Jos. - */ -public class FeedSorterTrainer implements Runnable { - private FeedSorterProvider sorterProvider; - public FeedSorterTrainer(FeedSorterProvider sorterProvider) - { - this.sorterProvider = sorterProvider; - } - - @Override - public void run() { - Log.d("FeedSorterTrainer", "Training starting..."); - for (int i = 0; i < 50; i++) { - sorterProvider.getFeedSorter().train(); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - sorterProvider.save(); - } -} diff --git a/app/src/main/java/org/rssin/android/SortedFeedItemContainer.java b/app/src/main/java/org/rssin/android/SortedFeedItemContainer.java new file mode 100644 index 0000000..fd2777c --- /dev/null +++ b/app/src/main/java/org/rssin/android/SortedFeedItemContainer.java @@ -0,0 +1,74 @@ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.rssin.android; + +import android.content.Context; + +import org.rssin.neurons.Feedback; +import org.rssin.neurons.TrainingCase; +import org.rssin.rss.FeedItem; +import org.rssin.rss.FeedSorterProvider; + +import java.io.Serializable; + +/** + * @author Jos. + */ +public class SortedFeedItemContainer implements Comparable, Serializable { + private FeedItem feeditem; + + private long score = -1; + private TrainingCase trainingCase; + + public SortedFeedItemContainer(FeedItem feeditem) + { + this.feeditem = feeditem; + } + + public FeedItem getFeeditem() { + return feeditem; + } + + public boolean hasScore() { + return score != 0; + } + + public long getScore() { + return score; + } + + public void feedback(Context context, Feedback feedback) + { + if(trainingCase == null) + { + trainingCase = FeedSorterProvider.getInstance(DefaultStorageProvider.getInstance(context)).getFeedSorter().feedback(getFeeditem(), feedback); + }else { + trainingCase.setFeedback(feedback); + } + } + + public void setScore(long score) { + this.score = score; + } + + @Override + public int compareTo(SortedFeedItemContainer another) { + return (int)(another.getScore() - this.getScore()); + } +} diff --git a/app/src/main/java/org/rssin/neurons/FeedSorter.java b/app/src/main/java/org/rssin/neurons/FeedSorter.java index 8e1dc55..b195772 100644 --- a/app/src/main/java/org/rssin/neurons/FeedSorter.java +++ b/app/src/main/java/org/rssin/neurons/FeedSorter.java @@ -1,27 +1,27 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.rssin.neurons; import android.util.Log; import org.rssin.rss.FeedItem; -import org.rssin.rssin.SortedFeedItemContainer; +import org.rssin.android.SortedFeedItemContainer; import org.rssin.storage.Storable; import java.util.ArrayList; diff --git a/app/src/main/java/org/rssin/rss/FeedSorterProvider.java b/app/src/main/java/org/rssin/rss/FeedSorterProvider.java new file mode 100644 index 0000000..304e4fc --- /dev/null +++ b/app/src/main/java/org/rssin/rss/FeedSorterProvider.java @@ -0,0 +1,101 @@ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.rssin.rss; + +import android.content.Context; +import android.util.Log; + +import org.rssin.neurons.FeedSorter; +import org.rssin.storage.StorageProvider; + +/** + * @author Jos. + */ +public class FeedSorterProvider { + + private static FeedSorterProvider instance; + private FeedSorter sorter = null; + private final String storageKey = "FeedSorter"; + private final StorageProvider storageProvider; + + private FeedSorterProvider(StorageProvider storageProvider) + { + this.storageProvider = storageProvider; + } + + public synchronized static FeedSorterProvider getInstance() + { + return instance; + } + + public synchronized static FeedSorterProvider getInstance(StorageProvider storageProvider) + { + if(instance == null) + { + instance = new FeedSorterProvider(storageProvider); + } + + return instance; + } + + public synchronized FeedSorter getFeedSorter() + { + if(sorter == null) + { + try { + sorter = (FeedSorter) storageProvider.fetch(storageKey, FeedSorter.class); + } catch (Exception e) { + sorter = new FeedSorter(); + Log.v("FST", "Saving new empty sorterProvider", e); + this.save(); + } + } + + return sorter; + } + + public void save() + { + FeedSorterStorer storer = new FeedSorterStorer(storageKey, storageProvider, sorter); + new Thread(storer).start(); + } + + private class FeedSorterStorer implements Runnable { + private final Object storageKey; + private final StorageProvider storageProvider; + private final FeedSorter feedSorter; + + public FeedSorterStorer(Object storageKey, StorageProvider storageProvider, FeedSorter feedSorter) { + this.storageKey = storageKey; + this.storageProvider = storageProvider; + this.feedSorter = feedSorter; + } + + @Override + public void run() { + try { + synchronized (feedSorter) { + storageProvider.store(storageKey, feedSorter); + } + } catch (Exception e) { + Log.e("Filter", "Failed to store FeedSorter", e); + } + } + } +} diff --git a/app/src/main/java/org/rssin/rss/FeedSorterTrainer.java b/app/src/main/java/org/rssin/rss/FeedSorterTrainer.java new file mode 100644 index 0000000..097cfe6 --- /dev/null +++ b/app/src/main/java/org/rssin/rss/FeedSorterTrainer.java @@ -0,0 +1,47 @@ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.rssin.rss; + +import android.util.Log; + +/** + * @author Jos. + */ +public class FeedSorterTrainer implements Runnable { + private FeedSorterProvider sorterProvider; + public FeedSorterTrainer(FeedSorterProvider sorterProvider) + { + this.sorterProvider = sorterProvider; + } + + @Override + public void run() { + Log.d("FeedSorterTrainer", "Training starting..."); + for (int i = 0; i < 50; i++) { + sorterProvider.getFeedSorter().train(); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + sorterProvider.save(); + } +} diff --git a/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java b/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java index 3581368..e561657 100644 --- a/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java +++ b/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java @@ -1,33 +1,34 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.rssin.rssin; -import android.content.Context; import android.util.Log; -import org.rssin.android.FeedSorterProvider; +import org.rssin.rss.FeedSorterProvider; +import org.rssin.android.SortedFeedItemContainer; import org.rssin.http.Fetcher; import org.rssin.listener.FallibleListener; import org.rssin.listener.RealtimeListener; import org.rssin.neurons.FeedSorter; import org.rssin.rss.FeedItem; import org.rssin.rss.FeedLoader; +import org.rssin.storage.StorageProvider; import java.util.ArrayList; import java.util.List; @@ -53,13 +54,13 @@ public class FeedLoaderAndSorter { * @param listener Listener for when the fetcher finishes */ public void getFilteredFeedItems( - Context context, + StorageProvider storageProvider, Fetcher fetcher, final RealtimeListener, Object> listener) { final List resultingItems = new ArrayList<>(); final Counter counter = new Counter(feeds.size()); Log.v("FLAS", "Counter has size " + feeds.size()); - final FeedSorter sorter = FeedSorterProvider.getInstance(context).getFeedSorter(); + final FeedSorter sorter = FeedSorterProvider.getInstance(storageProvider).getFeedSorter(); for (Feed feed : feeds) { Loader loader = new Loader( diff --git a/app/src/main/java/org/rssin/rssin/SortedFeedItemContainer.java b/app/src/main/java/org/rssin/rssin/SortedFeedItemContainer.java deleted file mode 100644 index bc2d373..0000000 --- a/app/src/main/java/org/rssin/rssin/SortedFeedItemContainer.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * RSSin - Clever RSS reader for Android - * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.rssin.rssin; - -import android.content.Context; - -import org.rssin.android.FeedSorterProvider; -import org.rssin.neurons.Feedback; -import org.rssin.neurons.TrainingCase; -import org.rssin.rss.FeedItem; - -import java.io.Serializable; - -/** - * @author Jos. - */ -public class SortedFeedItemContainer implements Comparable, Serializable { - private FeedItem feeditem; - - private long score = -1; - private TrainingCase trainingCase; - - public SortedFeedItemContainer(FeedItem feeditem) - { - this.feeditem = feeditem; - } - - public FeedItem getFeeditem() { - return feeditem; - } - - public boolean hasScore() { - return score != 0; - } - - public long getScore() { - return score; - } - - public void feedback(Context context, Feedback feedback) - { - if(trainingCase == null) - { - trainingCase = FeedSorterProvider.getInstance(context).getFeedSorter().feedback(getFeeditem(), feedback); - }else { - trainingCase.setFeedback(feedback); - } - } - - public void setScore(long score) { - this.score = score; - } - - @Override - public int compareTo(SortedFeedItemContainer another) { - return (int)(another.getScore() - this.getScore()); - } -} -- cgit v1.2.3