Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import it.niedermann.owncloud.notes.branding.BrandedActivity
import it.niedermann.owncloud.notes.branding.BrandedFragment
import it.niedermann.owncloud.notes.branding.BrandingUtil
import it.niedermann.owncloud.notes.databinding.ActivityItemDetailsBinding
import it.niedermann.owncloud.notes.persistence.NotesRepository
import it.niedermann.owncloud.notes.persistence.entity.Account
import it.niedermann.owncloud.notes.persistence.entity.Note
import it.niedermann.owncloud.notes.share.NoteShareFragment
Expand All @@ -31,19 +32,23 @@ class ItemDetailsActivity : BrandedActivity() {
lateinit var note: Note
lateinit var account: Account
lateinit var page: PAGE
lateinit var repo: NotesRepository

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

parseArguments()

repo = NotesRepository.getInstance(this)

binding = ActivityItemDetailsBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.toolbar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }

loadHeaderData()
loadFragments()
setHeaderListeners()
}

@Suppress("ThrowsCount")
Expand All @@ -57,11 +62,8 @@ class ItemDetailsActivity : BrandedActivity() {
}

private fun loadHeaderData() {
updateFavoriteIcon()
binding.filename.text = note.title
binding.favorite.setImageResource(
if (note.favorite) R.drawable.ic_star_yellow_24dp
else R.drawable.ic_star_border_grey_ccc_24dp
)
binding.lastModificationTimestamp.text = note.modified?.let {
DateUtils.formatDateTime(
this,
Expand All @@ -71,6 +73,21 @@ class ItemDetailsActivity : BrandedActivity() {
}
}

private fun setHeaderListeners() {
binding.favorite.setOnClickListener {
repo.toggleFavorite(account, note.id)
note.favorite = !note.favorite
updateFavoriteIcon()
}
}

private fun updateFavoriteIcon() {
binding.favorite.setImageResource(
if (note.favorite) R.drawable.ic_star_yellow_24dp
else R.drawable.ic_star_border_grey_ccc_24dp
)
}

private fun loadFragments() {
val pages = listOf(
PageTab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ public Map<Long, Long> getIdMap(long accountId) {
.collect(toMap(Note::getRemoteId, Note::getId));
}

/**
* @deprecated Use {@link #toggleFavorite(Account, long)} instead
*/
@Deprecated
@AnyThread
public void toggleFavoriteAndSync(Account account, Note note) {
executor.submit(() -> {
Expand All @@ -576,6 +580,21 @@ public void toggleFavoriteAndSync(Account account, Note note) {
});
}

/**
* Toggles the favorite for a given note.
*
* @param account The single sign on account
* @param noteId The note which will be updated
*/
@AnyThread
public void toggleFavorite(@NonNull Account account, long noteId) {
executor.submit(() -> {
db.getNoteDao().updateStatus(noteId, DBStatus.LOCAL_EDITED);
db.getNoteDao().toggleFavorite(noteId);
scheduleSync(account, true);
});
}

/**
* Set the category for a given note.
* This method will search in the database to find out the category id in the db.
Expand Down
Loading