[app] Navigation fixes (#707)

* [app] Update fragment animation

* [app] Use safe args

* [app] Fix tablet ui
This commit is contained in:
tehcneko 2021-05-31 17:19:54 +08:00 committed by GitHub
parent 24948657d5
commit 0a8edb92ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 314 additions and 76 deletions

View File

@ -24,6 +24,7 @@ import java.nio.file.Paths
plugins {
id("org.gradle.idea")
id("com.android.application")
id("androidx.navigation.safeargs")
kotlin("android")
}

View File

@ -53,18 +53,20 @@ public class BaseActivity extends MaterialActivity {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// make sure the versions are consistent
String coreVersionStr = ConfigManager.getXposedVersionName();
if (coreVersionStr != null) {
if (!BuildConfig.VERSION_NAME.equals(coreVersionStr)) {
new AlertDialog.Builder(this)
.setMessage(R.string.outdated_manager)
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
NavUtil.startURL(this, getString(R.string.about_source));
finish();
})
.setCancelable(false)
.show();
if (!BuildConfig.DEBUG) {
// make sure the versions are consistent
String coreVersionStr = ConfigManager.getXposedVersionName();
if (coreVersionStr != null) {
if (!BuildConfig.VERSION_NAME.equals(coreVersionStr)) {
new AlertDialog.Builder(this)
.setMessage(R.string.outdated_manager)
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
NavUtil.startURL(this, getString(R.string.about_source));
finish();
})
.setCancelable(false)
.show();
}
}
}
}

View File

@ -92,8 +92,9 @@ public class AppListFragment extends BaseFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String modulePackageName = getArguments().getString("modulePackageName");
int moduleUserId = getArguments().getInt("moduleUserId", -1);
AppListFragmentArgs args = AppListFragmentArgs.fromBundle(getArguments());
String modulePackageName = args.getModulePackageName();
int moduleUserId = args.getModuleUserId();
module = ModuleUtil.getInstance().getModule(modulePackageName, moduleUserId);
if (module == null) {

View File

@ -24,7 +24,6 @@ import android.view.View;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
import androidx.navigation.Navigation;
import org.lsposed.manager.R;
@ -65,13 +64,4 @@ public class BaseFragment extends Fragment {
onPrepareOptionsMenu(toolbar.getMenu());
}
}
public NavOptions getNavOptions() {
return new NavOptions.Builder()
.setEnterAnim(R.anim.nav_default_enter_anim)
.setExitAnim(R.anim.nav_default_exit_anim)
.setPopEnterAnim(R.anim.nav_default_pop_enter_anim)
.setPopExitAnim(R.anim.nav_default_pop_exit_anim)
.build();
}
}

View File

@ -77,10 +77,10 @@ public class HomeFragment extends BaseFragment {
NavUtil.startURL(activity, getString(R.string.about_source));
}
});
binding.modules.setOnClickListener(new StartFragmentListener(R.id.action_main_fragment_to_modules_fragment, true));
binding.download.setOnClickListener(new StartFragmentListener(R.id.action_main_fragment_to_repo_fragment, false));
binding.logs.setOnClickListener(new StartFragmentListener(R.id.action_main_fragment_to_logs_fragment, true));
binding.settings.setOnClickListener(new StartFragmentListener(R.id.action_main_fragment_to_settings_fragment, false));
binding.modules.setOnClickListener(new StartFragmentListener(R.id.action_modules_fragment, true));
binding.download.setOnClickListener(new StartFragmentListener(R.id.action_repo_fragment, false));
binding.logs.setOnClickListener(new StartFragmentListener(R.id.action_logs_fragment, true));
binding.settings.setOnClickListener(new StartFragmentListener(R.id.action_settings_fragment, false));
binding.about.setOnClickListener(v -> {
DialogAboutBinding binding = DialogAboutBinding.inflate(LayoutInflater.from(requireActivity()), null, false);
binding.sourceCode.setMovementMethod(LinkMovementMethod.getInstance());
@ -152,7 +152,7 @@ public class HomeFragment extends BaseFragment {
if (requireInstalled && ConfigManager.getXposedVersionName() == null) {
Snackbar.make(snackbar, R.string.lsposed_not_active, Snackbar.LENGTH_LONG).show();
} else {
getNavController().navigate(fragment, null, getNavOptions());
getNavController().navigate(fragment);
}
}
}

View File

@ -314,10 +314,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
.show();
return true;
} else if (itemId == R.id.menu_repo) {
Bundle bundle = new Bundle();
bundle.putString("modulePackageName", selectedModule.packageName);
bundle.putString("moduleName", selectedModule.getAppName());
getNavController().navigate(R.id.action_modules_fragment_to_repo_item_fragment, bundle, getNavOptions());
getNavController().navigate(ModulesFragmentDirections.actionModulesFragmentToRepoItemFragment(selectedModule.packageName, selectedModule.getAppName()));
return true;
}
return super.onContextItemSelected(item);
@ -456,10 +453,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
if (!isPick) {
holder.root.setAlpha(moduleUtil.isModuleEnabled(item.packageName) ? 1.0f : .5f);
holder.itemView.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putString("modulePackageName", item.packageName);
bundle.putInt("moduleUserId", item.userId);
getNavController().navigate(R.id.action_modules_fragment_to_app_list_fragment, bundle, getNavOptions());
getNavController().navigate(ModulesFragmentDirections.actionModulesFragmentToAppListFragment(item.packageName, item.userId));
});
holder.itemView.setOnLongClickListener(v -> {
selectedModule = item;

View File

@ -203,10 +203,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
}
holder.appDescription.setText(sb);
holder.itemView.setOnClickListener(v -> {
Bundle bundle = new Bundle();
bundle.putString("modulePackageName", module.getName());
bundle.putString("moduleName", module.getDescription());
getNavController().navigate(R.id.action_repo_fragment_to_repo_item_fragment, bundle, getNavOptions());
getNavController().navigate(RepoFragmentDirections.actionRepoFragmentToRepoItemFragment(module.getName(), module.getDescription()));
});
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="0"
android:toAlpha="1" />
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="0.9"
android:fromYScale="0.9"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1"
android:toYScale="1" />
</set>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="0"
android:toAlpha="1" />
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="1.1"
android:fromYScale="1.1"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1"
android:toYScale="1" />
</set>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="1"
android:toAlpha="0" />
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1.1"
android:toYScale="1.1" />
</set>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="1"
android:toAlpha="0" />
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="0.9"
android:toYScale="0.9" />
</set>

View File

@ -30,30 +30,24 @@
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_weight="1">
<include layout="@layout/fragment_home" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/item_width" />
<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/tablet_nav_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/container_margin"
app:defaultNavHost="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/snackbar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:navGraph="@navigation/sub_nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
@ -25,19 +24,35 @@
<fragment
android:id="@+id/main_fragment"
android:name="org.lsposed.manager.ui.fragment.HomeFragment"
android:label="MainFragment" >
android:label="MainFragment">
<action
android:id="@+id/action_main_fragment_to_settings_fragment"
app:destination="@id/settings_fragment" />
app:destination="@id/settings_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_main_fragment_to_logs_fragment"
app:destination="@id/logs_fragment" />
app:destination="@id/logs_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_main_fragment_to_repo_fragment"
app:destination="@id/repo_fragment" />
app:destination="@id/repo_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_main_fragment_to_modules_fragment"
app:destination="@id/modules_fragment" />
app:destination="@id/modules_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</fragment>
<fragment
android:id="@+id/logs_fragment"
@ -46,13 +61,21 @@
<fragment
android:id="@+id/modules_fragment"
android:name="org.lsposed.manager.ui.fragment.ModulesFragment"
android:label="modules" >
android:label="modules">
<action
android:id="@+id/action_modules_fragment_to_app_list_fragment"
app:destination="@id/app_list_fragment" />
app:destination="@id/app_list_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_modules_fragment_to_repo_item_fragment"
app:destination="@id/repo_item_fragment" />
app:destination="@id/repo_item_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</fragment>
<fragment
android:id="@+id/settings_fragment"
@ -61,17 +84,65 @@
<fragment
android:id="@+id/app_list_fragment"
android:name="org.lsposed.manager.ui.fragment.AppListFragment"
android:label="app_list" />
android:label="app_list">
<argument
android:name="modulePackageName"
app:argType="string" />
<argument
android:name="moduleUserId"
app:argType="integer" />
</fragment>
<fragment
android:id="@+id/repo_fragment"
android:name="org.lsposed.manager.ui.fragment.RepoFragment"
android:label="repo" >
android:label="repo">
<action
android:id="@+id/action_repo_fragment_to_repo_item_fragment"
app:destination="@id/repo_item_fragment" />
app:destination="@id/repo_item_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</fragment>
<fragment
android:id="@+id/repo_item_fragment"
android:name="org.lsposed.manager.ui.fragment.RepoItemFragment"
android:label="repo_item" />
android:label="repo_item" >
<argument
android:name="modulePackageName"
app:argType="string" />
<argument
android:name="moduleName"
app:argType="string" />
</fragment>
<action
android:id="@+id/action_settings_fragment"
app:destination="@id/settings_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_logs_fragment"
app:destination="@id/logs_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_repo_fragment"
app:destination="@id/repo_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_modules_fragment"
app:destination="@id/modules_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</navigation>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
@ -29,13 +28,21 @@
<fragment
android:id="@+id/modules_fragment"
android:name="org.lsposed.manager.ui.fragment.ModulesFragment"
android:label="modules" >
android:label="modules">
<action
android:id="@+id/action_modules_fragment_to_app_list_fragment"
app:destination="@id/app_list_fragment" />
app:destination="@id/app_list_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_modules_fragment_to_repo_item_fragment"
app:destination="@id/repo_item_fragment" />
app:destination="@id/repo_item_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</fragment>
<fragment
android:id="@+id/settings_fragment"
@ -44,17 +51,65 @@
<fragment
android:id="@+id/app_list_fragment"
android:name="org.lsposed.manager.ui.fragment.AppListFragment"
android:label="app_list" />
android:label="app_list">
<argument
android:name="modulePackageName"
app:argType="string" />
<argument
android:name="moduleUserId"
app:argType="integer" />
</fragment>
<fragment
android:id="@+id/repo_fragment"
android:name="org.lsposed.manager.ui.fragment.RepoFragment"
android:label="repo" >
android:label="repo">
<action
android:id="@+id/action_repo_fragment_to_repo_item_fragment"
app:destination="@id/repo_item_fragment" />
app:destination="@id/repo_item_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</fragment>
<fragment
android:id="@+id/repo_item_fragment"
android:name="org.lsposed.manager.ui.fragment.RepoItemFragment"
android:label="repo_item" />
android:label="repo_item" >
<argument
android:name="modulePackageName"
app:argType="string" />
<argument
android:name="moduleName"
app:argType="string" />
</fragment>
<action
android:id="@+id/action_settings_fragment"
app:destination="@id/settings_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_logs_fragment"
app:destination="@id/logs_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_repo_fragment"
app:destination="@id/repo_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
<action
android:id="@+id/action_modules_fragment"
app:destination="@id/modules_fragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop" />
</navigation>

View File

@ -27,6 +27,7 @@ buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.0.0-beta03")
classpath("org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5")
classpath(kotlin("gradle-plugin", version = "1.4.32"))
}
}