Commit 11396615 authored by feihuaduo's avatar feihuaduo

高清卡图下载

parent 96a79072
......@@ -9,7 +9,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
//classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}d
}
}
ext {
......
......@@ -117,5 +117,7 @@ dependencies {
//Tencent bugly
implementation 'com.tencent.bugly:crashreport_upgrade:latest.release'
implementation 'com.tencent.bugly:nativecrashreport:latest.release'
//http请求库
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
}
......@@ -336,6 +336,16 @@ public class AppsSettings {
mSharedPreferences.putString(Constants.PREF_IMAGE_QUALITY, "" + quality);
}
/**
* 根据卡密获取卡图的路径
* @param code 卡密
* @return
*/
public String getCardImagePath(int code){
return new File(getCardImagePath(),code+".jpg").getAbsolutePath();
}
/***
* 图片文件夹
*/
......
package cn.garymb.ygomobile.ui.cards;
import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.feihua.dialogutils.util.DialogUtils;
import java.io.File;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus;
import cn.garymb.ygomobile.utils.CardUtils;
import cn.garymb.ygomobile.utils.DownloadUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
import ocgcore.StringManager;
import ocgcore.data.Card;
import ocgcore.enums.CardType;
......@@ -22,6 +36,11 @@ import ocgcore.enums.CardType;
* 卡片详情
*/
public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private static final int TYPE_DOWNLOAD_CARD_IMAGE_OK = 0;
private static final int TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION = 1;
private static final int TYPE_DOWNLOAD_CARD_IMAGE_ING = 2;
private static final String TAG = "CardDetail";
private ImageView cardImage;
private TextView name;
......@@ -53,6 +72,36 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private OnCardClickListener mListener;
private DialogUtils dialog;
private ImageView photoView;
private LinearLayout ll_bar;
private ProgressBar pb_loading;
private TextView tv_loading;
@SuppressLint("HandlerLeak")
Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TYPE_DOWNLOAD_CARD_IMAGE_OK:
ll_bar.startAnimation(AnimationUtils.loadAnimation(context,R.anim.out_from_bottom));
ll_bar.setVisibility(View.GONE);
imageLoader.bindImage(photoView, msg.arg1, null, true);
break;
case TYPE_DOWNLOAD_CARD_IMAGE_ING:
tv_loading.setText("下载高清卡图中 "+msg.arg1+"%");
pb_loading.setProgress(msg.arg1);
break;
case TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION:
ll_bar.startAnimation(AnimationUtils.loadAnimation(context,R.anim.out_from_bottom));
ll_bar.setVisibility(View.GONE);
YGOUtil.show("下载失败,原因为"+msg.obj);
break;
}
}
};
public CardDetail(BaseActivity context, ImageLoader imageLoader, StringManager stringManager) {
super(LayoutInflater.from(context).inflate(R.layout.dialog_cardinfo, null));
......@@ -173,12 +222,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
imageLoader.bindImage(cardImage, cardInfo.Code, null, true);
dialog = DialogUtils.getdx(context);
cardImage.setOnClickListener((v) -> {
View view = dialog.initDialog(context, R.layout.dialog_photo);
ImageView photoView = view.findViewById(R.id.photoView);
photoView.setOnClickListener(View -> {
dialog.dis();
});
imageLoader.bindImage(photoView, cardInfo.Code, null, true);
showCardImageDetail(cardInfo.Code);
});
name.setText(cardInfo.Name);
desc.setText(cardInfo.Desc);
......@@ -244,6 +288,55 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
private void showCardImageDetail(int code) {
AppsSettings appsSettings = AppsSettings.get();
File file = new File(appsSettings.getCardImagePath(code));
View view = dialog.initDialog(context, R.layout.dialog_photo);
dialog.setDialogWidth(ViewGroup.LayoutParams.MATCH_PARENT);
photoView = view.findViewById(R.id.photoView);
ll_bar = view.findViewById(R.id.ll_bar);
pb_loading = view.findViewById(R.id.pb_loading);
tv_loading = view.findViewById(R.id.tv_name);
pb_loading.setMax(100);
photoView.setOnClickListener(View -> {
dialog.dis();
});
//先显示普通卡片大图,判断如果没有高清图就下载
imageLoader.bindImage(photoView, code, null, true);
if (!file.exists()) {
ll_bar.setVisibility(View.VISIBLE);
ll_bar.startAnimation(AnimationUtils.loadAnimation(context,R.anim.in_from_top));
DownloadUtil.get().download(YGOUtil.getCardImageDetailUrl(code), file.getParent(), file.getName(), new DownloadUtil.OnDownloadListener() {
@Override
public void onDownloadSuccess(File file) {
Message message = new Message();
message.what = TYPE_DOWNLOAD_CARD_IMAGE_OK;
message.arg1 = code;
handler.sendMessage(message);
}
@Override
public void onDownloading(int progress) {
Message message = new Message();
message.what = TYPE_DOWNLOAD_CARD_IMAGE_ING;
message.arg1 = progress;
handler.sendMessage(message);
}
@Override
public void onDownloadFailed(Exception e) {
Message message = new Message();
message.what = TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION;
message.obj = e.toString();
handler.sendMessage(message);
}
});
}
}
public void onPreCard() {
int position = getCurPosition();
CardListProvider provider = getProvider();
......@@ -327,4 +420,5 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
}
......@@ -66,7 +66,6 @@ import cn.garymb.ygomobile.ui.cards.deck.DeckItemTouchHelper;
import cn.garymb.ygomobile.ui.cards.deck.DeckItemType;
import cn.garymb.ygomobile.ui.cards.deck.DeckLayoutManager;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import cn.garymb.ygomobile.ui.plus.AOnGestureListener;
import cn.garymb.ygomobile.ui.plus.DefaultOnBoomListener;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
......@@ -78,6 +77,7 @@ import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.ShareUtil;
import cn.garymb.ygomobile.utils.YGODialogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
import ocgcore.DataManager;
import ocgcore.data.Card;
import ocgcore.data.LimitList;
......@@ -800,10 +800,10 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView
public void onClick(View v) {
du.dis();
stopService(new Intent(DeckManagerActivityImpl.this, ServiceDuelAssistant.class));
Util.fzMessage(DeckManagerActivityImpl.this, et_code.getText().toString().trim());
YGOUtil.copyMessage(DeckManagerActivityImpl.this, et_code.getText().toString().trim());
showToast(getString(R.string.deck_text_copyed));
//复制完毕开启决斗助手
Util.startDuelService(DeckManagerActivityImpl.this);
YGOUtil.startDuelService(DeckManagerActivityImpl.this);
}
});
......
......@@ -77,9 +77,9 @@ import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.PayUtils;
import cn.garymb.ygomobile.utils.ScreenUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
import static cn.garymb.ygomobile.Constants.ASSET_SERVER_LIST;
import static cn.garymb.ygomobile.ui.mycard.mcchat.util.Util.startDuelService;
public abstract class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
//卡查关键字
......@@ -152,7 +152,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
//check update
Beta.checkUpgrade(false, false);
//ServiceDuelAssistant
startDuelService(this);
YGOUtil.startDuelService(this);
//萌卡
StartMycard();
checkNotch();
......
......@@ -18,7 +18,7 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.mycard.mcchat.adapter.ChatAdapter;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import cn.garymb.ygomobile.utils.YGOUtil;
public class McchatActivity extends Activity implements ChatListener {
......@@ -101,13 +101,13 @@ public class McchatActivity extends Activity implements ChatListener {
public void onClick(View p1) {
String message = main_send_message.getText().toString().trim();
if (message.equals("")) {
Util.show(McchatActivity.this, getString(R.string.noting_to_send));
YGOUtil.show( getString(R.string.noting_to_send));
} else {
try {
su.sendMessage(message);
main_send_message.setText("");
} catch (Exception e) {
Util.show(McchatActivity.this, getString(R.string.sending_failed));
YGOUtil.show( getString(R.string.sending_failed));
}
}
// TODO: Implement this method
......
......@@ -23,7 +23,7 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.mycard.MyCardActivity;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import cn.garymb.ygomobile.utils.YGOUtil;
public class SplashActivity extends Activity {
......@@ -43,7 +43,7 @@ public class SplashActivity extends Activity {
su.setIsConnected(false);
sp_jz.setVisibility(View.GONE);
sp_tv.setText(getString(R.string.logining_failed));
Util.show(SplashActivity.this, getString(R.string.failed_reason) + msg.obj);
YGOUtil.show( getString(R.string.failed_reason) + msg.obj);
break;
case 1:
startActivity(new Intent(SplashActivity.this, McchatActivity.class));
......
......@@ -19,7 +19,7 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.mycard.mcchat.ChatMessage;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import cn.garymb.ygomobile.utils.YGOUtil;
public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
......@@ -84,8 +84,8 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
@Override
public boolean onLongClick(View p1) {
Util.fzMessage(context, cm.getMessage());
Util.show(context, "已复制到剪贴板");
YGOUtil.copyMessage(context, cm.getMessage());
YGOUtil.show( "已复制到剪贴板");
// TODO: Implement this method
return true;
}
......@@ -94,7 +94,7 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
@Override
public void onClick(View p1) {
Util.closeKeyboard((Activity) context);
YGOUtil.closeKeyboard((Activity) context);
// TODO: Implement this method
}
});
......
package cn.garymb.ygomobile.ui.mycard.mcchat.util;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant;
import cn.garymb.ygomobile.utils.PermissionUtil;
public class Util {
//提示
public static void show(Context context, String message) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
//关闭输入法
public static void closeKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager == null)
return;
View view = activity.getCurrentFocus();
if (view == null)
return;
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken()
, InputMethodManager.HIDE_NOT_ALWAYS);
}
//复制字符串到剪贴板
public static void fzMessage(Context context, String message) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setPrimaryClip(ClipData.newPlainText(null, message));//复制命令
}
public static void startDuelService(Context context) {
if (AppsSettings.get().isServiceDuelAssistant() && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
DialogPlus dialogPlus = PermissionUtil.isNotificationPermission(context);
if (dialogPlus == null)
context.startForegroundService(new Intent(context, ServiceDuelAssistant.class));
else
dialogPlus.show();
} else {
context.startService(new Intent(context, ServiceDuelAssistant.class));
}
}
}
}
package cn.garymb.ygomobile.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class DownloadUtil {
private static DownloadUtil downloadUtil;
private final OkHttpClient okHttpClient;
public static DownloadUtil get() {
if (downloadUtil == null) {
downloadUtil = new DownloadUtil();
}
return downloadUtil;
}
public DownloadUtil() {
okHttpClient = new OkHttpClient();
}
/**
* @param url 下载连接
* @param destFileDir 下载的文件储存目录
* @param destFileName 下载文件名称
* @param listener 下载监听
*/
public void download(final String url, final String destFileDir, final String destFileName, final OnDownloadListener listener) {
Request request = new Request.Builder()
.url(url)
.build();
/* OkHttpClient client = new OkHttpClient();
try {
Response response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}*/
//异步请求
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// 下载失败监听回调
listener.onDownloadFailed(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
InputStream is = null;
byte[] buf = new byte[2048];
int len = 0;
FileOutputStream fos = null;
//储存下载文件的目录
File dir = new File(destFileDir);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, destFileName);
try {
is = response.body().byteStream();
long total = response.body().contentLength();
fos = new FileOutputStream(file);
long sum = 0;
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
sum += len;
int progress = (int) (sum * 1.0f / total * 100);
//下载中更新进度条
listener.onDownloading(progress);
}
fos.flush();
//下载完成
listener.onDownloadSuccess(file);
} catch (Exception e) {
listener.onDownloadFailed(e);
}finally {
try {
if (is != null) {
is.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
}
}
}
});
}
public static interface OnDownloadListener{
/**
* 下载成功之后的文件
*/
void onDownloadSuccess(File file);
/**
* 下载进度
*/
void onDownloading(int progress);
/**
* 下载异常信息
*/
void onDownloadFailed(Exception e);
}
}
package cn.garymb.ygomobile.utils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.text.InputType;
import android.view.Gravity;
import android.widget.EditText;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.text.InputType;
import android.view.Gravity;
import android.widget.EditText;
import com.base.bj.paysdk.domain.TrPayResult;
import com.base.bj.paysdk.listener.PayResultListener;
import com.base.bj.paysdk.utils.TrPay;
import com.base.bj.paysdk.domain.TrPayResult;
import com.base.bj.paysdk.listener.PayResultListener;
import com.base.bj.paysdk.utils.TrPay;
import java.net.URLEncoder;
import java.util.UUID;
import java.net.URLEncoder;
import java.util.UUID;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import static cn.garymb.ygomobile.Constants.ALIPAY_URL;
import static cn.garymb.ygomobile.Constants.ALIPAY_URL;
public class PayUtils {
/***
......@@ -88,7 +89,7 @@ public class PayUtils {
public static String getID(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
@SuppressLint("MissingPermission") String imei = telephonyManager.getDeviceId();
return imei;
}
}
package cn.garymb.ygomobile.utils;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant;
public class YGOUtil {
......@@ -20,4 +31,43 @@ public class YGOUtil {
public static String s(int stringId){
return App.get().getResources().getString(stringId);
}
public static String getCardImageDetailUrl(int code){
return "https://code.mycard.moe/fallenstardust/ygoimage/raw/master/"+code+".jpg";
}
//关闭输入法
public static void closeKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager == null)
return;
View view = activity.getCurrentFocus();
if (view == null)
return;
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken()
, InputMethodManager.HIDE_NOT_ALWAYS);
}
//复制字符串到剪贴板
public static void copyMessage(Context context, String message) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setPrimaryClip(ClipData.newPlainText(null, message));//复制命令
}
public static void startDuelService(Context context) {
if (AppsSettings.get().isServiceDuelAssistant() && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
DialogPlus dialogPlus = PermissionUtil.isNotificationPermission(context);
if (dialogPlus == null)
context.startForegroundService(new Intent(context, ServiceDuelAssistant.class));
else
dialogPlus.show();
} else {
context.startService(new Intent(context, ServiceDuelAssistant.class));
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromYDelta = "-100%"
android:toYDelta = "0%"
android:duration = "250" >
</translate>
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromYDelta = "0%"
android:toYDelta = "-100%"
android:duration = "250" >
</translate>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:background="@color/tr_transparent_background" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="fitCenter" />
<LinearLayout
android:visibility="gone"
android:id="@+id/ll_bar"
android:background="@color/gray"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_name"
android:textColor="@color/black"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:textStyle="bold"
android:text="下载高清卡图中"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="@+id/pb_loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar.Horizontal" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tr_transparent_background">
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="350dp"
......
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