Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
Notes
Commits
6cbbab72
Commit
6cbbab72
authored
Mar 07, 2021
by
Stefan Niedermann
Committed by
Niedermann IT-Dienstleistungen
Mar 07, 2021
Browse files
Prepare first entry of list widget to be scrollable
parent
71f4b5da
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java
View file @
6cbbab72
package
it.niedermann.owncloud.notes.widget.notelist
;
import
android.app.PendingIntent
;
import
android.appwidget.AppWidgetManager
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -9,15 +10,18 @@ import android.util.Log;
import
android.widget.RemoteViews
;
import
android.widget.RemoteViewsService
;
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.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
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
;
...
...
@@ -27,8 +31,8 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
private
final
Context
context
;
private
final
NoteListsWidgetData
data
;
private
NotesDatabase
db
;
private
List
<
DBNote
>
dbNotes
;
private
final
NotesDatabase
db
;
private
final
List
<
DBNote
>
dbNotes
=
new
ArrayList
<>()
;
NoteListWidgetFactory
(
Context
context
,
Intent
intent
)
{
this
.
context
=
context
;
...
...
@@ -45,18 +49,19 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
@Override
public
void
onDataSetChanged
()
{
dbNotes
.
clear
();
try
{
Log
.
v
(
TAG
,
"--- data - "
+
data
);
switch
(
data
.
getMode
())
{
case
MODE_DISPLAY_ALL:
dbNotes
=
db
.
getNotes
(
data
.
getAccountId
());
dbNotes
.
addAll
(
db
.
getNotes
(
data
.
getAccountId
())
)
;
break
;
case
MODE_DISPLAY_STARRED:
dbNotes
=
db
.
searchNotes
(
data
.
getAccountId
(),
null
,
null
,
true
);
dbNotes
.
addAll
(
db
.
searchNotes
(
data
.
getAccountId
(),
null
,
null
,
true
)
)
;
break
;
case
MODE_DISPLAY_CATEGORY:
if
(
data
.
getCategoryId
()
!=
null
)
{
dbNotes
=
db
.
searchNotes
(
data
.
getAccountId
(),
null
,
db
.
getCategoryTitleById
(
data
.
getAccountId
(),
data
.
getCategoryId
()),
null
);
dbNotes
.
addAll
(
db
.
searchNotes
(
data
.
getAccountId
(),
null
,
db
.
getCategoryTitleById
(
data
.
getAccountId
(),
data
.
getCategoryId
()),
null
)
)
;
}
break
;
}
...
...
@@ -77,37 +82,50 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
*/
@Override
public
int
getCount
()
{
if
(
dbNotes
==
null
)
{
return
0
;
}
return
dbNotes
.
size
();
}
@Override
public
RemoteViews
getViewAt
(
int
position
)
{
RemoteViews
note_content
;
if
(
dbNotes
==
null
||
position
>
dbNotes
.
size
()
-
1
||
dbNotes
.
get
(
position
)
==
null
)
{
Log
.
e
(
TAG
,
"Could not find position \""
+
position
+
"\" in dbNotes list."
);
return
null
;
}
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
>
dbNotes
.
size
()
-
1
||
dbNotes
.
get
(
position
)
==
null
)
{
Log
.
e
(
TAG
,
"Could not find position \""
+
position
+
"\" in dbNotes list."
);
return
null
;
}
DBNote
note
=
dbNotes
.
get
(
position
);
final
Intent
fillInIntent
=
new
Intent
();
final
Bundle
extras
=
new
Bundle
();
extras
.
putLong
(
EditNoteActivity
.
PARAM_NOTE_ID
,
note
.
getId
());
extras
.
putLong
(
EditNoteActivity
.
PARAM_ACCOUNT_ID
,
note
.
getAccountId
());
fillInIntent
.
putExtras
(
extras
);
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
,
note
.
getTitle
());
note_content
.
setImageViewResource
(
R
.
id
.
widget_entry_fav_icon
,
note
.
isFavorite
()
?
R
.
drawable
.
ic_star_yellow_24dp
:
R
.
drawable
.
ic_star_grey_ccc_24dp
);
DBNote
note
=
dbNotes
.
get
(
position
);
final
Intent
fillInIntent
=
new
Intent
();
final
Bundle
extras
=
new
Bundle
();
extras
.
putLong
(
EditNoteActivity
.
PARAM_NOTE_ID
,
note
.
getId
());
extras
.
putLong
(
EditNoteActivity
.
PARAM_ACCOUNT_ID
,
note
.
getAccountId
());
fillInIntent
.
putExtras
(
extras
);
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
,
note
.
getTitle
());
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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment