Commit ff177821 authored by feihuaduo's avatar feihuaduo

决斗助手加房ip端口支持

parent 40bd5415
......@@ -184,9 +184,9 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
}
@Override
public void onJoinRoom(String password, int id) {
public void onJoinRoom(String host,int port,String password, int id) {
if (id == ID_MAINACTIVITY) {
QuickjoinRoom(password);
QuickjoinRoom(host,port,password);
}
}
......@@ -606,10 +606,20 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
});
}
private void QuickjoinRoom(String password) {
private void QuickjoinRoom(String host,int port,String password) {
String message;
if (!TextUtils.isEmpty(host))
message = getString(R.string.quick_join)
+ "IP:" + host
+ "端口:" + port
+ "密码:" + password;
else
message = getString(R.string.quick_join) + "\"" + password + "\"";
DialogPlus dialog = new DialogPlus(this);
dialog.setTitle(R.string.question);
dialog.setMessage(getString(R.string.quick_join) + password + "\"");
dialog.setMessage(message);
dialog.setMessageGravity(Gravity.CENTER_HORIZONTAL);
dialog.setLeftButtonText(R.string.Cancel);
dialog.setRightButtonText(R.string.join);
......@@ -633,7 +643,13 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
return fileList;
}).done((list) -> {
if (list != null) {
String host1=host;
int port1=port;
ServerInfo serverInfo = list.getServerInfoList().get(0);
if (!TextUtils.isEmpty(host1)){
serverInfo.setServerAddr(host1);
serverInfo.setPort(port1);
}
joinGame(serverInfo, password);
}
});
......
package com.ourygo.assistant.base.listener;
public interface OnDuelAssistantListener {
void onJoinRoom(String password,int id);
void onJoinRoom(String host,int port,String password,int id);
void onCardSearch(String key,int id);
void onSaveDeck(String message,boolean isUrl,int id);
boolean isListenerEffective();
......
package com.ourygo.assistant.service;
import static cn.garymb.ygomobile.Constants.ASSET_SERVER_LIST;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
......@@ -13,11 +15,11 @@ import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RemoteViews;
......@@ -49,10 +51,8 @@ import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ServerListManager;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import static cn.garymb.ygomobile.Constants.ASSET_SERVER_LIST;
public class DuelAssistantService extends Service implements OnDuelAssistantListener{
public class DuelAssistantService extends Service implements OnDuelAssistantListener {
private static final String TAG = "DuelAssistantService";
......@@ -100,7 +100,7 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
startForeground();
//初始化加房布局
createFloatView();
duelAssistantManagement=DuelAssistantManagement.getInstance();
duelAssistantManagement = DuelAssistantManagement.getInstance();
duelAssistantManagement.addDuelAssistantListener(this);
}
......@@ -113,7 +113,6 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
}
private void startForeground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......@@ -222,39 +221,39 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
mWindowManager.removeView(mFloatLayout);
}
}, TIME_DIS_WINDOW);
bt_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
disJoinDialog();
}
});
bt_join.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
disJoinDialog();
//如果是卡组url
if (isUrl) {
Deck deckInfo = new Deck(getString(R.string.rename_deck) + System.currentTimeMillis(), Uri.parse(deckMessage));
File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir());
bt_close.setOnClickListener(v -> disJoinDialog());
bt_join.setOnClickListener(v -> {
disJoinDialog();
//如果是卡组url
if (isUrl) {
Deck deckInfo = new Deck(getString(R.string.rename_deck) + System.currentTimeMillis(), Uri.parse(deckMessage));
File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir());
DeckManagerActivity.start(DuelAssistantService.this, file.getAbsolutePath());
} else {
//如果是卡组文本
try {
//以当前时间戳作为卡组名保存卡组
File file = DeckUtils.save(getString(R.string.rename_deck) + System.currentTimeMillis(), deckMessage);
DeckManagerActivity.start(DuelAssistantService.this, file.getAbsolutePath());
} else {
//如果是卡组文本
try {
//以当前时间戳作为卡组名保存卡组
File file = DeckUtils.save(getString(R.string.rename_deck) + System.currentTimeMillis(), deckMessage);
DeckManagerActivity.start(DuelAssistantService.this, file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(DuelAssistantService.this, getString(R.string.save_failed_bcos) + e, Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(DuelAssistantService.this, getString(R.string.save_failed_bcos) + e, Toast.LENGTH_SHORT).show();
}
}
});
}
private void joinRoom(String password) {
tv_message.setText(getString(R.string.quick_join) + password + "\"");
private void joinRoom(String host, int port, String password) {
String message;
if (!TextUtils.isEmpty(host))
message = getString(R.string.quick_join)
+ "IP:" + host
+ "端口:" + port
+ "密码:" + password;
else
message = getString(R.string.quick_join) + "\"" + password + "\"";
tv_message.setText(message);
bt_join.setText(R.string.join);
bt_close.setText(R.string.search_close);
disJoinDialog();
......@@ -266,46 +265,42 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
}
}, TIME_DIS_WINDOW);
bt_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View p1) {
disJoinDialog();
bt_close.setOnClickListener(p1 -> disJoinDialog());
bt_join.setOnClickListener(p1 -> {
if (isDis) {
isDis = false;
mWindowManager.removeView(mFloatLayout);
}
});
bt_join.setOnClickListener(new OnClickListener() {
ServerListAdapter mServerListAdapter = new ServerListAdapter(DuelAssistantService.this);
@Override
public void onClick(View p1) {
if (isDis) {
isDis = false;
mWindowManager.removeView(mFloatLayout);
}
ServerListAdapter mServerListAdapter = new ServerListAdapter(DuelAssistantService.this);
ServerListManager mServerListManager = new ServerListManager(DuelAssistantService.this, mServerListAdapter);
mServerListManager.syncLoadData();
ServerListManager mServerListManager = new ServerListManager(DuelAssistantService.this, mServerListAdapter);
mServerListManager.syncLoadData();
File xmlFile = new File(getFilesDir(), Constants.SERVER_FILE);
VUiKit.defer().when(() -> {
ServerList assetList = ServerListManager.readList(DuelAssistantService.this.getAssets().open(ASSET_SERVER_LIST));
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
}).done((list) -> {
if (list != null) {
ServerInfo serverInfo = list.getServerInfoList().get(0);
Util.duelIntent(DuelAssistantService.this, serverInfo.getServerAddr(), serverInfo.getPort(), serverInfo.getPlayerName(), password);
File xmlFile = new File(getFilesDir(), Constants.SERVER_FILE);
VUiKit.defer().when(() -> {
ServerList assetList = ServerListManager.readList(DuelAssistantService.this.getAssets().open(ASSET_SERVER_LIST));
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
}).done((list) -> {
if (list != null) {
String host1=host;
int port1=port;
ServerInfo serverInfo = list.getServerInfoList().get(0);
if (TextUtils.isEmpty(host1)){
host1=serverInfo.getServerAddr();
port1=serverInfo.getPort();
}
});
Util.duelIntent(DuelAssistantService.this, host1, port1, serverInfo.getPlayerName(), password);
}
});
}
});
}
......@@ -360,18 +355,18 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
}
@Override
public void onJoinRoom(String password, int id) {
if (id== ClipManagement.ID_CLIP_LISTENER) {
public void onJoinRoom(String host, int port, String password, int id) {
if (id == ClipManagement.ID_CLIP_LISTENER) {
//如果有悬浮窗权限再显示
if (PermissionUtil.isServicePermission(this)) {
joinRoom(password);
joinRoom(host, port, password);
}
}
}
@Override
public void onCardSearch(String key, int id) {
if (id==ClipManagement.ID_CLIP_LISTENER) {
if (id == ClipManagement.ID_CLIP_LISTENER) {
Intent intent = new Intent(DuelAssistantService.this, CardSearchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CardSearchActivity.SEARCH_MESSAGE, key);
......@@ -381,8 +376,8 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
@Override
public void onSaveDeck(String message, boolean isUrl, int id) {
if (id==ClipManagement.ID_CLIP_LISTENER) {
saveDeck(message,isUrl);
if (id == ClipManagement.ID_CLIP_LISTENER) {
saveDeck(message, isUrl);
}
}
......
......@@ -8,6 +8,10 @@ import android.util.Log;
import com.ourygo.assistant.base.listener.OnClipChangedListener;
import com.ourygo.assistant.base.listener.OnDuelAssistantListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
......@@ -90,6 +94,23 @@ public class DuelAssistantManagement implements OnClipChangedListener {
public boolean roomCheck(String message, int id) {
int start = -1;
int end = -1;
start=message.indexOf(Record.ROOM_PREFIX);
if (start!=-1){
end=message.indexOf(Record.ROOM_END,start);
if (end!=-1){
message=message.substring(start,end);
JSONObject jsonObject= null;
try {
jsonObject = new JSONObject(message);
onJoinRoom(jsonObject.getString(Record.ARG_HOST),jsonObject.getInt(Record.ARG_PORT),jsonObject.getString(Record.ARG_PASSWORD),id);
return true;
} catch (JSONException e) { e.printStackTrace();
}
}
}
String passwordPrefixKey = null;
for (String s : Record.PASSWORD_PREFIX) {
start = message.indexOf(s);
......@@ -110,7 +131,7 @@ public class DuelAssistantManagement implements OnClipChangedListener {
if (end - start == passwordPrefixKey.length())
return false;
}
onJoinRoom(message.substring(start, end), id);
onJoinRoom(null,0,message.substring(start, end), id);
return true;
}
return false;
......@@ -126,7 +147,7 @@ public class DuelAssistantManagement implements OnClipChangedListener {
if (TextUtils.isEmpty(cardSearchMessage)) {
return false;
}
//如果卡查内容包含“=”并且复制的内容包含“.”不卡查
//如果卡查内容包含“=”并且复制的内容包含“.”不卡查(链接判断)
if (cardSearchMessage.contains("=") || message.contains(".")) {
return false;
}
......@@ -139,12 +160,12 @@ public class DuelAssistantManagement implements OnClipChangedListener {
return false;
}
private void onJoinRoom(String password, int id) {
private void onJoinRoom(String host,int port,String password, int id) {
int i = 0;
while (i < onDuelAssistantListenerList.size()) {
OnDuelAssistantListener onDuelAssistantListener = onDuelAssistantListenerList.get(i);
if (onDuelAssistantListener.isListenerEffective()) {
onDuelAssistantListener.onJoinRoom(password, id);
onDuelAssistantListener.onJoinRoom(host,port,password, id);
i++;
} else {
onDuelAssistantListenerList.remove(i);
......
......@@ -22,9 +22,17 @@ public class Record {
"LF2#", "lf2#",
"R#", "r#"
};
public static final String ROOM_PREFIX="room:{";
public static final String ROOM_END="}";
//卡组复制
public static final String[] DeckTextKey = new String[]{"#main"};
//卡组url前缀
public static final String DECK_URL_PREFIX = "ygo://deck";
public static final String ARG_PORT = "port";
public static final String ARG_HOST = "host";
public static final String ARG_PASSWORD = "password";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment