-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle MainActivity rotation correctly
* Code cleanup * Others
- Loading branch information
1 parent
de0b089
commit c8ba1a7
Showing
19 changed files
with
364 additions
and
316 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
app/src/main/java/io/mgba/Presenter/Interfaces/ICategoriesPresenter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPanelPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
23 changes: 5 additions & 18 deletions
23
app/src/main/java/io/mgba/Presenter/Interfaces/ISettingsPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SettingsCategory> getSettings(); | ||
Consumer<SettingsCategory> getOnClick(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Function<String, PreferenceFragmentCompat>> 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); | ||
} | ||
} |
Oops, something went wrong.