Skip to content

Commit

Permalink
* Handle MainActivity rotation correctly
Browse files Browse the repository at this point in the history
* Code cleanup
* Others
  • Loading branch information
Andr3Carvalh0 committed Mar 20, 2018
1 parent de0b089 commit c8ba1a7
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 316 deletions.
7 changes: 7 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</activity>

<activity
android:name=".UI.Activities.SettingsActivity"
android:name=".UI.Activities.SettingsPanelActivity"
android:label="@string/title_activity_settings"
android:theme="@style/SettingsTheme" />
<activity android:name=".UI.Activities.IntroActivity" />
Expand All @@ -53,7 +53,7 @@
</intent-filter>
</activity>
<activity android:name=".UI.Activities.EmulationActivity" />
<activity android:name=".UI.Activities.SettingsCategoriesActivity"
<activity android:name=".UI.Activities.SettingsActivity"
android:label="@string/title_activity_settings"
android:theme="@style/SettingsTheme"/>
</application>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/mgba/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
49 changes: 0 additions & 49 deletions app/src/main/java/io/mgba/Presenter/CategoriesPresenter.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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();
}
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();
}
11 changes: 3 additions & 8 deletions app/src/main/java/io/mgba/Presenter/MainPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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("")) {
Expand All @@ -98,6 +92,7 @@ public void onSearchTextChanged(String oldQuery, String newQuery, FloatingSearch
.subscribe(games -> {
mToolbar.swapSuggestions(games);
mToolbar.hideProgress();
onDestroy();
}));
}
}
Expand Down
109 changes: 109 additions & 0 deletions app/src/main/java/io/mgba/Presenter/SettingsPanelPresenter.java
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);
}
}
Loading

0 comments on commit c8ba1a7

Please sign in to comment.