Skip to content

Commit

Permalink
Bug fix: When disabling catch result toast, auto dissmiss encounter n…
Browse files Browse the repository at this point in the history
…otification wont work. Freeze bug on onPause.
  • Loading branch information
igoticecream committed Oct 11, 2016
1 parent 274c476 commit 2e8175e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void onPause() {

settingsReadable
.setReadable()
.toBlocking()
.subscribe(Timber::d, throwable -> {
Timber.e(throwable);
showReadableError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.icecream.snorlax.module.event.DismissNotification;
import com.icecream.snorlax.module.feature.Feature;
import com.icecream.snorlax.module.feature.mitm.MitmRelay;
import com.icecream.snorlax.module.util.Log;
Expand Down Expand Up @@ -63,13 +62,10 @@ private void onCapture(ByteString bytes) {

final CatchPokemonResponse.CatchStatus status = response.getStatus();

if (!status.equals(CatchPokemonResponse.CatchStatus.CATCH_MISSED)) {
if (mPreferences.isEnabled() && !status.equals(CatchPokemonResponse.CatchStatus.CATCH_MISSED)) {
mCaptureNotification.show(formatCapture(response.getStatus().name()));
}

if (status.equals(CatchPokemonResponse.CatchStatus.CATCH_SUCCESS) || status.equals(CatchPokemonResponse.CatchStatus.CATCH_FLEE)) {
mRxBus.post(DismissNotification.create());
}
mRxBus.post(new CaptureEvent(status));
}
catch (InvalidProtocolBufferException e) {
Log.d("CatchPokemonResponse failed: %s" + e.getMessage());
Expand All @@ -94,7 +90,6 @@ public void subscribe() {

mSubscription = mMitmRelay
.getObservable()
.compose(mPreferences.isEnabled())
.flatMap(envelope -> {
List<Request> requests = envelope.getRequest().getRequestsList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
* limitations under the License.
*/

package com.icecream.snorlax.module.event;
package com.icecream.snorlax.module.feature.capture;

public final class DismissNotification {
import static POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass.CatchPokemonResponse.CatchStatus;

public static DismissNotification create() {
return new DismissNotification();
public final class CaptureEvent {

private final CatchStatus mCatchStatus;

CaptureEvent(CatchStatus catchStatus) {
mCatchStatus = catchStatus;
}

private DismissNotification() {
public CatchStatus getCatchStatus() {
return mCatchStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.icecream.snorlax.module.context.snorlax.Snorlax;

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

@Singleton
final class CapturePreferences {
Expand All @@ -39,13 +38,10 @@ final class CapturePreferences {
mPreferences = preferences;
}

<T> Observable.Transformer<T, T> isEnabled() {
return observable -> observable
.doOnNext(t -> mPreferences.reload())
.filter(t -> {
final boolean expected = getPreferenceDefaultValue();
return expected == getPreference(expected);
});
boolean isEnabled() {
mPreferences.reload();
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 @@ -26,13 +26,14 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.icecream.snorlax.module.Pokemons;
import com.icecream.snorlax.module.event.DismissNotification;
import com.icecream.snorlax.module.feature.Feature;
import com.icecream.snorlax.module.feature.capture.CaptureEvent;
import com.icecream.snorlax.module.feature.mitm.MitmRelay;
import com.icecream.snorlax.module.util.Log;
import com.icecream.snorlax.module.util.RxBus;
import com.icecream.snorlax.module.util.RxFuncitons;

import POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass.CatchPokemonResponse.CatchStatus;
import rx.Observable;
import rx.Subscription;

Expand Down Expand Up @@ -106,7 +107,9 @@ public void subscribe() {
}, Log::e);

mRxBusSubscription = mRxBus
.receive(DismissNotification.class)
.receive(CaptureEvent.class)
.map(CaptureEvent::getCatchStatus)
.filter(status -> status.equals(CatchStatus.CATCH_FLEE) || status.equals(CatchStatus.CATCH_SUCCESS))
.compose(mEncounterPreferences.isDismissEnabled())
.subscribe(dismiss -> mEncounterNotification.cancel());
}
Expand Down

0 comments on commit 2e8175e

Please sign in to comment.