Skip to content

Commit

Permalink
all is successful ,it is the first version!
Browse files Browse the repository at this point in the history
happycbbboy committed Feb 6, 2024
1 parent 542de3f commit b89e240
Showing 6 changed files with 21 additions and 32 deletions.
13 changes: 0 additions & 13 deletions app/src/main/java/com/happycbbboy/MainActivity.java
Original file line number Diff line number Diff line change
@@ -33,19 +33,6 @@ public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private Menu menu;

/* private final BroadcastReceiver vpnSuccessReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Notify vpnParam = (Notify) intent.getExtras().get(Notify.PARAM_KEY);
if (vpnParam != null) {
Toast.makeText(MainActivity.this, vpnParam.getTitle() + ":" + vpnParam.getMsg(), Toast.LENGTH_SHORT).show();
if (!Objects.equals(vpnParam.getCode(), Notify.SUCCESS)) {
Log.e("VPN_SERVICE", vpnParam.getError());
}
}
}
};*/

@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
@Override
protected void onCreate(Bundle savedInstanceState) {
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.happycbbboy.ui.base;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.CompoundButton;
@@ -22,8 +23,8 @@ public List<AppUtils.AppInfo> getAllApps() {
return allApps;
}

public AppItermAdapter(Context context,List<AppUtils.AppInfo> allApps) {
if (inflater==null) {
public AppItermAdapter(Context context, List<AppUtils.AppInfo> allApps) {
if (inflater == null) {
inflater = LayoutInflater.from(context);
}
this.allApps = allApps;
@@ -34,12 +35,13 @@ public AppItermAdapter(Context context,List<AppUtils.AppInfo> allApps) {
@NonNull
@Override
public AppItermAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Log.i("AppItermAdapter", "onCreateViewHolder accept");
return new ViewHolder(AppItermBinding.inflate(inflater, parent, false));
}

@Override
public void onBindViewHolder(@NonNull AppItermAdapter.ViewHolder holder, int position) {
// Log.i("AppItermAdapter", "onBindViewHolder accept:"+holder);
Log.i("AppItermAdapter", "onBindViewHolder accept:" + position);
AppUtils.AppInfo appInfo = allApps.get(position);
holder.bind(appInfo);
/* holder.binding.appItermIcon.setImageDrawable(appInfo.getAppIcon());
Original file line number Diff line number Diff line change
@@ -106,11 +106,10 @@ public void onClick(View view) {

vpnOptionsImp.setRoute(routeConfig.getRoute());
if (routeConfig.getCurrentRoutePolicy() == RouteConfig.CURRENT_ROUTE_POLICY_NORMAL) {

}else if (routeConfig.getCurrentRoutePolicy() == RouteConfig.CURRENT_ROUTE_POLICY_FREEE) {
vpnOptionsImp.setIncludePackage(routeConfig.getCheckPackages());
}else if (routeConfig.getCurrentRoutePolicy() == RouteConfig.CURRENT_ROUTE_POLICY_TUNNEL) {
vpnOptionsImp.setExcludePackage(routeConfig.getCheckPackages());
}else if (routeConfig.getCurrentRoutePolicy() == RouteConfig.CURRENT_ROUTE_POLICY_TUNNEL) {
vpnOptionsImp.setIncludePackage(routeConfig.getCheckPackages());
}
// vpnOptionsImp.setExcludePackage(routeConfig.getExcludePackage());
// vpnOptionsImp.setIncludePackage(routeConfig.getIncludePackage());
Original file line number Diff line number Diff line change
@@ -119,8 +119,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
routeAppItrmSelectorConf.setAdapter(spinnerImageTextAdapter);
// 添加滚动监听器实现预加载
LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
layoutManager.setInitialPrefetchItemCount(256); // 设置预加载的Item数量
appListOptions.setLayoutManager(layoutManager);
layoutManager.setInitialPrefetchItemCount(10); // 设置预加载的Item数量
appListOptions.setItemViewCacheSize(256);
Log.i("RouteConfManagerFragment", "start get app info");

if (id != null) {
@@ -131,8 +132,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
name.setText(routeConfig.getName());
StringItermAdapter stringItermAdapter = new StringItermAdapter(routeConfig.getRoute());
routeConfigManagerItems.setAdapter(stringItermAdapter);
List<AppUtils.AppInfo> allInstalledApps = AppUtils.getAllInstalledApps(getContext(),"", routeConfig.getCheckPackages());
AppItermAdapter adapter = new AppItermAdapter(requireContext(),allInstalledApps);
List<AppUtils.AppInfo> allInstalledApps = AppUtils.getAllInstalledApps(getContext(), "", routeConfig.getCheckPackages());
AppItermAdapter adapter = new AppItermAdapter(requireContext(), allInstalledApps);
appListOptions.setAdapter(adapter);
/* // 高速缓存 不再每次调用on create
ViewCacheExtension extension = new ViewCacheExtension(allInstalledApps, adapter, position -> {
@@ -161,15 +162,11 @@ public void onNothingSelected(AdapterView<?> parentView) {
} else {
routeAppItrmSelectorConf.setSelection(RouteConfig.CURRENT_ROUTE_POLICY_NORMAL);

List<AppUtils.AppInfo> allInstalledApps = AppUtils.getAllInstalledApps(requireContext(),"", new ArrayList<>(0));
List<AppUtils.AppInfo> allInstalledApps = AppUtils.getAllInstalledApps(requireContext(), "", new ArrayList<>(0));
// AppItermAdapter adapter = new AppItermAdapter(requireContext(), new ArrayList<>(allInstalledApps.subList(0, Math.min(AppItermAdapter.INITIAL_SIZE, allInstalledApps.size()))));
AppItermAdapter adapter = new AppItermAdapter(requireContext(),allInstalledApps);
appListOptions.setAdapter(adapter);
// 高速缓存 不再每次调用on create
/* ViewCacheExtension extension = new ViewCacheExtension(allInstalledApps, adapter, position -> {
AppUtils.AppInfo appInfo = allInstalledApps.get(position);
return appInfo.toString();
});
appListOptions.setViewCacheExtension(extension);*/

}
// 设置自定义的缓存逻辑
// 在Fragment或Activity中
2 changes: 1 addition & 1 deletion app/src/main/java/com/happycbbboy/utils/AppUtils.java
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ public static synchronized List<AppInfo> getAllInstalledApps(Context context, St
packageManager = context.getPackageManager();
}

if (packagesCache == null || packagesCache.size() != 0) {
if (packagesCache == null || packagesCache.size() == 0) {
// Intent intent = new Intent(Intent.ACTION_MAIN, null);
// intent.addCategory(Intent.CATEGORY_LAUNCHER);
packagesCache = packageManager.getInstalledApplications(0);
8 changes: 6 additions & 2 deletions app/src/main/res/layout/fragment_route_conf_manager.xml
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@
android:src="@android:drawable/ic_menu_add"
tools:ignore="SmallSp" />
</LinearLayout>
<!-- android:layout_height="wrap_content"-->

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/route_config_manager_iterms"
@@ -117,16 +118,19 @@
</LinearLayout>


<!-- android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
-->

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/app_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="500dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:clipToPadding="false"
android:nestedScrollingEnabled="true"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.base.AppItermAdapter"
tools:listitem="@layout/app_iterm" />

0 comments on commit b89e240

Please sign in to comment.