mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Restore dynamic checkmark button count
This commit is contained in:
@@ -19,18 +19,14 @@
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.commands.CommandRunner;
|
||||
import org.isoron.uhabits.models.HabitList;
|
||||
import org.isoron.uhabits.models.ModelFactory;
|
||||
import org.isoron.uhabits.models.sqlite.SQLModelFactory;
|
||||
import org.isoron.uhabits.models.sqlite.SQLiteHabitList;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListCache;
|
||||
import org.isoron.uhabits.utils.Preferences;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.*;
|
||||
|
||||
/**
|
||||
* Module that provides dependencies when the application is running on
|
||||
@@ -48,13 +44,6 @@ public class AndroidModule
|
||||
return new CommandRunner();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
HabitCardListCache provideHabitCardListCache()
|
||||
{
|
||||
return new HabitCardListCache();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
HabitList provideHabitList()
|
||||
|
||||
@@ -19,31 +19,28 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.content.*;
|
||||
import android.content.res.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.ModelObservable;
|
||||
import org.isoron.uhabits.ui.BaseRootView;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.HabitCardListController;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListAdapter;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HintList;
|
||||
import org.isoron.uhabits.ui.habits.list.views.HabitCardListView;
|
||||
import org.isoron.uhabits.ui.habits.list.views.HintView;
|
||||
import org.isoron.uhabits.utils.InterfaceUtils;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.*;
|
||||
|
||||
public class ListHabitsRootView extends BaseRootView
|
||||
implements ModelObservable.Listener
|
||||
{
|
||||
public static final int MAX_CHECKMARK_COUNT = 21;
|
||||
|
||||
@BindView(R.id.listView)
|
||||
HabitCardListView listView;
|
||||
|
||||
@@ -71,6 +68,15 @@ public class ListHabitsRootView extends BaseRootView
|
||||
init();
|
||||
}
|
||||
|
||||
public static int getCheckmarkCount(View v)
|
||||
{
|
||||
Resources res = v.getResources();
|
||||
float labelWidth = res.getDimension(R.dimen.habitNameWidth);
|
||||
float buttonWidth = res.getDimension(R.dimen.checkmarkWidth);
|
||||
return Math.min(MAX_CHECKMARK_COUNT, Math.max(0,
|
||||
(int) ((v.getMeasuredWidth() - labelWidth) / buttonWidth)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ProgressBar getProgressBar()
|
||||
@@ -80,10 +86,16 @@ public class ListHabitsRootView extends BaseRootView
|
||||
|
||||
public boolean getShowArchived()
|
||||
{
|
||||
if(listAdapter == null) return false;
|
||||
if (listAdapter == null) return false;
|
||||
return listAdapter.getIncludeArchived();
|
||||
}
|
||||
|
||||
public void setShowArchived(boolean showArchived)
|
||||
{
|
||||
if (listAdapter == null) return;
|
||||
listAdapter.setShowArchived(showArchived);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Toolbar getToolbar()
|
||||
@@ -103,19 +115,6 @@ public class ListHabitsRootView extends BaseRootView
|
||||
updateEmptyView();
|
||||
}
|
||||
|
||||
public void setShowArchived(boolean showArchived)
|
||||
{
|
||||
if(listAdapter == null) return;
|
||||
listAdapter.setShowArchived(showArchived);
|
||||
}
|
||||
|
||||
private void updateEmptyView()
|
||||
{
|
||||
if (listAdapter == null) return;
|
||||
llEmpty.setVisibility(
|
||||
listAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setController(@Nullable ListHabitsController controller,
|
||||
@Nullable ListHabitsSelectionMenu menu)
|
||||
{
|
||||
@@ -139,20 +138,6 @@ public class ListHabitsRootView extends BaseRootView
|
||||
listAdapter.setListView(listView);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
addView(inflate(getContext(), R.layout.list_habits, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tvStarEmpty.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
|
||||
initToolbar();
|
||||
|
||||
String hints[] =
|
||||
getContext().getResources().getStringArray(R.array.hints);
|
||||
HintList hintList = new HintList(hints);
|
||||
hintView.setHints(hintList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
@@ -170,4 +155,25 @@ public class ListHabitsRootView extends BaseRootView
|
||||
listAdapter.getObservable().removeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
addView(inflate(getContext(), R.layout.list_habits, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tvStarEmpty.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
|
||||
initToolbar();
|
||||
|
||||
String hints[] =
|
||||
getContext().getResources().getStringArray(R.array.hints);
|
||||
HintList hintList = new HintList(hints);
|
||||
hintView.setHints(hintList);
|
||||
}
|
||||
|
||||
private void updateEmptyView()
|
||||
{
|
||||
if (listAdapter == null) return;
|
||||
llEmpty.setVisibility(
|
||||
listAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.io.File;
|
||||
|
||||
public class ListHabitsScreen extends BaseScreen
|
||||
{
|
||||
|
||||
@Nullable
|
||||
ListHabitsController controller;
|
||||
|
||||
@@ -71,7 +72,8 @@ public class ListHabitsScreen extends BaseScreen
|
||||
setMenu(menu);
|
||||
setSelectionMenu(selectionMenu);
|
||||
|
||||
HabitCardListAdapter adapter = new HabitCardListAdapter();
|
||||
HabitCardListAdapter adapter = new HabitCardListAdapter(
|
||||
ListHabitsRootView.MAX_CHECKMARK_COUNT);
|
||||
rootView.setListAdapter(adapter);
|
||||
selectionMenu.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@@ -19,22 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.HabitsApplication;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.ModelObservable;
|
||||
import org.isoron.uhabits.ui.habits.list.views.HabitCardListView;
|
||||
import org.isoron.uhabits.ui.habits.list.views.HabitCardView;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides data that backs a {@link HabitCardListView}.
|
||||
@@ -48,25 +41,25 @@ public class HabitCardListAdapter extends BaseAdapter
|
||||
@NonNull
|
||||
private ModelObservable observable;
|
||||
|
||||
@Inject
|
||||
@NonNull
|
||||
HabitCardListCache cache;
|
||||
|
||||
@Nullable
|
||||
private HabitCardListView listView;
|
||||
|
||||
@NonNull
|
||||
private final LinkedList<Habit> selected;
|
||||
|
||||
public HabitCardListAdapter()
|
||||
@NonNull
|
||||
private final HabitCardListCache cache;
|
||||
|
||||
public HabitCardListAdapter(int checkmarkCount)
|
||||
{
|
||||
this.selected = new LinkedList<>();
|
||||
this.observable = new ModelObservable();
|
||||
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
cache = new HabitCardListCache();
|
||||
cache.setListener(this);
|
||||
cache.setCheckmarkCount(5); // TODO: make this dynamic somehow
|
||||
cache.setCheckmarkCount(checkmarkCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,22 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.*;
|
||||
import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.HabitsApplication;
|
||||
import org.isoron.uhabits.commands.Command;
|
||||
import org.isoron.uhabits.commands.CommandRunner;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.HabitList;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* A HabitCardListCache fetches and keeps a cache of all the data necessary to
|
||||
@@ -114,7 +110,7 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
|
||||
public void onAttached()
|
||||
{
|
||||
// refreshAllHabits(true);
|
||||
refreshAllHabits(true);
|
||||
if (lastLoadTimestamp == null) refreshAllHabits(true);
|
||||
commandRunner.addListener(this);
|
||||
}
|
||||
@@ -129,11 +125,12 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
|
||||
public void onDetached()
|
||||
{
|
||||
// commandRunner.removeListener(this);
|
||||
commandRunner.removeListener(this);
|
||||
}
|
||||
|
||||
public void refreshAllHabits(final boolean refreshScoresAndCheckmarks)
|
||||
{
|
||||
Log.d("HabitCardListCache", "Refreshing all habits");
|
||||
if (currentFetchTask != null) currentFetchTask.cancel(true);
|
||||
currentFetchTask = new RefreshAllHabitsTask(refreshScoresAndCheckmarks);
|
||||
currentFetchTask.execute();
|
||||
|
||||
@@ -32,10 +32,11 @@ import android.widget.TextView;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.Score;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.RingView;
|
||||
import org.isoron.uhabits.utils.ColorUtils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -81,7 +82,9 @@ public class HabitCardView extends FrameLayout
|
||||
|
||||
public void setCheckmarkValues(int checkmarks[])
|
||||
{
|
||||
checkmarkPanel.setCheckmarkValues(checkmarks);
|
||||
int count = ListHabitsRootView.getCheckmarkCount(this);
|
||||
int visibleCheckmarks[] = Arrays.copyOfRange(checkmarks, 0, count);
|
||||
checkmarkPanel.setCheckmarkValues(visibleCheckmarks);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
@@ -50,8 +51,9 @@ public class HeaderView extends LinearLayout
|
||||
{
|
||||
removeAllViews();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
double count = ListHabitsRootView.getCheckmarkCount(this);
|
||||
|
||||
for (int i = 0; i < getButtonCount(); i++)
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int position = 0;
|
||||
|
||||
@@ -66,14 +68,6 @@ public class HeaderView extends LinearLayout
|
||||
}
|
||||
}
|
||||
|
||||
private int getButtonCount()
|
||||
{
|
||||
float labelWidth = getResources().getDimension(R.dimen.habitNameWidth);
|
||||
float buttonWidth = getResources().getDimension(R.dimen.checkmarkWidth);
|
||||
return Math.max(0,
|
||||
(int) ((getMeasuredWidth() - labelWidth) / buttonWidth));
|
||||
}
|
||||
|
||||
private int getCheckmarkOrder()
|
||||
{
|
||||
if (isInEditMode()) return CHECKMARK_LEFT_TO_RIGHT;
|
||||
|
||||
@@ -19,21 +19,16 @@
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.commands.CommandRunner;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.HabitList;
|
||||
import org.isoron.uhabits.models.ModelFactory;
|
||||
import org.isoron.uhabits.models.memory.MemoryHabitList;
|
||||
import org.isoron.uhabits.models.memory.MemoryModelFactory;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListCache;
|
||||
import org.isoron.uhabits.utils.Preferences;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.memory.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@Module
|
||||
public class TestModule
|
||||
@@ -52,13 +47,6 @@ public class TestModule
|
||||
return mock(CommandRunner.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
HabitCardListCache provideHabitCardListCache()
|
||||
{
|
||||
return mock(HabitCardListCache.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
HabitList provideHabitList()
|
||||
|
||||
Reference in New Issue
Block a user