mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
show tasks inside dialog / improve loading challenges
This commit is contained in:
parent
b86edf308b
commit
a281d7fbf8
14 changed files with 627 additions and 56 deletions
10
Habitica/res/drawable/border_1f000000.xml
Normal file
10
Habitica/res/drawable/border_1f000000.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/transparent" />
|
||||
|
||||
<stroke
|
||||
android:width="0.5dip"
|
||||
android:color="#1f000000"/>
|
||||
|
||||
</shape>
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:height="20dp"
|
||||
android:text="Challenge"
|
||||
android:text="@string/challenge"
|
||||
android:textAllCaps="true" />
|
||||
|
||||
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="GO TO CHALLENGE"
|
||||
android:text="@string/go_to_challenge"
|
||||
android:textColor="#6133b4"
|
||||
android:textSize="16sp" />
|
||||
|
||||
|
|
@ -96,7 +96,6 @@
|
|||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="28dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
|
|
@ -105,12 +104,20 @@
|
|||
style="@style/Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Some Leader"
|
||||
tools:text="Leader name"
|
||||
android:textColor="#6133b4" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/task_group_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="13dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
|
|
|||
84
Habitica/res/layout/dialog_challenge_detail_daily.xml
Normal file
84
Habitica/res/layout/dialog_challenge_detail_daily.xml
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?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="@drawable/border_1f000000"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/daily_checkbox" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="3">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/daily_title"
|
||||
style="@style/Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="17dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:maxLines="1"
|
||||
tools:text="Long text to see" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/checklistIndicatorWrapper"
|
||||
android:layout_width="@dimen/checklist_wrapper_width"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
style="@style/Body3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0" />
|
||||
|
||||
<View
|
||||
android:id="@+id/checklistDivider"
|
||||
android:layout_width="@dimen/checklist_divider_width"
|
||||
android:layout_height="2dp"
|
||||
android:background="#8a000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/checkListAllTextView"
|
||||
style="@style/Body3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
tools:text="4" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
101
Habitica/res/layout/dialog_challenge_detail_habit.xml
Normal file
101
Habitica/res/layout/dialog_challenge_detail_habit.xml
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?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:orientation="horizontal"
|
||||
android:background="@drawable/border_1f000000"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/plus_img_tinted"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/plus"
|
||||
android:tint="#4d000000"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/plus_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/plus"
|
||||
android:tint="#1f000000"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="3">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/habit_title"
|
||||
style="@style/Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="17dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:maxLines="1"
|
||||
tools:text="Long text to see" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/minus_img_tinted"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/minus"
|
||||
android:tint="#4d000000"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/minus_img"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/minus"
|
||||
android:tint="#1f000000"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
55
Habitica/res/layout/dialog_challenge_detail_reward.xml
Normal file
55
Habitica/res/layout/dialog_challenge_detail_reward.xml
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?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:orientation="horizontal"
|
||||
android:background="@drawable/border_1f000000"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/ic_header_gold"
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="3">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reward_title"
|
||||
style="@style/Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="17dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:maxLines="1"
|
||||
tools:text="Long text to see" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
25
Habitica/res/layout/dialog_challenge_detail_task_group.xml
Normal file
25
Habitica/res/layout/dialog_challenge_detail_task_group.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?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="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_group_name"
|
||||
style="@style/Body1"
|
||||
android:layout_marginTop="13dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="2 Habits" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tasks_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="11dp"
|
||||
android:background="@drawable/border_1f000000"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
83
Habitica/res/layout/dialog_challenge_detail_todo.xml
Normal file
83
Habitica/res/layout/dialog_challenge_detail_todo.xml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?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="@drawable/border_1f000000"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="3">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
android:layout_marginEnd="15.5dp"
|
||||
android:layout_marginLeft="14.5dp"
|
||||
android:layout_marginRight="15.5dp"
|
||||
android:layout_marginStart="14.5dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:src="@drawable/todo_checkbox" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="3">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/todo_title"
|
||||
style="@style/Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="17dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:maxLines="1"
|
||||
tools:text="Long text to see" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/checklistIndicatorWrapper"
|
||||
android:layout_width="@dimen/checklist_wrapper_width"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
style="@style/Body3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0" />
|
||||
|
||||
<View
|
||||
android:id="@+id/checklistDivider"
|
||||
android:layout_width="@dimen/checklist_divider_width"
|
||||
android:layout_height="2dp"
|
||||
android:background="#8a000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/checkListAllTextView"
|
||||
style="@style/Body3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
tools:text="4" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -449,4 +449,6 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="todo">To-Do</string>
|
||||
<string name="official_habitica_challenge">Official Habitica Challenge</string>
|
||||
<string name="participating">Participating</string>
|
||||
<string name="challenge">Challenge</string>
|
||||
<string name="go_to_challenge">Go to Challenge</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,17 @@
|
|||
<!-- <item name="android:letterSpacing" tools:targetApi="lollipop">0.03</item>-->
|
||||
</style>
|
||||
|
||||
<style name="Body3">
|
||||
<item name="android:fontFamily" tools:targetApi="jelly_bean">
|
||||
@string/font_family_condensed
|
||||
</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
<item name="android:textColor">
|
||||
#8a000000
|
||||
</item>
|
||||
<item name="android:letterSpacing" tools:targetApi="lollipop">0.035</item>
|
||||
</style>
|
||||
|
||||
<style name="Body2">
|
||||
<item name="android:fontFamily" tools:targetApi="jelly_bean">
|
||||
@string/font_family_regular
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
|
@ -146,7 +147,7 @@ public class ChallengesListViewAdapter extends RecyclerView.Adapter<ChallengesLi
|
|||
HashMap<String, String[]> tasksOrder = challenge.getTasksOrder();
|
||||
for (Map.Entry<String, String[]> stringEntry : tasksOrder.entrySet()) {
|
||||
if (stringEntry.getValue().length != 0) {
|
||||
taskSummary.add(stringEntry.getValue().length + " " + getLabelByTypeAndCount(stringEntry.getKey(), stringEntry.getValue().length));
|
||||
taskSummary.add(stringEntry.getValue().length + " " + getLabelByTypeAndCount(getContext(), stringEntry.getKey(), stringEntry.getValue().length));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -169,15 +170,15 @@ public class ChallengesListViewAdapter extends RecyclerView.Adapter<ChallengesLi
|
|||
}
|
||||
}
|
||||
|
||||
private String getLabelByTypeAndCount(String type, int count) {
|
||||
public static String getLabelByTypeAndCount(Context context, String type, int count) {
|
||||
if (type == Challenge.TASK_ORDER_DAILYS) {
|
||||
return getContext().getString(count == 1 ? R.string.daily : R.string.dailies);
|
||||
return context.getString(count == 1 ? R.string.daily : R.string.dailies);
|
||||
} else if (type == Challenge.TASK_ORDER_HABITS) {
|
||||
return getContext().getString(count == 1 ? R.string.habit : R.string.habits);
|
||||
return context.getString(count == 1 ? R.string.habit : R.string.habits);
|
||||
} else if (type == Challenge.TASK_ORDER_REWARDS) {
|
||||
return getContext().getString(count == 1 ? R.string.reward : R.string.rewards);
|
||||
return context.getString(count == 1 ? R.string.reward : R.string.rewards);
|
||||
} else {
|
||||
return getContext().getString(count == 1 ? R.string.todo : R.string.todos);
|
||||
return context.getString(count == 1 ? R.string.todo : R.string.todos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ package com.habitrpg.android.habitica.ui.fragments.social.challenges;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -14,15 +16,21 @@ import com.habitrpg.android.habitica.HabiticaApplication;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenFullProfileCommand;
|
||||
import com.habitrpg.android.habitica.ui.activities.ChallengeDetailActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.ChallengesListViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import net.pherth.android.emoji_library.EmojiParser;
|
||||
import net.pherth.android.emoji_library.EmojiTextView;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
|
@ -57,6 +65,8 @@ public class ChallegeDetailDialogHolder {
|
|||
@BindView(R.id.challenge_member_count)
|
||||
TextView member_count;
|
||||
|
||||
@BindView(R.id.task_group_layout)
|
||||
LinearLayout task_group_layout;
|
||||
|
||||
private AlertDialog dialog;
|
||||
private APIHelper apiHelper;
|
||||
|
|
@ -93,6 +103,164 @@ public class ChallegeDetailDialogHolder {
|
|||
|
||||
gem_amount.setText(challenge.prize + "");
|
||||
member_count.setText(challenge.memberCount + "");
|
||||
|
||||
apiHelper.apiService.getChallengeTasks(challenge.id)
|
||||
.compose(this.apiHelper.configureApiCallObserver())
|
||||
.subscribe(taskList -> {
|
||||
ArrayList<Task> todos = new ArrayList<>();
|
||||
ArrayList<Task> habits = new ArrayList<>();
|
||||
ArrayList<Task> dailies = new ArrayList<>();
|
||||
ArrayList<Task> rewards = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Task> entry : taskList.tasks.entrySet()) {
|
||||
switch (entry.getValue().type) {
|
||||
case Task.TYPE_TODO:
|
||||
todos.add(entry.getValue());
|
||||
break;
|
||||
case Task.TYPE_HABIT:
|
||||
|
||||
habits.add(entry.getValue());
|
||||
break;
|
||||
case Task.TYPE_DAILY:
|
||||
|
||||
dailies.add(entry.getValue());
|
||||
break;
|
||||
case Task.TYPE_REWARD:
|
||||
|
||||
rewards.add(entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (habits.size() > 0) {
|
||||
addHabits(habits);
|
||||
}
|
||||
|
||||
if (dailies.size() > 0) {
|
||||
addDailys(dailies);
|
||||
}
|
||||
|
||||
if (todos.size() > 0) {
|
||||
addTodos(todos);
|
||||
}
|
||||
|
||||
if (rewards.size() > 0) {
|
||||
addRewards(rewards);
|
||||
}
|
||||
}
|
||||
, Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
private void addHabits(ArrayList<Task> habits) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
||||
groupName.setText(habits.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_HABITS, habits.size()));
|
||||
|
||||
int size = habits.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Task task = habits.get(i);
|
||||
|
||||
View habitEntry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_habit, null);
|
||||
TextView habitTitle = (TextView) habitEntry.findViewById(R.id.habit_title);
|
||||
ImageView plusImg = (ImageView) habitEntry.findViewById(task.up ? R.id.plus_img_tinted : R.id.plus_img);
|
||||
ImageView minusImg = (ImageView) habitEntry.findViewById(task.down ? R.id.minus_img_tinted : R.id.minus_img);
|
||||
|
||||
plusImg.setVisibility(View.VISIBLE);
|
||||
minusImg.setVisibility(View.VISIBLE);
|
||||
|
||||
habitTitle.setText(task.text);
|
||||
|
||||
tasks_layout.addView(habitEntry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addDailys(ArrayList<Task> dailys) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
||||
int size = dailys.size();
|
||||
groupName.setText(dailys.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_DAILYS, size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Task task = dailys.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_daily, null);
|
||||
TextView title = (TextView) entry.findViewById(R.id.daily_title);
|
||||
title.setText(task.text);
|
||||
|
||||
if(task.checklist != null && !task.checklist.isEmpty()){
|
||||
View checklistIndicatorWrapper = entry.findViewById(R.id.checklistIndicatorWrapper);
|
||||
|
||||
checklistIndicatorWrapper.setVisibility(View.VISIBLE);
|
||||
|
||||
TextView checkListAllTextView = (TextView)entry.findViewById(R.id.checkListAllTextView);
|
||||
checkListAllTextView.setText(task.checklist.size()+"");
|
||||
}
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addTodos(ArrayList<Task> todos) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
||||
int size = todos.size();
|
||||
groupName.setText(todos.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_TODOS, size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Task task = todos.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_todo, null);
|
||||
TextView title = (TextView) entry.findViewById(R.id.todo_title);
|
||||
title.setText(task.text);
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
|
||||
if(task.checklist != null && !task.checklist.isEmpty()){
|
||||
View checklistIndicatorWrapper = entry.findViewById(R.id.checklistIndicatorWrapper);
|
||||
|
||||
checklistIndicatorWrapper.setVisibility(View.VISIBLE);
|
||||
|
||||
TextView checkListAllTextView = (TextView)entry.findViewById(R.id.checkListAllTextView);
|
||||
checkListAllTextView.setText(task.checklist.size()+"");
|
||||
}
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addRewards(ArrayList<Task> rewards) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
||||
int size = rewards.size();
|
||||
groupName.setText(rewards.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_REWARDS, size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Task task = rewards.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_reward, null);
|
||||
TextView title = (TextView) entry.findViewById(R.id.reward_title);
|
||||
title.setText(task.text);
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
public void setJoined(boolean joined) {
|
||||
|
|
@ -151,6 +319,9 @@ public class ChallegeDetailDialogHolder {
|
|||
|
||||
this.user.resetChallengeList();
|
||||
|
||||
if (challengeLeftAction != null) {
|
||||
challengeLeftAction.call(challenge);
|
||||
}
|
||||
|
||||
this.dialog.dismiss();
|
||||
}, throwable -> {
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@ import com.raizlabs.android.dbflow.sql.builder.Condition;
|
|||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import rx.Observable;
|
||||
import rx.functions.Action0;
|
||||
import rx.functions.Action1;
|
||||
|
||||
public class ChallengeListFragment extends BaseMainFragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
|
|
@ -34,6 +38,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
private ChallengesListViewAdapter challengeAdapter;
|
||||
private boolean viewUserChallengesOnly;
|
||||
private Action0 refreshCallback;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstance) {
|
||||
|
|
@ -46,6 +51,51 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
this.viewUserChallengesOnly = only;
|
||||
}
|
||||
|
||||
public void setRefreshingCallback(Action0 refreshCallback){
|
||||
this.refreshCallback = refreshCallback;
|
||||
}
|
||||
|
||||
public void setObservable(Observable<ArrayList<Challenge>> listObservable){
|
||||
listObservable
|
||||
.subscribe(challenges -> {
|
||||
|
||||
List<Challenge> userChallenges = this.user.getChallengeList();
|
||||
|
||||
HashSet<String> userChallengesHash = new HashSet<String>();
|
||||
|
||||
for (Challenge userChallenge : userChallenges) {
|
||||
userChallengesHash.add(userChallenge.id);
|
||||
}
|
||||
|
||||
userChallenges.clear();
|
||||
|
||||
for (Challenge challenge : challenges) {
|
||||
if (userChallengesHash.contains(challenge.id) && challenge.name != null && !challenge.name.isEmpty()) {
|
||||
challenge.user_id = this.user.getId();
|
||||
userChallenges.add(challenge);
|
||||
}
|
||||
|
||||
challenge.async().save();
|
||||
}
|
||||
|
||||
if (viewUserChallengesOnly) {
|
||||
setAdapterEntries(userChallenges);
|
||||
} else {
|
||||
setAdapterEntries(challenges);
|
||||
}
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, throwable -> {
|
||||
Log.e("ChallengeListFragment", "", throwable);
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
@ -91,54 +141,9 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
}
|
||||
|
||||
private void fetchOnlineChallenges() {
|
||||
if (this.apiHelper != null && this.apiHelper.apiService != null) {
|
||||
|
||||
apiHelper.apiService.getUserChallenges().
|
||||
compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(challenges -> {
|
||||
|
||||
List<Challenge> userChallenges = this.user.getChallengeList();
|
||||
|
||||
HashSet<String> userChallengesHash = new HashSet<String>();
|
||||
|
||||
for (Challenge userChallenge : userChallenges) {
|
||||
userChallengesHash.add(userChallenge.id);
|
||||
}
|
||||
|
||||
userChallenges.clear();
|
||||
|
||||
for (Challenge challenge : challenges) {
|
||||
if (userChallengesHash.contains(challenge.id) && challenge.name != null && !challenge.name.isEmpty()) {
|
||||
challenge.user_id = this.user.getId();
|
||||
userChallenges.add(challenge);
|
||||
}
|
||||
|
||||
challenge.async().save();
|
||||
|
||||
}
|
||||
|
||||
if (viewUserChallengesOnly) {
|
||||
setAdapterEntries(userChallenges);
|
||||
} else {
|
||||
|
||||
setAdapterEntries(challenges);
|
||||
}
|
||||
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, throwable -> {
|
||||
Log.e("ChallengeListFragment", "", throwable);
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
refreshCallback.call();
|
||||
}
|
||||
|
||||
|
||||
private void setAdapterEntries(List<Challenge> challenges) {
|
||||
challengeAdapter.setChallenges(challenges);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,11 @@ import com.raizlabs.android.dbflow.sql.language.Select;
|
|||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
public class ChallengesOverviewFragment extends BaseMainFragment {
|
||||
|
||||
public ViewPager viewPager;
|
||||
|
|
@ -43,12 +46,20 @@ public class ChallengesOverviewFragment extends BaseMainFragment {
|
|||
|
||||
setViewPagerAdapter();
|
||||
|
||||
Observable<ArrayList<Challenge>> getUserChallengesObservable = this.apiHelper.apiService.getUserChallenges()
|
||||
.compose(apiHelper.configureApiCallObserver());
|
||||
|
||||
|
||||
userChallengesFragment = new ChallengeListFragment();
|
||||
userChallengesFragment.setUser(this.user);
|
||||
userChallengesFragment.setRefreshingCallback(getUserChallengesObservable::repeat);
|
||||
userChallengesFragment.setObservable(getUserChallengesObservable);
|
||||
userChallengesFragment.setViewUserChallengesOnly(true);
|
||||
|
||||
availableChallengesFragment = new ChallengeListFragment();
|
||||
availableChallengesFragment.setUser(this.user);
|
||||
availableChallengesFragment.setRefreshingCallback(getUserChallengesObservable::repeat);
|
||||
availableChallengesFragment.setObservable(getUserChallengesObservable);
|
||||
availableChallengesFragment.setViewUserChallengesOnly(false);
|
||||
|
||||
pageHistory = new Stack<Integer>();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.support.v7.widget.AppCompatButton;
|
|||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class ViewHelper {
|
||||
|
||||
|
|
@ -35,6 +36,10 @@ public class ViewHelper {
|
|||
b.setBackgroundTintList(csl);
|
||||
}
|
||||
|
||||
public static void SetBackgroundTint(ImageView v, int tint) {
|
||||
v.setColorFilter(tint, PorterDuff.Mode.SRC);
|
||||
}
|
||||
|
||||
public static void SetBackgroundTint(View v, int tint) {
|
||||
v.getBackground().setColorFilter(tint, PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue