Skip to content

Commit

Permalink
- Fix styles bar not showing for emulators
Browse files Browse the repository at this point in the history
- Update notes styles
- Add encryption to local db
- Layout improvements
- Update dependencies
  • Loading branch information
YahiaAngelo committed Oct 1, 2020
1 parent 4e4f61b commit 5b4cc44
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 61 deletions.
15 changes: 8 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.noted.noted"
minSdkVersion 23
targetSdkVersion 29
versionCode 7
versionName "1.1.1"
versionCode 8
versionName "1.1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -49,7 +49,7 @@ android {

dependencies {
def nav_version = "2.3.0"
def koin_version = "2.2.0-alpha-1"
def koin_version = "2.2.0-beta-1"
def lifecycle_version = "2.2.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
Expand All @@ -71,18 +71,19 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation "androidx.security:security-crypto:1.1.0-alpha02"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation 'org.parceler:parceler-api:1.1.13'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.nonzeroapps:whatisnewdialog:1.0.7'
kapt 'org.parceler:parceler:1.1.13'
implementation "io.noties.markwon:core:4.3.1"
implementation "io.noties.markwon:ext-strikethrough:4.3.1"
implementation 'com.yahiaangelo.markdownedittext:markdownedittext:1.0.2'
implementation "io.noties.markwon:core:4.6.0"
implementation "io.noties.markwon:ext-strikethrough:4.6.0"
implementation "io.noties.markwon:ext-tasklist:4.6.0"
implementation 'com.yahiaangelo.markdownedittext:markdownedittext:1.1.0'
implementation('dev.doubledot.doki:library:0.0.1@aar') {
transitive = true
}
Expand Down
46 changes: 43 additions & 3 deletions app/src/main/java/com/noted/noted/AppController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.util.Base64
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import com.noted.noted.repositories.NoteRepo
import com.noted.noted.repositories.TaskRepo
import com.noted.noted.utils.Extensions
Expand All @@ -19,6 +22,8 @@ import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.dsl.module
import timber.log.Timber
import java.io.File
import java.security.SecureRandom

class AppController : Application(){

Expand Down Expand Up @@ -56,13 +61,48 @@ class AppController : Application(){

}



private fun initRealm(){
Realm.init(this)
val realmConfig = RealmConfiguration.Builder()
.name("noted.realm")

val newRealmConfig = RealmConfiguration.Builder()
.name("encryptedNoted.realm")
.schemaVersion(1)
.encryptionKey(loadKey())
.build()
Realm.setDefaultConfiguration(realmConfig)

val newRealmFile = File(newRealmConfig.path)
if (!newRealmFile.exists()){
val oldConfig = RealmConfiguration.Builder().name("noted.realm").schemaVersion(1).build()
val realm = Realm.getInstance(oldConfig)
realm.writeEncryptedCopyTo(newRealmFile, loadKey())
realm.close()
Realm.deleteRealm(oldConfig)
Realm.setDefaultConfiguration(newRealmConfig)
}else{
Realm.setDefaultConfiguration(newRealmConfig)
}

}

private fun loadKey(): ByteArray{
val sharedPrefs = EncryptedSharedPreferences.create(
"secret_preferences",
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
this ,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
val key = sharedPrefs.getString("realmdb", "")
return if (key!!.isNotEmpty()){
Base64.decode(key, Base64.NO_WRAP)
}else{
val newKey = ByteArray(64)
SecureRandom().nextBytes(newKey)
sharedPrefs.edit().putString("realmdb", Base64.encodeToString(newKey, Base64.NO_WRAP)).apply()
newKey
}
}

private fun createNotificationChannel() {
Expand Down
15 changes: 1 addition & 14 deletions app/src/main/java/com/noted/noted/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.GoogleAuthProvider
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import com.nonzeroapps.whatisnewdialog.NewItemDialog
import com.nonzeroapps.whatisnewdialog.`object`.NewFeatureItem
import com.noted.noted.databinding.ActivityMainBinding
import com.noted.noted.model.NoteCategory
import com.noted.noted.repositories.NoteRepo
Expand Down Expand Up @@ -80,7 +78,6 @@ class MainActivity : BaseActivity() {
}

}
showNewFeatures()

}

Expand Down Expand Up @@ -225,6 +222,7 @@ class MainActivity : BaseActivity() {
// Sign in success, update UI with the signed-in user's information
headerView.findViewById<MaterialButton>(R.id.google_login).visibility = View.GONE
headerView.findViewById<LinearLayout>(R.id.main_user_info).visibility = View.VISIBLE
Snackbar.make(binding.navView, "Your notes are now synced !", Snackbar.LENGTH_SHORT).show()
binding.mainDrawerLayout.closeDrawer(binding.navView)
NoteRepo.NotesWorker.uploadNotes()

Expand All @@ -251,17 +249,6 @@ class MainActivity : BaseActivity() {
.into(profileImage)
}

private fun showNewFeatures(){
val backupFeature = NewFeatureItem()
backupFeature.featureTitle = "Introducing Notes backups"
backupFeature.featureDesc = "Now you can sync your Notes with cloud by logging in with your Google account from left side menu"
backupFeature.setImageResource(R.drawable.backup_ss)
NewItemDialog.init(this)
.setVersionName(BuildConfig.VERSION_NAME)
.setDialogTitle("New features in ${BuildConfig.VERSION_NAME} version!")
.setItems(arrayListOf(backupFeature))
.showDialogIfConditionsSuitable(this)
}
private val FragmentManager.currentNavigationFragment: Fragment?
get() = primaryNavigationFragment?.childFragmentManager?.fragments?.first()

Expand Down
39 changes: 14 additions & 25 deletions app/src/main/java/com/noted/noted/view/activity/NoteAddActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import android.text.TextWatcher
import android.view.*
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
import androidx.transition.Fade
import androidx.transition.TransitionManager
import androidx.transition.TransitionSet
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
Expand All @@ -25,8 +22,6 @@ import com.noted.noted.model.NoteCategory
import com.noted.noted.repositories.NoteRepo
import com.noted.noted.utils.Utils
import io.realm.RealmList
import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent
import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEventListener
import org.koin.android.ext.android.inject
import org.parceler.Parcels
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -311,25 +306,18 @@ class NoteAddActivity : AppCompatActivity() {
}

private fun setupMarkwon() {
KeyboardVisibilityEvent.setEventListener(this, object : KeyboardVisibilityEventListener {
override fun onVisibilityChanged(isOpen: Boolean) {
val set: TransitionSet = TransitionSet()
.addTransition(Fade())
.setInterpolator(FastOutLinearInInterpolator())

TransitionManager.beginDelayedTransition(binding.noteStylesBar, set)
if(isOpen){
binding.noteStylesBar.visibility = View.VISIBLE
binding.noteDate.visibility = View.GONE
binding.noteBodyEditText.setStylesBar(binding.noteStylesBar)

}else{
binding.noteStylesBar.visibility = View.GONE
binding.noteDate.visibility = View.VISIBLE
}
}

})
binding.noteBodyEditText.setOnFocusChangeListener { v, hasFocus ->
if(hasFocus){
binding.noteStylesBar.visibility = View.VISIBLE
binding.noteDate.visibility = View.GONE
binding.noteBodyEditText.setStylesBar(binding.noteStylesBar)

}else{
binding.noteStylesBar.visibility = View.GONE
binding.noteDate.visibility = View.VISIBLE
}
}

val textWatcher = object : TextWatcher{
override fun afterTextChanged(s: Editable?) {
Expand All @@ -346,7 +334,8 @@ class NoteAddActivity : AppCompatActivity() {

}
binding.noteBodyEditText.addTextChangedListener(textWatcher)

binding.noteBodyEditText.taskBoxBackgroundColor = ResourcesCompat.getColor(resources, R.color.background, theme)
binding.noteBodyEditText.taskBoxColor = ResourcesCompat.getColor(resources, R.color.primary, theme)
}

private fun showSaveConfirmDialog(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Build
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.card.MaterialCardView
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
Expand All @@ -15,6 +16,7 @@ import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.Markwon
import io.noties.markwon.MarkwonVisitor
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
import io.noties.markwon.ext.tasklist.TaskListPlugin
import org.commonmark.node.SoftLineBreak

class NoteBinding(var note: Note) : AbstractBindingItem<ItemNoteBinding>() {
Expand All @@ -37,6 +39,7 @@ class NoteBinding(var note: Note) : AbstractBindingItem<ItemNoteBinding>() {
categoriesChipGroup = binding.noteChipGroup
val markwon = Markwon.builder(context)
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TaskListPlugin.create(ResourcesCompat.getColor(context.resources, R.color.primary, context.theme), ResourcesCompat.getColor(context.resources, R.color.primary, context.theme), ResourcesCompat.getColor(context.resources, R.color.background, context.theme)))
.usePlugin(object : AbstractMarkwonPlugin() {
override fun configureVisitor(builder: MarkwonVisitor.Builder) {
super.configureVisitor(builder)
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/main_nav_header_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@
</LinearLayout>

<View
android:layout_marginTop="18dp"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="18dp"
android:background="@color/divider"/>
android:alpha="0.5"
android:background="@color/text_secondary"/>

</LinearLayout>
3 changes: 0 additions & 3 deletions app/src/main/res/values-round/strings.xml

This file was deleted.

22 changes: 16 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<resources>
<string name="app_name">Noted</string>
<string name="title_activity_login">LoginActivity</string>
<!--
This string is used for square devices and overridden by hello_world in
values-round/strings.xml for round devices.
-->
<string name="hello_world">Hello Square World!</string>

<string name="login_welcome">Welcome..</string>
<string name="email">Email</string>
<string name="username">Username</string>
Expand All @@ -19,7 +15,21 @@
<string name="title">Title</string>
<string name="title_activity_settings">SettingsActivity</string>

<string name="app_changelog">### v1.0.2:\n
<string name="app_changelog">### v1.1.2:\n
- Fixed styles bar not showing for emulators\n
- Updated notes styles (fixed styles in lists and added tasks lists)\n
- Add encryption to local database\n
- Layout improvements\n
### v1.1.1:\n
- Fixed stylesbar crash\n
- Replaced in app rate with playstore link\n
- Fixed categories deleting\n
- Layout improvements\n
### v1.1.0:\n
- Added Notes sync with Firestore\n
- Added Note save confirmation\n
- Fixed keyboard showing above task add sheet\n
### v1.0.2:\n
- Added About screen\n
- Fixed category deletion in Note add screen\n
- Fixed force dark mode issues\n
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:6.1.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'


Expand Down

0 comments on commit 5b4cc44

Please sign in to comment.