Skip to content

Commit 32015f8

Browse files
committed
Fixed fab button not changing color bug and some other improvements in user experience.
1 parent 11d5978 commit 32015f8

6 files changed

Lines changed: 46 additions & 27 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.madscientistapps.mynotes"
1111
minSdkVersion 23
1212
targetSdkVersion 29
13-
versionCode 4
14-
versionName "1.4"
13+
versionCode 5
14+
versionName "1.5"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:theme="@style/AppTheme"
1212
android:name=".MyApplication">
1313
<activity android:name=".addNoteActivity"
14-
android:theme="@style/Theme.Cyanea.Dark.reference">
14+
android:theme="@style/Theme.Cyanea.Dark">
1515

1616
<meta-data
1717
android:name="android.support.PARENT_ACTIVITY"
@@ -21,7 +21,7 @@
2121

2222
</activity>
2323
<activity android:name=".MainActivity"
24-
android:theme="@style/Theme.Cyanea.Dark.reference">
24+
android:theme="@style/Theme.Cyanea.Dark">
2525
<intent-filter>
2626
<action android:name="android.intent.action.MAIN" />
2727

app/src/main/java/com/example/mynotes/MainActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.os.Bundle
99
import android.view.Menu
1010
import android.view.MenuItem
1111
import android.widget.SimpleCursorAdapter
12-
import android.widget.Toast
1312
import androidx.annotation.RequiresApi
1413
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity
1514
import com.jaredrummler.cyanea.prefs.CyaneaSettingsActivity
@@ -58,11 +57,10 @@ class MainActivity : CyaneaAppCompatActivity() {
5857
override fun onOptionsItemSelected(item: MenuItem): Boolean {
5958

6059
if (item.itemId == R.id.donate) {
61-
val browserIntent =
62-
Intent(Intent.ACTION_VIEW, Uri.parse("https://paypal.me/AnmolAgrawal"))
60+
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://paypal.me/AnmolAgrawal"))
6361
startActivity(browserIntent)
64-
Toast.makeText(this, "Thanks for donating!", Toast.LENGTH_LONG).show()
65-
} else {
62+
}
63+
else {
6664

6765
val inten = Intent(this, CyaneaSettingsActivity::class.java)
6866
startActivity(inten)

app/src/main/java/com/example/mynotes/addNoteActivity.kt

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ class addNoteActivity : CyaneaAppCompatActivity() {
5252

5353
}
5454

55+
fun deleteNote(noteId:Int) {
56+
57+
db?.delete("myNotes", "_id=?", arrayOf(noteId.toString()))
58+
Toast.makeText(this, "Note deleted successfully!", Toast.LENGTH_LONG).show()
59+
finish()
60+
61+
}
62+
5563
override fun onOptionsItemSelected(item: MenuItem): Boolean {
5664

5765
if(item.itemId == R.id.delete_note) {
5866

59-
db?.delete("myNotes", "_id=?", arrayOf(noteId.toString()))
60-
Toast.makeText(this, "Note deleted successfully!", Toast.LENGTH_LONG).show()
61-
finish()
67+
deleteNote(noteId!!)
68+
6269

6370
}
64-
onBackPressed()
71+
else
72+
onBackPressed()
6573
return super.onOptionsItemSelected(item)
6674

6775

@@ -79,8 +87,15 @@ class addNoteActivity : CyaneaAppCompatActivity() {
7987
}
8088

8189
private fun updateNote(noteValues: ContentValues) {
82-
db?.update("myNotes", noteValues, "_id=?", arrayOf(noteId.toString()))
83-
Toast.makeText(this, "Note updated successfully!", Toast.LENGTH_LONG).show()
90+
91+
if (cursor?.getString(0) == noteTitleText.text.toString() &&
92+
cursor?.getString(1) == fullNoteText.text.toString())
93+
finish()
94+
else {
95+
96+
db?.update("myNotes", noteValues, "_id=?", arrayOf(noteId.toString()))
97+
Toast.makeText(this, "Note updated successfully!", Toast.LENGTH_LONG).show()
98+
}
8499
}
85100

86101
override fun onDestroy() {
@@ -100,20 +115,24 @@ class addNoteActivity : CyaneaAppCompatActivity() {
100115

101116
val noteValues = ContentValues()
102117

103-
if (noteTitleText.text.toString() == "")
104-
noteValues.put("noteTitle", "Untitled Note")
105-
else
106-
noteValues.put("noteTitle", noteTitleText.text.toString())
118+
if (fullNoteText.text.toString() == "" && noteTitleText.text.toString() == "")
119+
deleteNote(noteId!!)
120+
else {
107121

108-
noteValues.put("fullNote", fullNoteText.text.toString())
122+
if (noteTitleText.text.toString() == "" && fullNoteText.text.toString() != "")
123+
noteValues.put("noteTitle", "Untitled Note")
124+
else
125+
noteValues.put("noteTitle", noteTitleText.text.toString())
109126

110-
if(noteId == 0)
111-
addNote(noteValues)
112-
else
113-
updateNote(noteValues)
127+
noteValues.put("fullNote", fullNoteText.text.toString())
114128

115-
super.onBackPressed()
116-
finish()
129+
if (noteId == 0)
130+
addNote(noteValues)
131+
else
132+
updateNote(noteValues)
117133

134+
super.onBackPressed()
135+
finish()
136+
}
118137
}
119138
}

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
android:id="@+id/addNoteButton"
1212
android:layout_width="wrap_content"
1313
android:layout_height="wrap_content"
14+
app:borderWidth="0dp"
1415
android:layout_marginEnd="32dp"
1516
android:layout_marginBottom="32dp"
17+
android:backgroundTint="@color/cyanea_accent"
1618
android:clickable="true"
1719
android:focusable="true"
1820
app:layout_constraintBottom_toBottomOf="parent"
@@ -29,5 +31,6 @@
2931
app:layout_constraintHorizontal_bias="0.0"
3032
app:layout_constraintStart_toStartOf="parent"
3133
app:layout_constraintTop_toTopOf="parent"
34+
android:divider="@color/cyanea_accent"
3235
app:layout_constraintVertical_bias="0.0" />
3336
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/styles.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
<item name="android:textColor">#FFFFFF</item>
1010
<item name="android:itemBackground">#000000</item>
1111
</style>
12-
<style name="Theme.Cyanea.Dark.reference"></style>
1312

1413
</resources>

0 commit comments

Comments
 (0)