Skip to content

Commit ddb0fcb

Browse files
committed
Final Changes
1 parent c2b211f commit ddb0fcb

24 files changed

+328
-465
lines changed

.idea/assetWizardSettings.xml

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dictionaries/mormont.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ dependencies {
2929
implementation fileTree(dir: 'libs', include: ['*.jar'])
3030
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3131
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
32+
implementation 'androidx.preference:preference:1.1.0-alpha03'
3233
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
3334
implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
34-
api ('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.22')
35+
api('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.22')
36+
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
3537
testImplementation 'junit:junit:4.12'
3638
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
3739
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.hackware.mormont.notebook">
3+
xmlns:tools="http://schemas.android.com/tools" package="com.hackware.mormont.notebook">
44

55
<application
6-
android:allowBackup="true"
76
android:icon="@mipmap/ic_launcher"
87
android:label="@string/app_name"
98
android:roundIcon="@mipmap/ic_launcher_round"
109
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
10+
android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
11+
<activity android:name=".MainActivity"
12+
android:screenOrientation="portrait">
13+
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN"/>
15-
1616
<category android:name="android.intent.category.LAUNCHER"/>
1717
</intent-filter>
1818
</activity>
1919
<activity android:name=".Editor">
2020
</activity>
21+
<activity
22+
android:name=".SettingsActivity"
23+
android:label="@string/title_activity_settings"
24+
android:screenOrientation="portrait"
25+
android:parentActivityName=".MainActivity">
26+
<meta-data
27+
android:name="android.support.PARENT_ACTIVITY"
28+
android:value="com.hackware.mormont.notebook.MainActivity"/>
29+
</activity>
2130
</application>
2231

2332
</manifest>

app/src/main/java/com/hackware/mormont/notebook/AppCompatPreferenceActivity.kt

Lines changed: 0 additions & 90 deletions
This file was deleted.

app/src/main/java/com/hackware/mormont/notebook/Editor.kt

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ package com.hackware.mormont.notebook
33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import android.os.Handler
6+
import android.view.Menu
7+
import android.view.MenuInflater
8+
import android.view.MenuItem
9+
import android.view.View
610
import android.widget.EditText
11+
import androidx.appcompat.widget.SearchView
712
import com.hackware.mormont.notebook.db.NotesDataBase
813
import com.hackware.mormont.notebook.db.entity.NotesData
914
import com.hackware.mormont.notebook.utils.DateUtil
15+
import kotlinx.android.synthetic.main.activity_main.*
16+
import org.wordpress.android.util.ToastUtils
1017
import org.wordpress.aztec.Aztec
1118
import org.wordpress.aztec.AztecText
1219
import org.wordpress.aztec.ITextFormat
1320
import org.wordpress.aztec.toolbar.AztecToolbar
1421
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
22+
import java.util.*
1523
import kotlin.random.Random
1624

1725

@@ -23,10 +31,12 @@ open class Editor : AppCompatActivity(),
2331

2432
private lateinit var title: EditText
2533
private lateinit var mDbWorkerThread: DbWorkerThread
34+
private lateinit var mToolbar: AztecToolbar
2635
private var mDb: NotesDataBase? = null
2736
private val INTENT_NOTE_ID: String = "NoteId"
2837
private var isEditing = false
2938
private lateinit var mData: NotesData
39+
private var isShowToolbar = false
3040

3141
private val mUiHandler = Handler()
3242

@@ -36,13 +46,15 @@ open class Editor : AppCompatActivity(),
3646
super.onCreate(savedInstanceState)
3747
setContentView(R.layout.activity_editor)
3848

49+
setSupportActionBar(findViewById(R.id.toolbar))
50+
3951
title = findViewById(R.id.title)
4052
mDb = NotesDataBase.getInstance(this)
4153

4254
val visualEditor = findViewById<AztecText>(R.id.aztec)
43-
val toolbar = findViewById<AztecToolbar>(R.id.formatting_toolbar)
55+
mToolbar = findViewById<AztecToolbar>(R.id.formatting_toolbar)
4456

45-
aztec = Aztec.with(visualEditor, toolbar, this)
57+
aztec = Aztec.with(visualEditor, mToolbar, this)
4658

4759
val noteId: Long= intent.getLongExtra(INTENT_NOTE_ID, 0.toLong())
4860
if( noteId != 0.toLong()){
@@ -51,31 +63,69 @@ open class Editor : AppCompatActivity(),
5163
}
5264
}
5365

66+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
67+
val inflater: MenuInflater = menuInflater
68+
inflater.inflate(R.menu.appbar_editor_menu, menu)
69+
return true
70+
}
71+
72+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
73+
return when (item.itemId){
74+
R.id.save_note -> {
75+
when(title.text.isEmpty()){
76+
true -> ToastUtils.showToast(applicationContext, R.string.don_save_empty)
77+
false -> {
78+
if (isEditing) {
79+
saveEditedData()
80+
}
81+
else{
82+
isEditing = true
83+
saveNewNote()
84+
}
85+
}
86+
}
87+
true
88+
}
89+
R.id.show_tool -> {
90+
if(isShowToolbar){
91+
mToolbar.visibility = View.INVISIBLE
92+
isShowToolbar = false
93+
}
94+
else{
95+
mToolbar.visibility = View.VISIBLE
96+
isShowToolbar = true
97+
}
98+
true
99+
}
100+
else -> super.onOptionsItemSelected(item)
101+
}
102+
}
103+
54104
override fun onBackPressed() {
55-
var data: NotesData
56105
if (isEditing){
57106
if (mData.title != title.text.toString() || mData.rawContent != aztec.visualEditor.toFormattedHtml() )
58107
saveEditedData()
59108
}else {
60-
if (!title.text.isEmpty()) {
61-
data = NotesData(
62-
Random.nextLong(),
63-
Random.nextLong(), DateUtil.getCurrentDate(), DateUtil.getCurrentDate(),
64-
title.text.toString(),
65-
aztec.visualEditor.text.toString(),
66-
aztec.visualEditor.toFormattedHtml()
67-
)
68-
69-
val task = Runnable {
70-
mDb?.notesDataDao()?.insertNote(data)
71-
}
72-
mDbWorkerThread.postTask(task)
109+
when(title.text.isEmpty()) {
110+
true -> ToastUtils.showToast(applicationContext, R.string.don_save_empty)
111+
false -> saveNewNote()
73112
}
74113
}
75-
76114
return super.onBackPressed()
77115
}
78-
116+
private fun saveNewNote(){
117+
mData = NotesData(
118+
Random.nextLong(),
119+
Random.nextLong(), DateUtil.getCurrentDate(), DateUtil.getCurrentDate(),
120+
title.text.toString(),
121+
aztec.visualEditor.text.toString(),
122+
aztec.visualEditor.toFormattedHtml()
123+
)
124+
val task = Runnable {
125+
mDb?.notesDataDao()?.insertNote(mData)
126+
}
127+
mDbWorkerThread.postTask(task)
128+
}
79129
private fun loadDataFromBd(id: Long){
80130
val task = Runnable {
81131
mData = mDb!!.notesDataDao().loadNoteWithId(id)
@@ -89,6 +139,7 @@ open class Editor : AppCompatActivity(),
89139
mDbWorkerThread.postTask(task)
90140
}
91141

142+
92143
private fun saveEditedData(){
93144
mData.title = title.text.toString()
94145
mData.strContent = aztec.visualEditor.text.toString()
@@ -101,7 +152,6 @@ open class Editor : AppCompatActivity(),
101152
mDbWorkerThread.postTask(task)
102153
}
103154

104-
105155
override fun onToolbarCollapseButtonClicked() {
106156
}
107157

0 commit comments

Comments
 (0)