summaryrefslogtreecommitdiff
path: root/org.fox.ttrss
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2025-05-16 14:53:50 +0300
committerAndrew Dolgov <fox@fakecake.org>2025-05-16 14:53:50 +0300
commit362a726c87c8ffe1d4596d6e409dc5068f71bed8 (patch)
tree9973f1ad7a4fe5b9c40734fcde2024fec3d5d1ee /org.fox.ttrss
parent0aee78089a45fdf99f1d21a379b21ea5e66e65fb (diff)
update subscribe activity a bit, change it to use common feed object
Diffstat (limited to 'org.fox.ttrss')
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/ArticlePager.java2
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java1
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java1
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesEventListener.java1
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/share/CommonActivity.java1
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/share/SubscribeActivity.java80
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java1
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategory.java59
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategoryList.java42
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedList.java41
10 files changed, 34 insertions, 195 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticlePager.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticlePager.java
index cf43f4f0..52f78cf0 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticlePager.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticlePager.java
@@ -15,8 +15,8 @@ import androidx.viewpager2.widget.ViewPager2;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed;
-import org.fox.ttrss.util.DiffFragmentStateAdapter;
import org.fox.ttrss.util.ArticleDiffItemCallback;
+import org.fox.ttrss.util.DiffFragmentStateAdapter;
public class ArticlePager extends androidx.fragment.app.Fragment {
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java
index bca2aa40..500eccb9 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/DetailActivity.java
@@ -19,7 +19,6 @@ import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.fox.ttrss.types.Article;
-import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed;
public class DetailActivity extends OnlineActivity implements HeadlinesEventListener {
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java
index a0ab4f33..513eaeb7 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java
@@ -48,7 +48,6 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
-import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesEventListener.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesEventListener.java
index 27e00bbf..14215a83 100644
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesEventListener.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesEventListener.java
@@ -1,7 +1,6 @@
package org.fox.ttrss;
import org.fox.ttrss.types.Article;
-import org.fox.ttrss.types.ArticleList;
public interface HeadlinesEventListener {
void onArticleListSelectionChange();
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/share/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/share/CommonActivity.java
index 9c9187d9..7ece9e4f 100644
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/share/CommonActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/share/CommonActivity.java
@@ -1,7 +1,6 @@
package org.fox.ttrss.share;
import android.app.Activity;
-import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.widget.Toast;
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/share/SubscribeActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/share/SubscribeActivity.java
index 82e2d52d..b894f213 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/share/SubscribeActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/share/SubscribeActivity.java
@@ -1,5 +1,6 @@
package org.fox.ttrss.share;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -21,16 +22,15 @@ import com.google.gson.reflect.TypeToken;
import org.fox.ttrss.ApiCommon;
import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.R;
-import org.fox.ttrss.types.FeedCategory;
-import org.fox.ttrss.types.FeedCategoryList;
+import org.fox.ttrss.types.Feed;
import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
public class SubscribeActivity extends CommonShareActivity {
private final String TAG = this.getClass().getSimpleName();
@@ -39,17 +39,17 @@ public class SubscribeActivity extends CommonShareActivity {
private Button m_catButton;
private CatListAdapter m_catAdapter;
private FeedListAdapter m_feedAdapter;
- private final FeedCategoryList m_cats = new FeedCategoryList();
+ private final List<Feed> m_cats = new ArrayList<>();
private final ArrayList<Map.Entry<String, JsonElement>> m_feeds = new ArrayList<>();
private ProgressBar m_progressBar;
private static final int REQ_CATS = 1;
private static final int REQ_POST = 2;
- static class CatTitleComparator implements Comparator<FeedCategory> {
+ static class TitleComparator implements Comparator<Feed> {
@Override
- public int compare(FeedCategory a, FeedCategory b) {
+ public int compare(Feed a, Feed b) {
if (a.id >= 0 && b.id >= 0)
return a.title.compareTo(b.title);
else
@@ -59,13 +59,10 @@ public class SubscribeActivity extends CommonShareActivity {
}
public void sortCats() {
- Comparator<FeedCategory> cmp = new CatTitleComparator();
-
- Collections.sort(m_cats, cmp);
- try {
+
+ if (m_catAdapter != null) {
+ m_cats.sort(new TitleComparator());
m_catAdapter.notifyDataSetChanged();
- } catch (NullPointerException e) {
- // adapter missing
}
}
@@ -82,30 +79,26 @@ public class SubscribeActivity extends CommonShareActivity {
if (savedInstanceState != null) {
urlValue = savedInstanceState.getString("url");
-
- ArrayList<FeedCategory> list = savedInstanceState.getParcelableArrayList("cats");
-
- m_cats.addAll(list);
}
setContentView(R.layout.activity_subscribe);
setSmallScreen(false);
- m_progressBar = (ProgressBar) findViewById(R.id.subscribe_progress);
- Spinner catList = (Spinner) findViewById(R.id.category_spinner);
+ m_progressBar = findViewById(R.id.subscribe_progress);
+ Spinner catList = findViewById(R.id.category_spinner);
- if (m_cats.isEmpty()) m_cats.add(new FeedCategory(0, "Uncategorized", 0));
+ if (m_cats.isEmpty()) m_cats.add(new Feed(0, "Uncategorized", true));
m_catAdapter = new CatListAdapter(this, android.R.layout.simple_spinner_dropdown_item, m_cats);
catList.setAdapter(m_catAdapter);
- final Spinner feedList = (Spinner) findViewById(R.id.feed_spinner);
+ final Spinner feedList = findViewById(R.id.feed_spinner);
feedList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String feed = m_feedAdapter.getItemURL(position);
- EditText feedUrl = (EditText) findViewById(R.id.feed_url);
+ EditText feedUrl = findViewById(R.id.feed_url);
if (feed != null && feedUrl != null) {
feedUrl.setText(feed);
@@ -140,24 +133,22 @@ public class SubscribeActivity extends CommonShareActivity {
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
- EditText url = (EditText) findViewById(R.id.url);
+ EditText url = findViewById(R.id.url);
if (url != null) {
out.putString("url", url.getText().toString());
}
-
- out.putParcelableArrayList("cats", m_cats);
}
private void subscribeToFeed() {
m_postButton.setEnabled(false);
- ApiRequest req = new ApiRequest(getApplicationContext()) {
+ @SuppressLint("StaticFieldLeak") ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
m_progressBar.setVisibility(View.INVISIBLE);
- if (m_lastError != ApiCommon.ApiError.UNKNOWN_ERROR) {
+ if (m_lastError != null && m_lastError != ApiCommon.ApiError.SUCCESS) {
toast(getErrorMessage());
} else {
try {
@@ -166,7 +157,7 @@ public class SubscribeActivity extends CommonShareActivity {
try {
rc = result.getAsJsonObject().get("status").getAsJsonObject().get("code").getAsInt();
} catch (Exception e) {
- e.printStackTrace();
+ toast(e.getMessage());
}
switch (rc) {
@@ -212,8 +203,7 @@ public class SubscribeActivity extends CommonShareActivity {
}
} catch (Exception e) {
- toast(R.string.error_while_subscribing);
- e.printStackTrace();
+ toast(e.getMessage());
}
}
@@ -221,10 +211,10 @@ public class SubscribeActivity extends CommonShareActivity {
}
};
- Spinner catSpinner = (Spinner) findViewById(R.id.category_spinner);
+ Spinner catSpinner = findViewById(R.id.category_spinner);
- final FeedCategory cat = (FeedCategory) m_catAdapter.getCategory(catSpinner.getSelectedItemPosition());
- final EditText feedUrl = (EditText) findViewById(R.id.feed_url);
+ final Feed cat = m_catAdapter.getCategory(catSpinner.getSelectedItemPosition());
+ final EditText feedUrl = findViewById(R.id.feed_url);
if (feedUrl != null ) {
HashMap<String, String> map = new HashMap<>();
@@ -255,29 +245,25 @@ public class SubscribeActivity extends CommonShareActivity {
}
private void updateCats() {
- ApiRequest req = new ApiRequest(getApplicationContext()) {
+ @SuppressLint("StaticFieldLeak") ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
m_progressBar.setVisibility(View.INVISIBLE);
- if (m_lastError != ApiCommon.ApiError.UNKNOWN_ERROR) {
+ if (m_lastError != null && m_lastError != ApiCommon.ApiError.SUCCESS) {
toast(getErrorMessage());
} else {
JsonArray content = result.getAsJsonArray();
if (content != null) {
- Type listType = new TypeToken<List<FeedCategory>>() {}.getType();
- final List<FeedCategory> cats = new Gson().fromJson(content, listType);
-
+ Type listType = new TypeToken<List<Feed>>() {}.getType();
+ final List<Feed> catsJson = new Gson().fromJson(content, listType);
+
m_cats.clear();
-
- for (FeedCategory c : cats) {
- if (c.id > 0)
- m_cats.add(c);
- }
-
+ m_cats.addAll(catsJson.stream().filter(f -> f.id > 0).collect(Collectors.toList()));
+
sortCats();
- m_cats.add(0, new FeedCategory(0, "Uncategorized", 0));
+ m_cats.add(0, new Feed(0, "Uncategorized", true));
m_catAdapter.notifyDataSetChanged();
@@ -316,10 +302,10 @@ public class SubscribeActivity extends CommonShareActivity {
}
private static class CatListAdapter extends ArrayAdapter<String> {
- private final List<FeedCategory> m_items;
+ private final List<Feed> m_items;
public CatListAdapter(Context context, int resource,
- List<FeedCategory> items) {
+ List<Feed> items) {
super(context, resource);
m_items = items;
@@ -330,7 +316,7 @@ public class SubscribeActivity extends CommonShareActivity {
return m_items.get(item).title;
}
- public FeedCategory getCategory(int item) {
+ public Feed getCategory(int item) {
try {
return m_items.get(item);
} catch (ArrayIndexOutOfBoundsException e) {
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
index 6724acb0..8a8a763f 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
@@ -1,6 +1,5 @@
package org.fox.ttrss.types;
-import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategory.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategory.java
deleted file mode 100644
index e9b4b489..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategory.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.fox.ttrss.types;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-@Deprecated
-public class FeedCategory implements Parcelable {
- public int id;
- public String title;
- public int unread;
- public int order_id;
-
- public FeedCategory(Parcel in) {
- readFromParcel(in);
- }
-
- public FeedCategory(int id, String title, int unread) {
- this.id = id;
- this.title = title;
- this.unread = unread;
- this.order_id = 0;
- }
-
- public FeedCategory() {
-
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- out.writeInt(id);
- out.writeString(title);
- out.writeInt(unread);
- out.writeInt(order_id);
- }
-
- public void readFromParcel(Parcel in) {
- id = in.readInt();
- title = in.readString();
- unread = in.readInt();
- order_id = in.readInt();
- }
-
- @SuppressWarnings("rawtypes")
- public static final Parcelable.Creator CREATOR =
- new Parcelable.Creator() {
- public FeedCategory createFromParcel(Parcel in) {
- return new FeedCategory(in);
- }
-
- public FeedCategory[] newArray(int size) {
- return new FeedCategory[size];
- }
- };
-}
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategoryList.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategoryList.java
deleted file mode 100644
index b5a3a935..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedCategoryList.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.fox.ttrss.types;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.util.ArrayList;
-
-@Deprecated
-public class FeedCategoryList extends ArrayList<FeedCategory> implements Parcelable {
-
- public FeedCategoryList() { }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- out.writeList(this);
- }
-
- public void readFromParcel(Parcel in) {
- in.readList(this, getClass().getClassLoader());
- }
-
- public FeedCategoryList(Parcel in) {
- readFromParcel(in);
- }
-
- @SuppressWarnings("rawtypes")
- public static final Parcelable.Creator CREATOR =
- new Parcelable.Creator() {
- public FeedCategoryList createFromParcel(Parcel in) {
- return new FeedCategoryList(in);
- }
-
- public FeedCategoryList[] newArray(int size) {
- return new FeedCategoryList[size];
- }
- };
- }
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedList.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedList.java
deleted file mode 100644
index 08164361..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/FeedList.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.fox.ttrss.types;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.util.ArrayList;
-
-public class FeedList extends ArrayList<Feed> implements Parcelable {
-
- public FeedList() { }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- out.writeList(this);
- }
-
- public void readFromParcel(Parcel in) {
- in.readList(this, getClass().getClassLoader());
- }
-
- public FeedList(Parcel in) {
- readFromParcel(in);
- }
-
- @SuppressWarnings("rawtypes")
- public static final Parcelable.Creator CREATOR =
- new Parcelable.Creator() {
- public FeedList createFromParcel(Parcel in) {
- return new FeedList(in);
- }
-
- public FeedList[] newArray(int size) {
- return new FeedList[size];
- }
- };
- }