Skip to content

Commit c45b615

Browse files
committed
Cleaned up code and tweaked UI (Minor changes)
1 parent 425bc17 commit c45b615

25 files changed

+90
-158
lines changed

app/src/main/java/android/print/PostPDFGenerator.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ object PostPDFGenerator {
5959

6060

6161
private fun getPrintAttributes(): PrintAttributes {
62-
return PrintAttributes.Builder()
63-
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
64-
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
65-
.setResolution(PrintAttributes.Resolution("Standard", "Standard", 100, 100))
66-
.build()
62+
val builder = PrintAttributes.Builder()
63+
builder.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
64+
builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
65+
builder.setResolution(PrintAttributes.Resolution("Standard", "Standard", 100, 100))
66+
return builder.build()
6767
}
6868

6969
private fun getFileDescriptor(file: File): ParcelFileDescriptor {

app/src/main/java/com/omgodse/notally/activities/MakeList.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.omgodse.notally.miscellaneous.getLocale
1212
import com.omgodse.notally.miscellaneous.setOnNextAction
1313
import com.omgodse.notally.recyclerview.ListItemListener
1414
import com.omgodse.notally.recyclerview.adapters.MakeListAdapter
15-
import com.omgodse.notally.recyclerview.viewholders.MakeListViewHolder
15+
import com.omgodse.notally.recyclerview.viewholders.MakeListVH
1616
import com.omgodse.notally.room.ListItem
1717
import com.omgodse.notally.viewmodels.BaseNoteModel
1818
import com.omgodse.notally.viewmodels.MakeListModel
@@ -67,7 +67,7 @@ class MakeList : NotallyActivity() {
6767
model.items.add(listItem)
6868
adapter.notifyItemInserted(position)
6969
binding.RecyclerView.post {
70-
val viewHolder = binding.RecyclerView.findViewHolderForAdapterPosition(position) as MakeListViewHolder?
70+
val viewHolder = binding.RecyclerView.findViewHolderForAdapterPosition(position) as MakeListVH?
7171
viewHolder?.requestFocus()
7272
}
7373
}
@@ -135,7 +135,7 @@ class MakeList : NotallyActivity() {
135135
}
136136

137137
private fun moveToNext(currentPosition: Int) {
138-
val viewHolder = binding.RecyclerView.findViewHolderForAdapterPosition(currentPosition + 1) as MakeListViewHolder?
138+
val viewHolder = binding.RecyclerView.findViewHolderForAdapterPosition(currentPosition + 1) as MakeListVH?
139139
if (viewHolder != null) {
140140
if (viewHolder.binding.CheckBox.isChecked) {
141141
moveToNext(currentPosition + 1)

app/src/main/java/com/omgodse/notally/fragments/Labels.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import com.omgodse.notally.databinding.DialogInputBinding
1818
import com.omgodse.notally.databinding.FragmentNotesBinding
1919
import com.omgodse.notally.miscellaneous.Constants
2020
import com.omgodse.notally.recyclerview.ItemListener
21-
import com.omgodse.notally.recyclerview.adapters.LabelsAdapter
21+
import com.omgodse.notally.recyclerview.adapters.LabelAdapter
2222
import com.omgodse.notally.room.Label
2323
import com.omgodse.notally.viewmodels.BaseNoteModel
2424

2525
class Labels : Fragment(), ItemListener {
2626

27-
private var labelsAdapter: LabelsAdapter? = null
27+
private var adapter: LabelAdapter? = null
2828
private var binding: FragmentNotesBinding? = null
2929

3030
private val model: BaseNoteModel by activityViewModels()
@@ -36,7 +36,7 @@ class Labels : Fragment(), ItemListener {
3636
}
3737

3838
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39-
labelsAdapter = LabelsAdapter(this)
39+
adapter = LabelAdapter(this)
4040

4141
binding?.RecyclerView?.setHasFixedSize(true)
4242
binding?.RecyclerView?.adapter = adapter

app/src/main/java/com/omgodse/notally/fragments/NotallyFragment.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.print.PostPDFGenerator
99
import android.view.LayoutInflater
1010
import android.view.View
1111
import android.view.ViewGroup
12-
import android.widget.LinearLayout
1312
import android.widget.Toast
1413
import androidx.core.content.FileProvider
1514
import androidx.core.view.isVisible
@@ -18,15 +17,12 @@ import androidx.fragment.app.activityViewModels
1817
import androidx.lifecycle.LiveData
1918
import androidx.lifecycle.lifecycleScope
2019
import androidx.navigation.fragment.findNavController
21-
import androidx.recyclerview.widget.LinearLayoutManager
2220
import androidx.recyclerview.widget.RecyclerView
2321
import androidx.recyclerview.widget.StaggeredGridLayoutManager
2422
import com.omgodse.notally.R
2523
import com.omgodse.notally.activities.MakeList
2624
import com.omgodse.notally.activities.TakeNote
2725
import com.omgodse.notally.databinding.FragmentNotesBinding
28-
import com.omgodse.notally.helpers.MenuDialog
29-
import com.omgodse.notally.helpers.MenuDialog.Operation
3026
import com.omgodse.notally.helpers.OperationsParent
3127
import com.omgodse.notally.helpers.SettingsHelper
3228
import com.omgodse.notally.miscellaneous.Constants
@@ -132,9 +128,10 @@ abstract class NotallyFragment : Fragment(), OperationsParent, ItemListener {
132128
}
133129

134130
private fun setupLayoutManager() {
135-
binding?.RecyclerView?.layoutManager = if (settingsHelper.getView() == getString(R.string.gridKey)) {
136-
StaggeredGridLayoutManager(2, LinearLayout.VERTICAL)
137-
} else LinearLayoutManager(requireContext())
131+
val columns = if (settingsHelper.getView() == getString(R.string.gridKey)) {
132+
2
133+
} else 1
134+
binding?.RecyclerView?.layoutManager = StaggeredGridLayoutManager(columns, RecyclerView.VERTICAL)
138135
}
139136

140137
private fun setupItemDecoration() {

app/src/main/java/com/omgodse/notally/fragments/Notes.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Notes : NotallyFragment() {
5151

5252
override fun getObservable() = model.baseNotes
5353

54-
override fun getBackground() = R.drawable.notebook
54+
override fun getBackground() = R.drawable.notes
5555

5656
override fun showOperations(baseNote: BaseNote) {
5757
val pin = if (baseNote.pinned) {

app/src/main/java/com/omgodse/notally/recyclerview/adapters/BaseNoteAdapter.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ import androidx.recyclerview.widget.ListAdapter
77
import com.omgodse.notally.databinding.RecyclerBaseNoteBinding
88
import com.omgodse.notally.helpers.SettingsHelper
99
import com.omgodse.notally.recyclerview.ItemListener
10-
import com.omgodse.notally.recyclerview.viewholders.BaseNoteViewHolder
10+
import com.omgodse.notally.recyclerview.viewholders.BaseNoteVH
1111
import com.omgodse.notally.room.BaseNote
1212
import org.ocpsoft.prettytime.PrettyTime
1313

1414
class BaseNoteAdapter(private val settingsHelper: SettingsHelper, private val itemListener: ItemListener) :
15-
ListAdapter<BaseNote, BaseNoteViewHolder>(DiffCallback()) {
15+
ListAdapter<BaseNote, BaseNoteVH>(DiffCallback()) {
1616

1717
private val prettyTime = PrettyTime()
1818

19-
override fun onBindViewHolder(holder: BaseNoteViewHolder, position: Int) {
19+
override fun onBindViewHolder(holder: BaseNoteVH, position: Int) {
2020
val baseNote = getItem(position)
2121
holder.bind(baseNote)
2222
}
2323

24-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseNoteViewHolder {
24+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseNoteVH {
2525
val inflater = LayoutInflater.from(parent.context)
2626
val binding = RecyclerBaseNoteBinding.inflate(inflater, parent, false)
27-
return BaseNoteViewHolder(binding, settingsHelper, itemListener, prettyTime)
27+
return BaseNoteVH(binding, settingsHelper, itemListener, prettyTime)
2828
}
2929

3030

app/src/main/java/com/omgodse/notally/recyclerview/adapters/LabelsAdapter.kt app/src/main/java/com/omgodse/notally/recyclerview/adapters/LabelAdapter.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import androidx.recyclerview.widget.DiffUtil
66
import androidx.recyclerview.widget.ListAdapter
77
import com.omgodse.notally.databinding.RecyclerLabelBinding
88
import com.omgodse.notally.recyclerview.ItemListener
9-
import com.omgodse.notally.recyclerview.viewholders.LabelsViewHolder
9+
import com.omgodse.notally.recyclerview.viewholders.LabelVH
1010
import com.omgodse.notally.room.Label
1111

12-
class LabelsAdapter(private val itemListener: ItemListener) : ListAdapter<Label, LabelsViewHolder>(DiffCallback()) {
12+
class LabelAdapter(private val itemListener: ItemListener) : ListAdapter<Label, LabelVH>(DiffCallback()) {
1313

14-
override fun onBindViewHolder(holder: LabelsViewHolder, position: Int) {
14+
override fun onBindViewHolder(holder: LabelVH, position: Int) {
1515
val label = getItem(position)
1616
holder.bind(label)
1717
}
1818

19-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelsViewHolder {
19+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelVH {
2020
val inflater = LayoutInflater.from(parent.context)
2121
val binding = RecyclerLabelBinding.inflate(inflater, parent, false)
22-
return LabelsViewHolder(binding, itemListener)
22+
return LabelVH(binding, itemListener)
2323
}
2424

2525

app/src/main/java/com/omgodse/notally/recyclerview/adapters/MakeListAdapter.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ import android.view.ViewGroup
55
import androidx.recyclerview.widget.RecyclerView
66
import com.omgodse.notally.databinding.RecyclerListItemBinding
77
import com.omgodse.notally.recyclerview.ListItemListener
8-
import com.omgodse.notally.recyclerview.viewholders.MakeListViewHolder
8+
import com.omgodse.notally.recyclerview.viewholders.MakeListVH
99
import com.omgodse.notally.room.ListItem
1010
import java.util.*
1111

1212
class MakeListAdapter(
1313
private val items: ArrayList<ListItem>,
1414
private val listItemListener: ListItemListener
15-
) : RecyclerView.Adapter<MakeListViewHolder>() {
15+
) : RecyclerView.Adapter<MakeListVH>() {
1616

1717
override fun getItemCount() = items.size
1818

19-
override fun onBindViewHolder(holder: MakeListViewHolder, position: Int) {
19+
override fun onBindViewHolder(holder: MakeListVH, position: Int) {
2020
val listItem = items[position]
2121
holder.bind(listItem)
2222
}
2323

24-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MakeListViewHolder {
24+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MakeListVH {
2525
val inflater = LayoutInflater.from(parent.context)
2626
val binding = RecyclerListItemBinding.inflate(inflater, parent, false)
27-
return MakeListViewHolder(binding, listItemListener)
27+
return MakeListVH(binding, listItemListener)
2828
}
2929
}

app/src/main/java/com/omgodse/notally/recyclerview/viewholders/BaseNoteViewHolder.kt app/src/main/java/com/omgodse/notally/recyclerview/viewholders/BaseNoteVH.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import com.omgodse.notally.room.Type
1616
import org.ocpsoft.prettytime.PrettyTime
1717
import java.util.*
1818

19-
class BaseNoteViewHolder(
19+
class BaseNoteVH(
2020
private val binding: RecyclerBaseNoteBinding,
2121
private val settingsHelper: SettingsHelper,
2222
private val itemListener: ItemListener,

app/src/main/java/com/omgodse/notally/recyclerview/viewholders/LabelsViewHolder.kt app/src/main/java/com/omgodse/notally/recyclerview/viewholders/LabelVH.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import com.omgodse.notally.databinding.RecyclerLabelBinding
55
import com.omgodse.notally.recyclerview.ItemListener
66
import com.omgodse.notally.room.Label
77

8-
class LabelsViewHolder(private val binding: RecyclerLabelBinding, itemListener: ItemListener) : RecyclerView.ViewHolder(binding.root) {
8+
class LabelVH(private val binding: RecyclerLabelBinding, itemListener: ItemListener) :
9+
RecyclerView.ViewHolder(binding.root) {
910

1011
init {
1112
binding.root.setOnClickListener {

app/src/main/java/com/omgodse/notally/recyclerview/viewholders/MakeListViewHolder.kt app/src/main/java/com/omgodse/notally/recyclerview/viewholders/MakeListVH.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.omgodse.notally.miscellaneous.setOnNextAction
99
import com.omgodse.notally.recyclerview.ListItemListener
1010
import com.omgodse.notally.room.ListItem
1111

12-
class MakeListViewHolder(val binding: RecyclerListItemBinding, listItemListener: ListItemListener) :
12+
class MakeListVH(val binding: RecyclerListItemBinding, listItemListener: ListItemListener) :
1313
RecyclerView.ViewHolder(binding.root) {
1414

1515
init {

app/src/main/java/com/omgodse/notally/room/SpanRepresentation.kt

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.omgodse.notally.room
22

33
import android.os.Parcelable
4-
import com.omgodse.notally.room.json.SafeJSONObject
54
import kotlinx.parcelize.Parcelize
5+
import org.json.JSONException
66
import org.json.JSONObject
77

88
@Parcelize
@@ -45,16 +45,23 @@ data class SpanRepresentation(
4545
private const val startTag = "start"
4646
private const val endTag = "end"
4747

48-
fun fromJSONObject(unsafeObject: JSONObject): SpanRepresentation {
49-
val safeObject = SafeJSONObject(unsafeObject.toString())
50-
val bold = safeObject.getBoolean(boldTag)
51-
val link = safeObject.getBoolean(linkTag)
52-
val italic = safeObject.getBoolean(italicTag)
53-
val monospace = safeObject.getBoolean(monospaceTag)
54-
val strikethrough = safeObject.getBoolean(strikethroughTag)
55-
val start = safeObject.getInt(startTag)
56-
val end = safeObject.getInt(endTag)
48+
fun fromJSONObject(jsonObject: JSONObject): SpanRepresentation {
49+
val bold = jsonObject.getSafeBoolean(boldTag)
50+
val link = jsonObject.getSafeBoolean(linkTag)
51+
val italic = jsonObject.getSafeBoolean(italicTag)
52+
val monospace = jsonObject.getSafeBoolean(monospaceTag)
53+
val strikethrough = jsonObject.getSafeBoolean(strikethroughTag)
54+
val start = jsonObject.getInt(startTag)
55+
val end = jsonObject.getInt(endTag)
5756
return SpanRepresentation(bold, link, italic, monospace, strikethrough, start, end)
5857
}
58+
59+
private fun JSONObject.getSafeBoolean(name: String): Boolean {
60+
return try {
61+
getBoolean(name)
62+
} catch (exception: JSONException) {
63+
false
64+
}
65+
}
5966
}
6067
}

app/src/main/java/com/omgodse/notally/room/json/SafeJSONObject.kt

-15
This file was deleted.

app/src/main/java/com/omgodse/notally/viewmodels/Extensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.launch
88
import kotlinx.coroutines.withContext
99

10-
internal fun ViewModel.executeAsyncWithCallback(function: suspend () -> Unit, callback: (success: Boolean) -> Unit) {
10+
fun ViewModel.executeAsyncWithCallback(function: suspend () -> Unit, callback: (success: Boolean) -> Unit) {
1111
viewModelScope.launch {
1212
val success = try {
1313
withContext(Dispatchers.IO) { function() }

app/src/main/res/drawable/drag_handle.xml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
22
android:width="24dp"
33
android:height="24dp"
4-
android:tint="?attr/colorControlNormal"
54
android:viewportWidth="24"
65
android:viewportHeight="24">
76
<path

app/src/main/res/drawable/notebook.xml

-57
This file was deleted.

app/src/main/res/drawable/notes.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
android:viewportHeight="24">
66
<path
77
android:fillColor="#000000"
8-
android:pathData="M3,18h12v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h18v-2L3,11v2z" />
8+
android:pathData="M19,5v14H5V5H19M19,3H5C3.9,3 3,3.9 3,5v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5C21,3.9 20.1,3 19,3L19,3z" />
9+
<path
10+
android:fillColor="#000000"
11+
android:pathData="M14,17H7v-2h7V17zM17,13H7v-2h10V13zM17,9H7V7h10V9z" />
912
</vector>

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
android:id="@+id/Toolbar"
1919
android:layout_width="match_parent"
2020
android:layout_height="wrap_content"
21-
app:contentInsetEnd="16dp"
22-
app:titleTextAppearance="@style/TextAppearance.Toolbar">
21+
app:contentInsetEnd="16dp">
2322

2423
<com.google.android.material.textfield.TextInputEditText
2524
android:id="@+id/EnterSearchKeyword"

0 commit comments

Comments
 (0)