Skip to content

Commit

Permalink
refactor: FanboxParser -> FanboxUserParser
Browse files Browse the repository at this point in the history
  • Loading branch information
npofsi committed Sep 3, 2021
1 parent 6fadd1c commit 9263d41
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ jobs:
with:
automatic_release_tag: ${{ steps.tag_version.outputs.new_tag }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
prerelease: true
files: app/build/outputs/apk/debug/app-debug.apk
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# pixiv Fanbox viewer
# pixiv FanboxViewer

> The application is under development.
**__本应用仅可查看您已赞助(订阅)的创作者的内容与各创作者的公开内容!__**\
**__This application can only check the contents posted by creators you've donated to and public contents!__**

Any question related to this project you can either use issue or join my [telegram group](https://t.me/joinchat/KP2S20Y99ihwPaYeeHabBQ)\
任何关于本工程的问题可以用Issue提交或加入[我的电报群](https://t.me/joinchat/KP2S20Y99ihwPaYeeHabBQ)
### Download

[Github Release](https://github.com/709924470/FanboxViewer/releases)

---
Any question related to this project you can either use issue or join my [telegram group](https://t.me/joinchat/KP2S20Y99ihwPaYeeHabBQ)\
任何关于本工程的问题可以用Issue提交或加入[我的电报群](https://t.me/joinchat/KP2S20Y99ihwPaYeeHabBQ)

开发者很懒, 不想每次都在手机上打开网页再下载, 所以写了这个软件\
Developer is too lazy to open the web page and download them one by one,\
Expand All @@ -17,13 +21,15 @@ So he wrote this application
我可能在完成大多数功能之后再拐回来完善这里\
And he is too lazy to write a readme, too uwu\
Maybe he will complete here after he finished major features.
### MailList:

---

### MailList:

`[email protected]`
[![捐赠](https://img.shields.io/badge/捐赠-支付宝二维码-BLUE.svg)](https://api.qrserver.com/v1/create-qr-code/?size=320x320&data=https://qr.alipay.com/fkx09642afxf1dgxi5kwp19)
[![捐赠](https://img.shields.io/badge/捐赠-微信二维码-DARKGREEN.svg)](https://api.qrserver.com/v1/create-qr-code/?size=320x320&data=wxp://f2f0QA34gBTVa83jgkEgGrGiOuWQOtHMTxku)
[![捐赠](https://img.shields.io/badge/Donate-PayPal-DARKBLUE.svg)](https://paypal.me/7099Kii)
[![捐赠](https://img.shields.io/badge/Donate-Ko--fi-ORANGE.svg)](https://Ko-fi.com/709924470)

`npofsi` [![Blog](https://img.shields.io/badge/Blog-npofsi.pro-ORANGE.svg)](https://blog.npofsi.pro)
`npofsi@outlook.com` [![Blog](https://img.shields.io/badge/Blog-npofsi.pro-ORANGE.svg)](https://blog.npofsi.pro)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import cn.settile.fanboxviewer.Network.Bean.CardItem;
import cn.settile.fanboxviewer.Network.Bean.MessageItem;
import cn.settile.fanboxviewer.Adapters.RecyclerView.Main.AllPostsRecyclerViewAdapter;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser;
import cn.settile.fanboxviewer.R;


Expand Down Expand Up @@ -81,8 +81,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void refreshPosts(boolean refresh,boolean refreshAll){

Executors.newSingleThreadExecutor().submit(() -> {
List<CardItem> lci = FanboxParser.getAllPosts(refresh, ctx);
List<MessageItem> lmi = FanboxParser.getPlans();
List<CardItem> lci = FanboxUserParser.getAllPosts(refresh, ctx);
List<MessageItem> lmi = FanboxUserParser.getPlans();
getActivity().runOnUiThread(() -> srl.setRefreshing(false));
if (lci != null) {
updateList(lci, lmi, refreshAll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.viewpager.widget.ViewPager
import cn.settile.fanboxviewer.Adapters.Fragment.MainFragmentAdapter
import cn.settile.fanboxviewer.MainActivity
import cn.settile.fanboxviewer.Network.Common
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser
import cn.settile.fanboxviewer.Network.URLRequestor
import cn.settile.fanboxviewer.R
import cn.settile.fanboxviewer.Util.Constants
Expand Down Expand Up @@ -109,7 +109,7 @@ class MainTabFragment : Fragment(R.layout.fragment_main_tabs) {
val iconUrl = user.getString("iconUrl")
val userName = user.getString("name")
val userId = user.getString("userId")
val unread = FanboxParser.getUnreadMessagesCount()
val unread = FanboxUserParser.getUnreadMessagesCount()
requireActivity().runOnUiThread {
(requireActivity() as MainActivity).viewModel.update_user_info(
userName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import cn.settile.fanboxviewer.Network.Bean.MessageItem;
import cn.settile.fanboxviewer.Adapters.RecyclerView.Main.MessageRecyclerViewAdapter;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser;
import cn.settile.fanboxviewer.R;

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
}
srl.setRefreshing(true);
Executors.newSingleThreadExecutor().submit(() -> {
List<MessageItem> lmi = FanboxParser.getMessages(false);
List<MessageItem> lmi = FanboxUserParser.getMessages(false);
srl.setRefreshing(false);
if (lmi != null) {
update(false);
Expand All @@ -97,7 +97,7 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
});

srl.setOnRefreshListener(() -> Executors.newSingleThreadExecutor().submit(() -> {
List<MessageItem> lmi = FanboxParser.getMessages(true);
List<MessageItem> lmi = FanboxUserParser.getMessages(true);
srl.setRefreshing(false);
if (lmi != null) {
update(true);
Expand All @@ -112,7 +112,7 @@ public void update(boolean refreshAll) {
if (v == null || c == null) {
return;
}
Future<List<MessageItem>> flmi = Executors.newSingleThreadExecutor().submit(() -> FanboxParser.getMessages(refreshAll));
Future<List<MessageItem>> flmi = Executors.newSingleThreadExecutor().submit(() -> FanboxUserParser.getMessages(refreshAll));
new Handler().post(() -> {
while(!flmi.isDone()){}
List<MessageItem> lmi = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import cn.settile.fanboxviewer.Adapters.RecyclerView.Main.MessageRecyclerViewAdapter;
import cn.settile.fanboxviewer.Network.Bean.MessageItem;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;

import cn.settile.fanboxviewer.R;

public class NetworkErrorFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import cn.settile.fanboxviewer.Adapters.RecyclerView.Main.SubscribedPostsRecyclerViewAdapter;
import cn.settile.fanboxviewer.Network.Bean.CardItem;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser;
import cn.settile.fanboxviewer.R;


Expand Down Expand Up @@ -76,7 +76,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

public void refreshPosts(boolean refresh, boolean refreshAll) {
Executors.newSingleThreadExecutor().submit(() -> {
List<CardItem> lci = FanboxParser.getSupportingPosts(refresh, c);
List<CardItem> lci = FanboxUserParser.getSupportingPosts(refresh, c);
getActivity().runOnUiThread(() -> srl.setRefreshing(false));
if (lci != null) {
updateList(lci, refreshAll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import cn.settile.fanboxviewer.Adapters.RecyclerView.CardRecyclerViewAdapterBase;
import cn.settile.fanboxviewer.Network.Bean.CardItem;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser;
import cn.settile.fanboxviewer.R;
import lombok.Setter;

Expand All @@ -34,7 +34,7 @@ public class PostFragment extends Fragment {
private View v;
private RecyclerView recyclerView;
private SwipeRefreshLayout srl;

List<CardItem> lci;
public PostFragment() {
}

Expand All @@ -47,6 +47,11 @@ public static PostFragment newInstance() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
c = getActivity();
try {
lci = new FanboxUserParser(userID).getUserPosts();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
Expand All @@ -70,18 +75,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return;
}
srl.setRefreshing(true);
refreshPosts(false,false);
refreshPosts(false, false);
});
srl.setOnRefreshListener(() -> refreshPosts(false,true));
srl.setOnRefreshListener(() -> refreshPosts(false, true));
srl.setRefreshing(true);
refreshPosts(true,true);
refreshPosts(true, true);

return inflate;
}

public void refreshPosts(boolean refresh, boolean refreshAll) {
Executors.newSingleThreadExecutor().submit(() -> {
List<CardItem> lci = new FanboxParser(userID).getUserPosts();

getActivity().runOnUiThread(() -> srl.setRefreshing(false));
if (lci != null) {
updateList(lci, refreshAll);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/cn/settile/fanboxviewer/Network/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.concurrent.TimeUnit;

import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxAPI;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxParser;
import cn.settile.fanboxviewer.Network.RESTfulClient.FanboxUserParser;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -78,7 +78,7 @@ public static OkHttpClient initClient() {
.build();

FanboxAPI api = fanbox.create(FanboxAPI.class);
FanboxParser.client = api;
FanboxUserParser.client = api;
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlin.collections.HashMap
@Deprecated("")
@Slf4j
object FanboxParser {
private const val TAG = "FanboxParser"
private const val TAG = "FanboxUserParser"
public var userToName = HashMap<String, String?>()
var postToCover = HashMap<String, String?>()
var lastMessageList: List<MessageItem> = ArrayList()
Expand Down Expand Up @@ -249,90 +249,6 @@ object FanboxParser {
}
}

@SuppressLint("SimpleDateFormat")
fun getUserPosts(userId: String, useUrl: String?, c: Context): HashMap<Int, Any>? {
return try {
// android.util.Log.d("getPosts", (refresh ? "t" : "f") + (all ? "t" : "f"));
val lci: MutableList<CardItem> = ArrayList()
val posts: JSONArray
var tmp: JSONObject?
val nextUrl: String
if (useUrl == null) {
tmp = getJSON(getUrl(userId))
tmp = tmp!!.getJSONObject("body")
// tmp = tmp.getJSONObject("post");
posts = tmp.getJSONArray("items")
nextUrl = tmp.getString("nextUrl")
} else {
val refer = "https://www.pixiv.net/fanbox/creator/$userId/post"
tmp = getJSON(useUrl, refer)
tmp = tmp!!.getJSONObject("body")
posts = tmp.getJSONArray("items")
nextUrl = tmp.getString("nextUrl")
}
for (i in 0 until posts.length()) {
val json = posts.getJSONObject(i)
// android.util.Log.d("getPosts", i + " -> " + json.toString());
val title = json.getString("title")
val desc = json.getString("excerpt")
val fee = json.getInt("feeRequired")
val plan = if (fee == 0) c.getString(R.string.plan_public) else " ¥$fee "
val user = json.getJSONObject("user")
val userName = user.getString("name")
val pixivId = user.getString("userId")
var iconUrl = user.getString("iconUrl")
if (userToIcon[userId] == null) {
userToIcon[userId] = iconUrl
} else {
iconUrl = userToIcon[userId]
}
if (userToName[userId] == null) {
userToName[userId] = userName
}
var date = json.getString("updatedDatetime")
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ")
val sdf = SimpleDateFormat(c.getString(R.string.date_formatting))
date = sdf.format(df.parse(date))
var headerUrl = json.getString("coverImageUrl")
if (headerUrl == null || headerUrl == "null") {
val body = json.optJSONObject("body")
if (body != null) {
val image = body.optJSONArray("images")
if (image != null) {
headerUrl = image.getJSONObject(0).getString("thumbnailUrl")
}
}
}
val url = "https://fanbox.pixiv.net/api/post.info?postId=" + json.getString("id")
if (!postToCover.containsKey(json.getString("id"))) {
postToCover[json.getString("id")] =
headerUrl
}
lci.add(
CardItem(
iconUrl,
headerUrl,
url,
title,
desc,
userName,
date,
plan,
userId,
pixivId
)
)
}
val result = HashMap<Int, Any>()
result[0] = nextUrl
result[1] = lci
return result
} catch (ex: Exception) {
Log.e(TAG, "EXCEPTION: " + ex)
return null
}
}

@Throws(Exception::class)
fun getPostDetail(url: String?, c: Context): List<DetailItem> {
val items: MutableList<DetailItem> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import cn.settile.fanboxviewer.Network.Bean.MessageItem;
import cn.settile.fanboxviewer.App;
import cn.settile.fanboxviewer.BuildConfig;
import cn.settile.fanboxviewer.Network.Common;
import cn.settile.fanboxviewer.R;
import lombok.extern.slf4j.Slf4j;
import okhttp3.ResponseBody;
Expand All @@ -38,7 +37,7 @@
import static cn.settile.fanboxviewer.Util.Util.toList;

@Slf4j
public class FanboxParser {
public class FanboxUserParser {
private static final String TAG = "Parser";
public static FanboxAPI client = null;

Expand All @@ -49,8 +48,8 @@ public class FanboxParser {
private final Context c = App.getContext();
private String postNext = null;

public FanboxParser(String user) throws Exception {
if (Objects.equals(FanboxParser.client, null)){
public FanboxUserParser(String user) throws Exception {
if (Objects.equals(FanboxUserParser.client, null)){
throw new AssertionError("Set client first");
}
//client= Common.getClientInstance();
Expand Down Expand Up @@ -371,8 +370,8 @@ public static int getUnreadMessagesCount() throws Exception{
}

public static void setClient(FanboxAPI client){
if (Objects.equals(FanboxParser.client, null)){
FanboxParser.client = client;
if (Objects.equals(FanboxUserParser.client, null)){
FanboxUserParser.client = client;
}
}

Expand Down
Loading

0 comments on commit 9263d41

Please sign in to comment.