mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
fixes #50 - delete tasks from inside the app / refactor deletion
This commit is contained in:
parent
ff5c1ece48
commit
dbadc948ae
7 changed files with 365 additions and 291 deletions
|
|
@ -1,235 +1,255 @@
|
|||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/scrollView">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_main_wrapper"
|
||||
android:padding="@dimen/abc_action_bar_content_inset_material">
|
||||
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/task_main_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_task_wrapper"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:layout_marginBottom="@dimen/abc_action_bar_content_inset_material">
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/abc_action_bar_content_inset_material">
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_text_edittext"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/text"
|
||||
android:textColor="@color/text_light" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_notes_edittext"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/notes"
|
||||
android:textColor="@color/text_light" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/difficulty"
|
||||
android:id="@+id/textView2"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/task_difficulty_spinner"
|
||||
android:layout_gravity="center_horizontal|right" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="140dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/task_startdate_layout">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/start_date"
|
||||
android:id="@+id/textView"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<DatePicker
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_startdate_picker"
|
||||
android:datePickerMode="spinner"
|
||||
android:calendarViewShown="false" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/task_actions_wrapper"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/actions"
|
||||
android:id="@+id/textView5" />
|
||||
|
||||
<RelativeLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/positive_habit_form"
|
||||
android:id="@+id/textView7"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="11dp"
|
||||
android:layout_toLeftOf="@+id/task_positive_checkbox"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_positive_checkbox"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="0dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/negative_habit_form"
|
||||
android:id="@+id/textView8"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="11dp"
|
||||
android:layout_toLeftOf="@+id/task_negative_checkbox"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_negative_checkbox"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="0dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/task_checklist_wrapper"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/checklist"
|
||||
android:id="@+id/textView9"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/checklist_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/new_checklist"
|
||||
android:hint="@string/new_checklist_item"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_checklist_item"
|
||||
android:id="@+id/add_checklist_button" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/task_weekdays_wrapper"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/frequency"
|
||||
android:id="@+id/textView10" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:id="@+id/task_frequency_spinner" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_task_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/task_frequency_container"
|
||||
android:layout_marginBottom="@dimen/abc_action_bar_content_inset_material"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/task_text_edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/text"
|
||||
android:textColor="@color/text_light" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/task_notes_edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/notes"
|
||||
android:textColor="@color/text_light" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/difficulty"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/task_difficulty_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_horizontal|right" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_startdate_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="140dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/start_date"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/task_startdate_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:calendarViewShown="false"
|
||||
android:datePickerMode="spinner" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_actions_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/actions"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="11dp"
|
||||
android:layout_toLeftOf="@+id/task_positive_checkbox"
|
||||
android:text="@string/positive_habit_form"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/task_positive_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="0dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView8"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="11dp"
|
||||
android:layout_toLeftOf="@+id/task_negative_checkbox"
|
||||
android:text="@string/negative_habit_form"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/task_negative_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="0dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_checklist_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView9"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/checklist"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/checklist_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/new_checklist"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/new_checklist_item" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/add_checklist_button"
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_checklist_item" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_weekdays_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView10"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/frequency"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/task_frequency_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_frequency_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_delete_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/action_delete"
|
||||
android:drawableRight="@drawable/ic_action_delete_white_24"
|
||||
android:textColor="@color/white"
|
||||
android:id="@+id/btn.delete.task"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
@ -201,8 +201,8 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
this.apiService.connectSocial(auth, callback);
|
||||
}
|
||||
|
||||
public void deleteTask(Task item, TaskDeletionCallback cb) {
|
||||
this.apiService.deleteTask(item.getId(), cb);
|
||||
public void deleteTask(String taskId, TaskDeletionCallback cb) {
|
||||
this.apiService.deleteTask(taskId, cb);
|
||||
}
|
||||
|
||||
public void updateTask(Task item, Callback cb) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ import android.widget.TextView;
|
|||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.events.OldTaskRemovedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskRemovedEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
|
|
@ -40,7 +41,9 @@ import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
|||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Delete;
|
||||
import com.raizlabs.android.dbflow.sql.language.From;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
|
|
@ -58,6 +61,9 @@ import butterknife.ButterKnife;
|
|||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
public class MainActivity extends InstabugAppCompatActivity implements HabitRPGUserCallback.OnUserReceived {
|
||||
|
||||
|
|
@ -142,6 +148,8 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
checkout.start();
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -162,14 +170,22 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
}
|
||||
}
|
||||
|
||||
public void onEvent(OpenGemPurchaseFragmentCommand cmd) {
|
||||
drawer.setSelection(MainDrawerBuilder.SIDEBAR_PURCHASE);
|
||||
public void onEvent(final DeleteTaskCommand cmd){
|
||||
mAPIHelper.apiService.deleteTask(cmd.TaskIdToDelete, new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
EventBus.getDefault().post(new TaskRemovedEvent(cmd.TaskIdToDelete));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||
public void onEvent(OpenGemPurchaseFragmentCommand cmd) {
|
||||
drawer.setSelection(MainDrawerBuilder.SIDEBAR_PURCHASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -247,8 +263,8 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
ArrayList<ChecklistItem> allChecklistItems = new ArrayList<>();
|
||||
|
||||
for(Task t : allTasks){
|
||||
if(t.checklist != null) {
|
||||
for (Task t : allTasks) {
|
||||
if (t.checklist != null) {
|
||||
allChecklistItems.addAll(t.checklist);
|
||||
}
|
||||
}
|
||||
|
|
@ -267,83 +283,93 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
onlineTaskIdList.add(oTask.getId());
|
||||
}
|
||||
|
||||
// Load Database Tasks
|
||||
new Select().from(Task.class).where(Condition.column("user_id").eq(userId)).async().queryList(new TransactionListener<List<Task>>() {
|
||||
@Override
|
||||
public void onResultReceived(List<Task> tasks) {
|
||||
Where<Task> query = new Select().from(Task.class).where(Condition.column("user_id").eq(userId));
|
||||
|
||||
ArrayList<Task> tasksToDelete = new ArrayList<Task>();
|
||||
if (query.count() != onlineEntries.size()) {
|
||||
|
||||
for (Task dbTask : tasks) {
|
||||
if (!onlineTaskIdList.contains(dbTask.getId())) {
|
||||
tasksToDelete.add(dbTask);
|
||||
// Load Database Tasks
|
||||
query.async().queryList(new TransactionListener<List<Task>>() {
|
||||
@Override
|
||||
public void onResultReceived(List<Task> tasks) {
|
||||
|
||||
ArrayList<Task> tasksToDelete = new ArrayList<Task>();
|
||||
|
||||
for (Task dbTask : tasks) {
|
||||
if (!onlineTaskIdList.contains(dbTask.getId())) {
|
||||
tasksToDelete.add(dbTask);
|
||||
}
|
||||
}
|
||||
|
||||
for (Task delTask : tasksToDelete) {
|
||||
// TaskTag
|
||||
new Delete().from(TaskTag.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// ChecklistItem
|
||||
new Delete().from(ChecklistItem.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// Days
|
||||
new Delete().from(Days.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// TASK
|
||||
delTask.async().delete();
|
||||
|
||||
EventBus.getDefault().post(new TaskRemovedEvent(delTask.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
for (Task delTask : tasksToDelete) {
|
||||
// TaskTag
|
||||
new Delete().from(TaskTag.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// ChecklistItem
|
||||
new Delete().from(ChecklistItem.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// Days
|
||||
new Delete().from(Days.class).where(Condition.column("task_id").eq(delTask.getId())).async().execute();
|
||||
|
||||
// TASK
|
||||
delTask.async().delete();
|
||||
|
||||
EventBus.getDefault().post(new OldTaskRemovedEvent(delTask.getId()));
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<List<Task>> baseTransaction) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<List<Task>> baseTransaction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<List<Task>> baseTransaction, List<Task> tasks) {
|
||||
return tasks != null && tasks.size() > 0;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<List<Task>> baseTransaction, List<Task> tasks) {
|
||||
return tasks != null && tasks.size() > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAndRemoveOldChecklists(final List<ChecklistItem> onlineEntries){
|
||||
private void loadAndRemoveOldChecklists(final List<ChecklistItem> onlineEntries) {
|
||||
final ArrayList<String> onlineChecklistItemIdList = new ArrayList<>();
|
||||
|
||||
for (ChecklistItem item : onlineEntries) {
|
||||
onlineChecklistItemIdList.add(item.getId());
|
||||
}
|
||||
|
||||
// Load Database Tasks
|
||||
new Select().from(ChecklistItem.class).async().queryList(new TransactionListener<List<ChecklistItem>>() {
|
||||
@Override
|
||||
public void onResultReceived(List<ChecklistItem> items) {
|
||||
From<ChecklistItem> query = new Select().from(ChecklistItem.class);
|
||||
|
||||
ArrayList<ChecklistItem> checkListItemsToDelete = new ArrayList<>();
|
||||
if (query.count() != onlineEntries.size()) {
|
||||
|
||||
for (ChecklistItem chItem : items) {
|
||||
if (!onlineChecklistItemIdList.contains(chItem.getId())) {
|
||||
checkListItemsToDelete.add(chItem);
|
||||
// Load Database Checklist items
|
||||
query.async().queryList(new TransactionListener<List<ChecklistItem>>() {
|
||||
@Override
|
||||
public void onResultReceived(List<ChecklistItem> items) {
|
||||
|
||||
ArrayList<ChecklistItem> checkListItemsToDelete = new ArrayList<>();
|
||||
|
||||
for (ChecklistItem chItem : items) {
|
||||
if (!onlineChecklistItemIdList.contains(chItem.getId())) {
|
||||
checkListItemsToDelete.add(chItem);
|
||||
}
|
||||
}
|
||||
|
||||
for (ChecklistItem chItem : checkListItemsToDelete) {
|
||||
chItem.async().delete();
|
||||
}
|
||||
}
|
||||
|
||||
for (ChecklistItem chItem : checkListItemsToDelete) {
|
||||
chItem.async().delete();
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<List<ChecklistItem>> baseTransaction) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<List<ChecklistItem>> baseTransaction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<List<ChecklistItem>> baseTransaction, List<ChecklistItem> items) {
|
||||
return items != null && items.size() > 0;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<List<ChecklistItem>> baseTransaction, List<ChecklistItem> items) {
|
||||
return items != null && items.size() > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUserAvatars() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.support.v7.widget.helper.ItemTouchHelper;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
|
@ -23,9 +22,11 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
|
||||
import com.habitrpg.android.habitica.ui.WrapContentRecyclerViewLayoutManager;
|
||||
import com.habitrpg.android.habitica.ui.adapter.CheckListAdapter;
|
||||
import com.habitrpg.android.habitica.ui.helpers.SimpleItemTouchHelperCallback;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days;
|
||||
|
|
@ -56,6 +57,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
|||
private LinearLayout frequencyContainer;
|
||||
private List<String> tags;
|
||||
private CheckListAdapter checklistAdapter;
|
||||
private Button btnDelete;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -76,6 +78,20 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
|||
taskText = (EditText) findViewById(R.id.task_text_edittext);
|
||||
taskNotes = (EditText) findViewById(R.id.task_notes_edittext);
|
||||
taskDifficultySpinner = (Spinner) findViewById(R.id.task_difficulty_spinner);
|
||||
btnDelete = (Button)findViewById(R.id.btn_delete_task);
|
||||
btnDelete.setEnabled(false);
|
||||
ViewHelper.SetBackgroundTint(btnDelete, getResources().getColor(R.color.worse_10));
|
||||
btnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
task.delete();
|
||||
|
||||
finish();
|
||||
dismissKeyboard();
|
||||
|
||||
EventBus.getDefault().post(new DeleteTaskCommand(taskId));
|
||||
}
|
||||
});
|
||||
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.task_difficulties, android.R.layout.simple_spinner_item);
|
||||
|
|
@ -120,6 +136,8 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
|||
this.task = task;
|
||||
this.populate(task);
|
||||
setTitle(task);
|
||||
|
||||
btnDelete.setEnabled(true);
|
||||
} else {
|
||||
setTitle((Task) null);
|
||||
}
|
||||
|
|
@ -372,7 +390,6 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
|||
}
|
||||
if (this.saveTask(this.task)) {
|
||||
this.task.save();
|
||||
List<TaskTag> taskTags = new ArrayList<TaskTag>();
|
||||
new Select()
|
||||
.from(Tag.class)
|
||||
.where(Condition.column("id").in("", tags.toArray())).async().queryList(tagsSearchingListener);
|
||||
|
|
@ -408,7 +425,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
|||
@Override
|
||||
public void onResultReceived(List<Tag> tags) {
|
||||
//UI thread.
|
||||
List<TaskTag> taskTags = new ArrayList<TaskTag>();
|
||||
List<TaskTag> taskTags = new ArrayList<>();
|
||||
for (Tag tag : tags) {
|
||||
TaskTag tt = new TaskTag();
|
||||
tt.setTag(tag);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package com.habitrpg.android.habitica.events;
|
|||
/**
|
||||
* Created by Negue on 01.12.2015.
|
||||
*/
|
||||
public class OldTaskRemovedEvent {
|
||||
public class TaskRemovedEvent {
|
||||
public String deletedTaskId;
|
||||
|
||||
public OldTaskRemovedEvent(String id) {
|
||||
public TaskRemovedEvent(String id) {
|
||||
deletedTaskId = id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.habitrpg.android.habitica.events.commands;
|
||||
|
||||
/**
|
||||
* Created by Negue on 02.12.2015.
|
||||
*/
|
||||
public class DeleteTaskCommand {
|
||||
public String TaskIdToDelete;
|
||||
|
||||
public DeleteTaskCommand(String id) {
|
||||
TaskIdToDelete = id;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import android.databinding.DataBindingUtil;
|
|||
import android.databinding.ObservableArrayList;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -27,7 +26,7 @@ import com.habitrpg.android.habitica.databinding.HabitItemCardBinding;
|
|||
import com.habitrpg.android.habitica.databinding.RewardItemCardBinding;
|
||||
import com.habitrpg.android.habitica.databinding.TodoItemCardBinding;
|
||||
import com.habitrpg.android.habitica.events.HabitScoreEvent;
|
||||
import com.habitrpg.android.habitica.events.OldTaskRemovedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskRemovedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskCreatedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskLongPressedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
|
|
@ -130,7 +129,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
filter();
|
||||
}
|
||||
|
||||
public void onEvent(OldTaskRemovedEvent evnt) {
|
||||
public void onEvent(TaskRemovedEvent evnt) {
|
||||
Task taskToDelete = null;
|
||||
|
||||
for(Task t : observableContent) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue