mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Can make either the normal checkmark widget or stackview checkmark widget
This commit is contained in:
@@ -110,18 +110,7 @@
|
|||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_checkmark_info"/>
|
android:resource="@xml/widget_checkmark_info"/>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver
|
<service android:name=".widgets.CheckmarkStackWidgetService"
|
||||||
android:name=".widgets.StackWidgetProvider"
|
|
||||||
android:label="@string/stacked_checkmark">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.appwidget.provider"
|
|
||||||
android:resource="@xml/widget_checkmark_stack_info"/>
|
|
||||||
</receiver>
|
|
||||||
<service android:name=".widgets.StackWidgetService"
|
|
||||||
android:permission="android.permission.BIND_REMOTEVIEWS"
|
android:permission="android.permission.BIND_REMOTEVIEWS"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<receiver
|
<receiver
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import android.view.View
|
|||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import org.isoron.uhabits.R
|
import org.isoron.uhabits.R
|
||||||
|
|
||||||
class StackGroupWidget(
|
class CheckmarkStackWidget(
|
||||||
context: Context,
|
context: Context,
|
||||||
widgetId: Int,
|
widgetId: Int,
|
||||||
private val habitIds: List<Long>
|
private val habitIds: List<Long>
|
||||||
@@ -39,10 +39,10 @@ class StackGroupWidget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getRemoteViews(width: Int, height: Int): RemoteViews {
|
override fun getRemoteViews(width: Int, height: Int): RemoteViews {
|
||||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget_stackview)
|
val remoteViews = RemoteViews(context.packageName, R.layout.stackview_widget)
|
||||||
val serviceIntent = Intent(context, StackWidgetService::class.java)
|
val serviceIntent = Intent(context, CheckmarkStackWidgetService::class.java)
|
||||||
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
||||||
serviceIntent.putExtra(StackWidgetService.HABIT_IDS_SELECTED, habitIds.toLongArray())
|
serviceIntent.putExtra(CheckmarkStackWidgetService.HABIT_IDS_SELECTED, habitIds.toLongArray())
|
||||||
remoteViews.setRemoteAdapter(R.id.stackWidgetView, serviceIntent)
|
remoteViews.setRemoteAdapter(R.id.stackWidgetView, serviceIntent)
|
||||||
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(id, R.id.stackWidgetView)
|
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(id, R.id.stackWidgetView)
|
||||||
// TODO what should the empty view look like?
|
// TODO what should the empty view look like?
|
||||||
@@ -3,11 +3,11 @@ package org.isoron.uhabits.widgets
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import org.isoron.uhabits.HabitsApplication
|
import org.isoron.uhabits.HabitsApplication
|
||||||
|
|
||||||
class StackWidgetProvider : BaseWidgetProvider() {
|
class CheckmarkStackWidgetProvider : BaseWidgetProvider() {
|
||||||
|
|
||||||
override fun getWidgetFromId(context: Context, id: Int): StackGroupWidget {
|
override fun getWidgetFromId(context: Context, id: Int): CheckmarkStackWidget {
|
||||||
val habitIds = getHabitGroupFromWidget(context, id)
|
val habitIds = getHabitGroupFromWidget(context, id)
|
||||||
return StackGroupWidget(context, id, habitIds)
|
return CheckmarkStackWidget(context, id, habitIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getHabitGroupFromWidget(context: Context, widgetId: Int) : List<Long> {
|
private fun getHabitGroupFromWidget(context: Context, widgetId: Int) : List<Long> {
|
||||||
@@ -19,25 +19,25 @@ import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH;
|
|||||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
|
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
|
||||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH;
|
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH;
|
||||||
import static org.isoron.androidbase.utils.InterfaceUtils.dpToPixels;
|
import static org.isoron.androidbase.utils.InterfaceUtils.dpToPixels;
|
||||||
import static org.isoron.uhabits.widgets.StackWidgetService.HABIT_IDS_SELECTED;
|
import static org.isoron.uhabits.widgets.CheckmarkStackWidgetService.HABIT_IDS_SELECTED;
|
||||||
|
|
||||||
public class StackWidgetService extends RemoteViewsService {
|
public class CheckmarkStackWidgetService extends RemoteViewsService {
|
||||||
|
|
||||||
public static final String HABIT_IDS_SELECTED = "HABIT_IDS_SELECTED";
|
public static final String HABIT_IDS_SELECTED = "HABIT_IDS_SELECTED";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
||||||
return new StackRemoteViewsFactory(this.getApplicationContext(), intent);
|
return new CheckmarkStackRemoteViewsFactory(this.getApplicationContext(), intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
|
class CheckmarkStackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private int mAppWidgetId;
|
private int mAppWidgetId;
|
||||||
private ArrayList<Habit> mHabitList;
|
private ArrayList<Habit> mHabitList;
|
||||||
private List<Long> mHabitsSelected;
|
private List<Long> mHabitsSelected;
|
||||||
|
|
||||||
public StackRemoteViewsFactory(Context context, Intent intent) {
|
public CheckmarkStackRemoteViewsFactory(Context context, Intent intent) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||||
mHabitsSelected = new ArrayList<>();
|
mHabitsSelected = new ArrayList<>();
|
||||||
@@ -19,10 +19,23 @@
|
|||||||
package org.isoron.uhabits.widgets
|
package org.isoron.uhabits.widgets
|
||||||
|
|
||||||
import android.content.*
|
import android.content.*
|
||||||
|
import org.isoron.uhabits.HabitsApplication
|
||||||
|
|
||||||
class CheckmarkWidgetProvider : BaseWidgetProvider() {
|
class CheckmarkWidgetProvider : BaseWidgetProvider() {
|
||||||
override fun getWidgetFromId(context: Context, id: Int): CheckmarkWidget {
|
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||||
val habit = getHabitFromWidgetId(id)
|
try {
|
||||||
return CheckmarkWidget(context, id, habit)
|
val habit = getHabitFromWidgetId(id)
|
||||||
|
return CheckmarkWidget(context, id, habit)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val habitIds = getHabitIdsGroupFromWidget(context, id)
|
||||||
|
return CheckmarkStackWidget(context, id, habitIds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getHabitIdsGroupFromWidget(context: Context, widgetId: Int) : List<Long> {
|
||||||
|
val app = context.getApplicationContext() as HabitsApplication
|
||||||
|
val widgetPrefs = app.component.widgetPreferences
|
||||||
|
val habitIds = widgetPrefs.getHabitIdsGroupFromWidgetId(widgetId)
|
||||||
|
return habitIds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,14 @@ class HabitGroupPickerDialog : Activity(), AdapterView.OnItemClickListener {
|
|||||||
}
|
}
|
||||||
with(findViewById(R.id.doneConfigureButton) as Button) {
|
with(findViewById(R.id.doneConfigureButton) as Button) {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (!habitIdsSelected.isEmpty()) {
|
if (habitIdsSelected.size == 1) {
|
||||||
|
preferences.addWidget(widgetId, habitIdsSelected.first())
|
||||||
|
widgetUpdater.updateWidgets()
|
||||||
|
setResult(Activity.RESULT_OK, Intent().apply {
|
||||||
|
putExtra(EXTRA_APPWIDGET_ID, widgetId)
|
||||||
|
})
|
||||||
|
finish()
|
||||||
|
} else if (!habitIdsSelected.isEmpty()) {
|
||||||
preferences.addWidget(widgetId, habitIdsSelected.toString())
|
preferences.addWidget(widgetId, habitIdsSelected.toString())
|
||||||
widgetUpdater.updateWidgets()
|
widgetUpdater.updateWidgets()
|
||||||
setResult(Activity.RESULT_OK, Intent().apply {
|
setResult(Activity.RESULT_OK, Intent().apply {
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class WidgetUpdater
|
|||||||
fun updateWidgets() {
|
fun updateWidgets() {
|
||||||
taskRunner.execute {
|
taskRunner.execute {
|
||||||
updateWidgets(CheckmarkWidgetProvider::class.java)
|
updateWidgets(CheckmarkWidgetProvider::class.java)
|
||||||
updateWidgets(StackWidgetProvider::class.java)
|
|
||||||
updateWidgets(HistoryWidgetProvider::class.java)
|
updateWidgets(HistoryWidgetProvider::class.java)
|
||||||
updateWidgets(ScoreWidgetProvider::class.java)
|
updateWidgets(ScoreWidgetProvider::class.java)
|
||||||
updateWidgets(StreakWidgetProvider::class.java)
|
updateWidgets(StreakWidgetProvider::class.java)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
android:id="@+id/stackWidgetEmptyView"
|
android:id="@+id/stackWidgetEmptyView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:text="@string/stacked_checkmark"
|
android:text="@string/checkmark_stack_widget"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="#ffffff"
|
android:textColor="#ffffff"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
@@ -125,7 +125,7 @@
|
|||||||
<string name="version_n">Version %s</string>
|
<string name="version_n">Version %s</string>
|
||||||
<string name="frequency">Frequency</string>
|
<string name="frequency">Frequency</string>
|
||||||
<string name="checkmark">Checkmark</string>
|
<string name="checkmark">Checkmark</string>
|
||||||
<string name="stacked_checkmark">Stacked Checkmark</string>
|
<string name="checkmark_stack_widget">Checkmark Stack Widget</string>
|
||||||
|
|
||||||
<string name="strength">Strength</string>
|
<string name="strength">Strength</string>
|
||||||
<string name="best_streaks">Best streaks</string>
|
<string name="best_streaks">Best streaks</string>
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
android:previewImage="@drawable/widget_preview_checkmark"
|
android:previewImage="@drawable/widget_preview_checkmark"
|
||||||
android:resizeMode="none"
|
android:resizeMode="none"
|
||||||
android:updatePeriodMillis="3600000"
|
android:updatePeriodMillis="3600000"
|
||||||
android:configure="org.isoron.uhabits.widgets.HabitPickerDialog"
|
android:configure="org.isoron.uhabits.widgets.HabitGroupPickerDialog"
|
||||||
android:widgetCategory="home_screen">
|
android:widgetCategory="home_screen">
|
||||||
|
|
||||||
|
|
||||||
</appwidget-provider>
|
</appwidget-provider>
|
||||||
@@ -1,33 +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/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- TODO need to change preview image here -->
|
|
||||||
|
|
||||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:minHeight="40dp"
|
|
||||||
android:minWidth="40dp"
|
|
||||||
android:initialLayout="@layout/widget_wrapper"
|
|
||||||
android:previewImage="@drawable/widget_preview_checkmark"
|
|
||||||
android:resizeMode="none"
|
|
||||||
android:updatePeriodMillis="3600000"
|
|
||||||
android:configure="org.isoron.uhabits.widgets.HabitGroupPickerDialog"
|
|
||||||
android:widgetCategory="home_screen">
|
|
||||||
|
|
||||||
</appwidget-provider>
|
|
||||||
Reference in New Issue
Block a user