mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-16 11:11:41 +00:00
correctly display dailies as due
This commit is contained in:
parent
3aa5ec4608
commit
a61f53caf5
7 changed files with 90 additions and 18 deletions
|
|
@ -112,8 +112,8 @@
|
|||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.19" level="project" />
|
||||
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.19" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="okhttp-2.3.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="rxjava-1.0.10" level="project" />
|
||||
|
|
@ -134,8 +134,8 @@
|
|||
<orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="compiler-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="materialize-0.2.7" level="project" />
|
||||
<orderEntry type="library" exported="" name="gridlayout-v7-23.0.1" level="project" />
|
||||
|
|
@ -147,15 +147,15 @@
|
|||
<orderEntry type="library" exported="" name="facebook-android-sdk-4.7.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="iconics-core-1.7.9" level="project" />
|
||||
<orderEntry type="library" exported="" name="paperboy-2.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="fab-1.6.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="instabugcore-1.8-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
|
||||
<orderEntry type="library" exported="" name="DBFlow-Compiler-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
|
||||
<orderEntry type="library" exported="" name="answers-1.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="retrofit-1.9.0" level="project" />
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
<variable
|
||||
name="displayChecklist"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="offset"
|
||||
type="int" />
|
||||
</data>
|
||||
|
||||
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
|
@ -25,7 +28,7 @@
|
|||
<RelativeLayout
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="match_parent"
|
||||
app:backgroundColor="@{daily.isDisplayedActive ? daily.getLightTaskColor : @color/task_gray}">
|
||||
app:backgroundColor="@{daily.isDisplayedActive(offset) ? daily.getLightTaskColor : @color/task_gray}">
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/checkbox_size"
|
||||
|
|
@ -72,7 +75,7 @@
|
|||
android:id="@+id/checklistIndicatorWrapper"
|
||||
android:layout_width="@dimen/checklist_wrapper_width"
|
||||
android:layout_height="match_parent"
|
||||
app:backgroundColor="@{daily.checklist.size != daily.getCompletedChecklistCount ? daily.getLightTaskColor : @color/task_gray}"
|
||||
app:backgroundColor="@{daily.isChecklistDisplayActive(offset) ? @color/task_gray : daily.getLightTaskColor}"
|
||||
android:visibility="@{daily.checklist.size > 0 ? View.VISIBLE : View.GONE}"
|
||||
android:gravity="center"
|
||||
android:layout_alignParentTop="true"
|
||||
|
|
@ -104,7 +107,7 @@
|
|||
android:id="@+id/rightBorderView"
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="match_parent"
|
||||
app:backgroundColor="@{daily.isDisplayedActive ? daily.getLightTaskColor : @color/task_gray}"
|
||||
app:backgroundColor="@{daily.isDisplayedActive(offset) ? daily.getLightTaskColor : @color/task_gray}"
|
||||
android:visibility="@{daily.checklist.size == 0 ? View.VISIBLE : View.GONE}"
|
||||
android:gravity="center"
|
||||
android:layout_alignParentTop="true"
|
||||
|
|
|
|||
|
|
@ -376,6 +376,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
public Fragment getItem(int position) {
|
||||
int layoutOfType;
|
||||
TaskRecyclerViewFragment fragment;
|
||||
HabitItemRecyclerViewAdapter adapter;
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
|
|
@ -385,11 +386,15 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
break;
|
||||
case 1:
|
||||
layoutOfType = R.layout.daily_item_card;
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(Task.TYPE_DAILY, MainActivity.this.tagsHelper, layoutOfType, HabitItemRecyclerViewAdapter.DailyViewHolder.class, MainActivity.this), Task.TYPE_DAILY);
|
||||
adapter = new HabitItemRecyclerViewAdapter(Task.TYPE_DAILY, MainActivity.this.tagsHelper, layoutOfType, HabitItemRecyclerViewAdapter.DailyViewHolder.class, MainActivity.this);
|
||||
if (User != null) {
|
||||
adapter.dailyResetOffset = User.getPreferences().getDayStart();
|
||||
}
|
||||
fragment = TaskRecyclerViewFragment.newInstance(adapter, Task.TYPE_DAILY);
|
||||
break;
|
||||
case 3:
|
||||
layoutOfType = R.layout.reward_item_card;
|
||||
HabitItemRecyclerViewAdapter adapter = new HabitItemRecyclerViewAdapter(Task.TYPE_REWARD, MainActivity.this.tagsHelper,
|
||||
adapter = new HabitItemRecyclerViewAdapter(Task.TYPE_REWARD, MainActivity.this.tagsHelper,
|
||||
layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, MainActivity.this,
|
||||
new HabitItemRecyclerViewAdapter.IAdditionalEntries() {
|
||||
@Override
|
||||
|
|
@ -520,7 +525,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
|
||||
private void updateHeader() {
|
||||
updateUserAvatars();
|
||||
setTitle(User.getProfile().getName() + " - Lv" + User.getStats().getLvl());
|
||||
setTitle(User.getProfile().getName());
|
||||
|
||||
android.support.v7.app.ActionBarDrawerToggle actionBarDrawerToggle = drawer.getActionBarDrawerToggle();
|
||||
|
||||
|
|
@ -571,7 +576,11 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
loadTaskLists();
|
||||
FillTagFilterDrawer(User.getTags());
|
||||
}
|
||||
Log.w("header", "updating header");
|
||||
TaskRecyclerViewFragment fragment = ViewFragmentsDictionary.get(2);
|
||||
if (fragment != null) {
|
||||
HabitItemRecyclerViewAdapter adapter =(HabitItemRecyclerViewAdapter)fragment.mAdapter;
|
||||
adapter.dailyResetOffset = User.getPreferences().getDayStart();
|
||||
}
|
||||
updateHeader();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
private ObservableArrayList<Task> observableContent;
|
||||
FlowContentObserver observer;
|
||||
Context context;
|
||||
public int dailyResetOffset;
|
||||
|
||||
static final int TYPE_HEADER = 0;
|
||||
static final int TYPE_CELL = 1;
|
||||
|
|
@ -418,6 +419,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
binding = DataBindingUtil.bind(itemView);
|
||||
|
||||
checkbox.setOnCheckedChangeListener(this);
|
||||
binding.setOffset(dailyResetOffset);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import de.greenrobot.event.EventBus;
|
|||
*/
|
||||
public class TaskRecyclerViewFragment extends Fragment implements View.OnClickListener {
|
||||
public RecyclerView mRecyclerView;
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
public RecyclerView.Adapter mAdapter;
|
||||
private String classType;
|
||||
|
||||
// TODO needs a bit of cleanup
|
||||
|
|
|
|||
|
|
@ -83,4 +83,17 @@ public class Days extends BaseModel {
|
|||
public void setM(boolean m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public boolean getForDay(int day) {
|
||||
switch (day) {
|
||||
case 2: return this.getM();
|
||||
case 3: return this.getT();
|
||||
case 4: return this.getW();
|
||||
case 5: return this.getTh();
|
||||
case 6: return this.getF();
|
||||
case 7: return this.getS();
|
||||
case 1: return this.getSu();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,11 @@ import com.raizlabs.android.dbflow.sql.language.Select;
|
|||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by viirus on 10/08/15.
|
||||
|
|
@ -27,6 +30,9 @@ public class Task extends BaseModel {
|
|||
public static String TYPE_TODO = "todo";
|
||||
public static String TYPE_DAILY = "daily";
|
||||
public static String TYPE_REWARD = "reward";
|
||||
public static String FREQUENCY_WEEKLY = "weekly";
|
||||
public static String FREQUENCY_DAILY = "daily";
|
||||
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
|
|
@ -64,6 +70,9 @@ public class Task extends BaseModel {
|
|||
@Column
|
||||
public Integer everyX, streak;
|
||||
|
||||
@Column
|
||||
Date startDate;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "days_id",
|
||||
columnType = Long.class,
|
||||
|
|
@ -273,6 +282,9 @@ public class Task extends BaseModel {
|
|||
public Integer getEveryX() { return everyX; }
|
||||
public void setEveryX(Integer everyX) { this.everyX = everyX; }
|
||||
|
||||
public Date getStartDate() { return startDate; }
|
||||
public void setStartDate(Date startDate) {this.startDate = startDate; }
|
||||
|
||||
/**
|
||||
* @return the repeat array.<br/>
|
||||
* This array contains 7 values, one for each days, starting from monday.
|
||||
|
|
@ -405,12 +417,45 @@ public class Task extends BaseModel {
|
|||
return R.color.best_10;
|
||||
}
|
||||
|
||||
public Boolean isDue() {
|
||||
//TODO: check if daily is due
|
||||
return !this.getCompleted();
|
||||
public Boolean isDue(int offset) {
|
||||
if (this.getCompleted()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Calendar today = new GregorianCalendar();
|
||||
today.add(Calendar.HOUR, -offset);
|
||||
|
||||
if (this.getStartDate() != null) {
|
||||
Calendar startDate = new GregorianCalendar();
|
||||
startDate.setTime(this.getStartDate());
|
||||
Calendar startDateAtMidnight = new GregorianCalendar(startDate.get(Calendar.YEAR),
|
||||
startDate.get(Calendar.MONTH),
|
||||
startDate.get(Calendar.DAY_OF_MONTH));
|
||||
|
||||
if ( startDateAtMidnight.after(today) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getFrequency().equals(FREQUENCY_DAILY)) {
|
||||
Calendar startDate = new GregorianCalendar();
|
||||
if (this.getStartDate() != null) {
|
||||
startDate.setTime(this.getStartDate());
|
||||
}
|
||||
TimeUnit timeUnit = TimeUnit.DAYS;
|
||||
long diffInMillies = startDate.getTimeInMillis() - today.getTimeInMillis();
|
||||
long daySinceStart = timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
return (daySinceStart % this.getEveryX() == 0);
|
||||
} else {
|
||||
return this.getRepeat().getForDay(today.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isDisplayedActive() {
|
||||
return this.isDue() && !this.completed;
|
||||
public Boolean isDisplayedActive(int offset) {
|
||||
return this.isDue(offset) && !this.completed;
|
||||
}
|
||||
|
||||
public Boolean isChecklistDisplayActive(int offset) {
|
||||
return this.isDisplayedActive(offset) || (this.checklist.size() != this.getCompletedChecklistCount());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue