mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-06-03 00:58:06 -04:00
添加jellyfin client
This commit is contained in:
parent
a61f82ab19
commit
12a2e96926
@ -24,7 +24,6 @@ import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
|
|||||||
|
|
||||||
public class CollectionActivity extends BaseActivity {
|
public class CollectionActivity extends BaseActivity {
|
||||||
private String TAG = "CollectionActivity";
|
private String TAG = "CollectionActivity";
|
||||||
private Activity mActivity = null;
|
|
||||||
private TvRecyclerView mGridContiner = null;
|
private TvRecyclerView mGridContiner = null;
|
||||||
private TextView tvTitleTip = null;
|
private TextView tvTitleTip = null;
|
||||||
private String ItemId = "";
|
private String ItemId = "";
|
||||||
@ -46,11 +45,10 @@ public class CollectionActivity extends BaseActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_collection);
|
setContentView(R.layout.activity_collection);
|
||||||
|
|
||||||
if (Utils.UserId.equals("") || Utils.AccessToken.equals("")) {
|
if (JfClient.UserId.equals("") || JfClient.AccessToken.equals("")) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
mActivity = this;
|
|
||||||
mGridContiner = findViewById(R.id.mGridView);
|
mGridContiner = findViewById(R.id.mGridView);
|
||||||
tvTitleTip = findViewById(R.id.activeBar_titleTip);
|
tvTitleTip = findViewById(R.id.activeBar_titleTip);
|
||||||
V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(this,6);
|
V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(this,6);
|
||||||
@ -69,73 +67,41 @@ public class CollectionActivity extends BaseActivity {
|
|||||||
currAdapter = getJAdapter(currItems);
|
currAdapter = getJAdapter(currItems);
|
||||||
mGridContiner.setAdapter(currAdapter);
|
mGridContiner.setAdapter(currAdapter);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
initData();
|
initData();
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
initSortByMenu();
|
initSortByMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initData() {
|
public void initData() {
|
||||||
String url = "/Users/" + Utils.UserId + "/Items/" + ItemId;
|
showLoadingDialog("加载中…………");
|
||||||
String CollectionStr = Utils.okhttpSend(url);
|
JfClient.GetItemInfo(ItemId,new JfClient.JJCallBack(){
|
||||||
JsonObject Collection = Utils.JsonToObj(CollectionStr,JsonObject.class);
|
@Override
|
||||||
if (null != Collection) {
|
public void onSuccess(JsonObject Collection) {
|
||||||
currObj = Collection;
|
currObj = Collection;
|
||||||
Type = Utils.getJsonString(Collection,"CollectionType").getAsString();
|
Type = JfClient.strFromGson(Collection,"CollectionType");
|
||||||
fillItems();
|
fillItems();
|
||||||
setLoadMore();
|
setLoadMore();
|
||||||
}else{
|
|
||||||
ShowToask("加载失败!");
|
|
||||||
}
|
}
|
||||||
|
},null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载条目数据
|
* 加载条目数据
|
||||||
*/
|
*/
|
||||||
private void fillItems(){
|
private void fillItems(){
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
JfClient.GetCollection(ItemId,Type,JfClient.config.getSortBy(),JfClient.config.getSortOrder(),limit,currentPage,new JfClient.JJCallBack(){
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void onSuccess(JsonObject items) {
|
||||||
showLoadingDialog();
|
totalCount = JfClient.jeFromGson(items,"TotalRecordCount").getAsInt();
|
||||||
}
|
|
||||||
});
|
|
||||||
String ItemsUrl = "/Users/" + Utils.UserId + "/Items?ParentId=" + ItemId + "&Limit=" + limit;
|
|
||||||
ItemsUrl += "&Recursive=true&Fields=PrimaryImageAspectRatio,BasicSyncInfo,Seasons,Episodes&ImageTypeLimit=1";
|
|
||||||
ItemsUrl += "&EnableImageTypes=Primary,Backdrop,Banner,Thumb";
|
|
||||||
ItemsUrl += "&SortBy="+Utils.config.getSortBy()+"%2CSortName%2CProductionYear&SortOrder=" + Utils.config.getSortOrder();
|
|
||||||
if (Type.equals("tvshows")) {
|
|
||||||
ItemsUrl += "&IncludeItemTypes=Series";
|
|
||||||
} else if (Type.equals("movies")) {
|
|
||||||
ItemsUrl += "&IncludeItemTypes=Movie";
|
|
||||||
} else {
|
|
||||||
ItemsUrl += "&IncludeItemTypes=Movie,Series";
|
|
||||||
}
|
|
||||||
int startIndex = currentPage * limit - limit;
|
|
||||||
ItemsUrl += "&StartIndex=" + startIndex;
|
|
||||||
String ItemsStr = Utils.okhttpSend(ItemsUrl);
|
|
||||||
JsonObject ItemsObj = Utils.JsonToObj(ItemsStr,JsonObject.class);
|
|
||||||
if (null != ItemsStr) {
|
|
||||||
totalCount = Utils.getJsonString(ItemsObj,"TotalRecordCount").getAsInt();
|
|
||||||
countPage = (int) Math.ceil((double) totalCount / limit);
|
countPage = (int) Math.ceil((double) totalCount / limit);
|
||||||
|
JsonArray Items = items.get("Items").getAsJsonArray();
|
||||||
JsonArray Items = ItemsObj.get("Items").getAsJsonArray();
|
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
dismissLoadingDialog();
|
dismissLoadingDialog();
|
||||||
currAdapter.addItems(Items);
|
currAdapter.addItems(Items);
|
||||||
setTitleTip();
|
setTitleTip();
|
||||||
mGridContiner.finishLoadMore();
|
mGridContiner.finishLoadMore();
|
||||||
}
|
}
|
||||||
});
|
},null);
|
||||||
}else{
|
|
||||||
ShowToask("加载明细失败!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JAdapter getJAdapter(JsonArray items){
|
private JAdapter getJAdapter(JsonArray items){
|
||||||
@ -147,12 +113,12 @@ public class CollectionActivity extends BaseActivity {
|
|||||||
String itemId = jo.get("Id").getAsString();
|
String itemId = jo.get("Id").getAsString();
|
||||||
Intent intent = null;
|
Intent intent = null;
|
||||||
if(type.equals("Folder") || type.equals("CollectionFolder")){
|
if(type.equals("Folder") || type.equals("CollectionFolder")){
|
||||||
intent = new Intent(mActivity,CollectionActivity.class);
|
intent = new Intent(mAA,CollectionActivity.class);
|
||||||
}else{
|
}else{
|
||||||
intent = new Intent(mActivity,DetailActivity.class);
|
intent = new Intent(mAA,DetailActivity.class);
|
||||||
}
|
}
|
||||||
intent.putExtra("itemId",itemId);
|
intent.putExtra("itemId",itemId);
|
||||||
mActivity.startActivity(intent);
|
mAA.startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return jAdapter;
|
return jAdapter;
|
||||||
|
@ -1,189 +0,0 @@
|
|||||||
package org.sifacai.vlcjellyfin;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.PopupMenu;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.owen.tvrecyclerview.widget.TvRecyclerView;
|
|
||||||
import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
|
|
||||||
|
|
||||||
public class CollectionActivity2 extends BaseActivity{
|
|
||||||
private String TAG = "CollectionActivity";
|
|
||||||
private Activity mActivity = null;
|
|
||||||
private TvRecyclerView mGridContiner = null;
|
|
||||||
private TextView tvTitleTip = null;
|
|
||||||
private String ItemId = "";
|
|
||||||
private int currentPage = 1; //当前页码
|
|
||||||
private int countPage = 1; //总页数
|
|
||||||
private int limit = 60; //每页条目
|
|
||||||
private int totalCount = 0; //总条目数
|
|
||||||
private String Type = "";
|
|
||||||
private JsonObject currObj = null;
|
|
||||||
private JsonArray currItems = null;
|
|
||||||
private JAdapter currAdapter = null;
|
|
||||||
|
|
||||||
private TextView sortMenuBtn;
|
|
||||||
|
|
||||||
private PopupMenu SortByMenu;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_collection);
|
|
||||||
|
|
||||||
if (JfClient.UserId.equals("") || JfClient.AccessToken.equals("")) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
mGridContiner = findViewById(R.id.mGridView);
|
|
||||||
tvTitleTip = findViewById(R.id.activeBar_titleTip);
|
|
||||||
V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(this,6);
|
|
||||||
mGridContiner.setLayoutManager(v7GridLayoutManager);
|
|
||||||
mGridContiner.setItemAnimator(null); //防崩溃
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
Intent intent = getIntent();
|
|
||||||
ItemId = intent.getStringExtra("itemId");
|
|
||||||
if(ItemId.equals("")){
|
|
||||||
finish();
|
|
||||||
}else{
|
|
||||||
currItems = new JsonArray();
|
|
||||||
currAdapter = getJAdapter(currItems);
|
|
||||||
mGridContiner.setAdapter(currAdapter);
|
|
||||||
|
|
||||||
initData();
|
|
||||||
initSortByMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initData() {
|
|
||||||
JfClient.GetItemInfo(ItemId,new JfClient.JJCallBack(){
|
|
||||||
@Override
|
|
||||||
public void onSuccess(JsonObject Collection) {
|
|
||||||
currObj = Collection;
|
|
||||||
Type = JfClient.strFromGson(Collection,"CollectionType");
|
|
||||||
fillItems();
|
|
||||||
setLoadMore();
|
|
||||||
}
|
|
||||||
},null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载条目数据
|
|
||||||
*/
|
|
||||||
private void fillItems(){
|
|
||||||
showLoadingDialog("加载中…………");
|
|
||||||
JfClient.GetCollection(ItemId,Type,JfClient.config.getSortBy(),JfClient.config.getSortOrder(),limit,currentPage,new JfClient.JJCallBack(){
|
|
||||||
@Override
|
|
||||||
public void onSuccess(JsonObject items) {
|
|
||||||
totalCount = JfClient.jeFromGson(items,"TotalRecordCount").getAsInt();
|
|
||||||
countPage = (int) Math.ceil((double) totalCount / limit);
|
|
||||||
JsonArray Items = items.get("Items").getAsJsonArray();
|
|
||||||
dismissLoadingDialog();
|
|
||||||
currAdapter.addItems(Items);
|
|
||||||
setTitleTip();
|
|
||||||
mGridContiner.finishLoadMore();
|
|
||||||
}
|
|
||||||
},null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setLoadMore(){
|
|
||||||
mGridContiner.setOnLoadMoreListener(new TvRecyclerView.OnLoadMoreListener() {
|
|
||||||
@Override
|
|
||||||
public void onLoadMore() {
|
|
||||||
if(currentPage < countPage){
|
|
||||||
currentPage += 1;
|
|
||||||
fillItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTitleTip(){
|
|
||||||
String tip = "共 "+ totalCount +" ," + countPage + " 页,已加载" + currentPage + "页";
|
|
||||||
tvTitleTip.setText(tip);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JAdapter getJAdapter(JsonArray items){
|
|
||||||
JAdapter jAdapter = new JAdapter(items,false);
|
|
||||||
jAdapter.setOnItemClickListener(new JAdapter.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(JsonObject jo) {
|
|
||||||
String type = JfClient.strFromGson(jo,"Type");
|
|
||||||
String itemId = jo.get("Id").getAsString();
|
|
||||||
Intent intent = null;
|
|
||||||
if(type.equals("Folder") || type.equals("CollectionFolder")){
|
|
||||||
intent = new Intent(mActivity,CollectionActivity.class);
|
|
||||||
}else{
|
|
||||||
intent = new Intent(mActivity,DetailActivity.class);
|
|
||||||
}
|
|
||||||
intent.putExtra("itemId",itemId);
|
|
||||||
mActivity.startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return jAdapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initSortByMenu(){
|
|
||||||
sortMenuBtn = findViewById(R.id.activeBar_sortBtn);
|
|
||||||
sortMenuBtn.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
int i = 0;
|
|
||||||
for(Config.SortByType sbt : Config.SortByType.values()){
|
|
||||||
if(sbt.value.equals(Utils.config.getSortBy())){
|
|
||||||
i = sbt.ordinal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SortByMenu.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
sortMenuBtn.setVisibility(View.VISIBLE);
|
|
||||||
setSortMenuBtnText();
|
|
||||||
SortByMenu = new PopupMenu(this,sortMenuBtn);
|
|
||||||
Menu menu = SortByMenu.getMenu();
|
|
||||||
Config.SortByType[] Ss = Config.SortByType.values();
|
|
||||||
for (Config.SortByType sortby:Ss) {
|
|
||||||
menu.add(0,sortby.ordinal(),sortby.ordinal(),sortby.name());
|
|
||||||
}
|
|
||||||
for (Config.SotrOrderType sot:Config.SotrOrderType.values()){
|
|
||||||
menu.add(1,sot.ordinal() + Ss.length,sot.ordinal() + Ss.length,sot.name());
|
|
||||||
}
|
|
||||||
SortByMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
|
||||||
if(menuItem.getGroupId() == 0) {
|
|
||||||
Utils.config.setSortBy(Config.SortByType.valueOf(menuItem.getTitle().toString()).value);
|
|
||||||
}else{
|
|
||||||
Utils.config.setSortOrder(Config.SotrOrderType.valueOf(menuItem.getTitle().toString()).value);
|
|
||||||
}
|
|
||||||
setSortMenuBtnText();
|
|
||||||
currAdapter.clearItems();
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
initData();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSortMenuBtnText(){
|
|
||||||
String s = Config.SortByType.findName(Utils.config.getSortBy());
|
|
||||||
s += "-";
|
|
||||||
s += Config.SotrOrderType.findName(Utils.config.getSortOrder());
|
|
||||||
sortMenuBtn.setText(s);
|
|
||||||
}
|
|
||||||
}
|
|
@ -177,7 +177,7 @@ public class HomeActivity extends BaseActivity{
|
|||||||
String itemId = jo.get("Id").getAsString();
|
String itemId = jo.get("Id").getAsString();
|
||||||
Intent intent = null;
|
Intent intent = null;
|
||||||
if (type.equals("Folder") || type.equals("CollectionFolder")) {
|
if (type.equals("Folder") || type.equals("CollectionFolder")) {
|
||||||
intent = new Intent(mAA, CollectionActivity2.class);
|
intent = new Intent(mAA, CollectionActivity.class);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(mAA, DetailActivity.class);
|
intent = new Intent(mAA, DetailActivity.class);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user