Skip to content

Commit

Permalink
Convert widget providers to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Jul 21, 2017
1 parent efcb571 commit c7aaa98
Show file tree
Hide file tree
Showing 23 changed files with 514 additions and 801 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void setUp()
setTheme(R.style.TransparentWidgetTheme);

habit = fixtures.createLongHabit();
ScoreWidget widget = new ScoreWidget(targetContext, 0, habit);
ScoreWidget widget = new ScoreWidget(targetContext, 0, habit, prefs);
view = convertToView(widget, 400, 400);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <[email protected]>
*
* 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.widgets

import android.content.*
import android.view.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.widgets.views.*

class CheckmarkWidget(
context: Context,
widgetId: Int,
private val habit: Habit
) : BaseWidget(context, widgetId) {

override fun getOnClickPendingIntent(context: Context) =
pendingIntentFactory.toggleCheckmark(habit, null)

override fun refreshData(v: View) {
(v as CheckmarkWidgetView).apply {
setPercentage(habit.scores.todayValue.toFloat())
setActiveColor(PaletteUtils.getColor(context, habit.color))
setName(habit.name)
setCheckmarkValue(habit.checkmarks.todayValue)
refresh()
}
}

override fun buildView() = CheckmarkWidgetView(context)
override fun getDefaultHeight() = 125
override fun getDefaultWidth() = 125
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@
* 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.widgets;
package org.isoron.uhabits.widgets

import android.content.*;
import android.support.annotation.*;
import android.content.*

import org.isoron.uhabits.core.models.*;

public class StreakWidgetProvider extends BaseWidgetProvider
{
@NonNull
@Override
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
{
Habit habit = getHabitFromWidgetId(id);
return new StreakWidget(context, id, habit);
class CheckmarkWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): CheckmarkWidget {
val habit = getHabitFromWidgetId(id)
return CheckmarkWidget(context, id, habit)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <[email protected]>
*
* 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.widgets

import android.content.*
import android.view.*
import org.isoron.uhabits.activities.common.views.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.widgets.views.*

class FrequencyWidget(
context: Context,
widgetId: Int,
private val habit: Habit
) : BaseWidget(context, widgetId) {

override fun getOnClickPendingIntent(context: Context) =
pendingIntentFactory.showHabit(habit)

override fun refreshData(v: View) {
val widgetView = v as GraphWidgetView
widgetView.setTitle(habit.name)
(widgetView.dataView as FrequencyChart).apply {
setColor(PaletteUtils.getColor(context, habit.color))
setFrequency(habit.repetitions.weekdayFrequency)
}
}

override fun buildView() =
GraphWidgetView(context, FrequencyChart(context))

override fun getDefaultHeight() = 200
override fun getDefaultWidth() = 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@
* 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.widgets;

import android.content.*;
import android.support.annotation.*;
package org.isoron.uhabits.widgets

import org.isoron.uhabits.core.models.*;
import android.content.*

public class ScoreWidgetProvider extends BaseWidgetProvider
{
@NonNull
@Override
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
{
Habit habit = getHabitFromWidgetId(id);
return new ScoreWidget(context, id, habit);
class FrequencyWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habit = getHabitFromWidgetId(id)
return FrequencyWidget(context, id, habit)
}
}
Loading

0 comments on commit c7aaa98

Please sign in to comment.