mirror of https://github.com/iSoron/uhabits.git
parent
4c1c6e76fc
commit
98d17d60a5
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show
|
||||
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class ShowHabitPresenter
|
||||
@Inject constructor(
|
||||
val habit: Habit,
|
||||
) {
|
||||
private val listeners = mutableListOf<Listener>()
|
||||
|
||||
private fun build() = ShowHabitViewModel(
|
||||
title = habit.name,
|
||||
isNumerical = habit.isNumerical,
|
||||
)
|
||||
|
||||
fun addListener(listener: Listener) {
|
||||
listeners.add(listener)
|
||||
}
|
||||
|
||||
fun removeListener(listener: Listener) {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
|
||||
fun requestData(listener: Listener) {
|
||||
listener.onData(build())
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun onData(data: ShowHabitViewModel)
|
||||
}
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show;
|
||||
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.activities.habits.show.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
@ActivityScope
|
||||
public class ShowHabitRootView extends BaseRootView
|
||||
implements ModelObservable.Listener
|
||||
{
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
@BindView(R.id.frequencyCard)
|
||||
FrequencyCard frequencyCard;
|
||||
|
||||
@BindView(R.id.streakCard)
|
||||
StreakCard streakCard;
|
||||
|
||||
@BindView(R.id.subtitleCard)
|
||||
SubtitleCard subtitleCard;
|
||||
|
||||
@BindView(R.id.notesCard)
|
||||
NotesCard notesCard;
|
||||
|
||||
@BindView(R.id.habitNotes)
|
||||
TextView habitNotes;
|
||||
|
||||
@BindView(R.id.overviewCard)
|
||||
OverviewCard overviewCard;
|
||||
|
||||
@BindView(R.id.scoreCard)
|
||||
ScoreCard scoreCard;
|
||||
|
||||
@BindView(R.id.historyCard)
|
||||
HistoryCard historyCard;
|
||||
|
||||
@BindView(R.id.barCard)
|
||||
BarCard barCard;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@BindView(R.id.targetCard)
|
||||
TargetCard targetCard;
|
||||
|
||||
@NonNull
|
||||
private Controller controller;
|
||||
|
||||
@Inject
|
||||
public ShowHabitRootView(@NonNull @ActivityContext Context context,
|
||||
@NonNull Habit habit)
|
||||
{
|
||||
super(context);
|
||||
this.habit = habit;
|
||||
|
||||
addView(inflate(getContext(), R.layout.show_habit, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
controller = new Controller() {};
|
||||
setDisplayHomeAsUp(true);
|
||||
initCards();
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolbarColor()
|
||||
{
|
||||
StyledResources res = new StyledResources(getContext());
|
||||
if (!res.getBoolean(R.attr.useHabitColorAsPrimary))
|
||||
return super.getToolbarColor();
|
||||
|
||||
return PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelChange()
|
||||
{
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
toolbar.setTitle(habit.getName());
|
||||
});
|
||||
|
||||
controller.onToolbarChanged();
|
||||
}
|
||||
|
||||
public void setController(@NonNull Controller controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
historyCard.setController(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initToolbar()
|
||||
{
|
||||
super.initToolbar();
|
||||
toolbar.setTitle(habit.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
super.onAttachedToWindow();
|
||||
habit.getObservable().addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
habit.getObservable().removeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void initCards()
|
||||
{
|
||||
subtitleCard.setHabit(habit);
|
||||
notesCard.setHabit(habit);
|
||||
overviewCard.setHabit(habit);
|
||||
scoreCard.setHabit(habit);
|
||||
historyCard.setHabit(habit);
|
||||
streakCard.setHabit(habit);
|
||||
frequencyCard.setHabit(habit);
|
||||
barCard.setHabit(habit);
|
||||
targetCard.setHabit(habit);
|
||||
|
||||
if(habit.isNumerical()) {
|
||||
overviewCard.setVisibility(View.GONE);
|
||||
streakCard.setVisibility(View.GONE);
|
||||
} else {
|
||||
targetCard.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Controller extends HistoryCard.Controller
|
||||
{
|
||||
default void onToolbarChanged() {}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.uhabits.activities.habits.show
|
||||
|
||||
import android.content.*
|
||||
import android.view.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.habits.show.views.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.databinding.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class ShowHabitRootView
|
||||
@Inject constructor(
|
||||
@ActivityContext context: Context,
|
||||
private val habit: Habit,
|
||||
private val presenter: ShowHabitPresenter,
|
||||
) : BaseRootView(context), ShowHabitPresenter.Listener {
|
||||
|
||||
private var controller: Controller = object : Controller {}
|
||||
private var binding = ShowHabitBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
init {
|
||||
addView(binding.root)
|
||||
displayHomeAsUp = true
|
||||
|
||||
binding.subtitleCard.habit = habit
|
||||
binding.notesCard.habit = habit
|
||||
binding.overviewCard.habit = habit
|
||||
binding.scoreCard.habit = habit
|
||||
binding.historyCard.habit = habit
|
||||
binding.streakCard.habit = habit
|
||||
binding.frequencyCard.habit = habit
|
||||
binding.barCard.habit = habit
|
||||
binding.targetCard.habit = habit
|
||||
|
||||
initToolbar()
|
||||
}
|
||||
|
||||
override fun getToolbarColor(): Int {
|
||||
val res = StyledResources(context)
|
||||
return if (!res.getBoolean(R.attr.useHabitColorAsPrimary)) super.getToolbarColor()
|
||||
else habit.color.toThemedAndroidColor(context)
|
||||
}
|
||||
|
||||
fun setController(controller: Controller) {
|
||||
this.controller = controller
|
||||
binding.historyCard.setController(controller)
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
presenter.addListener(this)
|
||||
presenter.requestData(this)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
presenter.removeListener(this)
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
|
||||
override fun onData(data: ShowHabitViewModel) {
|
||||
binding.toolbar.title = data.title
|
||||
if (data.isNumerical) {
|
||||
binding.overviewCard.visibility = GONE
|
||||
binding.streakCard.visibility = GONE
|
||||
} else {
|
||||
binding.targetCard.visibility = GONE
|
||||
}
|
||||
controller.onToolbarChanged()
|
||||
}
|
||||
|
||||
interface Controller : HistoryCard.Controller {
|
||||
fun onToolbarChanged() {}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show
|
||||
|
||||
data class ShowHabitViewModel(
|
||||
val title: String,
|
||||
val isNumerical: Boolean,
|
||||
)
|
@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:background="?windowBackgroundColor"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true"
|
||||
tools:showIn="@layout/show_habit">
|
||||
|
||||
<LinearLayout
|
||||
style="@style/CardList"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.SubtitleCard
|
||||
android:id="@+id/subtitleCard"
|
||||
style="@style/ShowHabit.Subtitle"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.NotesCard
|
||||
android:id="@+id/notesCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center" />
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.OverviewCard
|
||||
android:id="@+id/overviewCard"
|
||||
style="@style/Card"
|
||||
android:paddingTop="12dp"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.TargetCard
|
||||
android:id="@+id/targetCard"
|
||||
style="@style/Card"
|
||||
android:paddingTop="12dp"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.ScoreCard
|
||||
android:id="@+id/scoreCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.BarCard
|
||||
android:id="@+id/barCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.HistoryCard
|
||||
android:id="@+id/historyCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="0dp"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.StreakCard
|
||||
android:id="@+id/streakCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
<org.isoron.uhabits.activities.habits.show.views.FrequencyCard
|
||||
android:id="@+id/frequencyCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
Loading…
Reference in new issue