version:1.0.1
fix: update:基本跳转对接完成
This commit is contained in:
@@ -11,11 +11,12 @@ import android.widget.RelativeLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.FragmentAiBinding;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.jxw.Util;
|
||||
import com.youth.banner.adapter.BannerAdapter;
|
||||
import com.youth.banner.listener.OnBannerListener;
|
||||
import com.youth.banner.transformer.ZoomOutPageTransformer;
|
||||
@@ -84,22 +85,13 @@ public class AiFragment extends BaseMvvmFragment<AiViewModel, FragmentAiBinding>
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
|
||||
mViewDataBinding.banner.setOnBannerListener(new OnBannerListener<String>() {
|
||||
@Override
|
||||
public void OnBannerClick(String s, int i) {
|
||||
if (i == 2) {
|
||||
// Util.downloadClickListener(getActivity(), "com.jxw.aikyls", "com.jxw.aiteacher.ui.SplashActivity", null, "ai口语老师");
|
||||
} else if (i == 3) {
|
||||
// Util.downloadClickListener(getActivity(), "com.jxw.aixhb", "com.jxw.aixhb.mvi.ui.activity.MainActivity", null, "AI小伙伴");
|
||||
}
|
||||
}
|
||||
});
|
||||
List<String> arrayList = new ArrayList<String>() {{
|
||||
this.add("1");
|
||||
this.add("1");
|
||||
this.add("1");
|
||||
this.add("1");
|
||||
}};
|
||||
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
arrayList.add("1");
|
||||
arrayList.add("1");
|
||||
arrayList.add("1");
|
||||
arrayList.add("1");
|
||||
mViewDataBinding.banner.addBannerLifecycleObserver(this)
|
||||
.setAdapter(new BannerExampleAdapter(arrayList))
|
||||
.setIndicator(mViewDataBinding.indicator, false)
|
||||
@@ -112,8 +104,20 @@ public class AiFragment extends BaseMvvmFragment<AiViewModel, FragmentAiBinding>
|
||||
.setPageTransformer(new ZoomOutPageTransformer())
|
||||
.isAutoLoop(false)
|
||||
.setBannerGalleryEffect((int) getResources().getDimension(R.dimen.x30), (int) getResources().getDimension(R.dimen.x30));
|
||||
|
||||
mViewDataBinding.banner.setOnBannerListener(new OnBannerListener<String>() {
|
||||
@Override
|
||||
public void OnBannerClick(String s, int position) {
|
||||
if (position == 2) {
|
||||
Util.downloadClickListener(getActivity(), "com.jxw.aikyls", "com.jxw.aiteacher.ui.SplashActivity", null, "ai口语老师");
|
||||
} else if (position == 3) {
|
||||
Util.downloadClickListener(getActivity(), "com.jxw.aixhb", "com.jxw.aixhb.mvi.ui.activity.MainActivity", null, "AI小伙伴");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initData(Bundle savedInstanceState) {
|
||||
|
||||
@@ -144,9 +148,7 @@ public class AiFragment extends BaseMvvmFragment<AiViewModel, FragmentAiBinding>
|
||||
|
||||
|
||||
public class BtnClick {
|
||||
public void openPrecisionHome(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class BannerExampleAdapter extends BannerAdapter<String, BannerExampleAdapter.ImageTitleHolder> {
|
||||
@@ -186,23 +188,23 @@ public class AiFragment extends BaseMvvmFragment<AiViewModel, FragmentAiBinding>
|
||||
}
|
||||
|
||||
public class ImageTitleHolder extends RecyclerView.ViewHolder {
|
||||
public ImageView aijzx;
|
||||
public ImageView fdzy;
|
||||
public ImageView pgkst;
|
||||
public ImageView pgzy;
|
||||
public ImageView pzst;
|
||||
public RelativeLayout rl_root;
|
||||
public ImageView ykyl;
|
||||
RelativeLayout rl_root;
|
||||
ImageView aijzx;
|
||||
ImageView fdzy;
|
||||
ImageView pgkst;
|
||||
ImageView pgzy;
|
||||
ImageView pzst;
|
||||
ImageView ykyl;
|
||||
|
||||
public ImageTitleHolder(View view) {
|
||||
super(view);
|
||||
this.rl_root = view.findViewById(R.id.rl_root);
|
||||
this.fdzy = view.findViewById(R.id.fdzy);
|
||||
this.pgkst = view.findViewById(R.id.pgkst);
|
||||
this.pgzy = view.findViewById(R.id.pgzy);
|
||||
this.ykyl = view.findViewById(R.id.ykyl);
|
||||
this.aijzx = view.findViewById(R.id.aijzx);
|
||||
this.pzst = view.findViewById(R.id.pzst);
|
||||
rl_root = view.findViewById(R.id.rl_root);
|
||||
fdzy = view.findViewById(R.id.fdzy);
|
||||
pgkst = view.findViewById(R.id.pgkst);
|
||||
pgzy = view.findViewById(R.id.pgzy);
|
||||
ykyl = view.findViewById(R.id.ykyl);
|
||||
aijzx = view.findViewById(R.id.aijzx);
|
||||
pzst = view.findViewById(R.id.pzst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,41 @@ package com.xwad.os.fragment.chinese;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
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.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
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.FragmentChineseBinding;
|
||||
import com.xwad.os.jxw.AssertUtils;
|
||||
import com.xwad.os.jxw.SPUtils;
|
||||
import com.xwad.os.jxw.Util;
|
||||
import com.xwad.os.manager.AmapManager;
|
||||
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.
|
||||
@@ -22,8 +46,32 @@ import com.xwad.os.manager.AmapManager;
|
||||
*/
|
||||
public class ChineseFragment extends BaseMvvmFragment<ChineseViewModel, FragmentChineseBinding> implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||
private static final String TAG = "ChineseFragment";
|
||||
private static final String FILE_NAME = "app_list_yw";
|
||||
private static final String type = "yw";
|
||||
|
||||
|
||||
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
|
||||
@@ -125,11 +173,17 @@ public class ChineseFragment extends BaseMvvmFragment<ChineseViewModel, Fragment
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
@@ -169,6 +223,19 @@ public class ChineseFragment extends BaseMvvmFragment<ChineseViewModel, Fragment
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void setTag(View view) {
|
||||
String str;
|
||||
String checkGrade = Util.checkGrade(SPUtils.getGrade());
|
||||
if (checkGrade.equals("小学")) {
|
||||
str = "tag_args_new_ztsp_xxyw";
|
||||
} else {
|
||||
str = checkGrade.equals("初中") ? "tag_args_new_ztsp_czyw" : "tag_args_new_ztsp_gzyw";
|
||||
}
|
||||
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);
|
||||
@@ -181,10 +248,92 @@ public class ChineseFragment extends BaseMvvmFragment<ChineseViewModel, Fragment
|
||||
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/yw_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 x(View view) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,41 @@ package com.xwad.os.fragment.english;
|
||||
|
||||
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.bumptech.glide.Glide;
|
||||
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.bean.jxw.TbddBookBean;
|
||||
import com.xwad.os.databinding.FragmentEnglishBinding;
|
||||
import com.xwad.os.jxw.AssertUtils;
|
||||
import com.xwad.os.jxw.SPUtils;
|
||||
import com.xwad.os.jxw.TbddProviderUtil;
|
||||
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 +45,31 @@ import com.xwad.os.databinding.FragmentEnglishBinding;
|
||||
*/
|
||||
public class EnglishFragment extends BaseMvvmFragment<EnglishViewModel, FragmentEnglishBinding> {
|
||||
private static final String TAG = "EnglishFragment";
|
||||
private static final String FILE_NAME = "app_list_yy";
|
||||
private static final String type = "yy";
|
||||
|
||||
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
|
||||
@@ -114,12 +164,21 @@ public class EnglishFragment extends BaseMvvmFragment<EnglishViewModel, Fragment
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchData() {
|
||||
Log.e(TAG, "fetchData: ");
|
||||
Log.e("zsj", "lazyLoad");
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,6 +186,20 @@ public class EnglishFragment extends BaseMvvmFragment<EnglishViewModel, Fragment
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
private void setTag(View view) {
|
||||
String str;
|
||||
String checkGrade = Util.checkGrade(SPUtils.getGrade());
|
||||
if (checkGrade.equals("小学")) {
|
||||
str = "tag_args_new_ztsp_xxyy";
|
||||
} else {
|
||||
str = checkGrade.equals("初中") ? "tag_args_new_ztsp_czyy" : "tag_args_new_ztsp_gzyy";
|
||||
}
|
||||
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);
|
||||
@@ -139,5 +212,107 @@ public class EnglishFragment extends BaseMvvmFragment<EnglishViewModel, Fragment
|
||||
mViewDataBinding.ivTabJdbk.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
TbddBookBean tbddData = TbddProviderUtil.getTbddData("英语", "", "");
|
||||
try {
|
||||
if (tbddData != null) {
|
||||
mViewDataBinding.ivZb.setVisibility(View.VISIBLE);
|
||||
Glide.with(mContext).load(tbddData.getCoverUrl()).into(mViewDataBinding.ivCover);
|
||||
} else {
|
||||
mViewDataBinding.ivZb.setVisibility(View.GONE);
|
||||
mViewDataBinding.ivCover.setBackgroundResource(R.drawable.icon_yw_tjsb);
|
||||
}
|
||||
} catch (Exception unused) {
|
||||
}
|
||||
}
|
||||
|
||||
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/yy_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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,31 @@ package com.xwad.os.fragment.read;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xwad.os.bean.jxw.YdbgBean;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.FragmentReadBinding;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.jxw.fragment.BookFragment;
|
||||
import com.xwad.os.jxw.fragment.BookListFragment;
|
||||
import com.xwad.os.view.jxw.view.VerticalProgressBar;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
@@ -22,6 +39,12 @@ public class ReadFragment extends BaseMvvmFragment<ReadViewModel, FragmentReadBi
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private MyAdapter adapter;
|
||||
private List<Fragment> mFragment = new ArrayList();
|
||||
int progressBarMax = 0;
|
||||
private List<YdbgBean> ydbgBeanLists;
|
||||
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
@@ -72,6 +95,37 @@ public class ReadFragment extends BaseMvvmFragment<ReadViewModel, FragmentReadBi
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
mViewDataBinding.subjectViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int i, float f, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int i) {
|
||||
if (i == 0) {
|
||||
mViewDataBinding.tvTitle.setText("最近阅读");
|
||||
} else {
|
||||
mViewDataBinding.tvTitle.setText("我的书架");
|
||||
}
|
||||
mViewDataBinding.indicator.setCurrentPosition(i);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mFragment.add(new BookFragment());
|
||||
mFragment.add(new BookListFragment());
|
||||
adapter = new MyAdapter(getChildFragmentManager());
|
||||
mViewDataBinding.subjectViewPager.setAdapter(adapter);
|
||||
mViewDataBinding.indicator.setCellCount(2);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
mViewDataBinding.rvChart.setLayoutManager(linearLayoutManager);
|
||||
getydbg();
|
||||
|
||||
}
|
||||
|
||||
@@ -88,7 +142,7 @@ public class ReadFragment extends BaseMvvmFragment<ReadViewModel, FragmentReadBi
|
||||
|
||||
@Override
|
||||
public void fetchData() {
|
||||
|
||||
getydbg();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,10 +157,119 @@ public class ReadFragment extends BaseMvvmFragment<ReadViewModel, FragmentReadBi
|
||||
|
||||
}
|
||||
|
||||
private void getydbg() {
|
||||
// try {
|
||||
// JSONObject jSONObject = new JSONObject();
|
||||
// jSONObject.put("oprateType", 1);
|
||||
// OkhtttpUtils.getInstance().doPost(getActivity(), Constant.GW_URL + "/report/api/report/learn/libraryDetail", jSONObject, true, new OkhtttpUtils.OkCallback() {
|
||||
// @Override
|
||||
// public void onFailure(Exception exc) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResponse(String str) {
|
||||
// try {
|
||||
// JSONObject jSONObject2 = new JSONObject(str);
|
||||
// if ("0".equals(jSONObject2.getString("code"))) {
|
||||
// JSONObject jSONObject3 = new JSONObject(jSONObject2.optString("data"));
|
||||
// Type type = new TypeToken<Collection<YdbgBean>>() {
|
||||
// }.getType();
|
||||
// ydbgBeanLists = (List) new Gson().fromJson(jSONObject3.optString("detailList"), type);
|
||||
// initBarChart();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.getMessage();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// } catch (Exception unused) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void initBarChart() {
|
||||
mViewDataBinding.rlNodata.setVisibility(8);
|
||||
mViewDataBinding.rvChart.setVisibility(0);
|
||||
int readTime = (ydbgBeanLists.get(0).getReadTime() / 1000) / 60;
|
||||
for (int i = 1; i < ydbgBeanLists.size(); i++) {
|
||||
if ((ydbgBeanLists.get(i).getReadTime() / 1000) / 60 > readTime) {
|
||||
readTime = (ydbgBeanLists.get(i).getReadTime() / 1000) / 60;
|
||||
}
|
||||
}
|
||||
if (readTime <= 10) {
|
||||
progressBarMax = 10;
|
||||
} else if (readTime <= 100) {
|
||||
progressBarMax = 100;
|
||||
} else if (readTime <= 300) {
|
||||
progressBarMax = 300;
|
||||
} else if (readTime <= 500) {
|
||||
progressBarMax = 500;
|
||||
} else if (readTime <= 700) {
|
||||
progressBarMax = 700;
|
||||
} else if (readTime <= 1000) {
|
||||
progressBarMax = 1000;
|
||||
} else if (readTime <= 1440) {
|
||||
progressBarMax = 1440;
|
||||
}
|
||||
mViewDataBinding.rvChart.setAdapter(new ChartAdapter(ydbgBeanLists));
|
||||
}
|
||||
|
||||
|
||||
class MyAdapter extends FragmentPagerAdapter {
|
||||
public MyAdapter(FragmentManager fragmentManager) {
|
||||
super(fragmentManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return mFragment.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFragment.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return mFragment.get(i).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class ChartAdapter extends BaseQuickAdapter<YdbgBean, BaseViewHolder> {
|
||||
public ChartAdapter(List<YdbgBean> list) {
|
||||
super(R.layout.item_chart, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(BaseViewHolder baseViewHolder, YdbgBean ydbgBean) {
|
||||
VerticalProgressBar verticalProgressBar = baseViewHolder.getView(R.id.battery_pb);
|
||||
verticalProgressBar.setMaxProgress(progressBarMax);
|
||||
verticalProgressBar.setProgress((ydbgBean.getReadTime() / 1000) / 60);
|
||||
String hexWithAlpha = String.format("#%08X", -11485776);
|
||||
Log.e(TAG, "convert: " + hexWithAlpha);
|
||||
verticalProgressBar.setProgressColor(-11485776);
|
||||
((TextView) baseViewHolder.getView(R.id.tv_data)).setText(getWeekOfDate(ydbgBean.getDate()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getWeekOfDate(String str) {
|
||||
try {
|
||||
String[] strArr = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
||||
Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(str);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(parse);
|
||||
int i = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (i < 0) {
|
||||
i = 0;
|
||||
}
|
||||
return strArr[i];
|
||||
} catch (Exception unused) {
|
||||
return str.split("-")[1] + "." + str.split("-")[2];
|
||||
}
|
||||
}
|
||||
|
||||
public class BtnClick {
|
||||
public void openPrecisionHome(View view) {
|
||||
public void x(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user