Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress background SmartView. #474 #475

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByDueDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build;
import android.os.Build.VERSION;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.TimeRangeCursorFactory;
Expand All @@ -37,6 +37,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;

import java.text.DateFormatSymbols;

Expand Down Expand Up @@ -123,23 +124,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
{
priorityView.setBackgroundResource(R.color.priority_green);
}
if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}

new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.QuickAddDialogFragment;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
Expand All @@ -38,6 +38,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -120,23 +121,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByPriority.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.provider.tasks.AuthorityUtil;
import org.dmfs.tasks.QuickAddDialogFragment;
import org.dmfs.tasks.R;
Expand All @@ -41,6 +41,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -112,23 +113,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.ProgressCursorFactory;
Expand All @@ -35,6 +35,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -105,23 +106,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/BySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Build.VERSION;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
Expand All @@ -31,6 +30,7 @@
import android.widget.TextView;
import android.widget.Toast;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.contract.TaskContract.Tasks;
Expand All @@ -44,6 +44,7 @@
import org.dmfs.tasks.utils.SearchHistoryDatabaseHelper.SearchHistoryColumns;
import org.dmfs.tasks.utils.SearchHistoryHelper;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -116,23 +117,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByStartDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.format.Time;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.TimeRangeCursorFactory;
Expand All @@ -41,6 +41,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -138,23 +139,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.widget;

import android.os.Build;
import android.view.View;

import org.dmfs.optional.Optional;
import org.dmfs.tasks.R;


/**
* {@link SmartView} adapting any {@link View} so that its background can be updated with a progress in percent,
* so that it shows the value as a proportionate horizontal overlay.
*
* @author Gabor Keszthelyi
*/
public final class ProgressBackgroundView implements SmartView<Optional<Integer>>
{
private final View mBackgroundView;


public ProgressBackgroundView(View backgroundView)
{
mBackgroundView = backgroundView;
}


@Override
public void update(Optional<Integer> percentComplete)
{
if (Build.VERSION.SDK_INT >= 11 && percentComplete.isPresent())
{
mBackgroundView.setPivotX(0);
if (percentComplete.value() < 100)
{
mBackgroundView.setScaleX(percentComplete.value() / 100f);
mBackgroundView.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
mBackgroundView.setScaleX(1);
mBackgroundView.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
}
}
36 changes: 36 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/widget/SmartView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.widget;

import android.view.View;


/**
* Interface that can be implemented by any {@link View} that is 'smart', i.e. that takes care of how to update itself
* from data/model and may also initiate actions, when clicked for example, instead of calling back.
*
* @author Gabor Keszthelyi
*/
public interface SmartView<D>
{

/**
* Called to update the View's content with the provided data.
*/
void update(D data);

}