Menu + transitions

This commit is contained in:
Thomas 2020-12-15 10:00:26 +01:00
parent 2a091043c6
commit 7e6e1fcff6
7 changed files with 126 additions and 23 deletions

View File

@ -33,13 +33,18 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter; import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationListAdapter;
@ -68,6 +73,17 @@ public class MainActivity extends AppCompatActivity {
private MainBinding binding; private MainBinding binding;
private ApplicationListAdapter.OnAppClickListener onAppClickListener; private ApplicationListAdapter.OnAppClickListener onAppClickListener;
private String previousQuery = ""; private String previousQuery = "";
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
int itemId = item.getItemId();
if (itemId == R.id.navigation_apps) {
binding.viewpager.setCurrentItem(0);
} else if (itemId == R.id.navigation_analytics) {
binding.viewpager.setCurrentItem(1);
}
return true;
};
private HomeFragment home;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -103,7 +119,7 @@ public class MainActivity extends AppCompatActivity {
for (Updatable updatable : fragments) { for (Updatable updatable : fragments) {
updatable.onUpdateComplete(); updatable.onUpdateComplete();
} }
Snackbar bar = Snackbar.make(mainBinding.fragmentContainer, error, Snackbar.LENGTH_LONG); Snackbar bar = Snackbar.make(mainBinding.viewpager, error, Snackbar.LENGTH_LONG);
bar.show(); bar.show();
}); });
} }
@ -114,8 +130,31 @@ public class MainActivity extends AppCompatActivity {
} }
}; };
Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(binding.toolbar);
setSupportActionBar(toolbar); binding.navView.inflateMenu(R.menu.bottom_nav_menu);
binding.navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
binding.viewpager.setOffscreenPageLimit(2);
binding.viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
MenuItem item = binding.navView.getMenu().getItem(position);
binding.navView.setSelectedItemId(item.getItemId());
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
TrackerListAdapter.OnTrackerClickListener onTrackerClickListener = id -> { TrackerListAdapter.OnTrackerClickListener onTrackerClickListener = id -> {
TrackerFragment tracker = TrackerFragment.newInstance(id); TrackerFragment tracker = TrackerFragment.newInstance(id);
@ -131,6 +170,7 @@ public class MainActivity extends AppCompatActivity {
onAppClickListener = (vm) -> { 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);
ReportFragment report = ReportFragment.newInstance(pm, vm, packageInfo, onTrackerClickListener); ReportFragment report = ReportFragment.newInstance(pm, vm, packageInfo, onTrackerClickListener);
@ -141,7 +181,7 @@ public class MainActivity extends AppCompatActivity {
.replace(R.id.fragment_container, report) .replace(R.id.fragment_container, report)
.addToBackStack(null) .addToBackStack(null)
.commit(); .commit();
binding.fragmentContainer.setVisibility(View.VISIBLE);
packageName = packageInfo.packageName; packageName = packageInfo.packageName;
searchView.clearFocus(); searchView.clearFocus();
@ -149,22 +189,18 @@ public class MainActivity extends AppCompatActivity {
(toolbarMenu.findItem(R.id.action_filter)).collapseActionView(); (toolbarMenu.findItem(R.id.action_filter)).collapseActionView();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null; assert imm != null;
imm.hideSoftInputFromWindow(mainBinding.fragmentContainer.getWindowToken(), 0); imm.hideSoftInputFromWindow(mainBinding.viewpager.getWindowToken(), 0);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
}; };
HomeFragment home = new HomeFragment(); home = new HomeFragment();
fragments.add(home); fragments.add(home);
home.setNetworkListener(networkListener); home.setNetworkListener(networkListener);
home.setOnAppClickListener(onAppClickListener); home.setOnAppClickListener(onAppClickListener);
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
binding.viewpager.setAdapter(mPagerAdapter);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fragment_container, home)
.commit();
home.startRefresh(); home.startRefresh();
} }
@ -224,7 +260,6 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) { if (item.getItemId() == R.id.action_settings) {
@ -233,13 +268,13 @@ public class MainActivity extends AppCompatActivity {
try { try {
startActivity(intent); startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
Snackbar bar = Snackbar.make(binding.fragmentContainer, R.string.no_settings, Snackbar.LENGTH_LONG); Snackbar bar = Snackbar.make(binding.viewpager, R.string.no_settings, Snackbar.LENGTH_LONG);
bar.show(); bar.show();
} }
return true; return true;
} else if (item.getItemId() == R.id.action_filter_options) { } else if (item.getItemId() == R.id.action_filter_options) {
View menuItemView = findViewById(R.id.action_filter_options); View menuItemView = findViewById(R.id.action_filter_options);
PopupMenu popup = new PopupMenu(binding.fragmentContainer.getContext(), menuItemView); PopupMenu popup = new PopupMenu(binding.viewpager.getContext(), menuItemView);
popup.getMenuInflater() popup.getMenuInflater()
.inflate(R.menu.popup_menu_filter, popup.getMenu()); .inflate(R.menu.popup_menu_filter, popup.getMenu());
MenuItem filterByNameMI = popup.getMenu().findItem(R.id.filter_by_name); MenuItem filterByNameMI = popup.getMenu().findItem(R.id.filter_by_name);
@ -286,4 +321,27 @@ public class MainActivity extends AppCompatActivity {
return false; return false;
} }
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
@NonNull
@Override
public Fragment getItem(final int position) {
switch (position) {
case 1:
return new HomeFragment();
default:
return home;
}
}
@Override
public int getCount() {
return 2;
}
}
} }

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM9,17L7,17v-5h2v5zM13,17h-2v-3h2v3zM13,12h-2v-2h2v2zM17,17h-2L15,7h2v10z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z" />
</vector>

View File

@ -35,18 +35,26 @@
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" /> app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="10dp"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout <FrameLayout
android:id="@+id/fragment_container" android:id="@+id/fragment_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="?attr/actionBarSize" android:layout_marginBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" />
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view" android:id="@+id/nav_view"

View File

@ -11,6 +11,7 @@
type="org.eu.exodus_privacy.exodusprivacy.ReportViewModel" /> type="org.eu.exodus_privacy.exodusprivacy.ReportViewModel" />
</data> </data>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:background="?android:attr/windowBackground"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_apps"
android:icon="@drawable/ic_baseline_apps_24"
android:title="@string/title_apps" />
<item
android:id="@+id/navigation_analytics"
android:icon="@drawable/ic_baseline_analytics_24"
android:title="@string/title_trackers" />
</menu>

View File

@ -62,6 +62,8 @@
<string name="submit">Submit</string> <string name="submit">Submit</string>
<string name="app_not_analyzed">Would you like to analyze the app?\n\nThe app id will be automatically copied in your clipboard, you will only have to past it in website form.</string> <string name="app_not_analyzed">Would you like to analyze the app?\n\nThe app id will be automatically copied in your clipboard, you will only have to past it in website form.</string>
<string name="app_not_analyzed_title">This app has not been analyzed!</string> <string name="app_not_analyzed_title">This app has not been analyzed!</string>
<string name="title_apps">My apps</string>
<string name="title_trackers">Trackers</string>
</resources> </resources>