Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge feature: pinning note into v2.1.0 #558

Merged
merged 32 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b0cbaf2
Feature: Add pin to Notes
Varsha-Kulkarni Oct 4, 2022
c28a79e
Feature: add tests to pinning the Notes
Varsha-Kulkarni Oct 4, 2022
b5f124f
Feature: update tests to pinning the Notes
Varsha-Kulkarni Oct 4, 2022
3da88c6
Update noty-android/app/simpleapp/src/main/java/dev/shreyaspatil/noty…
Varsha-Kulkarni Oct 5, 2022
c9d523d
Update noty-android/app/simpleapp/src/main/java/dev/shreyaspatil/noty…
Varsha-Kulkarni Oct 5, 2022
c81f3f5
Update noty-android/core/src/main/java/dev/shreyaspatil/noty/core/rep…
Varsha-Kulkarni Oct 5, 2022
a89d1f5
Update sources to incorporate review comments
Varsha-Kulkarni Oct 5, 2022
0cc6886
Update noty-android/app/src/main/java/dev/shreyaspatil/noty/view/view…
Varsha-Kulkarni Oct 5, 2022
78a1a90
Merge pull request #539 from Varsha-Kulkarni/pin_notes
PatilShreyas Oct 5, 2022
1efcb90
build: API to pin and unpin notes
mrfamouskk7 Oct 6, 2022
2427c23
chore: Add test cases to pin and unpin notes
mrfamouskk7 Oct 6, 2022
8098bdc
Fix CRLF
mrfamouskk7 Oct 6, 2022
e873cd9
feat: Add updated field to Notes table to keep latest pinned note on top
mrfamouskk7 Oct 6, 2022
11d7fc5
fix: Change pin request from PUT to PATCH
mrfamouskk7 Oct 6, 2022
adc2407
refactor: Method names in notesController, notesRouter and noteDao
mrfamouskk7 Oct 6, 2022
546e880
- fixed failing test cases due to jacoco
Oct 6, 2022
a104333
Merge pull request #550 from tusharpingale04/fix-test-cases
PatilShreyas Oct 7, 2022
0e5a39e
Merge pull request #546 from mrfamouskk7/feat/pin-note
PatilShreyas Oct 7, 2022
93f0dbf
Notes Pin Unpin support with remote Api
Oct 7, 2022
892528e
Create deploy_dispatch.yml
PatilShreyas Oct 7, 2022
2ac7b16
Merge pull request #552 from PatilShreyas/master
PatilShreyas Oct 7, 2022
0d591eb
Fix deploy_dispatch workflow
PatilShreyas Oct 7, 2022
f4bb02c
Notes Pin/Unpin Api Path Corrected
Oct 7, 2022
d5911e3
Wild Card imports fixed
Oct 7, 2022
957b200
Fixed Fake pin/Unpin implementation for testing
Oct 7, 2022
804b9a9
Merge pull request #553 from tyaporush/feature/pin-note
PatilShreyas Oct 7, 2022
6bc66b4
Test written for Pin/Unpin Api
Oct 7, 2022
ba7893a
replace deprecated OptionsMenu with MenuProvider (issue 547)
Varsha-Kulkarni Oct 7, 2022
ff14539
Merge branch 'feature/pin-note' of https://github.com/Varsha-Kulkarni…
Varsha-Kulkarni Oct 7, 2022
a487439
Merge pull request #555 from tyaporush/feature/pin-note
PatilShreyas Oct 8, 2022
32b02a1
Update to extract setting up menu into separate function
Varsha-Kulkarni Oct 8, 2022
5cb7065
Merge pull request #557 from Varsha-Kulkarni/feature/pin-note
PatilShreyas Oct 8, 2022
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
25 changes: 25 additions & 0 deletions .github/workflows/deploy_dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy Dispatch (API)

on: workflow_dispatch

jobs:
deploy_api:
name: Deploy to Heroku
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Install Heroku CLI
run: curl https://cli-assets.heroku.com/install-ubuntu.sh | sh

- name: Deploy to Heroku
run: |
git config --global user.name ${{ github.actor }}
git config --global user.email ${{ secrets.HEROKU_USER_EMAIL }}
echo "$HEROKU_AUTH" > ~/.netrc
heroku git:remote --app noty-api
git subtree split --prefix noty-api -b deployment-branch
git push -f heroku deployment-branch:master
env:
HEROKU_AUTH: ${{ secrets.HEROKU_AUTH }}
2 changes: 1 addition & 1 deletion noty-android/app/composeapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {

buildTypes {
debug {
testCoverageEnabled true
testCoverageEnabled false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package dev.shreyaspatil.noty.composeapp

import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
Expand Down Expand Up @@ -57,7 +58,7 @@ abstract class NotyScreenTest {
body: AndroidComposeTestRule<ActivityScenarioRule<MainActivity>, MainActivity>.() -> Unit
) = composeTestRule.run(body)

fun setNotyContent(content: @Composable () -> Unit) = composeTestRule.setContent {
fun setNotyContent(content: @Composable () -> Unit) = composeTestRule.activity.setContent {
NotyTheme {
content()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NoteCardTest : NotyComposableTest() {
fun testNoteCard() = runTest {
var clickCount = 0
setContent {
NoteCard(title = "Lorem Ipsum", note = "Hello World") {
NoteCard(title = "Lorem Ipsum", note = "Hello World", isPinned = false) {
clickCount++
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ class NotesScreenTest : NotyScreenTest() {
setNotyContent { NotesScreen(onNavigateToNoteDetail = { navigateToNoteId = it }) }
registerIdlingResource(prefillNotes())

onNodeWithText("Lorem Ipsum 1").performClick()
onNodeWithText("Lorem Ipsum 1", useUnmergedTree = true).performClick()
waitForIdle()
assertEquals("1", navigateToNoteId)

onNodeWithText("Hello World 2").performClick()
onNodeWithText("Hello World 2", useUnmergedTree = true).performClick()
waitForIdle()
assertEquals("2", navigateToNoteId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import dev.shreyaspatil.noty.R

@Composable
fun PinAction(isPinned: Boolean, onClick: () -> Unit) {
val icon = painterResource(id = if (isPinned) R.drawable.ic_pinned else R.drawable.ic_unpinned)
IconButton(onClick = onClick) {
Icon(
painter = icon,
contentDescription = "Pinned Note",
modifier = Modifier
.padding(8.dp)
)
}
}

@Composable
fun DeleteAction(onClick: () -> Unit) {
val icon = painterResource(R.drawable.ic_delete)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ package dev.shreyaspatil.noty.composeapp.component.note

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.MaterialTheme.typography
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.shreyaspatil.noty.composeapp.R
import dev.shreyaspatil.noty.composeapp.utils.NotyPreview

@Composable
fun NoteCard(title: String, note: String, onNoteClick: () -> Unit) {
fun NoteCard(title: String, note: String, isPinned: Boolean, onNoteClick: () -> Unit) {
Card(
shape = RoundedCornerShape(4.dp),
backgroundColor = MaterialTheme.colors.surface,
Expand All @@ -52,12 +56,22 @@ fun NoteCard(title: String, note: String, onNoteClick: () -> Unit) {
modifier = Modifier
.padding(16.dp)
) {
Text(
text = title,
style = typography.h5,
color = MaterialTheme.colors.onPrimary,
fontWeight = FontWeight.Bold
)
Row(Modifier.fillMaxWidth()) {
Text(
text = title,
style = typography.h5,
color = MaterialTheme.colors.onPrimary,
fontWeight = FontWeight.Bold,
modifier = Modifier.weight(1f)
)
if (isPinned) {
Icon(
painterResource(id = R.drawable.ic_pinned),
contentDescription = "Pinned Note",
modifier = Modifier.padding(8.dp)
)
}
}
Spacer(modifier = Modifier.height(12.dp))
Text(
text = note,
Expand All @@ -73,5 +87,10 @@ fun NoteCard(title: String, note: String, onNoteClick: () -> Unit) {
@Preview
@Composable
fun PreviewNoteCard() = NotyPreview {
NoteCard(title = "Lorem Ipsum", note = "Here is note body...", onNoteClick = {})
NoteCard(
title = "Lorem Ipsum",
note = "Here is note body...",
isPinned = true,
onNoteClick = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fun NotesList(notes: List<Note>, onClick: (Note) -> Unit) {
NoteCard(
title = note.title,
note = note.note,
isPinned = note.isPinned,
onNoteClick = { onClick(note) }
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package dev.shreyaspatil.noty.composeapp.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Surface
Expand All @@ -38,7 +38,7 @@ import dev.shreyaspatil.noty.view.viewmodel.NoteDetailViewModel
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
class MainActivity : ComponentActivity() {

@Inject
lateinit var preferenceManager: PreferenceManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dev.shreyaspatil.capturable.Capturable
import dev.shreyaspatil.capturable.controller.CaptureController
import dev.shreyaspatil.capturable.controller.rememberCaptureController
import dev.shreyaspatil.noty.composeapp.component.action.DeleteAction
import dev.shreyaspatil.noty.composeapp.component.action.PinAction
import dev.shreyaspatil.noty.composeapp.component.action.ShareAction
import dev.shreyaspatil.noty.composeapp.component.action.ShareActionItem
import dev.shreyaspatil.noty.composeapp.component.action.ShareDropdown
Expand Down Expand Up @@ -76,9 +77,11 @@ fun NoteDetailsScreen(
title = state.title ?: "",
note = state.note ?: "",
error = state.error,
isPinned = state.isPinned,
showSaveButton = state.showSave,
onTitleChange = viewModel::setTitle,
onNoteChange = viewModel::setNote,
onPinClick = viewModel::togglePin,
onSaveClick = viewModel::save,
onDeleteClick = { showDeleteNoteConfirmation = true },
onNavigateUp = onNavigateUp,
Expand Down Expand Up @@ -109,9 +112,11 @@ fun NoteDetailContent(
title: String,
note: String,
error: String?,
isPinned: Boolean,
showSaveButton: Boolean,
onTitleChange: (String) -> Unit,
onNoteChange: (String) -> Unit,
onPinClick: () -> Unit,
onSaveClick: () -> Unit,
onNavigateUp: () -> Unit,
onDeleteClick: () -> Unit,
Expand All @@ -131,6 +136,8 @@ fun NoteDetailContent(
onNavigateUp = onNavigateUp,
actions = {
NoteDetailActions(
isPinned = isPinned,
onPinClick = onPinClick,
onDeleteClick = onDeleteClick,
onShareNoteAsTextClick = onShareNoteAsText,
onShareNoteAsImageClick = {
Expand Down Expand Up @@ -166,11 +173,14 @@ fun NoteDetailContent(

@Composable
private fun NoteDetailActions(
isPinned: Boolean,
onPinClick: () -> Unit,
onDeleteClick: () -> Unit,
onShareNoteAsTextClick: () -> Unit,
onShareNoteAsImageClick: () -> Unit
) {
var dropdownExpanded by remember { mutableStateOf(false) }
PinAction(isPinned, onClick = onPinClick)
DeleteAction(onClick = onDeleteClick)
ShareAction(onClick = { dropdownExpanded = true })
ShareDropdown(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.core.view.drawToBitmap
import androidx.core.view.isVisible
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -64,6 +68,8 @@ class NoteDetailFragment :
*/
private var isNoteLoaded = false

private var pinMenuItem: MenuItem? = null

override val viewModel: NoteDetailViewModel by viewModels {
args.noteId?.let { noteId ->
NoteDetailViewModel.provideFactory(viewModelAssistedFactory, noteId)
Expand All @@ -79,9 +85,10 @@ class NoteDetailFragment :
)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setupMenu()
}

override fun initView() {
Expand All @@ -95,8 +102,6 @@ class NoteDetailFragment :
}

override fun render(state: NoteDetailState) {
showProgressDialog(state.isLoading)

binding.fabSave.isVisible = state.showSave

val title = state.title
Expand All @@ -116,6 +121,44 @@ class NoteDetailFragment :
if (errorMessage != null) {
toast("Error: $errorMessage")
}

updatePinnedIcon(state.isPinned)
}

private fun setupMenu() {
val menuHost: MenuHost = requireActivity()

menuHost.addMenuProvider(
object : MenuProvider {
override fun onPrepareMenu(menu: Menu) {
pinMenuItem = menu.findItem(R.id.action_pin)

super.onPrepareMenu(menu)
}

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.note_menu, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.action_delete -> confirmNoteDeletion()
R.id.action_pin -> viewModel.togglePin()
R.id.action_share_text -> shareText()
R.id.action_share_image -> shareImage()
}
return false
}
},
viewLifecycleOwner, Lifecycle.State.RESUMED
)
}

private fun updatePinnedIcon(isPinned: Boolean) {
pinMenuItem?.run {
val icon = if (isPinned) R.drawable.ic_pinned else R.drawable.ic_unpinned
setIcon(icon)
}
}

private fun shareText() {
Expand Down Expand Up @@ -146,20 +189,6 @@ class NoteDetailFragment :
Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.note_menu, menu)
super.onCreateOptionsMenu(menu, inflater)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_delete -> confirmNoteDeletion()
R.id.action_share_text -> shareText()
R.id.action_share_image -> shareImage()
}
return super.onOptionsItemSelected(item)
}

override fun getViewBinding(
inflater: LayoutInflater,
container: ViewGroup?
Expand Down
Loading