version:1.2

fix:修复首页不显示应用
add:
This commit is contained in:
2022-01-04 16:15:49 +08:00
parent dc3d192e51
commit 8a8f215bdb
5 changed files with 160 additions and 293 deletions

View File

@@ -154,6 +154,11 @@ dependencies {
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//butterknife
implementation 'com.jakewharton:butterknife:10.2.1'
// If you are using Kotlin, replace annotationProcessor with kapt.
// annotationProcessor rootProject.ext.dependencies["butterknife-compiler"]
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
//github第三方控件
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
//下拉刷新控件

View File

@@ -36,14 +36,10 @@ import java.util.List;
*/
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
private List<AppInfo> mAppInfoList;
private Context mContext;
private DownloadTask mDownloadTask;
//order代表是否显示所在的位置1.2.3.
public AppAdapter(List<AppInfo> appInfoList, Context context) {
this.mContext = context;
this.mAppInfoList = appInfoList;
@@ -208,6 +204,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
break;
case IEntity.STATE_CANCEL:
break;
default:
}
}
@@ -237,6 +234,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
break;
case IEntity.STATE_CANCEL:
break;
default:
}
}
}
@@ -246,51 +244,6 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
notifyDataSetChanged();
}
// private class ListDownloadListener extends DownloadListener {
//
// private Holder holder;
//
// ListDownloadListener(Object tag, Holder holder) {
// super(tag);
// this.holder = holder;
// }
//
// @Override
// public void onStart(Progress progress) {
//
// }
//
// @Override
// public void onProgress(Progress progress) {
// if (tag == holder.getTag()) {
// holder.refresh(progress);
// }
// }
//
// @Override
// public void onError(Progress progress) {
// Throwable throwable = progress.exception;
// if (throwable != null) throwable.printStackTrace();
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试");
// }
//
// @Override
// public void onFinish(final File file, Progress progress) {
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
// new Thread(new Runnable() {
// @Override
// public void run() {
// ApkUtils.installApp(mContext, file.getAbsolutePath());
// }
// }).start();
// }
//
// @Override
// public void onRemove(Progress progress) {
//
// }
// }
private void ItemChanged(DownloadTask task) {
mDownloadTask = task;
// notifyDataSetChanged();
@@ -345,6 +298,4 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
void onTaskFail(DownloadTask task, Exception e) {
ItemChanged(task);
}
}

View File

@@ -9,15 +9,12 @@ import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -28,7 +25,6 @@ import androidx.recyclerview.widget.SimpleItemAnimator;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.uiui.appstore.BuildConfig;
import com.uiui.appstore.R;
@@ -48,8 +44,6 @@ import com.uiui.appstore.utils.Utils;
import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhpan.bannerview.BannerViewPager;
import com.zhpan.bannerview.constants.IndicatorSlideMode;
import com.zhpan.bannerview.constants.PageStyle;
@@ -59,6 +53,8 @@ import com.zhpan.bannerview.utils.BannerUtils;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
@@ -73,132 +69,47 @@ import io.reactivex.schedulers.Schedulers;
public class FeaturedFragment extends LazyLoadFragment implements RefreshManager.RefreshInterface {
private String TAG = FeaturedFragment.class.getSimpleName();
@BindView(R.id.featured_rv_result)
RecyclerView mRvResult;
@BindView(R.id.cl)
ConstraintLayout cl;
@BindView(R.id.featured_refresh_layout)
SmartRefreshLayout mRefreshLayout;
@BindView(R.id.iv_banner)
ImageView iv_banner;
@BindView(R.id.banner_view)
BannerViewPager<String, BannerViewHolder> mViewPager;
private RecyclerView mRvResult;
private SmartRefreshLayout mRefreshLayout;
private BannerViewPager<String, BannerViewHolder> mViewPager;
private ImageView imageView, iv_banner;
private List<AppInfos> appInfoList;//
private List<AppInfo> newAppInfoList = new ArrayList<>();
private AppAdapter adapter;
private ConstraintLayout cl;
private boolean isNotLoadBitmap;
private installReceiver myReceiver;
private Context mContext;
public FeaturedFragment() {
}
@Override
public void onRefresh() {
mRefreshLayout.autoRefresh();
}
@Override
public void onLoadBitMap(boolean isLoad) {
}
@Override
public int getLayoutId() {
return R.layout.fragment_featured;
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
if (myReceiver != null) {
try {
getActivity().unregisterReceiver(myReceiver);
} catch (Exception e) {
LogUtils.e("onStop", e.getMessage());
}
}
}
@Override
public void initDatas() {
mContext = this.getActivity();
adapter = new AppAdapter(newAppInfoList, getActivity());
adapter.setHasStableIds(true);
int orientation = 0;
orientation = mContext.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
mRvResult.setLayoutManager(gridLayoutManager);
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
mRvResult.setLayoutManager(gridLayoutManager);
} else {
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
}
mRvResult.setAdapter(adapter);
mRefreshLayout.setEnableLoadMore(false);
mRefreshLayout.setEnableRefresh(true);
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
// initData();
initAPPData(handler);
}
});
mRefreshLayout.autoRefresh();
adapter.setData(newAppInfoList);
adapter.notifyDataSetChanged();
}
@Override
public void onConfigurationChanged(@androidx.annotation.NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
mRvResult.setLayoutManager(gridLayoutManager);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
mRvResult.setLayoutManager(gridLayoutManager);
} else {
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
}
initAPPData(handler);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
adapter.notifyDataSetChanged();
if (myReceiver == null) {
myReceiver = new installReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
getActivity().registerReceiver(myReceiver, filter);
}
}
@Override
public void initViews(View view) {
mRvResult = view.findViewById(R.id.featured_rv_result);
ButterKnife.bind(this, view);
((SimpleItemAnimator) mRvResult.getItemAnimator()).setSupportsChangeAnimations(false);
// mRvResult.setItemAnimator(null);
imageView = view.findViewById(R.id.imageView);
iv_banner = view.findViewById(R.id.iv_banner);
cl = view.findViewById(R.id.ll);
setImageViewSize();
mRefreshLayout = view.findViewById(R.id.featured_refresh_layout);
RefreshManager.getInstance().register(this);
mViewPager = view.findViewById(R.id.banner_view);
mViewPager
.setIndicatorSlideMode(IndicatorSlideMode.SMOOTH)
mViewPager.setIndicatorSlideMode(IndicatorSlideMode.SMOOTH)
.setHolderCreator(new HolderCreator<BannerViewHolder>() {
@Override
public BannerViewHolder createViewHolder() {
@@ -216,18 +127,104 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
isNotLoadBitmap = false;
}
@Override
public void initDatas() {
adapter = new AppAdapter(newAppInfoList, getActivity());
adapter.setHasStableIds(true);
int orientation = 0;
orientation = getActivity().getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
mRvResult.setLayoutManager(gridLayoutManager);
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
mRvResult.setLayoutManager(gridLayoutManager);
} else {
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
}
mRvResult.setAdapter(adapter);
mRefreshLayout.setEnableLoadMore(false);
mRefreshLayout.setEnableRefresh(true);
mRefreshLayout.setOnRefreshListener(refreshlayout -> {
initAPPData();
});
adapter.setData(newAppInfoList);
mRefreshLayout.autoRefresh();
}
@Override
public void loadData(Bundle savedInstanceState) {
// initData();
// initAPPData(handler);
}
synchronized private void initAPPData(final Handler handler) {
// OKGO.getAllAppInfo(handler);
@Override
public void onConfigurationChanged(@androidx.annotation.NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
mRvResult.setLayoutManager(gridLayoutManager);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
mRvResult.setLayoutManager(gridLayoutManager);
} else {
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
}
initAPPData();
}
@Override
public void onResume() {
super.onResume();
registerReceiver();
adapter.notifyDataSetChanged();
}
@Override
public void onDestroy() {
super.onDestroy();
if (myReceiver != null) {
try {
getActivity().unregisterReceiver(myReceiver);
} catch (Exception e) {
LogUtils.e("onDestroy", e.getMessage());
}
}
}
private void registerReceiver() {
if (myReceiver == null) {
myReceiver = new installReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
getActivity().registerReceiver(myReceiver, filter);
}
}
private installReceiver myReceiver;
public class installReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//接收安装广播
if (action.equals(Intent.ACTION_PACKAGE_ADDED)
|| action.equals(Intent.ACTION_PACKAGE_REPLACED)
|| action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged();
Log.e("installReceiver", action);
}
}
}
synchronized private void initAPPData() {
getAllAppInfo();
// OKGO.getBannerImg(handler);
// getBannerImg();
getBanner();
}
@@ -299,7 +296,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
});
}
private void setBannerResource(String url){
private void setBannerResource(String url) {
Glide.with(iv_banner)
.load(url)
.transition(new DrawableTransitionOptions().dontTransition())
@@ -360,16 +357,6 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
Log.e(TAG, "setImageViewSize: imageViewheight :" + iv_banner.getHeight());
}
@Override
public void onRefresh() {
mRefreshLayout.autoRefresh();
}
@Override
public void onLoadBitMap(boolean isLoad) {
}
private void getAllAppInfo() {
NetInterfaceManager.getInstance().getQueryAllAppControl().getAllApp(Utils.getSerial())
.subscribeOn(Schedulers.io())
@@ -387,13 +374,13 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
if (code == 200) {
List<AppInfo> infos = listBaseResponse.data;
newAppInfoList = infos;
mRvResult.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);
// mRvResult.setVisibility(View.VISIBLE);
// imageView.setVisibility(View.GONE);
adapter.setData(newAppInfoList);
adapter.notifyDataSetChanged();
} else {
mRvResult.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
// mRvResult.setVisibility(View.GONE);
// imageView.setVisibility(View.VISIBLE);
if (!BuildConfig.DEBUG) {
Intent intent = new Intent();
// intent.putExtra("text", getResources().getString(R.string.no_app));
@@ -488,72 +475,4 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
});
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
// case 0:
// mRvResult.setVisibility(View.GONE);
// imageView.setVisibility(View.VISIBLE);
// break;
// case 1:
// mRvResult.setVisibility(View.VISIBLE);
// imageView.setVisibility(View.GONE);
// newAppInfoList = (List<AppInfo>) msg.obj;
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
// adapter.notifyDataSetChanged();
// break;
case 200:
List<String> list = (List<String>) msg.obj;
mViewPager
.setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_5))
.setRevealWidth(BannerUtils.dp2px(0))
.setPageStyle(PageStyle.MULTI_PAGE)
.setHolderCreator(new HolderCreator<BannerViewHolder>() {
@Override
public BannerViewHolder createViewHolder() {
return new BannerViewHolder();
}
})
.setIndicatorColor(getResources().getColor(R.color.white), getResources().getColor(R.color.colorAccent))
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
@Override
public void onPageClick(int position) {
}
})
.setInterval(5000)
.create(list);
break;
}
mRefreshLayout.finishRefresh();
}
};
// public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
// for (AppInfo appInfo : list) {
// appInfo.setInstall(ApkUtils.isAvailable(mContext, appInfo.getApp_package()));
// appInfo.setUpdate(ApkUtils.checkIsUpdate(mContext, appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
// }
// return list;
// }
public class installReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//接收安装广播
if (action.equals(Intent.ACTION_PACKAGE_ADDED)
|| action.equals(Intent.ACTION_PACKAGE_REPLACED)
|| action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged();
Log.e("installReceiver", action);
}
}
}
}

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@@ -16,7 +15,7 @@
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll"
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@@ -45,31 +44,30 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner_view">
<androidx.recyclerview.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/featured_rv_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:overScrollMode="never" />
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/icon_nodata"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- <ImageView-->
<!-- android:id="@+id/imageView"-->
<!-- android:layout_width="300dp"-->
<!-- android:layout_height="300dp"-->
<!-- android:layout_centerInParent="true"-->
<!-- android:adjustViewBounds="true"-->
<!-- android:scaleType="centerInside"-->
<!-- android:src="@drawable/icon_nodata"-->
<!-- android:visibility="gone"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@@ -16,7 +15,7 @@
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll"
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -45,39 +44,34 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner_view">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sdasdasd"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@+id/featured_rv_result" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/featured_rv_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:overScrollMode="never" />
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/icon_nodata"
android:visibility="gone"
android:overScrollMode="never"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- <ImageView-->
<!-- android:id="@+id/imageView"-->
<!-- android:layout_width="300dp"-->
<!-- android:layout_height="300dp"-->
<!-- android:layout_centerInParent="true"-->
<!-- android:adjustViewBounds="true"-->
<!-- android:scaleType="centerInside"-->
<!-- android:src="@drawable/icon_nodata"-->
<!-- android:visibility="gone"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>