mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 11:49:01 +00:00
fix setup
This commit is contained in:
parent
f7c2e97e66
commit
5ab5c2ebba
3 changed files with 26 additions and 20 deletions
|
|
@ -10,6 +10,7 @@ import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
|||
import com.habitrpg.android.habitica.ui.fragments.setup.AvatarSetupFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.setup.TaskSetupFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
|
|
@ -89,28 +90,24 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
protected void onStart() {
|
||||
super.onStart();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
||||
if (this.pager.getAdapter() == null) {
|
||||
if (this.user != null) {
|
||||
setupViewpager();
|
||||
} else {
|
||||
this.apiHelper.apiService.getUser()
|
||||
.compose(this.apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
private void setupViewpager() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
|
|
@ -145,15 +142,21 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
@Subscribe
|
||||
public void onEvent(UpdateUserCommand event) {
|
||||
this.apiHelper.apiService.updateUser(event.updateData)
|
||||
.subscribe(new MergeUserCallback(this, user), throwable -> {});
|
||||
.compose(this.apiHelper.configureApiCallObserver())
|
||||
.subscribe(new MergeUserCallback(this, user), throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == this.nextButton) {
|
||||
if (this.pager.getCurrentItem() == 1) {
|
||||
List<Map<String, Object>> operations = this.taskSetupFragment.createSampleTasks();
|
||||
List<Map<String, Object>> newTasks = this.taskSetupFragment.createSampleTasks();
|
||||
this.completedSetup = true;
|
||||
this.apiHelper.apiService.createItems(newTasks)
|
||||
.compose(this.apiHelper.configureApiCallObserver())
|
||||
.subscribe(tasks -> {
|
||||
onUserReceived(user);
|
||||
}, throwable -> {});
|
||||
//this.apiHelper.apiService.batchOperation(operations, new HabitRPGUserCallback(this));
|
||||
}
|
||||
this.pager.setCurrentItem(this.pager.getCurrentItem()+1);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.ui.activities.SetupActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.setup.TaskSetupAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
|
@ -106,20 +107,19 @@ public class TaskSetupFragment extends BaseFragment {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
List<Map<String, Object>> operations = new ArrayList<>();
|
||||
List<Map<String, Object>> tasks = new ArrayList<>();
|
||||
for (Object[] task : this.tasks) {
|
||||
if (groups.contains((String) task[0])) {
|
||||
Map<String, Object> operation = new HashMap<>();
|
||||
operation.put("op", "addTask");
|
||||
Map<String, Object> taskObject = new HashMap<>();
|
||||
if (task.length == 5) {
|
||||
operation.put("body", this.makeTaskObject((String) task[1], (String) task[2], (Boolean) task[3], (Boolean) task[4]));
|
||||
taskObject = this.makeTaskObject((String) task[1], (String) task[2], (Boolean) task[3], (Boolean) task[4]);
|
||||
} else {
|
||||
operation.put("body", this.makeTaskObject((String) task[1], (String) task[2], null, null));
|
||||
taskObject = this.makeTaskObject((String) task[1], (String) task[2], null, null);
|
||||
}
|
||||
operations.add(operation);
|
||||
tasks.add(taskObject);
|
||||
}
|
||||
}
|
||||
return operations;
|
||||
return tasks;
|
||||
}
|
||||
|
||||
private Map<String, Object> makeTaskObject(String type, String text, Boolean up, Boolean down) {
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ public interface ApiService {
|
|||
@POST("tasks/user")
|
||||
Observable<Task> createItem(@Body Task item);
|
||||
|
||||
@POST("tasks/user")
|
||||
Observable<List<Task>> createItems(@Body List<Map<String, Object>> tasks);
|
||||
|
||||
@PUT("tasks/{id}")
|
||||
Observable<Task> updateTask(@Path("id") String id, @Body Task item);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue