mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
more layout + open new/edit TaskFormActivity without saving to DB + extract ChallengeTasksRecyclerViewAdapter
This commit is contained in:
parent
57e9dd9272
commit
94a4ef6b1d
17 changed files with 551 additions and 238 deletions
|
|
@ -141,15 +141,16 @@
|
|||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.CreateChallengeActivity"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:launchMode="singleTask"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
android:name=".ui.activities.CreateChallengeActivity"
|
||||
android:theme="@style/AppThemeWithActionBar"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:launchMode="singleTask"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity android:name="com.facebook.FacebookActivity"
|
||||
android:configChanges=
|
||||
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
|
||||
|
|
|
|||
4
Habitica/res/drawable-v21/ic_close_white_24dp.xml
Normal file
4
Habitica/res/drawable-v21/ic_close_white_24dp.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
||||
4
Habitica/res/drawable/ic_close_white_24dp.xml
Normal file
4
Habitica/res/drawable/ic_close_white_24dp.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
</vector>
|
||||
4
Habitica/res/drawable/ic_info_outline_black_24dp.xml
Normal file
4
Habitica/res/drawable/ic_info_outline_black_24dp.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
|
||||
<path android:fillColor="#000000" android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
|
||||
</vector>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/activity_create_challenge"
|
||||
|
|
@ -8,147 +8,177 @@
|
|||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.habitrpg.android.habitica.ui.activities.CreateChallengeActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin">
|
||||
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textColorHint="@color/brand_500"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="New challenge title" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Description"
|
||||
android:inputType="textMultiLine"
|
||||
|
||||
android:minLines="3"
|
||||
android:maxLines="5"
|
||||
/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:background="@color/brand_700"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Gem reward"
|
||||
style="@style/Body1"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/brand_200"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="22dp">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/plus"
|
||||
android:drawableTint="@color/brand_500"
|
||||
style="@style/Body1_Button"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/challenge_add_gem_btn"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="2"
|
||||
android:inputType="number"
|
||||
android:gravity="center"
|
||||
android:textAlignment="center"
|
||||
android:drawableLeft="@drawable/ic_header_gem"/>
|
||||
android:textColorHint="@color/brand_500"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:hint="New challenge title"
|
||||
|
||||
android:textColor="@color/white"
|
||||
android:textColorHighlight="@color/brand_500"
|
||||
android:textColorHint="@color/brand_500"
|
||||
|
||||
tools:text="Get in shape" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableRight="@drawable/minus"
|
||||
android:drawableTint="@color/brand_500"
|
||||
style="@style/Body1_Button"
|
||||
android:id="@+id/challenge_remove_gem_btn" />
|
||||
android:textColorHint="@color/brand_500"
|
||||
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Description"
|
||||
android:inputType="textMultiLine"
|
||||
|
||||
android:maxLines="5"
|
||||
android:minLines="3"
|
||||
android:textColor="@color/white"
|
||||
android:textColorHighlight="@color/brand_500"
|
||||
android:textColorHint="@color/brand_500" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:background="@color/brand_700" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Location"
|
||||
style="@style/Body1" />
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/challenge_location_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
style="@style/Subheader2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="23dp"
|
||||
android:text="@string/gem_reward"
|
||||
android:textColor="#cc000000" />
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="28dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/challenge_add_gem_btn"
|
||||
style="@style/Body1_Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:drawableLeft="@drawable/plus"
|
||||
android:drawableTint="@color/brand_400" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_header_gem" />
|
||||
|
||||
<EditText
|
||||
style="@style/Subheader2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:inputType="number"
|
||||
android:textColor="#8a000000"
|
||||
android:text="1"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/challenge_remove_gem_btn"
|
||||
style="@style/Body1_Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:drawableRight="@drawable/minus"
|
||||
android:drawableTint="@color/brand_400" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
style="@style/Subheader2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="26dp"
|
||||
android:text="@string/location"
|
||||
android:textColor="#cc000000" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/challenge_location_spinner"
|
||||
style="@android:style/Widget.Material.Spinner.Underlined"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#8a000000"
|
||||
android:layout_marginTop="17dp" />
|
||||
|
||||
<TextView
|
||||
style="@style/Subheader2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginTop="39dp"
|
||||
android:drawablePadding="12dp"
|
||||
android:drawableEnd="@drawable/ic_info_outline_black_24dp"
|
||||
android:drawableTint="@color/brand_300"
|
||||
android:gravity="center"
|
||||
android:text="Tag"
|
||||
android:textColor="#cc000000" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="23dp"
|
||||
android:hint="Identify your challenge with a tag .."
|
||||
android:textColorHint="#61000000" />
|
||||
|
||||
<TextView
|
||||
style="@style/Subheader2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tasks" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Tag"
|
||||
style="@style/Body1" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Tasks"
|
||||
style="@style/Body1" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add Habit" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add Daily" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add To-Do" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add Reward" />
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:id="@+id/create_challenge_task_list">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
|
|||
28
Habitica/res/layout/challenge_add_task_item.xml
Normal file
28
Habitica/res/layout/challenge_add_task_item.xml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#FFF"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="22dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:textAllCaps="false"
|
||||
style="@style/Subheader2"
|
||||
android:textColor="@color/brand_400"
|
||||
android:background="#f9f9f9"
|
||||
android:id="@+id/btn_add_task"
|
||||
tools:text="Add habit">
|
||||
|
||||
</Button>
|
||||
|
||||
</LinearLayout>
|
||||
11
Habitica/res/menu/menu_create_challenge.xml
Normal file
11
Habitica/res/menu/menu_create_challenge.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.habitrpg.android.habitica.TaskActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
android:title="@string/save"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
||||
|
|
@ -544,4 +544,8 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="action_back">Back</string>
|
||||
<string name="welcome_text">Oh, you must be new here. I’m Justin, I’ll be your guide in Habitica.\n\nTo start, you’ll need to create an avatar.</string>
|
||||
<string name="randomize">Randomize</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="location">Location</string>
|
||||
<string name="gem_reward">Gem reward</string>
|
||||
<string name="tasks">Tasks</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.habitrpg.android.habitica.ui.activities.SetupActivity;
|
|||
import com.habitrpg.android.habitica.ui.activities.SkillMemberActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.SkillTasksActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.TaskFormActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengeTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.DailiesRecyclerViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.HabitsRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.RewardsRecyclerViewAdapter;
|
||||
|
|
@ -226,7 +227,7 @@ public interface AppComponent {
|
|||
|
||||
void inject(SubscriptionFragment subscriptionFragment);
|
||||
|
||||
void inject(ChallengeTasksRecyclerViewFragment.ChallengeTasksRecyclerViewAdapter challengeTasksRecyclerViewAdapter);
|
||||
void inject(ChallengeTasksRecyclerViewAdapter challengeTasksRecyclerViewAdapter);
|
||||
|
||||
void inject(ChallengeTasksRecyclerViewFragment challengeTasksRecyclerViewFragment);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,172 @@
|
|||
package com.habitrpg.android.habitica.ui.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.view.menu.MenuAdapter;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengeTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeTasksRecyclerViewFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
public class CreateChallengeActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.challenge_location_spinner)
|
||||
Spinner challenge_location_spinner;
|
||||
|
||||
|
||||
@BindView(R.id.create_challenge_task_list)
|
||||
RecyclerView create_challenge_task_list;
|
||||
|
||||
private boolean displayingTaskForm;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_create_challenge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_create_challenge, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
Resources resources = getResources();
|
||||
|
||||
ActionBar supportActionBar = getSupportActionBar();
|
||||
if (supportActionBar != null) {
|
||||
supportActionBar.setIcon(R.drawable.ic_close_white_24dp);
|
||||
|
||||
supportActionBar.setBackgroundDrawable(new ColorDrawable(resources.getColor(R.color.brand_200)));
|
||||
supportActionBar.setElevation(0);
|
||||
}
|
||||
|
||||
ArrayAdapter<CharSequence> locationAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
|
||||
locationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
locationAdapter.addAll("Tavern", "My Group", "Some other");
|
||||
challenge_location_spinner.setAdapter(locationAdapter);
|
||||
|
||||
Task addHabit = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_habit));
|
||||
Task addDaily = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_daily));
|
||||
Task addTodo = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_todo));
|
||||
Task addReward = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_reward));
|
||||
|
||||
ArrayList<Task> taskList = new ArrayList<>();
|
||||
taskList.add(addHabit);
|
||||
taskList.add(createTask(Task.TYPE_HABIT));
|
||||
taskList.add(addDaily);
|
||||
taskList.add(createTask(Task.TYPE_DAILY));
|
||||
taskList.add(addTodo);
|
||||
taskList.add(createTask(Task.TYPE_TODO));
|
||||
taskList.add(addReward);
|
||||
taskList.add(createTask(Task.TYPE_REWARD));
|
||||
|
||||
ChallengeTasksRecyclerViewAdapter challengeTasks = new ChallengeTasksRecyclerViewAdapter(null, 0, this, "", null, false, true);
|
||||
challengeTasks.setTasks(taskList);
|
||||
challengeTasks.enableAddItem(t -> {
|
||||
if (t.equals(addHabit)) {
|
||||
openNewTaskActivity(Task.TYPE_HABIT);
|
||||
} else if (t.equals(addDaily)) {
|
||||
|
||||
openNewTaskActivity(Task.TYPE_DAILY);
|
||||
} else if (t.equals(addTodo)) {
|
||||
|
||||
openNewTaskActivity(Task.TYPE_TODO);
|
||||
} else if (t.equals(addReward)) {
|
||||
|
||||
openNewTaskActivity(Task.TYPE_REWARD);
|
||||
}
|
||||
});
|
||||
|
||||
create_challenge_task_list.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
||||
// Stop only scrolling.
|
||||
return rv.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING;
|
||||
}
|
||||
});
|
||||
create_challenge_task_list.setAdapter(challengeTasks);
|
||||
create_challenge_task_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
}
|
||||
|
||||
private void openNewTaskActivity(String type) {
|
||||
if (this.displayingTaskForm) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(TaskFormActivity.TASK_TYPE_KEY, type);
|
||||
bundle.putBoolean(TaskFormActivity.SAVE_TO_DB, false);
|
||||
|
||||
if (HabiticaApplication.User != null && HabiticaApplication.User.getPreferences() != null) {
|
||||
String allocationMode = HabiticaApplication.User.getPreferences().getAllocationMode();
|
||||
|
||||
bundle.putString(TaskFormActivity.USER_ID_KEY, HabiticaApplication.User.getId());
|
||||
bundle.putString(TaskFormActivity.ALLOCATION_MODE_KEY, allocationMode);
|
||||
}
|
||||
|
||||
|
||||
Intent intent = new Intent(this, TaskFormActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
|
||||
this.displayingTaskForm = true;
|
||||
startActivityForResult(intent, 1);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(TaskSaveEvent saveEvent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Task createTask(String taskType) {
|
||||
return createTask(taskType, "example " + taskType);
|
||||
}
|
||||
|
||||
private Task createTask(String taskType, String taskName) {
|
||||
Task t = new Task();
|
||||
|
||||
t.setId(UUID.randomUUID().toString());
|
||||
t.setType(taskType);
|
||||
t.setText(taskName);
|
||||
t.setNotes("example " + taskType + " notes");
|
||||
|
||||
if (taskType.equals(Task.TYPE_HABIT)) {
|
||||
t.setUp(true);
|
||||
t.setDown(false);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
public static final String USER_ID_KEY = "userId";
|
||||
public static final String TASK_TYPE_KEY = "type";
|
||||
public static final String ALLOCATION_MODE_KEY = "allocationModeKey";
|
||||
public static final String SAVE_TO_DB = "saveToDb";
|
||||
|
||||
@BindView(R.id.task_value_edittext)
|
||||
EditText taskValue;
|
||||
|
|
@ -214,6 +215,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
private RemindersManager remindersManager;
|
||||
private TaskAlarmManager taskAlarmManager;
|
||||
private FirstDayOfTheWeekHelper firstDayOfTheWeekHelper;
|
||||
private boolean saveToDb;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
|
|
@ -230,6 +232,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
taskId = bundle.getString(TASK_ID_KEY);
|
||||
userId = bundle.getString(USER_ID_KEY);
|
||||
allocationMode = bundle.getString(ALLOCATION_MODE_KEY);
|
||||
saveToDb = bundle.getBoolean(SAVE_TO_DB, true);
|
||||
tagCheckBoxList = new ArrayList<>();
|
||||
selectedTags = new ArrayList<>();
|
||||
if (taskType == null) {
|
||||
|
|
@ -873,7 +876,10 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
}
|
||||
//save
|
||||
this.task.setTags(taskTags);
|
||||
this.task.save();
|
||||
if(saveToDb){
|
||||
this.task.save();
|
||||
}
|
||||
|
||||
//send back to other elements.
|
||||
TaskSaveEvent event = new TaskSaveEvent();
|
||||
if (TaskFormActivity.this.task.getId() == null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,155 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social.challenges;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.helpers.TagsHelper;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.DailyViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.HabitViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.RewardViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.TodoViewHolder;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import butterknife.OnClick;
|
||||
import rx.functions.Action1;
|
||||
|
||||
public class ChallengeTasksRecyclerViewAdapter extends SortableTasksRecyclerViewAdapter<BaseTaskViewHolder> {
|
||||
public static final String TASK_TYPE_ADD_ITEM = "ADD_ITEM";
|
||||
|
||||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_HABIT = 1;
|
||||
private static final int TYPE_DAILY = 2;
|
||||
private static final int TYPE_TODO = 3;
|
||||
private static final int TYPE_REWARD = 4;
|
||||
private static final int TYPE_ADD_ITEM = 5;
|
||||
|
||||
private int dailyResetOffset = 0;
|
||||
private Action1<Task> addItemCallback;
|
||||
private boolean openTaskDisabled;
|
||||
private boolean taskActionsDisabled;
|
||||
|
||||
public ChallengeTasksRecyclerViewAdapter(TagsHelper tagsHelper, int layoutResource,
|
||||
Context newContext, String userID, SortTasksCallback sortCallback,
|
||||
boolean openTaskDisabled, boolean taskActionsDisabled) {
|
||||
super("", tagsHelper, layoutResource, newContext, userID, sortCallback);
|
||||
this.openTaskDisabled = openTaskDisabled;
|
||||
this.taskActionsDisabled = taskActionsDisabled;
|
||||
}
|
||||
|
||||
public void setDailyResetOffset(int newResetOffset){
|
||||
dailyResetOffset = newResetOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectThis(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadFromDatabase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Task task = this.filteredContent.get(position);
|
||||
|
||||
if (task.type.equals(Task.TYPE_HABIT))
|
||||
return TYPE_HABIT;
|
||||
|
||||
if (task.type.equals(Task.TYPE_DAILY))
|
||||
return TYPE_DAILY;
|
||||
|
||||
if (task.type.equals(Task.TYPE_TODO))
|
||||
return TYPE_TODO;
|
||||
|
||||
if (task.type.equals(Task.TYPE_REWARD))
|
||||
return TYPE_REWARD;
|
||||
|
||||
if(addItemCallback != null && task.type.equals(TASK_TYPE_ADD_ITEM))
|
||||
return TYPE_ADD_ITEM;
|
||||
|
||||
return TYPE_HEADER;
|
||||
}
|
||||
|
||||
public void enableAddItem(Action1<Task> cb) {
|
||||
addItemCallback = cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseTaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
BaseTaskViewHolder viewHolder = null;
|
||||
|
||||
switch (viewType) {
|
||||
case TYPE_HABIT:
|
||||
viewHolder = new HabitViewHolder(getContentView(parent, R.layout.habit_item_card));
|
||||
break;
|
||||
case TYPE_DAILY:
|
||||
viewHolder = new DailyViewHolder(getContentView(parent, R.layout.daily_item_card), dailyResetOffset);
|
||||
break;
|
||||
case TYPE_TODO:
|
||||
viewHolder = new TodoViewHolder(getContentView(parent, R.layout.todo_item_card));
|
||||
break;
|
||||
case TYPE_REWARD:
|
||||
viewHolder = new RewardViewHolder(getContentView(parent, R.layout.reward_item_card));
|
||||
break;
|
||||
case TYPE_ADD_ITEM:
|
||||
viewHolder = new AddItemViewHolder(getContentView(parent, R.layout.challenge_add_task_item), addItemCallback);
|
||||
break;
|
||||
default:
|
||||
viewHolder = new DividerViewHolder(getContentView(parent, R.layout.challenge_task_divider));
|
||||
break;
|
||||
}
|
||||
|
||||
viewHolder.setDisabled(openTaskDisabled, taskActionsDisabled);
|
||||
return viewHolder;
|
||||
}
|
||||
|
||||
public class AddItemViewHolder extends BaseTaskViewHolder {
|
||||
|
||||
private Button addBtn;
|
||||
private Action1<Task> callback;
|
||||
private Task newTask;
|
||||
|
||||
public AddItemViewHolder(View itemView, Action1<Task> callback) {
|
||||
super(itemView, false);
|
||||
this.callback = callback;
|
||||
|
||||
addBtn = (Button) itemView.findViewById(R.id.btn_add_task);
|
||||
addBtn.setClickable(true);
|
||||
addBtn.setOnClickListener(view -> callback.call(newTask));
|
||||
context = itemView.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Task newTask, int position) {
|
||||
this.newTask = newTask;
|
||||
addBtn.setText(newTask.text);
|
||||
}
|
||||
}
|
||||
|
||||
private class DividerViewHolder extends BaseTaskViewHolder {
|
||||
|
||||
private TextView divider_name;
|
||||
|
||||
public DividerViewHolder(View itemView) {
|
||||
super(itemView, false);
|
||||
|
||||
divider_name = (TextView) itemView.findViewById(R.id.divider_name);
|
||||
|
||||
context = itemView.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Task newTask, int position) {
|
||||
divider_name.setText(newTask.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.habitrpg.android.habitica.APIHelper;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.helpers.TagsHelper;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengeTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
|
|
@ -86,7 +87,10 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
|
|||
}
|
||||
|
||||
public void setInnerAdapter() {
|
||||
this.recyclerAdapter = new ChallengeTasksRecyclerViewAdapter(null, 0, getContext(), userID, null);
|
||||
ChallengeTasksRecyclerViewAdapter challengeTasksRecyclerViewAdapter = new ChallengeTasksRecyclerViewAdapter(null, 0, getContext(), userID, null, true, true);
|
||||
this.recyclerAdapter = challengeTasksRecyclerViewAdapter;
|
||||
|
||||
challengeTasksRecyclerViewAdapter.setDailyResetOffset(user.getPreferences().getDayStart());
|
||||
|
||||
if (tasksOnInitialize.size() != 0 && recyclerAdapter != null && recyclerAdapter.getItemCount() == 0) {
|
||||
recyclerAdapter.setTasks(tasksOnInitialize);
|
||||
|
|
@ -137,96 +141,8 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
|
|||
|
||||
// region Challenge specific RecyclerViewAdapters
|
||||
|
||||
public class ChallengeTasksRecyclerViewAdapter extends SortableTasksRecyclerViewAdapter<BaseTaskViewHolder> {
|
||||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_HABIT = 1;
|
||||
private static final int TYPE_DAILY = 2;
|
||||
private static final int TYPE_TODO = 3;
|
||||
private static final int TYPE_REWARD = 4;
|
||||
|
||||
private int dailyResetOffset = 0;
|
||||
|
||||
public ChallengeTasksRecyclerViewAdapter(TagsHelper tagsHelper, int layoutResource, Context newContext, String userID, SortTasksCallback sortCallback) {
|
||||
super("", tagsHelper, layoutResource, newContext, userID, sortCallback);
|
||||
|
||||
if (user != null) {
|
||||
dailyResetOffset = user.getPreferences().getDayStart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectThis(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadFromDatabase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Task task = this.filteredContent.get(position);
|
||||
|
||||
if (task.type.equals(Task.TYPE_HABIT))
|
||||
return TYPE_HABIT;
|
||||
|
||||
if (task.type.equals(Task.TYPE_DAILY))
|
||||
return TYPE_DAILY;
|
||||
|
||||
if (task.type.equals(Task.TYPE_TODO))
|
||||
return TYPE_TODO;
|
||||
|
||||
if (task.type.equals(Task.TYPE_REWARD))
|
||||
return TYPE_REWARD;
|
||||
|
||||
return TYPE_HEADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseTaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
BaseTaskViewHolder viewHolder = null;
|
||||
|
||||
switch (viewType) {
|
||||
case TYPE_HABIT:
|
||||
viewHolder = new HabitViewHolder(getContentView(parent, R.layout.habit_item_card));
|
||||
break;
|
||||
case TYPE_DAILY:
|
||||
viewHolder = new DailyViewHolder(getContentView(parent, R.layout.daily_item_card), dailyResetOffset);
|
||||
break;
|
||||
case TYPE_TODO:
|
||||
viewHolder = new TodoViewHolder(getContentView(parent, R.layout.todo_item_card));
|
||||
break;
|
||||
case TYPE_REWARD:
|
||||
viewHolder = new RewardViewHolder(getContentView(parent, R.layout.reward_item_card));
|
||||
break;
|
||||
default:
|
||||
viewHolder = new DividerViewHolder(getContentView(parent, R.layout.challenge_task_divider));
|
||||
break;
|
||||
}
|
||||
|
||||
viewHolder.setDisabled(true);
|
||||
return viewHolder;
|
||||
}
|
||||
}
|
||||
|
||||
private class DividerViewHolder extends BaseTaskViewHolder {
|
||||
|
||||
private TextView divider_name;
|
||||
|
||||
public DividerViewHolder(View itemView) {
|
||||
super(itemView, false);
|
||||
|
||||
divider_name = (TextView) itemView.findViewById(R.id.divider_name);
|
||||
|
||||
context = itemView.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Task newTask, int position) {
|
||||
divider_name.setText(newTask.text);
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
|
|||
@BindView(R.id.approvalRequiredTextField)
|
||||
TextView approvalRequiredTextView;
|
||||
|
||||
boolean disabled;
|
||||
|
||||
public BaseTaskViewHolder(View itemView) {
|
||||
this(itemView, true);
|
||||
|
|
@ -187,7 +186,7 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v != itemView || isDisabled()) {
|
||||
if (v != itemView || this.openTaskDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -201,13 +200,11 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
protected boolean openTaskDisabled, taskActionsDisabled;
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
public void setDisabled(boolean openTaskDisabled, boolean taskActionsDisabled) {
|
||||
this.openTaskDisabled = openTaskDisabled;
|
||||
this.taskActionsDisabled = taskActionsDisabled;
|
||||
|
||||
itemView.setEnabled(!disabled);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,9 +167,9 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setDisabled(boolean disabled) {
|
||||
super.setDisabled(disabled);
|
||||
public void setDisabled(boolean openTaskDisabled, boolean taskActionsDisabled) {
|
||||
super.setDisabled(openTaskDisabled, taskActionsDisabled);
|
||||
|
||||
this.checkbox.setEnabled(!disabled);
|
||||
this.checkbox.setEnabled(!taskActionsDisabled);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ public class HabitViewHolder extends BaseTaskViewHolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setDisabled(boolean disabled) {
|
||||
super.setDisabled(disabled);
|
||||
public void setDisabled(boolean openTaskDisabled, boolean taskActionsDisabled) {
|
||||
super.setDisabled(openTaskDisabled, taskActionsDisabled);
|
||||
|
||||
this.btnPlus.setEnabled(!disabled);
|
||||
this.btnMinus.setEnabled(!disabled);
|
||||
this.btnPlus.setEnabled(!taskActionsDisabled);
|
||||
this.btnMinus.setEnabled(!taskActionsDisabled);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ public class RewardViewHolder extends BaseTaskViewHolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setDisabled(boolean disabled) {
|
||||
super.setDisabled(disabled);
|
||||
public void setDisabled(boolean openTaskDisabled, boolean taskActionsDisabled) {
|
||||
super.setDisabled(openTaskDisabled, taskActionsDisabled);
|
||||
|
||||
this.rewardButton.setEnabled(!disabled);
|
||||
this.rewardButton.setEnabled(!taskActionsDisabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue