Commit 25e02e3e authored by kenan's avatar kenan

Merge branch 'master' into cc

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