优化详情页

This commit is contained in:
sifacaii 2022-09-01 20:08:13 +08:00
parent 691d1132dd
commit 3730f712ab
4 changed files with 76 additions and 84 deletions

View File

@ -107,7 +107,7 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
String Genres = String.join(",", details.getGenres());
tvTitle.setText(Name);
tvDetails.append(details.getProductionYear().equals("") ? "" : "年份:" + details.getProductionYear() + " ");
tvDetails.append(details.getProductionYear() == null ? "" : "年份:" + details.getProductionYear() + " ");
tvDetails.append(Genres.equals("") ? "" : "风格:" + Genres + "\n");
tvDetails.append(details.getCommunityRating() == null ? "" : "评分:" + details.getCommunityRating() + " ");
tvDetails.append(details.getOfficialRating() == null ? "" : "评级:" + details.getOfficialRating() + "\n");
@ -133,8 +133,8 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
tvDetails.append(audio.equals("") ? "" : "音频:" + audio + "\n");
tvDetails.append(subtitle.equals("") ? "" : "字幕:" + subtitle + "\n");
}
tvDetails.append("简介: " + Html.fromHtml(details.getOverview()));
String overview = details.getOverview() == null ? "" : details.getOverview();
tvDetails.append("简介: " + Html.fromHtml(overview));
//填充列表
String type = details.getType();
@ -150,10 +150,8 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
} else if (type.equals("Movie")) {
fillMovie(details);
} else if (type.equals("Person")) {
String ProductionLocations = details.getProductionLocations().toString();
String PremiereDate = String.join(",", details.getPremiereDate());
tvDetails.append("\n出生日期" + Utils.UtcToLocal(PremiereDate) + "\n");
tvDetails.append("出生地:" + (ProductionLocations == null ? "" : ProductionLocations));
tvDetails.append("\n出生日期" + Utils.UtcToLocal(details.getPremiereDate()) + "\n");
tvDetails.append("出生地:" + String.join(",",details.getProductionLocations()));
fillItemsByPerson(Id);
}
@ -346,7 +344,7 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
this.startActivity(intent);
}
private JfClient.JJCallBack errcb = new JfClient.JJCallBack(){
private JfClient.JJCallBack errcb = new JfClient.JJCallBack() {
@Override
public void onError(String str) {
ShowToask(str);

View File

@ -24,7 +24,7 @@ import org.sifacai.vlcjellyfin.Bean.Items;
import java.util.List;
public class HomeActivity extends BaseActivity{
public class HomeActivity extends BaseActivity {
private final String TAG = "HomeActivity";
private LinearLayout tvContiner;
@ -39,45 +39,40 @@ public class HomeActivity extends BaseActivity{
JfClient.init(getApplication());
Log.d(TAG, "onCreate: " + JfClient.config.getJellyfinUrl());
if(JfClient.AccessToken.equals("") ||JfClient.UserId.equals("")){
if (JfClient.AccessToken.equals("") || JfClient.UserId.equals("")) {
showLoadingDialog("正在验证服务器地址!");
JfClient.VerityServerUrl(JfClient.config.getJellyfinUrl(),new JfClient.JJCallBack(){
JfClient.VerityServerUrl(JfClient.config.getJellyfinUrl(), new JfClient.JJCallBack() {
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
if(bool){
showLoadingDialog("正在验证用户名和密码!");
JfClient.AuthenticateByName(JfClient.config.getUserName(),JfClient.config.getPassWord(),new JfClient.JJCallBack(){
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
if(bool){
initView(); //加载首页
}else{
showLoginDialog();
}
}
},null,false);
}else{
ShowToask("服务器地址不正确!");
showLoginDialog();
}
setLoadingText("正在验证用户名和密码!");
JfClient.AuthenticateByName(JfClient.config.getUserName(), JfClient.config.getPassWord(), new JfClient.JJCallBack() {
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
initView();
}
}, connErr, false);
}
},new JfClient.JJCallBack(){
@Override
public void onError(String str) {
dismissLoadingDialog();
ShowToask("服务器连接失败!");
showLoginDialog();
}
});
}else{
initView();
}, connErr);
}
}
private void showLoginDialog(){
private JfClient.JJCallBack connErr = new JfClient.JJCallBack() {
@Override
public void onError(String str) {
dismissLoadingDialog();
ShowToask(str);
showLoginDialog();
}
};
@Override
protected void onResume() {
super.onResume();
initView();
}
private void showLoginDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alert = builder.setTitle("登录")
.setMessage("请输入登录信息")
@ -103,29 +98,27 @@ public class HomeActivity extends BaseActivity{
@Override
public void onClick(View view) {
showLoadingDialog("正在验证服务器地址!");
JfClient.VerityServerUrl(urlbox.getText().toString(),new JfClient.JJCallBack(){
JfClient.VerityServerUrl(urlbox.getText().toString(), new JfClient.JJCallBack() {
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
if(bool){
showLoadingDialog("正在验证用户名和密码!");
JfClient.AuthenticateByName(unbox.getText().toString(),pwbox.getText().toString(),new JfClient.JJCallBack(){
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
if(bool){
alert.dismiss();
initView(); //加载首页
}else{
ShowToask("用户名密码不正确!");
}
}
},null,saveBox.isChecked());
}else{
ShowToask("服务器地址不正确!");
}
setLoadingText("正在验证用户名和密码!");
JfClient.AuthenticateByName(unbox.getText().toString(), pwbox.getText().toString(), new JfClient.JJCallBack() {
@Override
public void onSuccess(Boolean bool) {
dismissLoadingDialog();
alert.dismiss();
initView(); //加载首页
}
}, new JfClient.JJCallBack(){
@Override
public void onError(String str) {
dismissLoadingDialog();
ShowToask("用户名密码验证失败!");
}
}, saveBox.isChecked());
}
},new JfClient.JJCallBack(){
}, new JfClient.JJCallBack() {
@Override
public void onError(String str) {
dismissLoadingDialog();
@ -137,31 +130,31 @@ public class HomeActivity extends BaseActivity{
}
private void initView(){
private void initView() {
showLoadingDialog("正在加载首页…………");
JfClient.GetViews(new JfClient.JJCallBack(){
JfClient.GetViews(new JfClient.JJCallBack() {
@Override
public void onSuccess(Items views) {
List<Item> items = views.getItems();
addRowTvRecyclerView("我的媒体", items, true);
for(int i=0;i<items.size();i++){
for (int i = 0; i < items.size(); i++) {
Item item = items.get(i);
JfClient.GetLatest(item.getId(),new JfClient.JJCallBack(){
JfClient.GetLatest(item.getId(), new JfClient.JJCallBack() {
@Override
public void onSuccess(Items latests) {
addRowTvRecyclerView("新的 " + item.getName(),latests.getItems(),false);
addRowTvRecyclerView("新的 " + item.getName(), latests.getItems(), false);
}
},null);
}, null);
}
dismissLoadingDialog();
}
},null);
JfClient.GetResume(new JfClient.JJCallBack(){
}, null);
JfClient.GetResume(new JfClient.JJCallBack() {
@Override
public void onSuccess(Items resumes) {
addRowTvRecyclerView("最近播放",resumes.getItems(),false);
addRowTvRecyclerView("最近播放", resumes.getItems(), false);
}
},null);
}, null);
}
@ -207,6 +200,7 @@ public class HomeActivity extends BaseActivity{
}
private long exitTime = 0;
public void exit() {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序",

View File

@ -411,8 +411,8 @@ public class JfClient {
SendPost(url, reqjson, new JJCallBack() {
@Override
public void onSuccess(String str) {
JsonObject userObj = new Gson().fromJson(str, JsonObject.class);
if (userObj != null) {
try {
JsonObject userObj = new Gson().fromJson(str, JsonObject.class);
if (userObj.has("User") && userObj.has("AccessToken")) {
String userId = userObj.get("User").getAsJsonObject().get("Id").getAsString();
String Token = userObj.get("AccessToken").getAsString();
@ -426,13 +426,13 @@ public class JfClient {
SetHeaders();
cb.onSuccess(true);
} else {
cb.onSuccess(false);
err.onError("验证失败:" + str);
}
} else {
err.onError("验证失败:" + str);
}
} else {
cb.onSuccess(false);
} catch (Exception e) {
err.onError("验证失败:" + e.getMessage());
}
}
}, err);
@ -466,25 +466,24 @@ public class JfClient {
SendGet(url + "/system/info/public", new JJCallBack() {
@Override
public void onSuccess(String str) {
JsonObject serverInfo = new Gson().fromJson(str, JsonObject.class);
Log.d(TAG, "onSuccess: " + str);
String ServerId = "";
if (serverInfo.has("Id")) {
try {
JsonObject serverInfo = new Gson().fromJson(str, JsonObject.class);
String ServerId = "";
ServerId = serverInfo.get("Id").getAsString();
if (ServerId == null || ServerId.length() == 0) {
cb.onSuccess(false);
err.onError("服务器连接失败!");
} else {
config.setJellyfinUrl(url);
cb.onSuccess(true);
}
} else {
err.onError("联系服务器失败!");
} catch (Exception e) {
err.onError(e.getMessage());
}
}
}, err);
}
} else {
cb.onSuccess(false);
err.onError("服务器地址不能为空!");
}
}

View File

@ -45,6 +45,7 @@ public class Utils {
* @return
*/
public static String UtcToLocal(String utcTime) {
if(utcTime == null || utcTime.length() == 0) return "";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String dt = "";