Skip to content

Commit

Permalink
v.1.0.1
Browse files Browse the repository at this point in the history
- dialog improvements
- minor changes
  • Loading branch information
Yanndroid committed Feb 13, 2022
1 parent 98f0b73 commit 88b8a5e
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 210 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "de.dlyt.yanndroid.notinotes"
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0.0",
"versionCode": 2,
"versionName": "1.0.1",
"outputFile": "app-release.apk"
}
],
Expand Down
233 changes: 116 additions & 117 deletions app/src/main/java/de/dlyt/yanndroid/notinotes/QSTile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.res.Configuration
import android.graphics.PixelFormat
import android.net.Uri
import android.os.Build
Expand All @@ -17,6 +16,7 @@ import android.service.quicksettings.TileService
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.*
import androidx.core.app.NotificationCompat
Expand All @@ -34,33 +34,38 @@ class QSTile : TileService() {
private val NOTIFICATION_CHANNEL = "1234"
private val ACTION_EDIT_NOTE = "de.dlyt.yanndroid.notinotes.EDIT_NOTE"
private val ACTION_DELETE_NOTE = "de.dlyt.yanndroid.notinotes.DELETE_NOTE"
private val ACTION_SHOW_NOTE = "de.dlyt.yanndroid.notinotes.SHOW_NOTE"

var COLORS = intArrayOf(
R.color.color_1,
R.color.color_2,
R.color.color_3,
R.color.color_4,
R.color.color_5,
R.color.color_6
R.color.color_6,
R.color.color_7,
R.color.color_8
)
var RBIDS = intArrayOf(
R.id.color_1,
R.id.color_2,
R.id.color_3,
R.id.color_4,
R.id.color_5,
R.id.color_6
R.id.color_6,
R.id.color_7,
R.id.color_8
)

private val context: Context = this
private var notes: ArrayList<Note> = ArrayList()
private val mBroadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.e("mBroadcastReceiver", intent.action.toString())
val note: Note = (intent.getSerializableExtra(INTENT_EXTRA) ?: return) as Note
when (intent.action) {
ACTION_EDIT_NOTE -> editNotePopup(note)
ACTION_DELETE_NOTE -> deleteNoteDialog(note)
ACTION_SHOW_NOTE -> showNoteDialog(note)
}
}
}
Expand All @@ -72,10 +77,8 @@ class QSTile : TileService() {
var id = id
}

private fun saveNotesToSP() {
getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
.putString("notes", Gson().toJson(notes)).apply()
}
private fun saveNotesToSP() = getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
.putString("notes", Gson().toJson(notes)).apply()

private fun loadNotesFromSP() {
notes = Gson().fromJson(
Expand All @@ -86,16 +89,16 @@ class QSTile : TileService() {

override fun onCreate() {
super.onCreate()
requestPermission()
createNotificationChannel()
loadNotesFromSP()
for (note in notes) showNotification(note)

val intentFilter = IntentFilter()
intentFilter.addAction(ACTION_EDIT_NOTE)
intentFilter.addAction(ACTION_DELETE_NOTE)
registerReceiver(mBroadcastReceiver, intentFilter)

requestPermission()
registerReceiver(mBroadcastReceiver, IntentFilter().also {
it.addAction(ACTION_EDIT_NOTE)
it.addAction(ACTION_DELETE_NOTE)
it.addAction(ACTION_SHOW_NOTE)
})
}

override fun onTileRemoved() {
Expand Down Expand Up @@ -149,89 +152,6 @@ class QSTile : TileService() {
}
}

private fun editNotePopup(note: Note) {
if (!Settings.canDrawOverlays(context)) return
closePanel()
val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val params = WindowManager.LayoutParams(
((if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) resources.displayMetrics.widthPixels else resources.displayMetrics.heightPixels) * 0.90).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_DIM_BEHIND or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
PixelFormat.TRANSLUCENT
)
params.windowAnimations = R.style.PopupAnimStyle
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
params.dimAmount = 0.35f
params.gravity = Gravity.BOTTOM

val pView = LayoutInflater.from(context).inflate(R.layout.popup_edit_layout, null)
windowManager.addView(pView, params)

val pTitle = pView.findViewById<EditText>(R.id.pTitle)
val pNote = pView.findViewById<EditText>(R.id.pNote)
val pSave = pView.findViewById<Button>(R.id.pSave)
val pCancel = pView.findViewById<Button>(R.id.pCancel)
val pColorPicker = pView.findViewById<RadioGroup>(R.id.color_picker)

pTitle.setText(note.title)
pNote.setText(note.content)
pSave.setOnClickListener {
note.title = pTitle.text.toString()
note.content = pNote.text.toString()
note.colorIndex = RBIDS.indexOf(pColorPicker.checkedRadioButtonId)
saveNote(note)
windowManager.removeView(pView)
}

pCancel.setOnClickListener { windowManager.removeView(pView) }
pView.setOnClickListener { windowManager.removeView(pView) }

pColorPicker.setOnCheckedChangeListener { radioGroup, i ->
pSave.setTextColor(getColor(COLORS[RBIDS.indexOf(i)]))
pCancel.setTextColor(getColor(COLORS[RBIDS.indexOf(i)]))
}
pColorPicker.check(RBIDS[note.colorIndex])
}

private fun deleteNoteDialog(note: Note) {
if (!Settings.canDrawOverlays(context)) return
closePanel()
val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val params = WindowManager.LayoutParams(
(resources.displayMetrics.widthPixels * 0.90).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
PixelFormat.TRANSLUCENT
)
params.windowAnimations = R.style.PopupAnimStyle
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
params.dimAmount = 0.35f
params.gravity = Gravity.BOTTOM

val pView = LayoutInflater.from(context).inflate(R.layout.popup_delete_layout, null)
windowManager.addView(pView, params)

val pTitle = pView.findViewById<TextView>(R.id.pTitle)
val pNote = pView.findViewById<TextView>(R.id.pNote)
val pDelete = pView.findViewById<Button>(R.id.pDelete)
val pCancel = pView.findViewById<Button>(R.id.pCancel)

pTitle.text = getString(R.string.del_x, note.title)
pNote.text = note.content
pDelete.setOnClickListener {
deleteNote(note)
windowManager.removeView(pView)
}

pCancel.setOnClickListener { windowManager.removeView(pView) }
pView.setOnClickListener { windowManager.removeView(pView) }

pDelete.setTextColor(getColor(COLORS[note.colorIndex]))
pCancel.setTextColor(getColor(COLORS[note.colorIndex]))
}

private fun showNotification(note: Note) {
val nmc = NotificationManagerCompat.from(this)
nmc.notify( //for some reason this in needed to make grouping work
Expand All @@ -253,13 +173,14 @@ class QSTile : TileService() {
.addAction(
R.drawable.ic_edit,
getString(R.string.edit),
getPendingIntent(note, false)
getPendingIntent(note, ACTION_EDIT_NOTE)
)
.addAction(
R.drawable.ic_delete,
getString(R.string.del),
getPendingIntent(note, true)
getPendingIntent(note, ACTION_DELETE_NOTE)
)
.setContentIntent(getPendingIntent(note, ACTION_SHOW_NOTE))
.setColor(getColor(COLORS[note.colorIndex]))
.build()
)
Expand All @@ -271,7 +192,93 @@ class QSTile : TileService() {
if (notes.size == 0) nmc.cancel(NOTIFICATION_GROUP_HOLDER)
}

// #### helper methods ####
private fun editNotePopup(note: Note) {
if (!Settings.canDrawOverlays(context)) return
val deleteDialog = Dialog(R.layout.popup_edit_layout, note, note.title)
val pColorPicker = deleteDialog.pView.findViewById<RadioGroup>(R.id.color_picker).also {
it.setOnCheckedChangeListener { _, i ->
deleteDialog.pPos.setTextColor(getColor(COLORS[RBIDS.indexOf(i)]))
deleteDialog.pNeg.setTextColor(getColor(COLORS[RBIDS.indexOf(i)]))
deleteDialog.pIcon.setColorFilter(getColor(COLORS[RBIDS.indexOf(i)]))
}
it.check(RBIDS[note.colorIndex])
}

deleteDialog.pNeg.setOnClickListener { deleteDialog.dismiss() }
deleteDialog.pPos.setOnClickListener {
note.title = deleteDialog.pTitle.text.toString()
note.content = deleteDialog.pNote.text.toString()
note.colorIndex = RBIDS.indexOf(pColorPicker.checkedRadioButtonId)
saveNote(note)
deleteDialog.dismiss()
}
}

private fun deleteNoteDialog(note: Note) {
if (!Settings.canDrawOverlays(context)) return
val deleteDialog =
Dialog(R.layout.popup_show_layout, note, getString(R.string.del_x, note.title))
deleteDialog.pNeg.setText(R.string.cancel)
deleteDialog.pNeg.setOnClickListener { deleteDialog.dismiss() }
deleteDialog.pPos.setOnClickListener {
deleteNote(note)
deleteDialog.dismiss()
}
}

private fun showNoteDialog(note: Note) {
if (!Settings.canDrawOverlays(context)) return
val deleteDialog = Dialog(R.layout.popup_show_layout, note, note.title)
deleteDialog.pNeg.setOnClickListener {
editNotePopup(note)
deleteDialog.dismiss()
}
deleteDialog.pPos.setOnClickListener {
deleteNoteDialog(note)
deleteDialog.dismiss()
}
}

inner class Dialog(layoutRes: Int, note: Note, title: String?) {
private val windowManager: WindowManager
val pView: View
val pTitle: TextView
val pNote: TextView
val pNeg: Button
val pPos: Button
val pIcon: ImageView

init {
closePanel()
windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val params = WindowManager.LayoutParams(
(resources.displayMetrics.widthPixels * 0.90).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
PixelFormat.TRANSLUCENT
)
params.windowAnimations = R.style.PopupAnimStyle
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
params.dimAmount = 0.35f
params.gravity = Gravity.BOTTOM

pView = LayoutInflater.from(context).inflate(layoutRes, null)
windowManager.addView(pView, params)
pView.setOnClickListener { dismiss() }

pTitle = pView.findViewById<TextView>(R.id.pTitle).also { it.text = title }
pNote = pView.findViewById<TextView>(R.id.pNote).also { it.text = note.content }
pNeg = pView.findViewById<Button>(R.id.pNeg)
.also { it.setTextColor(getColor(COLORS[note.colorIndex])) }
pPos = pView.findViewById<Button>(R.id.pPos)
.also { it.setTextColor(getColor(COLORS[note.colorIndex])) }
pIcon = pView.findViewById<ImageView>(R.id.pIcon)
.also { it.setColorFilter(getColor(COLORS[note.colorIndex])) }
}

fun dismiss() = windowManager.removeView(pView)
}

private fun requestPermission() {
if (!Settings.canDrawOverlays(this)) {
Expand Down Expand Up @@ -303,8 +310,8 @@ class QSTile : TileService() {
return newID
}

private fun getPendingIntent(note: Note, delete: Boolean): PendingIntent {
val intent = Intent(if (delete) ACTION_DELETE_NOTE else ACTION_EDIT_NOTE)
private fun getPendingIntent(note: Note, action: String): PendingIntent {
val intent = Intent(action)
intent.putExtra(INTENT_EXTRA, note)
return PendingIntent.getBroadcast(
context,
Expand Down Expand Up @@ -345,20 +352,24 @@ class QSTile : TileService() {
noteView.setTextViewText(R.id.qs_list_item_title, note.title)
noteView.setTextColor(R.id.qs_list_item_title, getColor(COLORS[note.colorIndex]))
noteView.setTextViewText(R.id.qs_list_item_content, note.content)
noteView.setOnClickPendingIntent(
R.id.qs_list_item_container,
getPendingIntent(note, ACTION_SHOW_NOTE)
)
noteView.setOnClickPendingIntent(
R.id.qs_list_item_edit,
getPendingIntent(note, false)
getPendingIntent(note, ACTION_EDIT_NOTE)
)
noteView.setOnClickPendingIntent(
R.id.qs_list_item_delete,
getPendingIntent(note, true)
getPendingIntent(note, ACTION_DELETE_NOTE)
)
adapter.addView(noteView)
}

remoteViews.setOnClickPendingIntent(
R.id.qs_detail_add,
getPendingIntent(Note(null, null, 0, generateNewNoteID()), false)
getPendingIntent(Note(null, null, 0, generateNewNoteID()), ACTION_EDIT_NOTE)
)
return remoteViews
}
Expand All @@ -374,16 +385,4 @@ class QSTile : TileService() {
root.addView(LLId, aView)
}
}

/*
public final void semFireToggleStateChanged(boolean var1, boolean var2)
public RemoteViews semGetDetailView()
public CharSequence semGetDetailViewSettingButtonName()
public CharSequence semGetDetailViewTitle()
public Intent semGetSettingsIntent()
public boolean semIsToggleButtonChecked()
public boolean semIsToggleButtonExists()
public void semSetToggleButtonChecked(boolean var1)
public final void semUpdateDetailView()
*/
}
13 changes: 9 additions & 4 deletions app/src/main/res/drawable/ic_delete.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="24.0dip"
android:height="24.0dip"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M14.249,2.9375C14.939,2.9375 15.499,3.4985 15.499,4.1875L15.499,4.1875L15.499,6.1875L19.686,6.1875C20.1,6.1875 20.436,6.5235 20.436,6.9375C20.436,7.3525 20.1,7.6875 19.686,7.6875L19.686,7.6875L18.334,7.6875L17.427,18.9535C17.334,20.1165 16.308,21.0625 15.142,21.0625L15.142,21.0625L8.858,21.0625C7.692,21.0625 6.667,20.1165 6.573,18.9535L6.573,18.9535L5.667,7.6875L4.314,7.6875C3.9,7.6875 3.564,7.3525 3.564,6.9375C3.564,6.5235 3.9,6.1875 4.314,6.1875L4.314,6.1875L8.499,6.1875L8.499,4.1875C8.499,3.4985 9.06,2.9375 9.749,2.9375L9.749,2.9375ZM10.131,10.8515C9.716,10.8515 9.381,11.1875 9.381,11.6015L9.381,11.6015L9.381,16.0515C9.381,16.4665 9.716,16.8015 10.131,16.8015C10.545,16.8015 10.881,16.4665 10.881,16.0515L10.881,16.0515L10.881,11.6015C10.881,11.1875 10.545,10.8515 10.131,10.8515ZM13.87,10.8515C13.456,10.8515 13.12,11.1875 13.12,11.6015L13.12,11.6015L13.12,16.0515C13.12,16.4665 13.456,16.8015 13.87,16.8015C14.284,16.8015 14.62,16.4665 14.62,16.0515L14.62,16.0515L14.62,11.6015C14.62,11.1875 14.284,10.8515 13.87,10.8515ZM13.999,4.4375L9.999,4.4375L9.999,6.1875L13.999,6.1875L13.999,4.4375Z" />
android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M18.2369,6.8956L17.2849,19.1546C17.2049,20.1966 16.3359,20.9996 15.2919,20.9996L8.7089,20.9996C7.6639,20.9996 6.7959,20.1966 6.7149,19.1546L5.7639,6.8956M4.314,6.5001L19.686,6.5001M13.8702,11.6642L13.8702,16.1142M10.1304,11.6642L10.1304,16.1142M9.2496,6.0001L9.2496,3.7501C9.2496,3.4751 9.4746,3.2501 9.7496,3.2501L14.2496,3.2501C14.5246,3.2501 14.7496,3.4751 14.7496,3.7501L14.7496,6.0001"
android:strokeWidth="1.5"
android:strokeColor="@android:color/white"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>
Loading

0 comments on commit 88b8a5e

Please sign in to comment.