Commit fed9b439 authored by fallenstardust's avatar fallenstardust

萌卡网页监听文件下载

根据拓展名区分下载路径
constants arrange
parent b0d70e5f
......@@ -100,6 +100,8 @@ public interface Constants {
String CORE_SKIN_AVATAR_OPPONENT = "opponent.jpg";
String UNKNOWN_IMAGE = "unknown.jpg";
String YDK_FILE_EX = ".ydk";
String YRP_FILE_EX = ".yrp";
String YPK_FILE_EX = ".ypk";
int[] CORE_SKIN_BG_SIZE = new int[]{1920, 1080};
int[] CORE_SKIN_CARD_MINI_SIZE = new int[]{44, 64};
......
......@@ -8,6 +8,9 @@ import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH;
import static cn.garymb.ygomobile.Constants.QUERY_NAME;
import static cn.garymb.ygomobile.Constants.REQUEST_SETTINGS_CODE;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
import static cn.garymb.ygomobile.Constants.YPK_FILE_EX;
import static cn.garymb.ygomobile.Constants.YRP_FILE_EX;
import static cn.garymb.ygomobile.utils.ServerUtil.loadServerInfoFromZipOrYpk;
import android.app.Activity;
......@@ -123,10 +126,10 @@ public class GameUriManager {
return file;
}
}
return new File(dir, "tmp_" + System.currentTimeMillis() + ".ydk");
return new File(dir, "tmp_" + System.currentTimeMillis() + YDK_FILE_EX);
} else {
IOUtils.createFolder(dir);
file = new File(dir, name + ".ydk");
file = new File(dir, name + YDK_FILE_EX);
}
return file;
}
......@@ -166,7 +169,7 @@ public class GameUriManager {
}
String name = getPathName(path, false);
File local;
if (name.toLowerCase(Locale.US).endsWith(".ydk")) {
if (name.toLowerCase(Locale.US).endsWith(YDK_FILE_EX)) {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
local = getDeckFile(dir, getPathName(path, true));
} else if (name.toLowerCase(Locale.US).endsWith(".ypk")) {
......@@ -178,7 +181,7 @@ public class GameUriManager {
}
}
local = new File(AppsSettings.get().getExpansionsPath(), name);
} else if (name.toLowerCase(Locale.US).endsWith(".yrp")) {
} else if (name.toLowerCase(Locale.US).endsWith(YRP_FILE_EX)) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH, name);
} else if (name.toLowerCase(Locale.US).endsWith(".lua")) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_SINGLE_PATH, name);
......@@ -226,9 +229,9 @@ public class GameUriManager {
Toast.makeText(activity, "open file error", Toast.LENGTH_LONG).show();
return;
}
boolean isYdk = file.getName().toLowerCase(Locale.US).endsWith(".ydk");
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk");
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp");
boolean isYdk = file.getName().toLowerCase(Locale.US).endsWith(YDK_FILE_EX);
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(YPK_FILE_EX);
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(YRP_FILE_EX);
boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua");
boolean isConf = file.getName().toLowerCase(Locale.US).endsWith(".conf");
Log.i(Constants.TAG, "open file:" + uri + "->" + file.getAbsolutePath());
......
......@@ -13,6 +13,7 @@ import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.DeckInfo;
import cn.garymb.ygomobile.utils.IOUtils;
......@@ -138,7 +139,7 @@ public class DeckUtils {
FileWriter fw = null;
//如果文件存在,则重写内容;如果文件不存在,则创建文件
File f = new File(AppsSettings.get().getDeckDir(),name+".ydk");
File f = new File(AppsSettings.get().getDeckDir(),name + Constants.YDK_FILE_EX);
fw = new FileWriter(f, false);
PrintWriter pw = new PrintWriter(fw);
......
......@@ -27,15 +27,20 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.ourygo.lib.duelassistant.util.Util;
import com.tencent.smtt.sdk.DownloadListener;
import com.tencent.smtt.sdk.ValueCallback;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.MessageFormat;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.YGOStarter;
import cn.garymb.ygomobile.base.BaseFragemnt;
import cn.garymb.ygomobile.lite.BuildConfig;
......@@ -48,6 +53,8 @@ import cn.garymb.ygomobile.ui.mycard.bean.McUser;
import cn.garymb.ygomobile.ui.mycard.mcchat.ChatListener;
import cn.garymb.ygomobile.ui.mycard.mcchat.ChatMessage;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.utils.DownloadUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.HandlerUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
import cn.garymb.ygomobile.utils.glide.GlideCompat;
......@@ -55,7 +62,7 @@ import cn.garymb.ygomobile.utils.glide.GlideCompat;
public class MycardFragment extends BaseFragemnt implements View.OnClickListener, MyCard.MyCardListener, OnJoinChatListener, ChatListener {
private static final int FILECHOOSER_RESULTCODE = 10;
private static final int TYPE_MC_LOGIN = 0;
private static final int TYPE_MC_LOGIN_FAILED = 1;
private static final int TYPE_MC_LOGIN_FAILED = -1;
private HomeActivity homeActivity;
long exitLasttime = 0;
//头像昵称账号
......@@ -76,19 +83,23 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == TYPE_MC_LOGIN) {
McUser mcUser = (McUser) msg.obj;
if (!TextUtils.isEmpty(mcUser.getAvatar_url())) {
GlideCompat.with(getActivity()).load(mcUser.getAvatar_url()).into(mHeadView);//刷新头像图片
}
mNameView.setText(mcUser.getUsername());//刷新用户名
mStatusView.setText(mcUser.getEmail());//刷新账号信息
serviceManagement.start();
}
if (msg.what == TYPE_MC_LOGIN_FAILED) {
switch (msg.what) {
case TYPE_MC_LOGIN:
McUser mcUser = (McUser) msg.obj;
if (!TextUtils.isEmpty(mcUser.getAvatar_url())) {
GlideCompat.with(getActivity()).load(mcUser.getAvatar_url()).into(mHeadView);//刷新头像图片
}
mNameView.setText(mcUser.getUsername());//刷新用户名
mStatusView.setText(mcUser.getEmail());//刷新账号信息
serviceManagement.start();
break;
case TYPE_MC_LOGIN_FAILED:
break;
}
}
......@@ -113,6 +124,52 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
mMyCard = new MyCard(getActivity());
mMcUser = new McUser();
mWebViewPlus = view.findViewById(R.id.webbrowser);
//设置网页下载监听
mWebViewPlus.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
String fileName = "";
try {
//从contentDisposition获取文件名并转换urlcode为UTF-8
fileName = URLDecoder.decode(contentDisposition.substring(contentDisposition.lastIndexOf("''") + 2), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
String destFileDir = "";
if (contentDisposition.endsWith(Constants.YDK_FILE_EX)) {
destFileDir = AppsSettings.get().getDeckDir();
} else if (contentDisposition.endsWith(Constants.YRP_FILE_EX)) {
destFileDir = AppsSettings.get().getReplayDir();
} else {//萌卡还有些什么文件格式后续可以添加
destFileDir = AppsSettings.get().getResourcePath();
}
File file = new File(destFileDir + "/" + fileName);
DownloadUtil.get().download(url, destFileDir, file.getName(), new DownloadUtil.OnDownloadListener() {
@Override
public void onDownloadSuccess(File file) {
if (file.getName().endsWith("ydk")) {
YGOUtil.showTextToast(getString(R.string.tip_download_OK) + getString(R.string.deck_list));
} else if (file.getName().endsWith("yrp")) {
YGOUtil.showTextToast(getString(R.string.tip_download_OK) + getString(R.string.replay_list));
} else {
YGOUtil.showTextToast(getString(R.string.tip_download_failed));
}
}
@Override
public void onDownloading(int progress) {}
@Override
public void onDownloadFailed(Exception e) {
//下载失败后删除下载的文件
FileUtils.deleteFile(file);
YGOUtil.showTextToast(getString(R.string.tip_download_failed));
}
});
}
});
//init layout
mProgressBar = view.findViewById(R.id.progressBar);
mProgressBar.setMax(100);
tv_back_mc = view.findViewById(R.id.tv_back_mc);
......
package cn.garymb.ygomobile.utils;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
import static cn.garymb.ygomobile.ui.home.HomeActivity.pre_code_list;
import static cn.garymb.ygomobile.ui.home.HomeActivity.released_code_list;
import static cn.garymb.ygomobile.utils.ComparisonTableUtil.newIDsArray;
......@@ -89,7 +90,7 @@ public class DeckUtil {
File[] files = new File(path).listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".ydk")) {
if (file.isFile() && file.getName().endsWith(YDK_FILE_EX)) {
deckList.add(new DeckFile(file));
}
}
......@@ -118,7 +119,7 @@ public class DeckUtil {
if (file.isDirectory()) {
deckList.addAll(getDeckAllList(file.getAbsolutePath(), true));
}
if (file.isFile() && file.getName().endsWith(".ydk")) {
if (file.isFile() && file.getName().endsWith(YDK_FILE_EX)) {
deckList.add(new DeckFile(file));
}
}
......@@ -167,7 +168,7 @@ public class DeckUtil {
File[] files = new File(appsSettings.getExpansionsPath(), Constants.CORE_DECK_PATH).listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".ydk")) {
if (file.isFile() && file.getName().endsWith(YDK_FILE_EX)) {
deckList.add(new DeckFile(file));
}
}
......@@ -181,7 +182,7 @@ public class DeckUtil {
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.getName().endsWith(".ydk")) {
if (entry.getName().endsWith(YDK_FILE_EX)) {
String name = entry.getName();
name = name.substring(name.lastIndexOf("/"));
InputStream inputStream = zipFile.getInputStream(entry);
......
......@@ -349,6 +349,8 @@
<string name="settings_screen_padding">Altura Reservada (Para Pantalla Curva)</string>
<string name="tip_load_cdb_error">Error al intentar cargar la base de datos</string>
<string name="action_download_expansions">Descargar \nexpansiones</string>
<string name="tip_download_failed">Fallo al guardar</string>
<string name="tip_download_OK">guardado en</string>
<string name="replay">Repeticiones</string>
<string name="bot_mode">Jugar vs IA</string>
<string name="personal">My</string>
......@@ -368,5 +370,6 @@
<string name="Pre_Server_Name">Servidor Super-pre Mycard</string>
<string name="tip_ypk_is_deleted">Actualice las cartas pre-lanzadas de inmediato</string>
<string name="tip_superpre_desc">Actualización más rápida. Descargar expansiones</string>
<string name="replay_list">lista de reproducción</string>
</resources>
......@@ -347,6 +347,7 @@
<string name="file_installed">ファイル導入成功</string>
<string name="settings_screen_padding">窓の預入高さ</string>
<string name="tip_load_cdb_error">データロードエー</string>
<string name="tip_download_failed">保存失敗</string>
<string name="replay">リプレイを見る</string>
<string name="bot_mode">AIモード</string>
<string name="personal">自分の</string>
......@@ -362,4 +363,5 @@
<string name="tip_ypk_is_deleted">正式更新は非公式パスコードを無効にしますので常にパッチをダウンロードしてください</string>
<string name="tip_superpre_desc">をアップデートする(新規カードを含める)</string>
<string name="tip_download_ex">新しいカードがあるよ、遊びに来て!</string>
<string name="replay_list">リプレイ</string>
</resources>
......@@ -345,6 +345,8 @@
<string name="file_installed">파일을 불러왔습니다</string>
<string name="settings_screen_padding">화면 스타일</string>
<string name="tip_load_cdb_error">데이터를 불러오는 중에 오류가 발생했습니다.</string>
<string name="tip_download_failed">저장 실패</string>
<string name="tip_download_OK">에 저장됨</string>
<string name="replay">리플레이 보기</string>
<string name="bot_mode">AI 모드</string>
<string name="personal">개인 설정</string>
......@@ -363,4 +365,5 @@
<string name="tip_ypk_is_deleted">Please upgrade pre-released cards at once</string>
<string name="tip_superpre_desc">Please upgrade pre-released cards at once</string>
<string name="tip_download_ex">새 카드가 있어, 놀러 와!</string>
<string name="replay_list">재생 목록</string>
</resources>
......@@ -348,6 +348,7 @@
<string name="settings_screen_padding">瀑布屏预留高度</string>
<string name="tip_load_cdb_error">加载数据出错</string>
<string name="replay">查看录像</string>
<string name="replay_list">录像列表</string>
<string name="bot_mode">人机练习</string>
<string name="personal">我的设置</string>
<string name="back_to_mycard_home">返回萌卡首页</string>
......@@ -362,4 +363,6 @@
<string name="tip_ypk_is_deleted">正式卡更新会让旧先行卡失效,请及时重新下载先行卡补丁</string>
<string name="tip_superpre_desc">与本应用正式卡同步更新并提供超先行卡尝鲜</string>
<string name="tip_download_ex">新卡下载!</string>
<string name="tip_download_failed">保存失败,请检查网络并重试</string>
<string name="tip_download_OK">已保存至</string>
</resources>
......@@ -233,7 +233,7 @@
<string name="game_version">Game Version</string>
<string name="tip">Info</string>
<string name="error_game_ver">Wrong!be right as "0x1342"(as 1.034.2)</string>
<string name="tip_no_netwrok" translatable="false">please confirm net works</string>
<string name="tip_no_netwrok">please confirm net works</string>
<string name="message">Copying datas...</string>
<string name="ex_pack">Extend cards</string>
<string name="deck_manager_v2">Deck Manager V2</string>
......@@ -372,4 +372,7 @@
<string name="tip_ypk_is_deleted">Please upgrade pre-released cards at once</string>
<string name="tip_superpre_desc">fastest upgrade. download expansions</string>
<string name="tip_download_ex">New cards available!</string>
<string name="tip_download_failed">Save Failed!</string>
<string name="tip_download_OK">Saved to</string>
<string name="replay_list">Replay List</string>
</resources>
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