mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 19:59:00 +00:00
try to prevent multiple tasks being created
This commit is contained in:
parent
32fc3642b4
commit
45c1ce8a90
4 changed files with 63 additions and 62 deletions
|
|
@ -9,6 +9,7 @@ import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment;
|
|||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -27,6 +28,12 @@ public class GemPurchaseActivity extends BaseActivity implements GemsPurchaseFra
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
checkout.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -47,6 +54,13 @@ public class GemPurchaseActivity extends BaseActivity implements GemsPurchaseFra
|
|||
.add(R.id.fragment_container, firstFragment).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (checkout != null) {
|
||||
checkout.stop();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
|
|
|||
|
|
@ -50,21 +50,27 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.ItemsCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.MergeUserCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskCreationCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskScoringCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskUpdateCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.UnlockCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.databinding.ValueBarBinding;
|
||||
import com.habitrpg.android.habitica.events.ContentReloadedEvent;
|
||||
import com.habitrpg.android.habitica.events.DisplayFragmentEvent;
|
||||
import com.habitrpg.android.habitica.events.DisplayTutorialEvent;
|
||||
import com.habitrpg.android.habitica.events.HabitScoreEvent;
|
||||
import com.habitrpg.android.habitica.events.ReloadContentEvent;
|
||||
import com.habitrpg.android.habitica.events.SelectClassEvent;
|
||||
import com.habitrpg.android.habitica.events.ShareEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskRemovedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.events.ToggledEditTagsEvent;
|
||||
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.BuyGemItemCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.BuyRewardCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ChecklistCheckedCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.EquipCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand;
|
||||
|
|
@ -73,6 +79,7 @@ import com.habitrpg.android.habitica.events.commands.OpenFullProfileCommand;
|
|||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.SellItemCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.TaskCheckedCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UnlockPathCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager;
|
||||
|
|
@ -167,8 +174,6 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
|
||||
public static final int SELECT_CLASS_RESULT = 11;
|
||||
public static final int MIN_LEVEL_FOR_SKILLS = 11;
|
||||
// Checkout needs to be in the Activity..
|
||||
public ActivityCheckout checkout = null;
|
||||
@Inject
|
||||
public APIHelper apiHelper;
|
||||
@Inject
|
||||
|
|
@ -864,17 +869,12 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
checkout.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
// region Events
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (checkout != null) {
|
||||
checkout.stop();
|
||||
}
|
||||
|
||||
EventBus.getDefault().unregister(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
|
@ -1451,6 +1451,46 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_using)));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(TaskCheckedCommand event) {
|
||||
apiHelper.apiService.postTaskDirection(event.Task.getId(), (event.Task.getCompleted() ? TaskDirection.down : TaskDirection.up).toString())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskScoringCallback(this, event.Task.getId()), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(ChecklistCheckedCommand event) {
|
||||
apiHelper.apiService.scoreChecklistItem(event.task.getId(), event.item.getId())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(HabitScoreEvent event) {
|
||||
apiHelper.apiService.postTaskDirection(event.habit.getId(), (event.Up ? TaskDirection.up : TaskDirection.down).toString())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskScoringCallback(this, event.habit.getId()), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(final TaskSaveEvent event) {
|
||||
Task task = event.task;
|
||||
if (event.created) {
|
||||
this.apiHelper.apiService.createItem(task)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskCreationCallback(), throwable -> {
|
||||
});
|
||||
} else {
|
||||
this.apiHelper.apiService.updateTask(task.getId(), task)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMaintenance() {
|
||||
this.maintenanceService.getMaintenanceStatus()
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ public abstract class BaseFragment extends DialogFragment {
|
|||
public String tutorialStepIdentifier;
|
||||
public String tutorialText;
|
||||
public Unbinder unbinder;
|
||||
private boolean registerEventBus = false;
|
||||
private TransactionListener<TutorialStep> tutorialStepTransactionListener = new TransactionListener<TutorialStep>() {
|
||||
@Override
|
||||
public void onResultReceived(TutorialStep step) {
|
||||
|
|
@ -87,7 +86,6 @@ public abstract class BaseFragment extends DialogFragment {
|
|||
// Receive Events
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
registerEventBus = true;
|
||||
} catch (EventBusException ignored) {
|
||||
|
||||
}
|
||||
|
|
@ -109,7 +107,7 @@ public abstract class BaseFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (registerEventBus) {
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
if (unbinder != null) {
|
||||
|
|
|
|||
|
|
@ -415,30 +415,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(TaskCheckedCommand event) {
|
||||
apiHelper.apiService.postTaskDirection(event.Task.getId(), (event.Task.getCompleted() ? TaskDirection.down : TaskDirection.up).toString())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskScoringCallback(activity, event.Task.getId()), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(ChecklistCheckedCommand event) {
|
||||
apiHelper.apiService.scoreChecklistItem(event.task.getId(), event.item.getId())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(HabitScoreEvent event) {
|
||||
apiHelper.apiService.postTaskDirection(event.habit.getId(), (event.Up ? TaskDirection.up : TaskDirection.down).toString())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskScoringCallback(activity, event.habit.getId()), throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(AddNewTaskCommand event) {
|
||||
openNewTaskActivity(event.ClassType.toLowerCase());
|
||||
|
|
@ -446,36 +422,9 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(final TaskSaveEvent event) {
|
||||
Task task = event.task;
|
||||
if (event.created) {
|
||||
this.apiHelper.apiService.createItem(task)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskCreationCallback(), throwable -> {
|
||||
});
|
||||
floatingMenu.close(true);
|
||||
} else {
|
||||
this.apiHelper.apiService.updateTask(task.getId(), task)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
||||
});
|
||||
}
|
||||
floatingMenu.close(true);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(ToggledInnStateEvent event) {
|
||||
user.getPreferences().setSleep(event.Inn);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(ToggledEditTagsEvent event) {
|
||||
if(user != null) {
|
||||
if(this.editingTags == event.editing) {
|
||||
return;
|
||||
}
|
||||
this.editingTags = event.editing;
|
||||
fillTagFilterDrawer(tags);
|
||||
}
|
||||
}
|
||||
//endregion Events
|
||||
|
||||
public void fillTagFilterDrawer(List<Tag> tagList) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue