diff --git a/android/app/build.gradle b/android/app/build.gradle index dc6f4117b..c2f9bb392 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -41,9 +41,10 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.preference:preference:1.1.0-alpha05' implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation "androidx.viewpager2:viewpager2:1.0.0" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f270ef751..29fc9bf6e 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -26,6 +26,7 @@ diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/SettingsActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/SettingsActivity.java index e2ad55966..8e031babe 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/SettingsActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/SettingsActivity.java @@ -1,12 +1,22 @@ package com.github.stenzek.duckstation; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; import androidx.preference.PreferenceFragmentCompat; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; public class SettingsActivity extends AppCompatActivity { @@ -16,7 +26,7 @@ public class SettingsActivity extends AppCompatActivity { setContentView(R.layout.settings_activity); getSupportFragmentManager() .beginTransaction() - .replace(R.id.settings, new SettingsFragment()) + .replace(R.id.settings, new SettingsCollectionFragment()) .commit(); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -35,9 +45,72 @@ public class SettingsActivity extends AppCompatActivity { } public static class SettingsFragment extends PreferenceFragmentCompat { + private int resourceId; + public SettingsFragment(int resourceId) { + this.resourceId = resourceId; + } + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setPreferencesFromResource(R.xml.root_preferences, rootKey); + setPreferencesFromResource(resourceId, rootKey); + } + } + + public static class SettingsCollectionFragment extends Fragment { + private SettingsCollectionAdapter adapter; + private ViewPager2 viewPager; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_settings_collection, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + adapter = new SettingsCollectionAdapter(this); + viewPager = view.findViewById(R.id.view_pager); + viewPager.setAdapter(adapter); + + TabLayout tabLayout = view.findViewById(R.id.tab_layout); + new TabLayoutMediator(tabLayout, viewPager, + (tab, position) -> tab.setText(getResources().getStringArray(R.array.settings_tabs)[position]) + ).attach(); + } + } + + public static class SettingsCollectionAdapter extends FragmentStateAdapter { + public SettingsCollectionAdapter(@NonNull Fragment fragment) { + super(fragment); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + switch (position) { + case 0: // General + return new SettingsFragment(R.xml.general_preferences); + + case 1: // Console + return new SettingsFragment(R.xml.display_preferences); + + case 2: // Enhancements + return new SettingsFragment(R.xml.enhancements_preferences); + + case 3: // Controllers + return new SettingsFragment(R.xml.controllers_preferences); + + case 4: // Advanced + return new SettingsFragment(R.xml.advanced_preferences); + + default: + return new Fragment(); + } + } + + @Override + public int getItemCount() { + return 5; } } } \ No newline at end of file diff --git a/android/app/src/main/res/layout/fragment_settings_collection.xml b/android/app/src/main/res/layout/fragment_settings_collection.xml new file mode 100644 index 000000000..49bc94180 --- /dev/null +++ b/android/app/src/main/res/layout/fragment_settings_collection.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/arrays.xml b/android/app/src/main/res/values/arrays.xml index 8477fdd3b..c424b1971 100644 --- a/android/app/src/main/res/values/arrays.xml +++ b/android/app/src/main/res/values/arrays.xml @@ -224,4 +224,11 @@ Debug Trace + + General + Display + Enhancements + Controllers + Advanced + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index b849520af..f5f8f0670 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -11,7 +11,7 @@ GPU - Region + Console Region Auto BIOS Path Enable TTY Output diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index b57a6c6e5..6d6374064 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -29,4 +29,9 @@ @color/black_overlay + + diff --git a/android/app/src/main/res/xml/advanced_preferences.xml b/android/app/src/main/res/xml/advanced_preferences.xml new file mode 100644 index 000000000..75e718d14 --- /dev/null +++ b/android/app/src/main/res/xml/advanced_preferences.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + diff --git a/android/app/src/main/res/xml/controllers_preferences.xml b/android/app/src/main/res/xml/controllers_preferences.xml new file mode 100644 index 000000000..51bb7b2ad --- /dev/null +++ b/android/app/src/main/res/xml/controllers_preferences.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + diff --git a/android/app/src/main/res/xml/display_preferences.xml b/android/app/src/main/res/xml/display_preferences.xml new file mode 100644 index 000000000..c2ed35d50 --- /dev/null +++ b/android/app/src/main/res/xml/display_preferences.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + diff --git a/android/app/src/main/res/xml/enhancements_preferences.xml b/android/app/src/main/res/xml/enhancements_preferences.xml new file mode 100644 index 000000000..434de8805 --- /dev/null +++ b/android/app/src/main/res/xml/enhancements_preferences.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/xml/general_preferences.xml b/android/app/src/main/res/xml/general_preferences.xml new file mode 100644 index 000000000..58e4eba24 --- /dev/null +++ b/android/app/src/main/res/xml/general_preferences.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/xml/root_preferences.xml b/android/app/src/main/res/xml/root_preferences.xml deleted file mode 100644 index 699e488d2..000000000 --- a/android/app/src/main/res/xml/root_preferences.xml +++ /dev/null @@ -1,386 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -