Skip to content

Commit

Permalink
Rename preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Diaz committed Sep 29, 2016
1 parent 14edc3f commit 444b583
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ <T> Observable.Transformer<T, T> isEnabled() {
return observable -> observable
.doOnNext(t -> mPreferences.reload())
.filter(t -> {
final boolean excepted = getPreferenceDefaultValue();
return excepted == getPreference(excepted);
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ <T> Observable.Transformer<T, T> isEnabled() {
return observable -> observable
.doOnNext(t -> mPreferences.reload())
.filter(t -> {
final boolean excepted = getPreferenceDefaultValue();
return excepted == getPreference(excepted);
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
/*
* Copyright (c) 2016. Pedro Diaz <igoticecream@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.icecream.snorlax.module.feature.hatch;

import javax.inject.Inject;
import javax.inject.Singleton;

import android.content.res.Resources;

import com.icecream.snorlax.R;
import com.icecream.snorlax.module.context.snorlax.Snorlax;

import javax.inject.Inject;
import javax.inject.Singleton;

import de.robv.android.xposed.XSharedPreferences;
import rx.Observable;

Expand All @@ -27,8 +43,8 @@ <T> Observable.Transformer<T, T> isEnabled() {
return observable -> observable
.doOnNext(t -> mPreferences.reload())
.filter(t -> {
final boolean excepted = getPreferenceDefaultValue();
return excepted == getPreference(excepted);
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class MockPreferences {

boolean isEnabled() {
mPreferences.reload();
final boolean excepted = getPreferenceDefaultValue();
return excepted == getPreference(excepted);
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
}

private boolean getPreferenceDefaultValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
public final class Rename implements Feature, MitmListener {

private final MitmProvider mMitmProvider;
private final RenamePreferences mRenamePreferences;

@Inject
Rename(MitmProvider mitmProvider) {
Rename(MitmProvider mitmProvider, RenamePreferences renamePreferences) {
mMitmProvider = mitmProvider;
mRenamePreferences = renamePreferences;
}

@Override
Expand All @@ -61,6 +63,10 @@ public void unsubscribe() {

@Override
public ResponseEnvelope onMitm(List<Request> requests, ResponseEnvelope envelope) {
if (!mRenamePreferences.isEnabled()) {
return null;
}

for (int i = 0; i < requests.size(); i++) {
if (requests.get(i).getRequestType() == RequestType.GET_INVENTORY) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2016. Pedro Diaz <igoticecream@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.icecream.snorlax.module.feature.rename;

import javax.inject.Inject;
import javax.inject.Singleton;

import android.content.res.Resources;

import com.icecream.snorlax.R;
import com.icecream.snorlax.module.context.snorlax.Snorlax;

import de.robv.android.xposed.XSharedPreferences;

@Singleton
final class RenamePreferences {

private final Resources mResources;
private final XSharedPreferences mPreferences;

@Inject
RenamePreferences(@Snorlax Resources resources, XSharedPreferences preferences) {
mResources = resources;
mPreferences = preferences;
}

boolean isEnabled() {
mPreferences.reload();
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
}

private boolean getPreferenceDefaultValue() {
return mResources.getBoolean(R.bool.preference_rename_enable);
}

private boolean getPreference(boolean defaultValue) {
return mPreferences.getBoolean(mResources.getString(R.string.preference_rename_enable_key), defaultValue);
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<bool name="preference_general_mock_enable">true</bool>
<bool name="preference_encounter_notification_enable">true</bool>
<bool name="preference_rename_enable">true</bool>
<bool name="preference_catch_notification_enable">true</bool>
<bool name="preference_hatch_notification_enable">true</bool>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<string name="preference_encounter_notification_enable_title">Enable encounter notifications</string>
<string name="preference_encounter_notification_enable_summary">Show encounter pokemons stats via system notification</string>

<string name="preference_rename">Show pokemons stats</string>
<string name="preference_rename_enable_key">rename_key</string>
<string name="preference_rename_enable_title">Enable inventory pokemons stats</string>
<string name="preference_rename_enable_summary">Show inventory pokemons stats on ingame pokemon list</string>

<string name="preference_catch_notification">Catch Notifications</string>
<string name="preference_catch_notification_enable_key">catch_notification_key</string>
<string name="preference_catch_notification_enable_title">Enable catch notifications</string>
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@

</PreferenceCategory>

<PreferenceCategory
android:title="@string/preference_rename"
>

<SwitchPreference
android:defaultValue="@bool/preference_rename_enable"
android:key="@string/preference_rename_enable_key"
android:summary="@string/preference_rename_enable_summary"
android:title="@string/preference_rename_enable_title"
/>

</PreferenceCategory>

<PreferenceCategory
android:title="@string/preference_encounter_notification"
>
Expand Down Expand Up @@ -49,8 +62,8 @@
<SwitchPreference
android:defaultValue="@bool/preference_hatch_notification_enable"
android:key="@string/preference_hatch_notification_enable_key"
android:summary="@string/preference_hatch_notification_enable_summary"
android:title="@string/preference_hatch_notification_enable_title"
android:summary="@string/preference_hatch_notification_enable_summary"
/>
</PreferenceCategory>
Expand Down

0 comments on commit 444b583

Please sign in to comment.