From 02da8f35124a6f9320ff24e692c50f0448c912a7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 13 Jan 2020 18:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=98=E6=96=97=E6=97=A5?= =?UTF-8?q?=E5=BF=97=20=E6=88=98=E6=96=97=E7=BB=93=E6=9E=9C=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../Adapters/GameDataAdapters/WarAdapter.java | 18 ++- .../jianr_mg/Databases/JianRDataDataBase.java | 5 +- .../Adapters/DaytimeListViewAdapter.java | 81 ++++++++++ .../WarLogFragments/DaytimeFragment.java | 87 ++++++++++- .../WarLogFragments/WarData.java | 143 ++++++++++++++++++ .../com/yutou/jianr_mg/Network/HttpApi.java | 4 +- .../yutou/jianr_mg/views/WarLogActivity.java | 57 +++---- app/src/main/res/layout/item_war.xml | 43 ++++++ 9 files changed, 398 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/Adapters/DaytimeListViewAdapter.java create mode 100644 app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/WarData.java create mode 100644 app/src/main/res/layout/item_war.xml diff --git a/app/build.gradle b/app/build.gradle index 527550f..ad8325d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,13 +16,13 @@ android { } signingConfigs { release { - storeFile file('/media/yutou/_dde_data/AndroidKeys/yutou.jks') + storeFile file('D:\\AndroidKeys\\yutou.jks') storePassword '34864394' keyAlias 'yutou' keyPassword '34864394' } debug { - storeFile file('/media/yutou/_dde_data/AndroidKeys/yutou.jks') + storeFile file('D:\\AndroidKeys\\yutou.jks') storePassword '34864394' keyAlias 'yutou' keyPassword '34864394' diff --git a/app/src/main/java/com/yutou/jianr_mg/Adapters/GameDataAdapters/WarAdapter.java b/app/src/main/java/com/yutou/jianr_mg/Adapters/GameDataAdapters/WarAdapter.java index 0a8d8e0..ff8ad85 100644 --- a/app/src/main/java/com/yutou/jianr_mg/Adapters/GameDataAdapters/WarAdapter.java +++ b/app/src/main/java/com/yutou/jianr_mg/Adapters/GameDataAdapters/WarAdapter.java @@ -105,8 +105,8 @@ public class WarAdapter extends RecyclerAdapter>> { @Override public void onItemViewClick(List> data) { super.onItemViewClick(data); - Utils.toast(getContext(),"详细内容正在咕,敬请期待:"+ AppData.magicPackageName); - /* JSONArray array=new JSONArray(); + // Utils.toast(getContext(),"详细内容正在咕,敬请期待:"+ AppData.magicPackageName); + /*JSONArray array=new JSONArray(); for (Map datum : data) { try { JSONObject json=new JSONObject(); @@ -118,10 +118,20 @@ public class WarAdapter extends RecyclerAdapter>> { e.printStackTrace(); } + }*/ + Map map=data.get(0); + JSONObject json=new JSONObject(); + try { + json.put("data",map.get("data")); + json.put("DealNode",map.get("DealNode")); + json.put("WarReport",map.get("GetWarResult")); + } catch (JSONException e) { + e.printStackTrace(); } + Intent intent=new Intent(getContext(), WarLogActivity.class); - intent.putExtra("data", array.toString()); - getContext().startActivity(intent);*/ + intent.putExtra("data", json.toString()); + getContext().startActivity(intent); } } diff --git a/app/src/main/java/com/yutou/jianr_mg/Databases/JianRDataDataBase.java b/app/src/main/java/com/yutou/jianr_mg/Databases/JianRDataDataBase.java index 28e8d9e..7b324d3 100644 --- a/app/src/main/java/com/yutou/jianr_mg/Databases/JianRDataDataBase.java +++ b/app/src/main/java/com/yutou/jianr_mg/Databases/JianRDataDataBase.java @@ -398,12 +398,13 @@ public class JianRDataDataBase extends SQLiteOpenHelper { public void removeName(String name) { removeData(name); - writeDatabase.delete(TAB_DATA_NAME, "title", new String[]{name}); + writeDatabase.delete(TAB_DATA_NAME, "title=?", new String[]{name}); + } public void removeType(String name) { removeName(name); - writeDatabase.delete(TAB_DATA_TYPE, "typeName", new String[]{name}); + writeDatabase.delete(TAB_DATA_TYPE, "typeName=?", new String[]{name}); } public void clearTable(String tabName){ writeDatabase.execSQL("delete from "+tabName); diff --git a/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/Adapters/DaytimeListViewAdapter.java b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/Adapters/DaytimeListViewAdapter.java new file mode 100644 index 0000000..7b622da --- /dev/null +++ b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/Adapters/DaytimeListViewAdapter.java @@ -0,0 +1,81 @@ +package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.Adapters; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.WarData; +import com.yutou.jianr_mg.R; + +import java.util.List; + +public class DaytimeListViewAdapter extends BaseAdapter { + private Context context; + private List list; + + public DaytimeListViewAdapter(Context context, List list) { + this.context = context; + this.list = list; + } + + @Override + public int getCount() { + return list.size(); + } + + @Override + public Object getItem(int i) { + return list.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @SuppressLint("SetTextI18n") + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + ViewHolder holder; + if (view == null) { + view = LayoutInflater.from(context).inflate(R.layout.item_war, null); + holder = new ViewHolder(); + holder.user = view.findViewById(R.id.user); + holder.arrow = view.findViewById(R.id.arrow); + holder.enemy = view.findViewById(R.id.enemy); + view.setTag(holder); + } else { + holder = (ViewHolder) view.getTag(); + } + WarData warData = list.get(i); + holder.user.setText(warData.getUserName()); + holder.arrow.setText("--" + warData.getAttackModel() + "-->"); + String[] enemyName = warData.getEnemy(); + String name = ""; + for (int j = 0; j < enemyName.length; j++) { + name += enemyName[j] + "(-" + warData.getDamage()[j] + "HP)\n"; + } + holder.enemy.setText(name); + System.out.println(i+" "+list.size()); + return view; + } + + public void setData(List list) { + this.list = list; + notifyDataSetChanged(); + } + + public void clear() { + if (list != null) + list.clear(); + notifyDataSetChanged(); + } + + private class ViewHolder { + TextView user, arrow, enemy; + } +} diff --git a/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/DaytimeFragment.java b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/DaytimeFragment.java index df8e4a3..540a335 100644 --- a/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/DaytimeFragment.java +++ b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/DaytimeFragment.java @@ -1,18 +1,103 @@ package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments; +import android.graphics.Color; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ListView; + +import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.Adapters.DaytimeListViewAdapter; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; public class DaytimeFragment extends Fragment { + private ListView listView; + private DaytimeListViewAdapter adapter; + private JSONObject warReport, json; + private JSONArray shipVO; + + private static DaytimeFragment daytime; + + public static DaytimeFragment init() { + if (daytime == null) { + daytime = new DaytimeFragment(); + } + return daytime; + } + + private DaytimeFragment() { + + } + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return super.onCreateView(inflater, container, savedInstanceState); + if (listView != null) { + return listView; + } + listView = new ListView(getContext()); + if (adapter == null) { + adapter = new DaytimeListViewAdapter(getContext(), new ArrayList<>()); + listView.setAdapter(adapter); + } + initData(); + return listView; + } + public void setData(JSONObject json) { + try { + this.json = json; + shipVO = json.getJSONArray("shipVO"); + warReport = json.getJSONObject("warReport"); + initData(); + } catch (JSONException e) { + e.printStackTrace(); + getActivity().finish(); + } + } + + private void initData() { + List list = new ArrayList<>(); + list.addAll(nextData("openAirAttack", WarData.OPEN_AIR)); + list.addAll(nextData("openMissileAttack", WarData.OPEN_MISSILE)); + list.addAll(nextData("openAntiSubAttack", WarData.OPEN_ANTISUB)); + list.addAll(nextData("openTorpedoAttack", WarData.OPEN_TORPEDO)); + list.addAll(nextData("normalAttacks", WarData.ATTACK_NORMAL)); + list.addAll(nextData("normalAttacks2", WarData.ATTACK_NORMAL_2)); + list.addAll(nextData("closeTorpedoAttack", WarData.CLOSE_TORPEDO)); + list.addAll(nextData("closeMissileAttack", WarData.CLOSE_MISSILE)); + if (adapter != null) + adapter.setData(list); + } + + private List nextData(String name, int model) { + List list = new ArrayList<>(); + try { + for (int i = 0; i < warReport.getJSONArray(name).length(); i++) { + WarData warData = WarData.getInstance(model, warReport.getJSONArray(name).getJSONObject(i), warReport); + if (warData != null) + list.add(warData); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } + + @Override + public void onDestroy() { + super.onDestroy(); + daytime = null; } } diff --git a/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/WarData.java b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/WarData.java new file mode 100644 index 0000000..d8b86b3 --- /dev/null +++ b/app/src/main/java/com/yutou/jianr_mg/Fragments/GameDataFragments/WarLogFragments/WarData.java @@ -0,0 +1,143 @@ +package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments; + +import com.umeng.commonsdk.debug.W; + +import org.json.JSONArray; +import org.json.JSONObject; + +public class WarData { + public final static int OPEN_AIR = 0; + public final static int OPEN_MISSILE = 1; + public final static int OPEN_ANTISUB = 2; + public final static int OPEN_TORPEDO = 3; + public final static int ATTACK_NORMAL = 4; + public final static int ATTACK_NORMAL_2 = 5; + public final static int CLOSE_TORPEDO = 6; + public final static int CLOSE_MISSILE = 7; + private String title; + private String userName; + private long cid; + private int fromIndex; + private String[] enemy; + private int[] damage; + private boolean userAttack; + private int attackModel; + + public String getAttackModel() { + String model; + switch (attackModel) { + case WarData.OPEN_AIR: + model = "航空战"; + break; + case WarData.ATTACK_NORMAL: + model = "炮击"; + break; + case WarData.ATTACK_NORMAL_2: + model = "次轮炮击"; + break; + case WarData.OPEN_MISSILE: + model = "导弹战"; + break; + case WarData.OPEN_TORPEDO: + model = "开幕雷击"; + break; + case WarData.OPEN_ANTISUB: + model = "开幕反潜"; + break; + case WarData.CLOSE_TORPEDO: + model = "闭幕雷击"; + break; + case WarData.CLOSE_MISSILE: + model = "闭幕导弹"; + break; + default: + model = "未知攻击"; + } + return model; + } + + public void setAttackModel(int attackModel) { + this.attackModel = attackModel; + } + + public boolean isUserAttack() { + return userAttack; + } + + public void setUserAttack(boolean userAttack) { + this.userAttack = userAttack; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public long getCid() { + return cid; + } + + public void setCid(long cid) { + this.cid = cid; + } + + public int getFromIndex() { + return fromIndex; + } + + public void setFromIndex(int fromIndex) { + this.fromIndex = fromIndex; + } + + public String[] getEnemy() { + return enemy; + } + + public void setEnemy(String[] enemy) { + this.enemy = enemy; + } + + public int[] getDamage() { + return damage; + } + + public void setDamage(int[] damage) { + this.damage = damage; + } + public static WarData getInstance(int attackModel,JSONObject json,JSONObject warReport){ + WarData warData=null; + try{ + warData=new WarData(); + warData.userAttack= json.getInt("attackSide") == 1; + JSONArray array=warData.isUserAttack()?warReport.getJSONArray("selfShips"):warReport.getJSONArray("enemyShips"); + warData.setUserName(array.getJSONObject(json.getInt("fromIndex")).getString("title")); + warData.setCid(array.getJSONObject(json.getInt("fromIndex")).getLong("shipCid")); + int[] damages=new int[json.getJSONArray("damages").length()]; + for (int i = 0; i < json.getJSONArray("damage").length(); i++) { + damages[i]=json.getJSONArray("damage").getInt(i); + } + warData.setDamage(damages); + String[] enemyNames=new String[json.getJSONArray("targetIndex").length()]; + array=!warData.isUserAttack()?warReport.getJSONArray("selfShips"):warReport.getJSONArray("enemyShips"); + for (int i = 0; i < json.getJSONArray("targetIndex").length(); i++) { + enemyNames[i]=array.getJSONObject(json.getJSONArray("targetIndex").getInt(i)).getString("title"); + } + warData.setEnemy(enemyNames); + warData.setAttackModel(attackModel); + }catch (Exception e){ + e.printStackTrace(); + } + return warData; + } +} diff --git a/app/src/main/java/com/yutou/jianr_mg/Network/HttpApi.java b/app/src/main/java/com/yutou/jianr_mg/Network/HttpApi.java index ca0a4d4..8d11353 100644 --- a/app/src/main/java/com/yutou/jianr_mg/Network/HttpApi.java +++ b/app/src/main/java/com/yutou/jianr_mg/Network/HttpApi.java @@ -5,11 +5,11 @@ package com.yutou.jianr_mg.Network; */ public class HttpApi { - public static final String HOME="http://jianr.jianrmod.cn/"; + //public static final String HOME="http://jianr.jianrmod.cn/"; //public static final String HOME = "http://192.168.31.240:8088/"; //zzz_gz wifi // public static final String HOME = "http://192.168.43.68:8088/"; //zzz_gz wifi //public static final String HOME = "http://192.168.137.1:8088/"; //笔记本本身WIFI - //public static final String HOME = "http://192.168.1.84:8088/"; //公司 + public static final String HOME = "http://192.168.1.151:8080/"; //公司 public static final String HOME_URL=HOME+"android/"; //服务器 public static final String MOD_ALL = "mod/all.do"; diff --git a/app/src/main/java/com/yutou/jianr_mg/views/WarLogActivity.java b/app/src/main/java/com/yutou/jianr_mg/views/WarLogActivity.java index e7a0044..f480fd5 100644 --- a/app/src/main/java/com/yutou/jianr_mg/views/WarLogActivity.java +++ b/app/src/main/java/com/yutou/jianr_mg/views/WarLogActivity.java @@ -7,27 +7,24 @@ import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.AppCompatActivity; import com.yutou.jianr_mg.Adapters.ViewPagerAdapter; -import com.yutou.jianr_mg.Data.ShipEquipmnt; -import com.yutou.jianr_mg.Data.TeamData; import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.DaytimeFragment; import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.NightFragment; import com.yutou.jianr_mg.R; -import com.yutou.jianr_mg.Tools.JianRUtils; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import me.majiajie.pagerbottomtabstrip.NavigationController; import me.majiajie.pagerbottomtabstrip.PageNavigationView; import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener; public class WarLogActivity extends AppCompatActivity { - JSONArray array; + JSONObject json; private PageNavigationView tab; private ViewPager pager; private NavigationController navigationController; @@ -37,54 +34,43 @@ public class WarLogActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mod_list); - initView(); + try { - array = new JSONArray(getIntent().getStringExtra("data")); + json = new JSONObject(Objects.requireNonNull(getIntent().getStringExtra("data"))); } catch (Exception e) { e.printStackTrace(); } - if (array == null) { - array = new JSONArray(); - } - try { - JSONObject json = array.getJSONObject(0); - JSONObject data = json.getJSONObject("DealNode"); - JSONObject msg = new JSONObject(data.getString("message")); - List list = JianRUtils.getUserTeam(msg); - List hm=new ArrayList<>(); - for (TeamData teamData : list) { - // if(teamData.getType()>) - String name = teamData.getTitle(); - List equipment = teamData.getEquipments(); - for (String s : equipment) { - ShipEquipmnt equipmnt = JianRUtils.getEquipmnt(Integer.parseInt(s), -1); - System.out.println("舰娘:"+name+"装备名字:"+equipmnt.getTitle()+" 类型:"+equipmnt.getType()); - } - } - } catch (JSONException e) { - e.printStackTrace(); + if (json == null) { + json = new JSONObject(); } + initView(); } private void initView() { - tab = (PageNavigationView) findViewById(R.id.tab); - pager = (ViewPager) findViewById(R.id.pager); + tab = findViewById(R.id.tab); + pager = findViewById(R.id.pager); List list = new ArrayList<>(); - list.add(new DaytimeFragment()); + list.add(DaytimeFragment.init()); list.add(new NightFragment()); ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), list); pager.setAdapter(adapter); pager.setCurrentItem(0); navigationController = tab.material() - .addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "昼战") - .addItem(R.drawable.icon_night, R.drawable.icon_night_select, "夜战") + .addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "战斗过程") + .addItem(R.drawable.icon_night, R.drawable.icon_night_select, "战斗结束") .build(); navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() { @Override public void onSelected(int index, int old) { pager.setCurrentItem(index); - + if(index==0){ + try { + ((DaytimeFragment)list.get(index)).setData(new JSONObject(json.getJSONObject("DealNode").getString("message"))); + } catch (JSONException e) { + e.printStackTrace(); + } + } } @Override @@ -94,6 +80,11 @@ public class WarLogActivity extends AppCompatActivity { }); navigationController.setupWithViewPager(pager); navigationController.setSelect(0); + try {//message + ((DaytimeFragment)list.get(0)).setData(new JSONObject(json.getJSONObject("DealNode").getString("message"))); + } catch (JSONException e) { + e.printStackTrace(); + } } } diff --git a/app/src/main/res/layout/item_war.xml b/app/src/main/res/layout/item_war.xml new file mode 100644 index 0000000..443296e --- /dev/null +++ b/app/src/main/res/layout/item_war.xml @@ -0,0 +1,43 @@ + + + + + + + + + \ No newline at end of file