Skip to content

Commit

Permalink
Complete push logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
SDL committed Jun 27, 2022
1 parent cc27b75 commit e3b0bb8
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 217 deletions.
7 changes: 1 addition & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
android:name=".ui.activity.PlayActivity"
android:screenOrientation="landscape" />
<activity
android:name=".ui.activity.ProjectionPlayActivity"
android:name=".ui.activity.PushActivity"
android:screenOrientation="landscape" />
<activity
android:name=".ui.activity.SearchActivity"
Expand All @@ -66,11 +66,6 @@
<action android:name="android.content.movie.custom.web.Action" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.ProjectionReceiver">
<intent-filter>
<action android:name="android.content.movie.projection.Action" />
</intent-filter>
</receiver>

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class RefreshEvent {
public static final int TYPE_SEARCH_RESULT = 6;
public static final int TYPE_QUICK_SEARCH_RESULT = 7;
public static final int TYPE_API_URL_CHANGE = 8;
public static final int TYPE_PUSH_URL = 9;
public int type;
public Object obj;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void onApiReceived(String url) {
Hawk.put(HawkConfig.API_URL, url);
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_API_URL_CHANGE, url));
}

@Override
public void onPushReceived(String url) {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_PUSH_URL, url));
}
});
try {
mServer.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface DataReceiver {


void onApiReceived(String url);

void onPushReceived(String url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public NanoHTTPD.Response doResponse(NanoHTTPD.IHTTPSession session, String file
}
case "push": {
// 暂未实现
mDataReceiver.onPushReceived(params.get("url").trim());
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ protected void onPause() {
public void refresh(RefreshEvent event) {
if (event.type == RefreshEvent.TYPE_API_URL_CHANGE) {
Toast.makeText(mContext, "配置地址设置为" + (String) event.obj + ",重启应用生效!", Toast.LENGTH_SHORT).show();
} else if (event.type == RefreshEvent.TYPE_PUSH_URL) {
if (ApiConfig.get().getSource("push_agent") != null) {
Intent newIntent = new Intent(mContext, DetailActivity.class);
newIntent.putExtra("id", (String) event.obj);
newIntent.putExtra("sourceKey", "push_agent");
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
HomeActivity.this.startActivity(newIntent);
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.tvbox.osc.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.tvbox.osc.R;
import com.github.tvbox.osc.base.BaseActivity;
import com.github.tvbox.osc.server.ControlManager;
import com.github.tvbox.osc.ui.tv.QRCodeGen;

import me.jessyan.autosize.utils.AutoSizeUtils;

public class PushActivity extends BaseActivity {
private ImageView ivQRCode;
private TextView tvAddress;

@Override
protected int getLayoutResID() {
return R.layout.activity_push;
}

@Override
protected void init() {
initView();
initData();
}

private void initView() {
ivQRCode = findViewById(R.id.ivQRCode);
tvAddress = findViewById(R.id.tvAddress);
refreshQRCode();
findViewById(R.id.pushLocal).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
ClipboardManager manager = (ClipboardManager) PushActivity.this.getSystemService(Context.CLIPBOARD_SERVICE);
if (manager != null) {
if (manager.hasPrimaryClip() && manager.getPrimaryClip() != null && manager.getPrimaryClip().getItemCount() > 0) {
ClipData.Item addedText = manager.getPrimaryClip().getItemAt(0);
Intent newIntent = new Intent(mContext, DetailActivity.class);
newIntent.putExtra("id", addedText.getText().toString().trim());
newIntent.putExtra("sourceKey", "push_agent");
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PushActivity.this.startActivity(newIntent);
}
}
} catch (Throwable th) {

}
}
});
}

private void refreshQRCode() {
String address = ControlManager.get().getAddress(false);
tvAddress.setText(String.format("手机/电脑扫描上方二维码或者直接浏览器访问地址\n%s", address));
ivQRCode.setImageBitmap(QRCodeGen.generateBitmap(address, AutoSizeUtils.mm2px(this, 300), AutoSizeUtils.mm2px(this, 300), 4));
}

private void initData() {

}
}
Loading

0 comments on commit e3b0bb8

Please sign in to comment.