aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/rssin/android/FeedItemsListFragment.java43
-rw-r--r--app/src/main/java/org/rssin/neurons/NeuralNetwork.java42
-rw-r--r--app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java10
3 files changed, 49 insertions, 46 deletions
diff --git a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java
index d287884..f229098 100644
--- a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java
+++ b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java
@@ -94,27 +94,32 @@ public class FeedItemsListFragment extends Fragment {
loadingView.setVisibility(View.VISIBLE);
FeedLoaderAndSorter loaderAndSorter = new FeedLoaderAndSorter(feeds);
- loaderAndSorter.getFilteredFeedItems(
- DefaultStorageProvider.getInstance(context),
- VolleyFetcher.getInstance(context),
- new RealtimeListener<List<SortedFeedItemContainer>, Object>() {
- @Override
- public void finish() {
- loadingView.setVisibility(View.GONE);
- }
-
- @Override
- public void onReceive(List<SortedFeedItemContainer> data) {
- feedItemAdapter.feedItems = data;
- feedItemAdapter.notifyDataSetChanged();
- }
- @Override
- public void onError(Object error) {
- Frontend.error(context, R.string.error_net_load);
+ try {
+ loaderAndSorter.getFilteredFeedItems(
+ DefaultStorageProvider.getInstance(context),
+ VolleyFetcher.getInstance(context),
+ new RealtimeListener<List<SortedFeedItemContainer>, Object>() {
+ @Override
+ public void finish() {
+ loadingView.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onReceive(List<SortedFeedItemContainer> data) {
+ feedItemAdapter.feedItems = data;
+ feedItemAdapter.notifyDataSetChanged();
+ }
+
+ @Override
+ public void onError(Object error) {
+ Frontend.error(context, R.string.error_net_load);
+ }
}
- }
- );
+ );
+ } catch (Exception e) {
+ Frontend.error(context, R.string.error_unknown);
+ }
}
}
diff --git a/app/src/main/java/org/rssin/neurons/NeuralNetwork.java b/app/src/main/java/org/rssin/neurons/NeuralNetwork.java
index bd00dad..6164e06 100644
--- a/app/src/main/java/org/rssin/neurons/NeuralNetwork.java
+++ b/app/src/main/java/org/rssin/neurons/NeuralNetwork.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.neurons;
import android.annotation.SuppressLint;
@@ -77,7 +77,7 @@ class NeuralNetwork implements Serializable {
Neuron n = hiddenNodes[neuronNum];
double neuronOutput = 0;
- for (int i = 0; i < n.getWeightCount(); i++) {
+ for (int i = 0; i < n.getWeightCount() && i < inputs.length; i++) {
neuronOutput += n.getWeight(i) * inputs[i];
}
@@ -130,10 +130,10 @@ class NeuralNetwork implements Serializable {
final double learningRate = 0.2;
//Update input => hidden weights.
- for (int neuronNum = 0; neuronNum < hiddenNodes.length; neuronNum++) {
+ for (int neuronNum = 0; neuronNum < hiddenNodes.length && neuronNum < hiddenGradients.length; neuronNum++) {
Neuron n = hiddenNodes[neuronNum];
- for (int i = 0; i < n.getWeightCount(); i++) {
+ for (int i = 0; i < n.getWeightCount() && i < inputs.length; i++) {
//Calulate & apply delta
double delta = learningRate * hiddenGradients[neuronNum] * inputs[i];
n.adjustWeight(i, delta);
diff --git a/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java b/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java
index e561657..bd73538 100644
--- a/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java
+++ b/app/src/main/java/org/rssin/rssin/FeedLoaderAndSorter.java
@@ -117,13 +117,11 @@ public class FeedLoaderAndSorter {
synchronized (counter) {
counter.decr();
Log.v("FLAS", "Counter has size " + counter.count);
+ Log.v("FLAS", "Calling onReceive");
+ listener.onReceive(resultingItems);
if (counter.isZero()) {
- Log.v("FLAS", "Calling onReceive");
- listener.onReceive(resultingItems);
- if (counter.isZero()) {
- Log.v("FLAS", "Calling finish");
- ((RealtimeListener) listener).finish();
- }
+ Log.v("FLAS", "Calling finish");
+ ((RealtimeListener) listener).finish();
}
}
}