mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
set todo list widget title, if tapped - open app, show unchecked todo icon
This commit is contained in:
parent
a084d776e9
commit
4356bbd63a
10 changed files with 112 additions and 41 deletions
|
|
@ -1,35 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dailies_list_row"
|
||||
android:id="@+id/widget_list_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
<FrameLayout
|
||||
android:id="@+id/checkbox_background"
|
||||
android:layout_width="@dimen/button_compact_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/checkbox_compact_size"
|
||||
android:layout_height="@dimen/checkbox_compact_size"
|
||||
android:src="@drawable/daily_unchecked"
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:paddingLeft="@dimen/task_text_padding"
|
||||
android:paddingStart="@dimen/task_text_padding"
|
||||
android:paddingRight="@dimen/task_text_padding"
|
||||
android:paddingEnd="@dimen/task_text_padding"
|
||||
android:paddingBottom="@dimen/task_top_bottom_compact_padding"
|
||||
android:paddingTop="@dimen/task_top_bottom_compact_padding"
|
||||
android:id="@+id/dailies_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/primary_text_light" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/checkbox_background"
|
||||
android:layout_width="@dimen/button_compact_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/checkbox_compact_size"
|
||||
android:layout_height="@dimen/checkbox_compact_size"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/daily_unchecked" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dailies_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/task_top_bottom_compact_padding"
|
||||
android:paddingEnd="@dimen/task_text_padding"
|
||||
android:paddingLeft="@dimen/task_text_padding"
|
||||
android:paddingRight="@dimen/task_text_padding"
|
||||
android:paddingStart="@dimen/task_text_padding"
|
||||
android:paddingTop="@dimen/task_top_bottom_compact_padding"
|
||||
android:textColor="@color/primary_text_light" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dailies"
|
||||
android:background="@drawable/rounded_purple_square"
|
||||
android:padding="4dp"
|
||||
android:textSize="18sp"
|
||||
android:id="@+id/widget_title"
|
||||
android:textColor="@android:color/white"/>
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
42
Habitica/res/layout/widget_todo_list_row.xml
Normal file
42
Habitica/res/layout/widget_todo_list_row.xml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_list_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/checkbox_background"
|
||||
android:layout_width="@dimen/button_compact_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/checkbox_compact_size"
|
||||
android:layout_height="@dimen/checkbox_compact_size"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/todo_unchecked" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dailies_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/task_top_bottom_compact_padding"
|
||||
android:paddingEnd="@dimen/task_text_padding"
|
||||
android:paddingLeft="@dimen/task_text_padding"
|
||||
android:paddingRight="@dimen/task_text_padding"
|
||||
android:paddingStart="@dimen/task_text_padding"
|
||||
android:paddingTop="@dimen/task_top_bottom_compact_padding"
|
||||
android:textColor="@color/primary_text_light" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/selection_highlight" />
|
||||
</FrameLayout>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:initialLayout="@layout/widget_dailies"
|
||||
android:initialLayout="@layout/widget_task_list"
|
||||
android:minHeight="120dp"
|
||||
android:minWidth="120dp"
|
||||
android:updatePeriodMillis="1800000"
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ package com.habitrpg.android.habitica.widget;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
|
||||
public class DailiesListFactory extends TaskListFactory {
|
||||
public DailiesListFactory(Context context, Intent intent) {
|
||||
super(context, intent, Task.TYPE_DAILY);
|
||||
super(context, intent, Task.TYPE_DAILY, R.layout.widget_dailies_list_row);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.habitrpg.android.habitica.widget;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
public class DailiesWidgetProvider extends TaskListWidgetProvider{
|
||||
|
||||
@Override
|
||||
|
|
@ -11,5 +13,10 @@ public class DailiesWidgetProvider extends TaskListWidgetProvider{
|
|||
protected Class getProviderClass() {
|
||||
return DailiesWidgetProvider.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTitleResId() {
|
||||
return R.string.dailies;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,14 +26,16 @@ import rx.schedulers.Schedulers;
|
|||
|
||||
public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsFactory {
|
||||
private final int widgetId;
|
||||
private int listItemResId;
|
||||
private String taskType;
|
||||
private List<Task> taskList = new ArrayList<>();
|
||||
private Context context = null;
|
||||
private boolean reloadData;
|
||||
|
||||
public TaskListFactory(Context context, Intent intent, String taskType) {
|
||||
public TaskListFactory(Context context, Intent intent, String taskType, int listItemResId) {
|
||||
this.context = context;
|
||||
this.widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
|
||||
this.listItemResId = listItemResId;
|
||||
this.reloadData = false;
|
||||
this.taskType = taskType;
|
||||
|
||||
|
|
@ -85,7 +87,7 @@ public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsF
|
|||
@Override
|
||||
public RemoteViews getViewAt(int position) {
|
||||
final RemoteViews remoteView = new RemoteViews(
|
||||
context.getPackageName(), R.layout.widget_dailies_list_row);
|
||||
context.getPackageName(), listItemResId);
|
||||
if (taskList.size() > position) {
|
||||
Task task = taskList.get(position);
|
||||
|
||||
|
|
@ -98,14 +100,14 @@ public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsF
|
|||
remoteView.setInt(R.id.checkbox_background, "setBackgroundResource", task.getLightTaskColor());
|
||||
Intent fillInIntent = new Intent();
|
||||
fillInIntent.putExtra(TaskListWidgetProvider.TASK_ID_ITEM, task.getId());
|
||||
remoteView.setOnClickFillInIntent(R.id.dailies_list_row, fillInIntent);
|
||||
remoteView.setOnClickFillInIntent(R.id.widget_list_row, fillInIntent);
|
||||
}
|
||||
return remoteView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteViews getLoadingView() {
|
||||
return new RemoteViews(context.getPackageName(), R.layout.widget_dailies_list_row);
|
||||
return new RemoteViews(context.getPackageName(), listItemResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.appwidget.AppWidgetManager;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -15,6 +14,7 @@ import com.habitrpg.android.habitica.APIHelper;
|
|||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
|
|
@ -40,6 +40,7 @@ public abstract class TaskListWidgetProvider extends BaseWidgetProvider {
|
|||
|
||||
protected abstract Class getServiceClass();
|
||||
protected abstract Class getProviderClass();
|
||||
protected abstract int getTitleResId();
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -86,9 +87,15 @@ public abstract class TaskListWidgetProvider extends BaseWidgetProvider {
|
|||
Intent intent = new Intent(context, getServiceClass());
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
|
||||
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
|
||||
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_dailies);
|
||||
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_task_list);
|
||||
rv.setRemoteAdapter(appWidgetIds[i], R.id.list_view, intent);
|
||||
rv.setEmptyView(R.id.list, R.id.empty_view);
|
||||
rv.setTextViewText(R.id.widget_title, context.getString(getTitleResId()));
|
||||
|
||||
// if the user click on the title: open App
|
||||
Intent openAppIntent = new Intent(context.getApplicationContext(), MainActivity.class);
|
||||
PendingIntent openApp = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
rv.setOnClickPendingIntent(R.id.widget_title, openApp);
|
||||
|
||||
Intent taskIntent = new Intent(context, getProviderClass());
|
||||
taskIntent.setAction(DAILY_ACTION);
|
||||
|
|
@ -108,7 +115,7 @@ public abstract class TaskListWidgetProvider extends BaseWidgetProvider {
|
|||
|
||||
@Override
|
||||
public int layoutResourceId() {
|
||||
return R.layout.widget_dailies;
|
||||
return R.layout.widget_task_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ package com.habitrpg.android.habitica.widget;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
public class TodoListFactory extends TaskListFactory {
|
||||
public TodoListFactory(Context context, Intent intent) {
|
||||
super(context, intent, Task.TYPE_TODO);
|
||||
super(context, intent, Task.TYPE_TODO, R.layout.widget_todo_list_row);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.habitrpg.android.habitica.widget;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
public class TodoListWidgetProvider extends TaskListWidgetProvider{
|
||||
|
||||
@Override
|
||||
|
|
@ -11,4 +13,9 @@ public class TodoListWidgetProvider extends TaskListWidgetProvider{
|
|||
protected Class getProviderClass() {
|
||||
return TodoListWidgetProvider.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTitleResId() {
|
||||
return R.string.todos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue