From c8ba1a73264725b819910f72006b7dcd97fdd6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Carvalho?= Date: Tue, 20 Mar 2018 11:46:53 +0000 Subject: [PATCH] * Handle MainActivity rotation correctly * Code cleanup * Others --- .idea/kotlinc.xml | 7 ++ app/src/main/AndroidManifest.xml | 4 +- app/src/main/java/io/mgba/Constants.java | 4 + .../mgba/Presenter/CategoriesPresenter.java | 49 -------- .../Interfaces/ICategoriesPresenter.java | 11 -- .../Presenter/Interfaces/IMainPresenter.java | 6 - .../Interfaces/ISettingsPanelPresenter.java | 24 ++++ .../Interfaces/ISettingsPresenter.java | 23 +--- .../java/io/mgba/Presenter/MainPresenter.java | 11 +- .../Presenter/SettingsPanelPresenter.java | 109 ++++++++++++++++++ .../io/mgba/Presenter/SettingsPresenter.java | 105 ++++------------- .../io/mgba/UI/Activities/MainActivity.java | 49 +++++++- .../mgba/UI/Activities/SettingsActivity.java | 77 ++++--------- .../SettingsCategoriesActivity.java | 55 --------- .../UI/Activities/SettingsPanelActivity.java | 88 ++++++++++++++ .../io/mgba/UI/Views/GameInformationView.java | 33 ++++-- .../Interfaces/IGameInformationView.java | 6 +- app/src/main/java/io/mgba/todo | 17 +-- .../layout/activity_settings_categories.xml | 2 +- 19 files changed, 364 insertions(+), 316 deletions(-) create mode 100644 .idea/kotlinc.xml delete mode 100644 app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java delete mode 100644 app/src/main/java/io/mgba/Presenter/Interfaces/ICategoriesPresenter.java create mode 100644 app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPanelPresenter.java create mode 100644 app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java delete mode 100644 app/src/main/java/io/mgba/UI/Activities/SettingsCategoriesActivity.java create mode 100644 app/src/main/java/io/mgba/UI/Activities/SettingsPanelActivity.java diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..5806fb3 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 62a7d48..660e31e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,7 +37,7 @@ @@ -53,7 +53,7 @@ - diff --git a/app/src/main/java/io/mgba/Constants.java b/app/src/main/java/io/mgba/Constants.java index b8d8080..faaceb8 100644 --- a/app/src/main/java/io/mgba/Constants.java +++ b/app/src/main/java/io/mgba/Constants.java @@ -6,5 +6,9 @@ public class Constants { public final static String GAMES_INTENT = "games"; public final static String RECEIVE_GAME_LIST = "io.mgba.gamesreceiver"; public static final String ARG_PLATFORM = "platform"; + public static final String ARG_SHEET_CONTENT = "sheet_content"; + public static final String ARG_SHEET_IS_SHOWING = "sheet_is_showing"; + public static final String MAIN_TOOLBAR_STATE = "main_toolbar_state"; + public static final String MAIN_VIEWPAGE_STATE = "main_viewpage_state"; public static final String ARG_SETTINGS_ID = "settings_id_args"; } diff --git a/app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java b/app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java deleted file mode 100644 index 720c148..0000000 --- a/app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.mgba.Presenter; - -import android.content.Intent; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; - -import java.util.LinkedList; -import java.util.List; - -import io.mgba.Adapters.SettingsCategoriesAdapter; -import io.mgba.Constants; -import io.mgba.Presenter.Interfaces.ICategoriesPresenter; -import io.mgba.Data.Settings.SettingsCategory; -import io.mgba.R; -import io.mgba.UI.Activities.SettingsActivity; -import io.reactivex.functions.Consumer; - -public class CategoriesPresenter implements ICategoriesPresenter { - private final List settings; - private final AppCompatActivity context; - - public CategoriesPresenter(AppCompatActivity context) { - this.context = context; - - this.settings = new LinkedList<>(); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_audio), R.drawable.ic_audiotrack_black_24dp)); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_video), R.drawable.ic_personal_video_black_24dp)); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_emulation), R.drawable.ic_gamepad_black_24dp)); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_bios), R.drawable.ic_memory_black_24dp)); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_paths), R.drawable.ic_folder_black_24dp)); - settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_customization), R.drawable.ic_palette_black_24dp)); - } - - - @Override - public List getSettings() { - return settings; - } - - @Override - public Consumer getOnClick() { - return s -> { - Intent it = new Intent(context.getApplicationContext(), SettingsActivity.class); - it.putExtra(Constants.ARG_SETTINGS_ID, s.getTitle()); - context.startActivity(it); - }; - } -} diff --git a/app/src/main/java/io/mgba/Presenter/Interfaces/ICategoriesPresenter.java b/app/src/main/java/io/mgba/Presenter/Interfaces/ICategoriesPresenter.java deleted file mode 100644 index 0ef383a..0000000 --- a/app/src/main/java/io/mgba/Presenter/Interfaces/ICategoriesPresenter.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.mgba.Presenter.Interfaces; - -import java.util.List; -import io.mgba.Data.Settings.SettingsCategory; -import io.reactivex.functions.Consumer; - -public interface ICategoriesPresenter { - - List getSettings(); - Consumer getOnClick(); -} diff --git a/app/src/main/java/io/mgba/Presenter/Interfaces/IMainPresenter.java b/app/src/main/java/io/mgba/Presenter/Interfaces/IMainPresenter.java index c3876bd..2f2c780 100644 --- a/app/src/main/java/io/mgba/Presenter/Interfaces/IMainPresenter.java +++ b/app/src/main/java/io/mgba/Presenter/Interfaces/IMainPresenter.java @@ -15,16 +15,10 @@ public interface IMainPresenter { void onActivityResult(int requestCode, int resultCode, Intent intent); - void showBottomSheet(Game game); - void onDestroy(); - ILibrary getILibrary(); - void onMenuItemSelected(MenuItem item); - void onSearchTextChanged(String oldQuery, String newQuery, FloatingSearchView mToolbar); - void onSaveInstanceState(Bundle outState); } diff --git a/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPanelPresenter.java b/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPanelPresenter.java new file mode 100644 index 0000000..e66d042 --- /dev/null +++ b/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPanelPresenter.java @@ -0,0 +1,24 @@ +package io.mgba.Presenter.Interfaces; + +import android.content.Intent; +import android.os.Bundle; + +import permissions.dispatcher.PermissionRequest; + +public interface ISettingsPanelPresenter { + void init(Bundle savedInstanceState); + + void onSaveInstance(Bundle outState); + + void setupFragment(); + + void onActivityResult(int requestCode, int resultCode, Intent intent); + + void showFilePicker(); + + void showRationaleForStorage(PermissionRequest request); + + String requestPreferencesValue(String key, String defaultValue); + + String getTitle(); +} diff --git a/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPresenter.java b/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPresenter.java index b55765d..2cbf4f5 100644 --- a/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPresenter.java +++ b/app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPresenter.java @@ -1,24 +1,11 @@ package io.mgba.Presenter.Interfaces; -import android.content.Intent; -import android.os.Bundle; - -import permissions.dispatcher.PermissionRequest; +import java.util.List; +import io.mgba.Data.Settings.SettingsCategory; +import io.reactivex.functions.Consumer; public interface ISettingsPresenter { - void init(Bundle savedInstanceState); - - void onSaveInstance(Bundle outState); - - void setupFragment(); - - void onActivityResult(int requestCode, int resultCode, Intent intent); - - void showFilePicker(); - - void showRationaleForStorage(PermissionRequest request); - - String requestPreferencesValue(String key, String defaultValue); - String getTitle(); + List getSettings(); + Consumer getOnClick(); } diff --git a/app/src/main/java/io/mgba/Presenter/MainPresenter.java b/app/src/main/java/io/mgba/Presenter/MainPresenter.java index 51a4e0c..d6674a2 100644 --- a/app/src/main/java/io/mgba/Presenter/MainPresenter.java +++ b/app/src/main/java/io/mgba/Presenter/MainPresenter.java @@ -2,7 +2,6 @@ import android.app.Activity; import android.content.Intent; -import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; @@ -16,7 +15,7 @@ import io.mgba.Model.Interfaces.ILibrary; import io.mgba.R; import io.mgba.UI.Activities.Interfaces.IMainView; -import io.mgba.UI.Activities.SettingsCategoriesActivity; +import io.mgba.UI.Activities.SettingsActivity; import io.mgba.mgba; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -60,7 +59,7 @@ public void onMenuItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_settings) { - Intent settings = new Intent(context, SettingsCategoriesActivity.class); + Intent settings = new Intent(context, SettingsActivity.class); context.startActivityForResult(settings, SETTINGS_CODE); } } @@ -80,11 +79,6 @@ public ILibrary getILibrary() { return library; } - @Override - public void onSaveInstanceState(Bundle outState) { - - } - @Override public void onSearchTextChanged(String oldQuery, String newQuery, FloatingSearchView mToolbar) { if (!oldQuery.equals("") && newQuery.equals("")) { @@ -98,6 +92,7 @@ public void onSearchTextChanged(String oldQuery, String newQuery, FloatingSearch .subscribe(games -> { mToolbar.swapSuggestions(games); mToolbar.hideProgress(); + onDestroy(); })); } } diff --git a/app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java b/app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java new file mode 100644 index 0000000..b42b94b --- /dev/null +++ b/app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java @@ -0,0 +1,109 @@ +package io.mgba.Presenter; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.preference.PreferenceFragmentCompat; + +import com.google.common.base.Function; +import com.nononsenseapps.filepicker.Controllers.FilePickerUtils; + +import java.util.HashMap; + +import io.mgba.Constants; +import io.mgba.Presenter.Interfaces.ISettingsPanelPresenter; +import io.mgba.Model.Interfaces.IPermissionManager; +import io.mgba.Model.System.PermissionManager; +import io.mgba.Model.System.PreferencesManager; +import io.mgba.R; +import io.mgba.UI.Fragments.Settings.AudioFragment; +import io.mgba.UI.Fragments.Settings.BiosFragment; +import io.mgba.UI.Fragments.Settings.EmulationFragment; +import io.mgba.UI.Fragments.Settings.StorageFragment; +import io.mgba.UI.Fragments.Settings.UIFragment; +import io.mgba.UI.Fragments.Settings.VideoFragment; +import io.mgba.mgba; +import permissions.dispatcher.PermissionRequest; + +public class SettingsPanelPresenter implements ISettingsPanelPresenter { + private static final String TAG = "Settings_Controller"; + private final AppCompatActivity context; + private final HashMap> router; + private final IPermissionManager permissionService; + + private String id; + + public SettingsPanelPresenter(AppCompatActivity context) { + this.context = context; + this.permissionService = new PermissionManager(context); + + this.router = new HashMap<>(); + router.put(context.getString(R.string.settings_audio), (s) -> new AudioFragment()); + router.put(context.getString(R.string.settings_video), (s) -> new VideoFragment()); + router.put(context.getString(R.string.settings_emulation), (s) -> new EmulationFragment()); + router.put(context.getString(R.string.settings_bios), (s) -> new BiosFragment()); + router.put(context.getString(R.string.settings_paths), (s) -> new StorageFragment()); + router.put(context.getString(R.string.settings_customization), (s) -> new UIFragment()); + } + + @Override + public void init(Bundle savedInstanceState) { + id = savedInstanceState == null + ? context.getIntent().getExtras().getString(Constants.ARG_SETTINGS_ID) + : savedInstanceState.getString(Constants.ARG_SETTINGS_ID); + } + + @Override + public void onSaveInstance(Bundle outState) { + outState.putString(Constants.ARG_SETTINGS_ID, id); + } + + @Override + public void setupFragment() { + FragmentManager fm = context.getSupportFragmentManager(); + + PreferenceFragmentCompat fragment = (PreferenceFragmentCompat) fm.findFragmentByTag(TAG + id); + + if (fragment == null) + fragment = router.get(id).apply(id); + + fm.beginTransaction().replace(R.id.settings_container, fragment, TAG + id).commit(); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + if (requestCode == PermissionManager.DIR_CODE && resultCode == Activity.RESULT_OK) { + String dir = FilePickerUtils.getSelectedDir(intent); + processDirectory(dir); + } + } + + @Override + public void showFilePicker() { + permissionService.showFilePicker(); + } + + @Override + public void showRationaleForStorage(PermissionRequest request) { + permissionService.showRationaleForStorage(request); + } + + @Override + public String requestPreferencesValue(String key, String defaultValue) { + return ((mgba)context.getApplication()).getPreference(key, defaultValue); + } + + @Override + public String getTitle() { + return id; + } + + private void processDirectory(String dir){ + ((mgba)context.getApplication()).savePreference(PreferencesManager.GAMES_DIRECTORY, dir); + FragmentManager fm = context.getSupportFragmentManager(); + StorageFragment fragment = (StorageFragment) fm.findFragmentByTag(TAG + id); + fragment.changeGamesFolderSummary(dir); + } +} diff --git a/app/src/main/java/io/mgba/Presenter/SettingsPresenter.java b/app/src/main/java/io/mgba/Presenter/SettingsPresenter.java index e755141..fe27a14 100644 --- a/app/src/main/java/io/mgba/Presenter/SettingsPresenter.java +++ b/app/src/main/java/io/mgba/Presenter/SettingsPresenter.java @@ -1,109 +1,46 @@ package io.mgba.Presenter; -import android.app.Activity; import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; -import android.support.v7.preference.PreferenceFragmentCompat; -import com.google.common.base.Function; -import com.nononsenseapps.filepicker.Controllers.FilePickerUtils; - -import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import io.mgba.Constants; import io.mgba.Presenter.Interfaces.ISettingsPresenter; -import io.mgba.Model.Interfaces.IPermissionManager; -import io.mgba.Model.System.PermissionManager; -import io.mgba.Model.System.PreferencesManager; +import io.mgba.Data.Settings.SettingsCategory; import io.mgba.R; -import io.mgba.UI.Fragments.Settings.AudioFragment; -import io.mgba.UI.Fragments.Settings.BiosFragment; -import io.mgba.UI.Fragments.Settings.EmulationFragment; -import io.mgba.UI.Fragments.Settings.StorageFragment; -import io.mgba.UI.Fragments.Settings.UIFragment; -import io.mgba.UI.Fragments.Settings.VideoFragment; -import io.mgba.mgba; -import permissions.dispatcher.PermissionRequest; +import io.mgba.UI.Activities.SettingsPanelActivity; +import io.reactivex.functions.Consumer; public class SettingsPresenter implements ISettingsPresenter { - private static final String TAG = "Settings_Controller"; + private final List settings; private final AppCompatActivity context; - private final HashMap> router; - private final IPermissionManager permissionService; - - private String id; public SettingsPresenter(AppCompatActivity context) { this.context = context; - this.permissionService = new PermissionManager(context); - - this.router = new HashMap<>(); - router.put(context.getString(R.string.settings_audio), (s) -> new AudioFragment()); - router.put(context.getString(R.string.settings_video), (s) -> new VideoFragment()); - router.put(context.getString(R.string.settings_emulation), (s) -> new EmulationFragment()); - router.put(context.getString(R.string.settings_bios), (s) -> new BiosFragment()); - router.put(context.getString(R.string.settings_paths), (s) -> new StorageFragment()); - router.put(context.getString(R.string.settings_customization), (s) -> new UIFragment()); - } - - @Override - public void init(Bundle savedInstanceState) { - id = savedInstanceState == null - ? context.getIntent().getExtras().getString(Constants.ARG_SETTINGS_ID) - : savedInstanceState.getString(Constants.ARG_SETTINGS_ID); - } - - @Override - public void onSaveInstance(Bundle outState) { - outState.putString(Constants.ARG_SETTINGS_ID, id); - } - - @Override - public void setupFragment() { - FragmentManager fm = context.getSupportFragmentManager(); - PreferenceFragmentCompat fragment = (PreferenceFragmentCompat) fm.findFragmentByTag(TAG + id); - - if (fragment == null) - fragment = router.get(id).apply(id); - - fm.beginTransaction().replace(R.id.settings_container, fragment, TAG + id).commit(); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent intent) { - if (requestCode == PermissionManager.DIR_CODE && resultCode == Activity.RESULT_OK) { - String dir = FilePickerUtils.getSelectedDir(intent); - processDirectory(dir); - } - } - - @Override - public void showFilePicker() { - permissionService.showFilePicker(); + this.settings = new LinkedList<>(); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_audio), R.drawable.ic_audiotrack_black_24dp)); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_video), R.drawable.ic_personal_video_black_24dp)); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_emulation), R.drawable.ic_gamepad_black_24dp)); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_bios), R.drawable.ic_memory_black_24dp)); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_paths), R.drawable.ic_folder_black_24dp)); + settings.add(new SettingsCategory(context.getResources().getString(R.string.settings_customization), R.drawable.ic_palette_black_24dp)); } - @Override - public void showRationaleForStorage(PermissionRequest request) { - permissionService.showRationaleForStorage(request); - } @Override - public String requestPreferencesValue(String key, String defaultValue) { - return ((mgba)context.getApplication()).getPreference(key, defaultValue); + public List getSettings() { + return settings; } @Override - public String getTitle() { - return id; - } - - private void processDirectory(String dir){ - ((mgba)context.getApplication()).savePreference(PreferencesManager.GAMES_DIRECTORY, dir); - FragmentManager fm = context.getSupportFragmentManager(); - StorageFragment fragment = (StorageFragment) fm.findFragmentByTag(TAG + id); - fragment.changeGamesFolderSummary(dir); + public Consumer getOnClick() { + return s -> { + Intent it = new Intent(context.getApplicationContext(), SettingsPanelActivity.class); + it.putExtra(Constants.ARG_SETTINGS_ID, s.getTitle()); + context.startActivity(it); + }; } } diff --git a/app/src/main/java/io/mgba/UI/Activities/MainActivity.java b/app/src/main/java/io/mgba/UI/Activities/MainActivity.java index 4cd7971..b214ce6 100644 --- a/app/src/main/java/io/mgba/UI/Activities/MainActivity.java +++ b/app/src/main/java/io/mgba/UI/Activities/MainActivity.java @@ -6,6 +6,7 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; +import android.view.View; import com.arlib.floatingsearchview.FloatingSearchView; import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion; @@ -14,6 +15,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import io.mgba.Adapters.TabViewPager; +import io.mgba.Constants; import io.mgba.Presenter.Interfaces.IMainPresenter; import io.mgba.Presenter.MainPresenter; import io.mgba.Data.Database.Game; @@ -23,6 +25,7 @@ import io.mgba.UI.Views.GameInformationView; import io.mgba.UI.Views.Interfaces.IGameInformationView; +import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static io.mgba.Presenter.MainPresenter.DEFAULT_PANEL; public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener, io.mgba.UI.Activities.Interfaces.ILibrary, FloatingSearchView.OnMenuItemClickListener, FloatingSearchView.OnQueryChangeListener, FloatingSearchView.OnSearchListener, IMainView{ @@ -45,6 +48,15 @@ protected void onCreate(Bundle savedInstanceState) { prepareToolbar(); prepareViewPager(); + + if(savedInstanceState != null){ + toolbar.onRestoreInstanceState(savedInstanceState.getParcelable(Constants.MAIN_TOOLBAR_STATE)); + viewPager.onRestoreInstanceState(savedInstanceState.getParcelable(Constants.MAIN_VIEWPAGE_STATE)); + + if(savedInstanceState.getBoolean(Constants.ARG_SHEET_IS_SHOWING, false)) + showGameInformation(savedInstanceState); + + } } private void prepareToolbar() { @@ -126,9 +138,44 @@ public void onActionMenuItemSelected(MenuItem item) { @Override public void showGameInformation(Game game) { + initializeSheetController(); + showSheetWithView(sheetController.prepareView(sheetDialog, game)); + } + + private void showGameInformation(Bundle bundle) { + initializeSheetController(); + showSheetWithView(sheetController.prepareView(sheetDialog, bundle)); + } + + private void showSheetWithView(View view) { + if(view != null){ + sheetDialog.showWithSheetView(view); + + if(getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) + sheetDialog.expandSheet(); + } + } + + private void initializeSheetController(){ if(sheetController == null) sheetController = new GameInformationView(getApplicationContext()); - sheetDialog.showWithSheetView(sheetController.getView(sheetDialog, game)); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putParcelable(Constants.MAIN_TOOLBAR_STATE, toolbar.onSaveInstanceState()); + outState.putParcelable(Constants.MAIN_VIEWPAGE_STATE, viewPager.onSaveInstanceState()); + + if(sheetController != null && sheetDialog.getState().equals(BottomSheetLayout.State.PEEKED) + || sheetDialog.getState().equals(BottomSheetLayout.State.EXPANDED)) { + + outState.putBoolean(Constants.ARG_SHEET_IS_SHOWING, true); + sheetController.onSaveInstanceState(outState); + } + + + } } diff --git a/app/src/main/java/io/mgba/UI/Activities/SettingsActivity.java b/app/src/main/java/io/mgba/UI/Activities/SettingsActivity.java index 31a1c39..1f1cb42 100644 --- a/app/src/main/java/io/mgba/UI/Activities/SettingsActivity.java +++ b/app/src/main/java/io/mgba/UI/Activities/SettingsActivity.java @@ -1,88 +1,55 @@ package io.mgba.UI.Activities; -import android.Manifest; -import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; -import io.mgba.Presenter.Interfaces.ISettingsPresenter; +import butterknife.BindView; +import butterknife.ButterKnife; +import io.mgba.Adapters.SettingsCategoriesAdapter; import io.mgba.Presenter.SettingsPresenter; +import io.mgba.Presenter.Interfaces.ISettingsPresenter; import io.mgba.R; -import io.mgba.UI.Activities.Interfaces.ISettings; -import permissions.dispatcher.NeedsPermission; -import permissions.dispatcher.OnShowRationale; -import permissions.dispatcher.PermissionRequest; -import permissions.dispatcher.RuntimePermissions; -@RuntimePermissions -public class SettingsActivity extends AppCompatActivity implements ISettings { +public class SettingsActivity extends AppCompatActivity { + + @BindView(R.id.recyclerview) + RecyclerView recyclerView; - private static final String TAG = "Storage_Fragment"; private ISettingsPresenter controller; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_settings); + setContentView(R.layout.activity_settings_categories); + ButterKnife.bind(this); controller = new SettingsPresenter(this); - controller.init(savedInstanceState); - setupFragment(); setupToolbar(); + setupRecyclerView(); } - @Override - protected void onSaveInstanceState(Bundle outState) { - controller.onSaveInstance(outState); - super.onSaveInstanceState(outState); + private void setupRecyclerView() { + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setAdapter(new SettingsCategoriesAdapter(controller.getSettings(), + getApplicationContext(), + controller.getOnClick(), + recyclerView)); } private void setupToolbar() { - if(getSupportActionBar() != null){ - getSupportActionBar().setTitle(controller.getTitle()); + if (getSupportActionBar() != null){ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } } - private void setupFragment() { - controller.setupFragment(); - } - - @Override - public String requestPreferencesValue(String key, String defaultValue) { - return controller.requestPreferencesValue(key, defaultValue); - } - - @NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) - void showFilePicker() { - controller.showFilePicker(); - } - - @OnShowRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) - void showRationaleForStorage(final PermissionRequest request) { - controller.showRationaleForStorage(request); - } - - protected void onActivityResult(int requestCode, int resultCode, Intent intent) { - controller.onActivityResult(requestCode, resultCode, intent); - } - - @Override - public void requestStoragePermission() { - SettingsActivityPermissionsDispatcher.showFilePickerWithPermissionCheck(this); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - SettingsActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults); - } - @Override public boolean onSupportNavigateUp() { onBackPressed(); return true; } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/mgba/UI/Activities/SettingsCategoriesActivity.java b/app/src/main/java/io/mgba/UI/Activities/SettingsCategoriesActivity.java deleted file mode 100644 index 4f1ffbd..0000000 --- a/app/src/main/java/io/mgba/UI/Activities/SettingsCategoriesActivity.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.mgba.UI.Activities; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; - -import butterknife.BindView; -import butterknife.ButterKnife; -import io.mgba.Adapters.SettingsCategoriesAdapter; -import io.mgba.Presenter.CategoriesPresenter; -import io.mgba.Presenter.Interfaces.ICategoriesPresenter; -import io.mgba.R; - -public class SettingsCategoriesActivity extends AppCompatActivity { - - @BindView(R.id.recyclerview) - RecyclerView recyclerView; - - private ICategoriesPresenter controller; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_settings_categories); - - ButterKnife.bind(this); - controller = new CategoriesPresenter(this); - - setupToolbar(); - setupRecyclerView(); - } - - private void setupRecyclerView() { - recyclerView.setHasFixedSize(true); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(new SettingsCategoriesAdapter(controller.getSettings(), - getApplicationContext(), - controller.getOnClick(), - recyclerView)); - } - - private void setupToolbar() { - if (getSupportActionBar() != null){ - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowHomeEnabled(true); - } - } - - @Override - public boolean onSupportNavigateUp() { - onBackPressed(); - return true; - } -} diff --git a/app/src/main/java/io/mgba/UI/Activities/SettingsPanelActivity.java b/app/src/main/java/io/mgba/UI/Activities/SettingsPanelActivity.java new file mode 100644 index 0000000..65f8fa6 --- /dev/null +++ b/app/src/main/java/io/mgba/UI/Activities/SettingsPanelActivity.java @@ -0,0 +1,88 @@ +package io.mgba.UI.Activities; + +import android.Manifest; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; + +import io.mgba.Presenter.Interfaces.ISettingsPanelPresenter; +import io.mgba.Presenter.SettingsPanelPresenter; +import io.mgba.R; +import io.mgba.UI.Activities.Interfaces.ISettings; +import permissions.dispatcher.NeedsPermission; +import permissions.dispatcher.OnShowRationale; +import permissions.dispatcher.PermissionRequest; +import permissions.dispatcher.RuntimePermissions; + +@RuntimePermissions +public class SettingsPanelActivity extends AppCompatActivity implements ISettings { + + private static final String TAG = "Storage_Fragment"; + private ISettingsPanelPresenter controller; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_settings); + + controller = new SettingsPanelPresenter(this); + + controller.init(savedInstanceState); + setupFragment(); + setupToolbar(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + controller.onSaveInstance(outState); + super.onSaveInstanceState(outState); + } + + private void setupToolbar() { + if(getSupportActionBar() != null){ + getSupportActionBar().setTitle(controller.getTitle()); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + } + + private void setupFragment() { + controller.setupFragment(); + } + + @Override + public String requestPreferencesValue(String key, String defaultValue) { + return controller.requestPreferencesValue(key, defaultValue); + } + + @NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + void showFilePicker() { + controller.showFilePicker(); + } + + @OnShowRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) + void showRationaleForStorage(final PermissionRequest request) { + controller.showRationaleForStorage(request); + } + + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + controller.onActivityResult(requestCode, resultCode, intent); + } + + @Override + public void requestStoragePermission() { + SettingsPanelActivityPermissionsDispatcher.showFilePickerWithPermissionCheck(this); + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + SettingsPanelActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults); + } + + @Override + public boolean onSupportNavigateUp() { + onBackPressed(); + return true; + } +} \ No newline at end of file diff --git a/app/src/main/java/io/mgba/UI/Views/GameInformationView.java b/app/src/main/java/io/mgba/UI/Views/GameInformationView.java index 7f8446d..71488cf 100644 --- a/app/src/main/java/io/mgba/UI/Views/GameInformationView.java +++ b/app/src/main/java/io/mgba/UI/Views/GameInformationView.java @@ -1,6 +1,7 @@ package io.mgba.UI.Views; import android.content.Context; +import android.os.Bundle; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.RecyclerView; @@ -14,6 +15,7 @@ import butterknife.BindView; import butterknife.ButterKnife; +import io.mgba.Constants; import io.mgba.Data.Database.Game; import io.mgba.R; import io.mgba.UI.Views.Interfaces.IGameInformationView; @@ -47,26 +49,41 @@ public class GameInformationView implements IGameInformationView { RelativeLayout noSavestatesContainer; private View view; + private Game currentShowing; + public GameInformationView(Context ctx) { this.context = ctx; } @Override - public View getView(BottomSheetLayout sheet, Game game) { + public View prepareView(BottomSheetLayout container, Game game) { + currentShowing = game; - view = LayoutInflater.from(context).inflate(R.layout.library_sheet_view, sheet, false); + view = LayoutInflater.from(context).inflate(R.layout.library_sheet_view, container, false); ButterKnife.bind(this, view); - prepareView(game); + prepareView(); return view; } - private void prepareView(Game game) { - gameTitle.setText(game.getName()); - gameDescription.setText(game.getDescription()); + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putParcelable(Constants.ARG_SHEET_CONTENT, currentShowing); + } + + @Override + public View prepareView(BottomSheetLayout container, Bundle inState) { + Game game = (Game) inState.getParcelable(Constants.ARG_SHEET_CONTENT); + + return prepareView(container, game); + } + + private void prepareView() { + gameTitle.setText(currentShowing.getName()); + gameDescription.setText(currentShowing.getDescription()); - if(game.getCoverURL() != null) { - GlideUtils.init(view, game.getCoverURL()) + if(currentShowing.getCoverURL() != null) { + GlideUtils.init(view, currentShowing.getCoverURL()) .setPlaceholders(R.drawable.placeholder, R.drawable.error) .colorView(Colors.VIBRANT, Colors.DARK_MUTED, fab, savestateTitle) .colorView(Colors.LIGHT_MUTED, Colors.LIGHT_VIBRANT, bottomSheetHeader, noSavestateMessage, noContentImage) diff --git a/app/src/main/java/io/mgba/UI/Views/Interfaces/IGameInformationView.java b/app/src/main/java/io/mgba/UI/Views/Interfaces/IGameInformationView.java index e7ee62a..797aecf 100644 --- a/app/src/main/java/io/mgba/UI/Views/Interfaces/IGameInformationView.java +++ b/app/src/main/java/io/mgba/UI/Views/Interfaces/IGameInformationView.java @@ -1,5 +1,6 @@ package io.mgba.UI.Views.Interfaces; +import android.os.Bundle; import android.view.View; import com.flipboard.bottomsheet.BottomSheetLayout; @@ -7,7 +8,8 @@ import io.mgba.Data.Database.Game; public interface IGameInformationView { - View getView(BottomSheetLayout sheet, Game game); - + View prepareView(BottomSheetLayout container, Game game); + void onSaveInstanceState(Bundle outState); + View prepareView(BottomSheetLayout container, Bundle inState); } diff --git a/app/src/main/java/io/mgba/todo b/app/src/main/java/io/mgba/todo index 1bb6cf5..b28daef 100644 --- a/app/src/main/java/io/mgba/todo +++ b/app/src/main/java/io/mgba/todo @@ -1,20 +1,5 @@ -* [MEDIUM] Start handling device state (rotations, change language, etc...) - (Eg: for now if we rotate the device on the library activity we will fetch the data again for the db, this could be optimized) - - Activity | State - Intro Done - Main toImplement(Partial) - Settings toImplement - Emulation toImplement - * [MEDIUM] Dispose objects that we dont need. * [LOW] Add option to customize game controllers. -* [LOW] Move splashActivity logic to a controller. * [LOW] Start working on the landscape layout. * [LOW] Reload games when switching directories. -* [MEDIUM] Add so file so we can start using the emulator. -* [LOW] Fix IntroController. It receives a Activity object on CTOR. - In case of the need to recreate the Activity, there could happen a NullPointException when we came from the worker thread - For now the only change of it happen is if the user does the following: - enter app -> init setup -> exits -> changes devices language -> enters app - For now I'm going to assume that will be a low probably of that happening. +* [MEDIUM] Add .so file so we can start using the emulator. \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings_categories.xml b/app/src/main/res/layout/activity_settings_categories.xml index 56718b0..235f722 100644 --- a/app/src/main/res/layout/activity_settings_categories.xml +++ b/app/src/main/res/layout/activity_settings_categories.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".UI.Activities.SettingsCategoriesActivity"> + tools:context=".UI.Activities.SettingsActivity">