|
| 1 | +/* |
| 2 | + * Copyright 2017 dmfs GmbH |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.dmfs.tasks.detailsscreen; |
| 18 | + |
| 19 | +import android.content.Context; |
| 20 | +import android.content.Intent; |
| 21 | +import android.databinding.DataBindingUtil; |
| 22 | +import android.support.annotation.NonNull; |
| 23 | +import android.support.annotation.Nullable; |
| 24 | +import android.util.AttributeSet; |
| 25 | +import android.view.View; |
| 26 | +import android.widget.FrameLayout; |
| 27 | + |
| 28 | +import org.dmfs.android.bolts.color.Color; |
| 29 | +import org.dmfs.optional.Optional; |
| 30 | +import org.dmfs.rfc5545.DateTime; |
| 31 | +import org.dmfs.tasks.R; |
| 32 | +import org.dmfs.tasks.databinding.OpentasksViewItemTaskDetailsSubtaskBinding; |
| 33 | +import org.dmfs.tasks.readdata.TaskContentUri; |
| 34 | +import org.dmfs.tasks.utils.DateFormatter; |
| 35 | +import org.dmfs.tasks.utils.DateFormatter.DateFormatContext; |
| 36 | +import org.dmfs.tasks.widget.ProgressBackgroundView; |
| 37 | +import org.dmfs.tasks.widget.SmartView; |
| 38 | + |
| 39 | + |
| 40 | +/** |
| 41 | + * {@link View} for showing a subtask on the details screen. |
| 42 | + * |
| 43 | + * @author Gabor Keszthelyi |
| 44 | + */ |
| 45 | +public final class SubtaskView extends FrameLayout implements SmartView<SubtaskView.Params> |
| 46 | +{ |
| 47 | + |
| 48 | + public interface Params // i.e. fields of the subtask |
| 49 | + { |
| 50 | + Long id(); |
| 51 | + |
| 52 | + Optional<CharSequence> title(); |
| 53 | + |
| 54 | + Optional<DateTime> due(); |
| 55 | + |
| 56 | + Color color(); |
| 57 | + |
| 58 | + Optional<Integer> percentComplete(); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + public SubtaskView(@NonNull Context context, @Nullable AttributeSet attrs) |
| 63 | + { |
| 64 | + super(context, attrs); |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + @Override |
| 69 | + public void update(Params subtask) |
| 70 | + { |
| 71 | + OpentasksViewItemTaskDetailsSubtaskBinding views = DataBindingUtil.bind(this); |
| 72 | + |
| 73 | + views.opentasksTaskDetailsSubtaskTitle.setText(subtask.title().value(getContext().getString(R.string.opentasks_task_details_subtask_untitled))); |
| 74 | + |
| 75 | + if (subtask.due().isPresent()) |
| 76 | + { |
| 77 | + views.opentasksTaskDetailsSubtaskDue.setText( |
| 78 | + new DateFormatter(getContext()).format(subtask.due().value(), DateTime.now(), DateFormatContext.LIST_VIEW)); |
| 79 | + } |
| 80 | + |
| 81 | + views.opentasksTaskDetailsSubtaskListRibbon.setBackgroundColor(subtask.color().argb()); |
| 82 | + |
| 83 | + new ProgressBackgroundView(views.opentasksTaskDetailsSubtaskProgressBackground) |
| 84 | + .update(subtask.percentComplete()); |
| 85 | + |
| 86 | + views.getRoot().setOnClickListener((v) -> |
| 87 | + { |
| 88 | + Context ctx = v.getContext(); |
| 89 | + // TODO Use BasicTaskDetailsUi class when #589 is merged |
| 90 | + ctx.startActivity(new Intent(Intent.ACTION_VIEW, new TaskContentUri(subtask.id(), ctx).value())); |
| 91 | + }); |
| 92 | + } |
| 93 | +} |
0 commit comments