Skip to content

Commit

Permalink
More fixes and stability improvements. More Toasts and UX improvement…
Browse files Browse the repository at this point in the history
…s. Release Version 12.
  • Loading branch information
NilsFo committed Jan 4, 2023
1 parent 12e3a8e commit 1ba2ef4
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
minSdkVersion 17
targetSdkVersion 33
// targetSdkPreview "Tiramisu"
versionCode 12
versionName "1.0.10"
versionCode 13
versionName "1.0.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;

import java.util.Locale;

import de.nilsfo.lockscreennotes.util.VersionManager;
Expand Down Expand Up @@ -41,6 +43,7 @@ public class LockScreenNotes extends Application {
public static final int REQUEST_CODE_INTENT_AUTO_BACKUP_ALARM = 3;
public static final int REQUEST_CODE_INTENT_OPEN_APP = 4;
public static final int REQUEST_CODE_INTENT_OPEN_APP_EDIT_NOTE = 5;
public static final int REQUEST_CODE_INTENT_DISMISS_NOTE = 6;

public static boolean isDarkMode(Context context) {
return isDarkMode(context.getResources().getConfiguration());
Expand Down Expand Up @@ -142,7 +145,7 @@ public static boolean isDebugBuild() {

private class DebugTree extends Timber.DebugTree {
@Override
protected String createStackElementTag(StackTraceElement element) {
protected String createStackElementTag(@NonNull StackTraceElement element) {
return LOG_TAG + super.createStackElementTag(element) + ":" + element.getLineNumber();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,11 @@ public void onClick(DialogInterface dialog, int which) {
}
}
Timber.i("On accept: " + sequence);
if (sequence == null) {
Toast.makeText(builder.getContext(), R.string.error_internal_error, Toast.LENGTH_LONG).show();
return;
}

File file = new File(new FileManager(MainActivity.this).getNoteBackupDir(), sequence.toString());
Timber.i("Assumed backup File: " + file.getAbsolutePath() + " - Exists: " + file.exists());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -66,15 +67,19 @@ public void updateText(Context context) {
continue;
}
boolean contains = timestampMap.containsKey(v);

if (contains) {
long timestamp = timestampMap.get(v);
long timestamp = Note.DEFAULT_TIMESTAMP;
try {
timestamp = timestampMap.get(v);
} catch (Exception e) {
Timber.e(e);
Timber.e("Failed to get timestamp for: " + v);
Toast.makeText(context, R.string.error_internal_error, Toast.LENGTH_LONG).show();
}

if (v.isShown()) {
v.setText(context.getString(R.string.last_edited, new TimeUtils(context).formatRelative(timestamp)));
} //else {
// deleteList.add(v);
//}
}
} else {
v.setText(context.getString(R.string.last_edited, context.getText(R.string.error_internal_error)));
Timber.e("The timestamp map did a big oof.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@
* A Drawable object that draws text.
* A TextDrawable accepts most of the same parameters that can be applied to
* {@link android.widget.TextView} for displaying and formatting text.
*
* <p>
* Optionally, a {@link Path} may be supplied on which to draw the text.
*
* <p>
* A TextDrawable has an intrinsic size equal to that required to draw all
* the text it has been supplied, when possible. In cases where a {@link Path}
* has been supplied, the caller must explicitly call
* {@link #setBounds(android.graphics.Rect) setBounds()} to provide the Drawable
* size based on the Path constraints.
*/

@Deprecated
public class TextDrawable extends Drawable {

/* Platform XML constants for typeface */
Expand Down Expand Up @@ -168,6 +170,7 @@ public CharSequence getText() {

/**
* Set the text that will be displayed
*
* @param text Text to display
*/
public void setText(CharSequence text) {
Expand All @@ -187,6 +190,7 @@ public float getTextSize() {

/**
* Set the text size. The value will be interpreted in "sp" units
*
* @param size Text size value, in sp
*/
public void setTextSize(float size) {
Expand All @@ -195,6 +199,7 @@ public void setTextSize(float size) {

/**
* Set the text size, using the supplied complex units
*
* @param unit Units for the text size, such as dp or sp
* @param size Text size value
*/
Expand Down Expand Up @@ -224,6 +229,7 @@ public float getTextScaleX() {

/**
* Set the horizontal stretch factor of the text
*
* @param size Text scale factor
*/
public void setTextScaleX(float size) {
Expand All @@ -244,11 +250,12 @@ public Layout.Alignment getTextAlign() {
* Set the text alignment. The alignment itself is based on the text layout direction.
* For LTR text NORMAL is left aligned and OPPOSITE is right aligned.
* For RTL text, those alignments are reversed.
* @param align Text alignment value. Should be set to one of:
*
* {@link Layout.Alignment#ALIGN_NORMAL},
* {@link Layout.Alignment#ALIGN_NORMAL},
* {@link Layout.Alignment#ALIGN_OPPOSITE}.
* @param align Text alignment value. Should be set to one of:
* <p>
* {@link Layout.Alignment#ALIGN_NORMAL},
* {@link Layout.Alignment#ALIGN_NORMAL},
* {@link Layout.Alignment#ALIGN_OPPOSITE}.
*/
public void setTextAlign(Layout.Alignment align) {
if (mTextAlignment != align) {
Expand All @@ -262,7 +269,6 @@ public void setTextAlign(Layout.Alignment align) {
* and turns on the fake bold and italic bits in the Paint if the
* Typeface that you provided does not have all the bits in the
* style that you specified.
*
*/
public void setTypeface(Typeface tf, int style) {
if (style > 0) {
Expand Down Expand Up @@ -310,6 +316,7 @@ public void setTypeface(Typeface tf) {

/**
* Set a single text color for all states
*
* @param color Color value such as {@link Color#WHITE} or {@link Color#argb(int, int, int, int)}
*/
public void setTextColor(int color) {
Expand All @@ -318,6 +325,7 @@ public void setTextColor(int color) {

/**
* Set the text color as a state list
*
* @param colorStateList ColorStateList of text colors, such as inflated from an R.color resource
*/
public void setTextColor(ColorStateList colorStateList) {
Expand All @@ -330,7 +338,7 @@ public void setTextColor(ColorStateList colorStateList) {
* TextDrawable cannot properly measure the bounds this drawable will need.
* You must call {@link #setBounds(int, int, int, int) setBounds()} before
* applying this TextDrawable to any View.
*
* <p>
* Calling this method with <code>null</code> will remove any Path currently attached.
*/
public void setTextPath(Path path) {
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/de/nilsfo/lockscreennotes/io/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public boolean createNoMediaFile(File parent) {
public boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
if (children != null) {
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
}
return dir.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,50 @@ public class NotificationDismissedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null) {
Timber.e("I just got a 'NoitificationDismissed' intent! But there were no extras! Could not perform any actions!");
Timber.e("I just got a 'NotificationDismissed' intent! But there were no extras! Could not perform any actions!");
Toast.makeText(context, R.string.error_internal_error, Toast.LENGTH_LONG).show();
return;
}

long notificationId = NotesNotificationManager.INTENT_EXTRA_NOTE_ID_NONE;
if (extras.containsKey(NotesNotificationManager.INTENT_EXTRA_NOTE_ID)) {
notificationId = extras.getLong(NotesNotificationManager.INTENT_EXTRA_NOTE_ID);

// #######################
// TODO THIS IS A BIG ONE: THE NOTIFICATION ID ALWAYS RESOLVES TO THE ID OF THE FIRST NOTE WHY?
// #######################
} else {
Timber.e("FAILED TO GET INTENT EXTRA FOR THE NOTIFICATION ID!!");
Toast.makeText(context, R.string.error_internal_error, Toast.LENGTH_LONG).show();
return;
}

// TODO REMOVE THIS LINE BELOW, but only if you have resolved the issue stated above
// This is a backup case where all notifications will be disabled regardless
notificationId = NotesNotificationManager.INTENT_EXTRA_NOTE_ID_NONE;

// Opening the DB to fetch notes
DBAdapter databaseAdapter = new DBAdapter(context);
databaseAdapter.open();

long notificationId = extras.getInt(NotesNotificationManager.INTENT_EXTRA_NOTE_ID);
ArrayList<Note> notes = new ArrayList<>();
if (notificationId == NotesNotificationManager.INTENT_EXTRA_NOTE_ID_NONE) {
notes = Note.getAllNotesFromDB(databaseAdapter);
try {
notes = Note.getAllNotesFromDB(databaseAdapter);
} catch (Exception e) {
Timber.e(e);
Timber.e("Failed to get all notes from database!");
Toast.makeText(context, R.string.error_internal_error, Toast.LENGTH_LONG).show();
}
Timber.i("That was no known ID, so just hide them all.");
} else {
notes.add(Note.getNoteFromDB(notificationId, databaseAdapter));
try {
notes.add(Note.getNoteFromDB(notificationId, databaseAdapter));
} catch (Exception e) {
Timber.e(e);
Timber.e("Failed to get Note from Database with ID: " + notificationId);
Toast.makeText(context, R.string.error_internal_error, Toast.LENGTH_LONG).show();
}
Timber.i("Found the right note with matching ID in the database.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.nilsfo.lockscreennotes.receiver.widget;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
Expand All @@ -9,7 +8,6 @@

import java.util.Arrays;

import de.nilsfo.lockscreennotes.activity.MainActivity;
import timber.log.Timber;

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static de.nilsfo.lockscreennotes.util.NotificationChannelManager.CHANNEL_ID_AUTO_BACKUP_CHANNEL;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
Expand Down Expand Up @@ -42,7 +41,6 @@
import de.nilsfo.lockscreennotes.data.content.NoteContentAnalyzer;
import de.nilsfo.lockscreennotes.io.StoragePermissionManager;
import de.nilsfo.lockscreennotes.io.backups.BackupManager;
import de.nilsfo.lockscreennotes.receiver.NotificationDeleteReceiver;
import de.nilsfo.lockscreennotes.receiver.NotificationDismissedReceiver;
import de.nilsfo.lockscreennotes.sql.DBAdapter;
import de.nilsfo.lsn.R;
Expand All @@ -64,6 +62,7 @@ public class NotesNotificationManager {

public static final int REQUEST_CODE_INTENT_OPEN_APP_DYNAMIC_BASE = LockScreenNotes.REQUEST_CODE_INTENT_OPEN_APP * 10000;
public static final int REQUEST_CODE_INTENT_OPEN_APP_EDIT_NOTE_DYNAMIC_BASE = LockScreenNotes.REQUEST_CODE_INTENT_OPEN_APP_EDIT_NOTE * 10000;
public static final int REQUEST_CODE_INTENT_DISMISS_NOTE_DYNAMIC_BASE = LockScreenNotes.REQUEST_CODE_INTENT_DISMISS_NOTE * 10000;

@Deprecated
public static final String INTENT_EXTRA_DELETE = LockScreenNotes.APP_TAG + "delete_mode";
Expand All @@ -75,7 +74,7 @@ public class NotesNotificationManager {

public static final int DEFAULT_NOTIFICATION_ID = 100;
public static final int NOTE_PREVIEW_SIZE = -1;
public static final int INTENT_EXTRA_NOTE_ID_NONE = -1;
public static final long INTENT_EXTRA_NOTE_ID_NONE = -1;
private Context context;
private ArrayList<Note> notesList;
private boolean reversed;
Expand Down Expand Up @@ -296,12 +295,13 @@ private boolean applyActionsToIndividualNote(NotificationCompat.Builder builder,
return false;
}

PendingIntent dismissIntent = createOnNoteDismissIntent(INTENT_EXTRA_NOTE_ID_NONE);
long noteID = note.getDatabaseID();
PendingIntent dismissIntent = createOnNoteDismissIntent(noteID);
if (dismissIntent == null) {
Toast.makeText(context, R.string.error_notification_pending_intent_failure, Toast.LENGTH_LONG).show();
} else {
builder.setDeleteIntent(dismissIntent);
builder.addAction(R.drawable.baseline_notifications_off_black_24, context.getString(R.string.action_mark_disabled_all), createOnNoteDismissIntent(INTENT_EXTRA_NOTE_ID_NONE));
builder.addAction(R.drawable.baseline_notifications_off_black_24, context.getString(R.string.action_mark_disabled_all), createOnNoteDismissIntent(noteID));
}

Timber.i("Setting up notification actions for note ID " + note.getDatabaseID() + " (" + note.getTextPreview() + ").");
Expand All @@ -316,17 +316,18 @@ private boolean applyActionsToIndividualNote(NotificationCompat.Builder builder,
return true;
}

private PendingIntent createOnNoteDismissIntent(int notificationId) {
private PendingIntent createOnNoteDismissIntent(long noteID) {
Intent intent = new Intent(context, NotificationDismissedReceiver.class);
intent.putExtra(INTENT_EXTRA_NOTE_ID, notificationId);
Timber.i("Creating a dismiss intent. ID: " + notificationId);
intent.putExtra(INTENT_EXTRA_NOTE_ID, noteID);
Timber.i("Creating a dismiss intent. ID: " + REQUEST_CODE_INTENT_DISMISS_NOTE_DYNAMIC_BASE);
Timber.i("This intent has note ID: " + noteID);

PendingIntent broadcast = null;
try {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
broadcast = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
broadcast = PendingIntent.getBroadcast(context, REQUEST_CODE_INTENT_DISMISS_NOTE_DYNAMIC_BASE, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
broadcast = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
broadcast = PendingIntent.getBroadcast(context, REQUEST_CODE_INTENT_DISMISS_NOTE_DYNAMIC_BASE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
} catch (Exception e) {
Timber.e(e);
Expand Down Expand Up @@ -382,10 +383,10 @@ private void createOnNoteContentIntent(NotificationCompat.Builder builder, Note
} else {
pendingIntent = PendingIntent.getActivity(context, (int) note.getDatabaseID(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
}catch (Exception e){
} catch (Exception e) {
Timber.e(e);
Timber.e("Error! Could not set up note context specific intent!");
Toast.makeText(context, R.string.error_notification_pending_intent_failure,Toast.LENGTH_LONG).show();
Toast.makeText(context, R.string.error_notification_pending_intent_failure, Toast.LENGTH_LONG).show();
}

if (pendingIntent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ArrayList<String> findMatchesInText(String text) {
for (String s : list) {
if (s.equals(match)) {
add = false;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.nilsfo.lockscreennotes.util;

import static de.nilsfo.lockscreennotes.util.NotesNotificationManager.PREFERENCE_HIGH_PRIORITY_NOTE;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
Expand Down
Loading

0 comments on commit 1ba2ef4

Please sign in to comment.