Commit cfd0902a authored by Stefan Niedermann's avatar Stefan Niedermann Committed by Niedermann IT-Dienstleistungen
Browse files

NoteListWidget: Move create button to scrollable entry, remove header

parent 6cbbab72
......@@ -20,9 +20,9 @@ Please use **[GitHub reactions](https://blog.github.com/2016-03-10-add-reactions
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
1. Go to ''
2. Click on ''
3. Scroll down to ''
4. See error
......
......@@ -13,7 +13,7 @@ Guidelines for submitting issues:
Please use **[GitHub reactions](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)** 👍 to show that you are affected by the same issue. Please don't comment if you have no relevant information to add!
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [] -->
**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
......
......@@ -8,7 +8,7 @@ If you find a bug, feel free to [open an issue](https://github.com/stefan-nieder
**Device**: e. g. Motorola Moto G 2015
**System language**: English (US), German, ...
**System language**: English (US), German,
**App version:** e. g. v0.8.1
......@@ -18,14 +18,14 @@ If you find a bug, feel free to [open an issue](https://github.com/stefan-nieder
1. open the app
2. click on a note
3. use the top left back-arrow
4. ...
4.
### Copy & Paste
**Android version:** e. g. 6.0.1 Marshmallow
**Device**: e. g. Motorola Moto G 2015
**System language**: English (US), German, ...
**System language**: English (US), German,
**App version:** e. g. v0.8.1
......@@ -35,7 +35,7 @@ If you find a bug, feel free to [open an issue](https://github.com/stefan-nieder
1. open the app
2. click on a note
3. use the top left back-arrow
4. ...
4.
## Adding new features
......
......@@ -6,29 +6,15 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
import androidx.core.content.ContextCompat;
import java.util.NoSuchElementException;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.preferences.DarkModeSetting;
import it.niedermann.owncloud.notes.edit.EditNoteActivity;
import it.niedermann.owncloud.notes.main.MainActivity;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.shared.model.Category;
import it.niedermann.owncloud.notes.shared.model.LocalAccount;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.NotesApplication;
import static it.niedermann.owncloud.notes.edit.EditNoteActivity.PARAM_CATEGORY;
import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL;
import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_CATEGORY;
import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_STARRED;
public class NoteListWidget extends AppWidgetProvider {
private static final String TAG = NoteListWidget.class.getSimpleName();
......@@ -41,39 +27,15 @@ public class NoteListWidget extends AppWidgetProvider {
final NotesDatabase db = NotesDatabase.getInstance(context);
RemoteViews views;
DarkModeSetting darkTheme;
for (int appWidgetId : appWidgetIds) {
try {
final NoteListsWidgetData data = db.getNoteListWidgetData(appWidgetId);
final LocalAccount localAccount = db.getAccount(data.getAccountId());
String category = null;
if (data.getCategoryId() != null) {
category = db.getCategoryTitleById(data.getAccountId(), data.getCategoryId());
}
darkTheme = DarkModeSetting.fromModeID(data.getThemeMode());
Intent serviceIntent = new Intent(context, NoteListWidgetService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
// Launch application when user taps the header icon or app title
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(context.getPackageName(),
MainActivity.class.getName()));
// Open the main app if the user taps the widget header
PendingIntent openAppI = PendingIntent.getActivity(context, PENDING_INTENT_OPEN_APP_RQ,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Launch create note activity if user taps "+" icon on header
PendingIntent newNoteI = PendingIntent.getActivity(context, (PENDING_INTENT_NEW_NOTE_RQ + appWidgetId),
new Intent(context, EditNoteActivity.class).putExtra(PARAM_CATEGORY, new Category(category, data.getMode() == MODE_DISPLAY_STARRED)),
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent templatePI = PendingIntent.getActivity(context, PENDING_INTENT_EDIT_NOTE_RQ,
new Intent(context, EditNoteActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
......@@ -81,26 +43,11 @@ public class NoteListWidget extends AppWidgetProvider {
Log.v(TAG, "-- data - " + data);
views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list);
views.setTextViewText(R.id.widget_note_list_title_tv, getWidgetTitle(context, data.getMode(), category));
views.setOnClickPendingIntent(R.id.widget_note_header_icon, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_title_tv, openAppI);
views.setOnClickPendingIntent(R.id.widget_note_list_create_icon, newNoteI);
views.setPendingIntentTemplate(R.id.note_list_widget_lv, templatePI);
views.setRemoteAdapter(R.id.note_list_widget_lv, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_note_list_placeholder_tv);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv, localAccount.getTextColor());
} else {
views.setInt(R.id.widget_note_header, "setBackgroundColor", ContextCompat.getColor(context, R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv, Color.WHITE);
}
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv);
awm.updateAppWidget(appWidgetId, views);
} catch (NoSuchElementException e) {
Log.i(TAG, "onUpdate has been triggered before the user finished configuring the widget");
......@@ -146,23 +93,6 @@ public class NoteListWidget extends AppWidgetProvider {
}
}
private static String getWidgetTitle(Context context, int displayMode, String category) {
switch (displayMode) {
case MODE_DISPLAY_ALL:
return context.getString(R.string.app_name);
case MODE_DISPLAY_STARRED:
return context.getString(R.string.label_favorites);
case MODE_DISPLAY_CATEGORY:
if ("".equals(category)) {
return context.getString(R.string.action_uncategorized);
} else {
return category;
}
default:
return null;
}
}
/**
* Update note list widgets, if the note data was changed.
*/
......
package it.niedermann.owncloud.notes.widget.notelist;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
......@@ -10,16 +9,17 @@ import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.preferences.DarkModeSetting;
import it.niedermann.owncloud.notes.edit.EditNoteActivity;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.shared.model.Category;
import it.niedermann.owncloud.notes.shared.model.DBNote;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.shared.model.LocalAccount;
import static it.niedermann.owncloud.notes.edit.EditNoteActivity.PARAM_CATEGORY;
import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL;
......@@ -45,6 +45,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
@Override
public void onCreate() {
// Nothing to do here…
}
@Override
......@@ -82,29 +83,37 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
*/
@Override
public int getCount() {
return dbNotes.size();
return dbNotes.size() + 1;
}
@Override
public RemoteViews getViewAt(int position) {
final RemoteViews note_content;
// if(position == 0) {
// final Intent fillInIntent = new Intent();
// final Bundle extras = new Bundle();
// extras.putExtra(PARAM_CATEGORY, new Category(db.getCategoryTitleById(data.getAccountId(), data.getCategoryId()), data.getMode() == MODE_DISPLAY_STARRED)),
// extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId());
//
// fillInIntent.putExtras(extras);
// fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME)));
//
// fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME)));
//
// note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry);
// note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent);
// note_content.setTextViewText(R.id.widget_entry_content_tv, "Add new note in this category");
// note_content.setImageViewResource(R.id.widget_entry_fav_icon, R.drawable.ic_add_blue_24dp);
// } else {
if (position == 0) {
final LocalAccount localAccount = db.getAccount(data.getAccountId());
final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();
String category = null;
Long categoryId = data.getCategoryId();
if (categoryId != null) {
category = db.getCategoryTitleById(data.getAccountId(), categoryId);
}
extras.putSerializable(PARAM_CATEGORY, new Category(category, data.getMode() == MODE_DISPLAY_STARRED));
extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, data.getAccountId());
fillInIntent.putExtras(extras);
fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME)));
note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry_add);
note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent);
note_content.setTextViewText(R.id.widget_entry_content_tv, getAddButtonText(context, data.getMode(), category));
note_content.setImageViewResource(R.id.widget_entry_fav_icon, R.drawable.ic_add_blue_24dp);
note_content.setInt(R.id.widget_entry_fav_icon, "setColorFilter", localAccount.getColor());
} else {
position--;
if (position > dbNotes.size() - 1 || dbNotes.get(position) == null) {
Log.e(TAG, "Could not find position \"" + position + "\" in dbNotes list.");
return null;
......@@ -125,12 +134,29 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.isFavorite()
? R.drawable.ic_star_yellow_24dp
: R.drawable.ic_star_grey_ccc_24dp);
// }
}
return note_content;
}
@NonNull
private static String getAddButtonText(@NonNull Context context, int displayMode, String category) {
switch (displayMode) {
case MODE_DISPLAY_STARRED:
return context.getString(R.string.widget_note_list_add_favorite);
case MODE_DISPLAY_CATEGORY:
if ("".equals(category)) {
return context.getString(R.string.widget_note_list_add);
} else {
return context.getString(R.string.widget_note_list_add_to_category, category);
}
case MODE_DISPLAY_ALL:
default:
return context.getString(R.string.widget_note_list_add);
}
}
@Override
public RemoteViews getLoadingView() {
return null;
......@@ -138,12 +164,22 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
@Override
public int getViewTypeCount() {
return 1;
return 2;
}
@Override
public long getItemId(int i) {
return i;
public long getItemId(int position) {
if (position == 0) {
return -1;
} else {
position--;
if (position > dbNotes.size() - 1 || dbNotes.get(position) == null) {
Log.e(TAG, "Could not find position \"" + position + "\" in dbNotes list.");
return -2;
}
DBNote note = dbNotes.get(position);
return note.getId();
}
}
@Override
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_note_list_entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="@dimen/spacer_1hx"
android:paddingTop="@dimen/spacer_1x"
android:paddingEnd="@dimen/spacer_1hx"
android:paddingBottom="@dimen/spacer_1x">
<ImageView
android:id="@+id/widget_entry_fav_icon"
android:layout_width="@dimen/widget_note_list_fav_icon_width"
android:layout_height="@dimen/widget_note_list_fav_icon_height"
android:layout_gravity="center_vertical"
android:contentDescription="@string/widget_entry_fav_contentDescription"
android:foregroundGravity="center_vertical"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
app:srcCompat="@drawable/ic_add_blue_24dp" />
<TextView
android:id="@+id/widget_entry_content_tv"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="middle"
android:singleLine="true"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:textColor="@color/widget_foreground"
tools:text="@string/widget_note_list_add" />
</LinearLayout>
......@@ -6,55 +6,6 @@
android:background="@drawable/widget_background"
android:orientation="vertical">
<!-- Widget header -->
<RelativeLayout
android:id="@+id/widget_note_header"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_note_list_header_height"
android:background="@color/defaultBrand"
android:padding="@dimen/widget_note_list_hdr_padding">
<ImageView
android:id="@+id/widget_note_header_icon"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:contentDescription="@string/widget_app_launcher_contentDescription"
android:paddingStart="@dimen/widget_note_list_outer_padding"
android:paddingEnd="@dimen/widget_note_list_inner_padding"
android:scaleX="2"
android:scaleY="2"
android:src="@drawable/ic_launcher_foreground" />
<TextView
android:id="@+id/widget_note_list_title_tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toStartOf="@id/widget_note_list_create_icon"
android:layout_toEndOf="@id/widget_note_header_icon"
android:ellipsize="middle"
android:gravity="center_vertical"
android:paddingStart="@dimen/widget_note_list_hdr_padding"
android:paddingEnd="@dimen/widget_note_list_hdr_padding"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="18sp"
tools:text="@tools:sample/lorem/random" />
<ImageView
android:id="@+id/widget_note_list_create_icon"
android:layout_width="@dimen/widget_note_list_icon_width"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:contentDescription="@string/widget_create_note"
android:paddingStart="@dimen/widget_note_list_inner_padding"
android:paddingEnd="@dimen/widget_note_list_outer_padding"
android:src="@drawable/ic_add_white_24dp" />
</RelativeLayout>
<!-- End header -->
<ListView
android:id="@+id/note_list_widget_lv"
android:layout_width="match_parent"
......
......@@ -23,4 +23,5 @@
<color name="widget_background">#dd000000</color>
<color name="widget_foreground">#d8d8d8</color>
<color name="widget_foreground_strong">#f5f5f5</color>
</resources>
\ No newline at end of file
......@@ -29,4 +29,5 @@
<color name="widget_background">#ddffffff</color>
<color name="widget_foreground">#222222</color>
<color name="widget_foreground_strong">#121212</color>
</resources>
......@@ -82,6 +82,9 @@
<string name="about_license_tab_title">License</string>
<string name="widget_note_list_title">Note list</string>
<string name="widget_note_list_add">Add new note</string>
<string name="widget_note_list_add_favorite">Add new note to favorites</string>
<string name="widget_note_list_add_to_category">Add new note to %1$s</string>
<string name="widget_note_list_placeholder">No notes</string>
<string name="widget_single_note_title">Single note</string>
<string name="widget_single_note_placeholder_tv">Note not found</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment