Show error message on widget when habit not found

Fixes #35
pull/69/head
Alinson S. Xavier 10 years ago
parent 7778c5fb21
commit 851cae3662

@ -25,7 +25,6 @@ import android.appwidget.AppWidgetProvider;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.media.Image;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -33,7 +32,6 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.isoron.helpers.DialogHelper; import org.isoron.helpers.DialogHelper;
@ -106,6 +104,14 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
if(habitId < 0) return; if(habitId < 0) return;
Habit habit = Habit.get(habitId); Habit habit = Habit.get(habitId);
if(habit == null)
{
RemoteViews errorView = new RemoteViews(context.getPackageName(),
R.layout.widget_error);
manager.updateAppWidget(widgetId, errorView);
return;
}
View widgetView = buildCustomView(context, habit); View widgetView = buildCustomView(context, habit);
measureCustomView(context, width, height, widgetView); measureCustomView(context, width, height, widgetView);

@ -0,0 +1,41 @@
<?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/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/widget_background"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="4dp"
android:paddingBottom="0dp"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Habit not found"
android:textColor="#ffffff"/>
</LinearLayout>
Loading…
Cancel
Save