pull/102/head
FongMi 3 years ago
parent 93816a9e82
commit fe70235d2e
  1. 11
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/ConfigDialog.java
  2. 6
      app/src/leanback/res/layout/activity_search.xml
  3. 6
      app/src/leanback/res/layout/adapter_vod.xml
  4. 45
      app/src/leanback/res/layout/dialog_config.xml
  5. 17
      app/src/leanback/res/layout/view_controller_bottom.xml
  6. 49
      app/src/main/java/com/fongmi/android/tv/bean/ParseResult.java
  7. 53
      app/src/main/java/com/fongmi/android/tv/bean/Result.java
  8. 9
      app/src/main/java/com/fongmi/android/tv/player/ParseTask.java
  9. 3
      app/src/main/res/layout/view_empty.xml
  10. 4
      app/src/main/res/layout/view_error.xml

@ -9,10 +9,10 @@ import android.view.inputmethod.EditorInfo;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.databinding.DialogConfigBinding; import com.fongmi.android.tv.databinding.DialogConfigBinding;
import com.fongmi.android.tv.event.ServerEvent; import com.fongmi.android.tv.event.ServerEvent;
import com.fongmi.android.tv.server.Server; import com.fongmi.android.tv.server.Server;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.Prefers; import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.QRCode; import com.fongmi.android.tv.utils.QRCode;
import com.fongmi.android.tv.utils.ResUtil; import com.fongmi.android.tv.utils.ResUtil;
@ -52,13 +52,14 @@ public class ConfigDialog implements DialogInterface.OnDismissListener {
} }
private void initView() { private void initView() {
String address = Server.get().getAddress(false);
binding.text.setText(Prefers.getUrl()); binding.text.setText(Prefers.getUrl());
binding.text.setSelection(binding.text.getText().length()); binding.text.setSelection(binding.text.getText().length());
binding.code.setImageBitmap(QRCode.getBitmap(Server.get().getAddress(false), 150, 0)); binding.info.setText(ResUtil.getString(R.string.push_info, address));
binding.code.setImageBitmap(QRCode.getBitmap(address, 160, 0));
} }
private void initEvent() { private void initEvent() {
binding.history.setOnClickListener(this::onHistory);
binding.positive.setOnClickListener(this::onPositive); binding.positive.setOnClickListener(this::onPositive);
binding.negative.setOnClickListener(this::onNegative); binding.negative.setOnClickListener(this::onNegative);
binding.text.setOnEditorActionListener((textView, actionId, event) -> { binding.text.setOnEditorActionListener((textView, actionId, event) -> {
@ -78,10 +79,6 @@ public class ConfigDialog implements DialogInterface.OnDismissListener {
dialog.dismiss(); dialog.dismiss();
} }
private void onHistory(View view) {
Notify.show("尚未開發");
}
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onServerEvent(ServerEvent event) { public void onServerEvent(ServerEvent event) {
if (event.getType() != ServerEvent.Type.API) return; if (event.getType() != ServerEvent.Type.API) return;

@ -107,7 +107,7 @@
android:nextFocusLeft="@id/word" android:nextFocusLeft="@id/word"
android:text="@string/search_clear" android:text="@string/search_clear"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="18sp" /> android:textSize="16sp" />
<TextView <TextView
android:id="@+id/search" android:id="@+id/search"
@ -121,7 +121,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/home_search" android:text="@string/home_search"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="18sp" /> android:textSize="16sp" />
<TextView <TextView
android:id="@+id/remote" android:id="@+id/remote"
@ -134,7 +134,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/search_remote" android:text="@string/search_remote"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="18sp" /> android:textSize="16sp" />
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

@ -73,15 +73,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:background="@color/black_50" android:background="@color/black_60"
android:ellipsize="marquee" android:ellipsize="marquee"
android:gravity="center" android:gravity="center"
android:marqueeRepeatLimit="marquee_forever" android:marqueeRepeatLimit="marquee_forever"
android:padding="4dp" android:padding="6dp"
android:scrollHorizontally="true" android:scrollHorizontally="true"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="18sp" android:textSize="16sp"
tools:text="蜘蛛人" /> tools:text="蜘蛛人" />
<View <View

@ -6,16 +6,29 @@
<ImageView <ImageView
android:id="@+id/code" android:id="@+id/code"
android:layout_width="150dp" android:layout_width="160dp"
android:layout_height="150dp" android:layout_height="160dp"
android:scaleType="fitXY" /> android:scaleType="fitXY" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_toEndOf="@+id/code"
android:lineSpacingExtra="4dp"
android:text="@string/push_info"
android:textColor="@color/grey_700"
android:textSize="16sp" />
<EditText <EditText
android:id="@+id/text" android:id="@+id/text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="24dp" android:layout_above="@+id/bottom"
android:layout_toEndOf="@+id/code" android:layout_alignStart="@+id/info"
android:layout_marginBottom="16dp"
android:background="@null"
android:hint="@string/dialog_config_url_hint" android:hint="@string/dialog_config_url_hint"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:importantForAutofill="no" android:importantForAutofill="no"
@ -24,28 +37,14 @@
android:textSize="18sp" /> android:textSize="18sp" />
<LinearLayout <LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignStart="@+id/text" android:layout_alignStart="@+id/info"
android:layout_alignBottom="@+id/code" android:layout_alignBottom="@+id/code"
android:layout_marginTop="16dp"
android:gravity="end" android:gravity="end"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:id="@+id/history"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:singleLine="true"
android:text="@string/setting_history"
android:textColor="@color/white" />
<TextView <TextView
android:id="@+id/negative" android:id="@+id/negative"
android:layout_width="0dp" android:layout_width="0dp"
@ -58,7 +57,8 @@
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/dialog_negative" android:text="@string/dialog_negative"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
<TextView <TextView
android:id="@+id/positive" android:id="@+id/positive"
@ -71,7 +71,8 @@
android:gravity="center" android:gravity="center"
android:singleLine="true" android:singleLine="true"
android:text="@string/dialog_positive" android:text="@string/dialog_positive"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

@ -40,7 +40,8 @@
android:nextFocusLeft="@id/next" android:nextFocusLeft="@id/next"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:text="@string/play_next" android:text="@string/play_next"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
<TextView <TextView
android:id="@+id/prev" android:id="@+id/prev"
@ -52,7 +53,8 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:text="@string/play_prev" android:text="@string/play_prev"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
<TextView <TextView
android:id="@+id/replay" android:id="@+id/replay"
@ -64,7 +66,8 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:text="@string/play_replay" android:text="@string/play_replay"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
<TextView <TextView
android:id="@+id/speed" android:id="@+id/speed"
@ -76,6 +79,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp"
tools:text="1.00" /> tools:text="1.00" />
<TextView <TextView
@ -88,6 +92,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp"
tools:text="預設" /> tools:text="預設" />
<TextView <TextView
@ -108,6 +113,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp"
tools:text="00:00" /> tools:text="00:00" />
<TextView <TextView
@ -120,6 +126,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp"
tools:text="00:00" /> tools:text="00:00" />
<TextView <TextView
@ -132,6 +139,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp"
tools:text="15秒" /> tools:text="15秒" />
<TextView <TextView
@ -144,7 +152,8 @@
android:nextFocusRight="@id/reset" android:nextFocusRight="@id/reset"
android:nextFocusDown="@id/parse" android:nextFocusDown="@id/parse"
android:text="@string/play_reset" android:text="@string/play_reset"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout> </LinearLayout>

@ -1,49 +0,0 @@
package com.fongmi.android.tv.bean;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import org.json.JSONObject;
public class ParseResult {
@SerializedName("header")
private JsonElement header;
@SerializedName("jxFrom")
private String jxFrom;
@SerializedName("parse")
private Integer parse;
@SerializedName("url")
private String url;
public static ParseResult objectFrom(JSONObject object) {
try {
return new Gson().fromJson(object.toString(), ParseResult.class);
} catch (Exception e) {
return new ParseResult();
}
}
public JsonElement getHeader() {
return header;
}
public String getJxFrom() {
return TextUtils.isEmpty(jxFrom) ? "" : jxFrom;
}
public Integer getParse() {
return parse == null ? 0 : parse;
}
public String getUrl() {
return TextUtils.isEmpty(url) ? "" : url;
}
public boolean hasHeader() {
return getHeader() != null;
}
}

@ -12,10 +12,10 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.json.JSONObject;
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path; import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
@ -45,28 +45,28 @@ public class Result {
@SerializedName("filters") @SerializedName("filters")
private LinkedHashMap<String, List<Filter>> filters; private LinkedHashMap<String, List<Filter>> filters;
@SerializedName("header")
private JsonElement header;
@SerializedName("playUrl") @SerializedName("playUrl")
private String playUrl; private String playUrl;
@SerializedName("header") @SerializedName("jxFrom")
private String header; private String jxFrom;
@SerializedName("flag")
private String flag;
@SerializedName("url")
private String url;
@SerializedName("parse") @SerializedName("parse")
private Integer parse; private Integer parse;
@SerializedName("jx") @SerializedName("jx")
private Integer jx; private Integer jx;
@SerializedName("flag")
private String flag;
@SerializedName("url")
private String url;
public static Result fromJson(String str) { public static Result fromJson(String str) {
try { try {
Type type = new TypeToken<LinkedHashMap<String, List<Filter>>>() { Type type = new TypeToken<LinkedHashMap<String, List<Filter>>>() {}.getType();
}.getType();
Gson gson = new GsonBuilder().registerTypeAdapter(type, new FiltersAdapter()).create(); Gson gson = new GsonBuilder().registerTypeAdapter(type, new FiltersAdapter()).create();
Result result = gson.fromJson(str, Result.class); Result result = gson.fromJson(str, Result.class);
return result == null ? new Result() : result; return result == null ? new Result() : result;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return new Result(); return new Result();
} }
} }
@ -75,13 +75,20 @@ public class Result {
try { try {
return new Persister().read(Result.class, str); return new Persister().read(Result.class, str);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return new Result(); return new Result();
} }
} }
public static Result fromObject(JSONObject object) {
return objectFrom(object.toString());
}
public static Result objectFrom(String str) { public static Result objectFrom(String str) {
try {
return new Gson().fromJson(str, Result.class); return new Gson().fromJson(str, Result.class);
} catch (Exception e) {
return new Result();
}
} }
public List<Class> getTypes() { public List<Class> getTypes() {
@ -104,6 +111,10 @@ public class Result {
return filters == null ? new LinkedHashMap<>() : filters; return filters == null ? new LinkedHashMap<>() : filters;
} }
private JsonElement getHeader() {
return header;
}
public String getPlayUrl() { public String getPlayUrl() {
return TextUtils.isEmpty(playUrl) ? "" : playUrl; return TextUtils.isEmpty(playUrl) ? "" : playUrl;
} }
@ -112,8 +123,8 @@ public class Result {
this.playUrl = playUrl; this.playUrl = playUrl;
} }
public String getHeader() { public String getJxFrom() {
return TextUtils.isEmpty(header) ? "" : header; return TextUtils.isEmpty(jxFrom) ? "" : jxFrom;
} }
public Integer getParse() { public Integer getParse() {
@ -124,6 +135,10 @@ public class Result {
this.parse = parse; this.parse = parse;
} }
public Integer getJx() {
return jx == null ? 0 : jx;
}
public String getFlag() { public String getFlag() {
return TextUtils.isEmpty(flag) ? "" : flag; return TextUtils.isEmpty(flag) ? "" : flag;
} }
@ -132,10 +147,6 @@ public class Result {
this.flag = flag; this.flag = flag;
} }
public Integer getJx() {
return jx == null ? 0 : jx;
}
public String getUrl() { public String getUrl() {
return TextUtils.isEmpty(url) ? "" : url; return TextUtils.isEmpty(url) ? "" : url;
} }
@ -144,10 +155,12 @@ public class Result {
this.url = url; this.url = url;
} }
public boolean hasHeader() {
return getHeader() != null;
}
public Map<String, String> getHeaders() { public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); return hasHeader() ? Json.toMap(getHeader()) : new HashMap<>();
if (getHeader().isEmpty()) return headers;
return Json.toMap(JsonParser.parseString(getHeader()));
} }
@NonNull @NonNull

@ -5,7 +5,6 @@ import android.os.Looper;
import com.fongmi.android.tv.api.ApiConfig; import com.fongmi.android.tv.api.ApiConfig;
import com.fongmi.android.tv.bean.Parse; import com.fongmi.android.tv.bean.Parse;
import com.fongmi.android.tv.bean.ParseResult;
import com.fongmi.android.tv.bean.Result; import com.fongmi.android.tv.bean.Result;
import com.fongmi.android.tv.net.OKHttp; import com.fongmi.android.tv.net.OKHttp;
import com.fongmi.android.tv.utils.Json; import com.fongmi.android.tv.utils.Json;
@ -86,13 +85,13 @@ public class ParseTask {
private void jsonExtend(String webUrl) { private void jsonExtend(String webUrl) {
LinkedHashMap<String, String> jxs = new LinkedHashMap<>(); LinkedHashMap<String, String> jxs = new LinkedHashMap<>();
for (Parse item : ApiConfig.get().getParses()) if (item.getType() == 1) jxs.put(item.getName(), item.mixUrl()); for (Parse item : ApiConfig.get().getParses()) if (item.getType() == 1) jxs.put(item.getName(), item.mixUrl());
ParseResult result = ParseResult.objectFrom(ApiConfig.get().jsonExt(parse.getUrl(), jxs, webUrl)); Result result = Result.fromObject(ApiConfig.get().jsonExt(parse.getUrl(), jxs, webUrl));
if (result.getUrl().isEmpty()) { if (result.getUrl().isEmpty()) {
onParseError(); onParseError();
} else if (result.getParse() == 1) { } else if (result.getParse() == 1) {
handler.post(() -> Players.get().web().start(result.getUrl(), callback)); handler.post(() -> Players.get().web().start(result.getUrl(), callback));
} else { } else {
onParseSuccess(result.hasHeader() ? Json.toMap(result.getHeader()) : new HashMap<>(), result.getUrl()); onParseSuccess(result.getHeaders(), result.getUrl());
} }
} }
@ -105,13 +104,13 @@ public class ParseTask {
map.put("url", item.getUrl()); map.put("url", item.getUrl());
jxs.put(item.getName(), map); jxs.put(item.getName(), map);
} }
ParseResult result = ParseResult.objectFrom(ApiConfig.get().jsonExtMix(flag + "@", parse.getUrl(), parse.getName(), jxs, webUrl)); Result result = Result.fromObject(ApiConfig.get().jsonExtMix(flag + "@", parse.getUrl(), parse.getName(), jxs, webUrl));
if (result.getUrl().isEmpty()) { if (result.getUrl().isEmpty()) {
onParseError(); onParseError();
} else if (result.getParse() == 1) { } else if (result.getParse() == 1) {
handler.post(() -> Players.get().web().start(result.getUrl(), callback)); handler.post(() -> Players.get().web().start(result.getUrl(), callback));
} else { } else {
onParseSuccess(result.hasHeader() ? Json.toMap(result.getHeader()) : new HashMap<>(), result.getUrl()); onParseSuccess(result.getHeaders(), result.getUrl());
} }
} }

@ -19,7 +19,6 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/error_empty" android:text="@string/error_empty"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="20sp" android:textSize="20sp" />
android:textStyle="bold" />
</LinearLayout> </LinearLayout>

@ -20,7 +20,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="18sp" android:textSize="16sp"
tools:text="@string/error_play" /> tools:text="@string/error_play_format" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save