Improve app remember position by using first visible item.
This commit is contained in:
parent
8209559012
commit
a247cc997e
|
@ -61,7 +61,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private String packageName;
|
private String packageName;
|
||||||
private MainBinding binding;
|
private MainBinding binding;
|
||||||
private ApplicationListAdapter.OnAppClickListener onAppClickListener;
|
private ApplicationListAdapter.OnAppClickListener onAppClickListener;
|
||||||
private int appPosition;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -72,7 +71,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
getSupportActionBar().setTitle(R.string.app_title);
|
getSupportActionBar().setTitle(R.string.app_title);
|
||||||
}
|
}
|
||||||
fragments = new ArrayList<>();
|
fragments = new ArrayList<>();
|
||||||
appPosition = 0;
|
|
||||||
NetworkListener networkListener = new NetworkListener() {
|
NetworkListener networkListener = new NetworkListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
|
@ -121,11 +119,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
.commit();
|
.commit();
|
||||||
};
|
};
|
||||||
|
|
||||||
onAppClickListener = (vm, position) -> {
|
onAppClickListener = (vm) -> {
|
||||||
try {
|
try {
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
PackageInfo packageInfo = pm.getPackageInfo(vm.packageName, PackageManager.GET_PERMISSIONS);
|
PackageInfo packageInfo = pm.getPackageInfo(vm.packageName, PackageManager.GET_PERMISSIONS);
|
||||||
appPosition = position;
|
|
||||||
ReportFragment report = ReportFragment.newInstance(pm, vm, packageInfo, onTrackerClickListener);
|
ReportFragment report = ReportFragment.newInstance(pm, vm, packageInfo, onTrackerClickListener);
|
||||||
fragments.add(report);
|
fragments.add(report);
|
||||||
FragmentManager manager = getSupportFragmentManager();
|
FragmentManager manager = getSupportFragmentManager();
|
||||||
|
@ -168,10 +165,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
else {
|
else {
|
||||||
getSupportFragmentManager().popBackStack();
|
getSupportFragmentManager().popBackStack();
|
||||||
fragments.remove(fragments.size() - 1);
|
fragments.remove(fragments.size() - 1);
|
||||||
Updatable updatable = fragments.get(fragments.size() - 1);
|
|
||||||
if (updatable instanceof HomeFragment) {
|
|
||||||
((HomeFragment) updatable).scrollTo(appPosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
final ApplicationListViewHolder holder = (ApplicationListViewHolder) viewHolder;
|
final ApplicationListViewHolder holder = (ApplicationListViewHolder) viewHolder;
|
||||||
ApplicationViewModel vm = applicationViewModels.get(position);
|
ApplicationViewModel vm = applicationViewModels.get(position);
|
||||||
holder.setViewModel(vm);
|
holder.setViewModel(vm);
|
||||||
holder.itemView.setOnClickListener(v -> onAppClickListener.onAppClick(vm, position));
|
holder.itemView.setOnClickListener(v -> onAppClickListener.onAppClick(vm));
|
||||||
} else //noinspection RedundantSuppression
|
} else //noinspection RedundantSuppression
|
||||||
{
|
{
|
||||||
//noinspection unused
|
//noinspection unused
|
||||||
|
@ -145,7 +145,7 @@ public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnAppClickListener {
|
public interface OnAppClickListener {
|
||||||
void onAppClick(ApplicationViewModel vm, int position);
|
void onAppClick(ApplicationViewModel vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ApplicationEmptyViewHolder extends RecyclerView.ViewHolder {
|
static class ApplicationEmptyViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import org.eu.exodus_privacy.exodusprivacy.R;
|
import org.eu.exodus_privacy.exodusprivacy.R;
|
||||||
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
|
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
|
||||||
|
@ -28,6 +29,7 @@ public class AppListFragment extends Fragment {
|
||||||
private Type filterType = Type.NAME;
|
private Type filterType = Type.NAME;
|
||||||
private Object filterObject = "";
|
private Object filterObject = "";
|
||||||
private boolean scrollbarEnabled = true;
|
private boolean scrollbarEnabled = true;
|
||||||
|
private static int firstVisiblePosition = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -38,8 +40,21 @@ public class AppListFragment extends Fragment {
|
||||||
applications = new ArrayList<>();
|
applications = new ArrayList<>();
|
||||||
Context context = applistBinding.getRoot().getContext();
|
Context context = applistBinding.getRoot().getContext();
|
||||||
//configure list
|
//configure list
|
||||||
applistBinding.appList.setLayoutManager(new LinearLayoutManager(context));
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
|
||||||
|
applistBinding.appList.setLayoutManager(linearLayoutManager);
|
||||||
applistBinding.appList.setVerticalScrollBarEnabled(scrollbarEnabled);
|
applistBinding.appList.setVerticalScrollBarEnabled(scrollbarEnabled);
|
||||||
|
applistBinding.appList.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||||
|
super.onScrollStateChanged(recyclerView, newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
firstVisiblePosition = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
|
||||||
|
}
|
||||||
|
});
|
||||||
adapter = new ApplicationListAdapter(onAppClickListener);
|
adapter = new ApplicationListAdapter(onAppClickListener);
|
||||||
adapter.displayAppList(applications);
|
adapter.displayAppList(applications);
|
||||||
adapter.filter(filterType, filterObject);
|
adapter.filter(filterType, filterObject);
|
||||||
|
@ -54,6 +69,8 @@ public class AppListFragment extends Fragment {
|
||||||
public void setApplications(List<ApplicationViewModel> applicationList) {
|
public void setApplications(List<ApplicationViewModel> applicationList) {
|
||||||
applications = applicationList;
|
applications = applicationList;
|
||||||
if (adapter != null)
|
if (adapter != null)
|
||||||
|
|
||||||
|
|
||||||
adapter.displayAppList(applications);
|
adapter.displayAppList(applications);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +110,8 @@ public class AppListFragment extends Fragment {
|
||||||
TRACKER
|
TRACKER
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollTo(int position) {
|
public void scrollTo() {
|
||||||
applistBinding.appList.scrollToPosition(position);
|
applistBinding.appList.scrollToPosition(firstVisiblePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Order {
|
public enum Order {
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
|
||||||
private int lastResource = 0;
|
private int lastResource = 0;
|
||||||
private int lastProgress = 0;
|
private int lastProgress = 0;
|
||||||
private int lastMaxProgress = 0;
|
private int lastMaxProgress = 0;
|
||||||
private int scrollTo = 0;
|
|
||||||
private String last_refresh;
|
private String last_refresh;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,15 +111,9 @@ public class HomeFragment extends Fragment implements ComputeAppListTask.Listene
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (scrollTo > 0) {
|
appListFragment.scrollTo();
|
||||||
appListFragment.scrollTo(scrollTo);
|
|
||||||
scrollTo = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollTo(int position) {
|
|
||||||
scrollTo = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateComplete() {
|
public void onUpdateComplete() {
|
||||||
|
|
Loading…
Reference in New Issue