-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabor Keszthelyi
committed
Dec 21, 2017
1 parent
62e6af8
commit 0da7e7d
Showing
27 changed files
with
1,009 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
opentasks/src/main/java/org/dmfs/tasks/detailsscreen/SubtaskView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.detailsscreen; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.databinding.DataBindingUtil; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
|
||
import org.dmfs.android.bolts.color.Color; | ||
import org.dmfs.optional.Optional; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.R; | ||
import org.dmfs.tasks.databinding.OpentasksViewItemTaskDetailsSubtaskBinding; | ||
import org.dmfs.tasks.readdata.TaskContentUri; | ||
import org.dmfs.tasks.utils.DateFormatter; | ||
import org.dmfs.tasks.utils.DateFormatter.DateFormatContext; | ||
import org.dmfs.tasks.widget.ProgressBackgroundView; | ||
import org.dmfs.tasks.widget.SmartView; | ||
|
||
|
||
/** | ||
* {@link View} for showing a subtask on the details screen. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class SubtaskView extends FrameLayout implements SmartView<SubtaskView.Params> | ||
{ | ||
|
||
public interface Params // i.e. fields of the subtask | ||
{ | ||
Long id(); | ||
|
||
Optional<CharSequence> title(); | ||
|
||
Optional<DateTime> due(); | ||
|
||
Color color(); | ||
|
||
Optional<Integer> percentComplete(); | ||
} | ||
|
||
|
||
public SubtaskView(@NonNull Context context, @Nullable AttributeSet attrs) | ||
{ | ||
super(context, attrs); | ||
} | ||
|
||
|
||
@Override | ||
public void update(Params subtask) | ||
{ | ||
OpentasksViewItemTaskDetailsSubtaskBinding views = DataBindingUtil.bind(this); | ||
|
||
views.opentasksTaskDetailsSubtaskTitle.setText(subtask.title().value(getContext().getString(R.string.opentasks_task_details_subtask_untitled))); | ||
|
||
if (subtask.due().isPresent()) | ||
{ | ||
views.opentasksTaskDetailsSubtaskDue.setText( | ||
new DateFormatter(getContext()).format(subtask.due().value(), DateTime.now(), DateFormatContext.LIST_VIEW)); | ||
} | ||
|
||
views.opentasksTaskDetailsSubtaskListRibbon.setBackgroundColor(subtask.color().argb()); | ||
|
||
new ProgressBackgroundView(views.opentasksTaskDetailsSubtaskProgressBackground) | ||
.update(subtask.percentComplete()); | ||
|
||
views.getRoot().setOnClickListener((v) -> | ||
{ | ||
Context ctx = v.getContext(); | ||
// TODO Use BasicTaskDetailsUi class when #589 is merged | ||
ctx.startActivity(new Intent(Intent.ACTION_VIEW, new TaskContentUri(subtask.id(), ctx).value())); | ||
}); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
opentasks/src/main/java/org/dmfs/tasks/detailsscreen/SubtasksView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.detailsscreen; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import org.dmfs.android.bolts.color.Color; | ||
import org.dmfs.tasks.R; | ||
import org.dmfs.tasks.widget.PopulateableViewGroup; | ||
import org.dmfs.tasks.widget.SmartView; | ||
import org.dmfs.tasks.widget.UpdatedSmartViews; | ||
|
||
|
||
/** | ||
* {@link SmartView} for the subtasks section of the task details screen. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class SubtasksView implements SmartView<SubtasksView.Params> | ||
{ | ||
public interface Params | ||
{ | ||
Color taskListColor(); | ||
|
||
Iterable<SubtaskView.Params> subtasks(); | ||
} | ||
|
||
|
||
private final ViewGroup mContentView; | ||
|
||
|
||
public SubtasksView(ViewGroup contentView) | ||
{ | ||
mContentView = contentView; | ||
} | ||
|
||
|
||
@Override | ||
public void update(SubtasksView.Params params) | ||
{ | ||
if (!params.subtasks().iterator().hasNext()) | ||
{ | ||
// Don't show the subtasks UI section if there are no subtasks | ||
return; | ||
} | ||
|
||
LayoutInflater inflater = LayoutInflater.from(mContentView.getContext()); | ||
|
||
inflater.inflate(R.layout.opentasks_view_item_divider, mContentView); | ||
|
||
TextView sectionHeader = (TextView) inflater.inflate(R.layout.opentasks_view_item_task_details_subtitles_section_header, null); | ||
sectionHeader.setTextColor(new Darkened(params.taskListColor()).argb()); | ||
mContentView.addView(sectionHeader); | ||
|
||
new PopulateableViewGroup<SubtaskView>(mContentView) | ||
.populate(new UpdatedSmartViews<>(params.subtasks(), inflater, R.layout.opentasks_view_item_task_details_subtask)); | ||
} | ||
|
||
|
||
// TODO Remove when #522 is merged, use the version from there | ||
private static final class Darkened implements Color | ||
{ | ||
private final Color mOriginal; | ||
|
||
|
||
private Darkened(Color original) | ||
{ | ||
mOriginal = original; | ||
} | ||
|
||
|
||
@Override | ||
public int argb() | ||
{ | ||
float[] hsv = new float[3]; | ||
android.graphics.Color.colorToHSV(mOriginal.argb(), hsv); | ||
hsv[2] = hsv[2] * 0.75f; | ||
return android.graphics.Color.HSVToColor(hsv); | ||
} | ||
} | ||
} |
Oops, something went wrong.