mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-05-26 06:20:20 -04:00
优化login
This commit is contained in:
parent
5cbe9ee7fc
commit
c89c8b7d66
@ -29,6 +29,8 @@ public class BaseActivity extends AppCompatActivity implements CustomAdapt {
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Utils.config = new Config(this);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (null != actionBar) {
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
@ -100,6 +102,12 @@ public class BaseActivity extends AppCompatActivity implements CustomAdapt {
|
||||
mAA.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(null != progressDialog){
|
||||
if(progressDialog.isShowing()){
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
progressDialog = null;
|
||||
}
|
||||
progressDialog = new ProgressDialog(mAA);
|
||||
progressDialog.setMessage(title);
|
||||
progressDialog.show();
|
||||
@ -160,53 +168,13 @@ public class BaseActivity extends AppCompatActivity implements CustomAdapt {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置
|
||||
*/
|
||||
public void getConfigFromSP() {
|
||||
SharedPreferences sp = this.getSharedPreferences("Jellyfin", this.MODE_PRIVATE);
|
||||
Utils.JellyfinUrl = sp.getString("url", "");
|
||||
Utils.UserName = sp.getString("username", "");
|
||||
Utils.PassWord = sp.getString("password", "");
|
||||
Utils.SortBy = sp.getString("sortby","");
|
||||
Utils.SortOrder = sp.getString("sortorder","");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*
|
||||
* @param url
|
||||
* @param username
|
||||
* @param password
|
||||
*/
|
||||
public void saveConfigToSP(String url, String username, String password) {
|
||||
SharedPreferences sp = this.getSharedPreferences("Jellyfin", this.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString("url", url);
|
||||
editor.putString("username", username);
|
||||
editor.putString("password", password);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存单项配置
|
||||
*/
|
||||
public void saveConfigToSP(String key, String value) {
|
||||
SharedPreferences sp = this.getSharedPreferences("Jellyfin", this.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString(key, value);
|
||||
editor.putString(key, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登 出
|
||||
*/
|
||||
private void logout() {
|
||||
SharedPreferences sp = this.getSharedPreferences("Jellyfin", this.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
Utils.config.clear();
|
||||
Utils.UserId = "";
|
||||
Utils.AccessToken = "";
|
||||
System.exit(0);
|
||||
|
@ -107,7 +107,7 @@ public class CollectionActivity extends BaseActivity {
|
||||
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.SortBy+"%2CSortName%2CProductionYear&SortOrder=" + Utils.SortOrder;
|
||||
ItemsUrl += "&SortBy="+Utils.config.getSortBy()+"%2CSortName%2CProductionYear&SortOrder=" + Utils.config.getSortOrder();
|
||||
if (Type.equals("tvshows")) {
|
||||
ItemsUrl += "&IncludeItemTypes=Series";
|
||||
} else if (Type.equals("movies")) {
|
||||
@ -186,8 +186,8 @@ public class CollectionActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int i = 0;
|
||||
for(Utils.SortByType sbt : Utils.SortByType.values()){
|
||||
if(sbt.value.equals(Utils.SortBy)){
|
||||
for(Config.SortByType sbt : Config.SortByType.values()){
|
||||
if(sbt.value.equals(Utils.config.getSortBy())){
|
||||
i = sbt.ordinal();
|
||||
}
|
||||
}
|
||||
@ -199,20 +199,20 @@ public class CollectionActivity extends BaseActivity {
|
||||
setSortMenuBtnText();
|
||||
SortByMenu = new PopupMenu(this,sortMenuBtn);
|
||||
Menu menu = SortByMenu.getMenu();
|
||||
Utils.SortByType[] Ss = Utils.SortByType.values();
|
||||
for (Utils.SortByType sortby:Ss) {
|
||||
Config.SortByType[] Ss = Config.SortByType.values();
|
||||
for (Config.SortByType sortby:Ss) {
|
||||
menu.add(0,sortby.ordinal(),sortby.ordinal(),sortby.name());
|
||||
}
|
||||
for (Utils.SotrOrderType sot:Utils.SotrOrderType.values()){
|
||||
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.SortBy = Utils.SortByType.valueOf(menuItem.getTitle().toString()).value;
|
||||
Utils.config.setSortBy(Config.SortByType.valueOf(menuItem.getTitle().toString()).value);
|
||||
}else{
|
||||
Utils.SortOrder = Utils.SotrOrderType.valueOf(menuItem.getTitle().toString()).value;
|
||||
Utils.config.setSortOrder(Config.SotrOrderType.valueOf(menuItem.getTitle().toString()).value);
|
||||
}
|
||||
setSortMenuBtnText();
|
||||
currAdapter.clearItems();
|
||||
@ -228,26 +228,9 @@ public class CollectionActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void setSortMenuBtnText(){
|
||||
String s = "";
|
||||
Log.d(TAG, "setSortMenuBtnText: 排序规则:" + Utils.SortBy + "-" + Utils.SortOrder);
|
||||
for (Utils.SortByType Sb:Utils.SortByType.values()) {
|
||||
if(Sb.value.equals(Utils.SortBy)){
|
||||
s += Sb.name();
|
||||
}
|
||||
}
|
||||
String s = Config.SortByType.findName(Utils.config.getSortBy());
|
||||
s += "-";
|
||||
for (Utils.SotrOrderType Sot:Utils.SotrOrderType.values()) {
|
||||
if(Sot.value.equals(Utils.SortOrder)){
|
||||
s += Sot.name();
|
||||
}
|
||||
}
|
||||
s += Config.SotrOrderType.findName(Utils.config.getSortOrder());
|
||||
sortMenuBtn.setText(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
saveConfigToSP("sortby",Utils.SortBy);
|
||||
saveConfigToSP("sortorder",Utils.SortOrder);
|
||||
super.finish();
|
||||
}
|
||||
}
|
143
app/src/main/java/org/sifacai/vlcjellyfin/Config.java
Normal file
143
app/src/main/java/org/sifacai/vlcjellyfin/Config.java
Normal file
@ -0,0 +1,143 @@
|
||||
package org.sifacai.vlcjellyfin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class Config {
|
||||
private Context context;
|
||||
private String JellyfinUrl = "";
|
||||
private String UserName = "";
|
||||
private String PassWord = "";
|
||||
private String SortBy = "DateCreated";
|
||||
private String SortOrder = "Descending";
|
||||
|
||||
public Config(Context context) {
|
||||
this.context = context;
|
||||
getConfigFromSP();
|
||||
}
|
||||
|
||||
public String getJellyfinUrl() {
|
||||
return JellyfinUrl;
|
||||
}
|
||||
|
||||
public void setJellyfinUrl(String jellyfinUrl) {
|
||||
JellyfinUrl = jellyfinUrl;
|
||||
saveConfigToSP("url",jellyfinUrl);
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return UserName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
UserName = userName;
|
||||
saveConfigToSP("username",userName);
|
||||
}
|
||||
|
||||
public String getPassWord() {
|
||||
return PassWord;
|
||||
}
|
||||
|
||||
public void setPassWord(String passWord) {
|
||||
PassWord = passWord;
|
||||
saveConfigToSP("password",passWord);
|
||||
}
|
||||
|
||||
public String getSortBy() {
|
||||
return SortBy;
|
||||
}
|
||||
|
||||
public void setSortBy(String sortBy) {
|
||||
SortBy = sortBy;
|
||||
saveConfigToSP("sortby",sortBy);
|
||||
}
|
||||
|
||||
public String getSortOrder() {
|
||||
return SortOrder;
|
||||
}
|
||||
|
||||
public void setSortOrder(String sortOrder) {
|
||||
SortOrder = sortOrder;
|
||||
saveConfigToSP("sortorder",sortOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置
|
||||
*/
|
||||
public void getConfigFromSP() {
|
||||
SharedPreferences sp = context.getSharedPreferences("Jellyfin", context.MODE_PRIVATE);
|
||||
this.JellyfinUrl = sp.getString("url", "");
|
||||
this.UserName = sp.getString("username", "");
|
||||
this.PassWord = sp.getString("password", "");
|
||||
this.SortBy = sp.getString("sortby","DateCreated");
|
||||
this.SortOrder = sp.getString("sortorder","Descending");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存单项配置
|
||||
*/
|
||||
public void saveConfigToSP(String key, String value) {
|
||||
SharedPreferences sp = context.getSharedPreferences("Jellyfin", context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString(key, value);
|
||||
editor.putString(key, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除
|
||||
*/
|
||||
public void clear() {
|
||||
SharedPreferences sp = context.getSharedPreferences("Jellyfin", context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public enum SortByType {
|
||||
评分("CommunityRating"),
|
||||
加入日期("DateCreated"),
|
||||
播放日期("DatePlayed"),
|
||||
家长分级("OfficialRating"),
|
||||
播放次数("PlayCount"),
|
||||
发行日期("PremiereDate"),
|
||||
播放时长("Runtime");
|
||||
|
||||
public String value;
|
||||
|
||||
SortByType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String findName(String value){
|
||||
String name = "";
|
||||
for (SortByType sbt:SortByType.values()) {
|
||||
if(sbt.value.equals(value)){
|
||||
name = sbt.name();
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SotrOrderType{
|
||||
升序("Ascending"),
|
||||
降序("Descending");
|
||||
|
||||
public String value;
|
||||
|
||||
SotrOrderType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String findName(String value){
|
||||
String name = "";
|
||||
for (SotrOrderType sot:SotrOrderType.values()) {
|
||||
if(sot.value.equals(value)){
|
||||
name = sot.name();
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
@ -75,6 +75,7 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showLoadingDialog("加载中……");
|
||||
initData(ItemId);
|
||||
}
|
||||
}).start();
|
||||
@ -82,13 +83,6 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
||||
}
|
||||
|
||||
private void initData(String itemId) {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showLoadingDialog();
|
||||
}
|
||||
});
|
||||
|
||||
String detailUrl = "/Users/" + Utils.UserId + "/Items/" + itemId;
|
||||
|
||||
String detailStr = Utils.okhttpSend(detailUrl);
|
||||
@ -219,6 +213,8 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
||||
fillItems(AddPartStr);
|
||||
}
|
||||
}).start();
|
||||
}else {
|
||||
dismissLoadingDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +276,7 @@ public class DetailActivity extends BaseActivity implements JAdapter.OnItemClick
|
||||
String imgid = ImageTags.get("Primary").getAsString();
|
||||
media.cover = Utils.getImgUrl(media.Id, imgid);
|
||||
}
|
||||
media.Url = Utils.JellyfinUrl + "/videos/" + media.Id + "/stream.mp4?static=true&a";
|
||||
media.Url = Utils.config.getJellyfinUrl() + "/videos/" + media.Id + "/stream.mp4?static=true&a";
|
||||
if (item.has("UserData")) {
|
||||
JsonObject userdata = item.get("UserData").getAsJsonObject();
|
||||
media.startPositionTicks = userdata.get("PlaybackPositionTicks").getAsLong();
|
||||
|
@ -42,7 +42,6 @@ public class MainActivity extends BaseActivity {
|
||||
mActivity = this;
|
||||
tvLoginOut = findViewById(R.id.tvLoginOut);
|
||||
tvContiner = findViewById(R.id.tvItems);
|
||||
getConfigFromSP();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,16 +157,10 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
private void login() {
|
||||
boolean notL = true;
|
||||
if (ValidUrl(Utils.JellyfinUrl)) {
|
||||
if (ValidUrl(Utils.config.getJellyfinUrl())) {
|
||||
Log.d(TAG, "initView: Url有效");
|
||||
if (authenticateByName(Utils.UserName, Utils.PassWord)) {
|
||||
if (authenticateByName(Utils.config.getUserName(), Utils.config.getPassWord())) {
|
||||
Log.d(TAG, "initView: 用户名密码有效");
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//showLogoutBtn();
|
||||
}
|
||||
});
|
||||
notL = false;
|
||||
}
|
||||
}
|
||||
@ -199,11 +192,13 @@ public class MainActivity extends BaseActivity {
|
||||
ll.setPadding(pd,pd,pd,pd);
|
||||
EditText urlInput = new EditText(ll.getContext());
|
||||
urlInput.setHint("服务器地址");
|
||||
urlInput.setText(Utils.JellyfinUrl);
|
||||
urlInput.setText(Utils.config.getJellyfinUrl());
|
||||
EditText unInput = new EditText(ll.getContext());
|
||||
unInput.setHint("用户名");
|
||||
unInput.setText(Utils.config.getUserName());
|
||||
EditText pwInput = new EditText(ll.getContext());
|
||||
pwInput.setHint("密码");
|
||||
pwInput.setText(Utils.config.getPassWord());
|
||||
Button commitBtn = new Button(ll.getContext());
|
||||
commitBtn.setText("确定");
|
||||
commitBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@ -215,9 +210,13 @@ public class MainActivity extends BaseActivity {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showLoadingDialog("正在验证服务器链接……");
|
||||
if (ValidUrl(url)) {
|
||||
showLoadingDialog("正在验证用户名密码……");
|
||||
Utils.config.setJellyfinUrl(url);
|
||||
if (authenticateByName(un, pw)) {
|
||||
saveConfigToSP(url, un, pw);
|
||||
Utils.config.setUserName(un);
|
||||
Utils.config.setPassWord(pw);
|
||||
dialog.dismiss();
|
||||
initData(); //刷新首页
|
||||
} else {
|
||||
@ -226,6 +225,7 @@ public class MainActivity extends BaseActivity {
|
||||
} else {
|
||||
showMessage("服务器地址无效,请重新输入!");
|
||||
}
|
||||
dismissLoadingDialog();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@ -270,7 +270,6 @@ public class MainActivity extends BaseActivity {
|
||||
if (ServerId == null || ServerId.length() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
Utils.JellyfinUrl = url;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +37,10 @@ import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class Utils {
|
||||
public static final String XEmbyAuthorization = "MediaBrowser Client=\"CatTv\", Device=\"CatTv\", DeviceId=\"TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgNi4xOyBXa\", Version=\"10.8.1\"";
|
||||
public static String JellyfinUrl = "";
|
||||
public static String UserName = "";
|
||||
public static String PassWord = "";
|
||||
public static final String XEmbyAuthorization = "MediaBrowser Client=\"Vlc_J_TV\", Device=\"Vlc_J_TV\", DeviceId=\"TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgNi4xOyBXa\", Version=\"10.8.1\"";
|
||||
public static Config config;
|
||||
public static String UserId = "";
|
||||
public static String AccessToken = "";
|
||||
public static String SortBy = "DateCreated";
|
||||
public static String SortOrder = "Descending";
|
||||
|
||||
public static int playIndex = 0; //当前播放
|
||||
public static ArrayList<Video> playList = new ArrayList<>(); //播放列表
|
||||
@ -71,7 +67,7 @@ public class Utils {
|
||||
if (url.startsWith("http")) {
|
||||
|
||||
} else {
|
||||
url = JellyfinUrl + url;
|
||||
url = config.getJellyfinUrl() + url;
|
||||
}
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
OkHttpClient client = builder.sslSocketFactory(RxUtils.createSSLSocketFactory())
|
||||
@ -118,7 +114,7 @@ public class Utils {
|
||||
* @return
|
||||
*/
|
||||
public static String getImgUrl(String itemid, String tagid) {
|
||||
String url = JellyfinUrl + "/Items/" + itemid + "/Images/Primary";
|
||||
String url = config.getJellyfinUrl() + "/Items/" + itemid + "/Images/Primary";
|
||||
url += "?fillHeight=286&fillWidth=200&quality=96&tag=" + tagid;
|
||||
return url;
|
||||
}
|
||||
@ -167,7 +163,7 @@ public class Utils {
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaying(String Id, long PositionTicks) {
|
||||
String url = JellyfinUrl + "/Sessions/Playing";
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing";
|
||||
String json = "{\"itemId\":\"" + Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaying: " + Id + " : " + rsp);
|
||||
@ -180,15 +176,7 @@ public class Utils {
|
||||
*/
|
||||
public static void ReportPlaybackProgress(String Id, long PositionTicks) {
|
||||
String json = "{\"itemId\" : \"" + Id + "\",\"positionTicks\": \"" + PositionTicks * 10000 + "\"}";
|
||||
//JsonObject rjo = new JsonObject();
|
||||
//rjo.addProperty("itemId",Id);
|
||||
//rjo.addProperty("canSeek",true);
|
||||
//rjo.addProperty("isPaused",paused);
|
||||
//rjo.addProperty("isMuted",false);
|
||||
//rjo.addProperty("positionTicks",PositionTicks * 10000);
|
||||
//rjo.addProperty("PlayMethod","DirectPlay");
|
||||
//String json = rjo.toString();
|
||||
String url = JellyfinUrl + "/Sessions/Playing/Progress";
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing/Progress";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaybackProgress: 返回:" + Id + ":" + rsp);
|
||||
}
|
||||
@ -199,7 +187,7 @@ public class Utils {
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaybackStop(String Id, long PositionTicks) {
|
||||
String url = JellyfinUrl + "/Sessions/Playing/Stopped";
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing/Stopped";
|
||||
String json = "{\"itemId\":\"" + Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaybackStop: " + Id + " : " + rsp);
|
||||
@ -228,31 +216,4 @@ public class Utils {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public enum SortByType {
|
||||
评分("CommunityRating"),
|
||||
加入日期("DateCreated"),
|
||||
播放日期("DatePlayed"),
|
||||
家长分级("OfficialRating"),
|
||||
播放次数("PlayCount"),
|
||||
发行日期("PremiereDate"),
|
||||
播放时长("Runtime");
|
||||
|
||||
public String value;
|
||||
|
||||
SortByType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SotrOrderType{
|
||||
升序("Ascending"),
|
||||
降序("Descending");
|
||||
|
||||
public String value;
|
||||
|
||||
SotrOrderType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user