version:1.0.1
fix: update:基本跳转对接完成
This commit is contained in:
@@ -2,14 +2,38 @@ package com.xwad.os.fragment.math;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xwad.os.bean.jxw.ItemsBean;
|
||||
import com.xwad.os.databinding.FragmentMathBinding;
|
||||
import com.xwad.os.jxw.AssertUtils;
|
||||
import com.xwad.os.jxw.SPUtils;
|
||||
import com.xwad.os.jxw.Util;
|
||||
import com.xwad.os.utils.OpenApkUtils;
|
||||
import com.xwad.os.view.jxw.widget.AppsDialog;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
@@ -18,8 +42,31 @@ import com.xwad.os.databinding.FragmentMathBinding;
|
||||
*/
|
||||
public class MathFragment extends BaseMvvmFragment<MathViewModel, FragmentMathBinding> {
|
||||
private static final String TAG = "MathFragment";
|
||||
private static final String FILE_NAME = "app_list_sx";
|
||||
private static final String type = "sx";
|
||||
|
||||
private Activity mContext;
|
||||
private List<ItemsBean> appList = new ArrayList();
|
||||
private BaseQuickAdapter<ItemsBean, BaseViewHolder> contentAdapter = new BaseQuickAdapter<ItemsBean, BaseViewHolder>(R.layout.item_yw_app) {
|
||||
@Override
|
||||
public void convert(BaseViewHolder baseViewHolder, final ItemsBean itemsBean) {
|
||||
RelativeLayout relativeLayout = baseViewHolder.getView(R.id.rl_root);
|
||||
ImageView iv_app_icon = baseViewHolder.getView(R.id.iv_app_icon);
|
||||
TextView tv_app_name = baseViewHolder.getView(R.id.tv_app_name);
|
||||
iv_app_icon.setImageResource(mContext.getResources().getIdentifier(itemsBean.getIcon(), "drawable", mContext.getPackageName()));
|
||||
tv_app_name.setText(itemsBean.getText());
|
||||
relativeLayout.setTag(mContext.getResources().getString(mContext.getResources().getIdentifier(itemsBean.getTag(), "string", mContext.getPackageName())));
|
||||
relativeLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (TextUtils.isEmpty(itemsBean.getTag())) {
|
||||
return;
|
||||
}
|
||||
jumpTag(itemsBean, view);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
@@ -75,7 +122,7 @@ public class MathFragment extends BaseMvvmFragment<MathViewModel, FragmentMathBi
|
||||
mViewModel.setCtx(getCtx());
|
||||
mViewModel.setLifecycle(getLifecycleSubject());
|
||||
mViewModel.setVDBinding(mViewDataBinding);
|
||||
// mViewDataBinding.setClick(new BtnClick());
|
||||
mViewDataBinding.setClick(new BtnClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,6 +162,13 @@ public class MathFragment extends BaseMvvmFragment<MathViewModel, FragmentMathBi
|
||||
|
||||
@Override
|
||||
protected void initData(Bundle savedInstanceState) {
|
||||
setTag(mViewDataBinding.ivZxts);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
mViewDataBinding.rvApps.setLayoutManager(linearLayoutManager);
|
||||
mViewDataBinding.rvApps.setAdapter(contentAdapter);
|
||||
getMyList();
|
||||
contentAdapter.setNewData(appList);
|
||||
|
||||
}
|
||||
|
||||
@@ -128,6 +182,19 @@ public class MathFragment extends BaseMvvmFragment<MathViewModel, FragmentMathBi
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private void setTag(View view) {
|
||||
String str;
|
||||
String checkGrade = Util.checkGrade(SPUtils.getGrade());
|
||||
if (checkGrade.equals("小学")) {
|
||||
str = "tag_args_new_ztsp_xxsx";
|
||||
} else {
|
||||
str = checkGrade.equals("初中") ? "tag_args_new_ztsp_czsx" : "tag_args_new_ztsp_gzsx";
|
||||
}
|
||||
if (getActivity() != null) {
|
||||
view.setTag(getResources().getString(getResources().getIdentifier(str, "string", getActivity().getPackageName())));
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
mViewDataBinding.llTbjzx.setVisibility(View.GONE);
|
||||
mViewDataBinding.llDyfx.setVisibility(View.GONE);
|
||||
@@ -140,5 +207,94 @@ public class MathFragment extends BaseMvvmFragment<MathViewModel, FragmentMathBi
|
||||
mViewDataBinding.ivTabJdbk.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public void getMyList() {
|
||||
File fileStreamPath = mContext.getFileStreamPath(FILE_NAME);
|
||||
if (fileStreamPath.exists()) {
|
||||
try {
|
||||
appList.clear();
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileStreamPath));
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine == null) {
|
||||
break;
|
||||
}
|
||||
ItemsBean itemsBean = new ItemsBean();
|
||||
itemsBean.setText(readLine.split("\\|")[0]);
|
||||
itemsBean.setIcon(readLine.split("\\|")[1]);
|
||||
itemsBean.setTag(readLine.split("\\|")[2]);
|
||||
appList.add(itemsBean);
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (appList == null || appList.size() != 0) {
|
||||
return;
|
||||
}
|
||||
appList.addAll(getApps());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
appList.addAll(getApps());
|
||||
}
|
||||
|
||||
private List<ItemsBean> getApps() {
|
||||
Gson gson = new Gson();
|
||||
String jsonString = AssertUtils.getFromAssets(mContext, "script/sx_default_app.json");
|
||||
Type type = new TypeToken<List<ItemsBean>>() {
|
||||
}.getType();
|
||||
List<ItemsBean> itemsBeans = gson.fromJson(jsonString, type);
|
||||
return itemsBeans;
|
||||
}
|
||||
|
||||
public void jumpTag(ItemsBean itemsBean, View view) {
|
||||
String obj = view.getTag().toString();
|
||||
saveTag(itemsBean);
|
||||
contentAdapter.notifyDataSetChanged();
|
||||
// MyApp.getInstance().mBottomBtnOnClickListener.setContext(getActivity());
|
||||
// MyApp.getInstance().mBottomBtnOnClickListener.onClick(obj);
|
||||
OpenApkUtils.getInstance().openJxwApp(obj);
|
||||
}
|
||||
|
||||
private void saveTag(ItemsBean itemsBean) {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
if (i >= appList.size()) {
|
||||
break;
|
||||
} else if (appList.get(i).getTag().equals(itemsBean.getTag())) {
|
||||
appList.remove(i);
|
||||
break;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
appList.add(0, itemsBean);
|
||||
try {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(mContext.getFileStreamPath(FILE_NAME), false);
|
||||
for (int i2 = 0; i2 < appList.size() && i2 <= 2; i2++) {
|
||||
fileOutputStream.write((appList.get(i2).getText() + "|" + appList.get(i2).getIcon() + "|" + appList.get(i2).getTag() + "\n").getBytes());
|
||||
}
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BtnClick {
|
||||
public void openAppsDialog(View view) {
|
||||
AppsDialog appsDialog = new AppsDialog(getActivity(), type);
|
||||
appsDialog.show();
|
||||
appsDialog.setOnCallback(new AppsDialog.Callback() {
|
||||
|
||||
@Override
|
||||
public void onCallback() {
|
||||
getMyList();
|
||||
contentAdapter.setNewData(appList);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user