Add menu button to quickly change widget list

pull/996/head
Alex Baker 5 years ago
parent c318635caf
commit 2ca2c3a596

@ -151,6 +151,7 @@
<activity
android:exported="true"
android:name=".activities.FilterSelectionActivity"
android:taskAffinity=""
android:theme="@style/TranslucentDialog"/>
<activity

@ -75,4 +75,8 @@ public class LocalBroadcastManager {
public void broadcastPurchasesUpdated() {
localBroadcastManager.sendBroadcast(new Intent(REFRESH_PURCHASES));
}
public void reconfigureWidget(int appWidgetId) {
appWidgetManager.reconfigureWidget(appWidgetId);
}
}

@ -1,5 +1,6 @@
package org.tasks.activities;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -16,7 +17,11 @@ import org.tasks.LocalBroadcastManager;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.filters.FilterProvider;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.widget.WidgetPreferences;
public class FilterSelectionActivity extends InjectingAppCompatActivity {
@ -26,10 +31,13 @@ public class FilterSelectionActivity extends InjectingAppCompatActivity {
private static final String EXTRA_FILTER_SQL = "extra_filter_query";
private static final String EXTRA_FILTER_VALUES = "extra_filter_values";
@Inject @ForApplication Context context;
@Inject DialogBuilder dialogBuilder;
@Inject FilterAdapter filterAdapter;
@Inject FilterProvider filterProvider;
@Inject LocalBroadcastManager localBroadcastManager;
@Inject Preferences preferences;
@Inject DefaultFilterProvider defaultFilterProvider;
private CompositeDisposable disposables;
private Filter selected;
@ -46,6 +54,7 @@ public class FilterSelectionActivity extends InjectingAppCompatActivity {
Intent intent = getIntent();
boolean returnFilter = intent.getBooleanExtra(EXTRA_RETURN_FILTER, false);
int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
selected = intent.getParcelableExtra(EXTRA_FILTER);
if (savedInstanceState != null) {
@ -63,6 +72,11 @@ public class FilterSelectionActivity extends InjectingAppCompatActivity {
if (returnFilter) {
data.putExtra(EXTRA_FILTER, selectedFilter);
}
if (widgetId != -1) {
new WidgetPreferences(context, preferences, widgetId)
.setFilter(defaultFilterProvider.getFilterPreferenceValue(selectedFilter));
localBroadcastManager.reconfigureWidget(widgetId);
}
data.putExtra(EXTRA_FILTER_NAME, selectedFilter.listingTitle);
data.putExtra(EXTRA_FILTER_SQL, selectedFilter.getSqlQuery());
if (selectedFilter.valuesForNewTasks != null) {

@ -130,12 +130,7 @@ class ScrollableWidget : InjectingPreferenceFragment() {
override fun onPause() {
super.onPause()
localBroadcastManager.broadcastRefresh()
// force update after setting preferences
val intent = Intent(context, TasksWidget::class.java)
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(appWidgetId))
activity!!.sendBroadcast(intent)
localBroadcastManager.reconfigureWidget(appWidgetId)
}
private fun updateTheme() {

@ -2,6 +2,7 @@ package org.tasks.widget;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ForApplication;
@ -22,4 +23,12 @@ public class AppWidgetManager {
appWidgetManager.getAppWidgetIds(new ComponentName(context, TasksWidget.class));
appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.list_view);
}
public void reconfigureWidget(int appWidgetId) {
Intent intent = new Intent(context, TasksWidget.class);
intent.setAction(android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { appWidgetId });
context.sendBroadcast(intent);
updateWidgets();
}
}

@ -21,6 +21,7 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.injection.BroadcastComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingAppWidgetProvider;
@ -82,6 +83,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
remoteViews.setInt(R.id.widget_title, "setTextColor", color.getColorOnPrimary());
remoteViews.setInt(R.id.widget_button, "setColorFilter", color.getColorOnPrimary());
remoteViews.setInt(R.id.widget_reconfigure, "setColorFilter", color.getColorOnPrimary());
remoteViews.setInt(R.id.widget_change_list, "setColorFilter", color.getColorOnPrimary());
} else {
remoteViews.setViewVisibility(R.id.widget_header, View.GONE);
}
@ -101,6 +103,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
remoteViews.setEmptyView(R.id.list_view, R.id.empty_view);
remoteViews.setOnClickPendingIntent(R.id.widget_title, getOpenListIntent(context, filter, id));
remoteViews.setOnClickPendingIntent(R.id.widget_button, getNewTaskIntent(context, filter, id));
remoteViews.setOnClickPendingIntent(R.id.widget_change_list, getChooseListIntent(context, filter, id));
remoteViews.setOnClickPendingIntent(
R.id.widget_reconfigure, getWidgetConfigIntent(context, id));
remoteViews.setPendingIntentTemplate(R.id.list_view, getPendingIntentTemplate(context));
@ -128,7 +131,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
Intent intent = TaskIntents.getTaskListIntent(context, filter);
intent.setFlags(flags);
intent.setAction("open_list");
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
private PendingIntent getNewTaskIntent(Context context, Filter filter, int widgetId) {
@ -146,4 +149,13 @@ public class TasksWidget extends InjectingAppWidgetProvider {
intent.setAction("widget_settings");
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
private PendingIntent getChooseListIntent(Context context, Filter filter, int widgetId) {
Intent intent = new Intent(context, FilterSelectionActivity.class);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(FilterSelectionActivity.EXTRA_FILTER, filter);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
intent.setAction("choose_list");
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
}

@ -4,6 +4,7 @@
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
@ -12,14 +13,26 @@
<RelativeLayout
android:id="@+id/widget_header"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_height="48dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/widget_header_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"/>
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/widget_change_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:padding="@dimen/widget_padding"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_outline_menu_24px" />
<ImageButton
android:id="@+id/widget_button"
@ -27,12 +40,11 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingStart="@dimen/widget_padding"
android:paddingEnd="@dimen/widget_padding"
android:padding="@dimen/widget_padding"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_outline_add_24px"
android:tint="@android:color/white"/>
android:contentDescription="@string/action_create_new_task" />
<ImageButton
android:id="@+id/widget_reconfigure"
@ -40,27 +52,25 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/widget_button"
android:paddingStart="@dimen/widget_padding"
android:paddingEnd="0dp"
android:padding="@dimen/widget_padding"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_outline_settings_24px"
android:tint="@android:color/white"/>
android:contentDescription="@string/widget_settings" />
<TextView
android:id="@+id/widget_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/widget_change_list"
android:layout_toStartOf="@id/widget_reconfigure"
android:paddingStart="@dimen/widget_padding"
android:paddingEnd="0dp"
android:ellipsize="end"
tools:text="Today"
android:gravity="start|center_vertical"
android:maxLines="2"
android:textAlignment="viewStart"
android:textColor="@android:color/white"
android:textColor="@android:color/black"
android:textSize="18sp"/>
</RelativeLayout>
@ -73,7 +83,8 @@
android:id="@+id/widget_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"/>
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<ListView
android:id="@+id/list_view"

@ -22,7 +22,7 @@
<dimen name="elevation_refresh_indicator">3dp</dimen>
<dimen name="elevation_padding">0dp</dimen>
<dimen name="widget_padding">10dp</dimen>
<dimen name="widget_padding">12dp</dimen>
<dimen name="week_button_inset">6dp</dimen>
<dimen name="week_button_state_on_circle_size">48dp</dimen>

Loading…
Cancel
Save